{
qfile_flags_t flags;
int handle; // file descriptor
- size_t real_length; // uncompressed file size (for files opened in "read" mode)
- size_t position; // current position in the file
- size_t offset; // offset into the package (0 if external file)
+ fs_offset_t real_length; // uncompressed file size (for files opened in "read" mode)
+ fs_offset_t position; // current position in the file
+ fs_offset_t offset; // offset into the package (0 if external file)
int ungetc; // single stored character from ungetc, cleared to EOF when read
// Contents buffer
void FS_Ls_f(void);
static packfile_t* FS_AddFileToPack (const char* name, pack_t* pack,
- size_t offset, size_t packsize,
- size_t realsize, packfile_flags_t flags);
+ fs_offset_t offset, fs_offset_t packsize,
+ fs_offset_t realsize, packfile_flags_t flags);
/*
mempool_t *fs_mempool;
-size_t fs_filesize;
+fs_offset_t fs_filesize;
pack_t *packlist = NULL;
maxsize = ZIP_MAX_COMMENTS_SIZE + ZIP_END_CDIR_SIZE;
buffer = Mem_Alloc (tempmempool, maxsize);
lseek (packhandle, filesize - maxsize, SEEK_SET);
- if (read (packhandle, buffer, maxsize) != (ssize_t) maxsize)
+ if (read (packhandle, buffer, maxsize) != (fs_offset_t) maxsize)
{
Mem_Free (buffer);
return false;
{
qbyte *central_dir, *ptr;
unsigned int ind;
- size_t remaining;
+ fs_offset_t remaining;
// Load the central directory in memory
central_dir = Mem_Alloc (tempmempool, eocd->cdir_size);
ptr = central_dir;
for (ind = 0; ind < eocd->nbentries; ind++)
{
- size_t namesize, count;
+ fs_offset_t namesize, count;
// Checking the remaining size
if (remaining < ZIP_CDIR_CHUNK_BASE_SIZE)
if ((ptr[8] & 0x29) == 0 && (ptr[38] & 0x18) == 0)
{
// Still enough bytes for the name?
- if (remaining < namesize || namesize >= sizeof (*pack->files))
+ if (remaining < namesize || namesize >= (int)sizeof (*pack->files))
{
Mem_Free (central_dir);
return -1;
if (ptr[ZIP_CDIR_CHUNK_BASE_SIZE + namesize - 1] != '/')
{
char filename [sizeof (pack->files[0].name)];
- size_t offset, packsize, realsize;
+ fs_offset_t offset, packsize, realsize;
packfile_flags_t flags;
// Extract the name (strip it if necessary)
- if (namesize >= sizeof (filename))
- namesize = sizeof (filename) - 1;
+ namesize = min(namesize, (int)sizeof (filename) - 1);
memcpy (filename, &ptr[ZIP_CDIR_CHUNK_BASE_SIZE], namesize);
filename[namesize] = '\0';
qboolean PK3_GetTrueFileOffset (packfile_t *pfile, pack_t *pack)
{
qbyte buffer [ZIP_LOCAL_CHUNK_BASE_SIZE];
- size_t count;
+ fs_offset_t count;
// Already found?
if (pfile->flags & PACKFILE_FLAG_TRUEOFFS)
====================
*/
static packfile_t* FS_AddFileToPack (const char* name, pack_t* pack,
- size_t offset, size_t packsize,
- size_t realsize, packfile_flags_t flags)
+ fs_offset_t offset, fs_offset_t packsize,
+ fs_offset_t realsize, packfile_flags_t flags)
{
int (*strcmp_funct) (const char* str1, const char* str2);
int left, right, middle;
// parse the directory
for (i = 0;i < numpackfiles;i++)
{
- size_t offset = LittleLong (info[i].filepos);
- size_t size = LittleLong (info[i].filelen);
+ fs_offset_t offset = LittleLong (info[i].filepos);
+ fs_offset_t size = LittleLong (info[i].filelen);
FS_AddFileToPack (info[i].name, pack, offset, size, size, PACKFILE_FLAG_TRUEOFFS);
}
Write "datasize" bytes into a file
====================
*/
-size_t FS_Write (qfile_t* file, const void* data, size_t datasize)
+fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize)
{
- ssize_t result;
+ fs_offset_t result;
// If necessary, seek to the exact file position we're supposed to be
if (file->buff_ind != file->buff_len)
Read up to "buffersize" bytes from a file
====================
*/
-size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
+fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
{
- size_t count, done;
+ fs_offset_t count, done;
if (buffersize == 0)
return 0;
{
count = file->buff_len - file->buff_ind;
- done += (buffersize > count) ? count : buffersize;
+ done += ((fs_offset_t)buffersize > count) ? count : (fs_offset_t)buffersize;
memcpy (buffer, &file->buff[file->buff_ind], done);
file->buff_ind += done;
// If we have a lot of data to get, put them directly into "buffer"
if (buffersize > sizeof (file->buff) / 2)
{
- if (count > buffersize)
- count = buffersize;
+ if (count > (fs_offset_t)buffersize)
+ count = (fs_offset_t)buffersize;
lseek (file->handle, file->offset + file->position, SEEK_SET);
nb = read (file->handle, &((qbyte*)buffer)[done], count);
if (nb > 0)
}
else
{
- if (count > sizeof (file->buff))
- count = sizeof (file->buff);
+ if (count > (fs_offset_t)sizeof (file->buff))
+ count = (fs_offset_t)sizeof (file->buff);
lseek (file->handle, file->offset + file->position, SEEK_SET);
nb = read (file->handle, file->buff, count);
if (nb > 0)
return done;
count = ztk->comp_length - ztk->in_position;
- if (count > sizeof (ztk->input))
- count = sizeof (ztk->input);
+ if (count > (fs_offset_t)sizeof (ztk->input))
+ count = (fs_offset_t)sizeof (ztk->input);
lseek (file->handle, file->offset + ztk->in_position, SEEK_SET);
- if (read (file->handle, ztk->input, count) != (ssize_t)count)
+ if (read (file->handle, ztk->input, count) != (fs_offset_t)count)
{
Con_Printf ("FS_Read: unexpected end of file");
break;
int FS_VPrintf (qfile_t* file, const char* format, va_list ap)
{
int len;
- size_t buff_size;
+ fs_offset_t buff_size;
char *tempbuff = NULL;
buff_size = 1024;
Move the position index in a file
====================
*/
-int FS_Seek (qfile_t* file, long offset, int whence)
+int FS_Seek (qfile_t* file, fs_offset_t offset, int whence)
{
ztoolkit_t *ztk;
qbyte* buffer;
- size_t buffersize;
+ fs_offset_t buffersize;
// Compute the file offset
switch (whence)
return -1;
// If we have the data in our read buffer, we don't need to actually seek
- if (file->position - file->buff_len <= (size_t)offset &&
- (size_t)offset <= file->position)
+ if (file->position - (fs_offset_t)file->buff_len <= offset
+ && offset <= file->position)
{
file->buff_ind = offset + file->buff_len - file->position;
return 0;
ztk = file->ztk;
// If we have to go back in the file, we need to restart from the beginning
- if ((size_t)offset <= file->position)
+ if (offset <= file->position)
{
ztk->in_ind = 0;
ztk->in_len = 0;
buffer = Mem_Alloc (tempmempool, buffersize);
// Skip all data until we reach the requested offset
- while ((size_t)offset > file->position)
+ while (offset > file->position)
{
- size_t diff = offset - file->position;
- size_t count, len;
+ fs_offset_t diff = offset - file->position;
+ fs_offset_t count, len;
count = (diff > buffersize) ? buffersize : diff;
len = FS_Read (file, buffer, count);
Give the current position in a file
====================
*/
-size_t FS_Tell (qfile_t* file)
+fs_offset_t FS_Tell (qfile_t* file)
{
return file->position - file->buff_len + file->buff_ind;
}
The filename will be prefixed by the current game directory
============
*/
-qboolean FS_WriteFile (const char *filename, void *data, size_t len)
+qboolean FS_WriteFile (const char *filename, void *data, fs_offset_t len)
{
qfile_t *file;
fssearch_t *search;
searchpath_t *searchpath;
pack_t *pak;
- size_t i, basepathlength, numfiles, numchars;
+ int i, basepathlength, numfiles, numchars;
stringlist_t *dir, *dirfile, *liststart, *listcurrent, *listtemp;
const char *slash, *backslash, *colon, *separator;
char *basepath;
{
// look through all the pak file elements
pak = searchpath->pack;
- for (i = 0;i < (size_t)pak->numfiles;i++)
+ for (i = 0;i < pak->numfiles;i++)
{
strcpy(temp, pak->files[i].name);
while (temp[0])
extern int con_linewidth;
int FS_ListDirectory(const char *pattern, int oneperline)
{
- size_t numfiles;
- size_t numcolumns;
- size_t numlines;
- size_t columnwidth;
- size_t linebufpos;
- size_t i, j, k, l;
+ int numfiles;
+ int numcolumns;
+ int numlines;
+ int columnwidth;
+ int linebufpos;
+ int i, j, k, l;
const char *name;
char linebuf[4096];
fssearch_t *search;
if (l < numfiles)
{
name = search->filenames[l];
- for (j = 0;name[j] && linebufpos + 1 < sizeof(linebuf);j++)
+ for (j = 0;name[j] && linebufpos + 1 < (int)sizeof(linebuf);j++)
linebuf[linebufpos++] = name[j];
// space out name unless it's the last on the line
if (k + 1 < numcolumns && l + 1 < numfiles)
- for (;j < columnwidth && linebufpos + 1 < sizeof(linebuf);j++)
+ for (;j < columnwidth && linebufpos + 1 < (int)sizeof(linebuf);j++)
linebuf[linebufpos++] = ' ';
}
}
typedef struct qfile_s qfile_t;
+#ifdef WIN32
+typedef _int64 fs_offset_t;
+#else
+typedef long long fs_offset_t;
+#endif
+
+
// ------ Variables ------ //
extern char fs_gamedir [MAX_OSPATH];
extern char fs_basedir [MAX_OSPATH];
-extern size_t fs_filesize; // set by FS_Open (in "read" mode) and FS_LoadFile
+extern fs_offset_t fs_filesize; // set by FS_Open (in "read" mode) and FS_LoadFile
// ------ Main functions ------ //
qfile_t *FS_Open (const char* filepath, const char* mode, qboolean quiet, qboolean nonblocking);
int FS_Close (qfile_t* file);
-size_t FS_Write (qfile_t* file, const void* data, size_t datasize);
-size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize);
+fs_offset_t FS_Write (qfile_t* file, const void* data, size_t datasize);
+fs_offset_t FS_Read (qfile_t* file, void* buffer, size_t buffersize);
int FS_Print(qfile_t* file, const char *msg);
int FS_Printf(qfile_t* file, const char* format, ...);
int FS_VPrintf(qfile_t* file, const char* format, va_list ap);
int FS_Getc (qfile_t* file);
int FS_UnGetc (qfile_t* file, unsigned char c);
-int FS_Seek (qfile_t* file, long offset, int whence);
-size_t FS_Tell (qfile_t* file);
+int FS_Seek (qfile_t* file, fs_offset_t offset, int whence);
+fs_offset_t FS_Tell (qfile_t* file);
void FS_Purge (qfile_t* file);
typedef struct fssearch_s
void FS_FreeSearch(fssearch_t *search);
qbyte *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet);
-qboolean FS_WriteFile (const char *filename, void *data, size_t len);
+qboolean FS_WriteFile (const char *filename, void *data, fs_offset_t len);
// ------ Other functions ------ //