diff options
author | Bruno Haible <bruno@clisp.org> | 2010-12-22 19:25:34 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2010-12-22 19:25:34 +0100 |
commit | e53e23a012113952499a70115d2ca26b2a33e2bf (patch) | |
tree | c5bb164ee5ca5bfd8f95f3398aaf2a4c3f1a1406 /m4/getlogin_r.m4 | |
parent | f7fecbfc47c114a633f1fa754a0d9e1ad6cfc868 (diff) | |
download | gnulib-e53e23a012113952499a70115d2ca26b2a33e2bf.tar.gz |
getlogin_r: Work around portability problem on OSF/1.
* m4/getlogin_r.m4 (gl_FUNC_GETLOGIN_R): Detect the OSF/1 problem.
* lib/unistd.in.h (getlogin_r): Replace if REPLACE_GETLOGIN_R is set.
* lib/getlogin_r.c (getlogin_r): When getlogin_r exists, invoke it and
test for a truncated result.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize REPLACE_GETLOGIN_R.
* modules/unistd (Makefile.am): Substitute REPLACE_GETLOGIN_R.
* modules/getlogin_r (Depends-on): Add memchr.
* doc/posix-functions/getlogin_r.texi: Mention the OSF/1 problem.
Diffstat (limited to 'm4/getlogin_r.m4')
-rw-r--r-- | m4/getlogin_r.m4 | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/m4/getlogin_r.m4 b/m4/getlogin_r.m4 index 077ef8113e..9cda9a493e 100644 --- a/m4/getlogin_r.m4 +++ b/m4/getlogin_r.m4 @@ -1,4 +1,4 @@ -#serial 8 +#serial 9 # Copyright (C) 2005-2007, 2009-2010 Free Software Foundation, Inc. # @@ -27,6 +27,56 @@ AC_DEFUN([gl_FUNC_GETLOGIN_R], AC_CHECK_FUNCS_ONCE([getlogin_r]) if test $ac_cv_func_getlogin_r = no; then + HAVE_GETLOGIN_R=0 + else + HAVE_GETLOGIN_R=1 + dnl On OSF/1 5.1, getlogin_r returns a truncated result if the buffer is + dnl not large enough. + AC_REQUIRE([AC_CANONICAL_HOST]) + AC_CACHE_CHECK([whether getlogin_r works with small buffers], + [gl_cv_func_getlogin_r_works], + [ + dnl Initial guess, used when cross-compiling. +changequote(,)dnl + case "$host_os" in + # Guess no on OSF/1. + osf*) gl_cv_func_getlogin_r_works="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_getlogin_r_works="guessing yes" ;; + esac +changequote([,])dnl + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include <stddef.h> +#include <unistd.h> +#if !HAVE_DECL_GETLOGIN_R +extern int getlogin_r (char *, size_t); +#endif +int +main (void) +{ + int result = 0; + char buf[100]; + + if (getlogin_r (buf, 0) == 0) + result |= 16; + if (getlogin_r (buf, 1) == 0) + result |= 17; + return result; +}]])], + [gl_cv_func_getlogin_r_works=yes], + [case $? in + 16 | 17) gl_cv_func_getlogin_r_works=no ;; + esac + ], + [:]) + ]) + case "$gl_cv_func_getlogin_r_works" in + *yes) ;; + *) REPLACE_GETLOGIN_R=1 ;; + esac + fi + if test $HAVE_GETLOGIN_R = 0 || test $REPLACE_GETLOGIN_R = 1; then AC_LIBOBJ([getlogin_r]) gl_PREREQ_GETLOGIN_R fi |