From 729665ede40d843671027e450d4edf67e7a127cb Mon Sep 17 00:00:00 2001 From: lexborisov Date: Thu, 16 Mar 2017 20:02:01 +0300 Subject: [PATCH] Fix for https://github.com/lexborisov/Modest/issues/26 --- Makefile | 2 +- include/mycore/myosi.h | 22 ++++++++++++---------- source/mycore/myosi.h | 22 ++++++++++++---------- source/myfont/myfont.c | 22 +++++++++++----------- source/myport/posix/mycore/io.c | 20 ++++++++++++++------ source/myport/windows_nt/mycore/io.c | 10 ++++++++++ 6 files changed, 60 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 1dc1a1a..2bfda0e 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ CC ?= gcc .DEFAULT_GOAL := all -DESCRIPTION := Modest is a fast HTML renderer implemented as a pure C99 library with no outside dependencies +DESCRIPTION := fast HTML renderer library with no outside dependency #******************** # other Makefile diff --git a/include/mycore/myosi.h b/include/mycore/myosi.h index c8445a6..563c44e 100644 --- a/include/mycore/myosi.h +++ b/include/mycore/myosi.h @@ -148,16 +148,18 @@ void * mycore_realloc(void* dst, size_t size); void * mycore_calloc(size_t num, size_t size); void * mycore_free(void* dst); -/** - * Platform-specific hdef performance clock queries. - * Implemented in perf.c - */ - -///** Get clock resolution */ -//uint64_t mycore_hperf_res(mystatus_t *status); -// -///** Get current value in clock ticks */ -//uint64_t mycore_hperf_clock(mystatus_t *status); +/* io */ +FILE * mycore_fopen(const char *filename, const char *mode); +int mycore_fclose(FILE *stream); + +size_t mycore_fread(void *buffer, size_t size, size_t count, FILE *stream); +size_t mycore_fwrite(const void *buffer, size_t size, size_t count, FILE *stream); +int mycore_fflush(FILE *stream); +int mycore_fseek(FILE* stream, long offset, int origin); +long mycore_ftell(FILE* stream); +int mycore_ferror(FILE *stream); + +void mycore_setbuf(FILE *stream, char *buffer); #ifdef __cplusplus } /* extern "C" */ diff --git a/source/mycore/myosi.h b/source/mycore/myosi.h index c8445a6..563c44e 100644 --- a/source/mycore/myosi.h +++ b/source/mycore/myosi.h @@ -148,16 +148,18 @@ void * mycore_realloc(void* dst, size_t size); void * mycore_calloc(size_t num, size_t size); void * mycore_free(void* dst); -/** - * Platform-specific hdef performance clock queries. - * Implemented in perf.c - */ - -///** Get clock resolution */ -//uint64_t mycore_hperf_res(mystatus_t *status); -// -///** Get current value in clock ticks */ -//uint64_t mycore_hperf_clock(mystatus_t *status); +/* io */ +FILE * mycore_fopen(const char *filename, const char *mode); +int mycore_fclose(FILE *stream); + +size_t mycore_fread(void *buffer, size_t size, size_t count, FILE *stream); +size_t mycore_fwrite(const void *buffer, size_t size, size_t count, FILE *stream); +int mycore_fflush(FILE *stream); +int mycore_fseek(FILE* stream, long offset, int origin); +long mycore_ftell(FILE* stream); +int mycore_ferror(FILE *stream); + +void mycore_setbuf(FILE *stream, char *buffer); #ifdef __cplusplus } /* extern "C" */ diff --git a/source/myfont/myfont.c b/source/myfont/myfont.c index b97adbd..a3f86b0 100644 --- a/source/myfont/myfont.c +++ b/source/myfont/myfont.c @@ -109,46 +109,46 @@ mystatus_t myfont_load_from_file(myfont_font_t *mf, const char *filepath, uint8_ size_t file_data_size; - FILE *fh = fopen(filepath, "rb"); + FILE *fh = mycore_fopen(filepath, "rb"); if(fh == NULL) return MyFONT_STATUS_ERROR_FILE_OPEN; - if(fseek(fh, 0L, SEEK_END)) { - fclose(fh); + if(mycore_fseek(fh, 0L, SEEK_END)) { + mycore_fclose(fh); return MyFONT_STATUS_ERROR_FILE_SEEK; } - long file_size = ftell(fh); + long file_size = mycore_ftell(fh); if(file_size == -1) { - fclose(fh); + mycore_fclose(fh); return MyFONT_STATUS_ERROR_FILE_TELL; } - if(fseek(fh, 0L, SEEK_SET)) { - fclose(fh); + if(mycore_fseek(fh, 0L, SEEK_SET)) { + mycore_fclose(fh); return MyFONT_STATUS_ERROR_FILE_SEEK; } if(file_size > 0) file_data_size = (size_t)file_size; else { - fclose(fh); + mycore_fclose(fh); return MyFONT_STATUS_ERROR_FILE_TOO_SMALL; } uint8_t* data = (uint8_t*)mycore_malloc(file_size); if(data == NULL) { - fclose(fh); + mycore_fclose(fh); return MyFONT_STATUS_ERROR_MEMORY_ALLOCATION; } if(fread(data, 1, file_size, fh) != file_size) { - fclose(fh); + mycore_fclose(fh); return MyFONT_STATUS_ERROR_FILE_READ; } - fclose(fh); + mycore_fclose(fh); if(return_data) *return_data = data; diff --git a/source/myport/posix/mycore/io.c b/source/myport/posix/mycore/io.c index 4316ce9..135f101 100644 --- a/source/myport/posix/mycore/io.c +++ b/source/myport/posix/mycore/io.c @@ -22,7 +22,7 @@ #include /* FILE */ -FILE * mycore_fopen(const char *restrict filename, const char *restrict mode) +FILE * mycore_fopen(const char *filename, const char *mode) { return fopen(filename, mode); } @@ -32,12 +32,12 @@ int mycore_fclose(FILE *stream) return fclose(stream); } -size_t mycore_fread(void *restrict buffer, size_t size, size_t count, FILE *restrict stream) +size_t mycore_fread(void *buffer, size_t size, size_t count, FILE *stream) { return fread(buffer, size, count, stream); } -size_t mycore_fwrite(const void *restrict buffer, size_t size, size_t count, FILE *restrict stream) +size_t mycore_fwrite(const void *buffer, size_t size, size_t count, FILE *stream) { return fwrite(buffer, size, count, stream); } @@ -47,15 +47,23 @@ int mycore_fflush(FILE *stream) return fflush(stream); } +int mycore_fseek(FILE* stream, long offset, int origin) +{ + return fseek(stream, offset, origin); +} + +long mycore_ftell(FILE* stream) +{ + return ftell(stream); +} + int mycore_ferror(FILE *stream) { return ferror(stream); } /* setbuf */ -void mycore_setbuf(FILE *restrict stream, char *restrict buffer) +void mycore_setbuf(FILE *stream, char *buffer) { setbuf(stream, buffer); } - - diff --git a/source/myport/windows_nt/mycore/io.c b/source/myport/windows_nt/mycore/io.c index 5ae1525..b383cd4 100644 --- a/source/myport/windows_nt/mycore/io.c +++ b/source/myport/windows_nt/mycore/io.c @@ -47,6 +47,16 @@ int mycore_fflush(FILE *stream) return fflush(stream); } +int mycore_fseek(FILE* stream, long offset, int origin) +{ + return fseek(stream, offset, origin); +} + +long mycore_ftell(FILE* stream) +{ + return ftell(stream); +} + int mycore_ferror(FILE *stream) { return ferror(stream);