Mercurial > hg > octave-shane > gnulib-hg
annotate lib/xstrtol.h @ 13706:b236a91e37b9
pthread: add pthread_spin_destroy
* lib/pthread.in.h (pthread_spin_destroy): New function.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 20 Sep 2010 16:14:49 -0700 |
parents | fcd269d69e88 |
children | 97fc9a21a8fb |
rev | line source |
---|---|
3412
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
1 /* A more useful interface to strtol. |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
2 |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12518
diff
changeset
|
3 Copyright (C) 1995-1996, 1998-1999, 2001-2004, 2006-2010 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. |
3412
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
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 |
3412
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
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. |
3412
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
10 |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
11 This program is distributed in the hope that it will be useful, |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
14 GNU General Public License for more details. |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
15 |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
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/>. */ |
3412
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
18 |
764 | 19 #ifndef XSTRTOL_H_ |
20 # define XSTRTOL_H_ 1 | |
366 | 21 |
9143
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
22 # include <getopt.h> |
7162
19c2e5121b2f
Add and change modules to make it easier for coreutils to use
Paul Eggert <eggert@cs.ucla.edu>
parents:
5848
diff
changeset
|
23 # include <inttypes.h> |
366 | 24 |
1170 | 25 # ifndef _STRTOL_ERROR |
366 | 26 enum strtol_error |
27 { | |
4788
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
28 LONGINT_OK = 0, |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
29 |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
30 /* These two values can be ORed together, to indicate that both |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
31 errors occurred. */ |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
32 LONGINT_OVERFLOW = 1, |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
33 LONGINT_INVALID_SUFFIX_CHAR = 2, |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
34 |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
35 LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9613
diff
changeset
|
36 | LONGINT_OVERFLOW), |
4788
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
37 LONGINT_INVALID = 4 |
366 | 38 }; |
39 typedef enum strtol_error strtol_error; | |
1170 | 40 # endif |
366 | 41 |
1782
891c8561137d
(__xstrtol, __strtol, __unsigned): Remove macro decls.
Jim Meyering <jim@meyering.net>
parents:
1393
diff
changeset
|
42 # define _DECLARE_XSTRTOL(name, type) \ |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
43 strtol_error name (const char *, char **, int, type *, const char *); |
1782
891c8561137d
(__xstrtol, __strtol, __unsigned): Remove macro decls.
Jim Meyering <jim@meyering.net>
parents:
1393
diff
changeset
|
44 _DECLARE_XSTRTOL (xstrtol, long int) |
891c8561137d
(__xstrtol, __strtol, __unsigned): Remove macro decls.
Jim Meyering <jim@meyering.net>
parents:
1393
diff
changeset
|
45 _DECLARE_XSTRTOL (xstrtoul, unsigned long int) |
3379 | 46 _DECLARE_XSTRTOL (xstrtoimax, intmax_t) |
1782
891c8561137d
(__xstrtol, __strtol, __unsigned): Remove macro decls.
Jim Meyering <jim@meyering.net>
parents:
1393
diff
changeset
|
47 _DECLARE_XSTRTOL (xstrtoumax, uintmax_t) |
366 | 48 |
12814 | 49 #if HAVE_LONG_LONG_INT |
50 _DECLARE_XSTRTOL (xstrtoll, long long int) | |
51 _DECLARE_XSTRTOL (xstrtoull, unsigned long long int) | |
52 #endif | |
53 | |
9143
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
54 #ifndef __attribute__ |
9613
c4fa39bf5223
Don't redefine __attribute__ without a need.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
55 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) |
9143
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
56 # define __attribute__(x) |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
57 # endif |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
58 #endif |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
59 |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
60 #ifndef ATTRIBUTE_NORETURN |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
61 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
62 #endif |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
63 |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
64 /* 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:
9141
diff
changeset
|
65 |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
66 ERR is the error code returned by one of the xstrto* functions. |
366 | 67 |
9143
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
68 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:
9141
diff
changeset
|
69 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:
9141
diff
changeset
|
70 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:
9141
diff
changeset
|
71 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:
9141
diff
changeset
|
72 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:
9141
diff
changeset
|
73 characters. |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
74 |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
75 ARG is the option-argument containing the integer. |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
76 |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
77 After reporting an error, exit with a failure status. */ |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
78 |
4290c9101f09
* NEWS: In xstrtol, remove STRTOL_FATAL_ERROR and add xstrtol_fatal.
Paul Eggert <eggert@cs.ucla.edu>
parents:
9141
diff
changeset
|
79 void xstrtol_fatal (enum strtol_error, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9613
diff
changeset
|
80 int, char, struct option const *, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9613
diff
changeset
|
81 char const *) ATTRIBUTE_NORETURN; |
373 | 82 |
764 | 83 #endif /* not XSTRTOL_H_ */ |