Commit 313293e7 authored by conrad's avatar conrad

liboggz::oggz_io: handle out of memory (& update API docs)


git-svn-id: http://svn.annodex.net/liboggz/trunk@3820 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 5f3ff711
......@@ -125,6 +125,7 @@ typedef int (*OggzIOFlush) (void * user_handle);
* \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ; \a oggz not
* open for reading.
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*/
int oggz_io_set_read (OGGZ * oggz, OggzIORead read, void * user_handle);
......@@ -147,6 +148,7 @@ void * oggz_io_get_read_user_handle (OGGZ * oggz);
* \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ; \a oggz not
* open for writing.
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*/
int oggz_io_set_write (OGGZ * oggz, OggzIOWrite write, void * user_handle);
......@@ -168,6 +170,7 @@ void * oggz_io_get_write_user_handle (OGGZ * oggz);
* \retval 0 Success
* \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*
* \note If you provide an OggzIOSeek function, you MUST also provide
* an OggzIOTell function, or else all your seeks will fail.
......@@ -193,6 +196,7 @@ void * oggz_io_get_seek_user_handle (OGGZ * oggz);
* \retval 0 Success
* \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*/
int oggz_io_set_tell (OGGZ * oggz, OggzIOTell tell, void * user_handle);
......@@ -216,6 +220,7 @@ void * oggz_io_get_tell_user_handle (OGGZ * oggz);
* \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ; \a oggz not
* open for writing.
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*/
int oggz_io_set_flush (OGGZ * oggz, OggzIOFlush flush, void * user_handle);
......
......@@ -176,11 +176,15 @@ oggz_io_flush (OGGZ * oggz)
/* get/set functions */
static void
static int
oggz_io_init (OGGZ * oggz)
{
oggz->io = (OggzIO *) oggz_malloc (sizeof (OggzIO));
if (oggz->io == NULL) return -1;
memset (oggz->io, 0, sizeof (OggzIO));
return 0;
}
int
......@@ -189,7 +193,10 @@ oggz_io_set_read (OGGZ * oggz, OggzIORead read, void * user_handle)
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
if (oggz->file != NULL) return OGGZ_ERR_INVALID;
if (oggz->io == NULL) oggz_io_init (oggz);
if (oggz->io == NULL) {
if (oggz_io_init (oggz) == -1)
return OGGZ_ERR_OUT_OF_MEMORY;
}
oggz->io->read = read;
oggz->io->read_user_handle = user_handle;
......@@ -214,7 +221,10 @@ oggz_io_set_write (OGGZ * oggz, OggzIOWrite write, void * user_handle)
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
if (oggz->file != NULL) return OGGZ_ERR_INVALID;
if (oggz->io == NULL) oggz_io_init (oggz);
if (oggz->io == NULL) {
if (oggz_io_init (oggz) == -1)
return OGGZ_ERR_OUT_OF_MEMORY;
}
oggz->io->write = write;
oggz->io->write_user_handle = user_handle;
......@@ -239,7 +249,10 @@ oggz_io_set_seek (OGGZ * oggz, OggzIOSeek seek, void * user_handle)
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
if (oggz->file != NULL) return OGGZ_ERR_INVALID;
if (oggz->io == NULL) oggz_io_init (oggz);
if (oggz->io == NULL) {
if (oggz_io_init (oggz) == -1)
return OGGZ_ERR_OUT_OF_MEMORY;
}
oggz->io->seek = seek;
oggz->io->seek_user_handle = user_handle;
......@@ -264,7 +277,10 @@ oggz_io_set_tell (OGGZ * oggz, OggzIOTell tell, void * user_handle)
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
if (oggz->file != NULL) return OGGZ_ERR_INVALID;
if (oggz->io == NULL) oggz_io_init (oggz);
if (oggz->io == NULL) {
if (oggz_io_init (oggz) == -1)
return OGGZ_ERR_OUT_OF_MEMORY;
}
oggz->io->tell = tell;
oggz->io->tell_user_handle = user_handle;
......@@ -289,7 +305,10 @@ oggz_io_set_flush (OGGZ * oggz, OggzIOFlush flush, void * user_handle)
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
if (oggz->file != NULL) return OGGZ_ERR_INVALID;
if (oggz->io == NULL) oggz_io_init (oggz);
if (oggz->io == NULL) {
if (oggz_io_init (oggz) == -1)
return OGGZ_ERR_OUT_OF_MEMORY;
}
oggz->io->flush = flush;
oggz->io->flush_user_handle = user_handle;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment