(rxml) Use retro_file

This commit is contained in:
twinaphex 2015-09-23 13:49:45 +02:00
parent d92bf9b559
commit 1a4c60ac65
2 changed files with 21 additions and 14 deletions

View File

@ -1,9 +1,14 @@
TARGET := rxml TARGET := rxml
SOURCES := $(wildcard *.c) LIBRETRO_COMM_DIR := ../..
SOURCES := \
$(wildcard *.c) \
$(LIBRETRO_COMM_DIR)/file/retro_file.c
OBJS := $(SOURCES:.c=.o) 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) all: $(TARGET)

View File

@ -20,16 +20,20 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <formats/rxml.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdint.h>
#include <boolean.h> #include <boolean.h>
#include <retro_file.h>
#include <compat/posix_string.h> #include <compat/posix_string.h>
#include <formats/rxml.h>
struct rxml_document struct rxml_document
{ {
struct rxml_node *root_node; struct rxml_node *root_node;
@ -414,8 +418,7 @@ rxml_document_t *rxml_load_document(const char *path)
char *new_memory_buffer = NULL; char *new_memory_buffer = NULL;
const char *mem_ptr = NULL; const char *mem_ptr = NULL;
long len = 0; long len = 0;
RFILE *file = retro_fopen(path, RFILE_MODE_READ, -1);
FILE *file = fopen(path, "r");
if (!file) if (!file)
return NULL; return NULL;
@ -423,19 +426,19 @@ rxml_document_t *rxml_load_document(const char *path)
if (!doc) if (!doc)
goto error; goto error;
fseek(file, 0, SEEK_END); retro_fseek(file, 0, SEEK_END);
len = ftell(file); len = retro_ftell(file);
rewind(file); retro_frewind(file);
memory_buffer = (char*)malloc(len + 1); memory_buffer = (char*)malloc(len + 1);
if (!memory_buffer) if (!memory_buffer)
goto error; goto error;
memory_buffer[len] = '\0'; 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; goto error;
fclose(file); retro_fclose(file);
file = NULL; file = NULL;
mem_ptr = memory_buffer; mem_ptr = memory_buffer;
@ -459,8 +462,7 @@ rxml_document_t *rxml_load_document(const char *path)
error: error:
free(memory_buffer); free(memory_buffer);
if (file) retro_fclose(file);
fclose(file);
rxml_free_document(doc); rxml_free_document(doc);
return NULL; return NULL;
} }