MCPcopy Create free account
hub / github.com/JACoders/OpenJK / FS_ReadFile

Function FS_ReadFile

code/qcommon/files.cpp:1750–1803  ·  view source on GitHub ↗

============ FS_ReadFile Filename are relative to the quake search path a null buffer will just return the file length without loading ============ */

Source from the content-addressed store, hash-verified

1748============
1749*/
1750long FS_ReadFile( const char *qpath, void **buffer ) {
1751 fileHandle_t h;
1752 byte* buf;
1753 long len;
1754
1755 FS_AssertInitialised();
1756
1757 if ( !qpath || !qpath[0] ) {
1758 Com_Error( ERR_FATAL, "FS_ReadFile with empty name\n" );
1759 }
1760
1761 // stop sounds from repeating
1762 S_ClearSoundBuffer();
1763
1764 buf = NULL; // quiet compiler warning
1765
1766 // look for it in the filesystem or pack files
1767 len = FS_FOpenFileRead( qpath, &h, qfalse );
1768 if ( h == 0 ) {
1769 if ( buffer ) {
1770 *buffer = NULL;
1771 }
1772 return -1;
1773 }
1774
1775 if ( !buffer ) {
1776 FS_FCloseFile( h);
1777 return len;
1778 }
1779
1780 fs_loadCount++;
1781
1782 buf = (byte*)Z_Malloc( len+1, TAG_FILESYS, qfalse);
1783 buf[len]='\0'; // because we're not calling Z_Malloc with optional trailing 'bZeroIt' bool
1784 *buffer = buf;
1785
1786 Z_Label(buf, qpath);
1787
1788 // PRECACE CHECKER!
1789#ifndef FINAL_BUILD
1790 if (com_sv_running && com_sv_running->integer && cls.state >= CA_ACTIVE) { //com_cl_running
1791 if (strncmp(qpath,"menu/",5) ) {
1792 Com_DPrintf( S_COLOR_MAGENTA"FS_ReadFile: %s NOT PRECACHED!\n", qpath );
1793 }
1794 }
1795#endif
1796
1797 FS_Read (buf, len, h);
1798
1799 // guarantee that it will have a trailing 0 for string operations
1800 buf[len] = 0;
1801 FS_FCloseFile( h );
1802 return len;
1803}
1804
1805/*
1806=============

Callers 12

FS_InitFilesystemFunction · 0.70
FS_RestartFunction · 0.70
Cmd_Exec_fFunction · 0.70
SE_LoadFileDataFunction · 0.70
JK2SP_RegisterFunction · 0.70
Sys_UnpackDLLFunction · 0.50
ReadFileFunction · 0.50
AS_ParseFileFunction · 0.50
LoadEALFileFunction · 0.50
R_CheckMP3sFunction · 0.50
SV_Map_Function · 0.50

Calls 9

Z_LabelFunction · 0.85
FS_AssertInitialisedFunction · 0.70
Com_ErrorFunction · 0.70
FS_FOpenFileReadFunction · 0.70
FS_FCloseFileFunction · 0.70
Z_MallocFunction · 0.70
Com_DPrintfFunction · 0.70
FS_ReadFunction · 0.70
S_ClearSoundBufferFunction · 0.50

Tested by

no test coverage detected