DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
fs.h File Reference
#include <stddef.h>
#include <stdarg.h>
#include "qtypes.h"
#include "qdefs.h"
#include "zone.h"
+ Include dependency graph for fs.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  fssearch_t
 
struct  gamedir_t
 
struct  vfs_t
 

Macros

#define FS_FILETYPE_DIRECTORY   2
 
#define FS_FILETYPE_FILE   1
 
#define FS_FILETYPE_NONE   0
 
#define MAX_GAMEDIRS   17
 

Typedefs

typedef int64_t fs_offset_t
 

Enumerations

enum  addgamedirs_t { GAMEDIRS_ALLGOOD = -1 , GAMEDIRS_FAILURE = 0 , GAMEDIRS_SUCCESS = 1 }
 

Functions

qbool FS_AddPack (const char *pakfile, qbool *already_loaded, qbool keep_plain_dirs, qbool dlcache)
 
qbool FS_ChangeGameDirs (int numgamedirs, const char *gamedirs[], qbool failmissing)
 
const char * FS_CheckGameDir (const char *gamedir)
 
int FS_CheckNastyPath (const char *path, qbool isgamedir)
 
int FS_Close (qfile_t *file)
 
int FS_CRCFile (const char *filename, size_t *filesizepointer)
 
void FS_CreatePath (char *path)
 
void FS_DefaultExtension (char *path, const char *extension, size_t size_path)
 
unsigned char * FS_Deflate (const unsigned char *data, size_t size, size_t *deflated_size, int level, mempool_t *mempool)
 
const char * FS_FileExists (const char *filename)
 Look for a file in the packages and in the filesystem Returns its canonical name (same case as used in the pack) if found, else NULL.
 
const char * FS_FileExtension (const char *in)
 
qfile_t * FS_FileFromData (const unsigned char *data, const size_t size, qbool quiet)
 
fs_offset_t FS_FileSize (qfile_t *file)
 
int FS_FileType (const char *filename)
 Look for a file in the packages and in the filesystem.
 
const char * FS_FileWithoutPath (const char *in)
 
void FS_FreeSearch (fssearch_t *search)
 
int FS_Getc (qfile_t *file)
 
qbool FS_HasZlib (void)
 
unsigned char * FS_Inflate (const unsigned char *data, size_t size, size_t *inflated_size, mempool_t *mempool)
 
void FS_Init (void)
 
void FS_Init_Commands (void)
 
void FS_Init_SelfPack (void)
 
qbool FS_IsRegisteredQuakePack (const char *name)
 
unsigned char * FS_LoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
 
qfile_t * FS_OpenRealFile (const char *filepath, const char *mode, qbool quiet)
 
qfile_t * FS_OpenVirtualFile (const char *filepath, qbool quiet)
 
int FS_Print (qfile_t *file, const char *msg)
 
int FS_Printf (qfile_t *file, const char *format,...) DP_FUNC_PRINTF(2)
 
void FS_Purge (qfile_t *file)
 
fs_offset_t FS_Read (qfile_t *file, void *buffer, size_t buffersize)
 
void FS_RemoveOnClose (qfile_t *file)
 
void FS_Rescan (void)
 
void FS_SanitizePath (char *path)
 
fssearch_tFS_Search (const char *pattern, int caseinsensitive, int quiet, const char *packfile)
 
int FS_Seek (qfile_t *file, fs_offset_t offset, int whence)
 
addgamedirs_t FS_SetGameDirs (int numgamedirs, const char *gamedirs[], qbool failmissing, qbool abortonfail)
 
void FS_Shutdown (void)
 
void FS_StripExtension (const char *in, char *out, size_t size_out)
 
qbool FS_SysFileExists (const char *filename)
 Look for a file in the filesystem only.
 
int FS_SysFileType (const char *filename)
 Look for a file in the filesystem only.
 
