OpenCoverage

glob.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/glob/glob.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* glob.c -- file-name wildcard pattern matching for Bash.-
2-
3 Copyright (C) 1985-2017 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne-Again SHell.-
6 -
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21/* To whomever it may concern: I have never seen the code which most-
22 Unix programs use to perform this function. I wrote this from scratch-
23 based on specifications for the pattern matching. --RMS. */-
24-
25#include <config.h>-
26-
27#if !defined (__GNUC__) && !defined (HAVE_ALLOCA_H) && defined (_AIX)-
28 #pragma alloca-
29#endif /* _AIX && RISC6000 && !__GNUC__ */-
30-
31#include "bashtypes.h"-
32-
33#if defined (HAVE_UNISTD_H)-
34# include <unistd.h>-
35#endif-
36-
37#include "bashansi.h"-
38#include "posixdir.h"-
39#include "posixstat.h"-
40#include "shmbutil.h"-
41#include "xmalloc.h"-
42-
43#include "filecntl.h"-
44#if !defined (F_OK)-
45# define F_OK 0-
46#endif-
47-
48#include "stdc.h"-
49#include "memalloc.h"-
50-
51#include <signal.h>-
52-
53#include "shell.h"-
54-
55#include "glob.h"-
56#include "strmatch.h"-
57-
58#if !defined (HAVE_BCOPY) && !defined (bcopy)-
59# define bcopy(s, d, n) ((void) memcpy ((d), (s), (n)))-
60#endif /* !HAVE_BCOPY && !bcopy */-
61-
62#if !defined (NULL)-
63# if defined (__STDC__)-
64# define NULL ((void *) 0)-
65# else-
66# define NULL 0x0-
67# endif /* __STDC__ */-
68#endif /* !NULL */-
69-
70#if !defined (FREE)-
71# define FREE(x) if (x) free (x)-
72#endif-
73-
74/* Don't try to alloca() more than this much memory for `struct globval'-
75 in glob_vector() */-
76#ifndef ALLOCA_MAX-
77# define ALLOCA_MAX 100000-
78#endif-
79-
80struct globval-
81 {-
82 struct globval *next;-
83 char *name;-
84 };-
85-
86extern void throw_to_top_level __P((void));-
87extern int sh_eaccess __P((const char *, int));-
88extern char *sh_makepath __P((const char *, const char *, int));-
89extern int signal_is_pending __P((int));-
90extern void run_pending_traps __P((void));-
91-
92extern int extended_glob;-
93-
94/* Global variable which controls whether or not * matches .*.-
95 Non-zero means don't match .*. */-
96int noglob_dot_filenames = 1;-
97-
98/* Global variable which controls whether or not filename globbing-
99 is done without regard to case. */-
100int glob_ignore_case = 0;-
101-
102/* Global variable to return to signify an error in globbing. */-
103char *glob_error_return;-
104-
105static struct globval finddirs_error_return;-
106-
107/* Some forward declarations. */-
108static int skipname __P((char *, char *, int));-
109#if HANDLE_MULTIBYTE-
110static int mbskipname __P((char *, char *, int));-
111#endif-
112#if HANDLE_MULTIBYTE-
113static void udequote_pathname __P((char *));-
114static void wdequote_pathname __P((char *));-
115#else-
116# define dequote_pathname udequote_pathname-
117#endif-
118static void dequote_pathname __P((char *));-
119static int glob_testdir __P((char *, int));-
120static char **glob_dir_to_array __P((char *, char **, int));-
121-
122/* Make sure these names continue to agree with what's in smatch.c */-
123extern char *glob_patscan __P((char *, char *, int));-
124extern wchar_t *glob_patscan_wc __P((wchar_t *, wchar_t *, int));-
125-
126/* And this from gmisc.c/gm_loop.c */-
127extern int wextglob_pattern_p __P((wchar_t *));-
128-
129extern char *glob_dirscan __P((char *, int));-
130-
131/* Compile `glob_loop.c' for single-byte characters. */-
132#define GCHAR unsigned char-
133#define CHAR char-
134#define INT int-
135#define L(CS) CS-
136#define INTERNAL_GLOB_PATTERN_P internal_glob_pattern_p-
137#include "glob_loop.c"-
138-
139/* Compile `glob_loop.c' again for multibyte characters. */-
140#if HANDLE_MULTIBYTE-
141-
142#define GCHAR wchar_t-
143#define CHAR wchar_t-
144#define INT wint_t-
145#define L(CS) L##CS-
146#define INTERNAL_GLOB_PATTERN_P internal_glob_wpattern_p-
147#include "glob_loop.c"-
148-
149#endif /* HANDLE_MULTIBYTE */-
150-
151/* And now a function that calls either the single-byte or multibyte version-
152 of internal_glob_pattern_p. */-
153int-
154glob_pattern_p (pattern)-
155 const char *pattern;-
156{-
157#if HANDLE_MULTIBYTE-
158 size_t n;-
159 wchar_t *wpattern;-
160 int r;-
161-
162 if (MB_CUR_MAX == 1)
(__ctype_get_m...r_max ()) == 1Description
TRUEevaluated 1185 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1095 times by 1 test
Evaluated by:
  • Self test
1095-1185
163 return (internal_glob_pattern_p ((unsigned char *)pattern));
executed 1185 times by 1 test: return (internal_glob_pattern_p ((unsigned char *)pattern));
Executed by:
  • Self test
1185
164-
165 /* Convert strings to wide chars, and call the multibyte version. */-
166 n = xdupmbstowcs (&wpattern, NULL, pattern);-
167 if (n == (size_t)-1)
n == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 1095 times by 1 test
Evaluated by:
  • Self test
0-1095
168 /* Oops. Invalid multibyte sequence. Try it as single-byte sequence. */-
169 return (internal_glob_pattern_p ((unsigned char *)pattern));
never executed: return (internal_glob_pattern_p ((unsigned char *)pattern));
0
170-
171 r = internal_glob_wpattern_p (wpattern);-
172 free (wpattern);-
173-
174 return r;
executed 1095 times by 1 test: return r;
Executed by:
  • Self test
1095
175#else-
176 return (internal_glob_pattern_p (pattern));-
177#endif-
178}-
179-
180#if EXTENDED_GLOB-
181/* Return 1 if all subpatterns in the extended globbing pattern PAT indicate-
182 that the name should be skipped. XXX - doesn't handle pattern negation,-
183 not sure if it should */-
184static int-
185extglob_skipname (pat, dname, flags)-
186 char *pat, *dname;-
187 int flags;-
188{-
189 char *pp, *pe, *t, *se;-
190 int n, r, negate, wild;-
191-
192 negate = *pat == '!';-
193 wild = *pat == '*' || *pat == '?';
*pat == '*'Description
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2306 times by 1 test
Evaluated by:
  • Self test
*pat == '?'Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2290 times by 1 test
Evaluated by:
  • Self test
16-2306
194 pp = pat + 2;-
195 se = pp + strlen (pp) - 1; /* end of string */-
196 pe = glob_patscan (pp, se, 0); /* end of extglob pattern (( */-
197 /* we should check for invalid extglob pattern here */-
198 if (pe == 0)
pe == 0Description
TRUEnever evaluated
FALSEevaluated 2352 times by 1 test
Evaluated by:
  • Self test
0-2352
199 return 0;
never executed: return 0;
0
200-
201 /* if pe != se we have more of the pattern at the end of the extglob-
202 pattern. Check the easy case first ( */-
203 if (pe == se && *pe == ')' && (t = strchr (pp, '|')) == 0)
pe == seDescription
TRUEevaluated 2314 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
*pe == ')'Description
TRUEevaluated 2256 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 58 times by 1 test
Evaluated by:
  • Self test
(t = (__extens...'|' ))) ) == 0Description
TRUEevaluated 2112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 144 times by 1 test
Evaluated by:
  • Self test
