This fixes a small bug in the m4/getlogin_r.m4 macros: The presence of a getlogin_r() declaration in <unistd.h> depends on whether AC_USE_SYSTEM_EXTENSIONS was already executed. And a tiny optimization in lib/getlogin_r.c.
2010-01-09 Bruno Haible <br...@clisp.org> getlogin_r: Small fixes. * lib/getlogin_r.c (getlogin_r): Don't set errno if the function succeeds. * m4/getlogin_r.m4 (gl_GETLOGIN_R): Require gl_USE_SYSTEM_EXTENSIONS before testing whether getlogin_r is declared. No need to set HAVE_DECL_GETLOGIN_R to 1. (gl_PREREQ_GETLOGIN_R): Don't check for the getlogin_r declaration. --- lib/getlogin_r.c.orig Sat Jan 9 15:08:13 2010 +++ lib/getlogin_r.c Sat Jan 9 15:07:43 2010 @@ -1,6 +1,6 @@ /* Provide a working getlogin_r for systems which lack it. - Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2005-2007, 2009-2010 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 @@ -39,15 +39,10 @@ errno = 0; n = getlogin (); - - /* A system function like getlogin_r is never supposed to set errno - to zero, so make sure errno is nonzero here. ENOENT is a - reasonable errno value if getlogin returns NULL. */ - if (!errno) - errno = ENOENT; - if (!n) - return errno; + /* ENOENT is a reasonable errno value if getlogin returns NULL. */ + return (errno != 0 ? errno : ENOENT); + nlen = strlen (n); if (size <= nlen) return ERANGE; --- m4/getlogin_r.m4.orig Sat Jan 9 15:08:13 2010 +++ m4/getlogin_r.m4 Sat Jan 9 15:07:58 2010 @@ -1,6 +1,6 @@ -#serial 4 +#serial 5 -# Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. +# Copyright (C) 2005-2007, 2009-2010 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -14,13 +14,16 @@ AC_DEFUN([gl_GETLOGIN_R], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + dnl Persuade glibc <unistd.h> to declare getlogin_r(). + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + AC_CHECK_FUNCS_ONCE([getlogin_r]) if test $ac_cv_func_getlogin_r = no; then AC_LIBOBJ([getlogin_r]) gl_PREREQ_GETLOGIN_R - if test $ac_cv_have_decl_getlogin_r = yes; then - HAVE_DECL_GETLOGIN_R=1 - else + AC_CHECK_DECLS_ONCE([getlogin_r]) + if test $ac_cv_have_decl_getlogin_r = no; then HAVE_DECL_GETLOGIN_R=0 fi fi @@ -29,5 +32,4 @@ AC_DEFUN([gl_PREREQ_GETLOGIN_R], [ AC_CHECK_DECLS_ONCE([getlogin]) - AC_CHECK_DECLS_ONCE([getlogin_r]) ])