81 lines
2.2 KiB
C
81 lines
2.2 KiB
C
#ifndef FX_IO_FILE_H_
|
|
#define FX_IO_FILE_H_
|
|
|
|
#include <fx/core/error.h>
|
|
#include <fx/core/macros.h>
|
|
#include <fx/core/misc.h>
|
|
#include <fx/core/stream.h>
|
|
|
|
FX_DECLS_BEGIN;
|
|
|
|
#define FX_TYPE_FILE (fx_file_get_type())
|
|
|
|
FX_DECLARE_TYPE(fx_file);
|
|
|
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_file)
|
|
FX_TYPE_CLASS_DECLARATION_END(fx_file)
|
|
|
|
#define FX_OFFSET_CURRENT ((size_t)-1)
|
|
|
|
typedef enum fx_seek_basis {
|
|
FX_SEEK_BEGINNING,
|
|
FX_SEEK_CURRENT,
|
|
FX_SEEK_END
|
|
} fx_seek_basis;
|
|
|
|
typedef enum fx_file_attribute {
|
|
FX_FILE_ATTRIB_NORMAL = 0x01u,
|
|
FX_FILE_ATTRIB_DIRECTORY = 0x02u,
|
|
FX_FILE_ATTRIB_BLOCK_DEVICE = 0x04u,
|
|
FX_FILE_ATTRIB_CHAR_DEVICE = 0x08u,
|
|
FX_FILE_ATTRIB_SYMLINK = 0x80u,
|
|
} fx_file_attribute;
|
|
|
|
typedef enum fx_file_mode {
|
|
FX_FILE_READ_ONLY = 0x01u,
|
|
FX_FILE_WRITE_ONLY = 0x02u,
|
|
FX_FILE_READ_WRITE = FX_FILE_READ_ONLY | FX_FILE_WRITE_ONLY,
|
|
FX_FILE_TRUNCATE = 0x04u,
|
|
FX_FILE_CREATE = 0x08u,
|
|
FX_FILE_CREATE_ONLY = 0x10u | FX_FILE_CREATE,
|
|
FX_FILE_APPEND = 0x20u,
|
|
FX_FILE_BINARY = 0x40u,
|
|
FX_FILE_DELETE_ON_CLOSE = 0x80u,
|
|
FX_FILE_SHADOW = 0x100u,
|
|
} fx_file_mode;
|
|
|
|
typedef struct fx_file_info {
|
|
fx_file_attribute attrib;
|
|
fx_file_mode mode;
|
|
|
|
size_t length;
|
|
} fx_file_info;
|
|
|
|
FX_API fx_type fx_file_get_type(void);
|
|
|
|
FX_API fx_result fx_file_open(
|
|
FX_TYPE_FWDREF(fx_directory) * root, const FX_TYPE_FWDREF(fx_path) * path,
|
|
fx_file_mode mode, fx_file **out);
|
|
FX_API fx_result fx_file_open_temp(fx_file_mode mode, fx_file **out);
|
|
FX_API fx_result fx_file_open_shadow(
|
|
fx_file *original, fx_file_mode mode, fx_file **out);
|
|
|
|
FX_API fx_status fx_file_stat(fx_file *file, fx_file_info *out);
|
|
FX_API fx_status fx_file_size(fx_file *file, size_t *out_len);
|
|
FX_API fx_status fx_file_cursor(fx_file *file, size_t *out_pos);
|
|
FX_API fx_status fx_file_resize(fx_file *file, size_t len);
|
|
FX_API fx_status fx_file_seek(fx_file *file, long long offset, fx_seek_basis basis);
|
|
FX_API const FX_TYPE_FWDREF(fx_path) * fx_file_path(const fx_file *file);
|
|
|
|
FX_API fx_status fx_file_swap_shadow(fx_file *main_file, fx_file *shadow_file);
|
|
|
|
FX_API fx_status fx_file_read(
|
|
fx_file *file, size_t offset, size_t len, void *buf, size_t *nr_read);
|
|
FX_API fx_status fx_file_write(
|
|
fx_file *file, size_t offset, size_t len, const void *buf,
|
|
size_t *nr_written);
|
|
|
|
FX_DECLS_END;
|
|
|
|
#endif
|