From: Bruno Haible Date: Sat, 14 Apr 2007 00:25:21 +0000 (+0000) Subject: New module 'fpurge'. X-Git-Tag: cvs-readonly~525 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=92b81629ca04421e908119a7e93510dab499f3ae;p=gnulib.git New module 'fpurge'. --- diff --git a/ChangeLog b/ChangeLog index 9d4c73505..adec0a6b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2007-04-13 Bruno Haible + * modules/fpurge: New file. + * lib/fpurge.h: New file. + * lib/fpurge.c: New file. + * m4/fpurge.m4: New file. + +2007-04-13 Bruno Haible + * modules/fbufmode-tests: New file. * tests/test-fbufmode.c: New file. diff --git a/lib/fpurge.c b/lib/fpurge.c new file mode 100644 index 000000000..dc56c8f0c --- /dev/null +++ b/lib/fpurge.c @@ -0,0 +1,47 @@ +/* Flushing buffers of a FILE stream. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "fpurge.h" + +int +fpurge (FILE *fp) +{ + /* Most systems provide FILE as a struct and the necessary bitmask in + , because they need it for implementing getc() and putc() as + fast macros. */ +#if defined _IO_ferror_unlocked /* GNU libc, BeOS */ + fp->_IO_read_end = fp->_IO_read_ptr; + fp->_IO_write_ptr = fp->_IO_write_base; + return 0; +#elif defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */ + fp->_p = fp->_bf._base; + fp->_r = 0; + fp->_w = ((fp->_flags & (__SLBF | __SNBF) == 0) /* fully buffered? */ + ? fp->_bf._size + : 0); +#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, mingw */ + fp->_ptr = fp->_base; + if (fp->_ptr != NULL) + fp->_cnt = 0; + return 0; +#else + #error "Please port gnulib fpurge.c to your platform!" +#endif +} diff --git a/lib/fpurge.h b/lib/fpurge.h new file mode 100644 index 000000000..87600f876 --- /dev/null +++ b/lib/fpurge.h @@ -0,0 +1,41 @@ +/* Flushing buffers of a FILE stream. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Discard all pending buffered I/O on the stream STREAM. + STREAM must not be wide-character oriented. + Return 0 if successful. Upon error, return -1 and set errno. */ + +#if HAVE___FPURGE /* glibc >= 2.2, Solaris >= 7 */ + +# include +# define fpurge(stream) (__fpurge (stream), 0) + +#elif ! HAVE_DECL_FPURGE + +# ifdef __cplusplus +extern "C" { +# endif + +extern int fpurge (FILE *stream); + +# ifdef __cplusplus +} +# endif + +#endif diff --git a/m4/fpurge.m4 b/m4/fpurge.m4 new file mode 100644 index 000000000..2de217969 --- /dev/null +++ b/m4/fpurge.m4 @@ -0,0 +1,16 @@ +# fpurge.m4 serial 1 +dnl Copyright (C) 2007 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_FPURGE], +[ + AC_CHECK_FUNCS_ONCE([fpurge]) + AC_CHECK_FUNCS_ONCE([__fpurge]) + AC_CHECK_DECLS([fpurge], , , [#include ]) + if test $ac_cv_func_fpurge = no && test $ac_cv_func___fpurge = no; then + AC_LIBOBJ([fpurge]) + AC_CHECK_FUNCS([fpurge]) + fi +]) diff --git a/modules/fpurge b/modules/fpurge new file mode 100644 index 000000000..abec32f6c --- /dev/null +++ b/modules/fpurge @@ -0,0 +1,24 @@ +Description: +fpurge() function: Flush buffers. + +Files: +lib/fpurge.h +lib/fpurge.c +m4/fpurge.m4 + +Depends-on: + +configure.ac: +gl_FUNC_FPURGE + +Makefile.am: + +Include: +"fpurge.h" + +License: +LGPL + +Maintainer: +Bruno Haible, Eric Blake +