changeset 9301:98e1721b4e40

New modules 'fopen' and 'freopen'.
author Bruno Haible <bruno@clisp.org>
date Sun, 07 Oct 2007 04:46:57 +0200
parents da8b529f93ee
children e0a1dcc13fb9
files ChangeLog doc/functions/fopen.texi doc/functions/freopen.texi lib/fopen.c lib/freopen.c lib/stdio.in.h m4/fopen.m4 m4/freopen.m4 m4/stdio_h.m4 modules/fopen modules/freopen modules/stdio
diffstat 12 files changed, 217 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2007-10-06  Bruno Haible  <bruno@clisp.org>
+
+	* modules/fopen: New file.
+	* lib/fopen.c: New file.
+	* m4/fopen.m4: New file.
+	* modules/freopen: New file.
+	* lib/freopen.c: New file.
+	* m4/freopen.m4: New file.
+	* lib/stdio.in.h (fopen, freopen): New declarations.
+	* m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Initialize also GNULIB_FOPEN,
+	GNULIB_FREOPEN, REPLACE_FOPEN, REPLACE_FREOPEN.
+	* modules/stdio (Makefile.am): Substitute also GNULIB_FOPEN,
+	GNULIB_FREOPEN, REPLACE_FOPEN, REPLACE_FREOPEN.
+	* doc/functions/fopen.texi: Mention the 'fopen' module.
+	* doc/functions/freopen.texi: Mention the 'freopen' module.
+
 2007-10-06  Bruno Haible  <bruno@clisp.org>
 
 	* modules/open-tests: New file.
--- a/doc/functions/fopen.texi
+++ b/doc/functions/fopen.texi
@@ -4,10 +4,13 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/fopen.html}
 
-Gnulib module: ---
+Gnulib module: fopen
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+On Windows platforms (excluding Cygwin), this function does usually not
+recognize the @file{/dev/null} filename.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/doc/functions/freopen.texi
+++ b/doc/functions/freopen.texi
@@ -4,10 +4,13 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/freopen.html}
 
-Gnulib module: ---
+Gnulib module: freopen
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+On Windows platforms (excluding Cygwin), this function does usually not
+recognize the @file{/dev/null} filename.
 @end itemize
 
 Portability problems not fixed by Gnulib:
