OpenCoverage

common.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/common.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* common.c - utility functions for all builtins */-
2-
3/* Copyright (C) 1987-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#include <config.h>-
22-
23#if defined (HAVE_UNISTD_H)-
24# ifdef _MINIX-
25# include <sys/types.h>-
26# endif-
27# include <unistd.h>-
28#endif-
29-
30#include <stdio.h>-
31#include <chartypes.h>-
32#include "../bashtypes.h"-
33#include "posixstat.h"-
34#include <signal.h>-
35-
36#include <errno.h>-
37-
38#if defined (PREFER_STDARG)-
39# include <stdarg.h>-
40#else-
41# include <varargs.h>-
42#endif-
43-
44#include "../bashansi.h"-
45#include "../bashintl.h"-
46-
47#define NEED_FPURGE_DECL-
48-
49#include "../shell.h"-
50#include "maxpath.h"-
51#include "../flags.h"-
52#include "../parser.h"-
53#include "../jobs.h"-
54#include "../builtins.h"-
55#include "../input.h"-
56#include "../execute_cmd.h"-
57#include "../trap.h"-
58#include "bashgetopt.h"-
59#include "common.h"-
60#include "builtext.h"-
61#include <tilde/tilde.h>-
62-
63#if defined (HISTORY)-
64# include "../bashhist.h"-
65#endif-
66-
67#if !defined (errno)-
68extern int errno; -
69#endif /* !errno */-
70-
71extern const char * const bash_getcwd_errstr;-
72-
73/* Used by some builtins and the mainline code. */-
74sh_builtin_func_t *last_shell_builtin = (sh_builtin_func_t *)NULL;-
75sh_builtin_func_t *this_shell_builtin = (sh_builtin_func_t *)NULL;-
76-
77/* **************************************************************** */-
78/* */-
79/* Error reporting, usage, and option processing */-
80/* */-
81/* **************************************************************** */-
82-
83/* This is a lot like report_error (), but it is for shell builtins-
84 instead of shell control structures, and it won't ever exit the-
85 shell. */-
86-
87static void-
88builtin_error_prolog ()-
89{-
90 char *name;-
91-
92 name = get_name_for_error ();-
93 fprintf (stderr, "%s: ", name);-
94-
95 if (interactive_shell == 0)
interactive_shell == 0Description
TRUEevaluated 715 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-715
96 fprintf (stderr, _("line %d: "), executing_line_number ());
executed 715 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "line %d: " , 5) , executing_line_number ());
Executed by:
  • Self test
715
97-
98 if (this_command_name && *this_command_name)
this_command_nameDescription
TRUEevaluated 670 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 46 times by 1 test
Evaluated by:
  • Self test
*this_command_nameDescription
TRUEevaluated 670 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-670
99 fprintf (stderr, "%s: ", this_command_name);
executed 670 times by 1 test: fprintf ( stderr , "%s: ", this_command_name);
Executed by:
  • Self test
670
100}
executed 716 times by 1 test: end of block
Executed by:
  • Self test
716
101-
102void-
103#if defined (PREFER_STDARG)-
104builtin_error (const char *format, ...)-
105#else-
106builtin_error (format, va_alist)-
107 const char *format;-
108 va_dcl-
109#endif-
110{-
111 va_list args;-
112-
113 builtin_error_prolog ();-
114-
115 SH_VA_START (args, format);-
116-
117 vfprintf (stderr, format, args);-
118 va_end (args);-
119 fprintf (stderr, "\n");-
120}
executed 706 times by 1 test: end of block
Executed by:
  • Self test
706
121-
122void-
123#if defined (PREFER_STDARG)-
124builtin_warning (const char *format, ...)-
125#else-
126builtin_warning (format, va_alist)-
127 const char *format;-
128 va_dcl-
129#endif-
130{-
131 va_list args;-
132-
133 builtin_error_prolog ();-
134 fprintf (stderr, _("warning: "));-
135-
136 SH_VA_START (args, format);-
137-
138 vfprintf (stderr, format, args);-
139 va_end (args);-
140 fprintf (stderr, "\n");-
141}
executed 10 times by 1 test: end of block
Executed by:
  • Self test
10
142-
143/* Print a usage summary for the currently-executing builtin command. */-
144void-
145builtin_usage ()-
146{-
147 if (this_command_name && *this_command_name)
this_command_nameDescription
TRUEevaluated 79 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*this_command_nameDescription
TRUEevaluated 79 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-79
148 fprintf (stderr, _("%s: usage: "), this_command_name);
executed 79 times by 1 test: fprintf ( stderr , dcgettext (((void *)0), "%s: usage: " , 5) , this_command_name);
Executed by:
  • Self test
79
149 fprintf (stderr, "%s\n", _(current_builtin->short_doc));-
150 fflush (stderr);-
151}
executed 79 times by 1 test: end of block
Executed by:
  • Self test
79
152-
153/* Return if LIST is NULL else barf and jump to top_level. Used by some-
154 builtins that do not accept arguments. */-
155void-
156no_args (list)-
157 WORD_LIST *list;-
158{-
159 if (list)
listDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 339 times by 1 test
Evaluated by:
  • Self test
5-339
160 {-
161 builtin_error (_("too many arguments"));-
162 top_level_cleanup ();-
163 jump_to_top_level (DISCARD);-
164 }
never executed: end of block
0
165}
executed 339 times by 1 test: end of block
Executed by:
  • Self test
339
166-
167/* Check that no options were given to the currently-executing builtin,-
168 and return 0 if there were options. */-
169int-
170no_options (list)-
171 WORD_LIST *list;-
172{-
173 int opt;-
174-
175 reset_internal_getopt ();-
176 if ((opt = internal_getopt (list, "")) != -1)
(opt = interna...st, "")) != -1Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14672 times by 1 test
Evaluated by:
  • Self test
9-14672
177 {-
178 if (opt == GETOPT_HELP)
opt == -99Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
179 {-
180 builtin_help ();-
181 return (2);
never executed: return (2);
0
182 }-
183 builtin_usage ();-
184 return (1);
executed 9 times by 1 test: return (1);
Executed by:
  • Self test
9
185 }-
186 return (0);
executed 14672 times by 1 test: return (0);
Executed by:
  • Self test
