This commit is contained in:
lexborisov 2017-03-16 20:02:01 +03:00
parent 43ab0fd013
commit 729665ede4
6 changed files with 60 additions and 38 deletions

View File

@ -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

View File

@ -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
*/
/* io */
FILE * mycore_fopen(const char *filename, const char *mode);
int mycore_fclose(FILE *stream);
///** 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);
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" */

View File

@ -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
*/
/* io */
FILE * mycore_fopen(const char *filename, const char *mode);
int mycore_fclose(FILE *stream);
///** 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);
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" */

View File

@ -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;

View File

@ -22,7 +22,7 @@
#include <stdarg.h>
/* 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);
}

View File

@ -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);