]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - quakeio.c
changed a debugging notice about texture loading
[xonotic/darkplaces.git] / quakeio.c
index 6e475ccb938fc46ce32f4d4769b276df8607dc54..d3dd6cfda4abe57c647011d94f5e2acf369e1fca 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)
 {
@@ -118,7 +116,7 @@ Qopen (const char *path, const char *mode)
        Qexpand_squiggle (path, e_path);
        path = e_path;
 
-       for (p = m; *mode && p - m < (sizeof (m) - 1); mode++) {
+       for (p = m; *mode && p - m < (int)(sizeof (m) - 1); mode++) {
                if (*mode == 'z') {
                        zip = 1;
                        continue;
@@ -132,14 +130,15 @@ Qopen (const char *path, const char *mode)
        }
        *p = 0;
 
-       file = calloc (sizeof (*file), 1);
+       file = Mem_Alloc(quakeio_mempool, sizeof (*file));
+       memset(file, 0, sizeof(*file));
        if (!file)
                return 0;
 #ifdef HAVE_ZLIB
        if (zip) {
                file->gzfile = gzopen (path, m);
                if (!file->gzfile) {
-                       free (file);
+                       Mem_Free(file);
                        return 0;
                }
        } else
@@ -147,7 +146,7 @@ Qopen (const char *path, const char *mode)
        {
                file->file = fopen (path, m);
                if (!file->file) {
-                       free (file);
+                       Mem_Free(file);
                        return 0;
                }
        }
@@ -161,7 +160,7 @@ Qdopen (int fd, const char *mode)
        char        m[80], *p;
        int         zip = 0;
 
-       for (p = m; *mode && p - m < (sizeof (m) - 1); mode++) {
+       for (p = m; *mode && p - m < (int)(sizeof (m) - 1); mode++) {
                if (*mode == 'z') {
                        zip = 1;
                        continue;
@@ -171,14 +170,15 @@ Qdopen (int fd, const char *mode)
 
        *p = 0;
 
-       file = calloc (sizeof (*file), 1);
+       file = Mem_Alloc(quakeio_mempool, sizeof (*file));
+       memset(file, 0, sizeof(*file));
        if (!file)
                return 0;
 #ifdef HAVE_ZLIB
        if (zip) {
                file->gzfile = gzdopen (fd, m);
                if (!file->gzfile) {
-                       free (file);
+                       Mem_Free(file);
                        return 0;
                }
        } else
@@ -186,7 +186,7 @@ Qdopen (int fd, const char *mode)
        {
                file->file = fdopen (fd, m);
                if (!file->file) {
-                       free (file);
+                       Mem_Free(file);
                        return 0;
                }
        }
@@ -206,7 +206,7 @@ Qclose (QFile *file)
        else
                gzclose (file->gzfile);
 #endif
-       free (file);
+       Mem_Free(file);
 }
 
 int
@@ -368,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);
@@ -392,3 +393,9 @@ Qgetline (QFile *file)
                buf[len - 1] = 0;
        return buf;
 }
+
+void QuakeIO_Init(void)
+{
+       quakeio_mempool = Mem_AllocPool("file management");
+}
+