* 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. */
| 897 | * @return The pointer to allocated memory where the file has been read. |
| 898 | */ |
| 899 | void *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 |
no test coverage detected