From: havoc Date: Tue, 5 Jul 2005 12:51:27 +0000 (+0000) Subject: added a 64bif fs_offset_t type to clean up most of the mess X-Git-Tag: xonotic-v0.1.0preview~4684 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3a16e432521bf1f1bb796a76c3819a5334b59b9b;p=xonotic%2Fdarkplaces.git added a 64bif fs_offset_t type to clean up most of the mess git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5502 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_demo.c b/cl_demo.c index 865a1b36..2ab796bc 100644 --- a/cl_demo.c +++ b/cl_demo.c @@ -189,7 +189,7 @@ void CL_ReadDemoMessage(void) cl.mviewangles[0][i] = LittleFloat(f); } - if (FS_Read(cls.demofile, net_message.data, net_message.cursize) == (size_t)net_message.cursize) + if (FS_Read(cls.demofile, net_message.data, net_message.cursize) == net_message.cursize) { MSG_BeginReading(); CL_ParseServerMessage(); diff --git a/console.c b/console.c index dca8f08a..b99f7c4b 100644 --- a/console.c +++ b/console.c @@ -780,7 +780,7 @@ void Con_DrawNotify (void) sprintf(temptext, "say_team:%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1)); else sprintf(temptext, "say:%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1)); - while (strlen(temptext) >= (size_t) con_linewidth) + while ((int)strlen(temptext) >= con_linewidth) { DrawQ_ColoredString( 0, v, temptext, con_linewidth, 8, 8, 1.0, 1.0, 1.0, 1.0, 0, &colorindex ); strcpy(temptext, &temptext[con_linewidth]); diff --git a/fs.c b/fs.c index d914b717..36cca0e4 100644 --- a/fs.c +++ b/fs.c @@ -148,9 +148,9 @@ struct qfile_s { 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 @@ -244,8 +244,8 @@ void FS_Dir_f(void); 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); /* @@ -258,7 +258,7 @@ VARIABLES mempool_t *fs_mempool; -size_t fs_filesize; +fs_offset_t fs_filesize; pack_t *packlist = NULL; @@ -384,7 +384,7 @@ qboolean PK3_GetEndOfCentralDir (const char *packfile, int packhandle, pk3_endOf 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; @@ -433,7 +433,7 @@ int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd) { 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); @@ -448,7 +448,7 @@ int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd) 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) @@ -475,7 +475,7 @@ int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd) 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; @@ -485,12 +485,11 @@ int PK3_BuildFileList (pack_t *pack, const pk3_endOfCentralDir_t *eocd) 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'; @@ -598,7 +597,7 @@ Find where the true file data offset is 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) @@ -638,8 +637,8 @@ Add a file to the list of files contained into a package ==================== */ 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; @@ -792,8 +791,8 @@ pack_t *FS_LoadPackPAK (const char *packfile) // 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); } @@ -1478,9 +1477,9 @@ FS_Write 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) @@ -1509,9 +1508,9 @@ FS_Read 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; @@ -1532,7 +1531,7 @@ size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize) { 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; @@ -1554,8 +1553,8 @@ size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize) // 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) @@ -1569,8 +1568,8 @@ size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize) } 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) @@ -1606,10 +1605,10 @@ size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize) 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; @@ -1719,7 +1718,7 @@ Print a string into a file 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; @@ -1783,11 +1782,11 @@ FS_Seek 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) @@ -1810,8 +1809,8 @@ int FS_Seek (qfile_t* file, long offset, int 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; @@ -1834,7 +1833,7 @@ int FS_Seek (qfile_t* file, long offset, int whence) 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; @@ -1853,10 +1852,10 @@ int FS_Seek (qfile_t* file, long offset, int whence) 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); @@ -1879,7 +1878,7 @@ FS_Tell 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; } @@ -1934,7 +1933,7 @@ FS_WriteFile 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; @@ -2075,7 +2074,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet) 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; @@ -2114,7 +2113,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet) { // 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]) @@ -2217,12 +2216,12 @@ void FS_FreeSearch(fssearch_t *search) 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; @@ -2261,11 +2260,11 @@ int FS_ListDirectory(const char *pattern, int oneperline) 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++] = ' '; } } diff --git a/fs.h b/fs.h index 7e9192a5..0047c076 100644 --- a/fs.h +++ b/fs.h @@ -30,13 +30,20 @@ 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 ------ // @@ -46,15 +53,15 @@ extern size_t fs_filesize; // set by FS_Open (in "read" mode) and FS_LoadFile 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 @@ -70,7 +77,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet); 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 ------ // diff --git a/host_cmd.c b/host_cmd.c index 00ea8a1a..b3cd8a7f 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -971,7 +971,7 @@ void Host_Say_Team_f(void) void Host_Tell_f(void) { client_t *save; - size_t j; + int j; const char *p1, *p2; char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64) qboolean fromServer = false; @@ -1018,13 +1018,13 @@ void Host_Tell_f(void) } while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r')) p2--; - for (j = strlen(text);j < (sizeof(text) - 2) && p1 < p2;) + for (j = (int)strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;) text[j++] = *p1++; text[j++] = '\n'; text[j++] = 0; save = host_client; - for (j = 0, host_client = svs.clients;j < (size_t)svs.maxclients;j++, host_client++) + for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++) if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1))) SV_ClientPrint(text); host_client = save; diff --git a/image.c b/image.c index 6af0ee2a..1c2af789 100644 --- a/image.c +++ b/image.c @@ -568,7 +568,7 @@ qbyte *LoadLMP (const qbyte *f, int matchwidth, int matchheight, qboolean loadAs if ((matchwidth && image_width != matchwidth) || (matchheight && image_height != matchheight)) return NULL; - if (fs_filesize < (size_t)(8 + image_width * image_height)) + if (fs_filesize < (fs_offset_t)(8 + image_width * image_height)) { Con_Print("LoadLMP: invalid LMP file\n"); return NULL; diff --git a/jpeg.c b/jpeg.c index 6a28208a..420fda73 100644 --- a/jpeg.c +++ b/jpeg.c @@ -628,7 +628,7 @@ static void JPEG_TermDestination (j_compress_ptr cinfo) // Write any data remaining in the buffer if (datacount > 0) - if (FS_Write (dest->outfile, dest->buffer, datacount) != datacount) + if (FS_Write (dest->outfile, dest->buffer, datacount) != (fs_offset_t)datacount) error_in_jpeg = true; } diff --git a/keys.c b/keys.c index 4be917f3..2b0017a0 100644 --- a/keys.c +++ b/keys.c @@ -348,7 +348,7 @@ Key_Console (int key, char ascii) // delete char on cursor if (key == K_DEL || key == K_KP_DEL) { - if ((size_t)key_linepos < strlen(key_lines[edit_line])) + if (key_linepos < (int)strlen(key_lines[edit_line])) strcpy(key_lines[edit_line] + key_linepos, key_lines[edit_line] + key_linepos + 1); return; } @@ -358,7 +358,7 @@ Key_Console (int key, char ascii) // otherwise just go right one if (key == K_RIGHTARROW || key == K_KP_RIGHTARROW) { - if ((size_t)key_linepos < strlen(key_lines[edit_line])) + if (key_linepos < (int)strlen(key_lines[edit_line])) key_linepos++; return; diff --git a/menu.c b/menu.c index efbe4e3b..337328ae 100644 --- a/menu.c +++ b/menu.c @@ -819,7 +819,7 @@ int loadable[MAX_SAVEGAMES]; void M_ScanSaves (void) { - size_t i, j, len; + int i, j, len; char name[MAX_OSPATH]; char buf[SAVEGAME_COMMENT_LENGTH + 256]; const char *t; diff --git a/model_brush.c b/model_brush.c index b5c5cb94..76500648 100644 --- a/model_brush.c +++ b/model_brush.c @@ -1337,7 +1337,7 @@ static void Mod_Q1BSP_LoadLighting(lump_t *l) data = (qbyte*) FS_LoadFile(litfilename, tempmempool, false); if (data) { - if (fs_filesize == (size_t)(8 + l->filelen * 3) && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T') + if (fs_filesize == (fs_offset_t)(8 + l->filelen * 3) && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T') { i = LittleLong(((int *)data)[1]); if (i == 1) diff --git a/prvm_cmds.c b/prvm_cmds.c index cf72710d..fbb54af8 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -74,9 +74,9 @@ checkextension(extensionname) // kind of helper function static qboolean checkextension(const char *name) { - size_t len; + int len; char *e, *start; - len = strlen(name); + len = (int)strlen(name); for (e = prog->extensionstring;*e;e++) { @@ -87,7 +87,7 @@ static qboolean checkextension(const char *name) start = e; while (*e && *e != ' ') e++; - if ((size_t)(e - start) == len && !strncasecmp(start, name, len)) + if ((e - start) == len && !strncasecmp(start, name, len)) return true; } return false; @@ -1677,7 +1677,7 @@ fputs(float fhandle, string s) //void(float fhandle, string s) fputs = #113; // writes a line of text to the end of the file void VM_fputs(void) { - size_t stringlength; + int stringlength; char string[VM_STRINGTEMP_LENGTH]; int filenum; @@ -1695,7 +1695,7 @@ void VM_fputs(void) return; } VM_VarString(1, string, sizeof(string)); - if ((stringlength = strlen(string))) + if ((stringlength = (int)strlen(string))) FS_Write(VM_FILES[filenum], string, stringlength); if (developer.integer) Con_Printf("fputs: %s: %s\n", PRVM_NAME, string); diff --git a/prvm_edict.c b/prvm_edict.c index 1d28aa26..35d5fde0 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -1283,7 +1283,7 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required } prog->progs = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false); - if (prog->progs == NULL || fs_filesize < sizeof(dprograms_t)) + if (prog->progs == NULL || fs_filesize < (fs_offset_t)sizeof(dprograms_t)) PRVM_ERROR ("PRVM_LoadProgs: couldn't load %s for %s", filename, PRVM_NAME); Con_DPrintf("%s programs occupy %iK.\n", PRVM_NAME, fs_filesize/1024); diff --git a/qtypes.h b/qtypes.h index 480b1e7f..24ab64b4 100644 --- a/qtypes.h +++ b/qtypes.h @@ -9,7 +9,9 @@ typedef unsigned char qbyte; typedef enum {false, true} qboolean; -#ifdef WIN32 +#ifdef WIN64 +# define ssize_t long long +#elifdef WIN32 # define ssize_t long #endif diff --git a/snd_main.c b/snd_main.c index 6451829f..fe590b12 100644 --- a/snd_main.c +++ b/snd_main.c @@ -569,7 +569,7 @@ int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f { channel_t *target_chan, *check; int ch_idx; - size_t skip; + int skip; if (!sound_started || !sfx || nosound.integer) return -1; @@ -603,8 +603,8 @@ int S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float f if (check->sfx == sfx && !check->pos) { skip = 0.1 * sfx->format.speed; - if (skip > sfx->total_length) - skip = sfx->total_length; + if (skip > (int)sfx->total_length) + skip = (int)sfx->total_length; if (skip > 0) skip = rand() % skip; target_chan->pos += skip; diff --git a/wad.c b/wad.c index 333e619b..b0ea75f1 100644 --- a/wad.c +++ b/wad.c @@ -178,7 +178,7 @@ void W_LoadTextureWadFile (char *filename, int complain) if (!(lumps = Mem_Alloc(tempmempool, sizeof(lumpinfo_t)*numlumps))) {Con_Print("W_LoadTextureWadFile: unable to allocate temporary memory for lump table\n");return;} - if (FS_Read(file, lumps, sizeof(lumpinfo_t) * numlumps) != sizeof(lumpinfo_t) * (size_t)numlumps) + if (FS_Read(file, lumps, sizeof(lumpinfo_t) * numlumps) != (fs_offset_t)sizeof(lumpinfo_t) * numlumps) {Con_Print("W_LoadTextureWadFile: unable to read lump table\n");return;} for (i=0, lump_p = lumps ; iwidth = LittleLong(tex->width);