]> pd.if.org Git - pdclib/blob - functions/stdio/_PDCLIB_prepwrite.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / stdio / _PDCLIB_prepwrite.c
1 /* _PDCLIB_prepwrite( 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_io.h"
12    
13 int _PDCLIB_prepwrite( FILE * stream )
14 {
15     if ( ( stream->bufidx < stream->bufend ) || ( stream->ungetidx > 0 ) ||
16          ( stream->status & ( _PDCLIB_FREAD | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) ||
17          ! ( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_FRW ) ) )
18     {
19         /* Function called on illegal (e.g. input) stream.
20            See the 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_FWRITE | _PDCLIB_BYTESTREAM;
28     return 0;
29 }
30 #endif
31
32 #ifdef TEST
33 #include "_PDCLIB_test.h"
34
35 int main( void )
36 {
37     /* Testing covered by ftell.c */
38     return TEST_RESULTS;
39 }
40
41 #endif
42