From 1a4c60ac657e9dbc91e32c069a01e666a26d7ec6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 23 Sep 2015 13:49:45 +0200 Subject: [PATCH] (rxml) Use retro_file --- libretro-common/formats/xml/Makefile | 9 +++++++-- libretro-common/formats/xml/rxml.c | 26 ++++++++++++++------------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/libretro-common/formats/xml/Makefile b/libretro-common/formats/xml/Makefile index 3c2a6e1fcb..1186c8e42d 100644 --- a/libretro-common/formats/xml/Makefile +++ b/libretro-common/formats/xml/Makefile @@ -1,9 +1,14 @@ TARGET := rxml -SOURCES := $(wildcard *.c) +LIBRETRO_COMM_DIR := ../.. + +SOURCES := \ + $(wildcard *.c) \ + $(LIBRETRO_COMM_DIR)/file/retro_file.c + OBJS := $(SOURCES:.c=.o) -CFLAGS += -DRXML_TEST -Wall -pedantic -std=gnu99 -O0 -g -I../../include +CFLAGS += -DRXML_TEST -Wall -pedantic -std=gnu99 -g -I$(LIBRETRO_COMM_DIR)/include all: $(TARGET) diff --git a/libretro-common/formats/xml/rxml.c b/libretro-common/formats/xml/rxml.c index 410fbf6230..73f03b6ae0 100644 --- a/libretro-common/formats/xml/rxml.c +++ b/libretro-common/formats/xml/rxml.c @@ -20,16 +20,20 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include #include +#include #include #include +#include + #include -#include + #include +#include #include +#include + struct rxml_document { struct rxml_node *root_node; @@ -414,8 +418,7 @@ rxml_document_t *rxml_load_document(const char *path) char *new_memory_buffer = NULL; const char *mem_ptr = NULL; long len = 0; - - FILE *file = fopen(path, "r"); + RFILE *file = retro_fopen(path, RFILE_MODE_READ, -1); if (!file) return NULL; @@ -423,19 +426,19 @@ rxml_document_t *rxml_load_document(const char *path) if (!doc) goto error; - fseek(file, 0, SEEK_END); - len = ftell(file); - rewind(file); + retro_fseek(file, 0, SEEK_END); + len = retro_ftell(file); + retro_frewind(file); memory_buffer = (char*)malloc(len + 1); if (!memory_buffer) goto error; memory_buffer[len] = '\0'; - if (fread(memory_buffer, 1, len, file) != (size_t)len) + if (retro_fread(file, memory_buffer, len) != (size_t)len) goto error; - fclose(file); + retro_fclose(file); file = NULL; mem_ptr = memory_buffer; @@ -459,8 +462,7 @@ rxml_document_t *rxml_load_document(const char *path) error: free(memory_buffer); - if (file) - fclose(file); + retro_fclose(file); rxml_free_document(doc); return NULL; }