changeset 8693:245bb390f2ad

New module 'fpurge'.
author Bruno Haible <bruno@clisp.org>
date Sat, 14 Apr 2007 00:25:21 +0000
parents a07da695dec0
children b94f0a933a76
files ChangeLog lib/fpurge.c lib/fpurge.h m4/fpurge.m4 modules/fpurge
diffstat 5 files changed, 135 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-13  Bruno Haible  <bruno@clisp.org>
+
+	* modules/fpurge: New file.
+	* lib/fpurge.h: New file.
+	* lib/fpurge.c: New file.
+	* m4/fpurge.m4: New file.
+
 2007-04-13  Bruno Haible  <bruno@clisp.org>
 
 	* modules/fbufmode-tests: New file.
new file mode 100644
--- /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 <config.h>
+
+/* Specification.  */
+#include "fpurge.h"
+
+int
+fpurge (FILE *fp)
+{
+  /* Most systems provide FILE as a struct and the necessary bitmask in
+     <stdio.h>, 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
+}
new file mode 100644
--- /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 <stdio.h>
+
+/* 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 <stdio_ext.h>
+# define fpurge(stream) (__fpurge (stream), 0)
+
+#elif ! HAVE_DECL_FPURGE
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+extern int fpurge (FILE *stream);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
new file mode 100644
--- /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 <stdio.h>])
+  if test $ac_cv_func_fpurge = no && test $ac_cv_func___fpurge = no; then
+    AC_LIBOBJ([fpurge])
+    AC_CHECK_FUNCS([fpurge])
+  fi
+])
new file mode 100644
--- /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
+