============ FS_ReadFile Filename are relative to the quake search path a null buffer will just return the file length without loading ============ */
| 1748 | ============ |
| 1749 | */ |
| 1750 | long 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 | ============= |
no test coverage detected