[hackers] [sbase] Add estrtoul() || sin

From: <git_AT_suckless.org>
Date: Fri, 30 Jan 2015 14:26:27 +0100 (CET)

commit 3d2b9a2ca73d948cf5da23bc0f00005060f36e04
Author: sin <sin_AT_2f30.org>
Date: Fri Jan 30 13:24:41 2015 +0000

    Add estrtoul()

diff --git a/Makefile b/Makefile
index a8ce4f0..a420784 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -40,6 +40,7 @@ LIBUTILSRC =\
         libutil/eregcomp.c\
         libutil/estrtod.c\
         libutil/estrtol.c\
+ libutil/estrtoul.c\
         libutil/fnck.c\
         libutil/getlines.c\
         libutil/human.c\
diff --git a/libutil/estrtoul.c b/libutil/estrtoul.c
new file mode 100644
index 0000000..b8907be
--- /dev/null
+++ b/libutil/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 != '\0') {
+ if (base == 0)
+ eprintf("%s: not an integer\n", s);
+ else
+ eprintf("%s: not a base %d integer\n", s, base);
+ }
+ if (errno != 0)
+ eprintf("%s:", s);
+
+ return n;
+}
diff --git a/util.h b/util.h
index f926044..f32f8b3 100644
--- a/util.h
+++ b/util.h
_AT_@ -32,6 +32,7 @@ void weprintf(const char *, ...);
 
 double estrtod(const char *);
 long estrtol(const char *, int);
+unsigned long estrtoul(const char *, int);
 
 #undef strcasestr
 char *strcasestr(const char *, const char *);
Received on Fri Jan 30 2015 - 14:26:27 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 30 2015 - 14:36:08 CET