getlogin_r: Move AC_LIBOBJ invocations to module description.
[gnulib.git] / m4 / getlogin_r.m4
1 #serial 10
2
3 # Copyright (C) 2005-2007, 2009-2011 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 int getlogin_r (char *, size_t);
54 #endif
55 int
56 main (void)
57 {
58   int result = 0;
59   char buf[100];
60
61   if (getlogin_r (buf, 0) == 0)
62     result |= 16;
63   if (getlogin_r (buf, 1) == 0)
64     result |= 17;
65   return result;
66 }]])],
67           [gl_cv_func_getlogin_r_works=yes],
68           [case $? in
69              16 | 17) gl_cv_func_getlogin_r_works=no ;;
70            esac
71           ],
72           [:])
73       ])
74     case "$gl_cv_func_getlogin_r_works" in
75       *yes) ;;
76       *) REPLACE_GETLOGIN_R=1 ;;
77     esac
78   fi
79 ])
80
81 AC_DEFUN([gl_PREREQ_GETLOGIN_R],
82 [
83   AC_CHECK_DECLS_ONCE([getlogin])
84 ])