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

Function File_Read

src/file.c:711–729  ·  view source on GitHub ↗

* Read bytes from a file into a buffer. * * @param index The index given by File_Open() of the file. * @param buffer The buffer to read into. * @param length The amount of bytes to read. * @return The amount of bytes truly read, or 0 if there was a failure. */

Source from the content-addressed store, hash-verified

709 * @return The amount of bytes truly read, or 0 if there was a failure.
710 */
711uint32 File_Read(uint8 index, void *buffer, uint32 length)
712{
713 if (index >= FILE_MAX) return 0;
714 if (s_file[index].fp == NULL) return 0;
715 if (s_file[index].position >= s_file[index].size) return 0;
716 if (length == 0) return 0;
717
718 if (length > s_file[index].size - s_file[index].position) length = s_file[index].size - s_file[index].position;
719
720 if (fread(buffer, length, 1, s_file[index].fp) != 1) {
721 Error("Read error\n");
722 File_Close(index);
723
724 length = 0;
725 }
726
727 s_file[index].position += length;
728 return length;
729}
730
731/**
732 * Read a 16bit unsigned from the file (written on disk in Little endian)

Callers 15

WSA_GotoNextFrameFunction · 0.85
WSA_LoadFileFunction · 0.85
Sprites_LoadCPSFileFunction · 0.85
Sprites_LoadImageFunction · 0.85
File_Read_LE16Function · 0.85
File_Read_LE32Function · 0.85
File_ReadBlockFile_ExFunction · 0.85
File_ReadWholeFileFunction · 0.85
File_ReadWholeFileLE16Function · 0.85
File_ReadFileFunction · 0.85
ChunkFile_Open_ExFunction · 0.85
ChunkFile_SeekFunction · 0.85

Calls 2

File_CloseFunction · 0.85
ErrorFunction · 0.50

Tested by

no test coverage detected