diff --git a/libretro-common/file/nbio/nbio_stdio.c b/libretro-common/file/nbio/nbio_stdio.c index 88bf5af78e..8c9c4635be 100644 --- a/libretro-common/file/nbio/nbio_stdio.c +++ b/libretro-common/file/nbio/nbio_stdio.c @@ -20,7 +20,7 @@ struct nbio_t static const char * modes[]={ "rb", "wb", "r+b" }; -struct nbio_t* nbio_open(const char * filename, enum nbio_mode_t mode) +struct nbio_t* nbio_open(const char * filename, unsigned mode) { struct nbio_t* handle = NULL; FILE* f=fopen(filename, modes[mode]); diff --git a/libretro-common/formats/png/rpng.c b/libretro-common/formats/png/rpng.c index a2986f90fe..fc6f33e260 100644 --- a/libretro-common/formats/png/rpng.c +++ b/libretro-common/formats/png/rpng.c @@ -794,6 +794,10 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, unsigned *height) { long pos, file_len; +#ifdef NONBLOCKING_TEST + uint8_t *buff_data = NULL; + struct nbio_t* nbread = NULL; +#endif uint8_t *inflate_buf = NULL; struct idat_buffer idat_buf = {0}; struct png_ihdr ihdr = {0}; @@ -805,16 +809,20 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, bool ret = true; 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); + { + size_t size = 0; + bool looped = false; + nbread = nbio_open(path, NBIO_READ); + void* ptr = nbio_get_ptr(nbread, &size); + nbio_begin_read(nbread); - while (!nbio_iterate(read)) looped=true; - ptr = nbio_get_ptr(read, &size); - (void)ptr; - (void)looped; + while (!nbio_iterate(nbread)) looped=true; + ptr = nbio_get_ptr(nbread, &size); + (void)ptr; + (void)looped; + + buff_data = (uint8_t*)ptr; + } #endif file = fopen(path, "rb"); @@ -828,17 +836,19 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, GOTO_END_ERROR(); { + unsigned i; char header[8]; #ifdef NONBLOCKING_TEST - /* TODO/FIXME */ + for (i = 0; i < 8; i++) + header[i] = buff_data[i]; #else if (fread(header, 1, sizeof(header), file) != sizeof(header)) return false; +#endif if (memcmp(header, png_magic, sizeof(png_magic)) != 0) return false; -#endif } /* feof() apparently isn't triggered after a seek (IEND). */ @@ -874,7 +884,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, end: #ifdef NONBLOCKING_TEST - nbio_free(read); + nbio_free(nbread); #endif if (file) fclose(file); diff --git a/libretro-common/include/file/nbio.h b/libretro-common/include/file/nbio.h index 522b1e9548..910deaae3d 100644 --- a/libretro-common/include/file/nbio.h +++ b/libretro-common/include/file/nbio.h @@ -4,20 +4,16 @@ #include #include -enum nbio_mode -{ - /* The comments tell which mode in fopen() it corresponds to. */ - NBIO_READ = 0,/* rb */ - NBIO_WRITE, /* wb */ - NBIO_UPDATE, /* r+b */ -}; +#define NBIO_READ 0 +#define NBIO_WRITE 1 +#define NBIO_UPDATE 2 struct nbio_t; /* * Creates an nbio structure for performing the given operation on the given file. */ -struct nbio_t* nbio_open(const char * filename, enum nbio_mode_t mode); +struct nbio_t* nbio_open(const char * filename, unsigned mode); /* * Starts reading the given file. When done, it will be available in nbio_get_ptr. @@ -59,4 +55,4 @@ void nbio_cancel(struct nbio_t* handle); */ void nbio_free(struct nbio_t* handle); -#endif \ No newline at end of file +#endif