X-Git-Url: https://pd.if.org/git/?p=pdclib.old;a=blobdiff_plain;f=platform%2Fgandr%2Ffunctions%2Fstdio%2F_PDCLIB_fileops.c;fp=platform%2Fgandr%2Ffunctions%2Fstdio%2F_PDCLIB_fileops.c;h=9dff0ce00e71ecd7e2145593d2955ff82c6224c1;hp=0000000000000000000000000000000000000000;hb=4ee48c2e350472aa6832594409bbdcf87c0ade54;hpb=ad5b4430336998c5117621106beb00e3375d1d55 diff --git a/platform/gandr/functions/stdio/_PDCLIB_fileops.c b/platform/gandr/functions/stdio/_PDCLIB_fileops.c new file mode 100644 index 0000000..9dff0ce --- /dev/null +++ b/platform/gandr/functions/stdio/_PDCLIB_fileops.c @@ -0,0 +1,61 @@ +/* _PDCLIB_fileops + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#ifndef REGTEST +#include +#include +#include <_PDCLIB_glue.h> +#include +#include + +static bool readf( _PDCLIB_fd_t fd, void * buf, size_t length, + size_t * numBytesRead ) +{ + int rv = gd_read(fd.pointer, buf, length, numBytesRead ); + + return rv >= 0; +} + +static bool writef( _PDCLIB_fd_t fd, const void * buf, size_t length, + size_t * numBytesWritten ) +{ + int rv = gd_write(fd.pointer, buf, length, numBytesWritten ); + + return rv >= 0; +} + +static bool seekf( _PDCLIB_fd_t fd, int_fast64_t offset, int whence, + int_fast64_t* newPos ) +{ + int rv = gd_seek( fd.pointer, offset, whence, &newPos ); + + return rv >= 0; +} + +static void closef( _PDCLIB_fd_t self ) +{ + gd_close( self.pointer ); +} + +const _PDCLIB_fileops_t _PDCLIB_fileops = { + .read = readf, + .write = writef, + .seek = seekf, + .close = closef, +}; + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + // Tested by stdio test cases + return TEST_RESULTS; +} + +#endif