summaryrefslogtreecommitdiff
path: root/src/stty.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-01-17 17:41:00 +0000
committerJim Meyering <jim@meyering.net>1996-01-17 17:41:00 +0000
commit4ad4b8aaec3e4780dba1a3de39d8f5b4622d0361 (patch)
tree263fd80a9ca245295efdd08ccd9625ddf667bdf9 /src/stty.c
parent0f32a825245c28c9365e11230d97bad4d5e2408c (diff)
downloadcoreutils-4ad4b8aaec3e4780dba1a3de39d8f5b4622d0361.tar.xz
(integer_arg): Use xstrtol instead of open-coding this.
Diffstat (limited to 'src/stty.c')
-rw-r--r--src/stty.c36
1 files changed, 2 insertions, 34 deletions
diff --git a/src/stty.c b/src/stty.c
index 9907ecb99..87ca09a39 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -51,6 +51,7 @@
#include "version.h"
#include "long-options.h"
#include "error.h"
+#include "xstrtol.h"
#if defined(GWINSZ_BROKEN) /* Such as for SCO UNIX 3.2.2. */
# undef TIOCGWINSZ
@@ -1647,7 +1648,6 @@ visible (unsigned int ch)
return (const char *) buf;
}
-/* FIXME: use xstrtol, but verify that result is not negative. */
/* Parse string S as an integer, using decimal radix by default,
but allowing octal and hex numbers as in C. */
/* From `od' by Richard Stallman. */
@@ -1656,39 +1656,7 @@ static long
integer_arg (char *s)
{
long value;
- int radix = 10;
- char *p = s;
- int c;
-
- if (*p != '0')
- radix = 10;
- else if (*++p == 'x')
- {
- radix = 16;
- p++;
- }
- else
- radix = 8;
-
- value = 0;
- while (((c = *p++) >= '0' && c <= '9')
- || (radix == 16 && (c & ~40) >= 'A' && (c & ~40) <= 'Z'))
- {
- value *= radix;
- if (c >= '0' && c <= '9')
- value += c - '0';
- else
- value += (c & ~40) - 'A';
- }
-
- if (c == 'b')
- value *= 512;
- else if (c == 'B')
- value *= 1024;
- else
- p--;
-
- if (*p)
+ if (xstrtol (s, NULL, 0, &value, "bB") != LONGINT_OK)
{
error (0, 0, _("invalid integer argument `%s'"), s);
usage (1);