make independent of zlib (ie use HAS_ZLIB)

This commit is contained in:
Bill Currie 2000-02-09 09:12:55 +00:00
parent 688d7d470a
commit 16e636cc01
2 changed files with 51 additions and 3 deletions

View file

@ -20,13 +20,16 @@ QFile *Qopen(const char *path, const char *mode)
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 {
} else
#endif
{
file->file=fopen(path,m);
if (!file->file) {
free(file);
@ -54,13 +57,16 @@ QFile *Qdopen(int fd, const char *mode)
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 {
} else
#endif
{
file->file=fdopen(fd,m);
if (!file->file) {
free(file);
@ -74,8 +80,10 @@ void Qclose(QFile *file)
{
if (file->file)
fclose(file->file);
#ifdef HAS_ZLIB
else
gzclose(file->gzfile);
#endif
free(file);
}
@ -83,26 +91,35 @@ int Qread(QFile *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
}
int Qwrite(QFile *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
}
int Qprintf(QFile *file, const char *fmt, ...)
{
va_list args;
int ret;
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);
@ -116,6 +133,7 @@ int Qprintf(QFile *file, const char *fmt, ...)
if (ret>0)
ret=gzwrite(file, buf, (unsigned)ret);
}
#endif
va_end(args);
return ret;
}
@ -124,54 +142,82 @@ char *Qgets(QFile *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
}
int Qgetc(QFile *file)
{
if (file->file)
return fgetc(file->file);
#ifdef HAS_ZLIB
else
return gzgetc(file->gzfile);
#else
return -1;
#endif
}
int Qputc(QFile *file, int c)
{
if (file->file)
return fputc(c, file->file);
#ifdef HAS_ZLIB
else
return gzputc(file->gzfile,c);
#else
return -1;
#endif
}
int Qseek(QFile *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
}
long Qtell(QFile *file)
{
if (file->file)
return ftell(file->file);
#ifdef HAS_ZLIB
else
return gztell(file->gzfile);
#else
return -1;
#endif
}
int Qflush(QFile *file)
{
if (file->file)
return fflush(file->file);
#ifdef HAS_ZLIB
else
return gzflush(file->gzfile,Z_SYNC_FLUSH);
#else
return -1;
#endif
}
int Qeof(QFile *file)
{
if (file->file)
return feof(file->file);
#ifdef HAS_ZLIB
else
return gzeof(file->gzfile);
#else
return -1;
#endif
}

View file

@ -10,7 +10,9 @@
typedef struct {
FILE *file;
#ifdef HAS_ZLIB
gzFile *gzfile;
#endif
} QFile;
QFile *Qopen(const char *path, const char *mode);