$Id$
*/
+#include "quakedef.h"
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
# include <unistd.h>
#endif
-#define HAVE_ZLIB
-
-#ifdef _MSC_VER
-# define _POSIX_
-#endif
-
#include <stdarg.h>
#include <stdlib.h>
#include <limits.h>
-#include "QF/quakefs.h"
-#include "QF/quakeio.h"
+#ifndef PATH_MAX
+# define PATH_MAX 512
+#endif
+
+#include "quakeio.h"
#ifdef WIN32
# ifndef __BORLANDC__
# endif
#endif
+mempool_t *quakeio_mempool;
+
void
Qexpand_squiggle (const char *path, char *dest)
{
}
*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
{
file->file = fopen (path, m);
if (!file->file) {
- free (file);
+ Mem_Free(file);
return 0;
}
}
*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
{
file->file = fdopen (fd, m);
if (!file->file) {
- free (file);
+ Mem_Free(file);
return 0;
}
}
else
gzclose (file->gzfile);
#endif
- free (file);
+ Mem_Free(file);
}
int
{
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') {
- char *t = realloc (buf, size + 256);
-
- if (!t)
- return 0;
- 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);
}
+ while ((len = strlen(buf)) && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
+ buf[len - 1] = 0;
return buf;
}
-int
-Qgetpos (QFile *file, fpos_t * pos)
+void QuakeIO_Init(void)
{
-#ifdef HAVE_FPOS_T_STRUCT
- pos->__pos = Qtell (file);
- return pos->__pos == -1 ? -1 : 0;
-#else
- *pos = Qtell (file);
- return *pos == -1 ? -1 : 0;
-#endif
+ quakeio_mempool = Mem_AllocPool("file management");
}
-int
-Qsetpos (QFile *file, fpos_t * pos)
-{
-#ifdef HAVE_FPOS_T_STRUCT
- return Qseek (file, pos->__pos, 0);
-#else
- return Qseek (file, *pos, 0);
-#endif
-}