changeset 21190:73c4119f4a88

(__xstrtol) [STRING_TO_UNSIGNED]: Return LONGINT_INVALID for strings that begin with `-'.
author Jim Meyering <jim@meyering.net>
date Sat, 26 Sep 1998 19:11:23 +0000
parents 00243cb8a429
children f8f5765e26d0
files lib/xstrtol.c
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/xstrtol.c	Mon Sep 21 12:05:49 1998 +0000
+++ b/lib/xstrtol.c	Sat Sep 26 19:11:23 1998 +0000
@@ -69,6 +69,18 @@
 # 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 ();
@@ -107,6 +119,18 @@
 
   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)