]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - quakeio.c
fix for 'falling' in a corner bug, thanks to Elric for finding the fix for this.
[xonotic/darkplaces.git] / quakeio.c
index 2610e45026209c40b091c45ad8ea8601197edcd4..65535f9352b0c4949066d99b578393219439a13a 100644 (file)
--- a/quakeio.c
+++ b/quakeio.c
 # include <unistd.h>
 #endif
 
-//#ifdef _MSC_VER
-//# define _POSIX_
-//#endif
-
 #include <stdarg.h>
 #include <stdlib.h>
 #include <limits.h>
@@ -60,6 +56,8 @@
 # endif
 #endif
 
+mempool_t *quakeio_mempool;
+
 void
 Qexpand_squiggle (const char *path, char *dest)
 {
@@ -132,7 +130,7 @@ Qopen (const char *path, const char *mode)
        }
        *p = 0;
 
-       file = qmalloc (sizeof (*file));
+       file = Mem_Alloc(quakeio_mempool, sizeof (*file));
        memset(file, 0, sizeof(*file));
        if (!file)
                return 0;
@@ -140,7 +138,7 @@ Qopen (const char *path, const char *mode)
        if (zip) {
                file->gzfile = gzopen (path, m);
                if (!file->gzfile) {
-                       qfree (file);
+                       Mem_Free(file);
                        return 0;
                }
        } else
@@ -148,7 +146,7 @@ Qopen (const char *path, const char *mode)
        {
                file->file = fopen (path, m);
                if (!file->file) {
-                       qfree (file);
+                       Mem_Free(file);
                        return 0;
                }
        }
@@ -172,7 +170,7 @@ Qdopen (int fd, const char *mode)
 
        *p = 0;
 
-       file = qmalloc (sizeof (*file));
+       file = Mem_Alloc(quakeio_mempool, sizeof (*file));
        memset(file, 0, sizeof(*file));
        if (!file)
                return 0;
@@ -180,7 +178,7 @@ Qdopen (int fd, const char *mode)
        if (zip) {
                file->gzfile = gzdopen (fd, m);
                if (!file->gzfile) {
-                       qfree (file);
+                       Mem_Free(file);
                        return 0;
                }
        } else
@@ -188,7 +186,7 @@ Qdopen (int fd, const char *mode)
        {
                file->file = fdopen (fd, m);
                if (!file->file) {
-                       qfree (file);
+                       Mem_Free(file);
                        return 0;
                }
        }
@@ -208,7 +206,7 @@ Qclose (QFile *file)
        else
                gzclose (file->gzfile);
 #endif
-       qfree (file);
+       Mem_Free(file);
 }
 
 int
@@ -370,22 +368,23 @@ Qgetline (QFile *file)
 {
        static int  size = 256;
        static char *buf = 0;
+       char        *t;
        int         len;
 
        if (!buf)
-               buf = malloc (size);
+               buf = Mem_Alloc(quakeio_mempool, size);
 
        if (!Qgets (file, buf, size))
                return 0;
 
        len = strlen (buf);
-       while (buf[len - 1] != '\n' && buf[len - 1] != '\r') {
-               char       *t = realloc (buf, size + 256);
-
-               if (!t)
-                       Host_Error("Qgetline: realloc failed, out of memory?\n");
-               buf = t;
+       while (buf[len - 1] != '\n' && buf[len - 1] != '\r')
+       {
+               t = Mem_Alloc(quakeio_mempool, size + 256);
+               memcpy(t, buf, size);
+               Mem_Free(buf);
                size += 256;
+               buf = t;
                if (!Qgets (file, buf + len, size - len))
                        break;
                len = strlen (buf);
@@ -394,3 +393,9 @@ Qgetline (QFile *file)
                buf[len - 1] = 0;
        return buf;
 }
+
+void QuakeIO_Init(void)
+{
+       quakeio_mempool = Mem_AllocPool("file management");
+}
+