From 89b39efd31cd0ffdaf05c9785c1af1e479728472 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 9 Jan 2010 15:14:41 +0100 Subject: [PATCH] getlogin_r: Small fixes. --- ChangeLog | 10 ++++++++++ lib/getlogin_r.c | 13 ++++--------- m4/getlogin_r.m4 | 14 ++++++++------ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index a201f2569..8a1908c33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2010-01-09 Bruno Haible + 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. + +2010-01-09 Bruno Haible + * lib/unistd.in.h (getlogin_r): Add comment. 2010-01-09 Bruno Haible diff --git a/lib/getlogin_r.c b/lib/getlogin_r.c index dca47993c..b8b6cdd2d 100644 --- a/lib/getlogin_r.c +++ b/lib/getlogin_r.c @@ -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 @@ getlogin_r (char *name, size_t size) 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; diff --git a/m4/getlogin_r.m4 b/m4/getlogin_r.m4 index d30b2e7c7..455e0813d 100644 --- a/m4/getlogin_r.m4 +++ b/m4/getlogin_r.m4 @@ -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 @@ dnl AC_DEFUN([gl_GETLOGIN_R], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + dnl Persuade glibc 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_GETLOGIN_R], AC_DEFUN([gl_PREREQ_GETLOGIN_R], [ AC_CHECK_DECLS_ONCE([getlogin]) - AC_CHECK_DECLS_ONCE([getlogin_r]) ]) -- 2.11.0