X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=quakeio.c;h=65535f9352b0c4949066d99b578393219439a13a;hb=a0db60e28809c5d2e8898c61a765f3fc9dadca5d;hp=2610e45026209c40b091c45ad8ea8601197edcd4;hpb=0cfc51ea6f050adc04e2324db38175bf454e3c1b;p=xonotic%2Fdarkplaces.git diff --git a/quakeio.c b/quakeio.c index 2610e450..65535f93 100644 --- a/quakeio.c +++ b/quakeio.c @@ -39,10 +39,6 @@ # include #endif -//#ifdef _MSC_VER -//# define _POSIX_ -//#endif - #include #include #include @@ -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"); +} +