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