Commit | Line | Data |
---|---|---|
c0c3707f | 1 | #serial 12 |
6ec2e0f5 | 2 | |
5df4cba6 | 3 | # Copyright (C) 2005-2007, 2009-2020 Free Software Foundation, Inc. |
6ec2e0f5 SDJ |
4 | # |
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. | |
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 | AC_CHECK_FUNCS_ONCE([getlogin_r]) | |
29 | if test $ac_cv_func_getlogin_r = no; then | |
30 | HAVE_GETLOGIN_R=0 | |
31 | else | |
32 | HAVE_GETLOGIN_R=1 | |
c0c3707f CB |
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. | |
6ec2e0f5 SDJ |
35 | AC_REQUIRE([AC_CANONICAL_HOST]) |
36 | AC_CACHE_CHECK([whether getlogin_r works with small buffers], | |
37 | [gl_cv_func_getlogin_r_works], | |
38 | [ | |
39 | dnl Initial guess, used when cross-compiling. | |
40 | changequote(,)dnl | |
41 | case "$host_os" in | |
c0c3707f CB |
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" ;; | |
6ec2e0f5 SDJ |
46 | esac |
47 | changequote([,])dnl | |
48 | AC_RUN_IFELSE( | |
49 | [AC_LANG_SOURCE([[ | |
50 | #include <stddef.h> | |
c0c3707f | 51 | #include <string.h> |
6ec2e0f5 SDJ |
52 | #include <unistd.h> |
53 | #if !HAVE_DECL_GETLOGIN_R | |
54 | extern | |
55 | # ifdef __cplusplus | |
56 | "C" | |
57 | # endif | |
58 | int getlogin_r (char *, size_t); | |
59 | #endif | |
60 | int | |
61 | main (void) | |
62 | { | |
63 | int result = 0; | |
64 | char buf[100]; | |
65 | ||
66 | if (getlogin_r (buf, 0) == 0) | |
c0c3707f | 67 | result |= 1; |
6ec2e0f5 | 68 | if (getlogin_r (buf, 1) == 0) |
c0c3707f CB |
69 | result |= 2; |
70 | if (getlogin_r (buf, 100) == 0) | |
71 | { | |
72 | size_t n = strlen (buf); | |
73 | if (getlogin_r (buf, n) == 0) | |
74 | result |= 4; | |
75 | } | |
6ec2e0f5 SDJ |
76 | return result; |
77 | }]])], | |
78 | [gl_cv_func_getlogin_r_works=yes], | |
c0c3707f | 79 | [gl_cv_func_getlogin_r_works=no], |
6ec2e0f5 SDJ |
80 | [:]) |
81 | ]) | |
82 | case "$gl_cv_func_getlogin_r_works" in | |
83 | *yes) ;; | |
84 | *) REPLACE_GETLOGIN_R=1 ;; | |
85 | esac | |
86 | fi | |
87 | ]) | |
88 | ||
89 | AC_DEFUN([gl_PREREQ_GETLOGIN_R], | |
90 | [ | |
91 | AC_CHECK_DECLS_ONCE([getlogin]) | |
92 | ]) |