X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=file.c;h=0c6177f84d57eb65fbf35cac804beda0eeb5e2c0;hp=ee14299b6df62773a055330d11b2f4fa8cb7b0b9;hb=d887174053073d15b027fd5e25a14dd0d4df063a;hpb=af711b4e66c96c112086a442ea09094643bd8d71 diff --git a/file.c b/file.c index ee14299..0c6177f 100644 --- a/file.c +++ b/file.c @@ -19,7 +19,9 @@ #include #include #include -#include +#ifndef WIN32 +# include +#endif #include #include @@ -43,7 +45,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,7 +56,29 @@ add_data_path(char *filename) return add_path(g_data_dir, filename); } -int +#ifdef WIN32 + +bool +is_dir(char *dirname) +{ + WIN32_FILE_ATTRIBUTE_DATA buf; + if(!GetFileAttributesEx(dirname, GetFileExInfoStandard, &buf)) + return false; + return buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; +} + +bool +is_file(char *filename) +{ + WIN32_FILE_ATTRIBUTE_DATA buf; + if(!GetFileAttributesEx(filename, GetFileExInfoStandard, &buf)) + return false; + return buf.dwFileAttributes & FILE_ATTRIBUTE_NORMAL; +} + +#else /* !WIN32 */ + +bool is_dir(char *dirname) { struct stat buf; @@ -62,7 +86,7 @@ is_dir(char *dirname) return S_ISDIR(buf.st_mode); } -int +bool is_file(char *filename) { struct stat buf; @@ -70,13 +94,15 @@ is_file(char *filename) return S_ISREG(buf.st_mode); } -int +#endif /* !WIN32 */ + +bool find_data_dir(void) { int i; char *data_options[3] = { - "./data", getenv("VOR_DATA"), + "data", DATA_PREFIX }; @@ -93,7 +119,7 @@ find_data_dir(void) return false; } -int +bool find_score_file(void) { char *dir, *s; @@ -106,17 +132,14 @@ find_score_file(void) if(s) { g_score_file = s; g_score_mask = 0177; - return is_file(s); + return true; } else return false; } -int +bool find_files(void) { - int r; - r = find_data_dir(); - find_score_file(); - return r; + return find_data_dir() && find_score_file(); } FILE *