31 #define ULONG_MAX ((unsigned long) ~(unsigned long) 0)
35 #define LONG_MAX ((long int) (ULONG_MAX >> 1))
40 #define BKM_SCALE(x, scale_factor, error_return) \
43 if ((x) > (double) __ZLONG_MAX / (scale_factor)) \
44 return (error_return); \
45 (x) *= (scale_factor); \
49 __unsigned
long int __strtol ();
54 __xstrtol (s
, ptr
, base
, val
, valid_suffixes
)
58 __unsigned
long int *val
;
59 const char *valid_suffixes
;
63 __unsigned
long int tmp
;
65 assert (0 <= base
&& base
<= 36);
67 p
= (ptr
? ptr
: &t_ptr
);
70 tmp
= __strtol (s
, p
, base
);
72 return LONGINT_OVERFLOW
;
74 return LONGINT_INVALID
;
83 return LONGINT_INVALID_SUFFIX_CHAR
;
86 if (**p
!= '\0' && strchr (valid_suffixes
, **p
))
91 BKM_SCALE (tmp
, 512, LONGINT_OVERFLOW
);
101 BKM_SCALE (tmp
, 1024, LONGINT_OVERFLOW
);
106 BKM_SCALE (tmp
, 1024 * 1024, LONGINT_OVERFLOW
);
111 BKM_SCALE (tmp
, 2, LONGINT_OVERFLOW
);
116 return LONGINT_INVALID_SUFFIX_CHAR
;
125 #ifdef TESTING_XSTRTO
133 main (int argc
, char** argv
)
138 program_name
= argv
[0];
139 for (i
=1; i
<argc
; i
++)
142 __unsigned
long int val
;
144 s_err
= __xstrtol (argv
[i
], &p
, 0, &val
, "bckmw");
145 if (s_err
== LONGINT_OK
)
147 printf ("%s->%lu (%s)\n", argv
[i
], val
, p
);
151 STRTOL_FATAL_ERROR (argv
[i
], "arg", s_err
);
156 #endif /* TESTING_XSTRTO */