changeset 13095:c47c56095752

fdopendir: work around FreeBSD bug Without a declaration, at least tar would core dump on 64-bit FreeBSD because gcc only used 32 bits of the resulting pointer. * m4/dirent_h.m4 (gl_DIRENT_H_DEFAULTS): New witness. * m4/fdopendir.m4 (gl_FUNC_FDOPENDIR): Set it. * modules/dirent (Makefile.am): Substitute it. * lib/dirent.in.h (fdopendir): Supply missing FreeBSD declaration. * doc/posix-functions/fdopendir.texi (fdopendir): Document the fix. Reported by Christian Weisgerber <naddy@mips.inka.de>. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Mon, 29 Mar 2010 15:08:59 -0600
parents 2ed0fc659db8
children 3e1ae5eb7f94
files ChangeLog doc/posix-functions/fdopendir.texi lib/dirent.in.h m4/dirent_h.m4 m4/fdopendir.m4 modules/dirent
diffstat 6 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-03-30  Eric Blake  <eblake@redhat.com>
+
+	fdopendir: work around FreeBSD bug
+	* m4/dirent_h.m4 (gl_DIRENT_H_DEFAULTS): New witness.
+	* m4/fdopendir.m4 (gl_FUNC_FDOPENDIR): Set it.
+	* modules/dirent (Makefile.am): Substitute it.
+	* lib/dirent.in.h (fdopendir): Supply missing FreeBSD
+	declaration.
+	* doc/posix-functions/fdopendir.texi (fdopendir): Document the
+	fix.
+	Reported by Christian Weisgerber <naddy@mips.inka.de>.
+
 2010-03-29  Bruno Haible  <bruno@clisp.org>
 
 	Emit #pragma system_header after the inclusion guard, not before.
--- a/doc/posix-functions/fdopendir.texi
+++ b/doc/posix-functions/fdopendir.texi
@@ -17,6 +17,9 @@
 that @samp{dirfd(fdopendir(n))==n} (dirfd might fail, or return a
 different file descriptor than n).
 @item
+This function exists but is not declared on some platforms:
+FreeBSD 7.3.
+@item
 This function does not reject non-directory file descriptors on some
 platforms:
 GNU/Hurd.
--- a/lib/dirent.in.h
+++ b/lib/dirent.in.h
@@ -77,7 +77,7 @@
 _GL_FUNCDECL_RPL (fdopendir, DIR *, (int fd));
 _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
 # else
-#  if !@HAVE_FDOPENDIR@
+#  if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@
 _GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd));
 #  endif
 _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
--- a/m4/dirent_h.m4
+++ b/m4/dirent_h.m4
@@ -1,4 +1,4 @@
-# dirent_h.m4 serial 11
+# dirent_h.m4 serial 12
 dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -46,6 +46,7 @@
   GNULIB_ALPHASORT=0;   AC_SUBST([GNULIB_ALPHASORT])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DECL_DIRFD=1;    AC_SUBST([HAVE_DECL_DIRFD])
+  HAVE_DECL_FDOPENDIR=1;AC_SUBST([HAVE_DECL_FDOPENDIR])
   HAVE_FDOPENDIR=1;     AC_SUBST([HAVE_FDOPENDIR])
   HAVE_SCANDIR=1;       AC_SUBST([HAVE_SCANDIR])
   HAVE_ALPHASORT=1;     AC_SUBST([HAVE_ALPHASORT])
--- a/m4/fdopendir.m4
+++ b/m4/fdopendir.m4
@@ -1,4 +1,4 @@
-# serial 3
+# serial 4
 # See if we need to provide fdopendir.
 
 dnl Copyright (C) 2009-2010 Free Software Foundation, Inc.
@@ -11,6 +11,10 @@
 AC_DEFUN([gl_FUNC_FDOPENDIR],
 [
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+  dnl FreeBSD 7.3 has the function, but failed to declare it.
+  AC_CHECK_DECLS([fdopendir], [], [HAVE_DECL_FDOPENDIR=0], [[
+#include <dirent.h>
+    ]])
   AC_CHECK_FUNCS_ONCE([fdopendir])
   if test $ac_cv_func_fdopendir = no; then
     AC_LIBOBJ([openat-proc])
@@ -23,6 +27,9 @@
       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
 #include <dirent.h>
 #include <fcntl.h>
+#if !HAVE_DECL_FDOPENDIR
+extern DIR *fdopendir (int);
+#endif
 ]], [int fd = open ("conftest.c", O_RDONLY);
      if (fd < 0) return 2;
      return !!fdopendir (fd);])],
--- a/modules/dirent
+++ b/modules/dirent
@@ -31,6 +31,7 @@
 	      -e 's|@''GNULIB_SCANDIR''@|$(GNULIB_SCANDIR)|g' \
 	      -e 's|@''GNULIB_ALPHASORT''@|$(GNULIB_ALPHASORT)|g' \
 	      -e 's|@''HAVE_DECL_DIRFD''@|$(HAVE_DECL_DIRFD)|g' \
+	      -e 's|@''HAVE_DECL_FDOPENDIR''@|$(HAVE_DECL_FDOPENDIR)|g' \
 	      -e 's|@''HAVE_FDOPENDIR''@|$(HAVE_FDOPENDIR)|g' \
 	      -e 's|@''HAVE_SCANDIR''@|$(HAVE_SCANDIR)|g' \
 	      -e 's|@''HAVE_ALPHASORT''@|$(HAVE_ALPHASORT)|g' \