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