* Write bytes from a buffer to a file. * * @param index The index given by File_Open() of the file. * @param buffer The buffer to write from. * @param length The amount of bytes to write. * @return The amount of bytes truly written, or 0 if there was a failure. */
| 763 | * @return The amount of bytes truly written, or 0 if there was a failure. |
| 764 | */ |
| 765 | uint32 File_Write(uint8 index, void *buffer, uint32 length) |
| 766 | { |
| 767 | if (index >= FILE_MAX) return 0; |
| 768 | if (s_file[index].fp == NULL) return 0; |
| 769 | |
| 770 | if (fwrite(buffer, length, 1, s_file[index].fp) != 1) { |
| 771 | Error("Write error\n"); |
| 772 | File_Close(index); |
| 773 | |
| 774 | length = 0; |
| 775 | } |
| 776 | |
| 777 | s_file[index].position += length; |
| 778 | if (s_file[index].position > s_file[index].size) s_file[index].size = s_file[index].position; |
| 779 | return length; |
| 780 | } |
| 781 | |
| 782 | /** |
| 783 | * Write a 16bit unsigned to the file (written on disk in Little endian) |
no test coverage detected