]> pd.if.org Git - pdclib/blob - functions/_PDCLIB/prepread.c
Removed the header include guard 'optimization'.
[pdclib] / functions / _PDCLIB / prepread.c
1 /* $Id$ */
2
3 /* _PDCLIB_prepread( struct _PDCLIB_file_t * )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdio.h>
10
11 #include <_PDCLIB_glue.h>
12
13 int _PDCLIB_prepread( struct _PDCLIB_file_t * stream )
14 {
15     if ( ( stream->bufidx > stream->bufend ) ||
16          ( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) ||
17          ! ( stream->status & ( _PDCLIB_FREAD | _PDCLIB_FRW ) ) )
18     {
19         /* Function called on illegal (e.g. output) stream.
20            See comments on implementation-defined errno values in
21            <_PDCLIB_config.h>.
22         */
23         _PDCLIB_errno = _PDCLIB_ERROR;
24         stream->status |= _PDCLIB_ERRORFLAG;
25         return EOF;
26     }
27     stream->status |= _PDCLIB_FREAD | _PDCLIB_BYTESTREAM;
28     if ( ( stream->bufidx == stream->bufend ) && ( stream->ungetidx == 0 ) )
29     {
30         return _PDCLIB_fillbuffer( stream );
31     }
32     else
33     {
34         return 0;
35     }
36 }
37
38 #ifdef TEST
39 #include <_PDCLIB_test.h>
40
41 int main( void )
42 {
43     /* Testing covered by ftell.c */
44     return TEST_RESULTS;
45 }
46
47 #endif
48