#pragma once #include #include #ifdef NAUNET_NEEDS_STDIO_ASSIST // It seems meson adds _FILE_OFFSET_BITS=64 on all "linuxlike" compilers even MinGW. // https://github.com/mesonbuild/meson/commit/853634a48da025c59eef70161dba0d150833f60d // https://github.com/mesonbuild/meson/issues/12931 // I don't think we necessarily want this on 32-bit Windows. #include #ifdef NAUNET_ON_WINDOWS #if _FILE_OFFSET_BITS == 64 #define fseek _fseeki64 #define ftell _ftelli64 #endif #else #define fseek fseeko #define ftell ftello #endif #else #ifdef NAUNET_ON_WINDOWS #else #include #include #include #include #include #endif #endif enum { NNWT_FILE_READONLY = 1, NNWT_FILE_CREATE = 1 << 1, NNWT_FILE_LOCK = 1 << 2 }; enum { NNWT_ENTRY_FILE = 0, NNWT_ENTRY_DIR, NNWT_ENTRY_OTHER }; struct nn_file { s32 flags; #ifdef NAUNET_NEEDS_STDIO_ASSIST FILE *file; #else #ifdef NAUNET_ON_WINDOWS #else s32 fd; #endif #endif str path; size_t size; }; struct nn_dir { #ifdef NAUNET_NEEDS_STDIO_ASSIST #else #ifdef NAUNET_ON_WINDOWS #else DIR *dir; #endif #endif str path; }; struct nn_dir_entry { u8 type; #ifdef NAUNET_NEEDS_STDIO_ASSIST #else #ifdef NAUNET_ON_WINDOWS #else struct dirent *entry; #endif #endif }; bool nn_file_open(struct nn_file *file, str *path, s32 flags); bool nn_file_exists(str *path); bool nn_file_create(str *path); bool nn_file_truncate(struct nn_file *file, off_t size); bool nn_file_flush(struct nn_file *file); off_t nn_file_seek(struct nn_file *file, off_t offset, s32 whence); bool nn_file_write(struct nn_file *file, void *buf, size_t size); bool nn_file_read(struct nn_file *file, void *buf, size_t size); s32 nn_file_read_as_str(struct nn_file *file, str *out); s32 nn_file_read_as_c_str(struct nn_file *file, char **out); s32 nn_file_replace(struct nn_file *file, str *buf); void *nn_file_mmap(struct nn_file *file); void *nn_file_mremap(struct nn_file *file, size_t size, void *old_map); void nn_file_munmap(struct nn_file *file, void *map); void nn_file_close(struct nn_file *file); bool nn_dir_open(struct nn_dir *dir, str *path); void nn_dir_close(struct nn_dir *dir); bool nn_dir_exists(str *path); bool nn_dir_create(str *path); bool nn_dir_read(struct nn_dir *dir, struct nn_dir_entry *entry); void nn_dir_entry_get_name(struct nn_dir_entry *entry, str *name); const char *nn_dir_entry_get_os_name(struct nn_dir_entry *entry); void nn_dir_entry_get_path(struct nn_dir_entry *entry, struct nn_dir *dir, str *path);