1 /* A more useful interface to strtol.
2 Copyright 1995, 1996, 1998, 1999, 2001 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 # include <inttypes.h> /* for uintmax_t */
26 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
27 # define PARAMS(Args) Args
29 # define PARAMS(Args) ()
33 # ifndef _STRTOL_ERROR
36 LONGINT_OK
, LONGINT_INVALID
, LONGINT_INVALID_SUFFIX_CHAR
, LONGINT_OVERFLOW
38 typedef enum strtol_error strtol_error
;
41 # define _DECLARE_XSTRTOL(name, type) \
43 name PARAMS ((const char *s, char **ptr, int base, \
44 type *val, const char *valid_suffixes));
45 _DECLARE_XSTRTOL (xstrtol
, long int)
46 _DECLARE_XSTRTOL (xstrtoul
, unsigned long int)
47 _DECLARE_XSTRTOL (xstrtoimax
, intmax_t)
48 _DECLARE_XSTRTOL (xstrtoumax
, uintmax_t)
50 # define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
58 case LONGINT_INVALID: \
59 error ((Exit_code), 0, "invalid %s `%s'", \
60 (Argument_type_string), (Str)); \
63 case LONGINT_INVALID_SUFFIX_CHAR: \
64 error ((Exit_code), 0, "invalid character following %s in `%s'", \
65 (Argument_type_string), (Str)); \
68 case LONGINT_OVERFLOW: \
69 error ((Exit_code), 0, "%s `%s' too large", \
70 (Argument_type_string), (Str)); \
76 # define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \
77 _STRTOL_ERROR (2, Str, Argument_type_string, Err)
79 # define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \
80 _STRTOL_ERROR (0, Str, Argument_type_string, Err)
82 #endif /* not XSTRTOL_H_ */