From c2ba0d474c720e24d48b2bedaf631ece6d61f970 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 2 Jan 2012 13:32:25 +0100 Subject: [PATCH] Use limits.h and PATH_MAX. --- conf/config_file.c | 10 +++--- file.c | 28 ++++++++-------- general.h | 83 ++++++++++++++++++++++------------------------ gfx/shader_cg.c | 4 +-- gfx/shader_glsl.c | 4 +-- settings.c | 10 +++--- ssnes.c | 13 ++++---- 7 files changed, 73 insertions(+), 79 deletions(-) diff --git a/conf/config_file.c b/conf/config_file.c index 59573c030e..a58333d2f0 100644 --- a/conf/config_file.c +++ b/conf/config_file.c @@ -27,17 +27,17 @@ #include "../msvc/msvc_compat.h" #if !defined(_WIN32) && !defined(__CELLOS_LV2__) -#include // MAXPATHLEN +#include // PATH_MAX #elif defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include #endif -#ifndef MAXPATHLEN +#ifndef PATH_MAX #ifdef PATH_MAX -#define MAXPATHLEN PATH_MAX +#define PATH_MAX PATH_MAX #else -#define MAXPATHLEN 512 +#define PATH_MAX 512 #endif #endif @@ -195,7 +195,7 @@ static void add_sub_conf(config_file_t *conf, char *line) add_include_list(conf, path); - char real_path[MAXPATHLEN]; + char real_path[PATH_MAX]; #ifdef _WIN32 // Accomodate POSIX systems on Win32. diff --git a/file.c b/file.c index e4ec0a6fcb..11bc08282f 100644 --- a/file.c +++ b/file.c @@ -376,9 +376,9 @@ static void dump_to_file_desperate(const void *data, size_t size, int type) if (!base) goto error; - char path[MAXPATHLEN]; + char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/SSNES-recovery-", base); - char timebuf[MAXPATHLEN]; + char timebuf[PATH_MAX]; time_t time_; time(&time_); @@ -838,8 +838,8 @@ char **dir_list_new(const char *dir, const char *ext) WIN32_FIND_DATAW ffd; HANDLE hFind = INVALID_HANDLE_VALUE; - wchar_t wchar_buf[MAXPATHLEN]; - char utf8_buf[MAXPATHLEN]; + wchar_t wchar_buf[PATH_MAX]; + char utf8_buf[PATH_MAX]; if (strlcpy(utf8_buf, dir, sizeof(utf8_buf)) >= sizeof(utf8_buf)) goto error; @@ -852,7 +852,7 @@ char **dir_list_new(const char *dir, const char *ext) goto error; } - if (MultiByteToWideChar(CP_UTF8, 0, utf8_buf, -1, wchar_buf, MAXPATHLEN) == 0) + if (MultiByteToWideChar(CP_UTF8, 0, utf8_buf, -1, wchar_buf, PATH_MAX) == 0) goto error; hFind = FindFirstFileW(wchar_buf, &ffd); @@ -881,7 +881,7 @@ char **dir_list_new(const char *dir, const char *ext) #ifdef _WIN32 if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; - if (WideCharToMultiByte(CP_UTF8, 0, ffd.cFileName, -1, utf8_buf, MAXPATHLEN, NULL, NULL) == 0) + if (WideCharToMultiByte(CP_UTF8, 0, ffd.cFileName, -1, utf8_buf, PATH_MAX, NULL, NULL) == 0) continue; if (ext && !strstr(utf8_buf, ext)) continue; @@ -890,16 +890,16 @@ char **dir_list_new(const char *dir, const char *ext) continue; #endif - dir_list[cur_ptr] = (char*)malloc(MAXPATHLEN); + dir_list[cur_ptr] = (char*)malloc(PATH_MAX); if (!dir_list[cur_ptr]) goto error; - strlcpy(dir_list[cur_ptr], dir, MAXPATHLEN); - strlcat(dir_list[cur_ptr], "/", MAXPATHLEN); + strlcpy(dir_list[cur_ptr], dir, PATH_MAX); + strlcat(dir_list[cur_ptr], "/", PATH_MAX); #ifdef _WIN32 - strlcat(dir_list[cur_ptr], utf8_buf, MAXPATHLEN); + strlcat(dir_list[cur_ptr], utf8_buf, PATH_MAX); #else - strlcat(dir_list[cur_ptr], entry->d_name, MAXPATHLEN); + strlcat(dir_list[cur_ptr], entry->d_name, PATH_MAX); #endif cur_ptr++; @@ -952,8 +952,8 @@ void dir_list_free(char **dir_list) bool path_is_directory(const char *path) { #ifdef _WIN32 - wchar_t buf[MAXPATHLEN]; - if (MultiByteToWideChar(CP_UTF8, 0, path, -1, buf, MAXPATHLEN) == 0) + wchar_t buf[PATH_MAX]; + if (MultiByteToWideChar(CP_UTF8, 0, path, -1, buf, PATH_MAX) == 0) return false; return PathIsDirectoryW(buf) == FILE_ATTRIBUTE_DIRECTORY; #elif defined(__CELLOS_LV2__) @@ -984,7 +984,7 @@ bool path_file_exists(const char *path) void fill_pathname(char *out_path, const char *in_path, const char *replace, size_t size) { - char tmp_path[MAXPATHLEN]; + char tmp_path[PATH_MAX]; ssnes_assert(strlcpy(tmp_path, in_path, sizeof(tmp_path)) < sizeof(tmp_path)); char *tok = strrchr(tmp_path, '.'); diff --git a/general.h b/general.h index b6246fa41b..16af3ae25b 100644 --- a/general.h +++ b/general.h @@ -22,6 +22,7 @@ #include "boolean.h" #include #include +#include #include "driver.h" #include "record/ffemu.h" #include "message.h" @@ -50,22 +51,12 @@ #include "audio/hermite.h" -#if !defined(_WIN32) && !defined(__CELLOS_LV2__) -#include // MAXPATHLEN -#elif defined(_WIN32) +#ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include #include "msvc/msvc_compat.h" #endif -#ifndef MAXPATHLEN -#ifdef PATH_MAX -#define MAXPATHLEN PATH_MAX -#else -#define MAXPATHLEN 512 -#endif -#endif - #define MAX_PLAYERS 5 #define MAX_BINDS (SSNES_BIND_LIST_END + 1) #define SSNES_NO_JOYPAD 0xFFFF @@ -94,20 +85,20 @@ struct settings bool force_aspect; bool crop_overscan; float aspect_ratio; - char cg_shader_path[MAXPATHLEN]; - char bsnes_shader_path[MAXPATHLEN]; - char filter_path[MAXPATHLEN]; + char cg_shader_path[PATH_MAX]; + char bsnes_shader_path[PATH_MAX]; + char filter_path[PATH_MAX]; enum ssnes_shader_type shader_type; float refresh_rate; bool render_to_texture; double fbo_scale_x; double fbo_scale_y; - char second_pass_shader[MAXPATHLEN]; + char second_pass_shader[PATH_MAX]; bool second_pass_smooth; - char shader_dir[MAXPATHLEN]; + char shader_dir[PATH_MAX]; - char font_path[MAXPATHLEN]; + char font_path[PATH_MAX]; unsigned font_size; bool font_enable; float msg_pos_x; @@ -122,7 +113,7 @@ struct settings bool hires_record; bool post_filter_record; - char external_driver[MAXPATHLEN]; + char external_driver[PATH_MAX]; } video; struct @@ -132,12 +123,12 @@ struct settings unsigned out_rate; float in_rate; float rate_step; - char device[MAXPATHLEN]; + char device[PATH_MAX]; unsigned latency; bool sync; - char dsp_plugin[MAXPATHLEN]; - char external_driver[MAXPATHLEN]; + char dsp_plugin[PATH_MAX]; + char external_driver[PATH_MAX]; } audio; struct @@ -149,11 +140,11 @@ struct settings bool netplay_client_swap_input; } input; - char libsnes[MAXPATHLEN]; - char cheat_database[MAXPATHLEN]; - char cheat_settings_path[MAXPATHLEN]; + char libsnes[PATH_MAX]; + char cheat_database[PATH_MAX]; + char cheat_settings_path[PATH_MAX]; - char screenshot_directory[MAXPATHLEN]; + char screenshot_directory[PATH_MAX]; bool rewind_enable; size_t rewind_buffer_size; @@ -195,29 +186,29 @@ struct global enum ssnes_game_type game_type; uint32_t cart_crc; - char gb_rom_path[MAXPATHLEN]; - char bsx_rom_path[MAXPATHLEN]; - char sufami_rom_path[2][MAXPATHLEN]; + char gb_rom_path[PATH_MAX]; + char bsx_rom_path[PATH_MAX]; + char sufami_rom_path[2][PATH_MAX]; bool has_set_save_path; bool has_set_state_path; #ifdef HAVE_CONFIGFILE - char config_path[MAXPATHLEN]; + char config_path[PATH_MAX]; #endif - char basename[MAXPATHLEN]; - char savefile_name_srm[MAXPATHLEN]; - char savefile_name_rtc[MAXPATHLEN]; // Make sure that fill_pathname has space. - char savefile_name_psrm[MAXPATHLEN]; - char savefile_name_asrm[MAXPATHLEN]; - char savefile_name_bsrm[MAXPATHLEN]; - char savestate_name[MAXPATHLEN]; - char xml_name[MAXPATHLEN]; + char basename[PATH_MAX]; + char savefile_name_srm[PATH_MAX]; + char savefile_name_rtc[PATH_MAX]; // Make sure that fill_pathname has space. + char savefile_name_psrm[PATH_MAX]; + char savefile_name_asrm[PATH_MAX]; + char savefile_name_bsrm[PATH_MAX]; + char savestate_name[PATH_MAX]; + char xml_name[PATH_MAX]; bool ups_pref; bool bps_pref; - char ups_name[MAXPATHLEN]; - char bps_name[MAXPATHLEN]; + char ups_name[PATH_MAX]; + char bps_name[PATH_MAX]; unsigned state_slot; @@ -225,7 +216,7 @@ struct global { struct snes_geometry geom; unsigned pitch; // If 0, has classic libsnes semantics. - char fullpath[MAXPATHLEN]; + char fullpath[PATH_MAX]; struct snes_system_timing timing; bool timing_set; bool need_fullpath; @@ -283,11 +274,11 @@ struct global struct { bsv_movie_t *movie; - char movie_path[MAXPATHLEN]; + char movie_path[PATH_MAX]; bool movie_playback; // Immediate playback/recording. - char movie_start_path[MAXPATHLEN]; + char movie_start_path[PATH_MAX]; bool movie_start_recording; bool movie_start_playback; bool movie_end; @@ -306,7 +297,7 @@ struct global // Netplay. #ifdef HAVE_NETPLAY netplay_t *netplay; - char netplay_server[MAXPATHLEN]; + char netplay_server[PATH_MAX]; bool netplay_enable; bool netplay_is_client; unsigned netplay_sync_frames; @@ -316,7 +307,7 @@ struct global // FFmpeg record. #ifdef HAVE_FFMPEG ffemu_t *rec; - char record_path[MAXPATHLEN]; + char record_path[PATH_MAX]; bool recording; unsigned record_width; unsigned record_height; @@ -400,6 +391,10 @@ static inline uint8_t is_little_endian(void) return u.y[0]; } +#ifdef GEKKO +#include +#endif + static inline void ssnes_sleep(unsigned msec) { #ifdef __CELLOS_LV2__ diff --git a/gfx/shader_cg.c b/gfx/shader_cg.c index 7cf501fecb..bc04ad52b4 100644 --- a/gfx/shader_cg.c +++ b/gfx/shader_cg.c @@ -690,7 +690,7 @@ static bool load_preset(const char *path) int shaders; // Basedir. - char dir_path[MAXPATHLEN]; + char dir_path[PATH_MAX]; char *ptr = NULL; SSNES_LOG("Loading Cg meta-shader: %s\n", path); @@ -874,7 +874,7 @@ static bool load_preset(const char *path) { char *shader_path; char attr_buf[64]; - char path_buf[MAXPATHLEN]; + char path_buf[PATH_MAX]; print_buf(attr_buf, "shader%u", i); if (config_get_string(conf, attr_buf, &shader_path)) diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index e110a89d82..a4a95ab650 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -122,7 +122,7 @@ static char gl_teximage_uniforms[MAX_TEXTURES][64]; static snes_tracker_t *gl_snes_tracker = NULL; static struct snes_tracker_uniform_info gl_tracker_info[MAX_VARIABLES]; static unsigned gl_tracker_info_cnt = 0; -static char gl_tracker_script[MAXPATHLEN]; +static char gl_tracker_script[PATH_MAX]; static char gl_tracker_script_class[64]; static xmlChar *gl_script_program = NULL; @@ -352,7 +352,7 @@ static bool get_texture_image(const char *shader_path, xmlNodePtr ptr) if (filter && strcmp((const char*)filter, "nearest") == 0) linear = false; - char tex_path[MAXPATHLEN]; + char tex_path[PATH_MAX]; strlcpy(tex_path, shader_path, sizeof(tex_path)); last = strrchr(tex_path, '/'); diff --git a/settings.c b/settings.c index b81932a2fd..600c783639 100644 --- a/settings.c +++ b/settings.c @@ -233,7 +233,7 @@ static config_file_t *open_default_config_file(void) const char *appdata = getenv("APPDATA"); if (appdata) { - char conf_path[MAXPATHLEN]; + char conf_path[PATH_MAX]; strlcpy(conf_path, appdata, sizeof(conf_path)); strlcat(conf_path, "/ssnes.cfg", sizeof(conf_path)); conf = config_file_new(conf_path); @@ -243,7 +243,7 @@ static config_file_t *open_default_config_file(void) const char *home = getenv("HOME"); if (home) { - char conf_path[MAXPATHLEN]; + char conf_path[PATH_MAX]; strlcpy(conf_path, home, sizeof(conf_path)); strlcat(conf_path, "/.ssnes.cfg", sizeof(conf_path)); conf = config_file_new(conf_path); @@ -260,14 +260,14 @@ static config_file_t *open_default_config_file(void) const char *home = getenv("HOME"); if (xdg) { - char conf_path[MAXPATHLEN]; + char conf_path[PATH_MAX]; strlcpy(conf_path, xdg, sizeof(conf_path)); strlcat(conf_path, "/ssnes/ssnes.cfg", sizeof(conf_path)); conf = config_file_new(conf_path); } else if (home) { - char conf_path[MAXPATHLEN]; + char conf_path[PATH_MAX]; strlcpy(conf_path, home, sizeof(conf_path)); strlcat(conf_path, "/.ssnes.cfg", sizeof(conf_path)); conf = config_file_new(conf_path); @@ -324,7 +324,7 @@ static void parse_config_file(void) int tmp_int; double tmp_double; bool tmp_bool; - char tmp_str[MAXPATHLEN]; + char tmp_str[PATH_MAX]; CONFIG_GET_DOUBLE(video.xscale, "video_xscale"); CONFIG_GET_DOUBLE(video.yscale, "video_yscale"); diff --git a/ssnes.c b/ssnes.c index ac8f11136d..952455b914 100644 --- a/ssnes.c +++ b/ssnes.c @@ -22,7 +22,6 @@ #include #include #include -#include #include "driver.h" #include "file.h" #include "general.h" @@ -1153,7 +1152,7 @@ static void init_movie(void) } else if (g_extern.bsv.movie_start_recording) { - char msg[MAXPATHLEN]; + char msg[PATH_MAX]; snprintf(msg, sizeof(msg), "Starting movie record to \"%s\"!", g_extern.bsv.movie_start_path); @@ -1297,7 +1296,7 @@ static void set_savestate_auto_index(void) if (!g_settings.savestate_auto_index) return; - char state_path[MAXPATHLEN]; + char state_path[PATH_MAX]; strlcpy(state_path, g_extern.savestate_name, sizeof(state_path)); char *split = strrchr(state_path, '/'); @@ -1408,7 +1407,7 @@ static void check_savestates(void) if (g_settings.savestate_auto_index) g_extern.state_slot++; - char save_path[MAXPATHLEN]; + char save_path[PATH_MAX]; if (g_extern.state_slot > 0) snprintf(save_path, sizeof(save_path), "%s%u", g_extern.savestate_name, g_extern.state_slot); @@ -1434,7 +1433,7 @@ static void check_savestates(void) bool should_loadstate = driver.input->key_pressed(driver.input_data, SSNES_LOAD_STATE_KEY); if (!should_savestate && should_loadstate && !old_should_loadstate) { - char load_path[MAXPATHLEN]; + char load_path[PATH_MAX]; if (g_extern.state_slot > 0) snprintf(load_path, sizeof(load_path), "%s%u", g_extern.savestate_name, g_extern.state_slot); @@ -1627,7 +1626,7 @@ static void check_movie_record(void) { g_settings.rewind_granularity = 1; - char path[MAXPATHLEN]; + char path[PATH_MAX]; if (g_extern.state_slot > 0) { snprintf(path, sizeof(path), "%s%u.bsv", @@ -1639,7 +1638,7 @@ static void check_movie_record(void) g_extern.bsv.movie_path); } - char msg[MAXPATHLEN]; + char msg[PATH_MAX]; snprintf(msg, sizeof(msg), "Starting movie record to \"%s\"!", path); g_extern.bsv.movie = bsv_movie_init(path, SSNES_MOVIE_RECORD);