// vim:fileencoding=utf-8:foldmethod=marker #ifndef FILE_H #define FILE_H #include "../../base/mem/allocator/mem_allocator.h" #include "../../common/aliases/aliases.h" #include "../../base/strings/str8/str8.h" #ifdef WAPP_PLATFORM_CPP BEGIN_C_LINKAGE #endif // !WAPP_PLATFORM_CPP typedef struct WFile WFile; typedef enum { WAPP_ACCESS_READ, // Equivalent to r WAPP_ACCESS_WRITE, // Equivalent to w WAPP_ACCESS_APPEND, // Equivalent to a WAPP_ACCESS_READ_EX, // Equivalent to r+ WAPP_ACCESS_WRITE_EX, // Equivalent to w+ WAPP_ACCESS_APPEND_EX, // Equivalent to a+ WAPP_ACCESS_WRITE_FAIL_ON_EXIST, // Equivalent to wx WAPP_ACCESS_WRITE_FAIL_ON_EXIST_EX, // Equivalent to wx+ FILE_ACCESS_MODE_COUNT, } FileAccessMode; typedef enum { WAPP_SEEK_START, WAPP_SEEK_CURRENT, WAPP_SEEK_END, FILE_SEEK_ORIGIN_COUNT, } FileSeekOrigin; // Return value should not be cached as it's not guaranteed to remain the same. Always call // wapp_file_stdin to get the standard input stream wapp_extern WFile *wapp_file_stdin(void); // Return value should not be cached as it's not guaranteed to remain the same. Always call // wapp_file_stdout to get the standard output stream wapp_extern WFile *wapp_file_stdout(void); // Return value should not be cached as it's not guaranteed to remain the same. Always call // wapp_file_stderr to get the standard error stream wapp_extern WFile *wapp_file_stderr(void); WFile *wapp_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode); i64 wapp_file_get_current_position(WFile *file); i64 wapp_file_seek(WFile *file, i64 offset, FileSeekOrigin origin); i64 wapp_file_get_length(WFile *file); u64 wapp_file_read(void *dst_buf, WFile *file, u64 byte_count); i64 wapp_file_write(const void *src_buf, WFile *file, u64 byte_count); u64 wapp_file_read_array(GenericArray dst_buf, WFile *file, u64 item_count); i64 wapp_file_write_array(const GenericArray src_buf, WFile *file, u64 item_count); i32 wapp_file_flush(WFile *file); i32 wapp_file_close(WFile *file); i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath); i32 wapp_file_remove(Str8RO *filepath); wapp_extern WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode); wapp_extern i64 _file_seek(WFile *file, i64 offset, FileSeekOrigin origin); wapp_extern u64 _file_read(void *dst_buf, u64 byte_count, WFile *file, u64 file_length); wapp_extern i64 _file_write(const void *src_buf, WFile *file, u64 byte_count); wapp_extern i32 _file_flush(WFile *file); wapp_extern i32 _file_close(WFile *file); wapp_extern i32 _file_rename(Str8RO *old_filepath, Str8RO *new_filepath); wapp_extern i32 _file_remove(Str8RO *filepath); #ifdef WAPP_PLATFORM_CPP END_C_LINKAGE #endif // !WAPP_PLATFORM_CPP #endif // !FILE_H