+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.
/* 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
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;
-#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,
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
AC_DEFUN([gl_PREREQ_GETLOGIN_R],
[
AC_CHECK_DECLS_ONCE([getlogin])
- AC_CHECK_DECLS_ONCE([getlogin_r])
])