14672
187}-
188-
189void-
190sh_needarg (s)-
191 char *s;-
192{-
193 builtin_error (_("%s: option requires an argument"), s);-
194}
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
195-
196void-
197sh_neednumarg (s)-
198 char *s;-
199{-
200 builtin_error (_("%s: numeric argument required"), s);-
201}
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
202-
203void-
204sh_notfound (s)-
205 char *s;-
206{-
207 builtin_error (_("%s: not found"), s);-
208}
executed 86 times by 1 test: end of block
Executed by:
  • Self test
86
209-
210/* Function called when one of the builtin commands detects an invalid-
211 option. */-
212void-
213sh_invalidopt (s)-
214 char *s;-
215{-
216 builtin_error (_("%s: invalid option"), s);-
217}
executed 59 times by 1 test: end of block
Executed by:
  • Self test
59
218-
219void-
220sh_invalidoptname (s)-
221 char *s;-
222{-
223 builtin_error (_("%s: invalid option name"), s);-
224}
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
225-
226void-
227sh_invalidid (s)-
228 char *s;-
229{-
230 builtin_error (_("`%s': not a valid identifier"), s);-
231}
executed 142 times by 1 test: end of block
Executed by:
  • Self test
142
232-
233void-
234sh_invalidnum (s)-
235 char *s;-
236{-
237 char *msg;-
238-
239 if (*s == '0' && isdigit ((unsigned char)s[1]))
*s == '0'Description
TRUEnever evaluated
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
((*__ctype_b_l...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0-24
240 msg = _("invalid octal number");
never executed: msg = dcgettext (((void *)0), "invalid octal number" , 5) ;
0
241 else if (*s == '0' && s[1] == 'x')
*s == '0'Description
TRUEnever evaluated
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
s[1] == 'x'Description
TRUEnever evaluated
FALSEnever evaluated
0-24
242 msg = _("invalid hex number");
never executed: msg = dcgettext (((void *)0), "invalid hex number" , 5) ;
0
243 else-
244 msg = _("invalid number");
executed 24 times by 1 test: msg = dcgettext (((void *)0), "invalid number" , 5) ;
Executed by:
  • Self test
24
245 builtin_error ("%s: %s", s, msg);-
246}
executed 24 times by 1 test: end of block
Executed by:
  • Self test
24
247-
248void-
249sh_invalidsig (s)-
250 char *s;-
251{-
252 builtin_error (_("%s: invalid signal specification"), s);-
253}
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
254-
255void-
256sh_badpid (s)-
257 char *s;-
258{-
259 builtin_error (_("`%s': not a pid or valid job spec"), s);-
260}
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
261-
262void-
263sh_readonly (s)-
264 const char *s;-
265{-
266 builtin_error (_("%s: readonly variable"), s);-
267}
executed 23 times by 1 test: end of block
Executed by:
  • Self test
23
268-
269void-
270sh_erange (s, desc)-
271 char *s, *desc;-
272{-
273 if (s)
sDescription
TRUEevaluated 30 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-30
274 builtin_error (_("%s: %s out of range"), s, desc ? desc : _("argument"));
executed 30 times by 1 test: builtin_error ( dcgettext (((void *)0), "%s: %s out of range" , 5) , s, desc ? desc : dcgettext (((void *)0), "argument" , 5) );
Executed by:
  • Self test
30
275 else-
276 builtin_error (_("%s out of range"), desc ? desc : _("argument"));
executed 1 time by 1 test: builtin_error ( dcgettext (((void *)0), "%s out of range" , 5) , desc ? desc : dcgettext (((void *)0), "argument" , 5) );
Executed by:
  • Self test
1
277}-
278-
279#if defined (JOB_CONTROL)-
280void-
281sh_badjob (s)-
282 char *s;-
283{-
284 builtin_error (_("%s: no such job"), s);-
285}
executed 17 times by 1 test: end of block
Executed by:
  • Self test
17
286-
287void-
288sh_nojobs (s)-
289 char *s;-
290{-
291 if (s)
sDescription
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
292 builtin_error (_("%s: no job control"), s);
never executed: builtin_error ( dcgettext (((void *)0), "%s: no job control" , 5) , s);
0
293 else-
294 builtin_error (_("no job control"));
executed 5 times by 1 test: builtin_error ( dcgettext (((void *)0), "no job control" , 5) );
Executed by:
  • Self test
5
295}-
296#endif-
297-
298#if defined (RESTRICTED_SHELL)-
299void-
300sh_restricted (s)-
301 char *s;-
302{-
303 if (s)
sDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2
304 builtin_error (_("%s: restricted"), s);
executed 2 times by 1 test: builtin_error ( dcgettext (((void *)0), "%s: restricted" , 5) , s);
Executed by:
  • Self test
2
305 else-
306 builtin_error (_("restricted"));
executed 2 times by 1 test: builtin_error ( dcgettext (((void *)0), "restricted" , 5) );
Executed by:
  • Self test
2
307}-
308#endif-
309-
310void-
311sh_notbuiltin (s)-
312 char *s;-
313{-
314 builtin_error (_("%s: not a shell builtin"), s);-
315}
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
316-
317void-
318sh_wrerror ()-
319{-
320#if defined (DONT_REPORT_BROKEN_PIPE_WRITE_ERRORS) && defined (EPIPE)-
321 if (errno != EPIPE)-
322#endif /* DONT_REPORT_BROKEN_PIPE_WRITE_ERRORS && EPIPE */-
323 builtin_error (_("write error: %s"), strerror (errno));-
324}
executed 20 times by 1 test: end of block
Executed by:
  • Self test
20
325-
326void-
327sh_ttyerror (set)-
328 int set;-
329{-
330 if (set)
setDescription
TRUEnever evaluated
FALSEnever evaluated
0
331 builtin_error (_("error setting terminal attributes: %s"), strerror (errno));
never executed: builtin_error ( dcgettext (((void *)0), "error setting terminal attributes: %s" , 5) , strerror ( (*__errno_location ()) ));
0
332 else-
333 builtin_error (_("error getting terminal attributes: %s"), strerror (errno));
never executed: builtin_error ( dcgettext (((void *)0), "error getting terminal attributes: %s" , 5) , strerror ( (*__errno_location ()) ));
0
334}-
335-
336int-
337sh_chkwrite (s)-
338 int s;-
339{-
340 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 688881 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 688881 times by 1 test
Evaluated by:
  • Self test
0-688881
341 fflush (stdout);-
342 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 688881 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 688881 times by 1 test
Evaluated by:
  • Self test
0-688881
343 if (ferror (stdout))
ferror ( stdout )Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 688861 times by 1 test
Evaluated by:
  • Self test
20-688861
344 {-
345 sh_wrerror ();-
346 fpurge (stdout);-
347 clearerr (stdout);-
348 return (EXECUTION_FAILURE);
executed 20 times by 1 test: return (1);
Executed by:
  • Self test
20
349 }-
350 return (s);
executed 688861 times by 1 test: return (s);
Executed by:
  • Self test
688861
351}-
352-
353/* **************************************************************** */-
354/* */-
355/* Shell positional parameter manipulation */-
356/* */-
357/* **************************************************************** */-
358-
359/* Convert a WORD_LIST into a C-style argv. Return the number of elements-
360 in the list in *IP, if IP is non-null. A convenience function for-
361 loadable builtins; also used by `test'. */-
362char **-
363make_builtin_argv (list, ip)-
364 WORD_LIST *list;-
365 int *ip;-
366{-
367 char **argv;-
368-
369 argv = strvec_from_word_list (list, 0, 1, ip);-
370 argv[0] = this_command_name;-
371 return argv;
executed 4434 times by 1 test: return argv;
Executed by:
  • Self test
4434
372}-
373-
374/* Remember LIST in $1 ... $9, and REST_OF_ARGS. If DESTRUCTIVE is-
375 non-zero, then discard whatever the existing arguments are, else-
376 only discard the ones that are to be replaced. */-
377void-
378remember_args (list, destructive)-
379 WORD_LIST *list;-
380 int destructive;-
381{-
382 register int i;-
383-
384 for (i = 1; i < 10; i++)
i < 10Description
TRUEevaluated 58839174 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6537686 times by 1 test
Evaluated by:
  • Self test
6537686-58839174
385 {-
386 if ((destructive || list) && dollar_vars[i])
destructiveDescription
TRUEevaluated 58839174 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
listDescription
TRUEnever evaluated
FALSEnever evaluated
dollar_vars[i]Description
TRUEevaluated 4903650 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 53935524 times by 1 test
Evaluated by:
  • Self test
0-58839174
387 {-
388 free (dollar_vars[i]);-
389 dollar_vars[i] = (char *)NULL;-
390 }
executed 4903650 times by 1 test: end of block
Executed by:
  • Self test
4903650
391-
392 if (list)
listDescription
TRUEevaluated 16803873 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42035301 times by 1 test
Evaluated by:
  • Self test
16803873-42035301
393 {-
394 dollar_vars[i] = savestring (list->word->word);-
395 list = list->next;-
396 }
executed 16803873 times by 1 test: end of block
Executed by:
  • Self test
16803873
397 }
executed 58839174 times by 1 test: end of block
Executed by:
  • Self test
58839174
398-
399 /* If arguments remain, assign them to REST_OF_ARGS.-
400 Note that copy_word_list (NULL) returns NULL, and-
401 that dispose_words (NULL) does nothing. */-
402 if (destructive || list)
destructiveDescription
TRUEevaluated 6537686 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
listDescription
TRUEnever evaluated
FALSEnever evaluated
0-6537686
403 {-
404 dispose_words (rest_of_args);-
405 rest_of_args = copy_word_list (list);-
406 }
executed 6537686 times by 1 test: end of block
Executed by:
  • Self test
6537686
407-
408 if (destructive)
destructiveDescription
TRUEevaluated 6537686 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6537686
409 set_dollar_vars_changed ();
executed 6537686 times by 1 test: set_dollar_vars_changed ();
Executed by:
  • Self test
6537686
410-
411 invalidate_cached_quoted_dollar_at ();-
412}
executed 6537686 times by 1 test: end of block
Executed by:
  • Self test
6537686
413-
414static int changed_dollar_vars;-
415-
416/* Have the dollar variables been reset to new values since we last-
417 checked? */-
418int-
419dollar_vars_changed ()-
420{-
421 return (changed_dollar_vars);
executed 1197 times by 1 test: return (changed_dollar_vars);
Executed by:
  • Self test
1197
422}-
423-
424void-
425set_dollar_vars_unchanged ()-
426{-
427 changed_dollar_vars = 0;-
428}
executed 1639923 times by 1 test: end of block
Executed by:
  • Self test
1639923
429-
430void-
431set_dollar_vars_changed ()-
432{-
433 if (variable_context)
variable_contextDescription
TRUEevaluated 6515837 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21849 times by 1 test
Evaluated by:
  • Self test
21849-6515837
434 changed_dollar_vars |= ARGS_FUNC;
executed 6515837 times by 1 test: changed_dollar_vars |= 0x02;
Executed by:
  • Self test
6515837
435 else if (this_shell_builtin == set_builtin)
this_shell_bui...== set_builtinDescription
TRUEevaluated 19361 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2488 times by 1 test
Evaluated by:
  • Self test
2488-19361
436 changed_dollar_vars |= ARGS_SETBLTIN;
executed 19361 times by 1 test: changed_dollar_vars |= 0x04;
Executed by:
  • Self test
19361
437 else-
438 changed_dollar_vars |= ARGS_INVOC;
executed 2488 times by 1 test: changed_dollar_vars |= 0x01;
Executed by:
  • Self test
2488
439}-
440-
441/* **************************************************************** */-
442/* */-
443/* Validating numeric input and arguments */-
444/* */-
445/* **************************************************************** */-
446-
447/* Read a numeric arg for this_command_name, the name of the shell builtin-
448 that wants it. LIST is the word list that the arg is to come from.-
449 Accept only the numeric argument; report an error if other arguments-
450 follow. If FATAL is 1, call throw_to_top_level, which exits the-
451 shell; if it's 2, call jump_to_top_level (DISCARD), which aborts the-
452 current command; if FATAL is 0, return an indication of an invalid-
453 number by setting *NUMOK == 0 and return -1. */-
454int-
455get_numeric_arg (list, fatal, count)-
456 WORD_LIST *list;-
457 int fatal;-
458 intmax_t *count;-
459{-
460 char *arg;-
461-
462 if (count)
countDescription
TRUEevaluated 15200312 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-15200312
463 *count = 1;
executed 15200312 times by 1 test: *count = 1;
Executed by:
  • Self test
15200312
464-
465 if (list && list->word && ISOPTION (list->word->word, '-'))
listDescription
TRUEevaluated 179 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15200133 times by 1 test
Evaluated by:
  • Self test
list->wordDescription
TRUEevaluated 179 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
list->word->word[0] == '-'Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 172 times by 1 test
Evaluated by:
  • Self test
list->word->word[1] == '-'Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
!list->word->word[2]Description
TRUEnever evaluated
FALSEnever evaluated
0-15200133
466 list = list->next;
never executed: list = list->next;
0
467-
468 if (list)
listDescription
TRUEevaluated 179 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15200133 times by 1 test
Evaluated by:
  • Self test
179-15200133
469 {-
470 arg = list->word->word;-
471 if (arg == 0 || (legal_number (arg, count) == 0))
arg == 0Description
TRUEnever evaluated
FALSEevaluated 179 times by 1 test
Evaluated by:
  • Self test
(legal_number ..., count) == 0)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 173 times by 1 test
Evaluated by:
  • Self test
0-179
472 {-
473 sh_neednumarg (list->word->word ? list->word->word : "`'");-
474 if (fatal == 0)
fatal == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-5
475 return 0;
executed 5 times by 1 test: return 0;
Executed by:
  • Self test
5
476 else if (fatal == 1) /* fatal == 1; abort */
fatal == 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
477 throw_to_top_level ();
executed 1 time by 1 test: throw_to_top_level ();
Executed by:
  • Self test
1
478 else /* fatal == 2; discard current command */-
479 {-
480 top_level_cleanup ();-
481 jump_to_top_level (DISCARD);-
482 }
never executed: end of block
0
483 }-
484 no_args (list->next);-
485 }
executed 168 times by 1 test: end of block
Executed by:
  • Self test
168
486-
487 return (1);
executed 15200301 times by 1 test: return (1);
Executed by:
  • Self test
15200301
488}-
489-
490/* Get an eight-bit status value from LIST */-
491int-
492get_exitstat (list)-
493 WORD_LIST *list;-
494{-
495 int status;-
496 intmax_t sval;-
497 char *arg;-
498-
499 if (list && list->word && ISOPTION (list->word->word, '-'))
listDescription
TRUEevaluated 172 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1996 times by 1 test
Evaluated by:
  • Self test
list->wordDescription
TRUEevaluated 172 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
list->word->word[0] == '-'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 169 times by 1 test
Evaluated by:
  • Self test
list->word->word[1] == '-'Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
!list->word->word[2]Description
TRUEnever evaluated
FALSEnever evaluated
0-1996
500 list = list->next;
never executed: list = list->next;
0
501-
502 if (list == 0)
list == 0Description
TRUEevaluated 1996 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 172 times by 1 test
Evaluated by:
  • Self test
172-1996
503 {-
504 /* If we're not running the DEBUG trap, the return builtin, when not-
505 given any arguments, uses the value of $? before the trap ran. If-
506 given an argument, return uses it. This means that the trap can't-
507 change $?. The DEBUG trap gets to change $?, though, since that is-
508 part of its reason for existing, and because the extended debug mode-
509 does things with the return value. */-
510 if (this_shell_builtin == return_builtin && running_trap > 0 && running_trap != DEBUG_TRAP+1)
this_shell_bui...return_builtinDescription
TRUEevaluated 1987 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
running_trap > 0Description
TRUEevaluated 1887 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 100 times by 1 test
Evaluated by:
  • Self test
running_trap != 65 +1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1884 times by 1 test
Evaluated by:
  • Self test
3-1987
511 return (trap_saved_exit_value);
executed 3 times by 1 test: return (trap_saved_exit_value);
Executed by:
  • Self test
3
512 return (last_command_exit_value);
executed 1993 times by 1 test: return (last_command_exit_value);
Executed by:
  • Self test
1993
513 }-
514-
515 arg = list->word->word;-
516 if (arg == 0 || legal_number (arg, &sval) == 0)
arg == 0Description
TRUEnever evaluated
FALSEevaluated 172 times by 1 test
Evaluated by:
  • Self test
legal_number (arg, &sval) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 171 times by 1 test
Evaluated by:
  • Self test
0-172
517 {-
518 sh_neednumarg (list->word->word ? list->word->word : "`'");-
519 return EX_BADUSAGE;
executed 1 time by 1 test: return 2;
Executed by:
  • Self test
1
520 }-
521 no_args (list->next);-
522-
523 status = sval & 255;-
524 return status;
executed 171 times by 1 test: return status;
Executed by:
  • Self test
171
525}-
526-
527/* Return the octal number parsed from STRING, or -1 to indicate-
528 that the string contained a bad number. */-
529int-
530read_octal (string)-
531 char *string;-
532{-
533 int result, digits;-
534-
535 result = digits = 0;-
536 while (*string && ISOCTAL (*string))
*stringDescription
TRUEevaluated 82 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
(*string) >= '0'Description
TRUEevaluated 82 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(*string) <= '7'Description
TRUEevaluated 77 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-82
537 {-
538 digits++;-
539 result = (result * 8) + (*string++ - '0');-
540 if (result > 07777)
result > 07777Description
TRUEnever evaluated
FALSEevaluated 77 times by 1 test
Evaluated by:
  • Self test
0-77
541 return -1;
never executed: return -1;
0
542 }
executed 77 times by 1 test: end of block
Executed by:
  • Self test
77
543-
544 if (digits == 0 || *string)
digits == 0Description
TRUEnever evaluated
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test
*stringDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
0-32
545 result = -1;
executed 5 times by 1 test: result = -1;
Executed by:
  • Self test
5
546-
547 return (result);
executed 32 times by 1 test: return (result);
Executed by:
  • Self test
32
548}-
549-
550/* **************************************************************** */-
551/* */-
552/* Manipulating the current working directory */-
553/* */-
554/* **************************************************************** */-
555-
556/* Return a consed string which is the current working directory.-
557 FOR_WHOM is the name of the caller for error printing. */-
558char *the_current_working_directory = (char *)NULL;-
559-
560char *-
561get_working_directory (for_whom)-
562 char *for_whom;-
563{-
564 if (no_symbolic_links)
no_symbolic_linksDescription
TRUEnever evaluated
FALSEevaluated 69 times by 1 test
Evaluated by:
  • Self test
0-69
565 {-
566 FREE (the_current_working_directory);
never executed: sh_xfree((the_current_working_directory), "common.c", 566);
the_current_working_directoryDescription
TRUEnever evaluated
FALSEnever evaluated
0
567 the_current_working_directory = (char *)NULL;-
568 }
never executed: end of block
0
569-
570 if (the_current_working_directory == 0)
the_current_wo...directory == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 66 times by 1 test
Evaluated by:
  • Self test
3-66
571 {-
572#if defined (GETCWD_BROKEN)-
573 the_current_working_directory = getcwd (0, PATH_MAX);-
574#else-
575 the_current_working_directory = getcwd (0, 0);-
576#endif-
577 if (the_current_working_directory == 0)
the_current_wo...directory == 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
578 {-
579 fprintf (stderr, _("%s: error retrieving current directory: %s: %s\n"),-
580 (for_whom && *for_whom) ? for_whom : get_name_for_error (),-
581 _(bash_getcwd_errstr), strerror (errno));-
582 return (char *)NULL;
never executed: return (char *) ((void *)0) ;
0
583 }-
584 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
585-
586 return (savestring (the_current_working_directory));
executed 69 times by 1 test: return ((char *)strcpy (sh_xmalloc((1 + strlen (the_current_working_directory)), "common.c", 586), (the_current_working_directory)));
Executed by:
  • Self test
69
587}-
588-
589/* Make NAME our internal idea of the current working directory. */-
590void-
591set_working_directory (name)-
592 char *name;-
593{-
594 FREE (the_current_working_directory);
executed 81 times by 1 test: sh_xfree((the_current_working_directory), "common.c", 594);
Executed by:
  • Self test
the_current_working_directoryDescription
TRUEevaluated 81 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5429 times by 1 test
Evaluated by:
  • Self test
81-5429
595 the_current_working_directory = savestring (name);-
596}
executed 5510 times by 1 test: end of block
Executed by:
  • Self test
5510
597-
598/* **************************************************************** */-
599/* */-
600/* Job control support functions */-
601/* */-
602/* **************************************************************** */-
603-
604#if defined (JOB_CONTROL)-
605int-
606get_job_by_name (name, flags)-
607 const char *name;-
608 int flags;-
609{-
610 register int i, wl, cl, match, job;-
611 register PROCESS *p;-
612 register JOB *j;-
613-
614 job = NO_JOB;-
615 wl = strlen (name);-
616 for (i = js.j_jobslots - 1; i >= 0; i--)
i >= 0Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-48
617 {-
618 j = get_job_by_jid (i);-
619 if (j == 0 || ((flags & JM_STOPPED) && J_JOBSTATE(j) != JSTOPPED))
j == 0Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
(flags & 0x08)Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
((j)->state) != JSTOPPEDDescription
TRUEnever evaluated
FALSEnever evaluated
0-42
620 continue;
executed 42 times by 1 test: continue;
Executed by:
  • Self test
42
621-
622 p = j->pipe;-
623 do-
624 {-
625 if (flags & JM_EXACT)
flags & 0x04Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
626 {-
627 cl = strlen (p->command);-
628 match = STREQN (p->command, name, cl);
never executed: __result = (((const unsigned char *) (const char *) ( p->command ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(cl == 0)Description
TRUEnever evaluated
FALSEnever evaluated
(p->command)[0] == (name)[0]Description
TRUEnever evaluated
FALSEnever evaluated
(__extension__... , cl ))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( cl )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons...( p->command )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( p->co...ize_t) ( cl ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( name )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( name ...ize_t) ( cl ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
629 }
never executed: end of block
0
630 else if (flags & JM_SUBSTRING)
flags & 0x02Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3
631 match = strcasestr (p->command, name) != (char *)0;
executed 3 times by 1 test: match = strcasestr (p->command, name) != (char *)0;
Executed by:
  • Self test
3
632 else-
633 match = STREQN (p->command, name, wl);
executed 3 times by 1 test: match = ((wl == 0) ? (1) : ((p->command)[0] == (name)[0] && (__extension__ (__builtin_constant_p ( wl ) && ((__builtin_constant_p ( p->command ) && strlen ( p->command ) < ((size_t) ( wl ))) || (__builtin_constant_p ( name ) && strlen ( name ) < ((size_t)...r *) ( name ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( p->command , name )))); }) : strncmp ( p->command , name , wl ))) == 0));
Executed by:
  • Self test
never executed: __result = (((const unsigned char *) (const char *) ( p->command ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(wl == 0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
(p->command)[0] == (name)[0]Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(__extension__... , wl ))) == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_constant_p ( wl )Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
__builtin_cons...( p->command )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( p->co...ize_t) ( wl ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( name )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( name ...ize_t) ( wl ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-3
634-
635 if (match == 0)
match == 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
636 {-
637 p = p->next;-
638 continue;
never executed: continue;
0
639 }-
640 else if (flags & JM_FIRSTMATCH)
flags & 0x10Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
641 return i; /* return first match */
never executed: return i;
0
642 else if (job != NO_JOB)
job != -1Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
643 {-
644 if (this_shell_builtin)
this_shell_builtinDescription
TRUEnever evaluated
FALSEnever evaluated
0
645 builtin_error (_("%s: ambiguous job spec"), name);
never executed: builtin_error ( dcgettext (((void *)0), "%s: ambiguous job spec" , 5) , name);
0
646 else-
647 internal_error (_("%s: ambiguous job spec"), name);
never executed: internal_error ( dcgettext (((void *)0), "%s: ambiguous job spec" , 5) , name);
0
648 return (DUP_JOB);
never executed: return (-2);
0
649 }-
650 else-
651 job = i;
executed 6 times by 1 test: job = i;
Executed by:
  • Self test
6
652 }-
653 while (p != j->pipe);
p != j->pipeDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
654 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
655-
656 return (job);
executed 6 times by 1 test: return (job);
Executed by:
  • Self test
6
657}-
658-
659/* Return the job spec found in LIST. */-
660int-
661get_job_spec (list)-
662 WORD_LIST *list;-
663{-
664 register char *word;-
665 int job, jflags;-
666-
667 if (list == 0)
list == 0Description
TRUEnever evaluated
FALSEevaluated 57 times by 1 test
Evaluated by:
  • Self test
0-57
668 return (js.j_current);
never executed: return (js.j_current);
0
669-
670 word = list->word->word;-
671-
672 if (*word == '\0')
*word == '\0'Description
TRUEnever evaluated
FALSEevaluated 57 times by 1 test
Evaluated by:
  • Self test
0-57
673 return (NO_JOB);
never executed: return (-1);
0
674-
675 if (*word == '%')
*word == '%'Description
TRUEevaluated 57 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-57
676 word++;
executed 57 times by 1 test: word++;
Executed by:
  • Self test
57
677-
678 if (DIGIT (*word) && all_digits (word))
(*word) >= '0'Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
(*word) <= '9'Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
all_digits (word)Description
TRUEevaluated 42 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-48
679 {-
680 job = atoi (word);-
681 return (job > js.j_jobslots ? NO_JOB : job - 1);
executed 42 times by 1 test: return (job > js.j_jobslots ? -1 : job - 1);
Executed by:
  • Self test
42
682 }-
683-
684 jflags = 0;-
685 switch (*word)-
686 {-
687 case 0:
never executed: case 0:
0
688 case '%':
executed 5 times by 1 test: case '%':
Executed by:
  • Self test
5
689 case '+':
executed 3 times by 1 test: case '+':
Executed by:
  • Self test
3
690 return (js.j_current);
executed 8 times by 1 test: return (js.j_current);
Executed by:
  • Self test
8
691-
692 case '-':
executed 1 time by 1 test: case '-':
Executed by:
  • Self test
1
693 return (js.j_previous);
executed 1 time by 1 test: return (js.j_previous);
Executed by:
  • Self test
1
694-
695 case '?': /* Substring search requested. */
executed 3 times by 1 test: case '?':
Executed by:
  • Self test
3
696 jflags |= JM_SUBSTRING;-
697 word++;-
698 /* FALLTHROUGH */-
699-
700 default:
code before this statement executed 3 times by 1 test: default:
Executed by:
  • Self test
executed 6 times by 1 test: default:
Executed by:
  • Self test
3-6
701 return get_job_by_name (word, jflags);
executed 6 times by 1 test: return get_job_by_name (word, jflags);
Executed by:
  • Self test
6
702 }-
703}-
704#endif /* JOB_CONTROL */-
705-
706/*-
707 * NOTE: `kill' calls this function with forcecols == 0-
708 */-
709int-
710display_signal_list (list, forcecols)-
711 WORD_LIST *list;-
712 int forcecols;-
713{-
714 register int i, column;-
715 char *name;-
716 int result, signum, dflags;-
717 intmax_t lsignum;-
718-
719 result = EXECUTION_SUCCESS;-
720 if (!list)
!listDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
2-4
721 {-
722 for (i = 1, column = 0; i < NSIG; i++)
i < 65Description
TRUEevaluated 128 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-128
723 {-
724 name = signal_name (i);-
725 if (STREQN (name, "SIGJUNK", 7) || STREQN (name, "Unknown", 7))
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "SIGJUNK" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "Unknown" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(7 == 0)Description
TRUEnever evaluated
FALSEevaluated 128 times by 1 test
Evaluated by:
  • Self test
(7 == 0)Description
TRUEnever evaluated
FALSEevaluated 124 times by 1 test
Evaluated by:
  • Self test
((7 == 0) ? (1..., 7 ))) == 0))Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 124 times by 1 test
Evaluated by:
  • Self test
(name)[0] == ("SIGJUNK")[0]Description
TRUEevaluated 128 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(__extension__..." , 7 ))) == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 124 times by 1 test
Evaluated by:
  • Self test
__builtin_constant_p ( 7 )Description
TRUEevaluated 128 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_constant_p ( name )Description
TRUEnever evaluated
FALSEevaluated 128 times by 1 test
Evaluated by:
  • Self test
strlen ( name ...size_t) ( 7 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons... ( "SIGJUNK" )Description
TRUEevaluated 128 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
strlen ( "SIGJ...size_t) ( 7 ))Description
TRUEnever evaluated
FALSEevaluated 128 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
((7 == 0) ? (1..., 7 ))) == 0))Description
TRUEnever evaluated
FALSEevaluated 124 times by 1 test
Evaluated by:
  • Self test
(name)[0] == ("Unknown")[0]Description
TRUEnever evaluated
FALSEevaluated 124 times by 1 test
Evaluated by:
  • Self test
(__extension__..." , 7 ))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( 7 )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( name )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( name ...size_t) ( 7 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons... ( "Unknown" )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( "Unkn...size_t) ( 7 ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-128
726 continue;
executed 4 times by 1 test: continue;
Executed by:
  • Self test
4
727-
728 if (posixly_correct && !forcecols)
posixly_correctDescription
TRUEnever evaluated
FALSEevaluated 124 times by 1 test
Evaluated by:
  • Self test
!forcecolsDescription
TRUEnever evaluated
FALSEnever evaluated
0-124
729 {-
730 /* This is for the kill builtin. POSIX.2 says the signal names-
731 are displayed without the `SIG' prefix. */-
732 if (STREQN (name, "SIG", 3))
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "SIG" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
((3 == 0) ? (1..., 3 ))) == 0))Description
TRUEnever evaluated
FALSEnever evaluated
(3 == 0)Description
TRUEnever evaluated
FALSEnever evaluated
(name)[0] == ("SIG")[0]Description
TRUEnever evaluated
FALSEnever evaluated
(__extension__..." , 3 ))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( 3 )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( name )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( name ...size_t) ( 3 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( "SIG" )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( "SIG"...size_t) ( 3 ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
733 name += 3;
never executed: name += 3;
0
734 printf ("%s%s", name, (i == NSIG - 1) ? "" : " ");-
735 }
never executed: end of block
0
736 else-
737 {-
738 printf ("%2d) %s", i, name);-
739-
740 if (++column < 5)
++column < 5Description
TRUEevaluated 100 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
24-100
741 printf ("\t");
executed 100 times by 1 test: printf ("\t");
Executed by:
  • Self test
100
742 else-
743 {-
744 printf ("\n");-
745 column = 0;-
746 }
executed 24 times by 1 test: end of block
Executed by:
  • Self test
24
747 }-
748 }-
749-
750 if ((posixly_correct && !forcecols) || column != 0)
posixly_correctDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
!forcecolsDescription
TRUEnever evaluated
FALSEnever evaluated
column != 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
751 printf ("\n");
executed 2 times by 1 test: printf ("\n");
Executed by:
  • Self test
2
752 return result;
executed 2 times by 1 test: return result;
Executed by:
  • Self test
2
753 }-
754-
755 /* List individual signal names or numbers. */-
756 while (list)
listDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4
757 {-
758 if (legal_number (list->word->word, &lsignum))
legal_number (...ord, &lsignum)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-3
759 {-
760 /* This is specified by Posix.2 so that exit statuses can be-
761 mapped into signal numbers. */-
762 if (lsignum > 128)
lsignum > 128Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-2
763 lsignum -= 128;
executed 2 times by 1 test: lsignum -= 128;
Executed by:
  • Self test
2
764 if (lsignum < 0 || lsignum >= NSIG)
lsignum < 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
lsignum >= 65Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-3
765 {-
766 sh_invalidsig (list->word->word);-
767 result = EXECUTION_FAILURE;-
768 list = list->next;-
769 continue;
executed 1 time by 1 test: continue;
Executed by:
  • Self test
1
770 }-
771-
772 signum = lsignum;-
773 name = signal_name (signum);-
774 if (STREQN (name, "SIGJUNK", 7) || STREQN (name, "Unknown", 7))
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "SIGJUNK" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "Unknown" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(7 == 0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(7 == 0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
((7 == 0) ? (1..., 7 ))) == 0))Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(name)[0] == ("SIGJUNK")[0]Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(__extension__..." , 7 ))) == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
__builtin_constant_p ( 7 )Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_constant_p ( name )Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
strlen ( name ...size_t) ( 7 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons... ( "SIGJUNK" )Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
strlen ( "SIGJ...size_t) ( 7 ))Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
((7 == 0) ? (1..., 7 ))) == 0))Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(name)[0] == ("Unknown")[0]Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(__extension__..." , 7 ))) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( 7 )Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_constant_p ( name )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( name ...size_t) ( 7 ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons... ( "Unknown" )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( "Unkn...size_t) ( 7 ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-2
775 {-
776 list = list->next;-
777 continue;
never executed: continue;
0
778 }-
779 /* POSIX.2 says that `kill -l signum' prints the signal name without-
780 the `SIG' prefix. */-
781 printf ("%s\n", (this_shell_builtin == kill_builtin && signum > 0) ? name + 3 : name);-
782 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
783 else-
784 {-
785 dflags = DSIG_NOCASE;-
786 if (posixly_correct == 0 || this_shell_builtin != kill_builtin)
posixly_correct == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
this_shell_bui...= kill_builtinDescription
TRUEnever evaluated
FALSEnever evaluated
0-1
787 dflags |= DSIG_SIGPREFIX;
executed 1 time by 1 test: dflags |= 0x01;
Executed by:
  • Self test
1
788 signum = decode_signal (list->word->word, dflags);-
789 if (signum == NO_SIG)
signum == -1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
790 {-
791 sh_invalidsig (list->word->word);-
792 result = EXECUTION_FAILURE;-
793 list = list->next;-
794 continue;
never executed: continue;
0
795 }-
796 printf ("%d\n", signum);-
797 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
798 list = list->next;-
799 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
800 return (result);
executed 4 times by 1 test: return (result);
Executed by:
  • Self test
4
801}-
802-
803/* **************************************************************** */-
804/* */-
805/* Finding builtin commands and their functions */-
806/* */-
807/* **************************************************************** */-
808-
809/* Perform a binary search and return the address of the builtin function-
810 whose name is NAME. If the function couldn't be found, or the builtin-
811 is disabled or has no function associated with it, return NULL.-
812 Return the address of the builtin.-
813 DISABLED_OKAY means find it even if the builtin is disabled. */-
814struct builtin *-
815builtin_address_internal (name, disabled_okay)-
816 char *name;-
817 int disabled_okay;-
818{-
819 int hi, lo, mid, j;-
820-
821 hi = num_shell_builtins - 1;-
822 lo = 0;-
823-
824 while (lo <= hi)
lo <= hiDescription
TRUEevaluated 138892085 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 387088 times by 1 test
Evaluated by:
  • Self test
387088-138892085
825 {-
826 mid = (lo + hi) / 2;-
827-
828 j = shell_builtins[mid].name[0] - name[0];-
829-
830 if (j == 0)
j == 0Description
TRUEevaluated 52496589 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 86395496 times by 1 test
Evaluated by:
  • Self test
52496589-86395496
831 j = strcmp (shell_builtins[mid].name, name);
executed 52496589 times by 1 test: j = __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( shell_builtins[mid].name ) && __builtin_constant_p ( name ) && (__s1_len = __builtin_strlen ( shell_builtins[mid].name ), __s2_len = __builtin_strlen ( name ), (!((size_t)(const void ...nst unsigned char *) (const char *) ( name ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( shell_builtins[mid].name , name )))); }) ;
Executed by:
  • Self test
never executed: __result = (((const unsigned char *) (const char *) ( shell_builtins[mid].name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-52496589
832-
833 if (j == 0)
j == 0Description
TRUEevaluated 33931597 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 104960488 times by 1 test
Evaluated by:
  • Self test
33931597-104960488
834 {-
835 /* It must have a function pointer. It must be enabled, or we-
836 must have explicitly allowed disabled functions to be found,-
837 and it must not have been deleted. */-
838 if (shell_builtins[mid].function &&
shell_builtins[mid].functionDescription
TRUEevaluated 33931595 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-33931595
839 ((shell_builtins[mid].flags & BUILTIN_DELETED) == 0) &&
((shell_builti... & 0x02) == 0)Description
TRUEevaluated 33931595 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-33931595
840 ((shell_builtins[mid].flags & BUILTIN_ENABLED) || disabled_okay))
(shell_builtin....flags & 0x01)Description
TRUEevaluated 33931586 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
disabled_okayDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-33931586
841 return (&shell_builtins[mid]);
executed 33931594 times by 1 test: return (&shell_builtins[mid]);
Executed by:
  • Self test
33931594
842 else-
843 return ((struct builtin *)NULL);
executed 3 times by 1 test: return ((struct builtin *) ((void *)0) );
Executed by:
  • Self test
3
844 }-
845 if (j > 0)
j > 0Description
TRUEevaluated 62649418 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 42311070 times by 1 test
Evaluated by:
  • Self test
42311070-62649418
846 hi = mid - 1;
executed 62649418 times by 1 test: hi = mid - 1;
Executed by:
  • Self test
62649418
847 else-
848 lo = mid + 1;
executed 42311070 times by 1 test: lo = mid + 1;
Executed by:
  • Self test
42311070
849 }-
850 return ((struct builtin *)NULL);
executed 387088 times by 1 test: return ((struct builtin *) ((void *)0) );
Executed by:
  • Self test
387088
851}-
852-
853/* Return the pointer to the function implementing builtin command NAME. */-
854sh_builtin_func_t *-
855find_shell_builtin (name)-
856 char *name;-
857{-
858 current_builtin = builtin_address_internal (name, 0);-
859 return (current_builtin ? current_builtin->function : (sh_builtin_func_t *)NULL);
executed 33083849 times by 1 test: return (current_builtin ? current_builtin->function : (sh_builtin_func_t *) ((void *)0) );
Executed by:
  • Self test
33083849
860}-
861-
862/* Return the address of builtin with NAME, whether it is enabled or not. */-
863sh_builtin_func_t *-
864builtin_address (name)-
865 char *name;-
866{-
867 current_builtin = builtin_address_internal (name, 1);-
868 return (current_builtin ? current_builtin->function : (sh_builtin_func_t *)NULL);
executed 3 times by 1 test: return (current_builtin ? current_builtin->function : (sh_builtin_func_t *) ((void *)0) );
Executed by:
  • Self test
3
869}-
870-
871/* Return the function implementing the builtin NAME, but only if it is a-
872 POSIX.2 special builtin. */-
873sh_builtin_func_t *-
874find_special_builtin (name)-
875 char *name;-
876{-
877 current_builtin = builtin_address_internal (name, 0);-
878 return ((current_builtin && (current_builtin->flags & SPECIAL_BUILTIN)) ?
executed 454 times by 1 test: return ((current_builtin && (current_builtin->flags & 0x08)) ? current_builtin->function : (sh_builtin_func_t *) ((void *)0) );
Executed by:
  • Self test
454
879 current_builtin->function :
executed 454 times by 1 test: return ((current_builtin && (current_builtin->flags & 0x08)) ? current_builtin->function : (sh_builtin_func_t *) ((void *)0) );
Executed by:
  • Self test
454
880 (sh_builtin_func_t *)NULL);
executed 454 times by 1 test: return ((current_builtin && (current_builtin->flags & 0x08)) ? current_builtin->function : (sh_builtin_func_t *) ((void *)0) );
Executed by:
  • Self test
454
881}-
882 -
883static int-
884shell_builtin_compare (sbp1, sbp2)-
885 struct builtin *sbp1, *sbp2;-
886{-
887 int result;-
888-
889 if ((result = sbp1->name[0] - sbp2->name[0]) == 0)
(result = sbp1...>name[0]) == 0Description
TRUEevaluated 511883 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1474157 times by 1 test
Evaluated by:
  • Self test
511883-1474157
890 result = strcmp (sbp1->name, sbp2->name);
executed 511883 times by 1 test: result = __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ( sbp1->name ) && __builtin_constant_p ( sbp2->name ) && (__s1_len = __builtin_strlen ( sbp1->name ), __s2_len = __builtin_strlen ( sbp2->name ), (!((size_t)(const void *)(( sbp1->...unsigned char *) (const char *) ( sbp2->name ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) ( sbp2->name ))[3] - __s2[3]); } } __result; }))) : __builtin_strcmp ( sbp1->name , sbp2->name )))); }) ;
Executed by:
  • Self test
never executed: __result = (((const unsigned char *) (const char *) ( sbp1->name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( sbp2->name ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-511883
891-
892 return (result);
executed 1986040 times by 1 test: return (result);
Executed by:
  • Self test
1986040
893}-
894-
895/* Sort the table of shell builtins so that the binary search will work-
896 in find_shell_builtin. */-
897void-
898initialize_shell_builtins ()-
899{-
900 qsort (shell_builtins, num_shell_builtins, sizeof (struct builtin),-
901 (QSFUNC *)shell_builtin_compare);-
902}
executed 5447 times by 1 test: end of block
Executed by:
  • Self test
5447
903-
904#if !defined (HELP_BUILTIN)-
905void-
906builtin_help ()-
907{-
908 printf ("%s: %s\n", this_command_name, _("help not available in this version"));-
909}-
910#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2