* 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. */
| 709 | * @return The amount of bytes truly read, or 0 if there was a failure. |
| 710 | */ |
| 711 | uint32 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) |
no test coverage detected