annotate lib/xstrtol-error.c @ 17363:5a51fb7777a9

sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin Problem reported by Marco Atzeri in <http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>. * lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]: Simply delegate to the system <sys/select.h> in this case too. Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to be needed on Solaris either. * lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]: Simply delgate to the system <sys/time.h> in this case.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 19 Mar 2013 09:08:47 -0700
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* A more useful interface to strtol.
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
2
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16234
diff changeset
3 Copyright (C) 1995-1996, 1998-1999, 2001-2004, 2006-2013 Free Software
12518
b5e42ef33b49 update nearly all FSF copyright year lists to include 2009
Jim Meyering <meyering@redhat.com>
parents: 12421
diff changeset
4 Foundation, Inc.
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9143
diff changeset
6 This program is free software: you can redistribute it and/or modify
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9143
diff changeset
8 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9143
diff changeset
9 (at your option) any later version.
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 This program is distributed in the hope that it will be useful,
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 GNU General Public License for more details.
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9143
diff changeset
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 #include <config.h>
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20 #include "xstrtol.h"
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21
9142
a5e5584188ed * lib/xstrtol-error.c: Add missing include.
Eric Blake <ebb9@byu.net>
parents: 9141
diff changeset
22 #include <stdlib.h>
a5e5584188ed * lib/xstrtol-error.c: Add missing include.
Eric Blake <ebb9@byu.net>
parents: 9141
diff changeset
23
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
24 #include "error.h"
9143
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
25 #include "exitfail.h"
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 #include "gettext.h"
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27
9143
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
28 #define N_(msgid) msgid
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
29
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
30 /* Report an error for an invalid integer in an option argument.
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
31
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
32 ERR is the error code returned by one of the xstrto* functions.
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
33
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
34 Use OPT_IDX to decide whether to print the short option string "C"
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
35 or "-C" or a long option string derived from LONG_OPTION. OPT_IDX
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
36 is -2 if the short option "C" was used, without any leading "-"; it
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
37 is -1 if the short option "-C" was used; otherwise it is an index
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
38 into LONG_OPTIONS, which should have a name preceded by two '-'
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
39 characters.
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
40
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
41 ARG is the option-argument containing the integer.
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42
9143
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
43 After reporting an error, exit with status EXIT_STATUS if it is
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
44 nonzero. */
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
45
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
46 static void
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
47 xstrtol_error (enum strtol_error err,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9681
diff changeset
48 int opt_idx, char c, struct option const *long_options,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9681
diff changeset
49 char const *arg,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9681
diff changeset
50 int exit_status)
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
51 {
9143
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
52 char const *hyphens = "--";
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
53 char const *msgid;
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
54 char const *option;
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
55 char option_buffer[2];
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
56
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 switch (err)
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 {
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59 default:
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 abort ();
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 case LONGINT_INVALID:
16234
f9b906545e2f Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
63 msgid = N_("invalid %s%s argument '%s'");
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 break;
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 case LONGINT_INVALID_SUFFIX_CHAR:
9143
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
67 case LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW:
16234
f9b906545e2f Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
68 msgid = N_("invalid suffix in %s%s argument '%s'");
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
69 break;
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
70
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
71 case LONGINT_OVERFLOW:
16234
f9b906545e2f Use ', not `, for quoting output.
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
72 msgid = N_("%s%s argument '%s' too large");
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
73 break;
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 }
9143
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
75
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
76 if (opt_idx < 0)
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
77 {
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
78 hyphens -= opt_idx;
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
79 option_buffer[0] = c;
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
80 option_buffer[1] = '\0';
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
81 option = option_buffer;
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
82 }
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
83 else
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
84 option = long_options[opt_idx].name;
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
85
9681
e7e16f35a3b7 xstrtol_error: Fix typo.
Jim Meyering <meyering@redhat.com>
parents: 9309
diff changeset
86 error (exit_status, 0, gettext (msgid), hyphens, option, arg);
9141
2f9763090486 Move xstrtol messages into gnulib domain, when --pobase is used.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 }
9143
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
88
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
89 /* Like xstrtol_error, except exit with a failure status. */
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
90
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
91 void
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
92 xstrtol_fatal (enum strtol_error err,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9681
diff changeset
93 int opt_idx, char c, struct option const *long_options,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9681
diff changeset
94 char const *arg)
9143
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
95 {
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
96 xstrtol_error (err, opt_idx, c, long_options, arg, exit_failure);
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
97 abort ();
4290c9101f09 * NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents: 9142
diff changeset
98 }