]> pd.if.org Git - pdclib/blob - functions/_PDCLIB/prepwrite.c
Comment cleanups.
[pdclib] / functions / _PDCLIB / prepwrite.c
1 /* _PDCLIB_prepwrite( 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 int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream )
10 {
11     if ( ( stream->bufidx < stream->bufend ) || ( stream->ungetidx > 0 ) ||
12          ( stream->status & ( _PDCLIB_FREAD | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) ||
13          ! ( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_FRW ) ) )
14     {
15         /* Function called on illegal (e.g. input) stream.
16            See the comments on implementation-defined errno values in
17            <_PDCLIB_config.h>.
18         */
19         _PDCLIB_errno = _PDCLIB_ERROR;
20         stream->status |= _PDCLIB_ERRORFLAG;
21         return EOF;
22     }
23     stream->status |= _PDCLIB_FWRITE | _PDCLIB_BYTESTREAM;
24     return 0;
25 }
26
27 #ifdef TEST
28 #include <_PDCLIB_test.h>
29
30 int main( void )
31 {
32     /* Testing covered by ftell.c */
33     return TEST_RESULTS;
34 }
35
36 #endif
37