]> pd.if.org Git - pdclib/blob - functions/_PDCLIB/prepwrite.c
c5a4c127543b40b14f016c60b3ac0fd04272538d
[pdclib] / functions / _PDCLIB / prepwrite.c
1 /* $Id$ */
2
3 /* _PDCLIB_prepwrite( 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 int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream )
12 {
13     if ( ( stream->bufidx < stream->bufend ) || ( stream->ungetidx > 0 ) ||
14          ( stream->status & ( _PDCLIB_FREAD | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) ||
15          ! ( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_FRW ) ) )
16     {
17         _PDCLIB_errno = _PDCLIB_EIO;
18         stream->status |= _PDCLIB_ERRORFLAG;
19         return EOF;
20     }
21     stream->status |= _PDCLIB_FWRITE | _PDCLIB_BYTESTREAM;
22     return 0;
23 }
24
25 #ifdef TEST
26 #include <_PDCLIB_test.h>
27
28 int main( void )
29 {
30     /* Testing covered by ftell.c */
31     return TEST_RESULTS;
32 }
33
34 #endif
35