immutable: Add tests.
[gnulib.git] / m4 / getpass.m4
blobb05cc34b1b9760ccc93dbf14b348d76bd1f17784
1 # getpass.m4 serial 16
2 dnl Copyright (C) 2002-2003, 2005-2006, 2009-2021 Free Software Foundation,
3 dnl 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.
8 # Provide a getpass() function if the system doesn't have it.
9 AC_DEFUN_ONCE([gl_FUNC_GETPASS],
11   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
13   dnl Persuade Solaris <unistd.h> and <stdlib.h> to declare getpass().
14   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16   AC_CHECK_FUNCS_ONCE([getpass])
17   if test $ac_cv_func_getpass = no; then
18     HAVE_GETPASS=0
19   fi
22 # Provide the GNU getpass() implementation. It supports passwords of
23 # arbitrary length (not just 8 bytes as on HP-UX).
24 AC_DEFUN([gl_FUNC_GETPASS_GNU],
26   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
27   AC_REQUIRE([gl_FUNC_GETPASS])
29   if test $ac_cv_func_getpass = yes; then
30     AC_CACHE_CHECK([for getpass without length limitations],
31       [gl_cv_func_getpass_good],
32       [AC_EGREP_CPP([Lucky GNU user],
33          [
34 #include <features.h>
35 #ifdef __GNU_LIBRARY__
36  #if (__GLIBC__ >= 2) && !defined __UCLIBC__
37   Lucky GNU user
38  #endif
39 #endif
40          ],
41          [gl_cv_func_getpass_good=yes],
42          [gl_cv_func_getpass_good=no])
43       ])
44     if test $gl_cv_func_getpass_good != yes; then
45       REPLACE_GETPASS=1
46     fi
47   fi
50 # Prerequisites of lib/getpass.c.
51 AC_DEFUN([gl_PREREQ_GETPASS], [
52   AC_CHECK_HEADERS_ONCE([stdio_ext.h termios.h])
53   AC_CHECK_FUNCS_ONCE([__fsetlocking])
54   AC_CHECK_DECLS([__fsetlocking],,,
55     [[#include <stdio.h>
56       #if HAVE_STDIO_EXT_H
57        #include <stdio_ext.h>
58       #endif]])
59   AC_CHECK_DECLS_ONCE([fflush_unlocked])
60   AC_CHECK_DECLS_ONCE([flockfile])
61   AC_CHECK_DECLS_ONCE([fputs_unlocked])
62   AC_CHECK_DECLS_ONCE([funlockfile])
63   AC_CHECK_DECLS_ONCE([putc_unlocked])
65   dnl We can't use AC_CHECK_FUNC here, because tcgetattr() is defined as a
66   dnl static inline function when compiling for Android 4.4 or older.
67   AC_CACHE_CHECK([for tcgetattr], [gl_cv_func_tcgetattr],
68     [AC_LINK_IFELSE(
69        [AC_LANG_PROGRAM(
70           [[#include <termios.h>
71             struct termios x;
72           ]],
73           [[return tcgetattr(0,&x);]])
74        ],
75        [gl_cv_func_tcgetattr=yes],
76        [gl_cv_func_tcgetattr=no])
77     ])
78   if test $gl_cv_func_tcgetattr = yes; then
79     HAVE_TCGETATTR=1
80   else
81     HAVE_TCGETATTR=0
82   fi
83   AC_DEFINE_UNQUOTED([HAVE_TCGETATTR], [$HAVE_TCGETATTR],
84     [Define to 1 if the system has the 'tcgetattr' function.])
86   dnl We can't use AC_CHECK_FUNC here, because tcsetattr() is defined as a
87   dnl static inline function when compiling for Android 4.4 or older.
88   AC_CACHE_CHECK([for tcsetattr], [gl_cv_func_tcsetattr],
89     [AC_LINK_IFELSE(
90        [AC_LANG_PROGRAM(
91           [[#include <termios.h>
92             struct termios x;
93           ]],
94           [[return tcsetattr(0,0,&x);]])
95        ],
96        [gl_cv_func_tcsetattr=yes],
97        [gl_cv_func_tcsetattr=no])
98     ])
99   if test $gl_cv_func_tcsetattr = yes; then
100     HAVE_TCSETATTR=1
101   else
102     HAVE_TCSETATTR=0
103   fi
104   AC_DEFINE_UNQUOTED([HAVE_TCSETATTR], [$HAVE_TCSETATTR],
105     [Define to 1 if the system has the 'tcsetattr' function.])