Basic Functions
[Input/Output]

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.

Function Documentation

enum io_type_e io_type ( io_t *  io  ) 

Return the type of the given io (see enum io_type_e).

Parameters:
io input IO object
Returns:
on of enum io_type_e defined item

Definition at line 43 of file io.c.

ssize_t io_pipe ( io_t *  out,
io_t *  in 
)

Read all data from in and copy it to out

Parameters:
out output IO object
in input IO object
Returns:
the number of bytes read from 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.

Parameters:
io the io_t object to be dupped
pio on success will contain the duplicated io_t object
Returns:
0 on success, not zero on failure
See also:
io_free

Definition at line 106 of file io.c.

ssize_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

Parameters:
out output io_t object
in input io_t object
size number of bytes to copy
Returns:
the number of bytes copied (that can be less the 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.

Parameters:
io the io_t object
off absolute offset to move to
Returns:
the given offset on success, -1 on error

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.

Parameters:
io the io_t object
Returns:
the given offset on success, -1 on error

Definition at line 197 of file io.c.

References io_flush().

int io_close ( io_t *  io  ) 

Close the underlying source/sink of the given io_t object.

Parameters:
io the io_t object to be free'd
Returns:
0 on success, non-zero on error
See also:
io_dup

Definition at line 442 of file io.c.

Referenced by io_free().

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.

Parameters:
io the io_t object to be free'd
Returns:
0 on success, non-zero on error
See also:
io_dup

Definition 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).

Parameters:
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
Returns:
the number of bytes read and saved to 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.

Parameters:
io the io_t object to write to
fmt printf-style format string
ap variable list arguments
Returns:
the number of chars written on success, -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.

Parameters:
io the io_t object to write to
fmt printf-style format string
... format string arguments
Returns:
the number of chars written on success, -1 on error

Definition at line 692 of file io.c.

References io_vprintf().

ssize_t io_flush ( io_t *  io  ) 

Force a write of all buffered data to the output device.

Parameters:
io the io_t object to be flushed
Returns:
zero on success, -1 on error

Definition at line 722 of file io.c.

Referenced by io_free(), io_seek(), io_tell(), and io_write().

ssize_t io_write ( io_t *  io,
const char *  buf,
size_t  size 
)

Write size bytes of buf to io.

Parameters:
io the io_t object
buf the buffer with the bytes to write
size number of bytes to write
Returns:
the number of bytes written or -1 on error.

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

Parameters:
io the io_t object
c the char to write
Returns:
the number of bytes written (i.e. 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]

Read a char from the io_t object io and save it at *pc.

Parameters:
io the io_t object
pc on success will hold the read character
Returns:
the number of bytes read (i.e. 1) on success or -1 on error.

Definition at line 815 of file io.c.

References io_read().

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.

Parameters:
io the io_t object
stop_at reads until this character is found
buf destination buffer
size size of buf
Returns:
the length of the line on success, 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.

Parameters:
io the io_t object
buf destination buffer
size size of buf
Returns:
the length of the line on success, 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 
)
Parameters:
io the io_t object
c the codec to append
Returns:
0 on success, non-zero on error

Definition at line 943 of file io.c.

int io_codec_add_tail ( io_t *  io,
codec_t *  c 
)
Parameters:
io the io_t object
c the codec to append
Returns:
0 on success, non-zero on error

Definition at line 963 of file io.c.

int io_codecs_remove ( io_t *  io  ) 
Parameters:
io the io_t object
Returns:
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.)

Parameters:
io the io_t object
name the name to be given to io
Returns:
0 on success, non-zero on error

Definition at line 1017 of file io.c.

Referenced by u_file_open(), and u_tmpfile_open().

int io_name_get ( io_t *  io,
char *  name,
size_t  sz 
)

Save in name the name of io.

Parameters:
io the io_t object
name on success will contain the name of the given io
sz size of name
Returns:
0 on success, non-zero on error

Definition at line 1048 of file io.c.


←Products
Copyright © 2005-2012 - KoanLogic S.r.l. - All rights reserved