Mercurial > hg > octave-kai > gnulib-hg
annotate lib/xstrtol.h @ 5848:a48fb0e98c8c
*** empty log message ***
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sat, 14 May 2005 06:03:57 +0000 |
parents | a535859efd14 |
children | 19c2e5121b2f |
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 |
4934
0ffd1692e066
Exit-status fixes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4788
diff
changeset
|
3 Copyright (C) 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004 Free |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
4 Software Foundation, Inc. |
3412
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
5 |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
6 This program is free software; you can redistribute it and/or modify |
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 |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
9 any later version. |
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 |
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
17 along with this program; if not, write to the Free Software Foundation, |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5159
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
3412
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
19 |
764 | 20 #ifndef XSTRTOL_H_ |
21 # define XSTRTOL_H_ 1 | |
366 | 22 |
4934
0ffd1692e066
Exit-status fixes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4788
diff
changeset
|
23 # include "exitfail.h" |
0ffd1692e066
Exit-status fixes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4788
diff
changeset
|
24 |
1782
891c8561137d
(__xstrtol, __strtol, __unsigned): Remove macro decls.
Jim Meyering <jim@meyering.net>
parents:
1393
diff
changeset
|
25 # if HAVE_INTTYPES_H |
4132
98b37cab8b76
More consistent inttypes.h / stdint.h handling.
Bruno Haible <bruno@clisp.org>
parents:
3412
diff
changeset
|
26 # include <inttypes.h> |
5159 | 27 # endif |
28 # if HAVE_STDINT_H | |
29 # include <stdint.h> | |
760 | 30 # endif |
366 | 31 |
1170 | 32 # ifndef _STRTOL_ERROR |
366 | 33 enum strtol_error |
34 { | |
4788
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
35 LONGINT_OK = 0, |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
36 |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
37 /* 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
|
38 errors occurred. */ |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
39 LONGINT_OVERFLOW = 1, |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
40 LONGINT_INVALID_SUFFIX_CHAR = 2, |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
41 |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
42 LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
43 | LONGINT_OVERFLOW), |
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
44 LONGINT_INVALID = 4 |
366 | 45 }; |
46 typedef enum strtol_error strtol_error; | |
1170 | 47 # endif |
366 | 48 |
1782
891c8561137d
(__xstrtol, __strtol, __unsigned): Remove macro decls.
Jim Meyering <jim@meyering.net>
parents:
1393
diff
changeset
|
49 # define _DECLARE_XSTRTOL(name, type) \ |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
50 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
|
51 _DECLARE_XSTRTOL (xstrtol, long int) |
891c8561137d
(__xstrtol, __strtol, __unsigned): Remove macro decls.
Jim Meyering <jim@meyering.net>
parents:
1393
diff
changeset
|
52 _DECLARE_XSTRTOL (xstrtoul, unsigned long int) |
3379 | 53 _DECLARE_XSTRTOL (xstrtoimax, intmax_t) |
1782
891c8561137d
(__xstrtol, __strtol, __unsigned): Remove macro decls.
Jim Meyering <jim@meyering.net>
parents:
1393
diff
changeset
|
54 _DECLARE_XSTRTOL (xstrtoumax, uintmax_t) |
366 | 55 |
760 | 56 # define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \ |
366 | 57 do \ |
58 { \ | |
759 | 59 switch ((Err)) \ |
366 | 60 { \ |
4788
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
61 default: \ |
366 | 62 abort (); \ |
63 \ | |
64 case LONGINT_INVALID: \ | |
759 | 65 error ((Exit_code), 0, "invalid %s `%s'", \ |
66 (Argument_type_string), (Str)); \ | |
366 | 67 break; \ |
68 \ | |
69 case LONGINT_INVALID_SUFFIX_CHAR: \ | |
4788
33e8f958b651
Handle invalid suffixes and overflow independently, so that
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
70 case LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW: \ |
3412
0053a9244567
* lib/xstrtol.h: Add copyright notice.
Jim Meyering <jim@meyering.net>
parents:
3379
diff
changeset
|
71 error ((Exit_code), 0, "invalid character following %s in `%s'", \ |
759 | 72 (Argument_type_string), (Str)); \ |
366 | 73 break; \ |
74 \ | |
75 case LONGINT_OVERFLOW: \ | |
1782
891c8561137d
(__xstrtol, __strtol, __unsigned): Remove macro decls.
Jim Meyering <jim@meyering.net>
parents:
1393
diff
changeset
|
76 error ((Exit_code), 0, "%s `%s' too large", \ |
759 | 77 (Argument_type_string), (Str)); \ |
366 | 78 break; \ |
79 } \ | |
80 } \ | |
81 while (0) | |
82 | |
760 | 83 # define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \ |
4934
0ffd1692e066
Exit-status fixes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4788
diff
changeset
|
84 _STRTOL_ERROR (exit_failure, Str, Argument_type_string, Err) |
373 | 85 |
760 | 86 # define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \ |
759 | 87 _STRTOL_ERROR (0, Str, Argument_type_string, Err) |
373 | 88 |
764 | 89 #endif /* not XSTRTOL_H_ */ |