* 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.
+2010-12-22 Bruno Haible <bruno@clisp.org>
+
+ 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.
+
2010-12-22 Bruno Haible <bruno@clisp.org>
ptsname: Avoid test failure on OSF/1 5.1.
@item
This function has an incompatible declaration on some platforms:
Solaris 11 2010-11 (when @code{_POSIX_PTHREAD_SEMANTICS} is not defined).
+@item
+This function returns a truncated result, instead of failing with error code
+@code{ERANGE}, when the buffer is not large enough, on some platforms:
+OSF/1 5.1.
@end itemize
Portability problems not fixed by Gnulib:
/* Provide a working getlogin_r for systems which lack it.
- Copyright (C) 2005-2007, 2009-2010 Free Software Foundation, Inc.
+ Copyright (C) 2005-2007, 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
int
getlogin_r (char *name, size_t size)
{
+#undef getlogin_r
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Native Windows platform. */
DWORD sz;
return ENOENT;
}
return 0;
+#elif HAVE_GETLOGIN_R
+ /* Platform with a getlogin_r() function. */
+ int ret = getlogin_r (name, size);
+
+ if (ret == 0 && memchr (name, '\0', size) == NULL)
+ /* name contains a truncated result. */
+ return ERANGE;
+ return ret;
#else
/* Platform with a getlogin() function. */
char *n;
${LOGNAME-$USER} on Unix platforms,
$USERNAME on native Windows platforms.
*/
-# if !@HAVE_DECL_GETLOGIN_R@
+# if @REPLACE_GETLOGIN_R@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define getlogin_r rpl_getlogin_r
+# endif
+_GL_FUNCDECL_RPL (getlogin_r, int, (char *name, size_t size)
+ _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (getlogin_r, int, (char *name, size_t size));
+# else
+# if !@HAVE_DECL_GETLOGIN_R@
_GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
_GL_ARG_NONNULL ((1)));
-# endif
+# endif
/* Need to cast, because on Solaris 10 systems, the second argument is
int size. */
_GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
+# endif
_GL_CXXALIASWARN (getlogin_r);
#elif defined GNULIB_POSIXCHECK
# undef getlogin_r
-#serial 8
+#serial 9
# Copyright (C) 2005-2007, 2009-2010 Free Software Foundation, Inc.
#
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
-# unistd_h.m4 serial 51
+# unistd_h.m4 serial 52
dnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
REPLACE_FCHOWNAT=0; AC_SUBST([REPLACE_FCHOWNAT])
REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD])
REPLACE_GETDOMAINNAME=0; AC_SUBST([REPLACE_GETDOMAINNAME])
+ REPLACE_GETLOGIN_R=0; AC_SUBST([REPLACE_GETLOGIN_R])
REPLACE_GETGROUPS=0; AC_SUBST([REPLACE_GETGROUPS])
REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE])
REPLACE_LCHOWN=0; AC_SUBST([REPLACE_LCHOWN])
Depends-on:
extensions
unistd
+memchr
configure.ac:
gl_FUNC_GETLOGIN_R
-e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \
-e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
-e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \
+ -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \
-e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \
-e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
-e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \