| 1 | #serial 11 |
| 2 | |
| 3 | # Copyright (C) 2005-2007, 2009-2016 Free Software Foundation, Inc. |
| 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 |
| 33 | dnl On OSF/1 5.1, getlogin_r returns a truncated result if the buffer is |
| 34 | dnl 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], |
| 38 | [ |
| 39 | dnl Initial guess, used when cross-compiling. |
| 40 | changequote(,)dnl |
| 41 | case "$host_os" in |
| 42 | # Guess no on OSF/1. |
| 43 | osf*) gl_cv_func_getlogin_r_works="guessing no" ;; |
| 44 | # Guess yes otherwise. |
| 45 | *) gl_cv_func_getlogin_r_works="guessing yes" ;; |
| 46 | esac |
| 47 | changequote([,])dnl |
| 48 | AC_RUN_IFELSE( |
| 49 | [AC_LANG_SOURCE([[ |
| 50 | #include <stddef.h> |
| 51 | #include <unistd.h> |
| 52 | #if !HAVE_DECL_GETLOGIN_R |
| 53 | extern |
| 54 | # ifdef __cplusplus |
| 55 | "C" |
| 56 | # endif |
| 57 | int getlogin_r (char *, size_t); |
| 58 | #endif |
| 59 | int |
| 60 | main (void) |
| 61 | { |
| 62 | int result = 0; |
| 63 | char buf[100]; |
| 64 | |
| 65 | if (getlogin_r (buf, 0) == 0) |
| 66 | result |= 16; |
| 67 | if (getlogin_r (buf, 1) == 0) |
| 68 | result |= 17; |
| 69 | return result; |
| 70 | }]])], |
| 71 | [gl_cv_func_getlogin_r_works=yes], |
| 72 | [case $? in |
| 73 | 16 | 17) gl_cv_func_getlogin_r_works=no ;; |
| 74 | esac |
| 75 | ], |
| 76 | [:]) |
| 77 | ]) |
| 78 | case "$gl_cv_func_getlogin_r_works" in |
| 79 | *yes) ;; |
| 80 | *) REPLACE_GETLOGIN_R=1 ;; |
| 81 | esac |
| 82 | fi |
| 83 | ]) |
| 84 | |
| 85 | AC_DEFUN([gl_PREREQ_GETLOGIN_R], |
| 86 | [ |
| 87 | AC_CHECK_DECLS_ONCE([getlogin]) |
| 88 | ]) |