summaryrefslogtreecommitdiff
path: root/lib/xstrtol.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-09-26 19:11:23 +0000
committerJim Meyering <jim@meyering.net>1998-09-26 19:11:23 +0000
commit3bf75404dc0cddbe6bc48df4a02fcaabecfcf791 (patch)
treed6a2513de6ab9c7d7eebf62815821d9ab80a528a /lib/xstrtol.c
parent09fbc76680b59d9cda236e542df69b2b7d228b23 (diff)
downloadgnulib-3bf75404dc0cddbe6bc48df4a02fcaabecfcf791.tar.gz
(__xstrtol) [STRING_TO_UNSIGNED]: Return
LONGINT_INVALID for strings that begin with `-'.
Diffstat (limited to 'lib/xstrtol.c')
-rw-r--r--lib/xstrtol.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/xstrtol.c b/lib/xstrtol.c
index 00d4b117b1..f4ba50ba28 100644
--- a/lib/xstrtol.c
+++ b/lib/xstrtol.c
@@ -69,6 +69,18 @@ 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 ();
@@ -107,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)