MFileTools

Collection of file manipulation tools, including File I/O designed to directly replace stdio, using MFile* in place of FILE*.

Code
Source.

Opens a file stream with the name specified by path. The argument mode should be a string containing one of the following modes:

Note: This usually should not be used directly and should be opened from the MFileTools interface

see also:, fopen

close
Close a file stream, if open.

see also:, fclose

read
Reads count amount of elements of data, each size bytes long, from the file, storing them at the location given by dest. Returns the number of items successfully read. If an error occurs, or the end-of-file is reached, the return value is a short item count (or zero)

see also:, fread

write
Writes count amount of elements of data, each size bytes long, to the file, obtaining them from the location given by str. Returns the number of items successfully written.

see also:, fwrite

print
Produces output according to the standard printf style format and writes to the file. Returns the number of characters written to the file (excluding the null byte used to end output strings)

see also:, fprintf

seek
Sets the file position indicator. The new position, measured in bytes, is obtained by adding offset bytes to the position specified by whence. If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the start of the file, the current position indicator, or end-of-file respectively.

see also:, fseek

tell
Obtains the current value of the file position indicator for the file

see also:, ftell

rewind
Sets the file position indicator to the beginning of the file.

see also:, rewind

Examples
MFile* fp = M_fopen("filename.txt", "r"); M_fseek(fp, 0L, SEEK_END); long size = M_ftell(fp); M_fseek(fp, 0L, SEEK_SET); char* buffer = new char[size]; M_fread(buffer, 1, size, fp); M_fclose(fp); delete [] buffer;