Functions | |
enum io_type_e | io_type (io_t *io) |
Returns the type of the given io. | |
ssize_t | io_pipe (io_t *out, io_t *in) |
Write the input stream to the output stream. | |
int | io_dup (io_t *io, io_t **pio) |
Duplicate an IO handle. | |
ssize_t | io_copy (io_t *out, io_t *in, size_t size) |
Copy a block of data between two io_t objects. | |
ssize_t | io_seek (io_t *io, size_t off) |
Seek to the given position. | |
ssize_t | io_tell (io_t *io) |
Return the current file position. | |
int | io_close (io_t *io) |
Close the given io object. | |
int | io_free (io_t *io) |
Free an io_t object. | |
ssize_t | io_read (io_t *io, char *buf, size_t size) |
Read a block of data from an io_t object. | |
ssize_t | io_vprintf (io_t *io, const char *fmt, va_list ap) |
Write a string to io using printf-style va_list. | |
ssize_t | io_printf (io_t *io, const char *fmt,...) |
Write a string to io using printf-style format strings. | |
ssize_t | io_flush (io_t *io) |
Flush the write buffer. | |
ssize_t | io_write (io_t *io, const char *buf, size_t size) |
Write a block of data to an io_t object. | |
ssize_t | io_putc (io_t *io, char c) |
Write a char to an io_t object. | |
ssize_t | io_getc (io_t *io, char *pc) |
Read a char from an io_t object. | |
ssize_t | io_get_until (io_t *io, char stop_at, char *buf, size_t size) |
Read a chunk of data until the given character is found. | |
ssize_t | io_gets (io_t *io, char *buf, size_t size) |
Read a line from an io_t object. | |
int | io_codec_add_head (io_t *io, codec_t *c) |
Insert a codec at the head the codec chain. | |
int | io_codec_add_tail (io_t *io, codec_t *c) |
Append a codec to the codec chain. | |
int | io_codecs_remove (io_t *io) |
Flush, remove and free all codecs in the codec chain. | |
int | io_name_set (io_t *io, const char *name) |
Set the name of an io_t object. | |
int | io_name_get (io_t *io, char *name, size_t sz) |
Return the name of the given io_t object. |
enum io_type_e io_type | ( | io_t * | io | ) |
ssize_t io_pipe | ( | io_t * | out, | |
io_t * | in | |||
) |
Read all data from in
and copy it to out
out | output IO object | |
in | input IO object |
in
and written to out
or -1
on error Definition at line 61 of file io.c.
References io_read(), and io_write().
int io_dup | ( | io_t * | io, | |
io_t ** | pio | |||
) |
Create a copy of io
and store it to *pio
. The returned object will share the same underlaying IO device, the same codecs connected to io
and the same input and output buffers. Buffers, codecs and IO devices will not be released until all io_t
object associated to it will be freed.
io | the io_t object to be dupped | |
pio | on success will contain the duplicated io_t object |
0
on success, not zero on failuressize_t io_copy | ( | io_t * | out, | |
io_t * | in, | |||
size_t | size | |||
) |
Read from in
a block of data size
bytes long and write it to the out
output io_t
object
out | output io_t object | |
in | input io_t object | |
size | number of bytes to copy |
size
in case of EOF on in
) or -1
on error. Definition at line 132 of file io.c.
References io_read(), and io_write().
ssize_t io_seek | ( | io_t * | io, | |
size_t | off | |||
) |
Moves the read/write file offset so that the next read or the next write will start at the given position. Note that not all io_t
devices support seeking (e.g. sockets don't) so this function will always fail when used on those devices.
io | the io_t object | |
off | absolute offset to move to |
Definition at line 175 of file io.c.
References io_flush().
ssize_t io_tell | ( | io_t * | io | ) |
Return the current file position. There exists a unique read and write position offset.
io | the io_t object |
Definition at line 197 of file io.c.
References io_flush().
int io_close | ( | io_t * | io | ) |
int io_free | ( | io_t * | io | ) |
Free the given io_t
object. If io
has been dup'd and the reference count is not zero then this function will only decrement it and return. Otherwise io
will be flushed, the codec applied to it (if any) freed and any other resource associated to it released.
io | the io_t object to be free'd |
0
on success, non-zero on errorDefinition at line 469 of file io.c.
References io_close(), io_codecs_remove(), and io_flush().
ssize_t io_read | ( | io_t * | io, | |
char * | buf, | |||
size_t | size | |||
) |
Read size
bytes from io
and save them to buf
(that must be big enough).
io | the io_t object onto which the read operation is performed | |
buf | the buffer that will contain the read bytes | |
size | number of bytes to read |
buf
, 0
on end of file condition, and -1
on error. Definition at line 572 of file io.c.
Referenced by io_copy(), io_getc(), io_pipe(), and u_md5io().
ssize_t io_vprintf | ( | io_t * | io, | |
const char * | fmt, | |||
va_list | ap | |||
) |
Vprintf-like function used to easily write strings to io
using well-known printf format strings. See printf(3) manual for format description.
io | the io_t object to write to | |
fmt | printf-style format string | |
ap | variable list arguments |
-1
on error Definition at line 621 of file io.c.
References io_write().
Referenced by io_printf().
ssize_t io_printf | ( | io_t * | io, | |
const char * | fmt, | |||
... | ||||
) |
Printf-like function used to easily write strings to io
using well-known printf format strings. See printf(3) manual for format description.
io | the io_t object to write to | |
fmt | printf-style format string | |
... | format string arguments |
-1
on error Definition at line 692 of file io.c.
References io_vprintf().
ssize_t io_flush | ( | io_t * | io | ) |
ssize_t io_write | ( | io_t * | io, | |
const char * | buf, | |||
size_t | size | |||
) |
Write size
bytes of buf
to io
.
io | the io_t object | |
buf | the buffer with the bytes to write | |
size | number of bytes to write |
Definition at line 757 of file io.c.
References io_flush().
Referenced by io_copy(), io_pipe(), io_putc(), and io_vprintf().
ssize_t io_putc | ( | io_t * | io, | |
char | c | |||
) | [inline] |
Write the character c
to io
io | the io_t object | |
c | the char to write |
1
) on success or -1
on error. Definition at line 799 of file io.c.
References io_write().
ssize_t io_getc | ( | io_t * | io, | |
char * | pc | |||
) | [inline] |
ssize_t io_get_until | ( | io_t * | io, | |
char | stop_at, | |||
char * | buf, | |||
size_t | size | |||
) |
Read from in
and save it to buf
that must be at least size
bytes long. Read stops when stop_at characted is found in the incoming stream.
io | the io_t object | |
stop_at | reads until this character is found | |
buf | destination buffer | |
size | size of buf |
0
on EOF or -1
on error. Definition at line 853 of file io.c.
Referenced by io_gets().
ssize_t io_gets | ( | io_t * | io, | |
char * | buf, | |||
size_t | size | |||
) |
Read a line from in
and save it to buf
that must be at least size
bytes long.
io | the io_t object | |
buf | destination buffer | |
size | size of buf |
0
on EOF or -1
on error. Definition at line 929 of file io.c.
References io_get_until().
Referenced by u_getline().
int io_codec_add_head | ( | io_t * | io, | |
codec_t * | c | |||
) |
int io_codec_add_tail | ( | io_t * | io, | |
codec_t * | c | |||
) |
int io_codecs_remove | ( | io_t * | io | ) |
io | the io_t object |
0
on success, non-zero on error Definition at line 982 of file io.c.
References codec_free().
Referenced by io_free().
int io_name_set | ( | io_t * | io, | |
const char * | name | |||
) |
Set the name of the given io
to name
. A name is a label that can be used to store any naming scheme (file names, URI, etc.)
io | the io_t object | |
name | the name to be given to io |
0
on success, non-zero on error Definition at line 1017 of file io.c.
Referenced by u_file_open(), and u_tmpfile_open().