1 /* _PDCLIB_fillbuffer( struct _PDCLIB_file_t * )
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
7 /* This is an example implementation of _PDCLIB_fillbuffer() fit for
8 use with POSIX kernels.
14 #include <_PDCLIB_glue.h>
16 #include </usr/include/errno.h>
19 extern ssize_t read( int fd, void * buf, size_t count );
21 int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream )
23 /* No need to handle buffers > INT_MAX, as PDCLib doesn't allow them */
24 ssize_t rc = read( stream->handle, stream->buffer, stream->bufsize );
27 /* Reading successful. */
28 if ( ! ( stream->status & _PDCLIB_FBIN ) )
30 /* TODO: Text stream conversion here */
32 stream->pos.offset += rc;
42 /* See comments on implementation-defined errno values in
50 _PDCLIB_errno = _PDCLIB_ERROR;
53 /* This should be something like EUNKNOWN. */
54 _PDCLIB_errno = _PDCLIB_ERROR;
57 stream->status |= _PDCLIB_ERRORFLAG;
61 stream->status |= _PDCLIB_EOFFLAG;
68 #include <_PDCLIB_test.h>
72 /* Testing covered by ftell.c */