* 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. --- ChangeLog | 15 +++++++++++++++ doc/posix-functions/readlink.texi | 2 +- doc/posix-functions/readlinkat.texi | 5 +++++ lib/readlinkat.c | 36 +++++++++++++++++++++++++----------- lib/unistd.in.h | 15 +++++++++++++-- m4/readlinkat.m4 | 15 ++++++++++++++- m4/unistd_h.m4 | 3 ++- modules/readlinkat | 2 +- modules/unistd | 1 + 9 files changed, 77 insertions(+), 17 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 0fbd2e7..e012f3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2014-10-18 Paul Eggert <egg...@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 <k...@gnu.org> * doc/posix-functions/dirname.texi: remove spurious {. diff --git a/doc/posix-functions/readlink.texi b/doc/posix-functions/readlink.texi index 2348a84..60654b1 100644 --- a/doc/posix-functions/readlink.texi +++ b/doc/posix-functions/readlink.texi @@ -14,7 +14,7 @@ FreeBSD 7.2, Solaris 9. @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. diff --git a/doc/posix-functions/readlinkat.texi b/doc/posix-functions/readlinkat.texi index a2988f2..51fbeba 100644 --- a/doc/posix-functions/readlinkat.texi +++ b/doc/posix-functions/readlinkat.texi @@ -13,6 +13,11 @@ This function is missing on some platforms: 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: diff --git a/lib/readlinkat.c b/lib/readlinkat.c index c8a6050..83ea0af 100644 --- a/lib/readlinkat.c +++ b/lib/readlinkat.c @@ -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 diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 58ca184..cae779d 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -1287,13 +1287,24 @@ _GL_WARN_ON_USE (readlink, "readlink is unportable - " #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 diff --git a/m4/readlinkat.m4 b/m4/readlinkat.m4 index 65c0689..f9ed943 100644 --- a/m4/readlinkat.m4 +++ b/m4/readlinkat.m4 @@ -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_DEFUN([gl_FUNC_READLINKAT], 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 ]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index 1fa197e..6d217d6 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -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 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], 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]) diff --git a/modules/readlinkat b/modules/readlinkat index f31d3fe..a89c53f 100644 --- a/modules/readlinkat +++ b/modules/readlinkat @@ -21,7 +21,7 @@ readlink [test $HAVE_READLINKAT = 0] 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]) diff --git a/modules/unistd b/modules/unistd index c470ba6..0bbeb84 100644 --- a/modules/unistd +++ b/modules/unistd @@ -150,6 +150,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -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' \ -- 1.9.3