From 979d8857760fb2e9440d03dfdb24221ca66315e5 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 27 Sep 2002 05:46:30 +0000 Subject: [PATCH] get Qseek working properly (d'oh) and Qtell (forgot it needed adjusting) --- libs/util/quakeio.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/libs/util/quakeio.c b/libs/util/quakeio.c index 21a1b0a35..3a611e380 100644 --- a/libs/util/quakeio.c +++ b/libs/util/quakeio.c @@ -59,6 +59,7 @@ static const char rcsid[] = #include #include #include +#include #include "QF/dstring.h" #include "QF/qendian.h" @@ -408,11 +409,30 @@ int Qseek (QFile *file, long offset, int whence) { if (file->file) { - return fseek (file->file, file->start + offset, whence); + int res; + switch (whence) { + case SEEK_SET: + res = fseek (file->file, file->start + offset, whence); + break; + case SEEK_CUR: + res = fseek (file->file, offset, whence); + break; + case SEEK_END: + res = fseek (file->file, + file->start + file->size - offset, SEEK_SET); + break; + default: + errno = EINVAL; + return -1; + } + if (res != -1) + res = ftell (file->file) - file->start; + return res; } #ifdef HAVE_ZLIB else { // libz seems to keep track of the true start position itself + // doesn't support SEEK_END, though return gzseek (file->gzfile, offset, whence); } #else @@ -424,10 +444,10 @@ long Qtell (QFile *file) { if (file->file) - return ftell (file->file); + return ftell (file->file) - file->start; #ifdef HAVE_ZLIB else - return gztell (file->gzfile); + return gztell (file->gzfile); //FIXME does gztell do the right thing? #else return -1; #endif