1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-03 00:38:44 +00:00

Create nbio_intf.c

This commit is contained in:
twinaphex 2017-11-25 05:35:55 +01:00
parent 81e543a4c9
commit 7a772b9cd4
5 changed files with 92 additions and 8 deletions

View File

@ -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 \

View File

@ -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

View File

@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>
#include <file/nbio.h>
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);
}

View File

@ -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",
};

View File

@ -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.
*/