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

Function File_ReadWholeFileLE16

src/file.c:928–955  ·  view source on GitHub ↗

* Reads the whole file in the memory. The file should contain little endian * 16bits unsigned integers. It is converted to host byte ordering if needed. * * @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

926 * @return The pointer to allocated memory where the file has been read.
927 */
928uint16 *File_ReadWholeFileLE16(const char *filename)
929{
930 uint8 index;
931 uint32 count;
932 uint16 *buffer;
933#if __BYTE_ORDER == __BIG_ENDIAN
934 uint32 i;
935#endif
936
937 index = File_Open(filename, FILE_MODE_READ);
938 count = File_GetSize(index) / sizeof(uint16);
939
940 buffer = malloc(count * sizeof(uint16));
941 if (File_Read(index, buffer, count * sizeof(uint16)) != count * sizeof(uint16)) {
942 free(buffer);
943 return NULL;
944 }
945
946 File_Close(index);
947
948#if __BYTE_ORDER == __BIG_ENDIAN
949 for(i = 0; i < count; i++) {
950 buffer[i] = LETOH16(buffer[i]);
951 }
952#endif
953
954 return buffer;
955}
956
957/**
958 * Reads the whole file into buffer.

Callers 1

Sprites_LoadTilesFunction · 0.85

Calls 4

File_GetSizeFunction · 0.85
File_ReadFunction · 0.85
freeFunction · 0.85
File_CloseFunction · 0.85

Tested by

no test coverage detected