49 if (!fs_stream || (!buf && n)) {
53 if (!fs_stream->
state.
f && n) {
70 if (!fs_stream || (!buf && n)) {
74 if (!fs_stream->
state.
f && n) {
81 fs_stream->
state.
f, buf, n, &osal_st );
118 fs_stream->
state.
f = NULL;
143 || args->
path == NULL
144 || *args->
path ==
'\0'
185 if (!p || !*p)
return;
205 mem->
free((
void*)ud);
241 if (!out || !args || !ctor_ud) {
308 .file_env = *file_env,
309 .file_ops = file_ops,
310 .port_env = *port_env
stream_status_t fs_stream_create_stream(stream_t **out, const fs_stream_args_t *args, const fs_stream_cfg_t *cfg, const fs_stream_env_t *env)
Create a file-backed stream instance.
static stream_status_t create_backend(fs_stream_t **out, const fs_stream_args_t *args, const fs_stream_cfg_t *cfg, const fs_stream_env_t *env)
fs_stream_cfg_t fs_stream_default_cfg(void)
Return a default configuration for the fs_stream adapter.
static stream_status_t fs_stream_close(void *backend)
stream_status_t fs_stream_ctor(const void *ud, const void *args, stream_t **out)
Factory constructor callback for the fs_stream adapter.
stream_status_t fs_stream_create_desc(stream_adapter_desc_t *out, stream_key_t key, const fs_stream_cfg_t *cfg, const fs_stream_env_t *env, const osal_mem_ops_t *mem)
Build an adapter descriptor for registering fs_stream in a factory.
static void destroy_backend(fs_stream_t **p)
static size_t fs_stream_read(void *backend, void *buf, size_t n, stream_status_t *st)
static size_t fs_stream_write(void *backend, const void *buf, size_t n, stream_status_t *st)
static void fs_stream_destroy_ud_ctor(const void *ud, const osal_mem_ops_t *mem)
static stream_status_t fs_stream_flush(void *backend)
static stream_status_t map_osal_status(osal_file_status_t osal_st)
static const stream_vtbl_t VTBL
fs_stream_env_t fs_stream_default_env(const osal_file_env_t *file_env, const osal_file_ops_t *file_ops, const stream_env_t *port_env)
Build a default environment for the fs_stream adapter.
Composition Root API for wiring the fs_stream adapter into the stream factory.
Private constructor user-data stored in fs_stream factory descriptors.
Private backend handle definition for the fs_stream adapter.
#define LEXLEO_ASSERT(expr)
void * osal_memcpy(void *dest, const void *src, size_t n)
stream_status_t stream_create(stream_t **out, const stream_vtbl_t *vtbl, void *backend, const stream_env_t *env)
Create a generic stream handle from adapter-provided backend bindings.
const char * stream_key_t
Public identifier type for a registered stream adapter.
stream_status_t
Public status codes used by the stream port.
@ STREAM_STATUS_NO_BACKEND
Arguments provided when creating a file-backed stream.
bool autoclose
Whether the OSAL file must be closed when the stream is destroyed.
const char * path
UTF-8 path of the target file.
uint32_t flags
OSAL file open flags.
Configuration type for the fs_stream adapter.
int reserved
Reserved configuration field.
Private constructor user-data for fs_stream factory registration.
Injected dependencies for the fs_stream adapter.
osal_file_env_t file_env
Borrowed OSAL file environment.
stream_env_t port_env
Borrowed stream port environment.
const osal_file_ops_t * file_ops
Borrowed OSAL file operations table.
Private backend handle for the fs_stream adapter.
const osal_mem_ops_t * mem_ops
const osal_file_ops_t * file_ops
const osal_mem_ops_t * mem
size_t(* write)(osal_file_t *f, const void *buf, size_t n, osal_file_status_t *status)
osal_file_status_t(* close)(osal_file_t *f)
osal_file_status_t(* flush)(osal_file_t *f)
size_t(* read)(osal_file_t *f, void *buf, size_t n, osal_file_status_t *status)
osal_file_t *(* open)(const char *path_utf8, uint32_t flags, osal_file_status_t *status, const osal_file_env_t *env)
void *(* calloc)(size_t nmemb, size_t size)
Public descriptor used to register a concrete stream adapter.
stream_key_t key
Public key used to identify the adapter.
const void * ud
Optional opaque user data bound to the constructor.
ud_dtor_fn_t ud_dtor
Optional destructor for ud.
stream_ctor_fn_t ctor
Adapter constructor used to create a stream_t.
Runtime environment for the stream port.
Private handle structure for a stream_t.
Adapter dispatch table bound to a stream_t instance.