__builtin_constant_p ( '|' )Description
TRUEevaluated 2256 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
!__builtin_constant_p ( pp )Description
TRUEevaluated 2256 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
( '|' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 2256 times by 1 test
Evaluated by:
  • Self test
0-2314
204 {-
205 *pe = '\0';-
206#if defined (HANDLE_MULTIBYTE)-
207 r = mbskipname (pp, dname, flags);-
208#else-
209 r = skipname (pp, dname, flags); /*(*/-
210#endif-
211 *pe = ')';-
212 if (wild && pe[1]) /* if we can match zero instances, check further */
wildDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2090 times by 1 test
Evaluated by:
  • Self test
pe[1]Description
TRUEnever evaluated
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test
0-2090
213 return (skipname (pe+1, dname, flags));
never executed: return (skipname (pe+1, dname, flags));
0
214 return r;
executed 2112 times by 1 test: return r;
Executed by:
  • Self test
2112
215 }-
216-
217 /* check every subpattern */-
218 while (t = glob_patscan (pp, pe, '|'))
t = glob_patscan (pp, pe, '|')Description
TRUEevaluated 275 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69 times by 1 test
Evaluated by:
  • Self test
69-275
219 {-
220 n = t[-1]; /* ( */-
221 if (extglob_pattern_p (pp) && n == ')')
extglob_pattern_p (pp)Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 211 times by 1 test
Evaluated by:
  • Self test
n == ')'Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-211
222 t[-1] = n; /* no-op for now */
executed 64 times by 1 test: t[-1] = n;
Executed by:
  • Self test
64
223 else-
224 t[-1] = '\0';
executed 211 times by 1 test: t[-1] = '\0';
Executed by:
  • Self test
211
225#if defined (HANDLE_MULTIBYTE)-
226 r = mbskipname (pp, dname, flags);-
227#else-
228 r = skipname (pp, dname, flags);-
229#endif-
230 t[-1] = n;-
231 if (r == 0) /* if any pattern says not skip, we don't skip */
r == 0Description
TRUEevaluated 171 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
104-171
232 return r;
executed 171 times by 1 test: return r;
Executed by:
  • Self test
171
233 pp = t;-
234 } /*(*/
executed 104 times by 1 test: end of block
Executed by:
  • Self test
104
235-
236 /* glob_patscan might find end of string */-
237 if (pp == se)
pp == seDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test
23-46
238 return r;
executed 46 times by 1 test: return r;
Executed by:
  • Self test
46
239-
240 /* but if it doesn't then we didn't match a leading dot */-
241 if (wild && *pe) /* if we can match zero instances, check further */
wildDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
*peDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-14
242 return (skipname (pe, dname, flags));
executed 14 times by 1 test: return (skipname (pe, dname, flags));
Executed by:
  • Self test
14
243 return 1;
executed 9 times by 1 test: return 1;
Executed by:
  • Self test
9
244}-
245#endif-
246-
247/* Return 1 if DNAME should be skipped according to PAT. Mostly concerned-
248 with matching leading `.'. */-
249static int-
250skipname (pat, dname, flags)-
251 char *pat;-
252 char *dname;-
253 int flags;-
254{-
255#if EXTENDED_GLOB-
256 if (extglob_pattern_p (pat)) /* XXX */
extglob_pattern_p (pat)Description
TRUEevaluated 2352 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 983727 times by 1 test
Evaluated by:
  • Self test
2352-983727
257 return (extglob_skipname (pat, dname, flags));
executed 2352 times by 1 test: return (extglob_skipname (pat, dname, flags));
Executed by:
  • Self test
2352
258#endif-
259-
260 /* If a leading dot need not be explicitly matched, and the pattern-
261 doesn't start with a `.', don't match `.' or `..' */-
262 if (noglob_dot_filenames == 0 && pat[0] != '.' &&
noglob_dot_filenames == 0Description
TRUEevaluated 164 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 983563 times by 1 test
Evaluated by:
  • Self test
pat[0] != '.'Description
TRUEevaluated 164 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-983563
263 (pat[0] != '\\' || pat[1] != '.') &&
pat[0] != '\\'Description
TRUEevaluated 164 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
pat[1] != '.'Description
TRUEnever evaluated
FALSEnever evaluated
0-164
264 (dname[0] == '.' &&
dname[0] == '.'Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 130 times by 1 test
Evaluated by:
  • Self test
34-130
265 (dname[1] == '\0' || (dname[1] == '.' && dname[2] == '\0'))))
dname[1] == '\0'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
dname[1] == '.'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
dname[2] == '\0'Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-26
266 return 1;
executed 16 times by 1 test: return 1;
Executed by:
  • Self test
16
267-
268 /* If a dot must be explicitly matched, check to see if they do. */-
269 else if (noglob_dot_filenames && dname[0] == '.' && pat[0] != '.' &&
noglob_dot_filenamesDescription
TRUEevaluated 983563 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 148 times by 1 test
Evaluated by:
  • Self test
dname[0] == '.'Description
TRUEevaluated 3164 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 980399 times by 1 test
Evaluated by:
  • Self test
pat[0] != '.'Description
TRUEevaluated 3138 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-983563
270 (pat[0] != '\\' || pat[1] != '.'))
pat[0] != '\\'Description
TRUEevaluated 3120 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
pat[1] != '.'Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3120
271 return 1;
executed 3138 times by 1 test: return 1;
Executed by:
  • Self test
3138
272-
273 return 0;
executed 980573 times by 1 test: return 0;
Executed by:
  • Self test
980573
274}-
275-
276#if HANDLE_MULTIBYTE-
277-
278static int-
279wskipname (pat, dname, flags)-
280 wchar_t *pat, *dname;-
281 int flags;-
282{-
283 /* If a leading dot need not be explicitly matched, and the-
284 pattern doesn't start with a `.', don't match `.' or `..' */-
285 if (noglob_dot_filenames == 0 && pat[0] != L'.' &&
noglob_dot_filenames == 0Description
TRUEnever evaluated
FALSEnever evaluated
pat[0] != L'.'Description
TRUEnever evaluated
FALSEnever evaluated
0
286 (pat[0] != L'\\' || pat[1] != L'.') &&
pat[0] != L'\\'Description
TRUEnever evaluated
FALSEnever evaluated
pat[1] != L'.'Description
TRUEnever evaluated
FALSEnever evaluated
0
287 (dname[0] == L'.' &&
dname[0] == L'.'Description
TRUEnever evaluated
FALSEnever evaluated
0
288 (dname[1] == L'\0' || (dname[1] == L'.' && dname[2] == L'\0'))))
dname[1] == L'\0'Description
TRUEnever evaluated
FALSEnever evaluated
dname[1] == L'.'Description
TRUEnever evaluated
FALSEnever evaluated
dname[2] == L'\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
289 return 1;
never executed: return 1;
0
290-
291 /* If a leading dot must be explicitly matched, check to see if the-
292 pattern and dirname both have one. */-
293 else if (noglob_dot_filenames && dname[0] == L'.' &&
noglob_dot_filenamesDescription
TRUEnever evaluated
FALSEnever evaluated
dname[0] == L'.'Description
TRUEnever evaluated
FALSEnever evaluated
0
294 pat[0] != L'.' &&
pat[0] != L'.'Description
TRUEnever evaluated
FALSEnever evaluated
0
295 (pat[0] != L'\\' || pat[1] != L'.'))
pat[0] != L'\\'Description
TRUEnever evaluated
FALSEnever evaluated
pat[1] != L'.'Description
TRUEnever evaluated
FALSEnever evaluated
0
296 return 1;
never executed: return 1;
0
297-
298 return 0;
never executed: return 0;
0
299}-
300-
301static int-
302wextglob_skipname (pat, dname, flags)-
303 wchar_t *pat, *dname;-
304 int flags;-
305{-
306#if EXTENDED_GLOB-
307 wchar_t *pp, *pe, *t, n, *se;-
308 int r, negate, wild;-
309-
310 negate = *pat == L'!';-
311 wild = *pat == L'*' || *pat == L'?';
*pat == L'*'Description
TRUEnever evaluated
FALSEnever evaluated
*pat == L'?'Description
TRUEnever evaluated
FALSEnever evaluated
0
312 pp = pat + 2;-
313 se = pp + wcslen (pp) - 1; /*(*/-
314 pe = glob_patscan_wc (pp, se, 0);-
315-
316 if (pe == se && *pe == ')' && (t = wcschr (pp, L'|')) == 0)
pe == seDescription
TRUEnever evaluated
FALSEnever evaluated
*pe == ')'Description
TRUEnever evaluated
FALSEnever evaluated
(t = wcschr (pp, L'|')) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
317 {-
318 *pe = L'\0';-
319 r = wskipname (pp, dname, flags); /*(*/-
320 *pe = L')';-
321 if (wild && pe[1] != L'\0')
wildDescription
TRUEnever evaluated
FALSEnever evaluated
pe[1] != L'\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
322 return (wskipname (pe+1, dname, flags));
never executed: return (wskipname (pe+1, dname, flags));
0
323 return r;
never executed: return r;
0
324 }-
325-
326 /* check every subpattern */-
327 while (t = glob_patscan_wc (pp, pe, '|'))
t = glob_patsc... (pp, pe, '|')Description
TRUEnever evaluated
FALSEnever evaluated
0
328 {-
329 n = t[-1]; /* ( */-
330 if (wextglob_pattern_p (pp) && n == L')')
wextglob_pattern_p (pp)Description
TRUEnever evaluated
FALSEnever evaluated
n == L')'Description
TRUEnever evaluated
FALSEnever evaluated
0
331 t[-1] = n; /* no-op for now */
never executed: t[-1] = n;
0
332 else-
333 t[-1] = L'\0';
never executed: t[-1] = L'\0';
0
334 r = wskipname (pp, dname, flags);-
335 t[-1] = n;-
336 if (r == 0)
r == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
337 return 0;
never executed: return 0;
0
338 pp = t;-
339 }
never executed: end of block
0
340-
341 if (pp == pe) /* glob_patscan_wc might find end of pattern */
pp == peDescription
TRUEnever evaluated
FALSEnever evaluated
0
342 return r;
never executed: return r;
0
343-
344 /* but if it doesn't then we didn't match a leading dot */-
345 if (wild && *pe != L'\0')
wildDescription
TRUEnever evaluated
FALSEnever evaluated
*pe != L'\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
346 return (wskipname (pe, dname, flags));
never executed: return (wskipname (pe, dname, flags));
0
347 return 1;
never executed: return 1;
0
348#else-
349 return (wskipname (pat, dname, flags));-
350#endif-
351}-
352-
353/* Return 1 if DNAME should be skipped according to PAT. Handles multibyte-
354 characters in PAT and DNAME. Mostly concerned with matching leading `.'. */-
355static int-
356mbskipname (pat, dname, flags)-
357 char *pat, *dname;-
358 int flags;-
359{-
360 int ret, ext;-
361 wchar_t *pat_wc, *dn_wc;-
362 size_t pat_n, dn_n;-
363-
364 if (mbsmbchar (dname) == 0 && mbsmbchar (pat) == 0)
mbsmbchar (dname) == 0Description
TRUEevaluated 487247 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
mbsmbchar (pat) == 0Description
TRUEevaluated 487247 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-487247
365 return (skipname (pat, dname, flags));
executed 487247 times by 1 test: return (skipname (pat, dname, flags));
Executed by:
  • Self test
487247
366-
367 ext = 0;-
368#if EXTENDED_GLOB-
369 ext = extglob_pattern_p (pat);-
370#endif-
371-
372 pat_wc = dn_wc = (wchar_t *)NULL;-
373-
374 pat_n = xdupmbstowcs (&pat_wc, NULL, pat);-
375 if (pat_n != (size_t)-1)
pat_n != (size_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
0
376 dn_n = xdupmbstowcs (&dn_wc, NULL, dname);
never executed: dn_n = xdupmbstowcs (&dn_wc, ((void *)0) , dname);
0
377-
378 ret = 0;-
379 if (pat_n != (size_t)-1 && dn_n !=(size_t)-1)
pat_n != (size_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
dn_n !=(size_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
0
380 ret = ext ? wextglob_skipname (pat_wc, dn_wc, flags) : wskipname (pat_wc, dn_wc, flags);
never executed: ret = ext ? wextglob_skipname (pat_wc, dn_wc, flags) : wskipname (pat_wc, dn_wc, flags);
extDescription
TRUEnever evaluated
FALSEnever evaluated
0
381 else-
382 ret = skipname (pat, dname, flags);
never executed: ret = skipname (pat, dname, flags);
0
383-
384 FREE (pat_wc);
never executed: sh_xfree((pat_wc), "glob.c", 384);
pat_wcDescription
TRUEnever evaluated
FALSEnever evaluated
0
385 FREE (dn_wc);
never executed: sh_xfree((dn_wc), "glob.c", 385);
dn_wcDescription
TRUEnever evaluated
FALSEnever evaluated
0
386-
387 return ret;
never executed: return ret;
0
388}-
389#endif /* HANDLE_MULTIBYTE */-
390-
391/* Remove backslashes quoting characters in PATHNAME by modifying PATHNAME. */-
392static void-
393udequote_pathname (pathname)-
394 char *pathname;-
395{-
396 register int i, j;-
397-
398 for (i = j = 0; pathname && pathname[i]; )
pathnameDescription
TRUEevaluated 423 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
pathname[i]Description
TRUEevaluated 228 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 195 times by 1 test
Evaluated by:
  • Self test
0-423
399 {-
400 if (pathname[i] == '\\')
pathname[i] == '\\'Description
TRUEnever evaluated
FALSEevaluated 228 times by 1 test
Evaluated by:
  • Self test
0-228
401 i++;
never executed: i++;
0
402-
403 pathname[j++] = pathname[i++];-
404-
405 if (pathname[i - 1] == 0)
pathname[i - 1] == 0Description
TRUEnever evaluated
FALSEevaluated 228 times by 1 test
Evaluated by:
  • Self test
0-228
406 break;
never executed: break;
0
407 }
executed 228 times by 1 test: end of block
Executed by:
  • Self test
228
408 if (pathname)
pathnameDescription
TRUEevaluated 195 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-195
409 pathname[j] = '\0';
executed 195 times by 1 test: pathname[j] = '\0';
Executed by:
  • Self test
195
410}
executed 195 times by 1 test: end of block
Executed by:
  • Self test
195
411-
412#if HANDLE_MULTIBYTE-
413/* Remove backslashes quoting characters in PATHNAME by modifying PATHNAME. */-
414static void-
415wdequote_pathname (pathname)-
416 char *pathname;-
417{-
418 mbstate_t ps;-
419 size_t len, n;-
420 wchar_t *wpathname;-
421 int i, j;-
422 wchar_t *orig_wpathname;-
423-
424 len = strlen (pathname);-
425 /* Convert the strings into wide characters. */-
426 n = xdupmbstowcs (&wpathname, NULL, pathname);-
427 if (n == (size_t) -1)
n == (size_t) -1Description
TRUEnever evaluated
FALSEevaluated 103 times by 1 test
Evaluated by:
  • Self test
0-103
428 {-
429 /* Something wrong. Fall back to single-byte */-
430 udequote_pathname (pathname);-
431 return;
never executed: return;
0
432 }-
433 orig_wpathname = wpathname;-
434-
435 for (i = j = 0; wpathname && wpathname[i]; )
wpathnameDescription
TRUEevaluated 382 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
wpathname[i]Description
TRUEevaluated 279 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 103 times by 1 test
Evaluated by:
  • Self test
0-382
436 {-
437 if (wpathname[i] == L'\\')
wpathname[i] == L'\\'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 278 times by 1 test
Evaluated by:
  • Self test
1-278
438 i++;
executed 1 time by 1 test: i++;
Executed by:
  • Self test
1
439-
440 wpathname[j++] = wpathname[i++];-
441-
442 if (wpathname[i - 1] == L'\0')
wpathname[i - 1] == L'\0'Description
TRUEnever evaluated
FALSEevaluated 279 times by 1 test
Evaluated by:
  • Self test
0-279
443 break;
never executed: break;
0
444 }
executed 279 times by 1 test: end of block
Executed by:
  • Self test
279
445 if (wpathname)
wpathnameDescription
TRUEevaluated 103 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-103
446 wpathname[j] = L'\0';
executed 103 times by 1 test: wpathname[j] = L'\0';
Executed by:
  • Self test
103
447-
448 /* Convert the wide character string into unibyte character set. */-
449 memset (&ps, '\0', sizeof(mbstate_t));-
450 n = wcsrtombs(pathname, (const wchar_t **)&wpathname, len, &ps);-
451 pathname[len] = '\0';-
452-
453 /* Can't just free wpathname here; wcsrtombs changes it in many cases. */-
454 free (orig_wpathname);-
455}
executed 103 times by 1 test: end of block
Executed by:
  • Self test
103
456-
457static void-
458dequote_pathname (pathname)-
459 char *pathname;-
460{-
461 if (MB_CUR_MAX > 1)
(__ctype_get_m...ur_max ()) > 1Description
TRUEevaluated 103 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 195 times by 1 test
Evaluated by:
  • Self test
103-195
462 wdequote_pathname (pathname);
executed 103 times by 1 test: wdequote_pathname (pathname);
Executed by:
  • Self test
103
463 else-
464 udequote_pathname (pathname);
executed 195 times by 1 test: udequote_pathname (pathname);
Executed by:
  • Self test
195
465}-
466#endif /* HANDLE_MULTIBYTE */-
467-
468/* Test whether NAME exists. */-
469-
470#if defined (HAVE_LSTAT)-
471# define GLOB_TESTNAME(name) (lstat (name, &finfo))-
472#else /* !HAVE_LSTAT */-
473# if !defined (AFS)-
474# define GLOB_TESTNAME(name) (sh_eaccess (name, F_OK))-
475# else /* AFS */-
476# define GLOB_TESTNAME(name) (access (name, F_OK))-
477# endif /* AFS */-
478#endif /* !HAVE_LSTAT */-
479-
480/* Return 0 if DIR is a directory, -1 otherwise. */-
481static int-
482glob_testdir (dir, flags)-
483 char *dir;-
484 int flags;-
485{-
486 struct stat finfo;-
487 int r;-
488-
489/*itrace("glob_testdir: testing %s" flags = %d, dir, flags);*/-
490#if defined (HAVE_LSTAT)-
491 r = (flags & GX_ALLDIRS) ? lstat (dir, &finfo) : stat (dir, &finfo);
(flags & 0x010)Description
TRUEevaluated 817 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 197 times by 1 test
Evaluated by:
  • Self test
197-817
492#else-
493 r = stat (dir, &finfo);-
494#endif-
495 if (r < 0)
r < 0Description
TRUEnever evaluated
FALSEevaluated 1014 times by 1 test
Evaluated by:
  • Self test
0-1014
496 return (-1);
never executed: return (-1);
0
497-
498 if (S_ISDIR (finfo.st_mode) == 0)
(((( finfo.st_...0040000)) == 0Description
TRUEevaluated 166 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 848 times by 1 test
Evaluated by:
  • Self test
166-848
499 return (-1);
executed 166 times by 1 test: return (-1);
Executed by:
  • Self test
166
500-
501 return (0);
executed 848 times by 1 test: return (0);
Executed by:
  • Self test
848
502}-
503-
504/* Recursively scan SDIR for directories matching PAT (PAT is always `**').-
505 FLAGS is simply passed down to the recursive call to glob_vector. Returns-
506 a list of matching directory names. EP, if non-null, is set to the last-
507 element of the returned list. NP, if non-null, is set to the number of-
508 directories in the returned list. These two variables exist for the-
509 convenience of the caller (always glob_vector). */-
510static struct globval *-
511finddirs (pat, sdir, flags, ep, np)-
512 char *pat;-
513 char *sdir;-
514 int flags;-
515 struct globval **ep;-
516 int *np;-
517{-
518 char **r, *n;-
519 int ndirs;-
520 struct globval *ret, *e, *g;-
521-
522/*itrace("finddirs: pat = `%s' sdir = `%s' flags = 0x%x", pat, sdir, flags);*/-
523 e = ret = 0;-
524 r = glob_vector (pat, sdir, flags);-
525 if (r == 0 || r[0] == 0)
r == 0Description
TRUEnever evaluated
FALSEevaluated 654 times by 1 test
Evaluated by:
  • Self test
r[0] == 0Description
TRUEevaluated 365 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 289 times by 1 test
Evaluated by:
  • Self test
0-654
526 {-
527 if (np)
npDescription
TRUEevaluated 365 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-365
528 *np = 0;
executed 365 times by 1 test: *np = 0;
Executed by:
  • Self test
365
529 if (ep)
epDescription
TRUEevaluated 365 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-365
530 *ep = 0;
executed 365 times by 1 test: *ep = 0;
Executed by:
  • Self test
365
531 if (r && r != &glob_error_return)
rDescription
TRUEevaluated 365 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
r != &glob_error_returnDescription
TRUEevaluated 365 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-365
532 free (r);
executed 365 times by 1 test: sh_xfree((r), "glob.c", 532);
Executed by:
  • Self test
365
533 return (struct globval *)0;
executed 365 times by 1 test: return (struct globval *)0;
Executed by:
  • Self test
365
534 }-
535 for (ndirs = 0; r[ndirs] != 0; ndirs++)
r[ndirs] != 0Description
TRUEevaluated 1308 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 289 times by 1 test
Evaluated by:
  • Self test
289-1308
536 {-
537 g = (struct globval *) malloc (sizeof (struct globval));-
538 if (g == 0)
g == 0Description
TRUEnever evaluated
FALSEevaluated 1308 times by 1 test
Evaluated by:
  • Self test
0-1308
539 {-
540 while (ret) /* free list built so far */
retDescription
TRUEnever evaluated
FALSEnever evaluated
0
541 {-
542 g = ret->next;-
543 free (ret);-
544 ret = g;-
545 }
never executed: end of block
0
546-
547 free (r);-
548 if (np)
npDescription
TRUEnever evaluated
FALSEnever evaluated
0
549 *np = 0;
never executed: *np = 0;
0
550 if (ep)
epDescription
TRUEnever evaluated
FALSEnever evaluated
0
551 *ep = 0;
never executed: *ep = 0;
0
552 return (&finddirs_error_return);
never executed: return (&finddirs_error_return);
0
553 }-
554 if (e == 0)
e == 0Description
TRUEevaluated 289 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1019 times by 1 test
Evaluated by:
  • Self test
289-1019
555 e = g;
executed 289 times by 1 test: e = g;
Executed by:
  • Self test
289
556-
557 g->next = ret;-
558 ret = g;-
559-
560 g->name = r[ndirs];-
561 }
executed 1308 times by 1 test: end of block
Executed by:
  • Self test
1308
562-
563 free (r);-
564 if (ep)
epDescription
TRUEevaluated 289 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-289
565 *ep = e;
executed 289 times by 1 test: *ep = e;
Executed by:
  • Self test
289
566 if (np)
npDescription
TRUEevaluated 289 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-289
567 *np = ndirs;
executed 289 times by 1 test: *np = ndirs;
Executed by:
  • Self test
289
568-
569 return ret;
executed 289 times by 1 test: return ret;
Executed by:
  • Self test
289
570}-
571 -
572/* Return a vector of names of files in directory DIR-
573 whose names match glob pattern PAT.-
574 The names are not in any particular order.-
575 Wildcards at the beginning of PAT do not match an initial period.-
576-
577 The vector is terminated by an element that is a null pointer.-
578-
579 To free the space allocated, first free the vector's elements,-
580 then free the vector.-
581-
582 Return 0 if cannot get enough memory to hold the pointer-
583 and the names.-
584-
585 Return -1 if cannot access directory DIR.-
586 Look in errno for more information. */-
587-
588char **-
589glob_vector (pat, dir, flags)-
590 char *pat;-
591 char *dir;-
592 int flags;-
593{-
594 DIR *d;-
595 register struct dirent *dp;-
596 struct globval *lastlink, *e, *dirlist;-
597 register struct globval *nextlink;-
598 register char *nextname, *npat, *subdir;-
599 unsigned int count;-
600 int lose, skip, ndirs, isdir, sdlen, add_current, patlen;-
601 register char **name_vector;-
602 register unsigned int i;-
603 int mflags; /* Flags passed to strmatch (). */-
604 int pflags; /* flags passed to sh_makepath () */-
605 int nalloca;-
606 struct globval *firstmalloc, *tmplink;-
607 char *convfn;-
608-
609 lastlink = 0;-
610 count = lose = skip = add_current = 0;-
611-
612 firstmalloc = 0;-
613 nalloca = 0;-
614-
615/*itrace("glob_vector: pat = `%s' dir = `%s' flags = 0x%x", pat, dir, flags);*/-
616 /* If PAT is empty, skip the loop, but return one (empty) filename. */-
617 if (pat == 0 || *pat == '\0')
pat == 0Description
TRUEnever evaluated
FALSEevaluated 1896 times by 1 test
Evaluated by:
  • Self test
*pat == '\0'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1890 times by 1 test
Evaluated by:
  • Self test
0-1896
618 {-
619 if (glob_testdir (dir, 0) < 0)
glob_testdir (dir, 0) < 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3
620 return ((char **) &glob_error_return);
executed 3 times by 1 test: return ((char **) &glob_error_return);
Executed by:
  • Self test
3
621-
622 nextlink = (struct globval *)alloca (sizeof (struct globval));-
623 if (nextlink == NULL)
nextlink == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
624 return ((char **) NULL);
never executed: return ((char **) ((void *)0) );
0
625-
626 nextlink->next = (struct globval *)0;-
627 nextname = (char *) malloc (1);-
628 if (nextname == 0)
nextname == 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
629 lose = 1;
never executed: lose = 1;
0
630 else-
631 {-
632 lastlink = nextlink;-
633 nextlink->name = nextname;-
634 nextname[0] = '\0';-
635 count = 1;-
636 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
637-
638 skip = 1;-
639 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
640-
641 patlen = (pat && *pat) ? strlen (pat) : 0;
patDescription
TRUEevaluated 1893 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*patDescription
TRUEevaluated 1890 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-1893
642-
643 /* If the filename pattern (PAT) does not contain any globbing characters,-
644 we can dispense with reading the directory, and just see if there is-
645 a filename `DIR/PAT'. If there is, and we can access it, just make the-
646 vector to return and bail immediately. */-
647 if (skip == 0 && glob_pattern_p (pat) == 0)
skip == 0Description
TRUEevaluated 1890 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
glob_pattern_p (pat) == 0Description
TRUEevaluated 191 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1699 times by 1 test
Evaluated by:
  • Self test
3-1890
648 {-
649 int dirlen;-
650 struct stat finfo;-
651-
652 if (glob_testdir (dir, 0) < 0)
glob_testdir (dir, 0) < 0Description
TRUEnever evaluated
FALSEevaluated 191 times by 1 test
Evaluated by:
  • Self test
0-191
653 return ((char **) &glob_error_return);
never executed: return ((char **) &glob_error_return);
0
654-
655 dirlen = strlen (dir);-
656 nextname = (char *)malloc (dirlen + patlen + 2);-
657 npat = (char *)malloc (patlen + 1);-
658 if (nextname == 0 || npat == 0)
nextname == 0Description
TRUEnever evaluated
FALSEevaluated 191 times by 1 test
Evaluated by:
  • Self test
npat == 0Description
TRUEnever evaluated
FALSEevaluated 191 times by 1 test
Evaluated by:
  • Self test
0-191
659 {-
660 FREE (nextname);
never executed: sh_xfree((nextname), "glob.c", 660);
nextnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
661 FREE (npat);
never executed: sh_xfree((npat), "glob.c", 661);
npatDescription
TRUEnever evaluated
FALSEnever evaluated
0
662 lose = 1;-
663 }
never executed: end of block
0
664 else-
665 {-
666 strcpy (npat, pat);-
667 dequote_pathname (npat);-
668-
669 strcpy (nextname, dir);-
670 nextname[dirlen++] = '/';-
671 strcpy (nextname + dirlen, npat);-
672-
673 if (GLOB_TESTNAME (nextname) >= 0)
(lstat (nextna... &finfo)) >= 0Description
TRUEevaluated 95 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 96 times by 1 test
Evaluated by:
  • Self test
95-96
674 {-
675 free (nextname);-
676 nextlink = (struct globval *)alloca (sizeof (struct globval));-
677 if (nextlink)
nextlinkDescription
TRUEevaluated 95 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-95
678 {-
679 nextlink->next = (struct globval *)0;-
680 lastlink = nextlink;-
681 nextlink->name = npat;-
682 count = 1;-
683 }
executed 95 times by 1 test: end of block
Executed by:
  • Self test
95
684 else-
685 {-
686 free (npat);-
687 lose = 1;-
688 }
never executed: end of block
0
689 }-
690 else-
691 {-
692 free (nextname);-
693 free (npat);-
694 }
executed 96 times by 1 test: end of block
Executed by:
  • Self test
96
695 }-
696-
697 skip = 1;-
698 }
executed 191 times by 1 test: end of block
Executed by:
  • Self test
191
699-
700 if (skip == 0)
skip == 0Description
TRUEevaluated 1699 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 194 times by 1 test
Evaluated by:
  • Self test
194-1699
701 {-
702 /* Open the directory, punting immediately if we cannot. If opendir-
703 is not robust (i.e., it opens non-directories successfully), test-
704 that DIR is a directory and punt if it's not. */-
705#if defined (OPENDIR_NOT_ROBUST)-
706 if (glob_testdir (dir, 0) < 0)-
707 return ((char **) &glob_error_return);-
708#endif-
709-
710 d = opendir (dir);-
711 if (d == NULL)
d == ((void *)0)Description
TRUEevaluated 167 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1532 times by 1 test
Evaluated by:
  • Self test
167-1532
712 return ((char **) &glob_error_return);
executed 167 times by 1 test: return ((char **) &glob_error_return);
Executed by:
  • Self test
167
713-
714 /* Compute the flags that will be passed to strmatch(). We don't-
715 need to do this every time through the loop. */-
716 mflags = (noglob_dot_filenames ? FNM_PERIOD : 0) | FNM_PATHNAME;
noglob_dot_filenamesDescription
TRUEevaluated 1526 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-1526
717-
718#ifdef FNM_CASEFOLD-
719 if (glob_ignore_case)
glob_ignore_caseDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1530 times by 1 test
Evaluated by:
  • Self test
2-1530
720 mflags |= FNM_CASEFOLD;
executed 2 times by 1 test: mflags |= (1 << 4);
Executed by:
  • Self test
2
721#endif-
722-
723 if (extended_glob)
extended_globDescription
TRUEevaluated 66 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1466 times by 1 test
Evaluated by:
  • Self test
66-1466
724 mflags |= FNM_EXTMATCH;
executed 66 times by 1 test: mflags |= (1 << 5);
Executed by:
  • Self test
66
725-
726 add_current = ((flags & (GX_ALLDIRS|GX_ADDCURDIR)) == (GX_ALLDIRS|GX_ADDCURDIR));-
727-
728 /* Scan the directory, finding all names that match.-
729 For each name that matches, allocate a struct globval-
730 on the stack and store the name in it.-
731 Chain those structs together; lastlink is the front of the chain. */-
732 while (1)-
733 {-
734 /* Make globbing interruptible in the shell. */-
735 if (interrupt_state || terminating_signal)
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 501789 times by 1 test
Evaluated by:
  • Self test
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 501789 times by 1 test
Evaluated by:
  • Self test
0-501789
736 {-
737 lose = 1;-
738 break;
never executed: break;
0
739 }-
740 else if (signal_is_pending (SIGINT)) /* XXX - make SIGINT traps responsive */
signal_is_pending ( 2 )Description
TRUEnever evaluated
FALSEevaluated 501789 times by 1 test
Evaluated by:
  • Self test
0-501789
741 {-
742 lose = 1;-
743 break;
never executed: break;
0
744 }-
745-
746 dp = readdir (d);-
747 if (dp == NULL)
dp == ((void *)0)Description
TRUEevaluated 1532 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 500257 times by 1 test
Evaluated by:
  • Self test
1532-500257
748 break;
executed 1532 times by 1 test: break;
Executed by:
  • Self test
1532
749-
750 /* If this directory entry is not to be used, try again. */-
751 if (REAL_DIR_ENTRY (dp) == 0)
(dp->d_ino != 0) == 0Description
TRUEnever evaluated
FALSEevaluated 500257 times by 1 test
Evaluated by:
  • Self test
0-500257
752 continue;
never executed: continue;
0
753-
754#if 0-
755 if (dp->d_name == 0 || *dp->d_name == 0)-
756 continue;-
757#endif-
758-
759#if HANDLE_MULTIBYTE-
760 if (MB_CUR_MAX > 1 && mbskipname (pat, dp->d_name, flags))
(__ctype_get_m...ur_max ()) > 1Description
TRUEevaluated 484860 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15397 times by 1 test
Evaluated by:
  • Self test
mbskipname (pa...d_name, flags)Description
TRUEevaluated 1439 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 483421 times by 1 test
Evaluated by:
  • Self test
1439-484860
761 continue;
executed 1439 times by 1 test: continue;
Executed by:
  • Self test
1439
762 else-
763#endif-
764 if (skipname (pat, dp->d_name, flags))
skipname (pat,...d_name, flags)Description
TRUEevaluated 1666 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 497152 times by 1 test
Evaluated by:
  • Self test
1666-497152
765 continue;
executed 1666 times by 1 test: continue;
Executed by:
  • Self test
1666
766-
767 /* If we're only interested in directories, don't bother with files */-
768 if (flags & (GX_MATCHDIRS|GX_ALLDIRS))
flags & (0x008|0x010)Description
TRUEevaluated 817 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 496335 times by 1 test
Evaluated by:
  • Self test
817-496335
769 {-
770 pflags = (flags & GX_ALLDIRS) ? MP_RMDOT : 0;
(flags & 0x010)Description
TRUEevaluated 817 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-817
771 if (flags & GX_NULLDIR)
flags & 0x100Description
TRUEevaluated 579 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 238 times by 1 test
Evaluated by:
  • Self test
238-579
772 pflags |= MP_IGNDOT;
executed 579 times by 1 test: pflags |= 0x08;
Executed by:
  • Self test
579
773 subdir = sh_makepath (dir, dp->d_name, pflags);-
774 isdir = glob_testdir (subdir, flags);-
775 if (isdir < 0 && (flags & GX_MATCHDIRS))
isdir < 0Description
TRUEevaluated 163 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 654 times by 1 test
Evaluated by:
  • Self test
(flags & 0x008)Description
TRUEnever evaluated
FALSEevaluated 163 times by 1 test
Evaluated by:
  • Self test
0-654
776 {-
777 free (subdir);-
778 continue;
never executed: continue;
0
779 }-
780 }
executed 817 times by 1 test: end of block
Executed by:
  • Self test
817
781-
782 if (flags & GX_ALLDIRS)
flags & 0x010Description
TRUEevaluated 817 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 496335 times by 1 test
Evaluated by:
  • Self test
817-496335
783 {-
784 if (isdir == 0)
isdir == 0Description
TRUEevaluated 654 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 163 times by 1 test
Evaluated by:
  • Self test
163-654
785 {-
786 dirlist = finddirs (pat, subdir, (flags & ~GX_ADDCURDIR), &e, &ndirs);-
787 if (dirlist == &finddirs_error_return)
dirlist == &fi...s_error_returnDescription
TRUEnever evaluated
FALSEevaluated 654 times by 1 test
Evaluated by:
  • Self test
0-654
788 {-
789 free (subdir);-
790 lose = 1;-
791 break;
never executed: break;
0
792 }-
793 if (ndirs) /* add recursive directories to list */
ndirsDescription
TRUEevaluated 289 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 365 times by 1 test
Evaluated by:
  • Self test
289-365
794 {-
795 if (firstmalloc == 0)
firstmalloc == 0Description
TRUEevaluated 144 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 145 times by 1 test
Evaluated by:
  • Self test
144-145
796 firstmalloc = e;
executed 144 times by 1 test: firstmalloc = e;
Executed by:
  • Self test
144
797 e->next = lastlink;-
798 lastlink = dirlist;-
799 count += ndirs;-
800 }
executed 289 times by 1 test: end of block
Executed by:
  • Self test
289
801 }
executed 654 times by 1 test: end of block
Executed by:
  • Self test
654
802-
803 nextlink = (struct globval *) malloc (sizeof (struct globval));-
804 if (firstmalloc == 0)
firstmalloc == 0Description
TRUEevaluated 203 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 614 times by 1 test
Evaluated by:
  • Self test
203-614
805 firstmalloc = nextlink;
executed 203 times by 1 test: firstmalloc = nextlink;
Executed by:
  • Self test
203
806 sdlen = strlen (subdir);-
807 nextname = (char *) malloc (sdlen + 1);-
808 if (nextlink == 0 || nextname == 0)
nextlink == 0Description
TRUEnever evaluated
FALSEevaluated 817 times by 1 test
Evaluated by:
  • Self test
nextname == 0Description
TRUEnever evaluated
FALSEevaluated 817 times by 1 test
Evaluated by:
  • Self test
0-817
809 {-
810 FREE (nextlink);
never executed: sh_xfree((nextlink), "glob.c", 810);
nextlinkDescription
TRUEnever evaluated
FALSEnever evaluated
0
811 FREE (nextname);
never executed: sh_xfree((nextname), "glob.c", 811);
nextnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
812 free (subdir);-
813 lose = 1;-
814 break;
never executed: break;
0
815 }-
816 nextlink->next = lastlink;-
817 lastlink = nextlink;-
818 nextlink->name = nextname;-
819 bcopy (subdir, nextname, sdlen + 1);-
820 free (subdir);-
821 ++count;-
822 continue;
executed 817 times by 1 test: continue;
Executed by:
  • Self test
817
823 }-
824 else if (flags & GX_MATCHDIRS)
flags & 0x008Description
TRUEnever evaluated
FALSEevaluated 496335 times by 1 test
Evaluated by:
  • Self test
0-496335
825 free (subdir);
never executed: sh_xfree((subdir), "glob.c", 825);
0
826-
827 convfn = fnx_fromfs (dp->d_name, D_NAMLEN (dp));-
828 if (strmatch (pat, convfn, mflags) != FNM_NOMATCH)
strmatch (pat,..., mflags) != 1Description
TRUEevaluated 986 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 495349 times by 1 test
Evaluated by:
  • Self test
986-495349
829 {-
830 if (nalloca < ALLOCA_MAX)
nalloca < 100000Description
TRUEevaluated 986 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-986
831 {-
832 nextlink = (struct globval *) alloca (sizeof (struct globval));-
833 nalloca += sizeof (struct globval);-
834 }
executed 986 times by 1 test: end of block
Executed by:
  • Self test
986
835 else-
836 {-
837 nextlink = (struct globval *) malloc (sizeof (struct globval));-
838 if (firstmalloc == 0)
firstmalloc == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
839 firstmalloc = nextlink;
never executed: firstmalloc = nextlink;
0
840 }
never executed: end of block
0
841-
842 nextname = (char *) malloc (D_NAMLEN (dp) + 1);-
843 if (nextlink == 0 || nextname == 0)
nextlink == 0Description
TRUEnever evaluated
FALSEevaluated 986 times by 1 test
Evaluated by:
  • Self test
nextname == 0Description
TRUEnever evaluated
FALSEevaluated 986 times by 1 test
Evaluated by:
  • Self test
0-986
844 {-
845 FREE (nextlink);
never executed: sh_xfree((nextlink), "glob.c", 845);
nextlinkDescription
TRUEnever evaluated
FALSEnever evaluated
0
846 FREE (nextname);
never executed: sh_xfree((nextname), "glob.c", 846);
nextnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
847 lose = 1;-
848 break;
never executed: break;
0
849 }-
850 nextlink->next = lastlink;-
851 lastlink = nextlink;-
852 nextlink->name = nextname;-
853 bcopy (dp->d_name, nextname, D_NAMLEN (dp) + 1);-
854 ++count;-
855 }
executed 986 times by 1 test: end of block
Executed by:
  • Self test
986
856 }
executed 496335 times by 1 test: end of block
Executed by:
  • Self test
496335
857-
858 (void) closedir (d);-
859 }
executed 1532 times by 1 test: end of block
Executed by:
  • Self test
1532
860-
861 /* compat: if GX_ADDCURDIR, add the passed directory also. Add an empty-
862 directory name as a placeholder if GX_NULLDIR (in which case the passed-
863 directory name is "."). */-
864 if (add_current)
add_currentDescription
TRUEevaluated 81 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1645 times by 1 test
Evaluated by:
  • Self test
81-1645
865 {-
866 sdlen = strlen (dir);-
867 nextname = (char *)malloc (sdlen + 1);-
868 nextlink = (struct globval *) malloc (sizeof (struct globval));-
869 if (nextlink == 0 || nextname == 0)
nextlink == 0Description
TRUEnever evaluated
FALSEevaluated 81 times by 1 test
Evaluated by:
  • Self test
nextname == 0Description
TRUEnever evaluated
FALSEevaluated 81 times by 1 test
Evaluated by:
  • Self test
0-81
870 {-
871 FREE (nextlink);
never executed: sh_xfree((nextlink), "glob.c", 871);
nextlinkDescription
TRUEnever evaluated
FALSEnever evaluated
0
872 FREE (nextname);
never executed: sh_xfree((nextname), "glob.c", 872);
nextnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
873 lose = 1;-
874 }
never executed: end of block
0
875 else-
876 {-
877 nextlink->name = nextname;-
878 nextlink->next = lastlink;-
879 lastlink = nextlink;-
880 if (flags & GX_NULLDIR)
flags & 0x100Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 66 times by 1 test
Evaluated by:
  • Self test
15-66
881 nextname[0] = '\0';
executed 15 times by 1 test: nextname[0] = '\0';
Executed by:
  • Self test
15
882 else-
883 bcopy (dir, nextname, sdlen + 1);
executed 66 times by 1 test: bcopy (dir, nextname, sdlen + 1);
Executed by:
  • Self test
66
884 ++count;-
885 }
executed 81 times by 1 test: end of block
Executed by:
  • Self test
81
886 }-
887-
888 if (lose == 0)
lose == 0Description
TRUEevaluated 1726 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1726
889 {-
890 name_vector = (char **) malloc ((count + 1) * sizeof (char *));-
891 lose |= name_vector == NULL;-
892 }
executed 1726 times by 1 test: end of block
Executed by:
  • Self test
1726
893-
894 /* Have we run out of memory? */-
895 if (lose)
loseDescription
TRUEnever evaluated
FALSEevaluated 1726 times by 1 test
Evaluated by:
  • Self test
0-1726
896 {-
897 tmplink = 0;-
898-
899 /* Here free the strings we have got. */-
900 while (lastlink)
lastlinkDescription
TRUEnever evaluated
FALSEnever evaluated
0
901 {-
902 /* Since we build the list in reverse order, the first N entries-
903 will be allocated with malloc, if firstmalloc is set, from-
904 lastlink to firstmalloc. */-
905 if (firstmalloc)
firstmallocDescription
TRUEnever evaluated
FALSEnever evaluated
0
906 {-
907 if (lastlink == firstmalloc)
lastlink == firstmallocDescription
TRUEnever evaluated
FALSEnever evaluated
0
908 firstmalloc = 0;
never executed: firstmalloc = 0;
0
909 tmplink = lastlink;-
910 }
never executed: end of block
0
911 else-
912 tmplink = 0;
never executed: tmplink = 0;
0
913 free (lastlink->name);-
914 lastlink = lastlink->next;-
915 FREE (tmplink);
never executed: sh_xfree((tmplink), "glob.c", 915);
tmplinkDescription
TRUEnever evaluated
FALSEnever evaluated
0
916 }
never executed: end of block
0
917-
918 /* Don't call QUIT; here; let higher layers deal with it. */-
919-
920 return ((char **)NULL);
never executed: return ((char **) ((void *)0) );
0
921 }-
922-
923 /* Copy the name pointers from the linked list into the vector. */-
924 for (tmplink = lastlink, i = 0; i < count; ++i)
i < countDescription
TRUEevaluated 3290 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1726 times by 1 test
Evaluated by:
  • Self test
1726-3290
925 {-
926 name_vector[i] = tmplink->name;-
927 tmplink = tmplink->next;-
928 }
executed 3290 times by 1 test: end of block
Executed by:
  • Self test
3290
929-
930 name_vector[count] = NULL;-
931-
932 /* If we allocated some of the struct globvals, free them now. */-
933 if (firstmalloc)
firstmallocDescription
TRUEevaluated 347 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1379 times by 1 test
Evaluated by:
  • Self test
347-1379
934 {-
935 tmplink = 0;-
936 while (lastlink)
lastlinkDescription
TRUEevaluated 2174 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 347 times by 1 test
Evaluated by:
  • Self test
347-2174
937 {-
938 tmplink = lastlink;-
939 if (lastlink == firstmalloc)
lastlink == firstmallocDescription
TRUEevaluated 347 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1827 times by 1 test
Evaluated by:
  • Self test
347-1827
940 lastlink = firstmalloc = 0;
executed 347 times by 1 test: lastlink = firstmalloc = 0;
Executed by:
  • Self test
347
941 else-
942 lastlink = lastlink->next;
executed 1827 times by 1 test: lastlink = lastlink->next;
Executed by:
  • Self test
1827
943 free (tmplink);-
944 }
executed 2174 times by 1 test: end of block
Executed by:
  • Self test
2174
945 }
executed 347 times by 1 test: end of block
Executed by:
  • Self test
347
946-
947 return (name_vector);
executed 1726 times by 1 test: return (name_vector);
Executed by:
  • Self test
1726
948}-
949-
950/* Return a new array which is the concatenation of each string in ARRAY-
951 to DIR. This function expects you to pass in an allocated ARRAY, and-
952 it takes care of free()ing that array. Thus, you might think of this-
953 function as side-effecting ARRAY. This should handle GX_MARKDIRS. */-
954static char **-
955glob_dir_to_array (dir, array, flags)-
956 char *dir, **array;-
957 int flags;-
958{-
959 register unsigned int i, l;-
960 int add_slash;-
961 char **result, *new;-
962 struct stat sb;-
963-
964 l = strlen (dir);-
965 if (l == 0)
l == 0Description
TRUEevaluated 716 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 293 times by 1 test
Evaluated by:
  • Self test
293-716
966 {-
967 if (flags & GX_MARKDIRS)
flags & 0x001Description
TRUEnever evaluated
FALSEevaluated 716 times by 1 test
Evaluated by:
  • Self test
0-716
968 for (i = 0; array[i]; i++)
array[i]Description
TRUEnever evaluated
FALSEnever evaluated
0
969 {-
970 if ((stat (array[i], &sb) == 0) && S_ISDIR (sb.st_mode))
(stat (array[i], &sb) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
(((( sb.st_mod... == (0040000))Description
TRUEnever evaluated
FALSEnever evaluated
0
971 {-
972 l = strlen (array[i]);-
973 new = (char *)realloc (array[i], l + 2);-
974 if (new == 0)
new == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
975 return NULL;
never executed: return ((void *)0) ;
0
976 new[l] = '/';-
977 new[l+1] = '\0';-
978 array[i] = new;-
979 }
never executed: end of block
0
980 }
never executed: end of block
0
981 return (array);
executed 716 times by 1 test: return (array);
Executed by:
  • Self test
716
982 }-
983-
984 add_slash = dir[l - 1] != '/';-
985-
986 i = 0;-
987 while (array[i] != NULL)
array[i] != ((void *)0)Description
TRUEevaluated 221 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 293 times by 1 test
Evaluated by:
  • Self test
221-293
988 ++i;
executed 221 times by 1 test: ++i;
Executed by:
  • Self test
221
989-
990 result = (char **) malloc ((i + 1) * sizeof (char *));-
991 if (result == NULL)
result == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 293 times by 1 test
Evaluated by:
  • Self test
0-293
992 return (NULL);
never executed: return ( ((void *)0) );
0
993-
994 for (i = 0; array[i] != NULL; i++)
array[i] != ((void *)0)Description
TRUEevaluated 221 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 293 times by 1 test
Evaluated by:
  • Self test
221-293
995 {-
996 /* 3 == 1 for NUL, 1 for slash at end of DIR, 1 for GX_MARKDIRS */-
997 result[i] = (char *) malloc (l + strlen (array[i]) + 3);-
998-
999 if (result[i] == NULL)
result[i] == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • Self test
0-221
1000 {-
1001 int ind;-
1002 for (ind = 0; ind < i; ind++)
ind < iDescription
TRUEnever evaluated
FALSEnever evaluated
0
1003 free (result[ind]);
never executed: sh_xfree((result[ind]), "glob.c", 1003);
0
1004 free (result);-
1005 return (NULL);
never executed: return ( ((void *)0) );
0
1006 }-
1007-
1008 strcpy (result[i], dir);-
1009 if (add_slash)
add_slashDescription
TRUEevaluated 148 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 73 times by 1 test
Evaluated by:
  • Self test
73-148
1010 result[i][l] = '/';
executed 148 times by 1 test: result[i][l] = '/';
Executed by:
  • Self test
148
1011 strcpy (result[i] + l + add_slash, array[i]);-
1012 if (flags & GX_MARKDIRS)
flags & 0x001Description
TRUEnever evaluated
FALSEevaluated 221 times by 1 test
Evaluated by:
  • Self test
0-221
1013 {-
1014 if ((stat (result[i], &sb) == 0) && S_ISDIR (sb.st_mode))
(stat (result[i], &sb) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
(((( sb.st_mod... == (0040000))Description
TRUEnever evaluated
FALSEnever evaluated
0
1015 {-
1016 size_t rlen;-
1017 rlen = strlen (result[i]);-
1018 result[i][rlen] = '/';-
1019 result[i][rlen+1] = '\0';-
1020 }
never executed: end of block
0
1021 }
never executed: end of block
0
1022 }
executed 221 times by 1 test: end of block
Executed by:
  • Self test
221
1023 result[i] = NULL;-
1024-
1025 /* Free the input array. */-
1026 for (i = 0; array[i] != NULL; i++)
array[i] != ((void *)0)Description
TRUEevaluated 221 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 293 times by 1 test
Evaluated by:
  • Self test
221-293
1027 free (array[i]);
executed 221 times by 1 test: sh_xfree((array[i]), "glob.c", 1027);
Executed by:
  • Self test
221
1028 free ((char *) array);-
1029-
1030 return (result);
executed 293 times by 1 test: return (result);
Executed by:
  • Self test
293
1031}-
1032-
1033/* Do globbing on PATHNAME. Return an array of pathnames that match,-
1034 marking the end of the array with a null-pointer as an element.-
1035 If no pathnames match, then the array is empty (first element is null).-
1036 If there isn't enough memory, then return NULL.-
1037 If a file system error occurs, return -1; `errno' has the error code. */-
1038char **-
1039glob_filename (pathname, flags)-
1040 char *pathname;-
1041 int flags;-
1042{-
1043 char **result, **new_result;-
1044 unsigned int result_size;-
1045 char *directory_name, *filename, *dname, *fn;-
1046 unsigned int directory_len;-
1047 int free_dirname; /* flag */-
1048 int dflags;-
1049-
1050 result = (char **) malloc (sizeof (char *));-
1051 result_size = 1;-
1052 if (result == NULL)
result == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 952 times by 1 test
Evaluated by:
  • Self test
0-952
1053 return (NULL);
never executed: return ( ((void *)0) );
0
1054-
1055 result[0] = NULL;-
1056-
1057 directory_name = NULL;-
1058-
1059 /* Find the filename. */-
1060 filename = strrchr (pathname, '/');-
1061#if defined (EXTENDED_GLOB)-
1062 if (filename && extended_glob)
filenameDescription
TRUEevaluated 254 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 698 times by 1 test
Evaluated by:
  • Self test
extended_globDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 252 times by 1 test
Evaluated by:
  • Self test
2-698
1063 {-
1064 fn = glob_dirscan (pathname, '/');-
1065#if DEBUG_MATCHING-
1066 if (fn != filename)-
1067 fprintf (stderr, "glob_filename: glob_dirscan: fn (%s) != filename (%s)\n", fn ? fn : "(null)", filename);-
1068#endif-
1069 filename = fn;-
1070 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
1071#endif-
1072-
1073 if (filename == NULL)
filename == ((void *)0)Description
TRUEevaluated 698 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 254 times by 1 test
Evaluated by:
  • Self test
254-698
1074 {-
1075 filename = pathname;-
1076 directory_name = "";-
1077 directory_len = 0;-
1078 free_dirname = 0;-
1079 }
executed 698 times by 1 test: end of block
Executed by:
  • Self test
698
1080 else-
1081 {-
1082 directory_len = (filename - pathname) + 1;-
1083 directory_name = (char *) malloc (directory_len + 1);-
1084-
1085 if (directory_name == 0) /* allocation failed? */
directory_name == 0Description
TRUEnever evaluated
FALSEevaluated 254 times by 1 test
Evaluated by:
  • Self test
0-254
1086 {-
1087 free (result);-
1088 return (NULL);
never executed: return ( ((void *)0) );
0
1089 }-
1090-
1091 bcopy (pathname, directory_name, directory_len);-
1092 directory_name[directory_len] = '\0';-
1093 ++filename;-
1094 free_dirname = 1;-
1095 }
executed 254 times by 1 test: end of block
Executed by:
  • Self test
254
1096-
1097 /* If directory_name contains globbing characters, then we-
1098 have to expand the previous levels. Just recurse. */-
1099 if (directory_len > 0 && glob_pattern_p (directory_name))
directory_len > 0Description
TRUEevaluated 254 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 698 times by 1 test
Evaluated by:
  • Self test
glob_pattern_p...irectory_name)Description
TRUEevaluated 147 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107 times by 1 test
Evaluated by:
  • Self test
107-698
1100 {-
1101 char **directories, *d, *p;-
1102 register unsigned int i;-
1103 int all_starstar, last_starstar;-
1104-
1105 all_starstar = last_starstar = 0;-
1106 d = directory_name;-
1107 dflags = flags & ~GX_MARKDIRS;-
1108 /* Collapse a sequence of ** patterns separated by one or more slashes-
1109 to a single ** terminated by a slash or NUL */-
1110 if ((flags & GX_GLOBSTAR) && d[0] == '*' && d[1] == '*' && (d[2] == '/' || d[2] == '\0'))
(flags & 0x400)Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 122 times by 1 test
Evaluated by:
  • Self test
d[0] == '*'Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
d[1] == '*'Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
d[2] == '/'Description
TRUEevaluated 21 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
d[2] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-122
1111 {-
1112 p = d;-
1113 while (d[0] == '*' && d[1] == '*' && (d[2] == '/' || d[2] == '\0'))
d[0] == '*'Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
d[1] == '*'Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
d[2] == '/'Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
d[2] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-28
1114 {-
1115 p = d;-
1116 if (d[2])
d[2]Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-28
1117 {-
1118 d += 3;-
1119 while (*d == '/')
*d == '/'Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
0-28
1120 d++;
never executed: d++;
0
1121 if (*d == 0)
*d == 0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
13-15
1122 break;
executed 15 times by 1 test: break;
Executed by:
  • Self test
15
1123 }
executed 13 times by 1 test: end of block
Executed by:
  • Self test
13
1124 }
executed 13 times by 1 test: end of block
Executed by:
  • Self test
13
1125 if (*d == 0)
*d == 0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-15
1126 all_starstar = 1;
executed 15 times by 1 test: all_starstar = 1;
Executed by:
  • Self test
15
1127 d = p;-
1128 dflags |= GX_ALLDIRS|GX_ADDCURDIR;-
1129 directory_len = strlen (d);-
1130 }
executed 21 times by 1 test: end of block
Executed by:
  • Self test
21
1131-
1132 /* If there is a non [star][star]/ component in directory_name, we-
1133 still need to collapse trailing sequences of [star][star]/ into-
1134 a single one and note that the directory name ends with [star][star],-
1135 so we can compensate if filename is [star][star] */-
1136 if ((flags & GX_GLOBSTAR) && all_starstar == 0)
(flags & 0x400)Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 122 times by 1 test
Evaluated by:
  • Self test
all_starstar == 0Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
10-122
1137 {-
1138 int dl, prev;-
1139 prev = dl = directory_len;-
1140 while (dl >= 4 && d[dl - 1] == '/' &&
dl >= 4Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
d[dl - 1] == '/'Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-17
1141 d[dl - 2] == '*' &&
d[dl - 2] == '*'Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-12
1142 d[dl - 3] == '*' &&
d[dl - 3] == '*'Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-10
1143 d[dl - 4] == '/')
d[dl - 4] == '/'Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-10
1144 prev = dl, dl -= 3;
executed 10 times by 1 test: prev = dl, dl -= 3;
Executed by:
  • Self test
10
1145 if (dl != directory_len)
dl != directory_lenDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-6
1146 last_starstar = 1;
executed 6 times by 1 test: last_starstar = 1;
Executed by:
  • Self test
6
1147 directory_len = prev;-
1148 }
executed 10 times by 1 test: end of block
Executed by:
  • Self test
10
1149-
1150 /* If the directory name ends in [star][star]/ but the filename is-
1151 [star][star], just remove the final [star][star] from the directory-
1152 so we don't have to scan everything twice. */-
1153 if (last_starstar && directory_len > 4 &&
last_starstarDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 141 times by 1 test
Evaluated by:
  • Self test
directory_len > 4Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-141
1154 filename[0] == '*' && filename[1] == '*' && filename[2] == 0)
filename[0] == '*'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
filename[1] == '*'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
filename[2] == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
1155 {-
1156 directory_len -= 3;-
1157 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
1158-
1159 if (d[directory_len - 1] == '/')
d[directory_len - 1] == '/'Description
TRUEevaluated 147 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-147
1160 d[directory_len - 1] = '\0';
executed 147 times by 1 test: d[directory_len - 1] = '\0';
Executed by:
  • Self test
147
1161-
1162 directories = glob_filename (d, dflags);-
1163-
1164 if (free_dirname)
free_dirnameDescription
TRUEevaluated 147 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-147
1165 {-
1166 free (directory_name);-
1167 directory_name = NULL;-
1168 }
executed 147 times by 1 test: end of block
Executed by:
  • Self test
147
1169-
1170 if (directories == NULL)
directories == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 147 times by 1 test
Evaluated by:
  • Self test
0-147
1171 goto memory_error;
never executed: goto memory_error;
0
1172 else if (directories == (char **)&glob_error_return)
directories ==...b_error_returnDescription
TRUEevaluated 112 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test
35-112
1173 {-
1174 free ((char *) result);-
1175 return ((char **) &glob_error_return);
executed 112 times by 1 test: return ((char **) &glob_error_return);
Executed by:
  • Self test
112
1176 }-
1177 else if (*directories == NULL)
*directories == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 34 times by 1 test
Evaluated by:
  • Self test
1-34
1178 {-
1179 free ((char *) directories);-
1180 free ((char *) result);-
1181 return ((char **) &glob_error_return);
executed 1 time by 1 test: return ((char **) &glob_error_return);
Executed by:
  • Self test
1
1182 }-
1183-
1184 /* If we have something like [star][star]/[star][star], it's no use to-
1185 glob **, then do it again, and throw half the results away. */-
1186 if (all_starstar && filename[0] == '*' && filename[1] == '*' && filename[2] == 0)
all_starstarDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
filename[0] == '*'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
filename[1] == '*'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
filename[2] == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-19
1187 {-
1188 free ((char *) directories);-
1189 free (directory_name);-
1190 directory_name = NULL;-
1191 directory_len = 0;-
1192 goto only_filename;
executed 5 times by 1 test: goto only_filename;
Executed by:
  • Self test
5
1193 }-
1194-
1195 /* We have successfully globbed the preceding directory name.-
1196 For each name in DIRECTORIES, call glob_vector on it and-
1197 FILENAME. Concatenate the results together. */-
1198 for (i = 0; directories[i] != NULL; ++i)
directories[i] != ((void *)0)Description
TRUEevaluated 432 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
29-432
1199 {-
1200 char **temp_results;-
1201 int shouldbreak;-
1202-
1203 shouldbreak = 0;-
1204 /* XXX -- we've recursively scanned any directories resulting from-
1205 a `**', so turn off the flag. We turn it on again below if-
1206 filename is `**' */-
1207 /* Scan directory even on a NULL filename. That way, `*h/'-
1208 returns only directories ending in `h', instead of all-
1209 files ending in `h' with a `/' appended. */-
1210 dname = directories[i];-
1211 dflags = flags & ~(GX_MARKDIRS|GX_ALLDIRS|GX_ADDCURDIR);-
1212 if ((flags & GX_GLOBSTAR) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0')
(flags & 0x400)Description
TRUEevaluated 363 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 69 times by 1 test
Evaluated by:
  • Self test
filename[0] == '*'Description
TRUEevaluated 136 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 227 times by 1 test
Evaluated by:
  • Self test
filename[1] == '*'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 73 times by 1 test
Evaluated by:
  • Self test
filename[2] == '\0'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-363
1213 dflags |= GX_ALLDIRS|GX_ADDCURDIR;
executed 63 times by 1 test: dflags |= 0x010|0x200;
Executed by:
  • Self test
63
1214 if (dname[0] == '\0' && filename[0])
dname[0] == '\0'Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 422 times by 1 test
Evaluated by:
  • Self test
filename[0]Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-422
1215 {-
1216 dflags |= GX_NULLDIR;-
1217 dname = "."; /* treat null directory name and non-null filename as current directory */-
1218 }
executed 10 times by 1 test: end of block
Executed by:
  • Self test
10
1219 temp_results = glob_vector (filename, dname, dflags);-
1220-
1221 /* Handle error cases. */-
1222 if (temp_results == NULL)
temp_results == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 432 times by 1 test
Evaluated by:
  • Self test
0-432
1223 goto memory_error;
never executed: goto memory_error;
0
1224 else if (temp_results == (char **)&glob_error_return)
temp_results =...b_error_returnDescription
TRUEevaluated 114 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 318 times by 1 test
Evaluated by:
  • Self test
114-318
1225 /* This filename is probably not a directory. Ignore it. */-
1226 ;
executed 114 times by 1 test: ;
Executed by:
  • Self test
114
1227 else-
1228 {-
1229 char **array;-
1230 register unsigned int l;-
1231-
1232 /* If we're expanding **, we don't need to glue the directory-
1233 name to the results; we've already done it in glob_vector */-
1234 if ((dflags & GX_ALLDIRS) && filename[0] == '*' && filename[1] == '*' && (filename[2] == '\0' || filename[2] == '/'))
(dflags & 0x010)Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 255 times by 1 test
Evaluated by:
  • Self test
filename[0] == '*'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
filename[1] == '*'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
filename[2] == '\0'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
filename[2] == '/'Description
TRUEnever evaluated
FALSEnever evaluated
0-255
1235 {-
1236 /* When do we remove null elements from temp_results? And-
1237 how to avoid duplicate elements in the final result? */-
1238 /* If (dflags & GX_NULLDIR) glob_filename potentially left a-
1239 NULL placeholder in the temp results just in case-
1240 glob_vector/glob_dir_to_array did something with it, but-
1241 if it didn't, and we're not supposed to be passing them-
1242 through for some reason ((flags & GX_NULLDIR) == 0) we-
1243 need to remove all the NULL elements from the beginning-
1244 of TEMP_RESULTS. */-
1245 /* If we have a null directory name and ** as the filename,-
1246 we have just searched for everything from the current-
1247 directory on down. Break now (shouldbreak = 1) to avoid-
1248 duplicate entries in the final result. */-
1249#define NULL_PLACEHOLDER(x) ((x) && *(x) && **(x) == 0)-
1250 if ((dflags & GX_NULLDIR) && (flags & GX_NULLDIR) == 0 &&
(dflags & 0x100)Description
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • Self test
(flags & 0x100) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-63
1251 NULL_PLACEHOLDER (temp_results))
(temp_results)Description
TRUEnever evaluated
FALSEnever evaluated
*(temp_results)Description
TRUEnever evaluated
FALSEnever evaluated
**(temp_results) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1252#undef NULL_PLACEHOLDER-
1253 {-
1254 register int i, n;-
1255 for (n = 0; temp_results[n] && *temp_results[n] == 0; n++)
temp_results[n]Description
TRUEnever evaluated
FALSEnever evaluated
*temp_results[n] == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1256 ;
never executed: ;
0
1257 i = n;-
1258 do-
1259 temp_results[i - n] = temp_results[i];
never executed: temp_results[i - n] = temp_results[i];
0
1260 while (temp_results[i++] != 0);
temp_results[i++] != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1261 array = temp_results;-
1262 shouldbreak = 1;-
1263 }
never executed: end of block
0
1264 else-
1265 array = temp_results;
executed 63 times by 1 test: array = temp_results;
Executed by:
  • Self test
63
1266 }-
1267 else-
1268 array = glob_dir_to_array (directories[i], temp_results, flags);
executed 255 times by 1 test: array = glob_dir_to_array (directories[i], temp_results, flags);
Executed by:
  • Self test
255
1269 l = 0;-
1270 while (array[l] != NULL)
array[l] != ((void *)0)Description
TRUEevaluated 414 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 318 times by 1 test
Evaluated by:
  • Self test
318-414
1271 ++l;
executed 414 times by 1 test: ++l;
Executed by:
  • Self test
414
1272-
1273 new_result = (char **)realloc (result, (result_size + l) * sizeof (char *));-
1274-
1275 if (new_result == NULL)
new_result == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 318 times by 1 test
Evaluated by:
  • Self test
0-318
1276 {-
1277 for (l = 0; array[l]; ++l)
array[l]Description
TRUEnever evaluated
FALSEnever evaluated
0
1278 free (array[l]);
never executed: sh_xfree((array[l]), "glob.c", 1278);
0
1279 free ((char *)array);-
1280 goto memory_error;
never executed: goto memory_error;
0
1281 }-
1282 result = new_result;-
1283-
1284 for (l = 0; array[l] != NULL; ++l)
array[l] != ((void *)0)Description
TRUEevaluated 414 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 318 times by 1 test
Evaluated by:
  • Self test
318-414
1285 result[result_size++ - 1] = array[l];
executed 414 times by 1 test: result[result_size++ - 1] = array[l];
Executed by:
  • Self test
414
1286-
1287 result[result_size - 1] = NULL;-
1288-
1289 /* Note that the elements of ARRAY are not freed. */-
1290 if (array != temp_results)
array != temp_resultsDescription
TRUEevaluated 245 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 73 times by 1 test
Evaluated by:
  • Self test
73-245
1291 free ((char *) array);
executed 245 times by 1 test: sh_xfree(((char *) array), "glob.c", 1291);
Executed by:
  • Self test
245
1292 else if ((dflags & GX_ALLDIRS) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0')
(dflags & 0x010)Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
filename[0] == '*'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
filename[1] == '*'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
filename[2] == '\0'Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-63
1293 free (temp_results); /* expanding ** case above */
executed 63 times by 1 test: sh_xfree((temp_results), "glob.c", 1293);
Executed by:
  • Self test
63
1294-
1295 if (shouldbreak)
shouldbreakDescription
TRUEnever evaluated
FALSEevaluated 318 times by 1 test
Evaluated by:
  • Self test
0-318
1296 break;
never executed: break;
0
1297 }
executed 318 times by 1 test: end of block
Executed by:
  • Self test
318
1298 }-
1299 /* Free the directories. */-
1300 for (i = 0; directories[i]; i++)
directories[i]Description
TRUEevaluated 432 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
29-432
1301 free (directories[i]);
executed 432 times by 1 test: sh_xfree((directories[i]), "glob.c", 1301);
Executed by:
  • Self test
432
1302-
1303 free ((char *) directories);-
1304-
1305 return (result);
executed 29 times by 1 test: return (result);
Executed by:
  • Self test
29
1306 }-
1307-
1308only_filename:
code before this statement executed 805 times by 1 test: only_filename:
Executed by:
  • Self test
805
1309 /* If there is only a directory name, return it. */-
1310 if (*filename == '\0')
*filename == '\0'Description
TRUEnever evaluated
FALSEevaluated 810 times by 1 test
Evaluated by:
  • Self test
0-810
1311 {-
1312 result = (char **) realloc ((char *) result, 2 * sizeof (char *));-
1313 if (result == NULL)
result == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1314 {-
1315 if (free_dirname)
free_dirnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
1316 free (directory_name);
never executed: sh_xfree((directory_name), "glob.c", 1316);
0
1317 return (NULL);
never executed: return ( ((void *)0) );
0
1318 }-
1319 /* Handle GX_MARKDIRS here. */-
1320 result[0] = (char *) malloc (directory_len + 1);-
1321 if (result[0] == NULL)
result[0] == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1322 goto memory_error;
never executed: goto memory_error;
0
1323 bcopy (directory_name, result[0], directory_len + 1);-
1324 if (free_dirname)
free_dirnameDescription
TRUEnever evaluated
FALSEnever evaluated
0
1325 free (directory_name);
never executed: sh_xfree((directory_name), "glob.c", 1325);
0
1326 result[1] = NULL;-
1327 return (result);
never executed: return (result);
0
1328 }-
1329 else-
1330 {-
1331 char **temp_results;-
1332-
1333 /* There are no unquoted globbing characters in DIRECTORY_NAME.-
1334 Dequote it before we try to open the directory since there may-
1335 be quoted globbing characters which should be treated verbatim. */-
1336 if (directory_len > 0)
directory_len > 0Description
TRUEevaluated 107 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 703 times by 1 test
Evaluated by:
  • Self test
107-703
1337 dequote_pathname (directory_name);
executed 107 times by 1 test: dequote_pathname (directory_name);
Executed by:
  • Self test
107
1338-
1339 /* We allocated a small array called RESULT, which we won't be using.-
1340 Free that memory now. */-
1341 free (result);-
1342-
1343 /* Just return what glob_vector () returns appended to the-
1344 directory name. */-
1345 /* If flags & GX_ALLDIRS, we're called recursively */-
1346 dflags = flags & ~GX_MARKDIRS;-
1347 if (directory_len == 0)
directory_len == 0Description
TRUEevaluated 703 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 107 times by 1 test
Evaluated by:
  • Self test
107-703
1348 dflags |= GX_NULLDIR;
executed 703 times by 1 test: dflags |= 0x100;
Executed by:
  • Self test
703
1349 if ((flags & GX_GLOBSTAR) && filename[0] == '*' && filename[1] == '*' && filename[2] == '\0')
(flags & 0x400)Description
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 780 times by 1 test
Evaluated by:
  • Self test
filename[0] == '*'Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
filename[1] == '*'Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
filename[2] == '\0'Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-780
1350 {-
1351 dflags |= GX_ALLDIRS|GX_ADDCURDIR;-
1352#if 0-
1353 /* If we want all directories (dflags & GX_ALLDIRS) and we're not-
1354 being called recursively as something like `echo [star][star]/[star].o'-
1355 ((flags & GX_ALLDIRS) == 0), we want to prevent glob_vector from-
1356 adding a null directory name to the front of the temp_results-
1357 array. We turn off ADDCURDIR if not called recursively and-
1358 dlen == 0 */-
1359#endif-
1360 if (directory_len == 0 && (flags & GX_ALLDIRS) == 0)
directory_len == 0Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
(flags & 0x010) == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
3-24
1361 dflags &= ~GX_ADDCURDIR;
executed 9 times by 1 test: dflags &= ~0x200;
Executed by:
  • Self test
9
1362 }
executed 27 times by 1 test: end of block
Executed by:
  • Self test
27
1363 temp_results = glob_vector (filename,-
1364 (directory_len == 0 ? "." : directory_name),-
1365 dflags);-
1366-
1367 if (temp_results == NULL || temp_results == (char **)&glob_error_return)
temp_results == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 810 times by 1 test
Evaluated by:
  • Self test
temp_results =...b_error_returnDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 754 times by 1 test
Evaluated by:
  • Self test
0-810
1368 {-
1369 if (free_dirname)
free_dirnameDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-56
1370 free (directory_name);
executed 56 times by 1 test: sh_xfree((directory_name), "glob.c", 1370);
Executed by:
  • Self test
56
1371 QUIT; /* XXX - shell */
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 56 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 56 times by 1 test
Evaluated by:
  • Self test
0-56
1372 run_pending_traps ();-
1373 return (temp_results);
executed 56 times by 1 test: return (temp_results);
Executed by:
  • Self test
56
1374 }-
1375-
1376 result = glob_dir_to_array ((dflags & GX_ALLDIRS) ? "" : directory_name, temp_results, flags);-
1377-
1378 if (free_dirname)
free_dirnameDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 698 times by 1 test
Evaluated by:
  • Self test
56-698
1379 free (directory_name);
executed 56 times by 1 test: sh_xfree((directory_name), "glob.c", 1379);
Executed by:
  • Self test
56
1380 return (result);
executed 754 times by 1 test: return (result);
Executed by:
  • Self test
754
1381 }-
1382-
1383 /* We get to memory_error if the program has run out of memory, or-
1384 if this is the shell, and we have been interrupted. */-
1385 memory_error:-
1386 if (result != NULL)
result != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1387 {-
1388 register unsigned int i;-
1389 for (i = 0; result[i] != NULL; ++i)
result[i] != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1390 free (result[i]);
never executed: sh_xfree((result[i]), "glob.c", 1390);
0
1391 free ((char *) result);-
1392 }
never executed: end of block
0
1393-
1394 if (free_dirname && directory_name)
free_dirnameDescription
TRUEnever evaluated
FALSEnever evaluated
directory_nameDescription
TRUEnever evaluated
FALSEnever evaluated
0
1395 free (directory_name);
never executed: sh_xfree((directory_name), "glob.c", 1395);
0
1396-
1397 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEnever evaluated
interrupt_stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1398 run_pending_traps ();-
1399-
1400 return (NULL);
never executed: return ( ((void *)0) );
0
1401}-
1402-
1403#if defined (TEST)-
1404-
1405main (argc, argv)-
1406 int argc;-
1407 char **argv;-
1408{-
1409 unsigned int i;-
1410-
1411 for (i = 1; i < argc; ++i)-
1412 {-
1413 char **value = glob_filename (argv[i], 0);-
1414 if (value == NULL)-
1415 puts ("Out of memory.");-
1416 else if (value == &glob_error_return)-
1417 perror (argv[i]);-
1418 else-
1419 for (i = 0; value[i] != NULL; i++)-
1420 puts (value[i]);-
1421 }-
1422-
1423 exit (0);-
1424}-
1425#endif /* TEST. */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2