X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=share%2Fbase_config.c;h=6df2faea4aac9c45801c9f79621d1f0fd37a10be;hb=5591d1ae2e911ce8264f7a7a45cbae0bedab821d;hp=5124339db42ab81c5bfdcdf27ec838c10bd80f01;hpb=84e0f09b31243dcd6d5402e9b8ec303e804e4a60;p=neverball diff --git a/share/base_config.c b/share/base_config.c index 5124339..6df2fae 100644 --- a/share/base_config.c +++ b/share/base_config.c @@ -12,8 +12,6 @@ * General Public License for more details. */ -#include -#include #include #include #include @@ -47,11 +45,11 @@ static const char *config_file(const char *path, const char *file) { static char absolute[MAXSTR]; - size_t d = strlen(path); + size_t d = path ? strlen(path) : 0; - strncpy(absolute, path, MAXSTR - 1); + strncpy(absolute, path ? path : "", MAXSTR - 1); strncat(absolute, "/", MAXSTR - d - 1); - strncat(absolute, file, MAXSTR - d - 2); + strncat(absolute, file ? file : "", MAXSTR - d - 2); return absolute; } @@ -86,8 +84,8 @@ const char *config_user(const char *file) /* * Attempt to find the game data directory. Search the command line - * paramater, the environment, and the hard-coded default, in that - * order. Confirm it by checking for presense of the named file. + * parameter, the environment, and the hard-coded default, in that + * order. Confirm it by checking for presence of the named file. */ int config_data_path(const char *path, const char *file) { @@ -105,7 +103,7 @@ int config_data_path(const char *path, const char *file) return 1; } - if (CONFIG_DATA && config_test(CONFIG_DATA, file)) + if (config_test(CONFIG_DATA, file)) { strncpy(data_path, CONFIG_DATA, MAXSTR); return 1; @@ -119,20 +117,25 @@ int config_data_path(const char *path, const char *file) * is a directory there for storing configuration, high scores, and * replays. * - * HACK: under Windows just assume the user has permission to write to - * the data directory. This is more reliable than trying to devine - * anything reasonable from the environment. + * Under Windows check the APPDATA environment variable and if that's + * not set, just assume the user has permission to write to the data + * directory. */ int config_user_path(const char *file) { #ifdef _WIN32 - size_t d = strlen(CONFIG_USER); + char *dir; - strncpy(user_path, data_path, MAXSTR - 1); - strncat(user_path, "\\", MAXSTR - d - 1); - strncat(user_path, CONFIG_USER, MAXSTR - d - 2); + if ((dir = getenv("APPDATA")) || (dir = data_path)) + { + size_t d = strlen(dir); + + strncpy(user_path, dir, MAXSTR - 1); + strncat(user_path, "\\", MAXSTR - d - 1); + strncat(user_path, CONFIG_USER, MAXSTR - d - 2); + } - if ((mkdir(user_path) == 0) || (errno = EEXIST)) + if ((mkdir(user_path) == 0) || (errno == EEXIST)) if (config_test(user_path, file)) return 1; #else @@ -142,12 +145,12 @@ int config_user_path(const char *file) { size_t d = strlen(dir); - strncpy(user_path, getenv("HOME"), MAXSTR - 1); - strncat(user_path, "/", MAXSTR - d - 1); - strncat(user_path, CONFIG_USER, MAXSTR - d - 2); + strncpy(user_path, dir, MAXSTR - 1); + strncat(user_path, "/", MAXSTR - d - 1); + strncat(user_path, CONFIG_USER, MAXSTR - d - 2); } - if ((mkdir(user_path, 0777) == 0) || (errno = EEXIST)) + if ((mkdir(user_path, 0777) == 0) || (errno == EEXIST)) if (config_test(user_path, file)) return 1; #endif