17 static size_t fd_read(
io_t *
self,
void *dst,
size_t size)
23 if (self->error != 0)
return SIZE_MAX;
28 static size_t fd_write(
io_t *
self,
const void *src,
size_t size)
34 if (self->error != 0)
return SIZE_MAX;
39 static size_t fd_size(
io_t *
self)
45 if (self->error != 0)
return SIZE_MAX;
50 static size_t fd_seek(
io_t *
self,
size_t offset)
56 if (self->error != 0)
return SIZE_MAX;
69 if (self->error != 0)
return NULL;
75 static os_error_t fd_close(
io_t *
self)
94 .fn_get_size = fd_size,
114 io_t *io =
io_init(buffer, &kFileCallbacks, mode, path, &impl, arena);
128 return impl_file_init(buffer, path, mode, arena);
138 return impl_file_init(buffer, path, mode, NULL);
os_protect_t
file mapping memory protection
os_access_t
file access mode
#define STA_DECL
sal2 annotation on function implementations to copy annotations from the declaration
CT_PUREFN CT_IO_API void * io_data(io_t *io)
get the user data from an io object
CT_IO_API io_t * io_init(STA_WRITES(sizeof(io_t)+cb->size) void *buffer, const io_callbacks_t *cb, os_access_t flags, const char *name, STA_READS(cb->size) const void *data, arena_t *arena)
initialize an IO object for a given interface
CT_NODISCARD CT_IO_API size_t io_size(io_t *io)
get the total size of an io objects contents
#define ARENA_MALLOC(size, name, parent, arena)
allocate memory from a custom allocator
#define CTASSERT(expr)
assert a condition, prints the condition as a message
STA_DECL io_t * io_file(const char *path, os_access_t mode, arena_t *arena)
create an IO object from a file
STA_DECL io_t * io_file_init(void *buffer, const char *path, os_access_t mode)
STA_DECL os_error_t os_file_read(os_file_t *file, void *buffer, size_t size, size_t *actual)
STA_DECL os_error_t os_file_seek(os_file_t *file, size_t offset, size_t *actual)
STA_DECL os_error_t os_file_write(os_file_t *file, const void *buffer, size_t size, size_t *actual)
STA_DECL os_error_t os_file_size(os_file_t *file, size_t *actual)
CT_OS_API os_error_t os_file_close(STA_RELEASE os_file_t *file)
close a file
CT_NODISCARD CT_PUREFN CT_OS_API bool os_mapping_active(const os_mapping_t *mapping)
does the mapping object contain a valid mapping checks if the mapping data exists,...
CT_OS_API os_error_t os_file_open(const char *path, os_access_t access, OUT_NOTNULL os_file_t *file)
file api
CT_OS_API os_error_t os_file_map(os_file_t *file, os_protect_t protect, size_t size, OUT_NOTNULL os_mapping_t *mapping)
map a file into memory
CT_OS_API os_error_t os_unmap(INOUT_NOTNULL os_mapping_t *mapping)
unmap a file from memory
CT_NODISCARD CT_OS_API void * os_mapping_data(os_mapping_t *mapping)
get the data of a file mapping
io_read_t fn_read
read callback may be NULL on non-readable objects
os_mapping_t mapping
memory mapping
os_file_t file
native file descriptor
os_error_t error
the last error set on this object