]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - fs.c
gitignore: add gmqcc, gmqpak, qmcvm, testsuite, pak.
[xonotic/gmqcc.git] / fs.c
diff --git a/fs.c b/fs.c
index 8d73b1d0b8ae793aa8dfefad075c9013457298ec..501041febe01709a3b965ddb56db813c553bbe97 100644 (file)
--- a/fs.c
+++ b/fs.c
  * to adding support for some other larger IO tasks (in the test-suite,
  * or even the QCVM we'll need it). There is also a third possibility of
  * building .dat files directly from zip files (which would be very cool
- * at least I think so).  
+ * at least I think so).
  */
 #ifdef _MSC_VER
+#include <crtdbg.h> /* _CrtSetReportMode, _CRT_ASSERT */
 /* {{{ */
     /*
      * Visual Studio has security CRT features which I actually want to support
      * if we ever port to Windows 8, and want GMQCC to be API safe.
      *
-     * We handle them here, for all file-operations. 
+     * We handle them here, for all file-operations.
      */
 
     static void file_exception (
@@ -53,7 +54,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() {
 
 /*
  * These are implemented as just generic wrappers to keep consistency in
- * the API.  Not as macros though  
+ * the API.  Not as macros though
  */
 void fs_file_close(FILE *fp) {
     /* Invokes file_exception on windows if fp is null */
@@ -165,16 +166,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);
@@ -231,17 +222,17 @@ 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) && !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);
+        util_strncpy(dir->dd_name, name, strlen(name));
         return dir;
     }
-        
+
     int fs_dir_close(DIR *dir) {
         FindClose((HANDLE)dir->dd_handle);
         mem_d ((void*)dir);
@@ -258,8 +249,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 */
+                    util_strncpy(dirname, dir->dd_name, n);
+                    util_strncpy(dirname + n, "\\*.*", 4);   /* 4 + 1 */
                 }
             } else {
                 if (!(dirname = util_strdup("\\*.*")))
@@ -277,9 +268,9 @@ int fs_file_getline(char **lineptr, size_t *n, FILE *stream) {
 
         if (!rets)
             return NULL;
-        
+
         if ((data = (struct dirent*)mem_a(sizeof(struct dirent)))) {
-            strncpy(data->d_name, info.cFileName, FILENAME_MAX - 1);
+            util_strncpy(data->d_name, info.cFileName, FILENAME_MAX - 1);
             data->d_name[FILENAME_MAX - 1] = '\0'; /* terminate */
             data->d_namlen                 = strlen(data->d_name);
         }
@@ -293,17 +284,9 @@ int fs_file_getline(char **lineptr, size_t *n, FILE *stream) {
     int fs_dir_make(const char *path) {
         return !CreateDirectory(path, NULL);
     }
-
-    /*
-     * Visual studio also lacks S_ISDIR for sys/stat.h, so we emulate this as well
-     * which is not hard at all.
-     */
-#   undef  S_ISDIR
-#   define S_ISDIR(X) ((X)&_S_IFDIR)
 #else
 #   if !defined(__MINGW32__)
 #       include <sys/stat.h> /* mkdir */
-#       include <unistd.h>   /* chdir */
 
         int fs_dir_make(const char *path) {
             return mkdir(path, 0700);
@@ -326,8 +309,4 @@ struct dirent *fs_dir_read(DIR *dir) {
     return readdir(dir);
 }
 
-int fs_dir_change(const char *path) {
-    return chdir(path);
-}
-
 #endif /*! defined(_WIN32) && !defined(__MINGW32__) */