Debian Codegraph @

m4/glob.m4

raw
1 # glob.m4
2 # serial 34
3 dnl Copyright (C) 2005-2007, 2009-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 # The glob module assumes you want GNU glob, with glob_pattern_p etc,
10 # rather than vanilla POSIX glob. This means your code should
11 # always include <glob.h> for the glob prototypes.
12
13 AC_DEFUN([gl_GLOB],
14 [
15 AC_REQUIRE([gl_GLOB_H])
16
17 AC_CHECK_FUNCS_ONCE([glob_pattern_p])
18 gl_CHECK_FUNCS_ANDROID([glob], [[#include <glob.h>]])
19 if test $ac_cv_func_glob = no; then
20 HAVE_GLOB=0
21 case "$gl_cv_onwards_func_glob" in
22 future*) REPLACE_GLOB=1 ;;
23 esac
24 else
25
26 AC_CACHE_CHECK([whether glob overflows the stack with recursive calls],
27 [gl_cv_glob_overflows_stack],
28 [AC_RUN_IFELSE(
29 [AC_LANG_SOURCE([[
30 #include <stddef.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <glob.h>
34 int
35 main (void)
36 {
37 /* Test that glob with many trailing slashes or slashes following
38 a wildcard does not overflow the stack as it did in glibc 2.42
39 and earlier. */
40 char *p = malloc (10000);
41 glob_t g;
42 int result = 0;
43 if (p != NULL)
44 {
45 /* This test fails on glibc <= 2.42 (stack overflow),
46 Android. */
47 memset (p, '/', 9999);
48 p[9999] = '\0';
49 if (glob (p, 0, NULL, &g) != 0)
50 result |= 1;
51 globfree (&g);
52 #if !defined __ANDROID__
53 /* This test fails on Cygwin 3.6.4 (return value
54 GLOB_ABORTED). */
55 memset (p, '/', 9997);
56 p[1] = '*';
57 strcpy (p + 9997, "sh");
58 if (glob (p, 0, NULL, &g) != 0)
59 result |= 2;
60 globfree (&g);
61 #endif
62 }
63 return result;
64 }]])],
65 [gl_cv_glob_overflows_stack=no],
66 [gl_cv_glob_overflows_stack=yes],
67 [case "$host_os" in
68 # Guess yes on glibc systems.
69 *-gnu* | gnu*) gl_cv_glob_overflows_stack="guessing yes" ;;
70 # Guess yes on Cygwin.
71 cygwin*) gl_cv_glob_overflows_stack="guessing yes" ;;
72 # Guess yes on Android.
73 linux*-android*) gl_cv_glob_overflows_stack="guessing yes" ;;
74 # If we don't know, obey --enable-cross-guesses.
75 *) gl_cv_glob_overflows_stack="$gl_cross_guess_inverted" ;;
76 esac
77 ])
78 ])
79
80 case $gl_cv_glob_overflows_stack in
81 *yes) REPLACE_GLOB=1 ;;
82 *) REPLACE_GLOB=0 ;;
83 esac
84
85 if test $REPLACE_GLOB = 0; then
86 AC_CACHE_CHECK([whether glob lists broken symlinks],
87 [gl_cv_glob_lists_symlinks],
88 [if test $cross_compiling != yes; then
89 if ln -s conf-doesntexist conf$$-globtest 2>/dev/null; then
90 gl_cv_glob_lists_symlinks=maybe
91 else
92 # If we can't make a symlink, then we cannot test this issue. Be
93 # pessimistic about this.
94 gl_cv_glob_lists_symlinks=no
95 fi
96 if test $gl_cv_glob_lists_symlinks = maybe; then
97 AC_RUN_IFELSE(
98 [AC_LANG_PROGRAM(
99 [[#include <stddef.h>
100 #include <glob.h>]],
101 [[glob_t found;
102 if (glob ("conf*-globtest", 0, NULL, &found) == GLOB_NOMATCH)
103 return 1;
104 globfree (&found);
105 ]])],
106 [gl_cv_glob_lists_symlinks=yes],
107 [gl_cv_glob_lists_symlinks=no],
108 [dnl We don't get here.
109 :
110 ])
111 fi
112 rm -f conf$$-globtest
113 else
114 gl_cv_glob_lists_symlinks="$gl_cross_guess_normal"
115 fi
116 ])
117 case "$gl_cv_glob_lists_symlinks" in
118 *yes) ;;
119 *) REPLACE_GLOB=1 ;;
120 esac
121 fi
122
123 if test $REPLACE_GLOB = 0; then
124 AC_CACHE_CHECK([whether glob NOTDIR*/ omits symlink to nondir],
125 [gl_cv_glob_omit_nondir_symlinks],
126 [if test $cross_compiling != yes; then
127 if ln -s conf$$-file conf$$-globtest 2>/dev/null && touch conf$$-file
128 then
129 gl_cv_glob_omit_nondir_symlinks=maybe
130 else
131 # If we can't make a symlink, then we cannot test this issue. Be
132 # pessimistic about this.
133 gl_cv_glob_omit_nondir_symlinks=no
134 fi
135 if test $gl_cv_glob_omit_nondir_symlinks = maybe; then
136 AC_RUN_IFELSE(
137 [AC_LANG_PROGRAM(
138 [[#include <stddef.h>
139 #include <glob.h>]],
140 [[glob_t found;
141 if (glob ("conf*-globtest/", 0, NULL, &found) != GLOB_NOMATCH)
142 return 1;
143 globfree (&found);
144 ]])],
145 [gl_cv_glob_omit_nondir_symlinks=yes],
146 [gl_cv_glob_omit_nondir_symlinks=no],
147 [dnl We don't get here.
148 :
149 ])
150 fi
151 rm -f conf$$-file conf$$-globtest
152 else
153 gl_cv_glob_omit_nondir_symlinks="$gl_cross_guess_normal"
154 fi
155 ])
156 case "$gl_cv_glob_omit_nondir_symlinks" in
157 *yes) ;;
158 *) REPLACE_GLOB=1 ;;
159 esac
160 fi
161
162 fi
163
164 if test $ac_cv_func_glob_pattern_p = no; then
165 HAVE_GLOB_PATTERN_P=0
166 else
167 if test $REPLACE_GLOB = 1; then
168 REPLACE_GLOB_PATTERN_P=1
169 fi
170 fi
171
172 if test $HAVE_GLOB = 0 || test $REPLACE_GLOB = 1; then
173 gl_REPLACE_GLOB_H
174 fi
175 ])
176
177 # Prerequisites of lib/glob.c and lib/globfree.c.
178 AC_DEFUN([gl_PREREQ_GLOB],
179 [
180 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_TYPE])
181 AC_CHECK_HEADERS_ONCE([unistd.h])
182 gl_CHECK_FUNCS_ANDROID([getlogin_r], [[#include <unistd.h>]])
183 gl_CHECK_FUNCS_ANDROID([getpwnam_r], [[#include <pwd.h>]])
184 ])