X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=file.c;h=1e02c8eace6d47dad5c96f5d0e0bffd281f534d8;hp=ee14299b6df62773a055330d11b2f4fa8cb7b0b9;hb=f68d2bb77d8b4d94af72b6cbe870d423ed82b17f;hpb=af711b4e66c96c112086a442ea09094643bd8d71 diff --git a/file.c b/file.c index ee14299..1e02c8e 100644 --- a/file.c +++ b/file.c @@ -19,7 +19,9 @@ #include #include #include -#include +#ifndef WIN32 +# include +#endif #include #include @@ -29,12 +31,11 @@ char *g_data_dir; char *g_score_file; -mode_t g_score_mask; -char * +static char * add_path(char *path, char *file) { - char *s; + char *r, *s; size_t plen, flen; if(!path || !file) return NULL; @@ -43,7 +44,7 @@ add_path(char *path, char *file) s = malloc(2+plen+flen); if(!s) return NULL; memcpy(s, path, plen); - s[plen] = '/'; + s[plen] = PATH_SEPARATOR; memcpy(s+plen+1, file, flen+1); return s; } @@ -54,29 +55,39 @@ add_data_path(char *filename) return add_path(g_data_dir, filename); } -int -is_dir(char *dirname) +#ifdef WIN32 + +static bool +find_data_dir(void) { - struct stat buf; - stat(dirname, &buf); - return S_ISDIR(buf.st_mode); + g_data_dir = "."; + return true; +} + +static bool +find_score_file(void) +{ + g_score_file = "scores"; + return true; } -int -is_file(char *filename) +#else /* !WIN32 */ + +static bool +is_dir(char *dirname) { struct stat buf; - stat(filename, &buf); - return S_ISREG(buf.st_mode); + stat(dirname, &buf); + return S_ISDIR(buf.st_mode); } -int +static bool find_data_dir(void) { int i; char *data_options[3] = { - "./data", getenv("VOR_DATA"), + "data", DATA_PREFIX }; @@ -93,7 +104,7 @@ find_data_dir(void) return false; } -int +static bool find_score_file(void) { char *dir, *s; @@ -105,30 +116,21 @@ find_score_file(void) s = add_path(dir, ".vor-scores"); if(s) { g_score_file = s; - g_score_mask = 0177; - return is_file(s); + return true; } else return false; } -int +#endif /* !WIN32 */ + +bool find_files(void) { - int r; - r = find_data_dir(); - find_score_file(); - return r; + return find_data_dir() && find_score_file(); } FILE * open_score_file(char *mode) { - mode_t old_mask; - FILE *f; - if(!g_score_file) return NULL; - - old_mask = umask(g_score_mask); - f = fopen(g_score_file, mode); - umask(old_mask); - return f; + return fopen(g_score_file, mode); }