José
|
IO Chaining. More...
Data Structures | |
struct | jose_io_t |
The interface for chained IO. More... | |
Typedefs | |
typedef jose_io_t | jose_io_auto_t |
Defines a jose_io_t which calls jose_io_decref() at end of scope. More... | |
Functions | |
jose_io_t * | jose_io_incref (jose_io_t *io) |
Increases the reference count of an IO object. More... | |
void | jose_io_decref (jose_io_t *io) |
Decreases the reference count of an IO object. More... | |
jose_io_t * | jose_io_malloc (jose_cfg_t *cfg, void **buf, size_t *len) |
Creates a new IO object which collects data into a dynamic buffer. More... | |
void * | jose_io_malloc_steal (void **buf) |
Steals the buffer created by the jose_io_malloc() IO object. More... | |
jose_io_t * | jose_io_buffer (jose_cfg_t *cfg, void *buf, size_t *len) |
Creates a new IO object which collects data into a static buffer. More... | |
jose_io_t * | jose_io_file (jose_cfg_t *cfg, FILE *file) |
Creates a new IO object which writes data into a FILE. More... | |
jose_io_t * | jose_io_multiplex (jose_cfg_t *cfg, jose_io_t **nexts, bool all) |
Creates a new IO object which multiplexes data into multiple IO objects. More... | |
IO Chaining.
typedef jose_io_t jose_io_auto_t |
Defines a jose_io_t which calls jose_io_decref() at end of scope.
For example:
void foo() { uint8_t *buf = NULL; size_t len = 0; jose_io_auto_t *io = jose_io_malloc(NULL, &buf, &len); // jose_io_decref() implicitly called }
Increases the reference count of an IO object.
This function always succeeds.
io | The jose_io_t entity you are using. |
io
(for convenience). void jose_io_decref | ( | jose_io_t * | io | ) |
Decreases the reference count of an IO object.
When the reference count reaches zero, io->free() is called.
io | The jose_io_t entity you are using. |
jose_io_t* jose_io_malloc | ( | jose_cfg_t * | cfg, |
void ** | buf, | ||
size_t * | len | ||
) |
Creates a new IO object which collects data into a dynamic buffer.
The dynamic buffer is allocated into the buf
pointer you provided and the length of the buffer is stored in len
. The pointer referenced by buf
must remain valid for the entire duration of the returned IO object.
The default behavior is for the IO object to zero and free the buffer when it is freed. This means that, by default, you own the buffer pointer but the buffer itself is owned by the IO object. You can, however, steal the buffer by setting the buffer pointer to NULL.
cfg | The configuration context (optional). |
buf | A buffer pointer pointer. |
len | A pointer to the length of the buffer. |
void* jose_io_malloc_steal | ( | void ** | buf | ) |
Steals the buffer created by the jose_io_malloc() IO object.
This convenience function simply returns the value of *buf
and then sets *buf
to NULL.
buf | A pointer to the buffer pointer. |
*buf
before it is set to NULL. jose_io_t* jose_io_buffer | ( | jose_cfg_t * | cfg, |
void * | buf, | ||
size_t * | len | ||
) |
Creates a new IO object which collects data into a static buffer.
The size of buf
MUST be specified in the variable pointed to by len
. This will be the maximum data written. However, after the function returns, the variable pointed to by len
will contain the current length of data in the buffer.
Unlike jose_io_malloc(), you own the buffer and it is not zeroed or freed when the IO object is freed.
cfg | The configuration context (optional). |
buf | A buffer pointer. |
len | A pointer to the length of the buffer. |
jose_io_t* jose_io_file | ( | jose_cfg_t * | cfg, |
FILE * | file | ||
) |
Creates a new IO object which writes data into a FILE.
This function DOES NOT take ownership of the FILE. You are still responsible for calling fclose() at the appropriate time.
cfg | The configuration context (optional). |
file | The output file which MUST be opened for writing or appending. |
Creates a new IO object which multiplexes data into multiple IO objects.
If all
is true, the success of all nexts
is required. Otherwise, all but one of the nexts
can fail before the error is propagated upward.
cfg | The configuration context (optional). |
nexts | A NULL-terminated array of IO object pointers. |
all | Whether or not the success of all nexts is required. |