New module 'fpurge'.
authorBruno Haible <bruno@clisp.org>
Sat, 14 Apr 2007 00:25:21 +0000 (00:25 +0000)
committerBruno Haible <bruno@clisp.org>
Sat, 14 Apr 2007 00:25:21 +0000 (00:25 +0000)
ChangeLog
lib/fpurge.c [new file with mode: 0644]
lib/fpurge.h [new file with mode: 0644]
m4/fpurge.m4 [new file with mode: 0644]
modules/fpurge [new file with mode: 0644]

index 9d4c735..adec0a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 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.
        * tests/test-fbufmode.c: New file.
 
diff --git a/lib/fpurge.c b/lib/fpurge.c
new file mode 100644 (file)
index 0000000..dc56c8f
--- /dev/null
@@ -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
+}
diff --git a/lib/fpurge.h b/lib/fpurge.h
new file mode 100644 (file)
index 0000000..87600f8
--- /dev/null
@@ -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
diff --git a/m4/fpurge.m4 b/m4/fpurge.m4
new file mode 100644 (file)
index 0000000..2de2179
--- /dev/null
@@ -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
+])
diff --git a/modules/fpurge b/modules/fpurge
new file mode 100644 (file)
index 0000000..abec32f
--- /dev/null
@@ -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
+