changeset 37449:3662455de1d7

readlinkat: port to AIX 7.1 * doc/posix-functions/readlink.texi (readlink): * doc/posix-functions/readlinkat.texi (readlinkat): Mention AIX porting problem. * lib/readlinkat.c (rpl_readlinkat) [HAVE_READLINKAT]: New function. * lib/unistd.in.h (readlinkat): Add replacement machinery. * m4/readlinkat.m4 (gl_FUNC_READLINKAT): Check readlinkat signature. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add REPLACE_READLINKAT. * modules/readlinkat (configure.ac): Also compile replacement if REPLACE_READLINKAT. * modules/unistd (unistd.h): Substitute REPLACE_READLINKAT.
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 18 Oct 2014 22:35:28 -0700
parents 503d9d833a18
children f7590a059d02
files ChangeLog doc/posix-functions/readlink.texi doc/posix-functions/readlinkat.texi lib/readlinkat.c lib/unistd.in.h m4/readlinkat.m4 m4/unistd_h.m4 modules/readlinkat modules/unistd
diffstat 9 files changed, 77 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Oct 12 09:03:23 2014 -0700
+++ b/ChangeLog	Sat Oct 18 22:35:28 2014 -0700
@@ -1,3 +1,18 @@
+2014-10-18  Paul Eggert  <eggert@cs.ucla.edu>
+
+	readlinkat: port to AIX 7.1
+	* doc/posix-functions/readlink.texi (readlink):
+	* doc/posix-functions/readlinkat.texi (readlinkat):
+	Mention AIX porting problem.
+	* lib/readlinkat.c (rpl_readlinkat) [HAVE_READLINKAT]:
+	New function.
+	* lib/unistd.in.h (readlinkat): Add replacement machinery.
+	* m4/readlinkat.m4 (gl_FUNC_READLINKAT): Check readlinkat signature.
+	* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add REPLACE_READLINKAT.
+	* modules/readlinkat (configure.ac): Also compile replacement
+	if REPLACE_READLINKAT.
+	* modules/unistd (unistd.h): Substitute REPLACE_READLINKAT.
+
 2014-10-12  Karl Berry  <karl@gnu.org>
 
 	* doc/posix-functions/dirname.texi: remove spurious {.
--- a/doc/posix-functions/readlink.texi	Sun Oct 12 09:03:23 2014 -0700
+++ b/doc/posix-functions/readlink.texi	Sat Oct 18 22:35:28 2014 -0700
@@ -14,7 +14,7 @@
 @item
 On some platforms, @code{readlink} returns @code{int} instead of
 @code{ssize_t}:
-glibc 2.4, FreeBSD 6.0, OpenBSD 3.8, Cygwin 1.5.x.
+glibc 2.4, FreeBSD 6.0, OpenBSD 3.8, Cygwin 1.5.x, AIX 7.1.
 @item
 This function is missing on some platforms:
 mingw, MSVC 9.
--- a/doc/posix-functions/readlinkat.texi	Sun Oct 12 09:03:23 2014 -0700
+++ b/doc/posix-functions/readlinkat.texi	Sat Oct 18 22:35:28 2014 -0700
@@ -13,6 +13,11 @@
 glibc 2.3.6, Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8,
 AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, mingw, MSVC 9, Interix 3.5, BeOS.
 But the replacement function is not safe to be used in libraries and is not multithread-safe.
+@item
+On some platforms, @code{readlinkat} returns @code{int} instead of
+@code{ssize_t}:
+AIX 7.1.
+@item
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/lib/readlinkat.c	Sun Oct 12 09:03:23 2014 -0700
+++ b/lib/readlinkat.c	Sat Oct 18 22:35:28 2014 -0700
@@ -20,6 +20,18 @@
 
 #include <unistd.h>
 
+#if HAVE_READLINKAT
+
+# undef readlinkat
+
+ssize_t
+rpl_readlinkat (int fd, char const *file, char *buf, size_t len)
+{
+  return readlinkat (fd, file, buf, len);
+}
+
+#else
+
 /* Gnulib provides a readlink stub for mingw; use it for distinction
    between EINVAL and ENOENT, rather than always failing with ENOSYS.  */
 
@@ -34,14 +46,16 @@
    then readlink/restore_cwd.  If either the save_cwd or the restore_cwd
    fails, then give a diagnostic and exit nonzero.  */
 
-#define AT_FUNC_NAME readlinkat
-#define AT_FUNC_F1 readlink
-#define AT_FUNC_POST_FILE_PARAM_DECLS , char *buf, size_t len
-#define AT_FUNC_POST_FILE_ARGS        , buf, len
-#define AT_FUNC_RESULT ssize_t
-#include "at-func.c"
-#undef AT_FUNC_NAME
-#undef AT_FUNC_F1
-#undef AT_FUNC_POST_FILE_PARAM_DECLS
-#undef AT_FUNC_POST_FILE_ARGS
-#undef AT_FUNC_RESULT
+# define AT_FUNC_NAME readlinkat
+# define AT_FUNC_F1 readlink
+# define AT_FUNC_POST_FILE_PARAM_DECLS , char *buf, size_t len
+# define AT_FUNC_POST_FILE_ARGS        , buf, len
+# define AT_FUNC_RESULT ssize_t
+# include "at-func.c"
+# undef AT_FUNC_NAME
+# undef AT_FUNC_F1
+# undef AT_FUNC_POST_FILE_PARAM_DECLS
+# undef AT_FUNC_POST_FILE_ARGS
+# undef AT_FUNC_RESULT
+
+#endif
--- a/lib/unistd.in.h	Sun Oct 12 09:03:23 2014 -0700
+++ b/lib/unistd.in.h	Sat Oct 18 22:35:28 2014 -0700
@@ -1287,13 +1287,24 @@
 
 
 #if @GNULIB_READLINKAT@
-# if !@HAVE_READLINKAT@
+# if @REPLACE_READLINKAT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define readlinkat rpl_readlinkat
+#  endif
+_GL_FUNCDECL_RPL (readlinkat, ssize_t,
+                  (int fd, char const *file, char *buf, size_t len)
+                  _GL_ARG_NONNULL ((2, 3)));
+_GL_CXXALIAS_RPL (readlinkat, ssize_t,
+                  (int fd, char const *file, char *buf, size_t len));
+# else
+#  if !@HAVE_READLINKAT@
 _GL_FUNCDECL_SYS (readlinkat, ssize_t,
                   (int fd, char const *file, char *buf, size_t len)
                   _GL_ARG_NONNULL ((2, 3)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (readlinkat, ssize_t,
                   (int fd, char const *file, char *buf, size_t len));
+# endif
 _GL_CXXALIASWARN (readlinkat);
 #elif defined GNULIB_POSIXCHECK
 # undef readlinkat
--- a/m4/readlinkat.m4	Sun Oct 12 09:03:23 2014 -0700
+++ b/m4/readlinkat.m4	Sat Oct 18 22:35:28 2014 -0700
@@ -1,4 +1,4 @@
-# serial 3
+# serial 4
 # See if we need to provide readlinkat replacement.
 
 dnl Copyright (C) 2009-2014 Free Software Foundation, Inc.
@@ -15,5 +15,18 @@
   AC_CHECK_FUNCS_ONCE([readlinkat])
   if test $ac_cv_func_readlinkat = no; then
     HAVE_READLINKAT=0
+  else
+    AC_CACHE_CHECK([whether readlinkat signature is correct],
+      [gl_cv_decl_readlinkat_works],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+           [[#include <unistd.h>
+             /* Check whether original declaration has correct type.  */
+             ssize_t readlinkat (int, char const *, char *, size_t);]])],
+         [gl_cv_decl_readlinkat_works=yes],
+         [gl_cv_decl_readlinkat_works=no])])
+    if test "$gl_cv_decl_readlink_works" != yes; then
+      REPLACE_READLINKAT=1
+    fi
   fi
 ])
