OpenCoverage

operand2sig.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/operand2sig.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* operand2sig.c -- common function for parsing signal specifications-
2 Copyright (C) 2008-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* Extracted from kill.c/timeout.c by Pádraig Brady.-
18 FIXME: Move this to gnulib/str2sig.c */-
19-
20-
21/* Convert OPERAND to a signal number with printable representation SIGNAME.-
22 Return the signal number, or -1 if unsuccessful. */-
23-
24#include <config.h>-
25#include <stdio.h>-
26#include <sys/types.h>-
27#include <sys/wait.h>-
28-
29#include "system.h"-
30#include "error.h"-
31#include "quote.h"-
32#include "sig2str.h"-
33#include "operand2sig.h"-
34-
35extern int-
36operand2sig (char const *operand, char *signame)-
37{-
38 int signum;-
39-
40 if (ISDIGIT (*operand))
((unsigned int...d) - '0' <= 9)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • kill
FALSEevaluated 16 times by 2 tests
Evaluated by:
  • kill
  • timeout
11-16
41 {-
42 /* Note we don't put a limit on the maximum value passed,-
43 because we're checking shell $? values here, and ksh for-
44 example will add 256 to the signal value, thus being wider-
45 than the number of WEXITSTATUS bits.-
46 We could validate that values were not above say-
47 ((WEXITSTATUS (~0) << 1) + 1), which would cater for ksh.-
48 But some shells may use other adjustments in future to be-
49 (forward) compatible with systems that support-
50 wider exit status values as discussed at-
51 http://austingroupbugs.net/view.php?id=947 */-
52-
53 char *endp;-
54 long int l = (errno = 0, strtol (operand, &endp, 10));-
55 int i = l;-
56 signum = (operand == endp || *endp || errno || i != l ? -1 : i);
operand == endpDescription
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • kill
*endpDescription
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • kill
(*__errno_location ())Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • kill
i != lDescription
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • kill
0-11
57-
58 if (signum != -1)
signum != -1Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • kill
FALSEnever evaluated
0-11
59 {-
60 /* Note AIX uses a different bit pattern for status returned-
61 from shell and wait(), so we can't use WTERMSIG etc. here.-
62 Also ksh returns 0xFF + signal number. */-
63 signum &= signum >= 0xFF ? 0xFF : 0x7F;
signum >= 0xFFDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • kill
FALSEevaluated 10 times by 1 test
Evaluated by:
  • kill
1-10
64 }
executed 11 times by 1 test: end of block
Executed by:
  • kill
11
65 }
executed 11 times by 1 test: end of block
Executed by:
  • kill
11
66 else-
67 {-
68 /* Convert signal to upper case in the C locale, not in the-
69 current locale. Don't assume ASCII; it might be EBCDIC. */-
70 char *upcased = xstrdup (operand);-
71 char *p;-
72 for (p = upcased; *p; p++)
*pDescription
TRUEevaluated 67 times by 2 tests
Evaluated by:
  • kill
  • timeout
FALSEevaluated 16 times by 2 tests
Evaluated by:
  • kill
  • timeout
16-67
73 if (strchr ("abcdefghijklmnopqrstuvwxyz", *p))
(__extension__...wxyz" , *p )))Description
TRUEevaluated 18 times by 2 tests
Evaluated by:
  • kill
  • timeout
FALSEevaluated 49 times by 2 tests
Evaluated by:
  • kill
  • timeout
__builtin_constant_p ( *p )Description
TRUEnever evaluated
FALSEevaluated 67 times by 2 tests
Evaluated by:
  • kill
  • timeout
!__builtin_con...pqrstuvwxyz" )Description
TRUEnever evaluated
FALSEnever evaluated
( *p ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-67
74 *p += 'A' - 'a';
executed 18 times by 2 tests: *p += 'A' - 'a';
Executed by:
  • kill
  • timeout
18
75-
76 /* Look for the signal name, possibly prefixed by "SIG",-
77 and possibly lowercased. */-
78 if (!(str2sig (upcased, &signum) == 0
str2sig (upcas... &signum) == 0Description
TRUEevaluated 10 times by 2 tests
Evaluated by:
  • kill
  • timeout
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • kill
  • timeout
6-10
79 || (upcased[0] == 'S' && upcased[1] == 'I' && upcased[2] == 'G'
upcased[0] == 'S'Description
TRUEnever evaluated
FALSEevaluated 6 times by 2 tests
Evaluated by:
  • kill
  • timeout
upcased[1] == 'I'Description
TRUEnever evaluated
FALSEnever evaluated
upcased[2] == 'G'Description
TRUEnever evaluated
FALSEnever evaluated
0-6
80 && str2sig (upcased + 3, &signum) == 0)))
str2sig (upcas... &signum) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
81 signum = -1;
executed 6 times by 2 tests: signum = -1;
Executed by:
  • kill
  • timeout
6
82-
83 free (upcased);-
84 }
executed 16 times by 2 tests: end of block
Executed by:
  • kill
  • timeout
16
85-
86 if (signum < 0 || sig2str (signum, signame) != 0)
signum < 0Description
TRUEevaluated 6 times by 2 tests
Evaluated by:
  • kill
  • timeout
FALSEevaluated 21 times by 2 tests
Evaluated by:
  • kill
  • timeout
sig2str (signum, signame) != 0Description
TRUEnever evaluated
FALSEevaluated 21 times by 2 tests
Evaluated by:
  • kill
  • timeout
0-21
87 {-
88 error (0, 0, _("%s: invalid signal"), quote (operand));-
89 return -1;
executed 6 times by 2 tests: return -1;
Executed by:
  • kill
  • timeout
6
90 }-
91-
92 return signum;
executed 21 times by 2 tests: return signum;
Executed by:
  • kill
  • timeout
21
93}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2