this just gets the binary of the file into memory, so I can parse it. Called by main SGE loader returns either char * of loaded file, else NULL for failed-to-open...
| 56 | // returns either char * of loaded file, else NULL for failed-to-open... |
| 57 | // |
| 58 | unsigned char *SE_LoadFileData( const char *psFileName, int *piLoadedLength /* = 0 */) |
| 59 | { |
| 60 | unsigned char *psReturn = NULL; |
| 61 | if ( piLoadedLength ) |
| 62 | { |
| 63 | *piLoadedLength = 0; |
| 64 | } |
| 65 | |
| 66 | #ifdef _STRINGED |
| 67 | if (psFileName[1] == ':') |
| 68 | { |
| 69 | // full-path filename... |
| 70 | // |
| 71 | FILE *fh = fopen( psFileName, "rb" ); |
| 72 | if (fh) |
| 73 | { |
| 74 | long lLength = filesize(fh); |
| 75 | |
| 76 | if (lLength > 0) |
| 77 | { |
| 78 | psReturn = (unsigned char *) malloc( lLength + 1); |
| 79 | if (psReturn) |
| 80 | { |
| 81 | int iBytesRead = fread( psReturn, 1, lLength, fh ); |
| 82 | if (iBytesRead != lLength) |
| 83 | { |
| 84 | // error reading file!!!... |
| 85 | // |
| 86 | free(psReturn); |
| 87 | psReturn = NULL; |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | psReturn[ lLength ] = '\0'; |
| 92 | if ( piLoadedLength ) |
| 93 | { |
| 94 | *piLoadedLength = iBytesRead; |
| 95 | } |
| 96 | } |
| 97 | fclose(fh); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | else |
| 103 | #endif |
| 104 | { |
| 105 | // local filename, so prepend the base dir etc according to game and load it however (from PAK?) |
| 106 | // |
| 107 | unsigned char *pvLoadedData; |
| 108 | int iLen = FS_ReadFile( psFileName, (void **)&pvLoadedData ); |
| 109 | |
| 110 | if (iLen>0) |
| 111 | { |
| 112 | psReturn = pvLoadedData; |
| 113 | if ( piLoadedLength ) |
| 114 | { |
| 115 | *piLoadedLength = iLen; |
no test coverage detected