MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / File_ReadWholeFile

Function File_ReadWholeFile

src/file.c:899–918  ·  view source on GitHub ↗

* Reads the whole file in the memory. * * @param filename The name of the file to open. * @param mallocFlags The type of memory to allocate. * @return The pointer to allocated memory where the file has been read. */

Source from the content-addressed store, hash-verified

897 * @return The pointer to allocated memory where the file has been read.
898 */
899void *File_ReadWholeFile(const char *filename)
900{
901 uint8 index;
902 uint32 length;
903 void *buffer;
904
905 index = File_Open(filename, FILE_MODE_READ);
906 if (index == FILE_INVALID) return NULL;
907 length = File_GetSize(index);
908
909 buffer = malloc(length + 1);
910 File_Read(index, buffer, length);
911
912 /* In case of text-files it can be very important to have a \0 at the end */
913 ((char *)buffer)[length] = '\0';
914
915 File_Close(index);
916
917 return buffer;
918}
919
920/**
921 * Reads the whole file in the memory. The file should contain little endian

Callers 5

String_LoadFunction · 0.85
Scenario_LoadFunction · 0.85
Sprites_LoadFunction · 0.85
Driver_LoadFileFunction · 0.85
Font_LoadFileFunction · 0.85

Calls 3

File_GetSizeFunction · 0.85
File_ReadFunction · 0.85
File_CloseFunction · 0.85

Tested by

no test coverage detected