tweak comment
[coreutils.git] / lib / xstrtol.h
blob7a9a024457f5c40a56d689c074eebd6d994dc66f
1 #ifndef XSTRTOL_H_
2 # define XSTRTOL_H_ 1
4 # if HAVE_INTTYPES_H
5 # include <inttypes.h> /* for uintmax_t */
6 # endif
8 # ifndef PARAMS
9 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
10 # define PARAMS(Args) Args
11 # else
12 # define PARAMS(Args) ()
13 # endif
14 # endif
16 # ifndef _STRTOL_ERROR
17 enum strtol_error
19 LONGINT_OK, LONGINT_INVALID, LONGINT_INVALID_SUFFIX_CHAR, LONGINT_OVERFLOW
21 typedef enum strtol_error strtol_error;
22 # endif
24 # define _DECLARE_XSTRTOL(name, type) \
25 strtol_error \
26 name PARAMS ((const char *s, char **ptr, int base, \
27 type *val, const char *valid_suffixes));
28 _DECLARE_XSTRTOL (xstrtol, long int)
29 _DECLARE_XSTRTOL (xstrtoul, unsigned long int)
30 _DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
32 # define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
33 do \
34 { \
35 switch ((Err)) \
36 { \
37 case LONGINT_OK: \
38 abort (); \
40 case LONGINT_INVALID: \
41 error ((Exit_code), 0, "invalid %s `%s'", \
42 (Argument_type_string), (Str)); \
43 break; \
45 case LONGINT_INVALID_SUFFIX_CHAR: \
46 error ((Exit_code), 0, "invalid character following %s `%s'", \
47 (Argument_type_string), (Str)); \
48 break; \
50 case LONGINT_OVERFLOW: \
51 error ((Exit_code), 0, "%s `%s' too large", \
52 (Argument_type_string), (Str)); \
53 break; \
54 } \
55 } \
56 while (0)
58 # define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \
59 _STRTOL_ERROR (2, Str, Argument_type_string, Err)
61 # define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \
62 _STRTOL_ERROR (0, Str, Argument_type_string, Err)
64 #endif /* not XSTRTOL_H_ */