X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fmy.c;h=bfae25f516d150ccbf2edd38e3af7eaea89ac493;hb=d070670f189ec66ed2ac6b45834a192c004bc92f;hp=0a7fcbcd6ce4a20958b2d915e730c2ee9fb89a81;hpb=e5c2eddc151a59db4e611a77901732d7c15fde90;p=flatwaifu.git diff --git a/src/my.c b/src/my.c index 0a7fcbc..bfae25f 100644 --- a/src/my.c +++ b/src/my.c @@ -23,7 +23,10 @@ #include #include "glob.h" #include "error.h" +#include "misc.h" #include +#include +#include void mysplitpath(const char* path, char* drv, char* dir, char* name, char* ext) { @@ -78,18 +81,50 @@ void mysplitpath(const char* path, char* drv, char* dir, char* name, char* ext) } } -size_t myfreadc(void *ptr, size_t size, size_t n, FILE *f) { +size_t myfreadc (void *ptr, size_t size, size_t n, FILE *f) { return fread(ptr, size, n, f); } -void myfread(void *ptr, size_t size, size_t n, FILE *f) { +void myfread (void *ptr, size_t size, size_t n, FILE *f) { if (myfreadc(ptr, size, n, f) != n) { ERR_fatal("File reading error\n"); } } -void myfwrite(void *ptr, size_t n, size_t size, FILE *f) { - size_t s = fwrite(ptr,n,size,f); +int8_t myfread8 (FILE *f) { + int8_t x; + myfread(&x, 1, 1, f); + return x; +} + +int16_t myfread16 (FILE *f) { + int16_t x; + myfread(&x, 2, 1, f); + return short2host(x); +} + +int32_t myfread32 (FILE *f) { + int32_t x; + myfread(&x, 4, 1, f); + return int2host(x); +} + +void myfwrite (void *ptr, size_t size, size_t n, FILE *f) { + assert(fwrite(ptr, size, n, f) == n); +} + +void myfwrite8 (int8_t x, FILE *f) { + myfwrite(&x, 1, 1, f); +} + +void myfwrite16 (int16_t x, FILE *f) { + x = short2host(x); + myfwrite(&x, 2, 1, f); +} + +void myfwrite32 (int32_t x, FILE *f) { + x = int2host(x); + myfwrite(&x, 4, 1, f); } void myrandomize(void)