Debian Codegraph @

m4/getlogin.m4

raw
1 # getlogin.m4
2 # serial 8
3 dnl Copyright (C) 2010-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 AC_DEFUN([gl_FUNC_GETLOGIN],
10 [
11 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
12 AC_CHECK_DECLS_ONCE([getlogin])
13 if test $ac_cv_have_decl_getlogin = no; then
14 HAVE_DECL_GETLOGIN=0
15 fi
16 AC_CHECK_FUNCS_ONCE([getlogin])
17 if test $ac_cv_func_getlogin = no; then
18 HAVE_GETLOGIN=0
19 else
20 dnl On musl libc, getlogin returns getenv ("LOGNAME").
21 AC_REQUIRE([AC_CANONICAL_HOST])
22 AC_CACHE_CHECK([whether getlogin works],
23 [gl_cv_func_getlogin_works],
24 [
25 dnl Initial guess, used when cross-compiling.
26 changequote(,)dnl
27 case "$host_os" in
28 # Guess no on musl libc.
29 *-musl* | midipix*) gl_cv_func_getlogin_works="guessing no" ;;
30 # Guess yes otherwise.
31 *) gl_cv_func_getlogin_works="guessing yes" ;;
32 esac
33 changequote([,])dnl
34 AC_RUN_IFELSE(
35 [AC_LANG_SOURCE([[
36 #include <stdlib.h>
37 #include <string.h>
38 #include <unistd.h>
39 #if !HAVE_DECL_GETLOGIN
40 extern
41 # ifdef __cplusplus
42 "C"
43 # endif
44 char *getlogin (void);
45 #endif
46 int
47 main (void)
48 {
49 int result = 0;
50 char *buf;
51
52 putenv ("LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke");
53 buf = getlogin ();
54 if (buf != NULL && strcmp (buf, "ygvfibmslhkmvoetbrcegzwydorcke") == 0)
55 result |= 1;
56 return result;
57 }]])],
58 [gl_cv_func_getlogin_works=yes],
59 [gl_cv_func_getlogin_works=no],
60 [:])
61 ])
62 case "$gl_cv_func_getlogin_works" in
63 *yes) ;;
64 *) REPLACE_GETLOGIN=1 ;;
65 esac
66 fi
67 ])
68
69 dnl Determines the library needed by the implementation of the
70 dnl getlogin and getlogin_r functions.
71 AC_DEFUN([gl_LIB_GETLOGIN],
72 [
73 AC_REQUIRE([AC_CANONICAL_HOST])
74 case $host_os in
75 mingw* | windows*)
76 GETLOGIN_LIB='-ladvapi32' ;;
77 *)
78 GETLOGIN_LIB= ;;
79 esac
80 AC_SUBST([GETLOGIN_LIB])
81 dnl For backward compatibility.
82 LIB_GETLOGIN="$GETLOGIN_LIB"
83 AC_SUBST([LIB_GETLOGIN])
84 ])