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.
15 #include "_PDCLIB_glue.h"
17 #include </usr/include/errno.h>
20 extern ssize_t read( int fd, void * buf, size_t count );
22 int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream )
24 /* No need to handle buffers > INT_MAX, as PDCLib doesn't allow them */
25 ssize_t rc = read( stream->handle, stream->buffer, stream->bufsize );
28 /* Reading successful. */
29 if ( ! ( stream->status & _PDCLIB_FBIN ) )
31 /* TODO: Text stream conversion here */
33 stream->pos.offset += rc;
43 /* See comments on implementation-defined errno values in
51 _PDCLIB_errno = _PDCLIB_ERROR;
54 /* This should be something like EUNKNOWN. */
55 _PDCLIB_errno = _PDCLIB_ERROR;
58 stream->status |= _PDCLIB_ERRORFLAG;
62 stream->status |= _PDCLIB_EOFFLAG;
70 #include "_PDCLIB_test.h"
74 /* Testing covered by ftell.c */