Don't include stdio.h.
[gnulib.git] / lib / xstrtol.c
index 6c11f7f..f4ba50b 100644 (file)
 # include <config.h>
 #endif
 
+/* Some pre-ANSI implementations (e.g. SunOS 4)
+   need stderr defined if assertion checking is enabled.  */
+#include <stdio.h>
+
 #if STDC_HEADERS
 # include <stdlib.h>
 #endif
@@ -34,7 +38,6 @@
 # endif
 #endif
 
-#define NDEBUG
 #include <assert.h>
 
 #include <errno.h>
@@ -66,14 +69,24 @@ extern int errno;
 # define LONG_MAX TYPE_MAXIMUM (long int)
 #endif
 
+#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
+# define IN_CTYPE_DOMAIN(c) 1
+#else
+# define IN_CTYPE_DOMAIN(c) isascii(c)
+#endif
+
+#ifdef isblank
+# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
+#else
+# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
+#endif
+
 #include "xstrtol.h"
 
 __unsigned long int __strtol ();
 
 static int
-bkm_scale (x, scale_factor)
-     __unsigned long int *x;
-     int scale_factor;
+bkm_scale (__unsigned long int *x, int scale_factor)
 {
   __unsigned long int product = *x * scale_factor;
   if (*x != product / scale_factor)
@@ -83,10 +96,7 @@ bkm_scale (x, scale_factor)
 }
 
 static int
-bkm_scale_by_power (x, base, power)
-     __unsigned long int *x;
-     int base;
-     int power;
+bkm_scale_by_power (__unsigned long int *x, int base, int power)
 {
   while (power--)
     if (bkm_scale (x, base))
@@ -109,6 +119,18 @@ __xstrtol (const char *s, char **ptr, int strtol_base,
 
   p = (ptr ? ptr : &t_ptr);
 
+#if STRING_TO_UNSIGNED
+  {
+    const char *q = s;
+    while (ISBLANK (*q))
+      {
+       ++q;
+      }
+    if (*q == '-')
+      return LONGINT_INVALID;
+  }
+#endif
+
   errno = 0;
   tmp = __strtol (s, p, strtol_base);
   if (errno != 0)