From 7a772b9cd43e6c39db46f6f70f6a9c72b7df7f2d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 25 Nov 2017 05:35:55 +0100 Subject: [PATCH] Create nbio_intf.c --- Makefile.common | 1 + griffin/griffin.c | 1 + libretro-common/file/nbio/nbio_intf.c | 48 ++++++++++++++++++++++++++ libretro-common/file/nbio/nbio_stdio.c | 28 ++++++++++----- libretro-common/include/file/nbio.h | 22 ++++++++++++ 5 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 libretro-common/file/nbio/nbio_intf.c diff --git a/Makefile.common b/Makefile.common index 7aeea49c68..e2ab3361ac 100644 --- a/Makefile.common +++ b/Makefile.common @@ -184,6 +184,7 @@ OBJ += frontend/frontend.o \ setting_list.o \ list_special.o \ $(LIBRETRO_COMM_DIR)/file/nbio/nbio_stdio.o \ + $(LIBRETRO_COMM_DIR)/file/nbio/nbio_intf.o \ $(LIBRETRO_COMM_DIR)/file/file_path.o \ file_path_special.o \ file_path_str.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index b65934f365..e781217661 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -822,6 +822,7 @@ FILE #include "../list_special.c" #include "../libretro-common/string/stdstring.c" #include "../libretro-common/file/nbio/nbio_stdio.c" +#include "../libretro-common/file/nbio/nbio_intf.c" /*============================================================ MESSAGE diff --git a/libretro-common/file/nbio/nbio_intf.c b/libretro-common/file/nbio/nbio_intf.c new file mode 100644 index 0000000000..b38e322a4d --- /dev/null +++ b/libretro-common/file/nbio/nbio_intf.c @@ -0,0 +1,48 @@ +#include +#include + +#include + +extern nbio_intf_t nbio_stdio; + +static nbio_intf_t *internal_nbio = &nbio_stdio; + +struct nbio_t* nbio_open(const char * filename, unsigned mode) +{ + return internal_nbio->open(filename, mode); +} + +void nbio_begin_read(struct nbio_t* handle) +{ + internal_nbio->begin_read(handle); +} + +void nbio_begin_write(struct nbio_t* handle) +{ + internal_nbio->begin_write(handle); +} + +bool nbio_iterate(struct nbio_t* handle) +{ + return internal_nbio->iterate(handle); +} + +void nbio_resize(struct nbio_t* handle, size_t len) +{ + internal_nbio->resize(handle, len); +} + +void *nbio_get_ptr(struct nbio_t* handle, size_t* len) +{ + return internal_nbio->get_ptr(handle, len); +} + +void nbio_cancel(struct nbio_t* handle) +{ + internal_nbio->cancel(handle); +} + +void nbio_free(struct nbio_t* handle) +{ + internal_nbio->free(handle); +} diff --git a/libretro-common/file/nbio/nbio_stdio.c b/libretro-common/file/nbio/nbio_stdio.c index 41f7cae867..8aee8cee43 100644 --- a/libretro-common/file/nbio/nbio_stdio.c +++ b/libretro-common/file/nbio/nbio_stdio.c @@ -35,7 +35,7 @@ static const char * modes[]={ "rb", "wb", "r+b", "rb", "wb", "r+b" }; static const wchar_t * modes[]={ L"rb", L"wb", L"r+b", L"rb", L"wb", L"r+b" }; #endif -struct nbio_t* nbio_open(const char * filename, unsigned mode) +static struct nbio_t* nbio_stdio_open(const char * filename, unsigned mode) { void *buf = NULL; struct nbio_t* handle = NULL; @@ -92,7 +92,7 @@ error: return NULL; } -void nbio_begin_read(struct nbio_t* handle) +static void nbio_stdio_begin_read(struct nbio_t* handle) { if (!handle) return; @@ -109,7 +109,7 @@ void nbio_begin_read(struct nbio_t* handle) handle->progress = 0; } -void nbio_begin_write(struct nbio_t* handle) +static void nbio_stdio_begin_write(struct nbio_t* handle) { if (!handle) return; @@ -125,7 +125,7 @@ void nbio_begin_write(struct nbio_t* handle) handle->progress = 0; } -bool nbio_iterate(struct nbio_t* handle) +static bool nbio_stdio_iterate(struct nbio_t* handle) { size_t amount = 65536; @@ -167,7 +167,7 @@ bool nbio_iterate(struct nbio_t* handle) return (handle->op < 0); } -void nbio_resize(struct nbio_t* handle, size_t len) +static void nbio_stdio_resize(struct nbio_t* handle, size_t len) { if (!handle) return; @@ -189,7 +189,7 @@ void nbio_resize(struct nbio_t* handle, size_t len) handle->progress = handle->len; } -void* nbio_get_ptr(struct nbio_t* handle, size_t* len) +static void *nbio_stdio_get_ptr(struct nbio_t* handle, size_t* len) { if (!handle) return NULL; @@ -200,7 +200,7 @@ void* nbio_get_ptr(struct nbio_t* handle, size_t* len) return NULL; } -void nbio_cancel(struct nbio_t* handle) +static void nbio_stdio_cancel(struct nbio_t* handle) { if (!handle) return; @@ -209,7 +209,7 @@ void nbio_cancel(struct nbio_t* handle) handle->progress = handle->len; } -void nbio_free(struct nbio_t* handle) +static void nbio_stdio_free(struct nbio_t* handle) { if (!handle) return; @@ -225,3 +225,15 @@ void nbio_free(struct nbio_t* handle) handle->data = NULL; free(handle); } + +nbio_intf_t nbio_stdio = { + nbio_stdio_open, + nbio_stdio_begin_read, + nbio_stdio_begin_write, + nbio_stdio_iterate, + nbio_stdio_resize, + nbio_stdio_get_ptr, + nbio_stdio_cancel, + nbio_stdio_free, + "nbio_stdio", +}; diff --git a/libretro-common/include/file/nbio.h b/libretro-common/include/file/nbio.h index 2d81b702b8..86b74098d6 100644 --- a/libretro-common/include/file/nbio.h +++ b/libretro-common/include/file/nbio.h @@ -53,6 +53,28 @@ RETRO_BEGIN_DECLS struct nbio_t; +typedef struct nbio_intf +{ + struct nbio_t* (*open)(const char * filename, unsigned mode); + + void (*begin_read)(struct nbio_t* handle); + + void (*begin_write)(struct nbio_t* handle); + + bool (*iterate)(struct nbio_t* handle); + + void (*resize)(struct nbio_t* handle, size_t len); + + void *(*get_ptr)(struct nbio_t* handle, size_t* len); + + void (*cancel)(struct nbio_t* handle); + + void (*free)(struct nbio_t* handle); + + /* Human readable string. */ + const char *ident; +} nbio_intf_t; + /* * Creates an nbio structure for performing the given operation on the given file. */