diff options
author | Bruno Haible <bruno@clisp.org> | 2007-10-07 04:46:57 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2007-10-07 04:46:57 +0200 |
commit | 86f87b4967587bcac4fae90ee86c6fce24e3a4f3 (patch) | |
tree | 8f5b7b203e64b52cf531e5b7bf08ddbf1ae19ce3 | |
parent | 77676a2d625501ec06a3c1dfb6f6db0c858b8b8c (diff) | |
download | gnulib-86f87b4967587bcac4fae90ee86c6fce24e3a4f3.tar.gz |
New modules 'fopen' and 'freopen'.
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | doc/functions/fopen.texi | 5 | ||||
-rw-r--r-- | doc/functions/freopen.texi | 5 | ||||
-rw-r--r-- | lib/fopen.c | 37 | ||||
-rw-r--r-- | lib/freopen.c | 37 | ||||
-rw-r--r-- | lib/stdio.in.h | 26 | ||||
-rw-r--r-- | m4/fopen.m4 | 17 | ||||
-rw-r--r-- | m4/freopen.m4 | 17 | ||||
-rw-r--r-- | m4/stdio_h.m4 | 6 | ||||
-rw-r--r-- | modules/fopen | 25 | ||||
-rw-r--r-- | modules/freopen | 25 | ||||
-rw-r--r-- | modules/stdio | 4 |
12 files changed, 217 insertions, 3 deletions
@@ -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. diff --git a/doc/functions/fopen.texi b/doc/functions/fopen.texi index 272638e7db..37edf9ce5f 100644 --- 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: diff --git a/doc/functions/freopen.texi b/doc/functions/freopen.texi index b126f70057..ccb25eace0 100644 --- 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: diff --git a/lib/fopen.c b/lib/fopen.c new file mode 100644 index 0000000000..2faad59027 --- /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); +} diff --git a/lib/freopen.c b/lib/freopen.c new file mode 100644 index 0000000000..4ae24096ec --- /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); +} diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 5264194bdf..772709cbd3 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -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 index 0000000000..1ec011bff9 --- /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 +]) diff --git a/m4/freopen.m4 b/m4/freopen.m4 new file mode 100644 index 0000000000..0149ebd65e --- /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 +]) diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 index b9a69984f6..45e54e2a62 100644 --- 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 @@ 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 index 0000000000..434cf17861 --- /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 + diff --git a/modules/freopen b/modules/freopen new file mode 100644 index 0000000000..5c556e4e05 --- /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 + diff --git a/modules/stdio b/modules/stdio index 5aaf973edd..d6a154943e 100644 --- a/modules/stdio +++ b/modules/stdio @@ -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' \ |