]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - fs.c
Fixes
[xonotic/gmqcc.git] / fs.c
diff --git a/fs.c b/fs.c
index eb1a57209d97bbd05b4c90bc75338ca2ae670f9f..997b368b13ce6bf801ff5637b9689ae464e853b0 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -53,7 +53,7 @@
     ) {
         wprintf(L"Invalid parameter dectected %s:%d %s [%s]\n", file, line, function, expression);
         wprintf(L"Aborting ...\n");
-        abort();
+        exit(EXIT_FAILURE);
     }
 
     static void file_init() {
@@ -165,16 +165,6 @@ int fs_file_seek(FILE *fp, long int off, int whence) {
     return fseek(fp, off, whence);
 }
 
-int fs_file_putc(FILE *fp, int ch) {
-    /* Invokes file_exception on windows if fp is null */
-    return fputc(ch, fp);
-}
-
-int fs_file_flush(FILE *fp) {
-    /* Invokes file_exception on windows if fp is null */
-    return fflush(fp);
-}
-
 long int fs_file_tell(FILE *fp) {
     /* Invokes file_exception on windows if fp is null */
     return ftell(fp);
@@ -232,13 +222,13 @@ int fs_file_getline(char **lineptr, size_t *n, FILE *stream) {
  * Now we implement some directory functionality.  Windows lacks dirent.h
  * this is such a pisss off, we implement it here.
  */  
-#if defined(_WIN32)
+#if defined(_WIN32) && !defined(__MINGW32__)
     DIR *fs_dir_open(const char *name) {
         DIR *dir = (DIR*)mem_a(sizeof(DIR) + strlen(name));
         if (!dir)
             return NULL;
 
-        strcpy(dir->dd_name, name);
+        strncpy(dir->dd_name, name, strlen(name));
         return dir;
     }
         
@@ -258,8 +248,8 @@ int fs_file_getline(char **lineptr, size_t *n, FILE *stream) {
             if (*dir->dd_name) {
                 size_t n = strlen(dir->dd_name);
                 if ((dirname  = (char*)mem_a(n + 5) /* 4 + 1 */)) {
-                    strcpy(dirname,     dir->dd_name);
-                    strcpy(dirname + n, "\\*.*");   /* 4 + 1 */
+                    strncpy(dirname, dir->dd_name, n);
+                    strncpy(dirname + n, "\\*.*", 4);   /* 4 + 1 */
                 }
             } else {
                 if (!(dirname = util_strdup("\\*.*")))
@@ -301,26 +291,28 @@ int fs_file_getline(char **lineptr, size_t *n, FILE *stream) {
 #   undef  S_ISDIR
 #   define S_ISDIR(X) ((X)&_S_IFDIR)
 #else
-    #include <sys/stat.h> /* mkdir */
-    #include <unistd.h>   /* chdir */
+#   if !defined(__MINGW32__)
+#       include <sys/stat.h> /* mkdir */
 
-    DIR *fs_dir_open(const char *name) {
-        return opendir(name);
-    }
+        int fs_dir_make(const char *path) {
+            return mkdir(path, 0700);
+        }
+#   else
+        int fs_dir_make(const char *path) {
+            return mkdir(path);
+        }
+#   endif /*! !defined(__MINGW32__) */
 
-    int fs_dir_close(DIR *dir) {
-        return closedir(dir);
-    }
+DIR *fs_dir_open(const char *name) {
+    return opendir(name);
+}
 
-    struct dirent *fs_dir_read(DIR *dir) {
-        return readdir(dir);
-    }
+int fs_dir_close(DIR *dir) {
+    return closedir(dir);
+}
 
-    int fs_dir_change(const char *path) {
-        return chdir(path);
-    }
+struct dirent *fs_dir_read(DIR *dir) {
+    return readdir(dir);
+}
 
-    int fs_dir_make(const char *path) {
-        return mkdir(path, 0700);
-    }
-#endif /*! defined (_WIN32) */
+#endif /*! defined(_WIN32) && !defined(__MINGW32__) */