mirror of
https://git.code.sf.net/p/quake/newtree
synced 2025-05-30 08:40:39 +00:00
Before I can fix the (MANY!) problems with newtree, I have to fix the
little problem of mixed QFile and FILE. Since we're not using ZLib in this tree, QFile makes no real sense. That didn't fix the real problem I am having though.
This commit is contained in:
parent
08b551f7ae
commit
3d59dfed98
24 changed files with 127 additions and 280 deletions
221
source/quakeio.c
221
source/quakeio.c
|
@ -32,24 +32,24 @@
|
|||
# include <config.h>
|
||||
#endif
|
||||
#ifdef HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
# include <malloc.h>
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <quakeio.h>
|
||||
#include <string.h>
|
||||
#ifdef WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
# include <io.h>
|
||||
# include <fcntl.h>
|
||||
#else
|
||||
#include <pwd.h>
|
||||
# include <pwd.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define _POSIX_
|
||||
# define _POSIX_
|
||||
#endif
|
||||
#include <limits.h>
|
||||
|
||||
|
@ -91,247 +91,104 @@ Qrename(const char *old, const char *new)
|
|||
return rename (e_old, e_new);
|
||||
}
|
||||
|
||||
QFile *
|
||||
FILE *
|
||||
Qopen(const char *path, const char *mode)
|
||||
{
|
||||
QFile *file;
|
||||
char m[80],*p;
|
||||
int zip=0;
|
||||
FILE *file;
|
||||
char e_path[PATH_MAX];
|
||||
|
||||
Qexpand_squiggle (path, e_path);
|
||||
path = e_path;
|
||||
|
||||
for (p=m; *mode && p-m<(sizeof(m)-1); mode++) {
|
||||
if (*mode=='z') {
|
||||
zip=1;
|
||||
continue;
|
||||
}
|
||||
*p++=*mode;
|
||||
}
|
||||
*p=0;
|
||||
|
||||
file=calloc(sizeof(*file),1);
|
||||
if (!file)
|
||||
return 0;
|
||||
#ifdef HAS_ZLIB
|
||||
if (zip) {
|
||||
file->gzfile=gzopen(path,m);
|
||||
if (!file->gzfile) {
|
||||
free(file);
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
file->file=fopen(path,m);
|
||||
if (!file->file) {
|
||||
free(file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
file=fopen(path,mode);
|
||||
return file;
|
||||
}
|
||||
|
||||
QFile *
|
||||
FILE *
|
||||
Qdopen(int fd, const char *mode)
|
||||
{
|
||||
QFile *file;
|
||||
char m[80],*p;
|
||||
int zip=0;
|
||||
FILE *file;
|
||||
|
||||
for (p=m; *mode && p-m<(sizeof(m)-1); mode++) {
|
||||
if (*mode=='z') {
|
||||
zip=1;
|
||||
continue;
|
||||
}
|
||||
*p++=*mode;
|
||||
}
|
||||
|
||||
*p=0;
|
||||
|
||||
file=calloc(sizeof(*file),1);
|
||||
if (!file)
|
||||
return 0;
|
||||
#ifdef HAS_ZLIB
|
||||
if (zip) {
|
||||
file->gzfile=gzdopen(fd,m);
|
||||
if (!file->gzfile) {
|
||||
free(file);
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
file->file=fdopen(fd,m);
|
||||
if (!file->file) {
|
||||
free(file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
file=fdopen(fd,mode);
|
||||
#ifdef WIN32
|
||||
#ifdef __BORLANDC__
|
||||
setmode(_fileno(file->file),O_BINARY);
|
||||
#else
|
||||
_setmode(_fileno(file->file),_O_BINARY);
|
||||
#endif
|
||||
# ifdef __BORLANDC__
|
||||
setmode(_fileno(file),O_BINARY);
|
||||
# else
|
||||
_setmode(_fileno(file),_O_BINARY);
|
||||
# endif
|
||||
#endif
|
||||
return file;
|
||||
}
|
||||
|
||||
void
|
||||
Qclose(QFile *file)
|
||||
Qclose(FILE *file)
|
||||
{
|
||||
if (file->file)
|
||||
fclose(file->file);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
gzclose(file->gzfile);
|
||||
#endif
|
||||
fclose(file);
|
||||
free(file);
|
||||
}
|
||||
|
||||
int
|
||||
Qread(QFile *file, void *buf, int count)
|
||||
Qread(FILE *file, void *buf, int count)
|
||||
{
|
||||
if (file->file)
|
||||
return fread(buf, 1, count, file->file);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
return gzread(file->gzfile,buf,count);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return fread(buf, 1, count, file);
|
||||
}
|
||||
|
||||
int
|
||||
Qwrite(QFile *file, void *buf, int count)
|
||||
Qwrite(FILE *file, void *buf, int count)
|
||||
{
|
||||
if (file->file)
|
||||
return fwrite(buf, 1, count, file->file);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
return gzwrite(file->gzfile,buf,count);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return fwrite(buf, 1, count, file);
|
||||
}
|
||||
|
||||
int
|
||||
Qprintf(QFile *file, const char *fmt, ...)
|
||||
Qprintf(FILE *file, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int ret=-1;
|
||||
|
||||
va_start(args,fmt);
|
||||
if (file->file)
|
||||
ret=vfprintf(file->file, fmt, args);
|
||||
#ifdef HAS_ZLIB
|
||||
else {
|
||||
char buf[4096];
|
||||
va_start(args, fmt);
|
||||
#ifdef HAVE_VSNPRINTF
|
||||
(void)vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
#else
|
||||
(void)vsprintf(buf, fmt, args);
|
||||
#endif
|
||||
va_end(args);
|
||||
ret = strlen(buf); /* some *sprintf don't return the nb of bytes written */
|
||||
if (ret>0)
|
||||
ret=gzwrite(file, buf, (unsigned)ret);
|
||||
}
|
||||
#endif
|
||||
ret=vfprintf(file, fmt, args);
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
Qgets(QFile *file, char *buf, int count)
|
||||
Qgets(FILE *file, char *buf, int count)
|
||||
{
|
||||
if (file->file)
|
||||
return fgets(buf, count, file->file);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
return gzgets(file->gzfile,buf,count);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
return fgets(buf, count, file);
|
||||
}
|
||||
|
||||
int
|
||||
Qgetc(QFile *file)
|
||||
Qgetc(FILE *file)
|
||||
{
|
||||
if (file->file)
|
||||
return fgetc(file->file);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
return gzgetc(file->gzfile);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return fgetc(file);
|
||||
}
|
||||
|
||||
int
|
||||
Qputc(QFile *file, int c)
|
||||
Qputc(FILE *file, int c)
|
||||
{
|
||||
if (file->file)
|
||||
return fputc(c, file->file);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
return gzputc(file->gzfile,c);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return fputc(c, file);
|
||||
}
|
||||
|
||||
int
|
||||
Qseek(QFile *file, long offset, int whence)
|
||||
Qseek(FILE *file, long offset, int whence)
|
||||
{
|
||||
if (file->file)
|
||||
return fseek(file->file, offset, whence);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
return gzseek(file->gzfile,offset,whence);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return fseek(file, offset, whence);
|
||||
}
|
||||
|
||||
long
|
||||
Qtell(QFile *file)
|
||||
Qtell(FILE *file)
|
||||
{
|
||||
if (file->file)
|
||||
return ftell(file->file);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
return gztell(file->gzfile);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return ftell(file);
|
||||
}
|
||||
|
||||
int
|
||||
Qflush(QFile *file)
|
||||
Qflush(FILE *file)
|
||||
{
|
||||
if (file->file)
|
||||
return fflush(file->file);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
return gzflush(file->gzfile,Z_SYNC_FLUSH);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return fflush(file);
|
||||
}
|
||||
|
||||
int
|
||||
Qeof(QFile *file)
|
||||
Qeof(FILE *file)
|
||||
{
|
||||
if (file->file)
|
||||
return feof(file->file);
|
||||
#ifdef HAS_ZLIB
|
||||
else
|
||||
return gzeof(file->gzfile);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
return feof(file);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue