aboutsummaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c97
1 files changed, 48 insertions, 49 deletions
diff --git a/src/io.c b/src/io.c
index 7fc04cf..8322707 100644
--- a/src/io.c
+++ b/src/io.c
@@ -4,21 +4,20 @@
#define BUFFER_SIZE (sizeof(char *))
-
-struct bh_io_s
+struct BH_IO
{
- bh_io_func_t func;
+ BH_IOCallback cb;
};
-bh_io_t *bh_io_new(bh_io_func_t func,
- void *data)
+BH_IO *BH_IONew(BH_IOCallback cb,
+ void *data)
{
size_t requested;
- bh_io_t *io;
+ BH_IO *io;
/* Get information about IO device size */
- if (func(NULL, BH_IO_INFO_CB, &requested, NULL))
+ if (cb(NULL, BH_IO_INFO_CB, &requested, NULL))
return NULL;
/* Allocate space for the IO device */
@@ -27,8 +26,8 @@ bh_io_t *bh_io_new(bh_io_func_t func,
return NULL;
/* Initialize IO device */
- io->func = func;
- if (func(io + 1, BH_IO_INIT_CB, data, NULL))
+ io->cb = cb;
+ if (cb(io + 1, BH_IO_INIT_CB, data, NULL))
{
free(io);
return NULL;
@@ -38,28 +37,28 @@ bh_io_t *bh_io_new(bh_io_func_t func,
}
-void bh_io_free(bh_io_t *io)
+void BH_IOFree(BH_IO *io)
{
/* Prevent working with NULL io */
if (!io)
return;
/* Call the IO device destruction handler */
- io->func(io + 1, BH_IO_DESTROY_CB, NULL, NULL);
+ io->cb(io + 1, BH_IO_DESTROY_CB, NULL, NULL);
/* Deallocate object */
free(io);
}
-const char *bh_io_classname(bh_io_t *io)
+const char *BH_IOClassname(BH_IO *io)
{
const char *name;
if (!io)
goto error;
- if (io->func(io + 1, BH_IO_INFO_CB, NULL, &name) != BH_OK)
+ if (io->cb(io + 1, BH_IO_INFO_CB, NULL, &name) != BH_OK)
goto error;
return name;
@@ -69,33 +68,33 @@ error:
}
-int bh_io_open(bh_io_t *io,
- int mode)
+int BH_IOOpen(BH_IO *io,
+ int mode)
{
/* Prevent working with NULL io */
if (!io)
return BH_ERROR;
/* Call the IO device open handler with specified mode */
- return io->func(io + 1, BH_IO_OPEN_CB, &mode, NULL);
+ return io->cb(io + 1, BH_IO_OPEN_CB, &mode, NULL);
}
-int bh_io_close(bh_io_t *io)
+int BH_IOClose(BH_IO *io)
{
/* Prevent working with NULL io */
if (!io)
return BH_ERROR;
/* Call the IO device close handler */
- return io->func(io + 1, BH_IO_CLOSE_CB, NULL, NULL);
+ return io->cb(io + 1, BH_IO_CLOSE_CB, NULL, NULL);
}
-int bh_io_read(bh_io_t *io,
- char *buffer,
- size_t size,
- size_t *actual)
+int BH_IORead(BH_IO *io,
+ char *buffer,
+ size_t size,
+ size_t *actual)
{
int code;
@@ -104,7 +103,7 @@ int bh_io_read(bh_io_t *io,
return BH_ERROR;
/* Call the IO device read handler */
- code = io->func(io + 1, BH_IO_READ_CB, buffer, &size);
+ code = io->cb(io + 1, BH_IO_READ_CB, buffer, &size);
/* If caller wants to know actual read size - report it back */
if (actual)
@@ -114,10 +113,10 @@ int bh_io_read(bh_io_t *io,
}
-int bh_io_write(bh_io_t *io,
- const char *buffer,
- size_t size,
- size_t *actual)
+int BH_IOWrite(BH_IO *io,
+ const char *buffer,
+ size_t size,
+ size_t *actual)
{
int code;
@@ -126,7 +125,7 @@ int bh_io_write(bh_io_t *io,
return BH_ERROR;
/* Call the IO device write handler */
- code = io->func(io + 1, BH_IO_WRITE_CB, (void *)buffer, &size);
+ code = io->cb(io + 1, BH_IO_WRITE_CB, (void *)buffer, &size);
/* If caller wants to know actual written size - report it back */
if (actual)
@@ -135,10 +134,10 @@ int bh_io_write(bh_io_t *io,
return code;
}
-int bh_io_peek(bh_io_t *io,
- char *buffer,
- size_t size,
- size_t *actual)
+int BH_IOPeek(BH_IO *io,
+ char *buffer,
+ size_t size,
+ size_t *actual)
{
int code;
@@ -147,7 +146,7 @@ int bh_io_peek(bh_io_t *io,
return BH_ERROR;
/* Call the IO device peek handler */
- code = io->func(io + 1, BH_IO_PEEK_CB, (void *)buffer, &size);
+ code = io->cb(io + 1, BH_IO_PEEK_CB, (void *)buffer, &size);
/* If caller wants to know actual written size - report it back */
if (actual)
@@ -157,71 +156,71 @@ int bh_io_peek(bh_io_t *io,
}
-int bh_io_tell(bh_io_t *io,
- int64_t *position)
+int BH_IOTell(BH_IO *io,
+ int64_t *position)
{
/* Prevent working with NULL io */
if (!io)
return BH_ERROR;
/* Call the IO device tell handler */
- return io->func(io + 1, BH_IO_TELL_CB, position, NULL);
+ return io->cb(io + 1, BH_IO_TELL_CB, position, NULL);
}
-int bh_io_seek(bh_io_t *io,
- int64_t position,
- int direction)
+int BH_IOSeek(BH_IO *io,
+ int64_t position,
+ int direction)
{
/* Prevent working with NULL io */
if (!io)
return BH_ERROR;
/* Call the IO device seek handler */
- return io->func(io + 1, BH_IO_SEEK_CB, &position, &direction);
+ return io->cb(io + 1, BH_IO_SEEK_CB, &position, &direction);
}
-int bh_io_flush(bh_io_t *io)
+int BH_IOFlush(BH_IO *io)
{
/* Prevent working with NULL io */
if (!io)
return BH_ERROR;
/* Call the IO device flush handler */
- return io->func(io + 1, BH_IO_FLUSH_CB, NULL, NULL);
+ return io->cb(io + 1, BH_IO_FLUSH_CB, NULL, NULL);
}
-int bh_io_size(bh_io_t *io,
- int64_t *size)
+int BH_IOSize(BH_IO *io,
+ int64_t *size)
{
/* Prevent working with NULL io */
if (!io)
return BH_ERROR;
/* Call the IO device size handler */
- return io->func(io + 1, BH_IO_SIZE_CB, size, NULL);
+ return io->cb(io + 1, BH_IO_SIZE_CB, size, NULL);
}
-int bh_io_flags(bh_io_t *io)
+int BH_IOFlags(BH_IO *io)
{
/* Prevent working with NULL io */
if (!io)
return BH_IO_FLAG_ERROR;
/* Call the IO device flags handler */
- return io->func(io + 1, BH_IO_FLAGS_CB, NULL, NULL);
+ return io->cb(io + 1, BH_IO_FLAGS_CB, NULL, NULL);
}
-int bh_io_clear(bh_io_t *io)
+int BH_IOClear(BH_IO *io)
{
/* Prevent working with NULL io */
if (!io)
return BH_OK;
/* Call the IO device clear error handler */
- return io->func(io + 1, BH_IO_CLEAR_CB, NULL, NULL);
+ return io->cb(io + 1, BH_IO_CLEAR_CB, NULL, NULL);
}