new file mode 100644
--- /dev/null
+++ b/lib/fopen.c
@@ -0,0 +1,37 @@
+/* Open a stream to a file.
+   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.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+#include <string.h>
+
+FILE *
+fopen (const char *filename, const char *mode)
+#undef fopen
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  if (strcmp (filename, "/dev/null") == 0)
+    filename = "NUL";
+#endif
+
+  return fopen (filename, mode);
+}
new file mode 100644
--- /dev/null
+++ b/lib/freopen.c
@@ -0,0 +1,37 @@
+/* Open a stream to a file.
+   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.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+#include <string.h>
+
+FILE *
+freopen (const char *filename, const char *mode, FILE *stream)
+#undef freopen
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  if (strcmp (filename, "/dev/null") == 0)
+    filename = "NUL";
+#endif
+
+  return freopen (filename, mode, stream);
+}
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -212,6 +212,32 @@
 # endif
 #endif
 
+#if @GNULIB_FOPEN@
+# if @REPLACE_FOPEN@
+#  define fopen rpl_fopen
+extern FILE * fopen (const char *filename, const char *mode);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef fopen
+# define fopen(f,m) \
+   (GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
+                     "use gnulib module fopen for portability"), \
+    fopen (f, m))
+#endif
+
+#if @GNULIB_FREOPEN@
+# if @REPLACE_FREOPEN@
+#  define freopen rpl_freopen
+extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef freopen
+# define freopen(f,m,s) \
+   (GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
+                     "use gnulib module freopen for portability"), \
+    freopen (f, m, s))
+#endif
+
 #if @GNULIB_FSEEKO@
 # if @REPLACE_FSEEKO@
 /* Provide fseek, fseeko functions that are aware of a preceding
new file mode 100644
--- /dev/null
+++ b/m4/fopen.m4
@@ -0,0 +1,17 @@
+# fopen.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_FOPEN],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  case "$host_os" in
+    mingw* | pw*)
+      REPLACE_FOPEN=1
+      AC_LIBOBJ([fopen])
+      ;;
+  esac
+])
new file mode 100644
--- /dev/null
+++ b/m4/freopen.m4
@@ -0,0 +1,17 @@
+# freopen.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_FREOPEN],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  case "$host_os" in
+    mingw* | pw*)
+      REPLACE_FREOPEN=1
+      AC_LIBOBJ([freopen])
+      ;;
+  esac
+])
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 7
+# stdio_h.m4 serial 8
 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,
@@ -28,6 +28,8 @@
   GNULIB_VSNPRINTF=0;      AC_SUBST([GNULIB_VSNPRINTF])
   GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX])
   GNULIB_VASPRINTF=0;      AC_SUBST([GNULIB_VASPRINTF])
+  GNULIB_FOPEN=0;          AC_SUBST([GNULIB_FOPEN])
+  GNULIB_FREOPEN=0;        AC_SUBST([GNULIB_FREOPEN])
   GNULIB_FSEEK=0;          AC_SUBST([GNULIB_FSEEK])
   GNULIB_FSEEKO=0;         AC_SUBST([GNULIB_FSEEKO])
   GNULIB_FTELL=0;          AC_SUBST([GNULIB_FTELL])
@@ -48,6 +50,8 @@
   REPLACE_VSPRINTF=0;      AC_SUBST([REPLACE_VSPRINTF])
   HAVE_VASPRINTF=1;        AC_SUBST([HAVE_VASPRINTF])
   REPLACE_VASPRINTF=0;     AC_SUBST([REPLACE_VASPRINTF])
+  REPLACE_FOPEN=0;         AC_SUBST([REPLACE_FOPEN])
+  REPLACE_FREOPEN=0;       AC_SUBST([REPLACE_FREOPEN])
   HAVE_FSEEKO=1;           AC_SUBST([HAVE_FSEEKO])
   REPLACE_FSEEKO=0;        AC_SUBST([REPLACE_FSEEKO])
   REPLACE_FSEEK=0;         AC_SUBST([REPLACE_FSEEK])
new file mode 100644
--- /dev/null
+++ b/modules/fopen
@@ -0,0 +1,25 @@
+Description:
+fopen() function: open a stream to a file.
+
+Files:
+lib/fopen.c
+m4/fopen.m4
+
+Depends-on:
+stdio
+
+configure.ac:
+gl_FUNC_FOPEN
+gl_STDIO_MODULE_INDICATOR([fopen])
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
new file mode 100644
--- /dev/null
+++ b/modules/freopen
@@ -0,0 +1,25 @@
+Description:
+freopen() function: open a stream to a file.
+
+Files:
+lib/freopen.c
+m4/freopen.m4
+
+Depends-on:
+stdio
+
+configure.ac:
+gl_FUNC_FREOPEN
+gl_STDIO_MODULE_INDICATOR([freopen])
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
--- a/modules/stdio
+++ b/modules/stdio
@@ -31,6 +31,8 @@
 	      -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
 	      -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
 	      -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \
+	      -e 's|@''GNULIB_FOPEN''@|$(GNULIB_FOPEN)|g' \
+	      -e 's|@''GNULIB_FREOPEN''@|$(GNULIB_FREOPEN)|g' \
 	      -e 's|@''GNULIB_FSEEK''@|$(GNULIB_FSEEK)|g' \
 	      -e 's|@''GNULIB_FSEEKO''@|$(GNULIB_FSEEKO)|g' \
 	      -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
@@ -50,6 +52,8 @@
 	      -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \
 	      -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
 	      -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \
+	      -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \
+	      -e 's|@''REPLACE_FREOPEN''@|$(REPLACE_FREOPEN)|g' \
 	      -e 's|@''REPLACE_FSEEKO''@|$(REPLACE_FSEEKO)|g' \
 	      -e 's|@''REPLACE_FSEEK''@|$(REPLACE_FSEEK)|g' \
 	      -e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \