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