3 # Copyright (C) 2005-2007, 2009-2018 Free Software Foundation, Inc.
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
11 dnl Provide getlogin_r when the system lacks it.
14 AC_DEFUN([gl_FUNC_GETLOGIN_R],
16 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
18 dnl Persuade glibc <unistd.h> to declare getlogin_r().
19 dnl Persuade Solaris <unistd.h> to provide the POSIX compliant declaration of
21 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
23 AC_CHECK_DECLS_ONCE([getlogin_r])
24 if test $ac_cv_have_decl_getlogin_r = no; then
25 HAVE_DECL_GETLOGIN_R=0
28 AC_CHECK_FUNCS_ONCE([getlogin_r])
29 if test $ac_cv_func_getlogin_r = no; then
33 dnl On Mac OS X 10.12 and OSF/1 5.1, getlogin_r returns a truncated result
34 dnl if the buffer is not large enough.
35 AC_REQUIRE([AC_CANONICAL_HOST])
36 AC_CACHE_CHECK([whether getlogin_r works with small buffers],
37 [gl_cv_func_getlogin_r_works],
39 dnl Initial guess, used when cross-compiling.
42 # Guess no on Mac OS X, OSF/1.
43 darwin* | osf*) gl_cv_func_getlogin_r_works="guessing no" ;;
44 # Guess yes otherwise.
45 *) gl_cv_func_getlogin_r_works="guessing yes" ;;
53 #if !HAVE_DECL_GETLOGIN_R
58 int getlogin_r (char *, size_t);
66 if (getlogin_r (buf, 0) == 0)
68 if (getlogin_r (buf, 1) == 0)
70 if (getlogin_r (buf, 100) == 0)
72 size_t n = strlen (buf);
73 if (getlogin_r (buf, n) == 0)
78 [gl_cv_func_getlogin_r_works=yes],
79 [gl_cv_func_getlogin_r_works=no],
82 case "$gl_cv_func_getlogin_r_works" in
84 *) REPLACE_GETLOGIN_R=1 ;;
89 AC_DEFUN([gl_PREREQ_GETLOGIN_R],
91 AC_CHECK_DECLS_ONCE([getlogin])