bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'fdopen'


From: Bruno Haible
Subject: new module 'fdopen'
Date: Wed, 21 Sep 2011 21:20:30 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

One of the new EBADF tests fails on mingw:

test-fdopen.c:38: assertion failed
FAIL: test-fdopen.exe

The reason is already listed in doc/posix-functions/fdopen.texi. But I don't
want to have test failures accumulate. So here's a new workaround module
that fixes it.


2011-09-21  Bruno Haible  <address@hidden>

        New module 'fdopen'.
        * lib/stdio.in.h (fdopen): New declaration.
        * lib/fdopen.c: New file.
        * m4/fdopen.m4: New file.
        * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Initialize GNULIB_FDOPEN,
        REPLACE_FDOPEN.
        * modules/stdio (Makefile.am): Substitute GNULIB_FDOPEN,
        REPLACE_FDOPEN.
        * modules/fdopen: New file.
        * modules/stdio-tests (Depends-on): Remove fdopen-tests.
        * tests/test-stdio-c++.cc: Check signature of fdopen.
        * doc/posix-functions/fdopen.texi: Mention the new module.

================================ lib/fdopen.c ================================
/* Open a stream with a given file descriptor.
   Copyright (C) 2011 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */

#include <config.h>

/* Specification.  */
#include <stdio.h>

#include <errno.h>

#undef fdopen

FILE *
rpl_fdopen (int fd, const char *mode)
{
  int saved_errno = errno;
  FILE *fp;

  errno = 0;
  fp = fdopen (fd, mode);
  if (fp == NULL)
    {
      if (errno == 0)
        errno = EBADF;
    }
  else
    errno = saved_errno;

  return fp;
}
================================ m4/fdopen.m4 ================================
# fdopen.m4 serial 1
dnl Copyright (C) 2011 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_FDOPEN],
[
  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles

  dnl Test whether fdopen() sets errno when it fails due to a bad fd argument.
  AC_CACHE_CHECK([whether fdopen sets errno], [gl_cv_func_fdopen_works],
    [
      AC_RUN_IFELSE(
        [AC_LANG_SOURCE([[
#include <stdio.h>
#include <errno.h>
int
main (void)
{
  FILE *fp;
  errno = 0;
  fp = fdopen (-1, "r");
  if (fp != NULL)
    return 1;
  if (errno == 0)
    return 2;
  return 0;
}]])],
        [gl_cv_func_fdopen_works=yes],
        [gl_cv_func_fdopen_works=no],
        [case "$host_os" in
           mingw*) gl_cv_func_fdopen_works="guessing no" ;;
           *)      gl_cv_func_fdopen_works="guessing yes" ;;
         esac
        ])
    ])
  case "$gl_cv_func_fdopen_works" in
    *no) REPLACE_FDOPEN=1 ;;
  esac
])

dnl Prerequisites of lib/fdopen.c.
AC_DEFUN([gl_PREREQ_FDOPEN], [])
=============================== modules/fdopen ===============================
Description:
fdopen() function: open a stream with a given file descriptor.

Files:
lib/fdopen.c
m4/fdopen.m4

Depends-on:
stdio

configure.ac:
gl_FUNC_FDOPEN
if test $REPLACE_FDOPEN = 1; then
  AC_LIBOBJ([fdopen])
  gl_PREREQ_FDOPEN
fi
gl_STDIO_MODULE_INDICATOR([fdopen])

Makefile.am:

Include:
<stdio.h>

License:
LGPLv2+

Maintainer:
Bruno Haible
==============================================================================
--- doc/posix-functions/fdopen.texi.orig        Wed Sep 21 21:12:23 2011
+++ doc/posix-functions/fdopen.texi     Wed Sep 21 16:56:06 2011
@@ -4,15 +4,15 @@
 
 POSIX specification:@* 
@url{http://www.opengroup.org/onlinepubs/9699919799/functions/fdopen.html}
 
-Gnulib module: ---
+Gnulib module: fdopen
 
 Portability problems fixed by Gnulib:
 @itemize
address@hidden
+On Windows platforms (excluding Cygwin), this function does not set 
@code{errno}
+upon failure.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
address@hidden
-On Windows platforms (excluding Cygwin), this function does not set 
@code{errno}
-upon failure.
 @end itemize
--- lib/stdio.in.h.orig Wed Sep 21 21:12:23 2011
+++ lib/stdio.in.h      Wed Sep 21 17:21:47 2011
@@ -170,6 +170,26 @@
                  "use gnulib module fclose for portable POSIX compliance");
 #endif
 
+#if @GNULIB_FDOPEN@
+# if @REPLACE_FDOPEN@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fdopen
+#   define fdopen rpl_fdopen
+#  endif
+_GL_FUNCDECL_RPL (fdopen, FILE *, (int fd, const char *mode)
+                                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode));
+# else
+_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode));
+# endif
+_GL_CXXALIASWARN (fdopen);
+#elif defined GNULIB_POSIXCHECK
+# undef fdopen
+/* Assume fdopen is always declared.  */
+_GL_WARN_ON_USE (fdopen, "fdopen on Win32 platforms is not POSIX compatible - "
+                 "use gnulib module fdopen for portability");
+#endif
+
 #if @GNULIB_FFLUSH@
 /* Flush all pending data on STREAM according to POSIX rules.  Both
    output and seekable input streams are supported.
--- m4/stdio_h.m4.orig  Wed Sep 21 21:12:23 2011
+++ m4/stdio_h.m4       Wed Sep 21 17:17:35 2011
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 39
+# stdio_h.m4 serial 40
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -91,6 +91,7 @@
 [
   GNULIB_DPRINTF=0;              AC_SUBST([GNULIB_DPRINTF])
   GNULIB_FCLOSE=0;               AC_SUBST([GNULIB_FCLOSE])
+  GNULIB_FDOPEN=0;               AC_SUBST([GNULIB_FDOPEN])
   GNULIB_FFLUSH=0;               AC_SUBST([GNULIB_FFLUSH])
   GNULIB_FGETC=0;                AC_SUBST([GNULIB_FGETC])
   GNULIB_FGETS=0;                AC_SUBST([GNULIB_FGETS])
@@ -161,6 +162,7 @@
   HAVE_VDPRINTF=1;               AC_SUBST([HAVE_VDPRINTF])
   REPLACE_DPRINTF=0;             AC_SUBST([REPLACE_DPRINTF])
   REPLACE_FCLOSE=0;              AC_SUBST([REPLACE_FCLOSE])
+  REPLACE_FDOPEN=0;              AC_SUBST([REPLACE_FDOPEN])
   REPLACE_FFLUSH=0;              AC_SUBST([REPLACE_FFLUSH])
   REPLACE_FOPEN=0;               AC_SUBST([REPLACE_FOPEN])
   REPLACE_FPRINTF=0;             AC_SUBST([REPLACE_FPRINTF])
--- modules/stdio.orig  Wed Sep 21 21:12:23 2011
+++ modules/stdio       Wed Sep 21 17:18:44 2011
@@ -31,6 +31,7 @@
              -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
              -e 's/@''GNULIB_DPRINTF''@/$(GNULIB_DPRINTF)/g' \
              -e 's/@''GNULIB_FCLOSE''@/$(GNULIB_FCLOSE)/g' \
+             -e 's/@''GNULIB_FDOPEN''@/$(GNULIB_FDOPEN)/g' \
              -e 's/@''GNULIB_FFLUSH''@/$(GNULIB_FFLUSH)/g' \
              -e 's/@''GNULIB_FGETC''@/$(GNULIB_FGETC)/g' \
              -e 's/@''GNULIB_FGETS''@/$(GNULIB_FGETS)/g' \
@@ -101,6 +102,7 @@
              -e 's|@''HAVE_VDPRINTF''@|$(HAVE_VDPRINTF)|g' \
              -e 's|@''REPLACE_DPRINTF''@|$(REPLACE_DPRINTF)|g' \
              -e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \
+             -e 's|@''REPLACE_FDOPEN''@|$(REPLACE_FDOPEN)|g' \
              -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
              -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \
              -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
--- modules/stdio-tests.orig    Wed Sep 21 21:12:23 2011
+++ modules/stdio-tests Wed Sep 21 17:19:09 2011
@@ -4,7 +4,6 @@
 Depends-on:
 verify
 stdio-c++-tests
-fdopen-tests
 fgetc-tests
 
 configure.ac:
--- tests/test-stdio-c++.cc.orig        Wed Sep 21 21:12:23 2011
+++ tests/test-stdio-c++.cc     Wed Sep 21 21:12:04 2011
@@ -32,6 +32,10 @@
 SIGNATURE_CHECK (GNULIB_NAMESPACE::fclose, int, (FILE *));
 #endif
 
+#if GNULIB_TEST_FDOPEN
+SIGNATURE_CHECK (GNULIB_NAMESPACE::fdopen, FILE *, (int, const char *));
+#endif
+
 #if GNULIB_TEST_FFLUSH
 SIGNATURE_CHECK (GNULIB_NAMESPACE::fflush, int, (FILE *));
 #endif

-- 
In memoriam Orlando Letelier <http://en.wikipedia.org/wiki/Orlando_Letelier>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]