[hackers] [ubase] Use estrtoul() in dd(1) || sin
 
commit 6ea2b1aa53ec29d3cf9adc7c981bfa4a4c33f29b
Author: sin <sin_AT_2f30.org>
Date:   Wed Jun 4 13:07:34 2014 +0100
    Use estrtoul() in dd(1)
    
    Allow specifications in hex and octal as well.
diff --git a/Makefile b/Makefile
index 04fe64d..a68d3ce 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -10,6 +10,7 @@ LIB = \
         util/ealloc.o         \
         util/eprintf.o        \
         util/estrtol.o        \
+	util/estrtoul.o       \
         util/explicit_bzero.o \
         util/proc.o           \
         util/putword.o        \
diff --git a/dd.c b/dd.c
index 9942253..2685d54 100644
--- a/dd.c
+++ b/dd.c
_AT_@ -237,15 +237,15 @@ main(int argc, char *argv[])
                 else if (sscanf(argv[i], "of=%1023c", buf) == 1)
                         config.out = strdup(buf);
                 else if (sscanf(argv[i], "skip=%1023c", buf) == 1)
-			config.skip = strtoul(buf, NULL, 10);
+			config.skip = estrtoul(buf, 0);
                 else if (sscanf(argv[i], "seek=%1023c", buf) == 1)
-			config.seek = strtoul(buf, NULL, 10);
+			config.seek = estrtoul(buf, 0);
                 else if (sscanf(argv[i], "count=%1023c", buf) == 1)
-			config.count = strtoul(buf, NULL, 10);
+			config.count = estrtoul(buf, 0);
                 else if (strcmp(argv[i], "direct") == 0)
                         config.direct = 1;
                 else if (sscanf(argv[i], "bs=%1023c", buf) == 1)
-			config.bs = strtoul(buf, NULL, 10);
+			config.bs = estrtoul(buf, 0);
                 else if (strcmp(argv[i], "bs") == 0)
                         config.bs = 0;
                 else if (strcmp(argv[i], "quiet") == 0)
diff --git a/util.h b/util.h
index 0ed7f6b..f43c6ee 100644
--- a/util.h
+++ b/util.h
_AT_@ -27,6 +27,9 @@ char *estrdup(const char *);
 /* estrtol.c */
 long estrtol(const char *, int);
 
+/* estrtoul.c */
+unsigned long estrtoul(const char *, int);
+
 /* explicit_bzero.c */
 #undef explicit_bzero
 void explicit_bzero(void *, size_t);
diff --git a/util/estrtoul.c b/util/estrtoul.c
new file mode 100644
index 0000000..f56a720
--- /dev/null
+++ b/util/estrtoul.c
_AT_@ -0,0 +1,26 @@
+/* See LICENSE file for copyright and license details. */
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "../util.h"
+
+unsigned long
+estrtoul(const char *s, int base)
+{
+	char *end;
+	unsigned long n;
+
+	errno = 0;
+	n = strtoul(s, &end, base);
+	if(*end != '
Received on Wed Jun 04 2014 - 14:13:07 CEST
This archive was generated by hypermail 2.3.0
: Wed Jun 04 2014 - 14:24:11 CEST