| 1 |
# getlogin_r.m4 |
| 2 |
# serial 17 |
| 3 |
dnl Copyright (C) 2005-2007, 2009-2026 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
dnl From Derek Price |
| 10 |
dnl |
| 11 |
dnl Provide getlogin_r when the system lacks it. |
| 12 |
dnl |
| 13 |
|
| 14 |
AC_DEFUN([gl_FUNC_GETLOGIN_R], |
| 15 |
[ |
| 16 |
AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) |
| 17 |
|
| 18 |
dnl Persuade glibc <unistd.h> to declare getlogin_r(). |
| 19 |
dnl Persuade Solaris <unistd.h> to provide the POSIX compliant declaration of |
| 20 |
dnl getlogin_r(). |
| 21 |
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 22 |
|
| 23 |
AC_CHECK_DECLS_ONCE([getlogin_r]) |
| 24 |
if test $ac_cv_have_decl_getlogin_r = no; then |
| 25 |
HAVE_DECL_GETLOGIN_R=0 |
| 26 |
fi |
| 27 |
|
| 28 |
gl_CHECK_FUNCS_ANDROID([getlogin_r], [[#include <unistd.h>]]) |
| 29 |
if test $ac_cv_func_getlogin_r = no; then |
| 30 |
HAVE_GETLOGIN_R=0 |
| 31 |
case "$gl_cv_onwards_func_getlogin_r" in |
| 32 |
future*) REPLACE_GETLOGIN_R=1 ;; |
| 33 |
esac |
| 34 |
else |
| 35 |
HAVE_GETLOGIN_R=1 |
| 36 |
dnl On Mac OS X 10.13, getlogin_r returns a truncated result |
| 37 |
dnl if the buffer is not large enough. |
| 38 |
dnl On musl libc, getlogin_r returns getenv ("LOGNAME"). |
| 39 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 40 |
AC_CACHE_CHECK([whether getlogin_r works], |
| 41 |
[gl_cv_func_getlogin_r_works], |
| 42 |
[ |
| 43 |
dnl Initial guess, used when cross-compiling. |
| 44 |
changequote(,)dnl |
| 45 |
case "$host_os" in |
| 46 |
# Guess no on Mac OS X. |
| 47 |
darwin*) gl_cv_func_getlogin_r_works="guessing no" ;; |
| 48 |
# Guess no on musl libc. |
| 49 |
*-musl* | midipix*) gl_cv_func_getlogin_r_works="guessing no" ;; |
| 50 |
# Guess yes otherwise. |
| 51 |
*) gl_cv_func_getlogin_r_works="guessing yes" ;; |
| 52 |
esac |
| 53 |
changequote([,])dnl |
| 54 |
AC_RUN_IFELSE( |
| 55 |
[AC_LANG_SOURCE([[ |
| 56 |
#include <stddef.h> |
| 57 |
#include <stdlib.h> |
| 58 |
#include <string.h> |
| 59 |
#include <unistd.h> |
| 60 |
#if !HAVE_DECL_GETLOGIN_R |
| 61 |
extern |
| 62 |
# ifdef __cplusplus |
| 63 |
"C" |
| 64 |
# endif |
| 65 |
int getlogin_r (char *, size_t); |
| 66 |
#endif |
| 67 |
int |
| 68 |
main (void) |
| 69 |
{ |
| 70 |
int result = 0; |
| 71 |
char buf[100]; |
| 72 |
|
| 73 |
if (getlogin_r (buf, 0) == 0) |
| 74 |
result |= 1; |
| 75 |
if (getlogin_r (buf, 1) == 0) |
| 76 |
result |= 2; |
| 77 |
if (getlogin_r (buf, 100) == 0) |
| 78 |
{ |
| 79 |
size_t n = strlen (buf); |
| 80 |
if (getlogin_r (buf, n) == 0) |
| 81 |
result |= 4; |
| 82 |
} |
| 83 |
putenv ("LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke"); |
| 84 |
if (getlogin_r (buf, 100) == 0 |
| 85 |
&& strcmp (buf, "ygvfibmslhkmvoetbrcegzwydorcke") == 0) |
| 86 |
result |= 8; |
| 87 |
return result; |
| 88 |
}]])], |
| 89 |
[gl_cv_func_getlogin_r_works=yes], |
| 90 |
[gl_cv_func_getlogin_r_works=no], |
| 91 |
[:]) |
| 92 |
]) |
| 93 |
case "$gl_cv_func_getlogin_r_works" in |
| 94 |
*yes) ;; |
| 95 |
*) REPLACE_GETLOGIN_R=1 ;; |
| 96 |
esac |
| 97 |
fi |
| 98 |
]) |
| 99 |
|
| 100 |
AC_DEFUN([gl_PREREQ_GETLOGIN_R], |
| 101 |
[ |
| 102 |
AC_CHECK_DECLS_ONCE([getlogin]) |
| 103 |
]) |