X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=file.c;h=4b7872a4050d8f38f51e6b83345ac70791358333;hp=ee14299b6df62773a055330d11b2f4fa8cb7b0b9;hb=0bbc23a37289ca20b8681229ccf74edfb6261d4e;hpb=cd7fb220b16a73c15ff9dff7a5627bf78478875f diff --git a/file.c b/file.c index ee14299..4b7872a 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; @@ -110,13 +136,10 @@ find_score_file(void) } 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 *