]> pd.if.org Git - pdclib/blob - platform/example_cygwin/functions/_PDCLIB/fillbuffer.c
Comment cleanups.
[pdclib] / platform / example_cygwin / functions / _PDCLIB / fillbuffer.c
1 /* _PDCLIB_fillbuffer( struct _PDCLIB_file_t * )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 /* This is an example implementation of _PDCLIB_fillbuffer() fit for
8    use with POSIX kernels.
9 */
10
11 #include <stdio.h>
12
13 #ifndef REGTEST
14 #include <_PDCLIB_glue.h>
15
16 #include </usr/include/errno.h>
17
18 typedef long ssize_t;
19 extern ssize_t read( int fd, void * buf, size_t count );
20
21 int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream )
22 {
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 );
25     if ( rc > 0 )
26     {
27         /* Reading successful. */
28         if ( ! ( stream->status & _PDCLIB_FBIN ) )
29         {
30             /* TODO: Text stream conversion here */
31         }
32         stream->bufend = rc;
33         stream->bufidx = 0;
34         return 0;
35     }
36     if ( rc < 0 )
37     {
38         /* Reading error */
39         switch ( errno )
40         {
41             /* See comments on implementation-defined errno values in
42                <_PDCLIB_config.h>.
43             */
44             case EBADF:
45             case EFAULT:
46             case EINTR:
47             case EINVAL:
48             case EIO:
49                 _PDCLIB_errno = _PDCLIB_ERROR;
50                 break;
51             default:
52                 /* This should be something like EUNKNOWN. */
53                 _PDCLIB_errno = _PDCLIB_ERROR;
54                 break;
55         }
56         stream->status |= _PDCLIB_ERRORFLAG;
57         return EOF;
58     }
59     /* End-of-File */
60     stream->status |= _PDCLIB_EOFFLAG;
61     return EOF;
62 }
63
64 #endif
65
66 #ifdef TEST
67 #include <_PDCLIB_test.h>
68
69 int main( void )
70 {
71     /* Testing covered by ftell.c */
72     return TEST_RESULTS;
73 }
74
75 #endif
76