diff options
author | Eric Blake <eblake@redhat.com> | 2009-07-03 11:58:04 +0000 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2009-07-03 11:58:04 +0000 |
commit | ce1eb6bba042d759a2fd8f57dfc01fcc8c478b57 (patch) | |
tree | 7d322aea0cc4b9ebe46f64da6e45a6d1aab190f4 /newlib/libc/stdio/fpurge.c | |
parent | a4175657bfb652ab816a54a219acf926a2f5762b (diff) | |
download | cygnal-ce1eb6bba042d759a2fd8f57dfc01fcc8c478b57.tar.gz cygnal-ce1eb6bba042d759a2fd8f57dfc01fcc8c478b57.tar.bz2 cygnal-ce1eb6bba042d759a2fd8f57dfc01fcc8c478b57.zip |
Add fpurge.
* libc/stdio/fpurge.c (fpurge, _fpurge_r): New file.
* libc/stdio/Makefile.am (ELIX_4_SOURCES, CHEWOUT_FILES, fpurge):
Build it.
* libc/stdio/Makefile.in: Regenerated.
* libc/include/stdio.h (fpurge, _fpurge_r): New declarations.
* libc/stdio/stdio.tex: Build documentation.
Diffstat (limited to 'newlib/libc/stdio/fpurge.c')
-rw-r--r-- | newlib/libc/stdio/fpurge.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/newlib/libc/stdio/fpurge.c b/newlib/libc/stdio/fpurge.c new file mode 100644 index 000000000..41228efd7 --- /dev/null +++ b/newlib/libc/stdio/fpurge.c @@ -0,0 +1,90 @@ +/* Copyright (C) 2009 Eric Blake + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +/* +FUNCTION +<<fpurge>>---discard pending file I/O + +INDEX + fpurge +INDEX + _fpurge_r + +ANSI_SYNOPSIS + #include <stdio.h> + int fpurge(FILE *<[fp]>); + + int _fpurge_r(struct _reent *<[reent]>, FILE *<[fp]>); + +DESCRIPTION +Use <<fpurge>> to clear all buffers of the given stream. For output +streams, this discards data not yet written to disk. For input streams, +this discards any data from <<ungetc>> and any data retrieved from disk +but not yet read via <<getc>>. This is more severe than <<fflush>>, +and generally is only needed when manually altering the underlying file +descriptor of a stream. + +The alternate function <<_fpurge_r>> is a reentrant version, where the +extra argument <[reent]> is a pointer to a reentrancy structure, and +<[fp]> must not be NULL. + +RETURNS +<<fpurge>> returns <<0>> unless <[fp]> is not valid, in which case it +returns <<EOF>> and sets <<errno>>. + +PORTABILITY +These functions are not portable to any standard. + +No supporting OS subroutines are required. +*/ + +#include <_ansi.h> +#include <stdio.h> +#include <errno.h> +#include "local.h" + +/* Discard I/O from a single file. */ + +int +_DEFUN(_fpurge_r, (ptr, fp), + struct _reent *ptr _AND + register FILE * fp) +{ + int t; + + CHECK_INIT (ptr, fp); + + _flockfile (fp); + + t = fp->_flags; + if (!t) + { + ptr->_errno = EBADF; + _funlockfile (fp); + return EOF; + } + fp->_p = fp->_bf._base; + if ((t & __SWR) == 0) + { + fp->_r = 0; + if (HASUB (fp)) + FREEUB (ptr, fp); + } + else + fp->_w = t & (__SLBF | __SNBF) ? 0 : fp->_bf._size; + _funlockfile (fp); + return 0; +} + +#ifndef _REENT_ONLY + +int +_DEFUN(fpurge, (fp), + register FILE * fp) +{ + return _fpurge_r (_REENT, fp); +} + +#endif /* _REENT_ONLY */ |