Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/stdio/_PDCLIB_prepread.c
2 views
1
/* _PDCLIB_prepread( FILE * )
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
#include <errno.h>
9
10
#ifndef REGTEST
11
#include "_PDCLIB_glue.h"
12
13
int _PDCLIB_prepread( FILE * 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
errno = EINVAL;
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
#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
50
51