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