getlogin_r: Small fixes.
authorBruno Haible <bruno@clisp.org>
Sat, 9 Jan 2010 14:14:41 +0000 (15:14 +0100)
committerIan Beckwith <ianb@erislabs.net>
Sun, 10 Jan 2010 00:50:44 +0000 (00:50 +0000)
(cherry picked from commit 89b39efd31cd0ffdaf05c9785c1af1e479728472)

ChangeLog
lib/getlogin_r.c
m4/getlogin_r.m4

index cbd3680..4d5d5f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2010-01-09  Bruno Haible  <bruno@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.
+
+2010-01-09  Bruno Haible  <bruno@clisp.org>
+
        * lib/unistd.in.h (getlogin_r): Add comment.
 
 2010-01-09  Bruno Haible  <bruno@clisp.org>
index dca4799..b8b6cdd 100644 (file)
@@ -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;
index d30b2e7..455e081 100644 (file)
@@ -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 <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_GETLOGIN_R],
 AC_DEFUN([gl_PREREQ_GETLOGIN_R],
 [
   AC_CHECK_DECLS_ONCE([getlogin])
-  AC_CHECK_DECLS_ONCE([getlogin_r])
 ])