.
[coreutils.git] / lib / xstrtol.h
blob5715134c8e0345ceeb3115c7a9476f5eb0862fc3
1 #ifndef XSTRTOL_H_
2 # define XSTRTOL_H_ 1
4 # if STRING_TO_UNSIGNED
5 # define __xstrtol xstrtoul
6 # define __strtol strtoul
7 # define __unsigned unsigned
8 # else
9 # define __xstrtol xstrtol
10 # define __strtol strtol
11 # define __unsigned /* empty */
12 # endif
14 # ifndef PARAMS
15 # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
16 # define PARAMS(Args) Args
17 # else
18 # define PARAMS(Args) ()
19 # endif
20 # endif
22 # ifndef _STRTOL_ERROR
23 enum strtol_error
25 LONGINT_OK, LONGINT_INVALID, LONGINT_INVALID_SUFFIX_CHAR, LONGINT_OVERFLOW
27 typedef enum strtol_error strtol_error;
28 # endif
30 strtol_error
31 __xstrtol PARAMS ((const char *s, char **ptr, int base,
32 __unsigned long int *val, const char *valid_suffixes));
34 # undef _STRTOL_ERROR
35 # define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
36 do \
37 { \
38 switch ((Err)) \
39 { \
40 case LONGINT_OK: \
41 abort (); \
43 case LONGINT_INVALID: \
44 error ((Exit_code), 0, "invalid %s `%s'", \
45 (Argument_type_string), (Str)); \
46 break; \
48 case LONGINT_INVALID_SUFFIX_CHAR: \
49 error ((Exit_code), 0, "invalid character following %s `%s'", \
50 (Argument_type_string), (Str)); \
51 break; \
53 case LONGINT_OVERFLOW: \
54 /* FIXME: make this message dependent on STRING_TO_UNSIGNED */\
55 error ((Exit_code), 0, "%s `%s' larger than maximum long int",\
56 (Argument_type_string), (Str)); \
57 break; \
58 } \
59 } \
60 while (0)
62 # define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \
63 _STRTOL_ERROR (2, Str, Argument_type_string, Err)
65 # define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \
66 _STRTOL_ERROR (0, Str, Argument_type_string, Err)
68 #endif /* not XSTRTOL_H_ */