X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample_cygwin%2Ffunctions%2F_PDCLIB%2Ffillbuffer.c;fp=platform%2Fexample_cygwin%2Ffunctions%2F_PDCLIB%2Ffillbuffer.c;h=ecfb96859bcc668b63bfe866d6aca7b4017e5ba8;hb=0c316ee3b4dc0712797877f5dc0f4a789646154d;hp=0000000000000000000000000000000000000000;hpb=ffa73a4a2673fece7cd63c471476db6bc4aef9e6;p=pdclib diff --git a/platform/example_cygwin/functions/_PDCLIB/fillbuffer.c b/platform/example_cygwin/functions/_PDCLIB/fillbuffer.c new file mode 100644 index 0000000..ecfb968 --- /dev/null +++ b/platform/example_cygwin/functions/_PDCLIB/fillbuffer.c @@ -0,0 +1,74 @@ +/* $Id$ */ + +/* _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +/* This is an example implementation of _PDCLIB_fillbuffer() fit for + use with POSIX kernels. +*/ + +#include + +#ifndef REGTEST +#include <_PDCLIB_glue.h> + +#include + +typedef long ssize_t; +extern ssize_t read( int fd, void * buf, size_t count ); + +int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) +{ + /* No need to handle buffers > INT_MAX, as PDCLib doesn't allow them */ + ssize_t rc = read( stream->handle, stream->buffer, stream->bufsize ); + if ( rc > 0 ) + { + /* Reading successful. */ + if ( ! ( stream->status & _PDCLIB_FBIN ) ) + { + /* TODO: Text stream conversion here */ + } + stream->bufend = rc; + stream->bufidx = 0; + return 0; + } + if ( rc < 0 ) + { + /* Reading error */ + switch ( errno ) + { + case EBADF: + case EFAULT: + case EINTR: + case EINVAL: + case EIO: + _PDCLIB_errno = _PDCLIB_EIO; + break; + default: + _PDCLIB_errno = _PDCLIB_EUNKNOWN; + break; + } + stream->status |= _PDCLIB_ERRORFLAG; + return EOF; + } + /* End-of-File */ + stream->status |= _PDCLIB_EOFFLAG; + return EOF; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + /* Testing covered by ftell.c */ + return TEST_RESULTS; +} + +#endif +