5 #include "xstrtol.h" /* Get definition for __P before use. */
10 __unsigned long int __strtol __P ((const char *, char **, int base));
35 #define ULONG_MAX ((unsigned long) ~(unsigned long) 0)
39 #define LONG_MAX ((long int) (ULONG_MAX >> 1))
42 #define BKM_SCALE(x, scale_factor, error_return) \
45 if ((x) > (double) __ZLONG_MAX / (scale_factor)) \
46 return (error_return); \
47 (x) *= (scale_factor); \
51 __unsigned long int __strtol ();
56 __xstrtol (s, ptr, base, val, valid_suffixes)
60 __unsigned long int *val;
61 const char *valid_suffixes;
65 __unsigned long int tmp;
67 assert (0 <= base && base <= 36);
69 p = (ptr ? ptr : &t_ptr);
72 tmp = __strtol (s, p, base);
74 return LONGINT_OVERFLOW;
76 return LONGINT_INVALID;
85 return LONGINT_INVALID_SUFFIX_CHAR;
88 if (**p != '\0' && strchr (valid_suffixes, **p))
93 BKM_SCALE (tmp, 512, LONGINT_OVERFLOW);
103 BKM_SCALE (tmp, 1024, LONGINT_OVERFLOW);
108 BKM_SCALE (tmp, 1024 * 1024, LONGINT_OVERFLOW);
113 BKM_SCALE (tmp, 2, LONGINT_OVERFLOW);
118 return LONGINT_INVALID_SUFFIX_CHAR;
127 #ifdef TESTING_XSTRTO
135 main (int argc, char** argv)
140 program_name = argv[0];
141 for (i=1; i<argc; i++)
144 __unsigned long int val;
146 s_err = __xstrtol (argv[i], &p, 0, &val, "bckmw");
147 if (s_err == LONGINT_OK)
149 printf ("%s->%lu (%s)\n", argv[i], val, p);
153 STRTOL_FATAL_ERROR (argv[i], "arg", s_err);
158 #endif /* TESTING_XSTRTO */