MCPcopy Create free account
hub / github.com/captain-amygdala/pistorm / LoadFileData

Function LoadFileData

raylib/utils.c:182–228  ·  view source on GitHub ↗

Load data from file into a buffer

Source from the content-addressed store, hash-verified

180
181// Load data from file into a buffer
182unsigned char *LoadFileData(const char *fileName, unsigned int *bytesRead)
183{
184 unsigned char *data = NULL;
185 *bytesRead = 0;
186
187 if (fileName != NULL)
188 {
189 if (loadFileData)
190 {
191 data = loadFileData(fileName, bytesRead);
192 return data;
193 }
194#if defined(SUPPORT_STANDARD_FILEIO)
195 FILE *file = fopen(fileName, "rb");
196
197 if (file != NULL)
198 {
199 // WARNING: On binary streams SEEK_END could not be found,
200 // using fseek() and ftell() could not work in some (rare) cases
201 fseek(file, 0, SEEK_END);
202 int size = ftell(file);
203 fseek(file, 0, SEEK_SET);
204
205 if (size > 0)
206 {
207 data = (unsigned char *)RL_MALLOC(size*sizeof(unsigned char));
208
209 // NOTE: fread() returns number of read elements instead of bytes, so we read [1 byte, size elements]
210 unsigned int count = (unsigned int)fread(data, sizeof(unsigned char), size, file);
211 *bytesRead = count;
212
213 if (count != size) TRACELOG(LOG_WARNING, "FILEIO: [%s] File partially loaded", fileName);
214 else TRACELOG(LOG_INFO, "FILEIO: [%s] File loaded successfully", fileName);
215 }
216 else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to read file", fileName);
217
218 fclose(file);
219 }
220 else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to open file", fileName);
221#else
222 TRACELOG(LOG_WARNING, "FILEIO: Standard file io not supported, use custom file callback");
223#endif
224 }
225 else TRACELOG(LOG_WARNING, "FILEIO: File name provided is not valid");
226
227 return data;
228}
229
230// Unload file data allocated by LoadFileData()
231void UnloadFileData(unsigned char *data)

Callers 10

LoadIQMFunction · 0.70
LoadIQMModelAnimationsFunction · 0.70
LoadGLTFFunction · 0.70
LoadGLTFModelAnimationsFunction · 0.70
LoadFontExFunction · 0.70
LoadImageFunction · 0.70
LoadImageRawFunction · 0.70
LoadImageAnimFunction · 0.70
SaveStorageValueFunction · 0.70
LoadStorageValueFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected