1
1
/* A more useful interface to strtol.
2
Copyright 1995, 1996, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
3
Copyright (C) 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004 Free
4
Software Foundation, Inc.
4
6
This program is free software; you can redistribute it and/or modify
5
7
it under the terms of the GNU General Public License as published by
14
16
You should have received a copy of the GNU General Public License
15
17
along with this program; if not, write to the Free Software Foundation,
16
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
21
# define XSTRTOL_H_ 1
23
# include "exitfail.h"
22
25
# if HAVE_INTTYPES_H
23
26
# include <inttypes.h>
31
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
32
# define PARAMS(Args) Args
34
# define PARAMS(Args) ()
38
32
# ifndef _STRTOL_ERROR
41
LONGINT_OK, LONGINT_INVALID, LONGINT_INVALID_SUFFIX_CHAR, LONGINT_OVERFLOW
37
/* These two values can be ORed together, to indicate that both
40
LONGINT_INVALID_SUFFIX_CHAR = 2,
42
LONGINT_INVALID_SUFFIX_CHAR_WITH_OVERFLOW = (LONGINT_INVALID_SUFFIX_CHAR
43
46
typedef enum strtol_error strtol_error;
46
49
# define _DECLARE_XSTRTOL(name, type) \
48
name PARAMS ((const char *s, char **ptr, int base, \
49
type *val, const char *valid_suffixes));
50
strtol_error name (const char *, char **, int, type *, const char *);
50
51
_DECLARE_XSTRTOL (xstrtol, long int)
51
52
_DECLARE_XSTRTOL (xstrtoul, unsigned long int)
52
53
_DECLARE_XSTRTOL (xstrtoimax, intmax_t)
68
69
case LONGINT_INVALID_SUFFIX_CHAR: \
70
case LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW: \
69
71
error ((Exit_code), 0, "invalid character following %s in `%s'", \
70
72
(Argument_type_string), (Str)); \
81
83
# define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \
82
_STRTOL_ERROR (2, Str, Argument_type_string, Err)
84
_STRTOL_ERROR (exit_failure, Str, Argument_type_string, Err)
84
86
# define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \
85
87
_STRTOL_ERROR (0, Str, Argument_type_string, Err)