1 /* Copyright (C) 2009 Eric Blake
2 * Permission to use, copy, modify, and distribute this software
3 * is freely granted, provided that this notice is preserved.
8 <<fpurge>>---discard pending file I/O
19 int fpurge(FILE *<[fp]>);
21 int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>);
24 #include <stdio_ext.h>
25 void __fpurge(FILE *<[fp]>);
29 Use <<fpurge>> to clear all buffers of the given stream. For output
30 streams, this discards data not yet written to disk. For input streams,
31 this discards any data from <<ungetc>> and any data retrieved from disk
32 but not yet read via <<getc>>. This is more severe than <<fflush>>,
33 and generally is only needed when manually altering the underlying file
34 descriptor of a stream.
36 <<__fpurge>> behaves exactly like <<fpurge>> but does not return a value.
38 The alternate function <<_fpurge_r>> is a reentrant version, where the
39 extra argument <[reent]> is a pointer to a reentrancy structure, and
40 <[fp]> must not be NULL.
43 <<fpurge>> returns <<0>> unless <[fp]> is not valid, in which case it
44 returns <<EOF>> and sets <<errno>>.
47 These functions are not portable to any standard.
49 No supporting OS subroutines are required.
55 #include <stdio_ext.h>
60 /* Discard I/O from a single file. */
63 _fpurge_r (struct _reent
*ptr
,
70 _newlib_flockfile_start (fp
);
75 _REENT_ERRNO(ptr
) = EBADF
;
76 _newlib_flockfile_exit (fp
);
79 fp
->_p
= fp
->_bf
._base
;
87 fp
->_w
= t
& (__SLBF
| __SNBF
) ? 0 : fp
->_bf
._size
;
88 _newlib_flockfile_end (fp
);
95 fpurge (register FILE * fp
)
97 return _fpurge_r (_REENT
, fp
);
103 __fpurge (register FILE * fp
)
105 _fpurge_r (_REENT
, fp
);
110 #endif /* _REENT_ONLY */