X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fmy.c;h=bfae25f516d150ccbf2edd38e3af7eaea89ac493;hb=1907773f7b61fb7e58c585a183180b44d213a286;hp=08877e98cc0e8edf835d80565694f5854ff6f27a;hpb=c7891b56fec4c7f8c85d28e33bb34e5d4b88d616;p=flatwaifu.git diff --git a/src/my.c b/src/my.c index 08877e9..bfae25f 100644 --- a/src/my.c +++ b/src/my.c @@ -22,9 +22,11 @@ #include #include "glob.h" -#include "keyb.h" #include "error.h" +#include "misc.h" #include +#include +#include void mysplitpath(const char* path, char* drv, char* dir, char* name, char* ext) { @@ -79,16 +81,50 @@ void mysplitpath(const char* path, char* drv, char* dir, char* name, char* ext) } } -void myfread(void *ptr, size_t n, size_t size, FILE *f) { - if (fread(ptr,n,size,f) != size) ERR_fatal("File reading error\n"); +size_t myfreadc (void *ptr, size_t size, size_t n, FILE *f) { + return fread(ptr, size, n, f); } -size_t myfreadc(void *ptr, size_t n, size_t size, FILE *f) { - return fread(ptr,n,size,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)