--- a/m4/unistd_h.m4	Sun Oct 12 09:03:23 2014 -0700
+++ b/m4/unistd_h.m4	Sat Oct 18 22:35:28 2014 -0700
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 67
+# unistd_h.m4 serial 68
 dnl Copyright (C) 2006-2014 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -173,6 +173,7 @@
   REPLACE_PWRITE=0;       AC_SUBST([REPLACE_PWRITE])
   REPLACE_READ=0;         AC_SUBST([REPLACE_READ])
   REPLACE_READLINK=0;     AC_SUBST([REPLACE_READLINK])
+  REPLACE_READLINKAT=0;   AC_SUBST([REPLACE_READLINKAT])
   REPLACE_RMDIR=0;        AC_SUBST([REPLACE_RMDIR])
   REPLACE_SLEEP=0;        AC_SUBST([REPLACE_SLEEP])
   REPLACE_SYMLINK=0;      AC_SUBST([REPLACE_SYMLINK])
--- a/modules/readlinkat	Sun Oct 12 09:03:23 2014 -0700
+++ b/modules/readlinkat	Sat Oct 18 22:35:28 2014 -0700
@@ -21,7 +21,7 @@
 
 configure.ac:
 gl_FUNC_READLINKAT
-if test $HAVE_READLINKAT = 0; then
+if test $HAVE_READLINKAT = 0 || test $REPLACE_READLINKAT = 1; then
   AC_LIBOBJ([readlinkat])
 fi
 gl_UNISTD_MODULE_INDICATOR([readlinkat])
--- a/modules/unistd	Sun Oct 12 09:03:23 2014 -0700
+++ b/modules/unistd	Sat Oct 18 22:35:28 2014 -0700
@@ -150,6 +150,7 @@
 	      -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \
 	      -e 's|@''REPLACE_READ''@|$(REPLACE_READ)|g' \
 	      -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \
+	      -e 's|@''REPLACE_READLINKAT''@|$(REPLACE_READLINKAT)|g' \
 	      -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \
 	      -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \
 	      -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \