1 /* A more useful interface to strtol.
3 Copyright (C) 1995-1996, 1998-1999, 2001-2004, 2006-2016 Free Software
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.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #define N_(msgid) msgid
30 /* Report an error for an invalid integer in an option argument.
32 ERR is the error code returned by one of the xstrto* functions.
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 '-'
41 ARG is the option-argument containing the integer.
43 After reporting an error, exit with status EXIT_STATUS if it is
47 xstrtol_error (enum strtol_error err,
48 int opt_idx, char c, struct option const *long_options,
52 char const *hyphens = "--";
55 char option_buffer[2];
63 msgid = N_("invalid %s%s argument '%s'");
66 case LONGINT_INVALID_SUFFIX_CHAR:
67 case LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW:
68 msgid = N_("invalid suffix in %s%s argument '%s'");
71 case LONGINT_OVERFLOW:
72 msgid = N_("%s%s argument '%s' too large");
80 option_buffer[1] = '\0';
81 option = option_buffer;
84 option = long_options[opt_idx].name;
86 error (exit_status, 0, gettext (msgid), hyphens, option, arg);
89 /* Like xstrtol_error, except exit with a failure status. */
92 xstrtol_fatal (enum strtol_error err,
93 int opt_idx, char c, struct option const *long_options,
96 xstrtol_error (err, opt_idx, c, long_options, arg, exit_failure);