JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
finish moving data files around (I think)
[vor.git] / file.c
diff --git a/file.c b/file.c
index ee14299..1e02c8e 100644 (file)
--- a/file.c
+++ b/file.c
@@ -19,7 +19,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/stat.h>
+#ifndef WIN32
+# include <sys/stat.h>
+#endif
 #include <sys/types.h>
 #include <unistd.h>
 
 
 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);
 }