Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/xstrtol-error.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /* A more useful interface to strtol. | - | ||||||
2 | - | |||||||
3 | Copyright (C) 1995-1996, 1998-1999, 2001-2004, 2006-2018 Free Software | - | ||||||
4 | Foundation, Inc. | - | ||||||
5 | - | |||||||
6 | This program is free software: you can redistribute it and/or modify | - | ||||||
7 | it under the terms of the GNU General Public License as published by | - | ||||||
8 | the Free Software Foundation; either version 3 of the License, or | - | ||||||
9 | (at your option) any later version. | - | ||||||
10 | - | |||||||
11 | This program is distributed in the hope that it will be useful, | - | ||||||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||
14 | GNU General Public License for more details. | - | ||||||
15 | - | |||||||
16 | You should have received a copy of the GNU General Public License | - | ||||||
17 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | - | ||||||
18 | - | |||||||
19 | #include <config.h> | - | ||||||
20 | #include "xstrtol.h" | - | ||||||
21 | - | |||||||
22 | #include <stdlib.h> | - | ||||||
23 | - | |||||||
24 | #include "error.h" | - | ||||||
25 | #include "exitfail.h" | - | ||||||
26 | #include "gettext.h" | - | ||||||
27 | - | |||||||
28 | #define N_(msgid) msgid | - | ||||||
29 | - | |||||||
30 | /* Report an error for an invalid integer in an option argument. | - | ||||||
31 | - | |||||||
32 | ERR is the error code returned by one of the xstrto* functions. | - | ||||||
33 | - | |||||||
34 | Use OPT_IDX to decide whether to print the short option string "C" | - | ||||||
35 | or "-C" or a long option string derived from LONG_OPTION. OPT_IDX | - | ||||||
36 | is -2 if the short option "C" was used, without any leading "-"; it | - | ||||||
37 | is -1 if the short option "-C" was used; otherwise it is an index | - | ||||||
38 | into LONG_OPTIONS, which should have a name preceded by two '-' | - | ||||||
39 | characters. | - | ||||||
40 | - | |||||||
41 | ARG is the option-argument containing the integer. | - | ||||||
42 | - | |||||||
43 | After reporting an error, exit with status EXIT_STATUS if it is | - | ||||||
44 | nonzero. */ | - | ||||||
45 | - | |||||||
46 | static void | - | ||||||
47 | xstrtol_error (enum strtol_error err, | - | ||||||
48 | int opt_idx, char c, struct option const *long_options, | - | ||||||
49 | char const *arg, | - | ||||||
50 | int exit_status) | - | ||||||
51 | { | - | ||||||
52 | char const *hyphens = "--"; | - | ||||||
53 | char const *msgid; | - | ||||||
54 | char const *option; | - | ||||||
55 | char option_buffer[2]; | - | ||||||
56 | - | |||||||
57 | switch (err) | - | ||||||
58 | { | - | ||||||
59 | default: never executed: default: | 0 | ||||||
60 | abort (); never executed: abort (); | 0 | ||||||
61 | - | |||||||
62 | case LONGINT_INVALID: code before this statement never executed: case LONGINT_INVALID: executed 22 times by 7 tests: case LONGINT_INVALID: Executed by:
| 0-22 | ||||||
63 | msgid = N_("invalid %s%s argument '%s'"); | - | ||||||
64 | break; executed 22 times by 7 tests: break; Executed by:
| 22 | ||||||
65 | - | |||||||
66 | case LONGINT_INVALID_SUFFIX_CHAR: never executed: case LONGINT_INVALID_SUFFIX_CHAR: | 0 | ||||||
67 | case LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW: executed 1 time by 1 test: case LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW: Executed by:
| 1 | ||||||
68 | msgid = N_("invalid suffix in %s%s argument '%s'"); | - | ||||||
69 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||
70 | - | |||||||
71 | case LONGINT_OVERFLOW: executed 1 time by 1 test: case LONGINT_OVERFLOW: Executed by:
| 1 | ||||||
72 | msgid = N_("%s%s argument '%s' too large"); | - | ||||||
73 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||
74 | } | - | ||||||
75 | - | |||||||
76 | if (opt_idx < 0)
| 7-17 | ||||||
77 | { | - | ||||||
78 | hyphens -= opt_idx; | - | ||||||
79 | option_buffer[0] = c; | - | ||||||
80 | option_buffer[1] = '\0'; | - | ||||||
81 | option = option_buffer; | - | ||||||
82 | } executed 7 times by 3 tests: end of block Executed by:
| 7 | ||||||
83 | else | - | ||||||
84 | option = long_options[opt_idx].name; executed 17 times by 7 tests: option = long_options[opt_idx].name; Executed by:
| 17 | ||||||
85 | - | |||||||
86 | error (exit_status, 0, gettext (msgid), hyphens, option, arg); | - | ||||||
87 | } never executed: end of block | 0 | ||||||
88 | - | |||||||
89 | /* Like xstrtol_error, except exit with a failure status. */ | - | ||||||
90 | - | |||||||
91 | void | - | ||||||
92 | xstrtol_fatal (enum strtol_error err, | - | ||||||
93 | int opt_idx, char c, struct option const *long_options, | - | ||||||
94 | char const *arg) | - | ||||||
95 | { | - | ||||||
96 | xstrtol_error (err, opt_idx, c, long_options, arg, exit_failure); | - | ||||||
97 | abort (); never executed: abort (); | 0 | ||||||
98 | } | - | ||||||
Source code | Switch to Preprocessed file |