New modules 'fopen' and 'freopen'.
authorBruno Haible <bruno@clisp.org>
Sun, 7 Oct 2007 02:46:57 +0000 (04:46 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 7 Oct 2007 02:46:57 +0000 (04:46 +0200)
12 files changed:
ChangeLog
doc/functions/fopen.texi
doc/functions/freopen.texi
lib/fopen.c [new file with mode: 0644]
lib/freopen.c [new file with mode: 0644]
lib/stdio.in.h
m4/fopen.m4 [new file with mode: 0644]
m4/freopen.m4 [new file with mode: 0644]
m4/stdio_h.m4
modules/fopen [new file with mode: 0644]
modules/freopen [new file with mode: 0644]
modules/stdio

index 43291d4..ae51c73 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 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.
        * tests/test-open.c: New file.
 
index 272638e..37edf9c 100644 (file)
@@ -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:
index b126f70..ccb25ea 100644 (file)
@@ -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:
diff --git a/lib/fopen.c b/lib/fopen.c
new file mode 100644 (file)
index 0000000..2faad59
--- /dev/null
@@ -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);
+}
diff --git a/lib/freopen.c b/lib/freopen.c
new file mode 100644 (file)
index 0000000..4ae2409
--- /dev/null
@@ -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);
+}
index 5264194..772709c 100644 (file)
@@ -212,6 +212,32 @@ extern int vsprintf (char *str, const char *format, va_list args)
 # 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
diff --git a/m4/fopen.m4 b/m4/fopen.m4
new file mode 100644 (file)
index 0000000..1ec011b
--- /dev/null
@@ -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
+])
diff --git a/m4/freopen.m4 b/m4/freopen.m4
new file mode 100644 (file)
index 0000000..0149ebd
--- /dev/null
@@ -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
+])
index b9a6998..45e54e2 100644 (file)
@@ -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 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   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 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   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])
diff --git a/modules/fopen b/modules/fopen
new file mode 100644 (file)
index 0000000..434cf17
--- /dev/null
@@ -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
+
diff --git a/modules/freopen b/modules/freopen
new file mode 100644 (file)
index 0000000..5c556e4
--- /dev/null
@@ -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
+
index 5aaf973..d6a1549 100644 (file)
@@ -31,6 +31,8 @@ stdio.h: stdio.in.h
              -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 @@ stdio.h: stdio.in.h
              -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' \