unsigned char * FS_SysLoadFile (const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
 
qfile_t * FS_SysOpen (const char *filepath, const char *mode, qbool nonblocking)
 
int FS_SysOpenFD (const char *filepath, const char *mode, qbool nonblocking)
 
fs_offset_t FS_Tell (qfile_t *file)
 
int FS_UnGetc (qfile_t *file, unsigned char c)
 
void FS_UnloadPacks_dlcache (void)
 
int FS_VPrintf (qfile_t *file, const char *format, va_list ap)
 
const char * FS_WhichPack (const char *filename)
 
fs_offset_t FS_Write (qfile_t *file, const void *data, size_t datasize)
 
qbool FS_WriteFile (const char *filename, const void *data, fs_offset_t len)
 
qbool FS_WriteFileInBlocks (const char *filename, const void *const *data, const fs_offset_t *len, size_t count)
 

Variables

gamedir_tfs_all_gamedirs
 
int fs_all_gamedirs_count
 
char fs_basedir [MAX_OSPATH]
 
const char *const fs_checkgamedir_missing
 
char fs_gamedir [MAX_OSPATH]
 
char fs_gamedirs [MAX_GAMEDIRS][MAX_QPATH]
 
int fs_numgamedirs
 
char fs_userdir [MAX_OSPATH]
 

Macro Definition Documentation

◆ FS_FILETYPE_DIRECTORY

#define FS_FILETYPE_DIRECTORY   2

Definition at line 139 of file fs.h.

Referenced by Con_CompleteCommandLine(), and FS_SysFileType().

◆ FS_FILETYPE_FILE

#define FS_FILETYPE_FILE   1

Definition at line 138 of file fs.h.

Referenced by Con_CompleteCommandLine(), FS_FileType(), and FS_SysFileType().

◆ FS_FILETYPE_NONE

#define FS_FILETYPE_NONE   0

Definition at line 137 of file fs.h.

Referenced by FS_FileType(), FS_SysFileExists(), and FS_SysFileType().

◆ MAX_GAMEDIRS

#define MAX_GAMEDIRS   17

Definition at line 46 of file fs.h.

Referenced by FS_GameDir_f(), FS_Init_Dir(), and FS_SetGameDirs().

Typedef Documentation

◆ fs_offset_t

typedef int64_t fs_offset_t

Definition at line 37 of file fs.h.

Enumeration Type Documentation

◆ addgamedirs_t

Enumerator
GAMEDIRS_ALLGOOD 
GAMEDIRS_FAILURE 
GAMEDIRS_SUCCESS 

Definition at line 102 of file fs.h.

102 {
103 GAMEDIRS_ALLGOOD = -1,
addgamedirs_t
Definition fs.h:102
@ GAMEDIRS_SUCCESS
Definition fs.h:105
@ GAMEDIRS_ALLGOOD
Definition fs.h:103
@ GAMEDIRS_FAILURE
Definition fs.h:104

Function Documentation

◆ FS_AddPack()

qbool FS_AddPack ( const char * pakfile,
qbool * already_loaded,
qbool keep_plain_dirs,
qbool dlcache )

Adds the given pack to the search path and searches for it in the game path. The pack type is autodetected by the file extension.

Returns true if the file was successfully added to the search path or if it was already included.

If keep_plain_dirs is set, the pack will be added AFTER the first sequence of plain directories.

Definition at line 1309 of file fs.c.

1310{
1311 char fullpath[MAX_OSPATH];
1312 int index;
1313 searchpath_t *search;
1314
1315 if(already_loaded)
1316 *already_loaded = false;
1317
1318 // then find the real name...
1319 search = FS_FindFile(pakfile, &index, NULL, true);
1320 if(!search || search->pack)
1321 {
1322 Con_Printf("could not find pak \"%s\"\n", pakfile);
1323 return false;
1324 }
1325
1326 dpsnprintf(fullpath, sizeof(fullpath), "%s%s", search->filename, pakfile);
1327
1328 return FS_AddPack_Fullpath(fullpath, pakfile, already_loaded, keep_plain_dirs, dlcache);
1329}
int dpsnprintf(char *buffer, size_t buffersize, const char *format,...)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
Definition common.c:997
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
static searchpath_t * FS_FindFile(const char *name, int *index, const char **canonicalname, qbool quiet)
Definition fs.c:2690
static qbool FS_AddPack_Fullpath(const char *pakfile, const char *shortname, qbool *already_loaded, qbool keep_plain_dirs, qbool dlcache)
Definition fs.c:1194
GLuint index
Definition glquake.h:629
#define MAX_OSPATH
max length of a filesystem pathname
Definition qdefs.h:175
#define NULL
Definition qtypes.h:12
Search paths for files (including packages)
Definition fs.c:400
pack_t * pack
Definition fs.c:403
char filename[MAX_OSPATH]
Definition fs.c:402

References Con_Printf(), dpsnprintf(), searchpath_t::filename, FS_AddPack_Fullpath(), FS_FindFile(), index, MAX_OSPATH, NULL, and searchpath_t::pack.

Referenced by Curl_Begin(), and Curl_EndDownload().

◆ FS_ChangeGameDirs()

qbool FS_ChangeGameDirs ( int numgamedirs,
const char * gamedirs[],
qbool failmissing )

Definition at line 1719 of file fs.c.

1720{
1721 addgamedirs_t addresult = COM_ChangeGameTypeForGameDirs(numgamedirs, gamedirs, failmissing, false);
1722
1723 if (addresult == GAMEDIRS_ALLGOOD)
1724 return true; // already using this set of gamedirs, do nothing
1725 else if (addresult == GAMEDIRS_FAILURE)
1726 return false;
1727
1729
1730 if (cls.demoplayback)
1731 CL_Disconnect();
1732 cls.demonum = 0; // make sure startdemos will work if the mod uses it
1733
1734 // unload all sounds so they will be reloaded from the new files as needed
1736
1737 // reinitialize filesystem to detect the new paks
1738 FS_Rescan();
1739
1740 // reload assets after the config is executed
1741 Cbuf_InsertText(cmd_local, "\nloadconfig\nr_restart\n");
1742
1743 return true;
1744}
client_static_t cls
Definition cl_main.c:116
void CL_Disconnect(void)
Definition cl_main.c:478
void Cbuf_InsertText(cmd_state_t *cmd, const char *text)
Definition cmd.c:292
cmd_state_t * cmd_local
command interpreter for local commands injected by SVQC, CSQC, MQC, server or client engine code uses...
Definition cmd.c:25
int COM_ChangeGameTypeForGameDirs(unsigned numgamedirs, const char *gamedirs[], qbool failmissing, qbool init)
Definition com_game.c:122
void FS_Rescan(void)
Definition fs.c:1538
void Host_SaveConfig(const char *file)
Definition host.c:195
#define CONFIGFILENAME
Definition quakedef.h:29
void S_UnloadAllSounds_f(cmd_state_t *cmd)
Definition snd_main.c:864
qbool demoplayback
Definition client.h:587

References Cbuf_InsertText(), CL_Disconnect(), cls, cmd_local, COM_ChangeGameTypeForGameDirs(), CONFIGFILENAME, client_static_t::demonum, client_static_t::demoplayback, FS_Rescan(), GAMEDIRS_ALLGOOD, GAMEDIRS_FAILURE, Host_SaveConfig(), and S_UnloadAllSounds_f().

Referenced by CL_ParseServerInfo(), FS_GameDir_f(), and ModList_Enable().

◆ FS_CheckGameDir()

const char * FS_CheckGameDir ( const char * gamedir)

Definition at line 1824 of file fs.c.

1825{
1826 const char *ret;
1827 static char buf[8192];
1828 char vabuf[1024];
1829
1830 if (FS_CheckNastyPath(gamedir, true))
1831 return NULL;
1832
1833 ret = FS_SysCheckGameDir(va(vabuf, sizeof(vabuf), "%s%s/", fs_userdir, gamedir), buf, sizeof(buf));
1834 if(ret)
1835 {
1836 if(!*ret)
1837 {
1838 // get description from basedir
1839 ret = FS_SysCheckGameDir(va(vabuf, sizeof(vabuf), "%s%s/", fs_basedir, gamedir), buf, sizeof(buf));
1840 if(ret)
1841 return ret;
1842 return "";
1843 }
1844 return ret;
1845 }
1846
1847 ret = FS_SysCheckGameDir(va(vabuf, sizeof(vabuf), "%s%s/", fs_basedir, gamedir), buf, sizeof(buf));
1848 if(ret)
1849 return ret;
1850
1852}
char * va(char *buf, size_t buflen, const char *format,...)
Definition common.c:972
static const char * FS_SysCheckGameDir(const char *gamedir, char *buf, size_t buflength)
Definition fs.c:1786
const char *const fs_checkgamedir_missing
Definition fs.c:438
char fs_basedir[MAX_OSPATH]
Definition fs.c:444
int FS_CheckNastyPath(const char *path, qbool isgamedir)
Definition fs.c:2618
char fs_userdir[MAX_OSPATH]
Definition fs.c:442
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition glquake.h:657
return ret

References buf, fs_basedir, fs_checkgamedir_missing, FS_CheckNastyPath(), FS_SysCheckGameDir(), fs_userdir, NULL, ret, and va().

Referenced by FS_ListGameDirs(), FS_SetGameDirs(), and ModList_RebuildList().

◆ FS_CheckNastyPath()

int FS_CheckNastyPath ( const char * path,
qbool isgamedir )

Definition at line 2618 of file fs.c.

2619{
2620 // all: never allow an empty path, as for gamedir it would access the parent directory and a non-gamedir path it is just useless
2621 if (!path[0])
2622 return 2;
2623
2624 // Windows: don't allow \ in filenames (windows-only), period.
2625 // (on Windows \ is a directory separator, but / is also supported)
2626 if (strstr(path, "\\"))
2627 return 1; // non-portable
2628
2629 // Mac: don't allow Mac-only filenames - : is a directory separator
2630 // instead of /, but we rely on / working already, so there's no reason to
2631 // support a Mac-only path
2632 // Amiga and Windows: : tries to go to root of drive
2633 if (strstr(path, ":"))
2634 return 1; // non-portable attempt to go to root of drive
2635
2636 // Amiga: // is parent directory
2637 if (strstr(path, "//"))
2638 return 1; // non-portable attempt to go to parent directory
2639
2640 // all: don't allow going to parent directory (../ or /../)
2641 if (strstr(path, ".."))
2642 return 2; // attempt to go outside the game directory
2643
2644 // Windows and UNIXes: don't allow absolute paths
2645 if (path[0] == '/')
2646 return 2; // attempt to go outside the game directory
2647
2648 // all: don't allow . character immediately before a slash, this catches all imaginable cases of ./, ../, .../, etc
2649 if (strstr(path, "./"))
2650 return 2; // possible attempt to go outside the game directory
2651
2652 // all: forbid trailing slash on gamedir
2653 if (isgamedir && path[strlen(path)-1] == '/')
2654 return 2;
2655
2656 // all: forbid leading dot on any filename for any reason
2657 if (strstr(path, "/."))
2658 return 2; // attempt to go outside the game directory
2659
2660 // after all these checks we're pretty sure it's a / separated filename
2661 // and won't do much if any harm
2662 return false;
2663}
float strlen(string s)

References strlen().

Referenced by CL_DownloadBegin_f(), FS_CheckGameDir(), FS_OpenReadFile(), FS_OpenRealFile(), FS_OpenVirtualFile(), SV_Download_f(), and VM_loadfromfile().

◆ FS_Close()

int FS_Close ( qfile_t * file)

Definition at line 2970 of file fs.c.

2971{
2972 if(file->flags & QFILE_FLAG_DATA)
2973 {
2974 Mem_Free(file);
2975 return 0;
2976 }
2977
2978 if (FILEDESC_CLOSE (file->handle))
2979 return EOF;
2980
2981 if (file->filename)
2982 {
2983 if (file->flags & QFILE_FLAG_REMOVE)
2984 {
2985 if (remove(file->filename) == -1)
2986 {
2987 // No need to report this. If removing a just
2988 // written file failed, this most likely means
2989 // someone else deleted it first - which we
2990 // like.
2991 }
2992 }
2993
2994 Mem_Free((void *) file->filename);
2995 }
2996
2997 if (file->ztk)
2998 {
2999 qz_inflateEnd (&file->ztk->zstream);
3000 Mem_Free (file->ztk);
3001 }
3002
3003 Mem_Free (file);
3004 return 0;
3005}
#define FILEDESC_CLOSE
Definition fs.c:111
#define QFILE_FLAG_REMOVE
real file will be removed on close
Definition fs.c:300
#define QFILE_FLAG_DATA
file is actually already loaded data
Definition fs.c:298
void remove(entity e)
#define Mem_Free(mem)
Definition zone.h:96

References FILEDESC_CLOSE, Mem_Free, QFILE_FLAG_DATA, QFILE_FLAG_REMOVE, and remove().

Referenced by CL_CutDemo(), CL_Locs_Save_f(), CL_Stop_f(), CL_StopPlayback(), Con_ConDump_f(), Crypto_KeyGen_f(), Crypto_KeyGen_Finished(), Crypto_LoadFile(), Crypto_SavePubKeyTextFile(), Curl_Begin(), Curl_EndDownload(), FS_LoadAndCloseQFile(), FS_OpenReadFile(), FS_SysCheckGameDir(), FS_WriteFileInBlocks(), GetMapList(), Host_SaveConfig(), Host_UnlockSession(), hz_bitstream_read_close(), jam_close(), JPEG_SaveImage_preflipped(), Key_History_Init(), Key_History_Shutdown(), libavw_close(), Log_Close(), Log_Printf(), M_ScanSaves(), PNG_SaveImage_preflipped(), PRVM_Prog_Load(), QW_CL_CheckOrDownloadFile(), R_GLSL_DumpShader_f(), SCR_CaptureVideo_Avi_EndVideo(), SCR_CaptureVideo_Ogg_EndVideo(), SV_Download_f(), SV_DropClient(), SV_ReadClientMessage(), SV_Savegame_to(), SV_StopDemoRecording(), VM_buf_loadfile(), VM_fclose(), VM_Files_CloseAll(), W_LoadTextureWadFile(), and W_UnloadAll().

◆ FS_CRCFile()

int FS_CRCFile ( const char * filename,
size_t * filesizepointer )

Definition at line 4158 of file fs.c.

4159{
4160 int crc = -1;
4161 unsigned char *filedata;
4162 fs_offset_t filesize;
4163 if (filesizepointer)
4164 *filesizepointer = 0;
4165 if (!filename || !*filename)
4166 return crc;
4167 filedata = FS_LoadFile(filename, tempmempool, true, &filesize);
4168 if (filedata)
4169 {
4170 if (filesizepointer)
4171 *filesizepointer = filesize;
4172 crc = CRC_Block(filedata, filesize);
4173 Mem_Free(filedata);
4174 }
4175 return crc;
4176}
unsigned short CRC_Block(const unsigned char *data, size_t size)
Definition com_crc16.c:75
unsigned char * FS_LoadFile(const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
Definition fs.c:3540
int64_t fs_offset_t
Definition fs.h:37
mempool_t * tempmempool
Definition zone.c:794

References CRC_Block(), FS_LoadFile(), Mem_Free, and tempmempool.

Referenced by CL_BeginDownloads(), CL_StopDownload(), and QW_CL_RequestNextDownload().

◆ FS_CreatePath()

void FS_CreatePath ( char * path)

Definition at line 1028 of file fs.c.

1029{
1030 char *ofs, save;
1031
1032 for (ofs = path+1 ; *ofs ; ofs++)
1033 {
1034 if (*ofs == '/' || *ofs == '\\')
1035 {
1036 // create the directory
1037 save = *ofs;
1038 *ofs = 0;
1039 FS_mkdir (path);
1040 *ofs = save;
1041 }
1042 }
1043}
static void FS_mkdir(const char *path)
Definition fs.c:999
prvm_uint_t ofs

References FS_mkdir(), and ofs.

Referenced by Crypto_KeyGen_f(), Crypto_KeyGen_Finished(), FS_OpenRealFile(), and Host_LockSession().

◆ FS_DefaultExtension()

void FS_DefaultExtension ( char * path,
const char * extension,
size_t size_path )

Definition at line 3641 of file fs.c.

3642{
3643 const char *src;
3644
3645 // if path doesn't have a .EXT, append extension
3646 // (extension should include the .)
3647 src = path + strlen(path);
3648
3649 while (*src != '/' && src != path)
3650 {
3651 if (*src == '.')
3652 return; // it has an extension
3653 src--;
3654 }
3655
3656 dp_strlcat (path, extension, size_path);
3657}
#define dp_strlcat(dst, src, dsize)
Definition common.h:304
prvm_eval_t * src

References dp_strlcat, src, and strlen().

Referenced by CL_PlayDemo(), CL_Record_f(), R_LoadTextureDDSFile(), SV_Loadgame_f(), SV_Savegame_f(), and SV_StartDemoRecording().

◆ FS_Deflate()

unsigned char * FS_Deflate ( const unsigned char * data,
size_t size,
size_t * deflated_size,
int level,
mempool_t * mempool )

Definition at line 4178 of file fs.c.

4179{
4180 z_stream strm;
4181 unsigned char *out = NULL;
4182 unsigned char *tmp;
4183
4184 *deflated_size = 0;
4185#ifndef LINK_TO_ZLIB
4186 if(!zlib_dll)
4187 return NULL;
4188#endif
4189
4190 memset(&strm, 0, sizeof(strm));
4191 strm.zalloc = Z_NULL;
4192 strm.zfree = Z_NULL;
4193 strm.opaque = Z_NULL;
4194
4195 if(level < 0)
4197
4199 {
4200 Con_Printf("FS_Deflate: deflate init error!\n");
4201 return NULL;
4202 }
4203
4204 strm.next_in = (unsigned char*)data;
4205 strm.avail_in = (unsigned int)size;
4206
4207 tmp = (unsigned char *) Mem_Alloc(tempmempool, size);
4208 if(!tmp)
4209 {
4210 Con_Printf("FS_Deflate: not enough memory in tempmempool!\n");
4211 qz_deflateEnd(&strm);
4212 return NULL;
4213 }
4214
4215 strm.next_out = tmp;
4216 strm.avail_out = (unsigned int)size;
4217
4218 if(qz_deflate(&strm, Z_FINISH) != Z_STREAM_END)
4219 {
4220 Con_Printf("FS_Deflate: deflate failed!\n");
4221 qz_deflateEnd(&strm);
4222 Mem_Free(tmp);
4223 return NULL;
4224 }
4225
4226 if(qz_deflateEnd(&strm) != Z_OK)
4227 {
4228 Con_Printf("FS_Deflate: deflateEnd failed\n");
4229 Mem_Free(tmp);
4230 return NULL;
4231 }
4232
4233 if(strm.total_out >= size)
4234 {
4235 Con_Printf("FS_Deflate: deflate is useless on this data!\n");
4236 Mem_Free(tmp);
4237 return NULL;
4238 }
4239
4240 out = (unsigned char *) Mem_Alloc(mempool, strm.total_out);
4241 if(!out)
4242 {
4243 Con_Printf("FS_Deflate: not enough memory in target mempool!\n");
4244 Mem_Free(tmp);
4245 return NULL;
4246 }
4247
4248 *deflated_size = (size_t)strm.total_out;
4249
4250 memcpy(out, tmp, strm.total_out);
4251 Mem_Free(tmp);
4252
4253 return out;
4254}
vector size
#define Z_DEFLATED
Definition fs.c:242
#define Z_BINARY
Definition fs.c:241
static dllhandle_t zlib_dll
Handle for Zlib DLL.
Definition fs.c:507
#define Z_STREAM_END
Definition fs.c:234
#define Z_FINISH
Definition fs.c:250
#define Z_OK
Definition fs.c:233
static int(ZEXPORT *qz_inflate)(z_stream *strm
static int level
Definition fs.c:481
#define qz_deflateInit2(strm, level, method, windowBits, memLevel, strategy)
Definition fs.c:488
#define MAX_WBITS
Definition fs.c:232
#define Z_NULL
Definition fs.c:245
#define Z_MEMLEVEL_DEFAULT
Definition fs.c:243
#define Z_DEFAULT_COMPRESSION
Definition fs.c:246
GLsizeiptr const GLvoid * data
Definition glquake.h:639
Definition fs.c:270
unsigned int avail_in
number of bytes available at next_in
Definition fs.c:272
unsigned long total_out
total nb of bytes output so far
Definition fs.c:277
void * opaque
private data object passed to zalloc and zfree
Definition fs.c:284
void * zalloc
used to allocate the internal state
Definition fs.c:282
void * zfree
used to free the internal state
Definition fs.c:283
unsigned char * next_out
next output byte should be put there
Definition fs.c:275
unsigned int avail_out
remaining free space at next_out
Definition fs.c:276
unsigned char * next_in
next input byte
Definition fs.c:271
#define Mem_Alloc(pool, size)
Definition zone.h:92

References z_stream::avail_in, z_stream::avail_out, Con_Printf(), data, int(), level, MAX_WBITS, Mem_Alloc, Mem_Free, z_stream::next_in, z_stream::next_out, NULL, z_stream::opaque, qz_deflateInit2, size, tempmempool, z_stream::total_out, Z_BINARY, Z_DEFAULT_COMPRESSION, Z_DEFLATED, Z_FINISH, Z_MEMLEVEL_DEFAULT, Z_NULL, Z_OK, Z_STREAM_END, z_stream::zalloc, z_stream::zfree, and zlib_dll.

Referenced by SV_Prepare_CSQC().

◆ FS_FileExists()

const char * FS_FileExists ( const char * filename)

Look for a file in the packages and in the filesystem Returns its canonical name (same case as used in the pack) if found, else NULL.

If the file is found outside a pak, this will be the same pointer as passed in.

Definition at line 3693 of file fs.c.

3694{
3695 const char *canonicalname;
3696
3697 return FS_FindFile(filename, NULL, &canonicalname, true) ? canonicalname : NULL;
3698}

References FS_FindFile(), and NULL.

Referenced by CDAudio_Play_byName(), CL_BeginDownloads(), CL_SetupWorldModel(), CL_StopDownload(), Curl_Begin(), Curl_Curl_f(), Font_LoadFont(), FS_Rescan(), Host_AddConfigText(), loadimagepixelsbgra(), M_Menu_Main_f(), MR_SetRouting(), SV_Download_f(), and SV_SpawnServer().

◆ FS_FileExtension()

const char * FS_FileExtension ( const char * in)

Definition at line 1403 of file fs.c.

1404{
1405 const char *separator, *backslash, *colon, *dot;
1406
1407 dot = strrchr(in, '.');
1408 if (dot == NULL)
1409 return "";
1410
1411 separator = strrchr(in, '/');
1412 backslash = strrchr(in, '\\');
1413 if (!separator || separator < backslash)
1414 separator = backslash;
1415 colon = strrchr(in, ':');
1416 if (!separator || separator < colon)
1417 separator = colon;
1418
1419 if (separator && (dot < separator))
1420 return "";
1421
1422 return dot + 1;
1423}

References NULL.

Referenced by CL_PlayVideo_f(), CL_StopDownload(), FS_AddGameDirectory(), FS_AddPack_Fullpath(), Image_StripImageExtension(), Mod_LoadModel(), SCR_ScreenShot_f(), and SV_Download_f().

◆ FS_FileFromData()

qfile_t * FS_FileFromData ( const unsigned char * data,
const size_t size,
qbool quiet )

Definition at line 2951 of file fs.c.

2952{
2953 qfile_t* file;
2954 file = (qfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
2955 memset (file, 0, sizeof (*file));
2956 file->flags = QFILE_FLAG_DATA;
2957 file->ungetc = EOF;
2958 file->real_length = size;
2959 file->data = data;
2960 return file;
2961}
mempool_t * fs_mempool
Definition fs.c:434

References data, fs_mempool, Mem_Alloc, QFILE_FLAG_DATA, and size.

Referenced by SV_Download_f().

◆ FS_FileSize()

fs_offset_t FS_FileSize ( qfile_t * file)

Definition at line 3474 of file fs.c.

3475{
3476 return file->real_length;
3477}

Referenced by LibAvW_FS_SeekSize(), SV_Download_f(), and SV_ReadClientMessage().

◆ FS_FileType()

int FS_FileType ( const char * filename)

Look for a file in the packages and in the filesystem.

Definition at line 3667 of file fs.c.

3668{
3669 searchpath_t *search;
3670 char fullpath[MAX_OSPATH];
3671
3672 search = FS_FindFile (filename, NULL, NULL, true);
3673 if(!search)
3674 return FS_FILETYPE_NONE;
3675
3676 if(search->pack && !search->pack->vpack)
3677 return FS_FILETYPE_FILE; // TODO can't check directories in paks yet, maybe later
3678
3679 dpsnprintf(fullpath, sizeof(fullpath), "%s%s", search->filename, filename);
3680 return FS_SysFileType(fullpath);
3681}
int FS_SysFileType(const char *path)
Look for a file in the filesystem only.
Definition fs.c:3708
#define FS_FILETYPE_FILE
Definition fs.h:138
#define FS_FILETYPE_NONE
Definition fs.h:137
qbool vpack
Definition fs.c:392

References dpsnprintf(), searchpath_t::filename, FS_FILETYPE_FILE, FS_FILETYPE_NONE, FS_FindFile(), FS_SysFileType(), MAX_OSPATH, NULL, searchpath_t::pack, and pack_t::vpack.

Referenced by Con_CompleteCommandLine().

◆ FS_FileWithoutPath()

const char * FS_FileWithoutPath ( const char * in)

Definition at line 1431 of file fs.c.

1432{
1433 const char *separator, *backslash, *colon;
1434
1435 separator = strrchr(in, '/');
1436 backslash = strrchr(in, '\\');
1437 if (!separator || separator < backslash)
1438 separator = backslash;
1439 colon = strrchr(in, ':');
1440 if (!separator || separator < colon)
1441 separator = colon;
1442 return separator ? separator + 1 : in;
1443}

Referenced by COM_InitGameType(), and FS_IsRegisteredQuakePack().

◆ FS_FreeSearch()

void FS_FreeSearch ( fssearch_t * search)

Definition at line 3963 of file fs.c.

3964{
3965 Z_Free(search);
3966}
#define Z_Free(data)
Definition zone.h:164

References Z_Free.

Referenced by Cmd_Exec_f(), Con_CompleteCommandLine(), FS_ListDirectory(), GetMapList(), Image_FixTransparentPixels_f(), Mod_LoadQ3Shaders(), VM_search_end(), and VM_Search_Reset().

◆ FS_Getc()

int FS_Getc ( qfile_t * file)

Definition at line 3323 of file fs.c.

3324{
3325 unsigned char c;
3326
3327 if (FS_Read (file, &c, 1) != 1)
3328 return EOF;
3329
3330 return c;
3331}
fs_offset_t FS_Read(qfile_t *file, void *buffer, size_t buffersize)
Definition fs.c:3066

References FS_Read().

Referenced by CL_PlayDemo(), Key_History_Init(), VM_buf_loadfile(), and VM_fgets().

◆ FS_HasZlib()

qbool FS_HasZlib ( void )

Definition at line 620 of file fs.c.

621{
622#ifdef LINK_TO_ZLIB
623 return true;
624#else
625 PK3_OpenLibrary(); // to be safe
626 return (zlib_dll != 0);
627#endif
628}
static qbool PK3_OpenLibrary(void)
Definition fs.c:581

References PK3_OpenLibrary(), and zlib_dll.

Referenced by CL_BeginDownloads().

◆ FS_Inflate()

unsigned char * FS_Inflate ( const unsigned char * data,
size_t size,
size_t * inflated_size,
mempool_t * mempool )

Definition at line 4273 of file fs.c.

4274{
4275 int ret;
4276 z_stream strm;
4277 unsigned char *out = NULL;
4278 unsigned char tmp[2048];
4279 unsigned int have;
4280 sizebuf_t outbuf;
4281
4282 *inflated_size = 0;
4283#ifndef LINK_TO_ZLIB
4284 if(!zlib_dll)
4285 return NULL;
4286#endif
4287
4288 memset(&outbuf, 0, sizeof(outbuf));
4289 outbuf.data = (unsigned char *) Mem_Alloc(tempmempool, sizeof(tmp));
4290 outbuf.maxsize = sizeof(tmp);
4291
4292 memset(&strm, 0, sizeof(strm));
4293 strm.zalloc = Z_NULL;
4294 strm.zfree = Z_NULL;
4295 strm.opaque = Z_NULL;
4296
4297 if(qz_inflateInit2(&strm, -MAX_WBITS) != Z_OK)
4298 {
4299 Con_Printf("FS_Inflate: inflate init error!\n");
4300 Mem_Free(outbuf.data);
4301 return NULL;
4302 }
4303
4304 strm.next_in = (unsigned char*)data;
4305 strm.avail_in = (unsigned int)size;
4306
4307 do
4308 {
4309 strm.next_out = tmp;
4310 strm.avail_out = sizeof(tmp);
4311 ret = qz_inflate(&strm, Z_NO_FLUSH);
4312 // it either returns Z_OK on progress, Z_STREAM_END on end
4313 // or an error code
4314 switch(ret)
4315 {
4316 case Z_STREAM_END:
4317 case Z_OK:
4318 break;
4319
4320 case Z_STREAM_ERROR:
4321 Con_Print("FS_Inflate: stream error!\n");
4322 break;
4323 case Z_DATA_ERROR:
4324 Con_Print("FS_Inflate: data error!\n");
4325 break;
4326 case Z_MEM_ERROR:
4327 Con_Print("FS_Inflate: mem error!\n");
4328 break;
4329 case Z_BUF_ERROR:
4330 Con_Print("FS_Inflate: buf error!\n");
4331 break;
4332 default:
4333 Con_Print("FS_Inflate: unknown error!\n");
4334 break;
4335
4336 }
4337 if(ret != Z_OK && ret != Z_STREAM_END)
4338 {
4339 Con_Printf("Error after inflating %u bytes\n", (unsigned)strm.total_in);
4340 Mem_Free(outbuf.data);
4341 qz_inflateEnd(&strm);
4342 return NULL;
4343 }
4344 have = sizeof(tmp) - strm.avail_out;
4345 AssertBufsize(&outbuf, max(have, sizeof(tmp)));
4346 SZ_Write(&outbuf, tmp, have);
4347 } while(ret != Z_STREAM_END);
4348
4349 qz_inflateEnd(&strm);
4350
4351 out = (unsigned char *) Mem_Alloc(mempool, outbuf.cursize);
4352 if(!out)
4353 {
4354 Con_Printf("FS_Inflate: not enough memory in target mempool!\n");
4355 Mem_Free(outbuf.data);
4356 return NULL;
4357 }
4358
4359 memcpy(out, outbuf.data, outbuf.cursize);
4360 Mem_Free(outbuf.data);
4361
4362 *inflated_size = (size_t)outbuf.cursize;
4363
4364 return out;
4365}
void SZ_Write(sizebuf_t *buf, const unsigned char *data, int length)
Definition common.c:72
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504
#define Z_BUF_ERROR
Definition fs.c:238
#define Z_DATA_ERROR
Definition fs.c:236
#define Z_STREAM_ERROR
Definition fs.c:235
static void AssertBufsize(sizebuf_t *buf, int length)
Definition fs.c:4256
#define Z_NO_FLUSH
Definition fs.c:247
#define Z_MEM_ERROR
Definition fs.c:237
#define qz_inflateInit2(strm, windowBits)
Definition fs.c:486
#define max(A, B)
Definition mathlib.h:38
unsigned char * data
Definition common.h:52
int cursize
Definition common.h:54
int maxsize
Definition common.h:53
unsigned long total_in
total nb of input bytes read so far
Definition fs.c:273

References AssertBufsize(), z_stream::avail_in, z_stream::avail_out, Con_Print(), Con_Printf(), sizebuf_t::cursize, data, sizebuf_t::data, int(), max, MAX_WBITS, sizebuf_t::maxsize, Mem_Alloc, Mem_Free, z_stream::next_in, z_stream::next_out, NULL, z_stream::opaque, qz_inflateInit2, ret, size, SZ_Write(), tempmempool, z_stream::total_in, Z_BUF_ERROR, Z_DATA_ERROR, Z_MEM_ERROR, Z_NO_FLUSH, Z_NULL, Z_OK, Z_STREAM_END, Z_STREAM_ERROR, z_stream::zalloc, z_stream::zfree, and zlib_dll.

Referenced by CL_StopDownload().

◆ FS_Init()

void FS_Init ( void )

Definition at line 2342 of file fs.c.

2343{
2344 fs_mempool = Mem_AllocPool("file management", 0, NULL);
2345
2346 PK3_OpenLibrary ();
2347
2348 // initialize the self-pack (must be before COM_InitGameType as it may add command line options)
2350
2351 // detect gamemode from commandline options or executable name
2353
2354 FS_Init_Commands(); // assumes com_startupgamegroup is set
2355
2356 FS_Init_Dir();
2357}
void COM_InitGameType(void)
Definition com_game.c:95
static void FS_Init_Dir(void)
Definition fs.c:2139
void FS_Init_Commands(void)
Definition fs.c:2117
void FS_Init_SelfPack(void)
Definition fs.c:2299
#define Mem_AllocPool(name, flags, parent)
Definition zone.h:104

References COM_InitGameType(), FS_Init_Commands(), FS_Init_Dir(), FS_Init_SelfPack(), fs_mempool, Mem_AllocPool, NULL, and PK3_OpenLibrary().

Referenced by Host_Init().

◆ FS_Init_Commands()

void FS_Init_Commands ( void )

Definition at line 2117 of file fs.c.

2118{
2123
2124 Cmd_AddCommand(CF_SHARED, "gamedir", FS_GameDir_f, "changes active gamedir list, can take multiple arguments which shouldn't include the base directory, the last gamedir is the \"primary\" and files will be saved there (example usage: gamedir ctf id1)");
2125 Cmd_AddCommand(CF_SHARED, "fs_rescan", FS_Rescan_f, "rescans filesystem for new pack archives and any other changes");
2126 Cmd_AddCommand(CF_SHARED, "path", FS_Path_f, "print searchpath (game directories and archives)");
2127 Cmd_AddCommand(CF_SHARED, "dir", FS_Dir_f, "list files in searchpath matching an * filename pattern, one per line");
2128 Cmd_AddCommand(CF_SHARED, "ls", FS_Ls_f, "list files in searchpath matching an * filename pattern, multiple per line");
2129 Cmd_AddCommand(CF_SHARED, "which", FS_Which_f, "accepts a file name as argument and reports where the file is taken from");
2130
2131#ifdef __EMSCRIPTEN__
2133#endif
2134
2136 Cmd_AddCommand(CF_SHARED, "game", FS_GameDir_f, "alias of gamedir, for compatibility with some Quake mod READMEs");
2137}
void Cmd_AddCommand(unsigned flags, const char *cmd_name, xcommand_t function, const char *description)
called by the init functions of other parts of the program to register commands and functions to call...
Definition cmd.c:1661
#define CF_SHARED
Definition cmd.h:67
gamemode_t com_startupgamegroup
Definition com_game.c:36
@ GAME_NORMAL
Definition com_game.h:28
void Cvar_RegisterVariable(cvar_t *variable)
registers a cvar that already has the name, string, and optionally the archive elements set.
Definition cvar.c:599
void FS_Dir_f(cmd_state_t *cmd)
Definition fs.c:4053
void FS_Ls_f(cmd_state_t *cmd)
Definition fs.c:4058
static void FS_Rescan_f(cmd_state_t *cmd)
Definition fs.c:1623
cvar_t cvar_fs_gamedir
Definition fs.c:458
static void FS_GameDir_f(cmd_state_t *cmd)
Definition fs.c:1751
cvar_t fs_unload_dlcache
Definition fs.c:457
void FS_Which_f(cmd_state_t *cmd)
Definition fs.c:4063
cvar_t fs_empty_files_in_pack_mark_deletions
Definition fs.c:456
cvar_t scr_screenshot_name
Definition fs.c:455
static void FS_Path_f(cmd_state_t *cmd)
Definition fs.c:1052
void Sys_EM_Register_Commands(void)
Definition sys_wasm.c:279

References CF_SHARED, Cmd_AddCommand(), com_startupgamegroup, cvar_fs_gamedir, Cvar_RegisterVariable(), FS_Dir_f(), fs_empty_files_in_pack_mark_deletions, FS_GameDir_f(), FS_Ls_f(), FS_Path_f(), FS_Rescan_f(), fs_unload_dlcache, FS_Which_f(), GAME_NORMAL, scr_screenshot_name, and Sys_EM_Register_Commands().

Referenced by FS_Init().

◆ FS_Init_SelfPack()

void FS_Init_SelfPack ( void )

Definition at line 2299 of file fs.c.

2300{
2301 char *buf;
2302
2303 // Load darkplaces.opt from the FS.
2304 if (!Sys_CheckParm("-noopt"))
2305 {
2306 buf = (char *) FS_SysLoadFile("darkplaces.opt", tempmempool, true, NULL);
2307 if(buf)
2308 {
2310 Mem_Free(buf);
2311 }
2312 }
2313
2314#ifndef USE_RWOPS
2315 // Provide the SelfPack.
2316 if (!Sys_CheckParm("-noselfpack") && sys.selffd >= 0)
2317 {
2319 if(fs_selfpack)
2320 {
2322 if (!Sys_CheckParm("-noopt"))
2323 {
2324 buf = (char *) FS_LoadFile("darkplaces.opt", tempmempool, true, NULL);
2325 if(buf)
2326 {
2328 Mem_Free(buf);
2329 }
2330 }
2331 }
2332 }
2333#endif
2334}
static void COM_InsertFlags(const char *buf)
Definition fs.c:1911
static pack_t * FS_LoadPackPK3FromFD(const char *packfile, filedesc_t packhandle, qbool silent)
Definition fs.c:836
static void FS_AddSelfPack(void)
Definition fs.c:1519
unsigned char * FS_SysLoadFile(const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
Definition fs.c:3555
static pack_t * fs_selfpack
Definition fs.c:445
int selffd
Definition sys.h:148
const char ** argv
Definition sys.h:147
sys_t sys
Definition sys_shared.c:42
int Sys_CheckParm(const char *parm)
Definition sys_shared.c:327

References sys_t::argv, buf, COM_InsertFlags(), FS_AddSelfPack(), FS_LoadFile(), FS_LoadPackPK3FromFD(), fs_selfpack, FS_SysLoadFile(), Mem_Free, NULL, sys_t::selffd, sys, Sys_CheckParm(), and tempmempool.

Referenced by FS_Init().

◆ FS_IsRegisteredQuakePack()

qbool FS_IsRegisteredQuakePack ( const char * name)

Definition at line 4112 of file fs.c.

4113{
4114 searchpath_t *search;
4115 pack_t *pak;
4116
4117 // search through the path, one element at a time
4118 for (search = fs_searchpaths;search;search = search->next)
4119 {
4120 if (search->pack && !search->pack->vpack && !strcasecmp(FS_FileWithoutPath(search->filename), name))
4121 // TODO do we want to support vpacks in here too?
4122 {
4123 int (*strcmp_funct) (const char* str1, const char* str2);
4124 int left, right, middle;
4125
4126 pak = search->pack;
4127 strcmp_funct = pak->ignorecase ? strcasecmp : strcmp;
4128
4129 // Look for the file (binary search)
4130 left = 0;
4131 right = pak->numfiles - 1;
4132 while (left <= right)
4133 {
4134 int diff;
4135
4136 middle = (left + right) / 2;
4137 diff = strcmp_funct (pak->files[middle].name, "gfx/pop.lmp");
4138
4139 // Found it
4140 if (!diff)
4141 return true;
4142
4143 // If we're too far in the list
4144 if (diff > 0)
4145 right = middle - 1;
4146 else
4147 left = middle + 1;
4148 }
4149
4150 // we found the requested pack but it is not registered quake
4151 return false;
4152 }
4153 }
4154
4155 return false;
4156}
searchpath_t * fs_searchpaths
Definition fs.c:437
const char * FS_FileWithoutPath(const char *in)
Definition fs.c:1431
const GLchar * name
Definition glquake.h:601
Definition fs.c:386
int numfiles
Definition fs.c:391
qbool ignorecase
PK3 ignores case.
Definition fs.c:390
packfile_t * files
Definition fs.c:394
char name[MAX_QPATH]
Definition fs.c:378
struct searchpath_s * next
Definition fs.c:404
static vec3_t right
Definition sv_user.c:305

References searchpath_t::filename, pack_t::files, FS_FileWithoutPath(), fs_searchpaths, pack_t::ignorecase, int(), name, packfile_t::name, searchpath_t::next, pack_t::numfiles, searchpath_t::pack, right, and pack_t::vpack.

Referenced by SV_Download_f().

◆ FS_LoadFile()

unsigned char * FS_LoadFile ( const char * path,
mempool_t * pool,
qbool quiet,
fs_offset_t * filesizepointer )

Definition at line 3540 of file fs.c.

3541{
3542 qfile_t *file = FS_OpenVirtualFile(path, quiet);
3543 return FS_LoadAndCloseQFile(file, path, pool, quiet, filesizepointer);
3544}
qfile_t * FS_OpenVirtualFile(const char *filepath, qbool quiet)
Definition fs.c:2928
static unsigned char * FS_LoadAndCloseQFile(qfile_t *file, const char *path, mempool_t *pool, qbool quiet, fs_offset_t *filesizepointer)
Definition fs.c:3503

References FS_LoadAndCloseQFile(), and FS_OpenVirtualFile().

Referenced by CL_CutDemo(), CL_IPLog_Load(), CL_Locs_Reload_f(), CL_Particles_LoadEffectInfo(), CL_ReadPointFile_f(), CL_VM_Init(), Cmd_Exec(), Curl_FindPackURL(), decode_image(), fontfilecache_LoadFile(), FS_CRCFile(), FS_Init_SelfPack(), GetMapList(), gl_main_newmap(), Image_GetStockPicSize(), LoadFont(), loadimagepixelsbgra(), LoadSubtitles(), M_Setup_Draw(), Mod_LoadModel(), Mod_LoadQ3Shaders(), Mod_LoadSkinFiles(), Mod_PSKMODEL_Load(), Mod_Q1BSP_LoadLighting(), Mod_Q1BSP_LoadMapBrushes(), Mod_Q2BSP_LoadTexinfo(), OGG_LoadVorbisFile(), Palette_Load(), Palette_LoadQ2Colormap(), Palette_SetupSpecialPalettes(), PRVM_LoadLNO(), PRVM_PO_Load(), PRVM_Prog_Load(), R_InitParticleTexture(), R_LoadQWSkin(), R_LoadTextureDDSFile(), R_Shadow_LoadLightsFile(), R_Shadow_LoadWorldLights(), R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(), S_LoadWavFile(), ShaderModeInfo_GetShaderText(), SV_Loadgame_f(), SV_ParticleEffectIndex(), SV_Prepare_CSQC(), SV_SpawnServer(), VM_loadfromfile(), W_GetLumpName(), and XMP_LoadModFile().

◆ FS_OpenRealFile()

qfile_t * FS_OpenRealFile ( const char * filepath,
const char * mode,
qbool quiet )

Definition at line 2901 of file fs.c.

2902{
2903 char real_path [MAX_OSPATH];
2904
2905 if (FS_CheckNastyPath(filepath, false))
2906 {
2907 Con_Printf("FS_OpenRealFile(\"%s\", \"%s\", %s): nasty filename rejected\n", filepath, mode, quiet ? "true" : "false");
2908 return NULL;
2909 }
2910
2911 dpsnprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath); // this is never a vpack
2912
2913 // If the file is opened in "write", "append", or "read/write" mode,
2914 // create directories up to the file.
2915 if (mode[0] == 'w' || mode[0] == 'a' || strchr (mode, '+'))
2916 FS_CreatePath (real_path);
2917 return FS_SysOpen (real_path, mode, false);
2918}
char fs_gamedir[MAX_OSPATH]
Definition fs.c:443
qfile_t * FS_SysOpen(const char *filepath, const char *mode, qbool nonblocking)
Definition fs.c:2484
void FS_CreatePath(char *path)
Definition fs.c:1028
GLenum mode
Definition glquake.h:718

References Con_Printf(), dpsnprintf(), FS_CheckNastyPath(), FS_CreatePath(), fs_gamedir, FS_SysOpen(), MAX_OSPATH, mode, and NULL.

Referenced by CheckPendingDownloads(), CL_CutDemo(), CL_Locs_Save_f(), CL_ParseServerInfo(), CL_Record_f(), Con_ConDump_f(), Curl_Begin(), Curl_EndDownload(), FS_WriteFileInBlocks(), Host_SaveConfig(), JPEG_SaveImage_preflipped(), Key_History_Init(), Key_History_Shutdown(), Log_Open(), Log_Printf(), M_ScanSaves(), PNG_SaveImage_preflipped(), PRVM_Prog_Load(), R_GLSL_DumpShader_f(), SCR_CaptureVideo_Avi_BeginVideo(), SCR_CaptureVideo_Ogg_BeginVideo(), SV_Savegame_to(), SV_StartDemoRecording(), and VM_fopen().

◆ FS_OpenVirtualFile()

qfile_t * FS_OpenVirtualFile ( const char * filepath,
qbool quiet )

Definition at line 2928 of file fs.c.

2929{
2930 qfile_t *result = NULL;
2931 if (FS_CheckNastyPath(filepath, false))
2932 {
2933 Con_Printf("FS_OpenVirtualFile(\"%s\", %s): nasty filename rejected\n", filepath, quiet ? "true" : "false");
2934 return NULL;
2935 }
2936
2938 result = FS_OpenReadFile (filepath, quiet, false, 16);
2940 return result;
2941}
void * fs_mutex
Definition fs.c:435
static qfile_t * FS_OpenReadFile(const char *filename, qbool quiet, qbool nonblocking, int symlinkLevels)
Definition fs.c:2786
#define Thread_LockMutex(m)
Definition thread.h:17
#define Thread_UnlockMutex(m)
Definition thread.h:18

References Con_Printf(), FS_CheckNastyPath(), fs_mutex, FS_OpenReadFile(), NULL, Thread_LockMutex, and Thread_UnlockMutex.

Referenced by CL_PlayDemo(), FS_LoadFile(), GetMapList(), hz_bitstream_read_open(), jam_open(), LibAvW_OpenVideo(), QW_CL_CheckOrDownloadFile(), SV_Download_f(), VM_buf_loadfile(), VM_fopen(), and W_LoadTextureWadFile().

◆ FS_Print()

int FS_Print ( qfile_t * file,
const char * msg )

Definition at line 3261 of file fs.c.

3262{
3263 return (int)FS_Write (file, msg, strlen (msg));
3264}
fs_offset_t FS_Write(qfile_t *file, const void *data, size_t datasize)
Definition fs.c:3019

References FS_Write(), and strlen().

Referenced by Log_Close(), Log_ConPrint(), Log_Open(), PRVM_ED_Write(), PRVM_ED_WriteGlobals(), R_GLSL_DumpShader_f(), and SV_Savegame_to().

◆ FS_Printf()

int FS_Printf ( qfile_t * file,
const char * format,
... )

Definition at line 3273 of file fs.c.

3274{
3275 int result;
3276 va_list args;
3277
3278 va_start (args, format);
3279 result = FS_VPrintf (file, format, args);
3280 va_end (args);
3281
3282 return result;
3283}
int FS_VPrintf(qfile_t *file, const char *format, va_list ap)
Definition fs.c:3293
GLint GLint GLint GLsizei GLsizei GLenum format
Definition glquake.h:649

References format, and FS_VPrintf().

Referenced by CL_CutDemo(), CL_Locs_Save_f(), CL_ParseServerInfo(), CL_Record_f(), Crypto_SavePubKeyTextFile(), Cvar_WriteVariables(), Key_History_Shutdown(), Key_WriteBindings(), PRVM_ED_Write(), PRVM_ED_WriteGlobals(), PRVM_Prog_Load(), SV_Savegame_to(), and SV_StartDemoRecording().

◆ FS_Purge()

void FS_Purge ( qfile_t * file)

Definition at line 3487 of file fs.c.

3488{
3489 file->buff_len = 0;
3490 file->buff_ind = 0;
3491 file->ungetc = EOF;
3492}

Referenced by FS_Read(), FS_Seek(), and FS_Write().

◆ FS_Read()

fs_offset_t FS_Read ( qfile_t * file,
void * buffer,
size_t buffersize )

Definition at line 3066 of file fs.c.

3067{
3068 fs_offset_t count, done;
3069
3070 if (buffersize == 0 || !buffer)
3071 return 0;
3072
3073 // Get rid of the ungetc character
3074 if (file->ungetc != EOF)
3075 {
3076 ((char*)buffer)[0] = file->ungetc;
3077 buffersize--;
3078 file->ungetc = EOF;
3079 done = 1;
3080 }
3081 else
3082 done = 0;
3083
3084 if(file->flags & QFILE_FLAG_DATA)
3085 {
3086 size_t left = file->real_length - file->position;
3087 if(buffersize > left)
3088 buffersize = left;
3089 memcpy(buffer, file->data + file->position, buffersize);
3090 file->position += buffersize;
3091 return buffersize;
3092 }
3093
3094 // First, we copy as many bytes as we can from "buff"
3095 if (file->buff_ind < file->buff_len)
3096 {
3097 count = file->buff_len - file->buff_ind;
3098 count = ((fs_offset_t)buffersize > count) ? count : (fs_offset_t)buffersize;
3099 done += count;
3100 memcpy (buffer, &file->buff[file->buff_ind], count);
3101 file->buff_ind += count;
3102
3103 buffersize -= count;
3104 if (buffersize == 0)
3105 return done;
3106 }
3107
3108 // NOTE: at this point, the read buffer is always empty
3109
3110 // If the file isn't compressed
3111 if (! (file->flags & QFILE_FLAG_DEFLATED))
3112 {
3113 fs_offset_t nb;
3114
3115 // We must take care to not read after the end of the file
3116 count = file->real_length - file->position;
3117
3118 // If we have a lot of data to get, put them directly into "buffer"
3119 if (buffersize > sizeof (file->buff) / 2)
3120 {
3121 if (count > (fs_offset_t)buffersize)
3122 count = (fs_offset_t)buffersize;
3123 if (FILEDESC_SEEK (file->handle, file->offset + file->position, SEEK_SET) == -1)
3124 {
3125 // Seek failed. When reading from a pipe, and
3126 // the caller never called FS_Seek, this still
3127 // works fine. So no reporting this error.
3128 }
3129 nb = FILEDESC_READ (file->handle, &((unsigned char*)buffer)[done], count);
3130 if (nb > 0)
3131 {
3132 done += nb;
3133 file->position += nb;
3134
3135 // Purge cached data
3136 FS_Purge (file);
3137 }
3138 }
3139 else
3140 {
3141 if (count > (fs_offset_t)sizeof (file->buff))
3142 count = (fs_offset_t)sizeof (file->buff);
3143 if (FILEDESC_SEEK (file->handle, file->offset + file->position, SEEK_SET) == -1)
3144 {
3145 // Seek failed. When reading from a pipe, and
3146 // the caller never called FS_Seek, this still
3147 // works fine. So no reporting this error.
3148 }
3149 nb = FILEDESC_READ (file->handle, file->buff, count);
3150 if (nb > 0)
3151 {
3152 file->buff_len = nb;
3153 file->position += nb;
3154
3155 // Copy the requested data in "buffer" (as much as we can)
3156 count = (fs_offset_t)buffersize > file->buff_len ? file->buff_len : (fs_offset_t)buffersize;
3157 memcpy (&((unsigned char*)buffer)[done], file->buff, count);
3158 file->buff_ind = count;
3159 done += count;
3160 }
3161 }
3162
3163 return done;
3164 }
3165
3166 // If the file is compressed, it's more complicated...
3167 // We cycle through a few operations until we have read enough data
3168 while (buffersize > 0)
3169 {
3170 ztoolkit_t *ztk = file->ztk;
3171 int error;
3172
3173 // NOTE: at this point, the read buffer is always empty
3174
3175 // If "input" is also empty, we need to refill it
3176 if (ztk->in_ind == ztk->in_len)
3177 {
3178 // If we are at the end of the file
3179 if (file->position == file->real_length)
3180 return done;
3181
3182 count = (fs_offset_t)(ztk->comp_length - ztk->in_position);
3183 if (count > (fs_offset_t)sizeof (ztk->input))
3184 count = (fs_offset_t)sizeof (ztk->input);
3185 FILEDESC_SEEK (file->handle, file->offset + (fs_offset_t)ztk->in_position, SEEK_SET);
3186 if (FILEDESC_READ (file->handle, ztk->input, count) != count)
3187 {
3188 Con_Printf ("FS_Read: unexpected end of file\n");
3189 break;
3190 }
3191
3192 ztk->in_ind = 0;
3193 ztk->in_len = count;
3194 ztk->in_position += count;
3195 }
3196
3197 ztk->zstream.next_in = &ztk->input[ztk->in_ind];
3198 ztk->zstream.avail_in = (unsigned int)(ztk->in_len - ztk->in_ind);
3199
3200 // Now that we are sure we have compressed data available, we need to determine
3201 // if it's better to inflate it in "file->buff" or directly in "buffer"
3202
3203 // Inflate the data in "file->buff"
3204 if (buffersize < sizeof (file->buff) / 2)
3205 {
3206 ztk->zstream.next_out = file->buff;
3207 ztk->zstream.avail_out = sizeof (file->buff);
3208 error = qz_inflate (&ztk->zstream, Z_SYNC_FLUSH);
3209 if (error != Z_OK && error != Z_STREAM_END)
3210 {
3211 Con_Printf ("FS_Read: Can't inflate file\n");
3212 break;
3213 }
3214 ztk->in_ind = ztk->in_len - ztk->zstream.avail_in;
3215
3216 file->buff_len = (fs_offset_t)sizeof (file->buff) - ztk->zstream.avail_out;
3217 file->position += file->buff_len;
3218
3219 // Copy the requested data in "buffer" (as much as we can)
3220 count = (fs_offset_t)buffersize > file->buff_len ? file->buff_len : (fs_offset_t)buffersize;
3221 memcpy (&((unsigned char*)buffer)[done], file->buff, count);
3222 file->buff_ind = count;
3223 }
3224
3225 // Else, we inflate directly in "buffer"
3226 else
3227 {
3228 ztk->zstream.next_out = &((unsigned char*)buffer)[done];
3229 ztk->zstream.avail_out = (unsigned int)buffersize;
3230 error = qz_inflate (&ztk->zstream, Z_SYNC_FLUSH);
3231 if (error != Z_OK && error != Z_STREAM_END)
3232 {
3233 Con_Printf ("FS_Read: Can't inflate file\n");
3234 break;
3235 }
3236 ztk->in_ind = ztk->in_len - ztk->zstream.avail_in;
3237
3238 // How much data did it inflate?
3239 count = (fs_offset_t)(buffersize - ztk->zstream.avail_out);
3240 file->position += count;
3241
3242 // Purge cached data
3243 FS_Purge (file);
3244 }
3245
3246 done += count;
3247 buffersize -= count;
3248 }
3249
3250 return done;
3251}
#define QFILE_FLAG_DEFLATED
file is compressed using the deflate algorithm (PK3 only)
Definition fs.c:296
#define FILEDESC_READ
Definition fs.c:109
void FS_Purge(qfile_t *file)
Definition fs.c:3487
#define Z_SYNC_FLUSH
Definition fs.c:231
#define FILEDESC_SEEK
Definition fs.c:112
GLuint buffer
Definition glquake.h:630
GLenum GLenum GLsizei count
Definition glquake.h:656
void error(string err,...)
size_t in_ind
Definition fs.c:307
size_t comp_length
length of the compressed file
Definition fs.c:306
size_t in_position
position in the compressed file
Definition fs.c:308
unsigned char input[FILE_BUFF_SIZE]
Definition fs.c:309
size_t in_len
input buffer current index and length
Definition fs.c:307
z_stream zstream
Definition fs.c:305

References z_stream::avail_in, z_stream::avail_out, buffer, ztoolkit_t::comp_length, Con_Printf(), count, error(), FILEDESC_READ, FILEDESC_SEEK, FS_Purge(), ztoolkit_t::in_ind, ztoolkit_t::in_len, ztoolkit_t::in_position, ztoolkit_t::input, int(), z_stream::next_in, z_stream::next_out, QFILE_FLAG_DATA, QFILE_FLAG_DEFLATED, Z_OK, Z_STREAM_END, Z_SYNC_FLUSH, and ztoolkit_t::zstream.

Referenced by CL_ReadDemoMessage(), Crypto_LoadFile(), Curl_Begin(), FS_Getc(), FS_LoadAndCloseQFile(), FS_OpenReadFile(), FS_Seek(), FS_SysCheckGameDir(), GetMapList(), hz_bitstream_read_blocks_read(), jam_open(), jam_video(), LibAvW_FS_Read(), M_ScanSaves(), SV_ReadClientMessage(), SV_SendClientDatagram(), W_GetTextureBGRA(), and W_LoadTextureWadFile().

◆ FS_RemoveOnClose()

void FS_RemoveOnClose ( qfile_t * file)

Definition at line 3007 of file fs.c.

3008{
3009 file->flags |= QFILE_FLAG_REMOVE;
3010}

References QFILE_FLAG_REMOVE.

Referenced by CL_Stop_f(), and SV_StopDemoRecording().

◆ FS_Rescan()

void FS_Rescan ( void )

Definition at line 1538 of file fs.c.

1539{
1540 int i;
1541 char gamedirbuf[MAX_INPUTLINE];
1542 char vabuf[1024];
1543
1545
1547
1548 // update the com_modname (used for server info)
1549 if (gamedirname2 && gamedirname2[0])
1551 else
1553
1554 // -game <gamedir>
1555 // Adds basedir/gamedir as an override game
1556 // LadyHavoc: now supports multiple -game directories
1557 // set the com_modname (reported in server info)
1558 *gamedirbuf = 0;
1559 for (i = 0;i < fs_numgamedirs;i++)
1560 {
1562 // update the com_modname (used server info)
1564 if(i)
1565 dp_strlcat(gamedirbuf, va(vabuf, sizeof(vabuf), " %s", fs_gamedirs[i]), sizeof(gamedirbuf));
1566 else
1567 dp_strlcpy(gamedirbuf, fs_gamedirs[i], sizeof(gamedirbuf));
1568 }
1569 Cvar_SetQuick(&cvar_fs_gamedir, gamedirbuf); // so QC or console code can query it
1570
1571 // add back the selfpack as new first item
1573
1574 if (cls.state != ca_dedicated)
1575 {
1576 // set the default screenshot name to either the mod name or the
1577 // gamemode screenshot name
1578 if (strcmp(com_modname, gamedirname1))
1580 else
1582 }
1583
1584 if((i = Sys_CheckParm("-modname")) && i < sys.argc - 1)
1586
1587 // If "-condebug" is in the command line, remove the previous log file
1588 if (Sys_CheckParm ("-condebug") != 0)
1589 unlink (va(vabuf, sizeof(vabuf), "%s/qconsole.log", fs_gamedir));
1590
1591 // look for the pop.lmp file and set registered to true if it is found
1592 if (FS_FileExists("gfx/pop.lmp"))
1594 switch(gamemode)
1595 {
1596 case GAME_NORMAL:
1597 case GAME_HIPNOTIC:
1598 case GAME_ROGUE:
1599 if (!registered.integer)
1600 {
1601 if (fs_numgamedirs > 1)
1602 Con_Print("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n");
1603 else
1604 Con_Print("Playing shareware version.\n");
1605 }
1606 else
1607 Con_Print("Playing registered version.\n");
1608 break;
1609 case GAME_STEELSTORM:
1610 if (registered.integer)
1611 Con_Print("Playing registered version.\n");
1612 else
1613 Con_Print("Playing shareware version.\n");
1614 break;
1615 default:
1616 break;
1617 }
1618
1619 // unload all wads so that future queries will return the new data
1620 W_UnloadAll();
1621}
@ ca_dedicated
Definition client.h:530
char com_modname[MAX_OSPATH]
Definition com_game.c:33
const char * gamescreenshotname
Definition com_game.c:31
const char * gamedirname2
Definition com_game.c:30
gamemode_t gamemode
Definition com_game.c:26
const char * gamedirname1
Definition com_game.c:29
@ GAME_ROGUE
Definition com_game.h:30
@ GAME_STEELSTORM
added by motorsep
Definition com_game.h:53
@ GAME_HIPNOTIC
Definition com_game.h:29
cvar_t registered
Definition common.c:32
#define dp_strlcpy(dst, src, dsize)
Definition common.h:303
void Cvar_SetValueQuick(cvar_t *var, float value)
Definition cvar.c:473
void Cvar_SetQuick(cvar_t *var, const char *value)
Definition cvar.c:436
static void FS_ClearSearchPath(void)
Definition fs.c:1451
char fs_gamedirs[MAX_GAMEDIRS][MAX_QPATH]
Definition fs.c:449
static void FS_AddGameHierarchy(const char *dir)
Definition fs.c:1387
int fs_numgamedirs
Definition fs.c:448
static void FS_ListGameDirs(void)
Definition fs.c:1854
const char * FS_FileExists(const char *filename)
Look for a file in the packages and in the filesystem Returns its canonical name (same case as used i...
Definition fs.c:3693
int i
#define MAX_INPUTLINE
maximum size of console commandline, QuakeC strings, and many other text processing buffers
Definition qdefs.h:94
cactive_t state
Definition client.h:568
int integer
Definition cvar.h:73
int argc
Definition sys.h:146
void W_UnloadAll(void)
Definition wad.c:87

References sys_t::argc, sys_t::argv, ca_dedicated, cls, com_modname, Con_Print(), cvar_fs_gamedir, Cvar_SetQuick(), Cvar_SetValueQuick(), dp_strlcat, dp_strlcpy, FS_AddGameHierarchy(), FS_AddSelfPack(), FS_ClearSearchPath(), FS_FileExists(), fs_gamedir, fs_gamedirs, FS_ListGameDirs(), fs_numgamedirs, GAME_HIPNOTIC, GAME_NORMAL, GAME_ROGUE, GAME_STEELSTORM, gamedirname1, gamedirname2, gamemode, gamescreenshotname, i, cvar_t::integer, MAX_INPUTLINE, registered, scr_screenshot_name, client_static_t::state, sys, Sys_CheckParm(), va(), and W_UnloadAll().

Referenced by CL_StopDownload(), FS_ChangeGameDirs(), FS_Init_Dir(), and FS_Rescan_f().

◆ FS_SanitizePath()

void FS_SanitizePath ( char * path)

Definition at line 2673 of file fs.c.

2674{
2675 for (; *path; path++)
2676 if (*path == '\\')
2677 *path = '/';
2678}

Referenced by loadimagepixelsbgra().

◆ FS_Search()

fssearch_t * FS_Search ( const char * pattern,
int caseinsensitive,
int quiet,
const char * packfile )

Definition at line 3756 of file fs.c.

3757{
3758 fssearch_t *search;
3759 searchpath_t *searchpath;
3760 pack_t *pak;
3761 int i, basepathlength, numfiles, numchars, resultlistindex, dirlistindex;
3762 stringlist_t resultlist;
3763 stringlist_t dirlist;
3764 stringlist_t matchedSet, foundSet;
3765 const char *start, *slash, *backslash, *colon, *separator;
3766 char *basepath;
3767
3768 for (i = 0;pattern[i] == '.' || pattern[i] == ':' || pattern[i] == '/' || pattern[i] == '\\';i++)
3769 ;
3770
3771 if (i > 0)
3772 {
3773 Con_Printf("Don't use punctuation at the beginning of a search pattern!\n");
3774 return NULL;
3775 }
3776
3777 stringlistinit(&resultlist);
3778 stringlistinit(&dirlist);
3779 search = NULL;
3780 slash = strrchr(pattern, '/');
3781 backslash = strrchr(pattern, '\\');
3782 colon = strrchr(pattern, ':');
3783 separator = max(slash, backslash);
3784 separator = max(separator, colon);
3785 basepathlength = separator ? (separator + 1 - pattern) : 0;
3786 basepath = (char *)Mem_Alloc (tempmempool, basepathlength + 1);
3787 if (basepathlength)
3788 memcpy(basepath, pattern, basepathlength);
3789 basepath[basepathlength] = 0;
3790
3791 // search through the path, one element at a time
3792 for (searchpath = fs_searchpaths;searchpath;searchpath = searchpath->next)
3793 {
3794 // is the element a pak file?
3795 if (searchpath->pack && !searchpath->pack->vpack)
3796 {
3797 // look through all the pak file elements
3798 pak = searchpath->pack;
3799 if(packfile)
3800 {
3801 if(strcmp(packfile, pak->shortname))
3802 continue;
3803 }
3804 for (i = 0;i < pak->numfiles;i++)
3805 {
3806 char temp[MAX_OSPATH];
3807 dp_strlcpy(temp, pak->files[i].name, sizeof(temp));
3808 while (temp[0])
3809 {
3810 if (matchpattern(temp, (char *)pattern, true))
3811 {
3812 for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
3813 if (!strcmp(resultlist.strings[resultlistindex], temp))
3814 break;
3815 if (resultlistindex == resultlist.numstrings)
3816 {
3817 stringlistappend(&resultlist, temp);
3818 if (!quiet && developer_loading.integer)
3819 Con_Printf("SearchPackFile: %s : %s\n", pak->filename, temp);
3820 }
3821 }
3822 // strip off one path element at a time until empty
3823 // this way directories are added to the listing if they match the pattern
3824 slash = strrchr(temp, '/');
3825 backslash = strrchr(temp, '\\');
3826 colon = strrchr(temp, ':');
3827 separator = temp;
3828 if (separator < slash)
3829 separator = slash;
3830 if (separator < backslash)
3831 separator = backslash;
3832 if (separator < colon)
3833 separator = colon;
3834 *((char *)separator) = 0;
3835 }
3836 }
3837 }
3838 else
3839 {
3840 if(packfile)
3841 continue;
3842
3843 start = pattern;
3844
3845 stringlistinit(&matchedSet);
3846 stringlistinit(&foundSet);
3847 // add a first entry to the set
3848 stringlistappend(&matchedSet, "");
3849 // iterate through pattern's path
3850 while (*start)
3851 {
3852 const char *asterisk, *wildcard, *nextseparator, *prevseparator;
3853 char subpath[MAX_OSPATH];
3854 char subpattern[MAX_OSPATH];
3855
3856 // find the next wildcard
3857 wildcard = strchr(start, '?');
3858 asterisk = strchr(start, '*');
3859 if (asterisk && (!wildcard || asterisk < wildcard))
3860 {
3861 wildcard = asterisk;
3862 }
3863
3864 if (wildcard)
3865 {
3866 nextseparator = strchr( wildcard, '/' );
3867 }
3868 else
3869 {
3870 nextseparator = NULL;
3871 }
3872
3873 if( !nextseparator ) {
3874 nextseparator = start + strlen( start );
3875 }
3876
3877 // prevseparator points past the '/' right before the wildcard and nextseparator at the one following it (or at the end of the string)
3878 // copy everything up except nextseperator
3879 dp_ustr2stp(subpattern, sizeof(subpattern), pattern, nextseparator - pattern);
3880 // find the last '/' before the wildcard
3881 prevseparator = strrchr( subpattern, '/' );
3882 if (!prevseparator)
3883 prevseparator = subpattern;
3884 else
3885 prevseparator++;
3886 // copy everything from start to the previous including the '/' (before the wildcard)
3887 // everything up to start is already included in the path of matchedSet's entries
3888 dp_ustr2stp(subpath, sizeof(subpath), start, (prevseparator - subpattern) - (start - pattern));
3889
3890 // for each entry in matchedSet try to open the subdirectories specified in subpath
3891 for( dirlistindex = 0 ; dirlistindex < matchedSet.numstrings ; dirlistindex++ ) {
3892 char temp[MAX_OSPATH];
3893 dp_strlcpy( temp, matchedSet.strings[ dirlistindex ], sizeof(temp) );
3894 dp_strlcat( temp, subpath, sizeof(temp) );
3895 listdirectory( &foundSet, searchpath->filename, temp );
3896 }
3897 if( dirlistindex == 0 ) {
3898 break;
3899 }
3900 // reset the current result set
3901 stringlistfreecontents( &matchedSet );
3902 // match against the pattern
3903 for( dirlistindex = 0 ; dirlistindex < foundSet.numstrings ; dirlistindex++ ) {
3904 const char *direntry = foundSet.strings[ dirlistindex ];
3905 if (matchpattern(direntry, subpattern, true)) {
3906 stringlistappend( &matchedSet, direntry );
3907 }
3908 }
3909 stringlistfreecontents( &foundSet );
3910
3911 start = nextseparator;
3912 }
3913
3914 for (dirlistindex = 0;dirlistindex < matchedSet.numstrings;dirlistindex++)
3915 {
3916 const char *matchtemp = matchedSet.strings[dirlistindex];
3917 if (matchpattern(matchtemp, (char *)pattern, true))
3918 {
3919 for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
3920 if (!strcmp(resultlist.strings[resultlistindex], matchtemp))
3921 break;
3922 if (resultlistindex == resultlist.numstrings)
3923 {
3924 stringlistappend(&resultlist, matchtemp);
3925 if (!quiet && developer_loading.integer)
3926 Con_Printf("SearchDirFile: %s\n", matchtemp);
3927 }
3928 }
3929 }
3930 stringlistfreecontents( &matchedSet );
3931 }
3932 }
3933
3934 if (resultlist.numstrings)
3935 {
3936 stringlistsort(&resultlist, true);
3937 numfiles = resultlist.numstrings;
3938 numchars = 0;
3939 for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
3940 numchars += (int)strlen(resultlist.strings[resultlistindex]) + 1;
3941 search = (fssearch_t *)Z_Malloc(sizeof(fssearch_t) + numchars + numfiles * sizeof(char *));
3942 search->filenames = (char **)((char *)search + sizeof(fssearch_t));
3943 search->filenamesbuffer = (char *)((char *)search + sizeof(fssearch_t) + numfiles * sizeof(char *));
3944 search->numfilenames = (int)numfiles;
3945 numfiles = 0;
3946 numchars = 0;
3947 for (resultlistindex = 0;resultlistindex < resultlist.numstrings;resultlistindex++)
3948 {
3949 size_t textlen;
3950 search->filenames[numfiles] = search->filenamesbuffer + numchars;
3951 textlen = strlen(resultlist.strings[resultlistindex]) + 1;
3952 memcpy(search->filenames[numfiles], resultlist.strings[resultlistindex], textlen);
3953 numfiles++;
3954 numchars += (int)textlen;
3955 }
3956 }
3957 stringlistfreecontents(&resultlist);
3958
3959 Mem_Free(basepath);
3960 return search;
3961}
char * dp_ustr2stp(char *dst, size_t dsize, const char *src, size_t slen)
Copies a measured byte sequence (unterminated string) to a null-terminated string.
Definition common.c:1388
void stringlistfreecontents(stringlist_t *list)
Definition filematch.c:87
void stringlistinit(stringlist_t *list)
Definition filematch.c:82
void stringlistsort(stringlist_t *list, qbool uniq)
Definition filematch.c:129
int matchpattern(const char *in, const char *pattern, int caseinsensitive)
Definition filematch.c:16
void stringlistappend(stringlist_t *list, const char *text)
Definition filematch.c:103
void listdirectory(stringlist_t *list, const char *basepath, const char *path)
Definition filematch.c:198
cvar_t developer_loading
Definition host.c:52
char ** filenames
Definition fs.h:117
int numfilenames
Definition fs.h:116
char * filenamesbuffer
Definition fs.h:119
char shortname[MAX_QPATH]
Definition fs.c:388
char filename[MAX_OSPATH]
Definition fs.c:387
char ** strings
Definition filematch.h:31
#define Z_Malloc(size)
Definition zone.h:161

References Con_Printf(), developer_loading, dp_strlcat, dp_strlcpy, dp_ustr2stp(), pack_t::filename, searchpath_t::filename, fssearch_t::filenames, fssearch_t::filenamesbuffer, pack_t::files, fs_searchpaths, i, int(), cvar_t::integer, listdirectory(), matchpattern(), max, MAX_OSPATH, Mem_Alloc, Mem_Free, packfile_t::name, searchpath_t::next, NULL, fssearch_t::numfilenames, pack_t::numfiles, stringlist_t::numstrings, searchpath_t::pack, pack_t::shortname, stringlistappend(), stringlistfreecontents(), stringlistinit(), stringlistsort(), stringlist_t::strings, strlen(), tempmempool, pack_t::vpack, and Z_Malloc.

Referenced by Cmd_Exec_f(), Con_CompleteCommandLine(), FS_ListDirectory(), GetMapList(), Image_FixTransparentPixels_f(), Mod_LoadQ3Shaders(), and VM_search_begin().

◆ FS_Seek()

int FS_Seek ( qfile_t * file,
fs_offset_t offset,
int whence )

Definition at line 3359 of file fs.c.

3360{
3361 ztoolkit_t *ztk;
3362 unsigned char* buffer;
3363 fs_offset_t buffersize;
3364
3365 // Compute the file offset
3366 switch (whence)
3367 {
3368 case SEEK_CUR:
3369 offset += file->position - file->buff_len + file->buff_ind;
3370 break;
3371
3372 case SEEK_SET:
3373 break;
3374
3375 case SEEK_END:
3376 offset += file->real_length;
3377 break;
3378
3379 default:
3380 return -1;
3381 }
3382 if (offset < 0 || offset > file->real_length)
3383 return -1;
3384
3385 if(file->flags & QFILE_FLAG_DATA)
3386 {
3387 file->position = offset;
3388 return 0;
3389 }
3390
3391 // If we have the data in our read buffer, we don't need to actually seek
3392 if (file->position - file->buff_len <= offset && offset <= file->position)
3393 {
3394 file->buff_ind = offset + file->buff_len - file->position;
3395 return 0;
3396 }
3397
3398 // Purge cached data
3399 FS_Purge (file);
3400
3401 // Unpacked or uncompressed files can seek directly
3402 if (! (file->flags & QFILE_FLAG_DEFLATED))
3403 {
3404 if (FILEDESC_SEEK (file->handle, file->offset + offset, SEEK_SET) == -1)
3405 return -1;
3406 file->position = offset;
3407 return 0;
3408 }
3409
3410 // Seeking in compressed files is more a hack than anything else,
3411 // but we need to support it, so here we go.
3412 ztk = file->ztk;
3413
3414 // If we have to go back in the file, we need to restart from the beginning
3416 {
3417 ztk->in_ind = 0;
3418 ztk->in_len = 0;
3419 ztk->in_position = 0;
3420 file->position = 0;
3421 if (FILEDESC_SEEK (file->handle, file->offset, SEEK_SET) == -1)
3422 Con_Printf("IMPOSSIBLE: couldn't seek in already opened pk3 file.\n");
3423
3424 // Reset the Zlib stream
3425 ztk->zstream.next_in = ztk->input;
3426 ztk->zstream.avail_in = 0;
3427 qz_inflateReset (&ztk->zstream);
3428 }
3429
3430 // We need a big buffer to force inflating into it directly
3431 buffersize = 2 * sizeof (file->buff);
3432 buffer = (unsigned char *)Mem_Alloc (tempmempool, buffersize);
3433
3434 // Skip all data until we reach the requested offset
3435 while (offset > (file->position - file->buff_len + file->buff_ind))
3436 {
3437 fs_offset_t diff = offset - (file->position - file->buff_len + file->buff_ind);
3438 fs_offset_t count, len;
3439
3440 count = (diff > buffersize) ? buffersize : diff;
3441 len = FS_Read (file, buffer, count);
3442 if (len != count)
3443 {
3444 Mem_Free (buffer);
3445 return -1;
3446 }
3447 }
3448
3449 Mem_Free (buffer);
3450 return 0;
3451}
GLuint GLuint GLintptr offset
Definition glquake.h:632
return position

References z_stream::avail_in, buffer, Con_Printf(), count, FILEDESC_SEEK, FS_Purge(), FS_Read(), ztoolkit_t::in_ind, ztoolkit_t::in_len, ztoolkit_t::in_position, ztoolkit_t::input, Mem_Alloc, Mem_Free, z_stream::next_in, offset, position, QFILE_FLAG_DATA, QFILE_FLAG_DEFLATED, tempmempool, and ztoolkit_t::zstream.

Referenced by CheckPendingDownloads(), CL_ReadDemoMessage(), GetMapList(), LibAvW_FS_Seek(), SCR_CaptureVideo_Avi_BeginVideo(), SCR_CaptureVideo_Avi_EndVideo(), SCR_CaptureVideo_RIFF_Finish(), SCR_CaptureVideo_RIFF_MakeIxChunk(), SCR_CaptureVideo_RIFF_Pop(), SV_ReadClientMessage(), W_GetTextureBGRA(), and W_LoadTextureWadFile().

◆ FS_SetGameDirs()

addgamedirs_t FS_SetGameDirs ( int numgamedirs,
const char * gamedirs[],
qbool failmissing,
qbool abortonfail )

Definition at line 1633 of file fs.c.

1634{
1635 int i, j, k;
1636 const char *p;
1637 const char *gamedirs_ok[MAX_GAMEDIRS + 2];
1638 int numgamedirs_ok;
1639
1640 // prepend the game-specific gamedirs (the primary and search order can be overriden)
1641 gamedirs_ok[0] = gamedirname1;
1642 numgamedirs_ok = 1;
1643 if (gamedirname2 && gamedirname2[0])
1644 {
1645 gamedirs_ok[1] = gamedirname2;
1646 ++numgamedirs_ok;
1647 }
1648
1649 // check the game-specific gamedirs
1650 for (i = 0; i < numgamedirs_ok; ++i)
1651 {
1652 p = FS_CheckGameDir(gamedirs_ok[i]);
1653 if(!p)
1654 Sys_Error("BUG: nasty gamedir name \"%s\" in gamemode_info", gamedirs_ok[i]);
1655 if(p == fs_checkgamedir_missing && failmissing)
1656 {
1657 Con_Printf(abortonfail ? CON_ERROR : CON_WARN "Base gamedir \"%s\" empty or not found!\n", gamedirs_ok[i]);
1658 if (abortonfail)
1659 return GAMEDIRS_FAILURE; // missing gamedirs
1660 }
1661 }
1662
1663 // copy and check the user-specified gamedirs
1664 for (i = 0; i < numgamedirs && (size_t)numgamedirs_ok < sizeof(gamedirs_ok) / sizeof(gamedirs_ok[0]); ++i)
1665 {
1666 // remove any previously-added duplicate (last one wins)
1667 for (j = 0; j < numgamedirs_ok; ++j)
1668 if (!strcasecmp(gamedirs_ok[j], gamedirs[i]))
1669 {
1670 --numgamedirs_ok;
1671 for (k = j; k < numgamedirs_ok; ++k)
1672 gamedirs_ok[k] = gamedirs_ok[k + 1];
1673 }
1674
1675 // if string is nasty, reject it
1676 p = FS_CheckGameDir(gamedirs[i]);
1677 if(!p)
1678 {
1679 Con_Printf(abortonfail ? CON_ERROR : CON_WARN "Nasty gamedir name \"%s\" rejected\n", gamedirs[i]);
1680 if (abortonfail)
1681 return GAMEDIRS_FAILURE; // nasty gamedirs
1682 else
1683 continue;
1684 }
1685 if(p == fs_checkgamedir_missing && failmissing)
1686 {
1687 Con_Printf(abortonfail ? CON_ERROR : CON_WARN "Gamedir \"%s\" empty or not found!\n", gamedirs[i]);
1688 if (abortonfail)
1689 return GAMEDIRS_FAILURE; // missing gamedirs
1690 else
1691 continue;
1692 }
1693
1694 gamedirs_ok[numgamedirs_ok++] = gamedirs[i];
1695 }
1696
1697 if (fs_numgamedirs == numgamedirs_ok)
1698 {
1699 for (i = 0;i < numgamedirs_ok;i++)
1700 if (strcasecmp(fs_gamedirs[i], gamedirs_ok[i]))
1701 break;
1702 if (i == numgamedirs_ok)
1703 return GAMEDIRS_ALLGOOD; // already using this set of gamedirs, do nothing
1704 }
1705
1706 if (numgamedirs_ok > MAX_GAMEDIRS)
1707 {
1708 Con_Printf(abortonfail ? CON_ERROR : CON_WARN "That is too many gamedirs (%i > %i)\n", numgamedirs_ok, MAX_GAMEDIRS);
1709 if (abortonfail)
1710 return GAMEDIRS_FAILURE; // too many gamedirs
1711 }
1712
1713 for (i = 0, fs_numgamedirs = 0; i < numgamedirs_ok && fs_numgamedirs < MAX_GAMEDIRS; ++i)
1714 dp_strlcpy(fs_gamedirs[fs_numgamedirs++], gamedirs_ok[i], sizeof(fs_gamedirs[0]));
1715
1716 return GAMEDIRS_SUCCESS;
1717}
#define CON_WARN
Definition console.h:101
#define CON_ERROR
Definition console.h:102
const char * FS_CheckGameDir(const char *gamedir)
Definition fs.c:1824
#define MAX_GAMEDIRS
Definition fs.h:46
void Sys_Error(const char *error,...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN
Causes the entire program to exit ASAP.
Definition sys_shared.c:724

References CON_ERROR, Con_Printf(), CON_WARN, dp_strlcpy, FS_CheckGameDir(), fs_checkgamedir_missing, fs_gamedirs, fs_numgamedirs, gamedirname1, gamedirname2, GAMEDIRS_ALLGOOD, GAMEDIRS_FAILURE, GAMEDIRS_SUCCESS, i, MAX_GAMEDIRS, and Sys_Error().

Referenced by COM_ChangeGameTypeForGameDirs().

◆ FS_Shutdown()

void FS_Shutdown ( void )

Definition at line 2364 of file fs.c.

2365{
2366 // close all pack files and such
2367 // (hopefully there aren't any other open files, but they'll be cleaned up
2368 // by the OS anyway)
2372
2373#ifdef WIN32
2374 Sys_FreeLibrary (&shfolder_dll);
2375 Sys_FreeLibrary (&shell32_dll);
2376 Sys_FreeLibrary (&ole32_dll);
2377#endif
2378
2379 if (fs_mutex)
2381}
static void PK3_CloseLibrary(void)
Definition fs.c:566
void Sys_FreeLibrary(dllhandle_t *handle)
Definition sys_shared.c:245
#define Thread_DestroyMutex(m)
Definition thread.h:16
#define Mem_FreePool(pool)
Definition zone.h:105

References FS_ClearSearchPath(), fs_mempool, fs_mutex, Mem_FreePool, PK3_CloseLibrary(), Sys_FreeLibrary(), and Thread_DestroyMutex.

◆ FS_StripExtension()

void FS_StripExtension ( const char * in,
char * out,
size_t size_out )

Definition at line 3611 of file fs.c.

3612{
3613 char *last = NULL;
3614 char currentchar;
3615
3616 if (size_out == 0)
3617 return;
3618
3619 while ((currentchar = *in) && size_out > 1)
3620 {
3621 if (currentchar == '.')
3622 last = out;
3623 else if (currentchar == '/' || currentchar == '\\' || currentchar == ':')
3624 last = NULL;
3625 *out++ = currentchar;
3626 in++;
3627 size_out--;
3628 }
3629 if (last)
3630 *last = 0;
3631 else
3632 *out = 0;
3633}

References NULL.

Referenced by CL_ParseServerInfo(), CL_SetupWorldModel(), COM_InitGameType(), dpvsimpledecode_open(), Image_StripImageExtension(), jam_open(), LibAvW_OpenVideo(), Mod_Decompile_f(), Mod_PSKMODEL_Load(), Mod_Q1BSP_LoadLighting(), Mod_Q1BSP_LoadMapBrushes(), Mod_Q1BSP_LoadTextures(), Mod_Q3BSP_LoadLightmaps(), PRVM_LoadLNO(), R_LoadTextureDDSFile(), and SV_SpawnServer().

◆ FS_SysFileExists()

qbool FS_SysFileExists ( const char * filename)

Look for a file in the filesystem only.

Definition at line 3744 of file fs.c.

3745{
3746 return FS_SysFileType (path) != FS_FILETYPE_NONE;
3747}

References FS_FILETYPE_NONE, and FS_SysFileType().

Referenced by FS_FindFile(), SCR_ScreenShot_f(), and Sys_FindInPATH().

◆ FS_SysFileType()

int FS_SysFileType ( const char * filename)

Look for a file in the filesystem only.

Definition at line 3708 of file fs.c.

3709{
3710#ifdef WIN32
3711 // Sajt - some older sdks are missing this define
3712# ifndef INVALID_FILE_ATTRIBUTES
3713# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
3714# endif
3715 WPATHDEF(pathw);
3716 DWORD result;
3717
3718 WIDE(path, pathw);
3719 result = GetFileAttributesW(pathw);
3720
3721 if(result == INVALID_FILE_ATTRIBUTES)
3722 return FS_FILETYPE_NONE;
3723
3724 if(result & FILE_ATTRIBUTE_DIRECTORY)
3725 return FS_FILETYPE_DIRECTORY;
3726
3727 return FS_FILETYPE_FILE;
3728#else
3729 struct stat buf;
3730
3731 if (stat (path,&buf) == -1)
3732 return FS_FILETYPE_NONE;
3733
3734#ifndef S_ISDIR
3735#define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR)
3736#endif
3737 if(S_ISDIR(buf.st_mode))
3738 return FS_FILETYPE_DIRECTORY;
3739
3740 return FS_FILETYPE_FILE;
3741#endif
3742}
#define WPATHDEF(var)
Definition fs.c:84
#define S_ISDIR(a)
#define FS_FILETYPE_DIRECTORY
Definition fs.h:139
#define WIDE(str, wstr)
Definition utf8lib.h:106

References buf, FS_FILETYPE_DIRECTORY, FS_FILETYPE_FILE, FS_FILETYPE_NONE, S_ISDIR, WIDE, and WPATHDEF.

Referenced by FS_FileType(), and FS_SysFileExists().

◆ FS_SysLoadFile()

unsigned char * FS_SysLoadFile ( const char * path,
mempool_t * pool,
qbool quiet,
fs_offset_t * filesizepointer )

Definition at line 3555 of file fs.c.

3556{
3557 qfile_t *file = FS_SysOpen(path, "rb", false);
3558 return FS_LoadAndCloseQFile(file, path, pool, quiet, filesizepointer);
3559}

References FS_LoadAndCloseQFile(), and FS_SysOpen().

Referenced by FS_Init_SelfPack(), and listdirectory().

◆ FS_SysOpen()

qfile_t * FS_SysOpen ( const char * filepath,
const char * mode,
qbool nonblocking )

Definition at line 2484 of file fs.c.

2485{
2486 qfile_t* file;
2487
2488 file = (qfile_t *)Mem_Alloc (fs_mempool, sizeof (*file));
2489 file->ungetc = EOF;
2490 file->handle = FS_SysOpenFiledesc(filepath, mode, nonblocking);
2491 if (!FILEDESC_ISVALID(file->handle))
2492 {
2493 Mem_Free (file);
2494 return NULL;
2495 }
2496
2497 file->filename = Mem_strdup(fs_mempool, filepath);
2498
2499 file->real_length = FILEDESC_SEEK (file->handle, 0, SEEK_END);
2500
2501 // For files opened in append mode, we start at the end of the file
2502 if (mode[0] == 'a')
2503 file->position = file->real_length;
2504 else
2505 FILEDESC_SEEK (file->handle, 0, SEEK_SET);
2506
2507 return file;
2508}
#define FILEDESC_ISVALID(fd)
Definition fs.c:108
static filedesc_t FS_SysOpenFiledesc(const char *filepath, const char *mode, qbool nonblocking)
Definition fs.c:2383
#define Mem_strdup(pool, s)
Definition zone.h:97

References FILEDESC_ISVALID, FILEDESC_SEEK, fs_mempool, FS_SysOpenFiledesc(), Mem_Alloc, Mem_Free, Mem_strdup, mode, and NULL.

Referenced by Crypto_KeyGen_f(), Crypto_KeyGen_Finished(), Crypto_LoadFile(), Crypto_SavePubKeyTextFile(), FS_OpenReadFile(), FS_OpenRealFile(), FS_SysCheckGameDir(), FS_SysLoadFile(), and Host_LockSession().

◆ FS_SysOpenFD()

int FS_SysOpenFD ( const char * filepath,
const char * mode,
qbool nonblocking )

Definition at line 2468 of file fs.c.

2469{
2470#ifdef USE_RWOPS
2471 return -1;
2472#else
2473 return FS_SysOpenFiledesc(filepath, mode, nonblocking);
2474#endif
2475}

References FS_SysOpenFiledesc(), and mode.

Referenced by Sys_ProvideSelfFD().

◆ FS_Tell()

fs_offset_t FS_Tell ( qfile_t * file)

Definition at line 3461 of file fs.c.

3462{
3463 return file->position - file->buff_len + file->buff_ind;
3464}

Referenced by CheckPendingDownloads(), SCR_CaptureVideo_RIFF_IndexEntry(), and SV_SendClientDatagram().

◆ FS_UnGetc()

int FS_UnGetc ( qfile_t * file,
unsigned char c )

Definition at line 3341 of file fs.c.

3342{
3343 // If there's already a character waiting to be read
3344 if (file->ungetc != EOF)
3345 return EOF;
3346
3347 file->ungetc = c;
3348 return c;
3349}

Referenced by VM_buf_loadfile(), and VM_fgets().

◆ FS_UnloadPacks_dlcache()

void FS_UnloadPacks_dlcache ( void )

Definition at line 1485 of file fs.c.

1486{
1487 searchpath_t *search = fs_searchpaths, *searchprev = fs_searchpaths, *searchnext;
1488
1490 return;
1491
1492 while (search)
1493 {
1494 searchnext = search->next;
1495 if (search->pack && search->pack->dlcache)
1496 {
1497 Con_DPrintf("Unloading pack: %s\n", search->pack->shortname);
1498
1499 // remove it from the search path list
1500 if (search == fs_searchpaths)
1501 fs_searchpaths = search->next;
1502 else
1503 searchprev->next = search->next;
1504
1505 // close the file
1506 FILEDESC_CLOSE(search->pack->handle);
1507 // free any memory associated with it
1508 if (search->pack->files)
1509 Mem_Free(search->pack->files);
1510 Mem_Free(search->pack);
1511 Mem_Free(search);
1512 }
1513 else
1514 searchprev = search;
1515 search = searchnext;
1516 }
1517}
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
Definition console.c:1544
filedesc_t handle
Definition fs.c:389
qbool dlcache
Definition fs.c:393

References Con_DPrintf(), pack_t::dlcache, FILEDESC_CLOSE, pack_t::files, fs_searchpaths, fs_unload_dlcache, pack_t::handle, cvar_t::integer, Mem_Free, searchpath_t::next, searchpath_t::pack, and pack_t::shortname.

Referenced by CL_DisconnectEx(), and CL_ParseServerInfo().

◆ FS_VPrintf()

int FS_VPrintf ( qfile_t * file,
const char * format,
va_list ap )

Definition at line 3293 of file fs.c.

3294{
3295 int len;
3296 fs_offset_t buff_size = MAX_INPUTLINE;
3297 char *tempbuff;
3298
3299 for (;;)
3300 {
3301 tempbuff = (char *)Mem_Alloc (tempmempool, buff_size);
3302 len = dpvsnprintf (tempbuff, buff_size, format, ap);
3303 if (len >= 0 && len < buff_size)
3304 break;
3305 Mem_Free (tempbuff);
3306 buff_size *= 2;
3307 }
3308
3309 len = FILEDESC_WRITE (file->handle, tempbuff, len);
3310 Mem_Free (tempbuff);
3311
3312 return len;
3313}
int dpvsnprintf(char *buffer, size_t buffersize, const char *format, va_list args)
Returns the number of printed characters, excluding the final '\0' or returns -1 if the buffer isn't ...
Definition common.c:1010
#define FILEDESC_WRITE
Definition fs.c:110

References dpvsnprintf(), FILEDESC_WRITE, format, MAX_INPUTLINE, Mem_Alloc, Mem_Free, and tempmempool.

Referenced by FS_Printf(), and Log_Printf().

◆ FS_WhichPack()

const char * FS_WhichPack ( const char * filename)

Definition at line 4091 of file fs.c.

4092{
4093 int index;
4094 searchpath_t *sp = FS_FindFile(filename, &index, NULL, true);
4095 if(sp && sp->pack)
4096 return sp->pack->shortname;
4097 else if(sp)
4098 return "";
4099 else
4100 return 0;
4101}

References FS_FindFile(), index, NULL, searchpath_t::pack, and pack_t::shortname.

Referenced by Curl_SendRequirement(), SV_Download_f(), and VM_whichpack().

◆ FS_Write()

fs_offset_t FS_Write ( qfile_t * file,
const void * data,
size_t datasize )

Definition at line 3019 of file fs.c.

3020{
3021 fs_offset_t written = 0;
3022
3023 // If necessary, seek to the exact file position we're supposed to be
3024 if (file->buff_ind != file->buff_len)
3025 {
3026 if (FILEDESC_SEEK (file->handle, file->buff_ind - file->buff_len, SEEK_CUR) == -1)
3027 {
3028 Con_Printf(CON_WARN "WARNING: could not seek in %s.\n", file->filename);
3029 }
3030 }
3031
3032 // Purge cached data
3033 FS_Purge (file);
3034
3035 // Write the buffer and update the position
3036 // LadyHavoc: to hush a warning about passing size_t to an unsigned int parameter on Win64 we do this as multiple writes if the size would be too big for an integer (we never write that big in one go, but it's a theory)
3037 while (written < (fs_offset_t)datasize)
3038 {
3039 // figure out how much to write in one chunk
3040 fs_offset_t maxchunk = 1<<30; // 1 GiB
3041 int chunk = (int)min((fs_offset_t)datasize - written, maxchunk);
3042 int result = (int)FILEDESC_WRITE (file->handle, (const unsigned char *)data + written, chunk);
3043 // if at least some was written, add it to our accumulator
3044 if (result > 0)
3045 written += result;
3046 // if the result is not what we expected, consider the write to be incomplete
3047 if (result != chunk)
3048 break;
3049 }
3050 file->position = FILEDESC_SEEK (file->handle, 0, SEEK_CUR);
3051 if (file->real_length < file->position)
3052 file->real_length = file->position;
3053
3054 // note that this will never be less than 0 even if the write failed
3055 return written;
3056}
#define min(A, B)
Definition mathlib.h:37

References Con_Printf(), CON_WARN, data, FILEDESC_SEEK, FILEDESC_WRITE, FS_Purge(), int(), and min.

Referenced by CL_PasteDemo(), CL_WriteDemoMessage(), Con_ConDump_f(), Crypto_KeyGen_f(), Crypto_KeyGen_Finished(), CURL_fwrite(), FS_Print(), FS_WriteFileInBlocks(), JPEG_EmptyOutputBuffer(), JPEG_TermDestination(), Log_Start(), PNG_fWriteData(), SCR_CaptureVideo_Ogg_BeginVideo(), SCR_CaptureVideo_Ogg_EndVideo(), SCR_CaptureVideo_Ogg_FlushInterleaving(), SCR_CaptureVideo_Ogg_Interleave(), SCR_CaptureVideo_RIFF_Flush(), SCR_CaptureVideo_RIFF_FlushNoIncrease(), SCR_CaptureVideo_RIFF_Pop(), SCR_CaptureVideo_RIFF_WriteBytes(), SV_WriteDemoMessage(), VM_buf_writefile(), and VM_fputs().

◆ FS_WriteFile()

qbool FS_WriteFile ( const char * filename,
const void * data,
fs_offset_t len )

Definition at line 3592 of file fs.c.

3593{
3594 return FS_WriteFileInBlocks(filename, &data, &len, 1);
3595}
qbool FS_WriteFileInBlocks(const char *filename, const void *const *data, const fs_offset_t *len, size_t count)
Definition fs.c:3569

References data, and FS_WriteFileInBlocks().

Referenced by CL_StopDownload(), Image_WriteTGABGRA(), Mod_Decompile_f(), Mod_Decompile_OBJ(), Mod_Decompile_SMD(), QW_CL_ParseDownload(), R_SaveTextureDDSFile(), R_Shadow_SaveWorldLights(), and SV_SaveEntFile_f().

◆ FS_WriteFileInBlocks()

qbool FS_WriteFileInBlocks ( const char * filename,
const void *const * data,
const fs_offset_t * len,
size_t count )

Definition at line 3569 of file fs.c.

3570{
3571 qfile_t *file;
3572 size_t i;
3573 fs_offset_t lentotal;
3574
3575 file = FS_OpenRealFile(filename, "wb", false);
3576 if (!file)
3577 {
3578 Con_Printf("FS_WriteFile: failed on %s\n", filename);
3579 return false;
3580 }
3581
3582 lentotal = 0;
3583 for(i = 0; i < count; ++i)
3584 lentotal += len[i];
3585 Con_DPrintf("FS_WriteFile: %s (%u bytes)\n", filename, (unsigned int)lentotal);
3586 for(i = 0; i < count; ++i)
3587 FS_Write (file, data[i], len[i]);
3588 FS_Close (file);
3589 return true;
3590}
qfile_t * FS_OpenRealFile(const char *filepath, const char *mode, qbool quiet)
Definition fs.c:2901
int FS_Close(qfile_t *file)
Definition fs.c:2970

References Con_DPrintf(), Con_Printf(), count, data, FS_Close(), FS_OpenRealFile(), FS_Write(), and i.

Referenced by FS_WriteFile(), and Image_WriteTGABGR_preflipped().

Variable Documentation

◆ fs_all_gamedirs

gamedir_t* fs_all_gamedirs
extern

Definition at line 452 of file fs.c.

Referenced by FS_ListGameDirs(), and VM_M_getgamedirinfo().

◆ fs_all_gamedirs_count

int fs_all_gamedirs_count
extern

Definition at line 453 of file fs.c.

Referenced by FS_ListGameDirs(), and VM_M_getgamedirinfo().

◆ fs_basedir

◆ fs_checkgamedir_missing

const char* const fs_checkgamedir_missing
extern

Definition at line 438 of file fs.c.

Referenced by FS_CheckGameDir(), FS_ListGameDirs(), FS_SetGameDirs(), and ModList_RebuildList().

◆ fs_gamedir

char fs_gamedir[MAX_OSPATH]
extern

Definition at line 443 of file fs.c.

Referenced by FS_AddGameDirectory(), FS_Init_Dir(), FS_OpenRealFile(), FS_Rescan(), and SCR_ScreenShot_f().

◆ fs_gamedirs

char fs_gamedirs[MAX_GAMEDIRS][MAX_QPATH]
extern

◆ fs_numgamedirs

int fs_numgamedirs
extern

◆ fs_userdir