From: havoc Date: Sat, 5 Nov 2005 14:18:22 +0000 (+0000) Subject: eliminated fs_filesize global, now File_LoadFile and File_Open take a fs_offset_t... X-Git-Tag: xonotic-v0.1.0preview~4494 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=ea3f4513f96a21ae1bcbaae4a4997968ace1ab95 eliminated fs_filesize global, now File_LoadFile and File_Open take a fs_offset_t filesize variable pointer to store the file size into git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5790 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_particles.c b/cl_particles.c index c5030ab5..55f9ac68 100644 --- a/cl_particles.c +++ b/cl_particles.c @@ -558,7 +558,7 @@ void CL_ReadPointFile_f (void) #if WORKINGLQUAKE pointfile = COM_LoadTempFile (name); #else - pointfile = (char *)FS_LoadFile(name, tempmempool, true); + pointfile = (char *)FS_LoadFile(name, tempmempool, true, NULL); #endif if (!pointfile) { diff --git a/cmd.c b/cmd.c index 12fe19fd..2626069c 100644 --- a/cmd.c +++ b/cmd.c @@ -265,7 +265,7 @@ static void Cmd_Exec_f (void) return; } - f = (char *)FS_LoadFile (Cmd_Argv(1), tempmempool, false); + f = (char *)FS_LoadFile (Cmd_Argv(1), tempmempool, false, NULL); if (!f) { Con_Printf("couldn't exec %s\n",Cmd_Argv(1)); diff --git a/fs.c b/fs.c index df394998..2179d6d5 100644 --- a/fs.c +++ b/fs.c @@ -262,8 +262,6 @@ VARIABLES mempool_t *fs_mempool; -fs_offset_t fs_filesize; - pack_t *packlist = NULL; searchpath_t *fs_searchpaths = NULL; @@ -381,7 +379,7 @@ Extract the end of the central directory from a PK3 package */ qboolean PK3_GetEndOfCentralDir (const char *packfile, int packhandle, pk3_endOfCentralDir_t *eocd) { - long filesize, maxsize; + fs_offset_t filesize, maxsize; unsigned char *buffer, *ptr; int ind; @@ -1167,8 +1165,6 @@ qfile_t *FS_OpenPackedFile (pack_t* pack, int pack_ind) pfile = &pack->files[pack_ind]; - fs_filesize = 0; - // If we don't have the true offset, get it now if (! (pfile->flags & PACKFILE_FLAG_TRUEOFFS)) if (!PK3_GetTrueFileOffset (pfile, pack)) @@ -1246,8 +1242,6 @@ qfile_t *FS_OpenPackedFile (pack_t* pack, int pack_ind) file->ztk = ztk; } - fs_filesize = pfile->realsize; - return file; } @@ -1379,8 +1373,6 @@ static searchpath_t *FS_FindFile (const char *name, int* index, qboolean quiet) FS_OpenReadFile Look for a file in the search paths and open it in read-only mode - -Sets fs_filesize =========== */ qfile_t *FS_OpenReadFile (const char *filename, qboolean quiet, qboolean nonblocking) @@ -1392,10 +1384,7 @@ qfile_t *FS_OpenReadFile (const char *filename, qboolean quiet, qboolean nonbloc // Not found? if (search == NULL) - { - fs_filesize = 0; return NULL; - } // Found in the filesystem? if (pack_ind < 0) @@ -1427,8 +1416,6 @@ Open a file. The syntax is the same as fopen */ qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet, qboolean nonblocking) { - qfile_t* file; - if (FS_CheckNastyPath(filepath)) { Con_Printf("FS_Open(\"%s\", \"%s\", %s): nasty filename rejected\n", filepath, mode, quiet ? "true" : "false"); @@ -1448,13 +1435,9 @@ qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet, qboole return FS_SysOpen (real_path, mode, nonblocking); } - // Else, we look at the various search paths and open the file in read-only mode - file = FS_OpenReadFile (filepath, quiet, nonblocking); - if (file != NULL) - fs_filesize = file->real_length; - - return file; + else + return FS_OpenReadFile (filepath, quiet, nonblocking); } @@ -1917,21 +1900,24 @@ Filename are relative to the quake directory. Always appends a 0 byte. ============ */ -unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet) +unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet, fs_offset_t *filesizepointer) { qfile_t *file; - unsigned char *buf; + unsigned char *buf = NULL; + fs_offset_t filesize = 0; file = FS_Open (path, "rb", quiet, false); - if (!file) - return NULL; - - buf = (unsigned char *)Mem_Alloc (pool, fs_filesize + 1); - buf[fs_filesize] = '\0'; - - FS_Read (file, buf, fs_filesize); - FS_Close (file); + if (file) + { + filesize = file->real_length; + buf = (unsigned char *)Mem_Alloc (pool, filesize + 1); + buf[filesize] = '\0'; + FS_Read (file, buf, filesize); + FS_Close (file); + } + if (filesizepointer) + *filesizepointer = filesize; return buf; } diff --git a/fs.h b/fs.h index c86870f9..a55df4b7 100644 --- a/fs.h +++ b/fs.h @@ -44,7 +44,6 @@ typedef long long fs_offset_t; extern char fs_gamedir [MAX_OSPATH]; extern char fs_basedir [MAX_OSPATH]; -extern fs_offset_t fs_filesize; // set by FS_Open (in "read" mode) and FS_LoadFile // ------ Main functions ------ // @@ -77,7 +76,7 @@ fssearch_t; fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet); void FS_FreeSearch(fssearch_t *search); -unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet); +unsigned char *FS_LoadFile (const char *path, mempool_t *pool, qboolean quiet, fs_offset_t *filesizepointer); qboolean FS_WriteFile (const char *filename, void *data, fs_offset_t len); diff --git a/gl_draw.c b/gl_draw.c index 59603aa2..85540ad2 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -50,9 +50,7 @@ static rtexture_t *draw_generateconchars(void) unsigned char buffer[65536][4], *data = NULL; double random; - fs_filesize = FONT_FILESIZE; - data = LoadTGA (concharimage, 256, 256); - fs_filesize = -1; + data = LoadTGA (concharimage, FONT_FILESIZE, 256, 256); // Gold numbers for (i = 0;i < 8192;i++) { diff --git a/gl_rmain.c b/gl_rmain.c index b73ebca9..9373aa1a 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -431,7 +431,7 @@ void gl_main_newmap(void) if (l >= 0 && !strcmp(entname + l, ".bsp")) { strcpy(entname + l, ".ent"); - if ((entities = (char *)FS_LoadFile(entname, tempmempool, true))) + if ((entities = (char *)FS_LoadFile(entname, tempmempool, true, NULL))) { CL_ParseEntityLump(entities); Mem_Free(entities); diff --git a/host_cmd.c b/host_cmd.c index 3030f7c3..38678a0e 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -586,7 +586,7 @@ void Host_Loadgame_f (void) cls.demonum = -1; // stop demo loop in case this fails - t = text = (char *)FS_LoadFile (filename, tempmempool, false); + t = text = (char *)FS_LoadFile (filename, tempmempool, false, NULL); if (!text) { Con_Print("ERROR: couldn't open.\n"); diff --git a/image.c b/image.c index 623ed589..5a151506 100644 --- a/image.c +++ b/image.c @@ -180,14 +180,14 @@ typedef struct pcx_s LoadPCX ============ */ -unsigned char* LoadPCX (const unsigned char *f, int matchwidth, int matchheight) +unsigned char* LoadPCX (const unsigned char *f, int filesize, int matchwidth, int matchheight) { pcx_t pcx; unsigned char *a, *b, *image_rgba, *pbuf; const unsigned char *palette, *fin, *enddata; int x, y, x2, dataByte; - if (fs_filesize < (int)sizeof(pcx) + 768) + if (filesize < (int)sizeof(pcx) + 768) { Con_Print("Bad pcx file\n"); return NULL; @@ -218,7 +218,7 @@ unsigned char* LoadPCX (const unsigned char *f, int matchwidth, int matchheight) if ((matchwidth && image_width != matchwidth) || (matchheight && image_height != matchheight)) return NULL; - palette = f + fs_filesize - 768; + palette = f + filesize - 768; image_rgba = (unsigned char *)Mem_Alloc(tempmempool, image_width*image_height*4); if (!image_rgba) @@ -297,7 +297,7 @@ void PrintTargaHeader(TargaHeader *t) LoadTGA ============= */ -unsigned char *LoadTGA (const unsigned char *f, int matchwidth, int matchheight) +unsigned char *LoadTGA (const unsigned char *f, int filesize, int matchwidth, int matchheight) { int x, y, row_inc, compressed, readpixelcount, red, green, blue, alpha, runlen, pindex, alphabits; unsigned char *pixbuf, *image_rgba; @@ -306,10 +306,10 @@ unsigned char *LoadTGA (const unsigned char *f, int matchwidth, int matchheight) TargaHeader targa_header; unsigned char palette[256*4]; - if (fs_filesize < 19) + if (filesize < 19) return NULL; - enddata = f + fs_filesize; + enddata = f + filesize; targa_header.id_length = f[0]; targa_header.colormap_type = f[1]; @@ -536,11 +536,11 @@ unsigned char *LoadTGA (const unsigned char *f, int matchwidth, int matchheight) LoadLMP ============ */ -unsigned char *LoadLMP (const unsigned char *f, int matchwidth, int matchheight, qboolean loadAs8Bit) +unsigned char *LoadLMP (const unsigned char *f, int filesize, int matchwidth, int matchheight, qboolean loadAs8Bit) { unsigned char *image_buffer; - if (fs_filesize < 9) + if (filesize < 9) { Con_Print("LoadLMP: invalid LMP file\n"); return NULL; @@ -557,7 +557,7 @@ unsigned char *LoadLMP (const unsigned char *f, int matchwidth, int matchheight, if ((matchwidth && image_width != matchwidth) || (matchheight && image_height != matchheight)) return NULL; - if (fs_filesize < (fs_offset_t)(8 + image_width * image_height)) + if (filesize < (8 + image_width * image_height)) { Con_Print("LoadLMP: invalid LMP file\n"); return NULL; @@ -576,9 +576,9 @@ unsigned char *LoadLMP (const unsigned char *f, int matchwidth, int matchheight, return image_buffer; } -static unsigned char *LoadLMPRGBA (const unsigned char *f, int matchwidth, int matchheight) +static unsigned char *LoadLMPRGBA (const unsigned char *f, int filesize, int matchwidth, int matchheight) { - return LoadLMP(f, matchwidth, matchheight, false); + return LoadLMP(f, filesize, matchwidth, matchheight, false); } @@ -593,12 +593,12 @@ typedef struct q2wal_s int value; } q2wal_t; -unsigned char *LoadWAL (const unsigned char *f, int matchwidth, int matchheight) +unsigned char *LoadWAL (const unsigned char *f, int filesize, int matchwidth, int matchheight) { unsigned char *image_rgba; const q2wal_t *inwal = (const q2wal_t *)f; - if (fs_filesize < (int) sizeof(q2wal_t)) + if (filesize < (int) sizeof(q2wal_t)) { Con_Print("LoadWAL: invalid WAL file\n"); return NULL; @@ -614,7 +614,7 @@ unsigned char *LoadWAL (const unsigned char *f, int matchwidth, int matchheight) if ((matchwidth && image_width != matchwidth) || (matchheight && image_height != matchheight)) return NULL; - if ((int) fs_filesize < (int) sizeof(q2wal_t) + (int) LittleLong(inwal->offsets[0]) + image_width * image_height) + if (filesize < (int) sizeof(q2wal_t) + (int) LittleLong(inwal->offsets[0]) + image_width * image_height) { Con_Print("LoadWAL: invalid WAL file\n"); return NULL; @@ -655,7 +655,7 @@ void Image_StripImageExtension (const char *in, char *out) struct imageformat_s { const char *formatstring; - unsigned char *(*loadfunc)(const unsigned char *f, int matchwidth, int matchheight); + unsigned char *(*loadfunc)(const unsigned char *f, int filesize, int matchwidth, int matchheight); } imageformats[] = { @@ -675,6 +675,7 @@ imageformats[] = unsigned char *loadimagepixels (const char *filename, qboolean complain, int matchwidth, int matchheight) { int i; + fs_offset_t filesize; unsigned char *f, *data = NULL; char basename[MAX_QPATH], name[MAX_QPATH], *c; if (developer_memorydebug.integer) @@ -690,10 +691,10 @@ unsigned char *loadimagepixels (const char *filename, qboolean complain, int mat for (i = 0;imageformats[i].formatstring;i++) { sprintf (name, imageformats[i].formatstring, basename); - f = FS_LoadFile(name, tempmempool, true); + f = FS_LoadFile(name, tempmempool, true, &filesize); if (f) { - data = imageformats[i].loadfunc(f, matchwidth, matchheight); + data = imageformats[i].loadfunc(f, filesize, matchwidth, matchheight); Mem_Free(f); if (data) { diff --git a/image.h b/image.h index 1a9e30d1..a25f2201 100644 --- a/image.h +++ b/image.h @@ -21,7 +21,7 @@ void Image_Copy8bitRGBA(const unsigned char *in, unsigned char *out, int pixels, // makes a RGBA mask from RGBA input, in can be the same as out int image_makemask (const unsigned char *in, unsigned char *out, int size); -unsigned char *LoadTGA (const unsigned char *f, int matchwidth, int matchheight); +unsigned char *LoadTGA (const unsigned char *f, int filesize, int matchwidth, int matchheight); // loads a texture, as pixel data unsigned char *loadimagepixels (const char *filename, qboolean complain, int matchwidth, int matchheight); @@ -61,7 +61,7 @@ void Image_Resample (const void *indata, int inwidth, int inheight, int indepth, void Image_MipReduce(const unsigned char *in, unsigned char *out, int *width, int *height, int *depth, int destwidth, int destheight, int destdepth, int bytesperpixel); // only used by menuplyr coloring -unsigned char *LoadLMP (const unsigned char *f, int matchwidth, int matchheight, qboolean loadAs8Bit); +unsigned char *LoadLMP (const unsigned char *f, int filesize, int matchwidth, int matchheight, qboolean loadAs8Bit); void Image_HeightmapToNormalmap(const unsigned char *inpixels, unsigned char *outpixels, int width, int height, int clamp, float bumpscale); diff --git a/jpeg.c b/jpeg.c index 44bbb5fe..7e503d3b 100644 --- a/jpeg.c +++ b/jpeg.c @@ -470,12 +470,12 @@ static void JPEG_SkipInputData (j_decompress_ptr cinfo, long num_bytes) cinfo->src->bytes_in_buffer -= num_bytes; } -static void JPEG_MemSrc (j_decompress_ptr cinfo, const unsigned char *buffer) +static void JPEG_MemSrc (j_decompress_ptr cinfo, const unsigned char *buffer, size_t filesize) { cinfo->src = (struct jpeg_source_mgr *)cinfo->mem->alloc_small ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr)); cinfo->src->next_input_byte = buffer; - cinfo->src->bytes_in_buffer = fs_filesize; + cinfo->src->bytes_in_buffer = filesize; cinfo->src->init_source = JPEG_Noop; cinfo->src->fill_input_buffer = JPEG_FillInputBuffer; @@ -498,7 +498,7 @@ JPEG_LoadImage Load a JPEG image into a RGBA buffer ==================== */ -unsigned char* JPEG_LoadImage (const unsigned char *f, int matchwidth, int matchheight) +unsigned char* JPEG_LoadImage (const unsigned char *f, int filesize, int matchwidth, int matchheight) { struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; @@ -511,7 +511,7 @@ unsigned char* JPEG_LoadImage (const unsigned char *f, int matchwidth, int match cinfo.err = qjpeg_std_error (&jerr); qjpeg_create_decompress (&cinfo); - JPEG_MemSrc (&cinfo, f); + JPEG_MemSrc (&cinfo, f, filesize); qjpeg_read_header (&cinfo, TRUE); qjpeg_start_decompress (&cinfo); diff --git a/jpeg.h b/jpeg.h index 6a9dd563..a657e7c3 100644 --- a/jpeg.h +++ b/jpeg.h @@ -27,7 +27,7 @@ qboolean JPEG_OpenLibrary (void); void JPEG_CloseLibrary (void); -unsigned char* JPEG_LoadImage (const unsigned char *f, int matchwidth, int matchheight); +unsigned char* JPEG_LoadImage (const unsigned char *f, int filesize, int matchwidth, int matchheight); qboolean JPEG_SaveImage_preflipped (const char *filename, int width, int height, unsigned char *data); diff --git a/menu.c b/menu.c index 68888fcd..c8ff19c4 100644 --- a/menu.c +++ b/menu.c @@ -1321,12 +1321,13 @@ void M_Setup_Draw (void) if (menuplyr_load) { unsigned char *data, *f; + fs_offset_t filesize; menuplyr_load = false; menuplyr_top = -1; menuplyr_bottom = -1; - if ((f = FS_LoadFile("gfx/menuplyr.lmp", tempmempool, true))) + if ((f = FS_LoadFile("gfx/menuplyr.lmp", tempmempool, true, &filesize))) { - data = LoadLMP (f, 0, 0, true); + data = LoadLMP (f, filesize, 0, 0, true); menuplyr_width = image_width; menuplyr_height = image_height; Mem_Free(f); diff --git a/model_alias.c b/model_alias.c index ea42d2bb..5d24ba6b 100644 --- a/model_alias.c +++ b/model_alias.c @@ -1666,6 +1666,7 @@ void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend) { int i, j, index, version, recordsize, numrecords; int numpnts, numvtxw, numfaces, nummatts, numbones, numrawweights, numanimbones, numanims, numanimkeys; + fs_offset_t filesize; pskpnts_t *pnts; pskvtxw_t *vtxw; pskface_t *faces; @@ -1710,8 +1711,8 @@ void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend) FS_StripExtension(loadmodel->name, animname, sizeof(animname)); strlcat(animname, ".psa", sizeof(animname)); - animbuffer = animfilebuffer = FS_LoadFile(animname, loadmodel->mempool, false); - animbufferend = (void *)((unsigned char*)animbuffer + fs_filesize); + animbuffer = animfilebuffer = FS_LoadFile(animname, loadmodel->mempool, false, &filesize); + animbufferend = (void *)((unsigned char*)animbuffer + (int)filesize); if (animbuffer == NULL) Host_Error("%s: can't find .psa file (%s)\n", loadmodel->name, animname); diff --git a/model_brush.c b/model_brush.c index 8622d3d0..26f6098d 100644 --- a/model_brush.c +++ b/model_brush.c @@ -1456,6 +1456,7 @@ static void Mod_Q1BSP_LoadLighting(lump_t *l) int i; unsigned char *in, *out, *data, d; char litfilename[1024]; + fs_offset_t filesize; loadmodel->brushq1.lightdata = NULL; if (loadmodel->brush.ishlbsp) // LordHavoc: load the colored lighting data straight { @@ -1474,17 +1475,17 @@ static void Mod_Q1BSP_LoadLighting(lump_t *l) strlcpy (litfilename, loadmodel->name, sizeof (litfilename)); FS_StripExtension (litfilename, litfilename, sizeof (litfilename)); strlcat (litfilename, ".lit", sizeof (litfilename)); - data = (unsigned char*) FS_LoadFile(litfilename, tempmempool, false); + data = (unsigned char*) FS_LoadFile(litfilename, tempmempool, false, &filesize); if (data) { - if (fs_filesize == (fs_offset_t)(8 + l->filelen * 3) && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T') + if (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) { Con_DPrintf("loaded %s\n", litfilename); - loadmodel->brushq1.lightdata = (unsigned char *)Mem_Alloc(loadmodel->mempool, fs_filesize - 8); - memcpy(loadmodel->brushq1.lightdata, data + 8, fs_filesize - 8); + loadmodel->brushq1.lightdata = (unsigned char *)Mem_Alloc(loadmodel->mempool, filesize - 8); + memcpy(loadmodel->brushq1.lightdata, data + 8, filesize - 8); Mem_Free(data); return; } @@ -1496,10 +1497,10 @@ static void Mod_Q1BSP_LoadLighting(lump_t *l) } else { - if (fs_filesize == 8) + if (filesize == 8) Con_Print("Empty .lit file, ignoring\n"); else - Con_Printf("Corrupt .lit file (file size %i bytes, should be %i bytes), ignoring\n", fs_filesize, 8 + l->filelen * 3); + Con_Printf("Corrupt .lit file (file size %i bytes, should be %i bytes), ignoring\n", filesize, 8 + l->filelen * 3); Mem_Free(data); } } @@ -1529,7 +1530,7 @@ static void Mod_Q1BSP_LoadLightList(void) strlcpy (lightsfilename, loadmodel->name, sizeof (lightsfilename)); FS_StripExtension (lightsfilename, lightsfilename, sizeof(lightsfilename)); strlcat (lightsfilename, ".lights", sizeof (lightsfilename)); - s = lightsstring = (char *) FS_LoadFile(lightsfilename, tempmempool, false); + s = lightsstring = (char *) FS_LoadFile(lightsfilename, tempmempool, false, NULL); if (s) { numlights = 0; @@ -2405,7 +2406,7 @@ static void Mod_Q1BSP_LoadMapBrushes(void) char mapfilename[MAX_QPATH]; FS_StripExtension (loadmodel->name, mapfilename, sizeof (mapfilename)); strlcat (mapfilename, ".map", sizeof (mapfilename)); - maptext = (unsigned char*) FS_LoadFile(mapfilename, tempmempool, false); + maptext = (unsigned char*) FS_LoadFile(mapfilename, tempmempool, false, NULL); if (!maptext) return; text = maptext; @@ -3855,7 +3856,7 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l) { for (i = 0;i < search->numfilenames;i++) { - if ((f = (char *)FS_LoadFile(search->filenames[i], tempmempool, false))) + if ((f = (char *)FS_LoadFile(search->filenames[i], tempmempool, false, NULL))) { text = f; while (COM_ParseToken(&text, false)) diff --git a/model_shared.c b/model_shared.c index 6b3a8e79..7e34223c 100644 --- a/model_shared.c +++ b/model_shared.c @@ -136,6 +136,7 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea int num; unsigned int crc; void *buf; + fs_offset_t filesize; mod->used = true; @@ -150,10 +151,10 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea { if (checkdisk && mod->loaded) Con_DPrintf("checking model %s\n", mod->name); - buf = FS_LoadFile (mod->name, tempmempool, false); + buf = FS_LoadFile (mod->name, tempmempool, false, &filesize); if (buf) { - crc = CRC_Block((unsigned char *)buf, fs_filesize); + crc = CRC_Block((unsigned char *)buf, filesize); if (mod->crc != crc) mod->loaded = false; } @@ -190,7 +191,7 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea if (buf) { - char *bufend = (char *)buf + fs_filesize; + char *bufend = (char *)buf + filesize; num = LittleLong(*((int *)buf)); // call the apropriate loader loadmodel = mod; @@ -1081,7 +1082,7 @@ tag_torso, */ memset(tagsets, 0, sizeof(tagsets)); memset(word, 0, sizeof(word)); - for (i = 0;i < MAX_SKINS && (data = text = (char *)FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), tempmempool, true));i++) + for (i = 0;i < MAX_SKINS && (data = text = (char *)FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), tempmempool, true, NULL));i++) { numtags = 0; diff --git a/palette.c b/palette.c index 67bcd0cc..7f569955 100644 --- a/palette.c +++ b/palette.c @@ -30,9 +30,10 @@ void Palette_SetupSpecialPalettes(void) int shirt_start, shirt_end; int reversed_start, reversed_end; unsigned char *colormap; + fs_offset_t filesize; - colormap = FS_LoadFile("gfx/colormap.lmp", tempmempool, true); - if (colormap && fs_filesize >= 16385) + colormap = FS_LoadFile("gfx/colormap.lmp", tempmempool, true, NULL); + if (colormap && filesize >= 16385) fullbright_start = 256 - colormap[16384]; else fullbright_start = 256; @@ -164,6 +165,7 @@ void Palette_Init(void) { int i; float gamma, scale, base; + fs_offset_t filesize; unsigned char *in, *out, *palfile; unsigned char texturegammaramp[256]; @@ -188,8 +190,8 @@ void Palette_Init(void) BuildGammaTable8(1.0f, gamma, scale, base, texturegammaramp); - palfile = (unsigned char *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false); - if (palfile && fs_filesize >= 768) + palfile = (unsigned char *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false, &filesize); + if (palfile && filesize >= 768) in = palfile; else { diff --git a/pr_edict.c b/pr_edict.c index 43330f39..c29ec8d4 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -1274,6 +1274,7 @@ extern void PR_Cmd_Reset (void); void PR_LoadProgs (const char *progsname) { int i; + fs_offset_t filesize; dstatement_t *st; ddef_t *infielddefs; dfunction_t *dfunctions; @@ -1283,13 +1284,13 @@ void PR_LoadProgs (const char *progsname) PR_FreeAll(); - progs = (dprograms_t *)FS_LoadFile (progsname, serverprogs_mempool, false); + progs = (dprograms_t *)FS_LoadFile (progsname, serverprogs_mempool, false, &filesize); if (!progs) Host_Error ("PR_LoadProgs: couldn't load %s", progsname); - Con_DPrintf("Programs occupy %iK.\n", fs_filesize/1024); + Con_DPrintf("Programs occupy %iK.\n", filesize/1024); - pr_crc = CRC_Block((unsigned char *)progs, fs_filesize); + pr_crc = CRC_Block((unsigned char *)progs, filesize); // byte swap the header for (i = 0;i < (int) sizeof(*progs) / 4;i++) @@ -1307,7 +1308,7 @@ void PR_LoadProgs (const char *progsname) pr_stringssize = 0; for (i = 0;i < progs->numstrings;i++) { - if (progs->ofs_strings + pr_stringssize >= fs_filesize) + if (progs->ofs_strings + pr_stringssize >= filesize) Host_Error ("progs.dat strings go past end of file\n"); pr_stringssize += strlen (pr_strings + pr_stringssize) + 1; } diff --git a/prvm_cmds.c b/prvm_cmds.c index 45cfb89d..b1bdc5fc 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -2108,7 +2108,7 @@ void VM_loadfromfile(void) } // not conform with VM_fopen - data = (char *)FS_LoadFile(filename, tempmempool, false); + data = (char *)FS_LoadFile(filename, tempmempool, false, NULL); if (data == NULL) PRVM_G_FLOAT(OFS_RETURN) = -1; diff --git a/prvm_edict.c b/prvm_edict.c index 5847f53e..f520342b 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -1231,6 +1231,7 @@ PRVM_LoadLNO =============== */ void PRVM_LoadLNO( const char *progname ) { + fs_offset_t filesize; unsigned char *lno; unsigned int *header; char filename[512]; @@ -1238,7 +1239,7 @@ void PRVM_LoadLNO( const char *progname ) { FS_StripExtension( progname, filename, sizeof( filename ) ); strlcat( filename, ".lno", sizeof( filename ) ); - lno = FS_LoadFile( filename, tempmempool, false ); + lno = FS_LoadFile( filename, tempmempool, false, &filesize ); if( !lno ) { return; } @@ -1252,7 +1253,7 @@ void PRVM_LoadLNO( const char *progname ) { SafeWrite (h, &numstatements, sizeof(int)); SafeWrite (h, statement_linenums, numstatements*sizeof(int)); */ - if( (unsigned) fs_filesize < (6 + prog->progs->numstatements) * sizeof( int ) ) { + if( (unsigned) filesize < (6 + prog->progs->numstatements) * sizeof( int ) ) { return; } @@ -1281,18 +1282,19 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required dstatement_t *st; ddef_t *infielddefs; dfunction_t *dfunctions; + fs_offset_t filesize; if( prog->loaded ) { PRVM_ERROR ("PRVM_LoadProgs: there is already a %s program loaded!\n", PRVM_NAME ); } - prog->progs = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false); - if (prog->progs == NULL || fs_filesize < (fs_offset_t)sizeof(dprograms_t)) + prog->progs = (dprograms_t *)FS_LoadFile (filename, prog->progs_mempool, false, &filesize); + if (prog->progs == NULL || 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); + Con_DPrintf("%s programs occupy %iK.\n", PRVM_NAME, filesize/1024); - prog->filecrc = CRC_Block((unsigned char *)prog->progs, fs_filesize); + prog->filecrc = CRC_Block((unsigned char *)prog->progs, filesize); // byte swap the header for (i = 0;i < (int) sizeof(*prog->progs) / 4;i++) @@ -1310,7 +1312,7 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required prog->stringssize = 0; for (i = 0;i < prog->progs->numstrings;i++) { - if (prog->progs->ofs_strings + prog->stringssize >= (int)fs_filesize) + if (prog->progs->ofs_strings + prog->stringssize >= (int)filesize) PRVM_ERROR ("%s: %s strings go past end of file\n", PRVM_NAME, filename); prog->stringssize += (int)strlen (prog->strings + prog->stringssize) + 1; } diff --git a/r_shadow.c b/r_shadow.c index 680295a4..4bb7823e 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -481,8 +481,8 @@ void r_shadow_start(void) int fragstrings_count; const char *vertstrings_list[SHADERPERMUTATION_COUNT+1]; const char *fragstrings_list[SHADERPERMUTATION_COUNT+1]; - vertstring = (char *)FS_LoadFile("glsl/light.vert", tempmempool, false); - fragstring = (char *)FS_LoadFile("glsl/light.frag", tempmempool, false); + vertstring = (char *)FS_LoadFile("glsl/light.vert", tempmempool, false, NULL); + fragstring = (char *)FS_LoadFile("glsl/light.frag", tempmempool, false, NULL); for (i = 0;i < SHADERPERMUTATION_COUNT;i++) { vertstrings_count = 0; @@ -3203,7 +3203,7 @@ void R_Shadow_LoadWorldLights(void) } FS_StripExtension (r_refdef.worldmodel->name, name, sizeof (name)); strlcat (name, ".rtlights", sizeof (name)); - lightsstring = (char *)FS_LoadFile(name, tempmempool, false); + lightsstring = (char *)FS_LoadFile(name, tempmempool, false, NULL); if (lightsstring) { s = lightsstring; @@ -3344,7 +3344,7 @@ void R_Shadow_LoadLightsFile(void) } FS_StripExtension (r_refdef.worldmodel->name, name, sizeof (name)); strlcat (name, ".lights", sizeof (name)); - lightsstring = (char *)FS_LoadFile(name, tempmempool, false); + lightsstring = (char *)FS_LoadFile(name, tempmempool, false, NULL); if (lightsstring) { s = lightsstring; @@ -3400,7 +3400,7 @@ void R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(void) // try to load a .ent file first FS_StripExtension (r_refdef.worldmodel->name, key, sizeof (key)); strlcat (key, ".ent", sizeof (key)); - data = entfiledata = (char *)FS_LoadFile(key, tempmempool, true); + data = entfiledata = (char *)FS_LoadFile(key, tempmempool, true, NULL); // and if that is not found, fall back to the bsp file entity string if (!data) data = r_refdef.worldmodel->brush.entities; diff --git a/snd_ogg.c b/snd_ogg.c index 79b53409..4919a572 100644 --- a/snd_ogg.c +++ b/snd_ogg.c @@ -571,6 +571,7 @@ Load an Ogg Vorbis file into memory qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *s) { unsigned char *data; + fs_offset_t filesize; ov_decode_t ov_decode; OggVorbis_File vf; vorbis_info *vi; @@ -584,7 +585,7 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *s) return true; // Load the file - data = FS_LoadFile (filename, snd_mempool, false); + data = FS_LoadFile (filename, snd_mempool, false, &filesize); if (data == NULL) return false; @@ -593,7 +594,7 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *s) // Open it with the VorbisFile API ov_decode.buffer = data; ov_decode.ind = 0; - ov_decode.buffsize = fs_filesize; + ov_decode.buffsize = filesize; if (qov_open_callbacks (&ov_decode, &vf, NULL, 0, callbacks) < 0) { Con_Printf ("error while opening Ogg Vorbis file \"%s\"\n", filename); @@ -616,7 +617,7 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *s) // Decide if we go for a stream or a simple PCM cache buff_len = ceil (STREAM_BUFFER_DURATION * (shm->format.speed * 2 * vi->channels)); - if (snd_streaming.integer && len > (ogg_int64_t)fs_filesize + 3 * buff_len) + if (snd_streaming.integer && len > (ogg_int64_t)filesize + 3 * buff_len) { ogg_stream_persfx_t* per_sfx; @@ -624,8 +625,8 @@ qboolean OGG_LoadVorbisFile (const char *filename, sfx_t *s) per_sfx = (ogg_stream_persfx_t *)Mem_Alloc (snd_mempool, sizeof (*per_sfx)); s->memsize += sizeof (*per_sfx); per_sfx->file = data; - per_sfx->filesize = fs_filesize; - s->memsize += fs_filesize; + per_sfx->filesize = filesize; + s->memsize += filesize; per_sfx->format.speed = vi->rate; per_sfx->format.width = 2; // We always work with 16 bits samples diff --git a/snd_wav.c b/snd_wav.c index 4be917db..3fa97dca 100644 --- a/snd_wav.c +++ b/snd_wav.c @@ -255,6 +255,7 @@ S_LoadWavFile */ qboolean S_LoadWavFile (const char *filename, sfx_t *s) { + fs_offset_t filesize; unsigned char *data; wavinfo_t info; int len; @@ -266,7 +267,7 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *s) return true; // Load the file - data = FS_LoadFile(filename, snd_mempool, false); + data = FS_LoadFile(filename, snd_mempool, false, &filesize); if (!data) return false; @@ -279,7 +280,7 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *s) Con_DPrintf ("Loading WAV file \"%s\"\n", filename); - info = GetWavinfo (s->name, data, (int)fs_filesize); + info = GetWavinfo (s->name, data, (int)filesize); // Stereo sounds are allowed (intended for music) if (info.channels < 1 || info.channels > 2) { diff --git a/sv_main.c b/sv_main.c index dc6ea218..cc076ff5 100644 --- a/sv_main.c +++ b/sv_main.c @@ -1861,7 +1861,7 @@ void SV_SpawnServer (const char *server) // load replacement entity file if found entities = NULL; if (sv_entpatch.integer) - entities = (char *)FS_LoadFile(va("maps/%s.ent", sv.name), tempmempool, true); + entities = (char *)FS_LoadFile(va("maps/%s.ent", sv.name), tempmempool, true, NULL); if (entities) { Con_Printf("Loaded maps/%s.ent\n", sv.name); diff --git a/wad.c b/wad.c index 027dec1a..13a7b9fd 100644 --- a/wad.c +++ b/wad.c @@ -61,6 +61,7 @@ static void W_CleanupName (const char *in, char *out) void *W_GetLumpName(const char *name) { int i; + fs_offset_t filesize; lumpinfo_t *lump; char clean[16]; wadinfo_t *header; @@ -76,17 +77,16 @@ void *W_GetLumpName(const char *name) if (!wad_loaded) { wad_loaded = true; - if ((temp = FS_LoadFile ("gfx.wad", tempmempool, false))) + if ((wad_base = FS_LoadFile ("gfx.wad", cl_mempool, false, &filesize))) { if (memcmp(temp, "WAD2", 4)) + { Con_Print("gfx.wad doesn't have WAD2 id\n"); + Mem_Free(wad_base); + wad_base = NULL; + } else { - wad_base = (unsigned char *)Mem_Alloc(cl_mempool, fs_filesize); - - memcpy(wad_base, temp, fs_filesize); - Mem_Free(temp); - header = (wadinfo_t *)wad_base; wad_numlumps = LittleLong(header->numlumps); infotableofs = LittleLong(header->infotableofs);