*** empty log message ***
[coreutils.git] / lib / xstrtol.h
blob5f351a7ba7ed01700da8529fa6276443c70f12f3
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 # define __ZLONG_MAX ULONG_MAX
9 # else
10 # define __xstrtol xstrtol
11 # define __strtol strtol
12 # define __unsigned /* empty */
13 # define __ZLONG_MAX LONG_MAX
14 # endif
16 # undef PARAMS
17 # if defined (__STDC__) && __STDC__
18 # define PARAMS(Args) Args
19 # else
20 # define PARAMS(Args) ()
21 # endif
23 #ifndef _STRTOL_ERROR
24 enum strtol_error
26 LONGINT_OK, LONGINT_INVALID, LONGINT_INVALID_SUFFIX_CHAR, LONGINT_OVERFLOW
28 typedef enum strtol_error strtol_error;
29 #endif
31 strtol_error
32 __xstrtol PARAMS ((const char *s, char **ptr, int base,
33 __unsigned long int *val, const char *valid_suffixes));
35 #undef _STRTOL_ERROR
36 # define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
37 do \
38 { \
39 switch ((Err)) \
40 { \
41 case LONGINT_OK: \
42 abort (); \
44 case LONGINT_INVALID: \
45 error ((Exit_code), 0, "invalid %s `%s'", \
46 (Argument_type_string), (Str)); \
47 break; \
49 case LONGINT_INVALID_SUFFIX_CHAR: \
50 error ((Exit_code), 0, "invalid character following %s `%s'", \
51 (Argument_type_string), (Str)); \
52 break; \
54 case LONGINT_OVERFLOW: \
55 /* FIXME: make this message dependent on STRING_TO_UNSIGNED */\
56 error ((Exit_code), 0, "%s `%s' larger than maximum long int",\
57 (Argument_type_string), (Str)); \
58 break; \
59 } \
60 } \
61 while (0)
63 # define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \
64 _STRTOL_ERROR (2, Str, Argument_type_string, Err)
66 # define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \
67 _STRTOL_ERROR (0, Str, Argument_type_string, Err)
69 #endif /* not XSTRTOL_H_ */