#ifndef ULE_FILE_H #define ULE_FILE_H #include // FILE #include // time_t #include "config.h" #include "array.hpp" namespace File { FILE* Open(const char* path, const char* mode = "rb"); FILE* Open(const char* path, size_t* outSize, const char* mode = "rb"); void Close(FILE* file); size_t Size(const char* path); size_t Size(FILE* fp); // most commonly this is what you want - provide a filesystem path, read the whole file, // and return a buffer with the file's contents. // the file is opened and closed internally. // the buffer you get returned is allocated internally and must be freed by the caller. u8* Read(const char* path); // if you also want to know the size of the file. u8* Read(const char* path, size_t* outSize); // for apis that want a more incremental approach, this function will read |file|'s contents into |destination|, // which must be pre-allocated. the provided file must be closed by the caller. // returns the number of bytes read. size_t Read(FILE* fp, void* destination); // calls fseek to determine file size size_t Read(FILE* fp, void* destination, size_t size); // you know and provide the file size s32 Write(const char* path, char* data, u32 count); // writes the filenames into the provided array |outFileNames|, must be allocated ahead of time. void GetFileNamesInFolder(const char* path, Array* outFileNames); // get the last-modified timestamp on a file located at 'path'. // there's no caching done, so it's the real, current value. // specifically, it's the field 'st_mtime' on the 'stat' struct. time_t LastModified(const char* path); s32 Rename(const char* oldFilename, const char* newFilename); s32 Remove(const char* path); } #endif