]> pd.if.org Git - pdclib/blob - functions/_PDCLIB/prepread.c
Comment cleanups.
[pdclib] / functions / _PDCLIB / prepread.c
1 /* _PDCLIB_prepread( 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 #include <stdio.h>
8
9 #include <_PDCLIB_glue.h>
10
11 int _PDCLIB_prepread( struct _PDCLIB_file_t * stream )
12 {
13     if ( ( stream->bufidx > stream->bufend ) ||
14          ( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) ||
15          ! ( stream->status & ( _PDCLIB_FREAD | _PDCLIB_FRW ) ) )
16     {
17         /* Function called on illegal (e.g. output) stream.
18            See comments on implementation-defined errno values in
19            <_PDCLIB_config.h>.
20         */
21         _PDCLIB_errno = _PDCLIB_ERROR;
22         stream->status |= _PDCLIB_ERRORFLAG;
23         return EOF;
24     }
25     stream->status |= _PDCLIB_FREAD | _PDCLIB_BYTESTREAM;
26     if ( ( stream->bufidx == stream->bufend ) && ( stream->ungetidx == 0 ) )
27     {
28         return _PDCLIB_fillbuffer( stream );
29     }
30     else
31     {
32         return 0;
33     }
34 }
35
36 #ifdef TEST
37 #include <_PDCLIB_test.h>
38
39 int main( void )
40 {
41     /* Testing covered by ftell.c */
42     return TEST_RESULTS;
43 }
44
45 #endif
46