(rpng) Add stub code for nonblocking

This commit is contained in:
twinaphex 2015-02-20 02:34:17 +01:00
parent 4d631cba30
commit deb282af4d
2 changed files with 29 additions and 1 deletions

View File

@ -61,6 +61,9 @@ struct nbio_t* nbio_open(const char * filename, enum nbio_mode_t mode)
void nbio_begin_read(struct nbio_t* handle) void nbio_begin_read(struct nbio_t* handle)
{ {
if (!handle)
return;
if (handle->op >= 0) if (handle->op >= 0)
{ {
puts("ERROR - attempted file read operation while busy"); puts("ERROR - attempted file read operation while busy");
@ -90,6 +93,9 @@ bool nbio_iterate(struct nbio_t* handle)
{ {
size_t amount = 65536; size_t amount = 65536;
if (!handle)
return false;
if (amount > handle->len - handle->progress) if (amount > handle->len - handle->progress)
amount = handle->len - handle->progress; amount = handle->len - handle->progress;
@ -126,6 +132,8 @@ void nbio_resize(struct nbio_t* handle, size_t len)
void* nbio_get_ptr(struct nbio_t* handle, size_t* len) void* nbio_get_ptr(struct nbio_t* handle, size_t* len)
{ {
if (!handle)
return NULL;
if (len) if (len)
*len = handle->len; *len = handle->len;
if (handle->op == -1) if (handle->op == -1)

View File

@ -28,6 +28,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <file/nbio.h>
#ifdef GEKKO #ifdef GEKKO
#include <malloc.h> #include <malloc.h>
#endif #endif
@ -43,6 +45,8 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif #endif
//#define NONBLOCKING_TEST
static const uint8_t png_magic[8] = { static const uint8_t png_magic[8] = {
0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a, 0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a,
}; };
@ -805,7 +809,20 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
bool has_iend = false; bool has_iend = false;
bool has_plte = false; bool has_plte = false;
bool ret = true; bool ret = true;
FILE *file = fopen(path, "rb"); FILE *file;
#ifdef NONBLOCKING_TEST
size_t size = 0;
bool looped = false;
struct nbio_t* read = nbio_open(path, NBIO_READ);
void* ptr = nbio_get_ptr(read, &size);
nbio_begin_read(read);
while (!nbio_iterate(read)) looped=true;
ptr = nbio_get_ptr(read, &size);
(void)ptr;
(void)looped;
#endif
file = fopen(path, "rb");
if (!file) if (!file)
{ {
@ -848,6 +865,9 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
width, height); width, height);
end: end:
#ifdef NONBLOCKING_TEST
nbio_free(read);
#endif
if (file) if (file)
fclose(file); fclose(file);
if (!ret) if (!ret)