#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;
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;
}
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
};
return false;
}
-int
+static bool
find_score_file(void)
{
char *dir, *s;
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);
}