sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit fd562481f3ca0b7cd9b4af69bdb6b232a3011f35
parent 8c359daee319b7fed45166c7965f6134b0a0d3cb
Author: FRIGN <dev@frign.de>
Date:   Fri, 30 Jan 2015 16:52:44 +0100

Convert estrto{l, ul} to estrtonum

Enough with this insanity!

Diffstat:
MMakefile | 2--
Marg.h | 2+-
Mcols.c | 5++---
Mdate.c | 3++-
Mdu.c | 4++--
Mexpand.c | 5++---
Mfold.c | 5+++--
Mhead.c | 3++-
Dlibutil/estrtol.c | 27---------------------------
Dlibutil/estrtoul.c | 26--------------------------
Mnice.c | 4++--
Mnl.c | 3++-
Mrenice.c | 2+-
Mseq.c | 5+++--
Msplit.c | 4++--
Mtail.c | 3++-
Mtouch.c | 3++-
Munexpand.c | 3++-
Mutil.h | 2--
19 files changed, 30 insertions(+), 81 deletions(-)

diff --git a/Makefile b/Makefile @@ -39,8 +39,6 @@ LIBUTILSRC =\ libutil/eprintf.c\ libutil/eregcomp.c\ libutil/estrtod.c\ - libutil/estrtol.c\ - libutil/estrtoul.c\ libutil/fnck.c\ libutil/getlines.c\ libutil/human.c\ diff --git a/arg.h b/arg.h @@ -46,7 +46,7 @@ extern char *argv0; #define ARGC() argc_ -#define ARGNUMF(base) (brk_ = 1, estrtol(argv[0], (base))) +#define ARGNUMF(base) (brk_ = 1, estrtonum(argv[0], 0, INT_MAX)) #define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ ((x), abort(), (char *)0) :\ diff --git a/cols.c b/cols.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include <assert.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -35,9 +36,7 @@ main(int argc, char *argv[]) ARGBEGIN { case 'c': cflag = 1; - chars = estrtol(EARGF(usage()), 0); - if (chars < 3) - eprintf("%d: too few character columns"); + chars = estrtonum(EARGF(usage()), 3, LONG_MAX); break; default: usage(); diff --git a/date.c b/date.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <time.h> @@ -25,7 +26,7 @@ main(int argc, char *argv[]) t = time(NULL); ARGBEGIN { case 'd': - t = estrtol(EARGF(usage()), 0); + t = estrtonum(EARGF(usage()), 0, LLONG_MAX); break; case 'u': tztime = gmtime; diff --git a/du.c b/du.c @@ -53,7 +53,7 @@ main(int argc, char *argv[]) break; case 'd': dflag = 1; - depth = estrtol(EARGF(usage()), 0); + depth = estrtonum(EARGF(usage()), 0, LONG_MAX); break; case 's': sflag = 1; @@ -73,7 +73,7 @@ main(int argc, char *argv[]) bsize = getenv("BLOCKSIZE"); if (bsize) - blksize = estrtol(bsize, 0); + blksize = estrtonum(bsize, 0, LONG_MAX); if (kflag) blksize = 1024; diff --git a/expand.c b/expand.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -21,9 +22,7 @@ parselist(const char *s) if (*p == '\0') eprintf("empty field in tablist\n"); tablist = erealloc(tablist, (i + 1) * sizeof(*tablist)); - tablist[i] = estrtol(p, 10); - if (!tablist[i] || tablist[i] < 0) - eprintf("tab field must be positive\n"); + tablist[i] = estrtonum(p, 1, LLONG_MAX); if (i > 0 && tablist[i - 1] >= tablist[i]) eprintf("tablist must be ascending\n"); } diff --git a/fold.c b/fold.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include <ctype.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -83,10 +84,10 @@ main(int argc, char *argv[]) sflag = 1; break; case 'w': - width = estrtol(EARGF(usage()), 0); + width = estrtonum(EARGF(usage()), 1, LLONG_MAX); break; ARGNUM: - width = ARGNUMF(0); + width = ARGNUMF(10); break; default: usage(); diff --git a/head.c b/head.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -40,7 +41,7 @@ main(int argc, char *argv[]) ARGBEGIN { case 'n': - n = estrtol(EARGF(usage()), 0); + n = estrtonum(EARGF(usage()), 0, LONG_MAX); break; ARGNUM: n = ARGNUMF(0); diff --git a/libutil/estrtol.c b/libutil/estrtol.c @@ -1,27 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> - -#include "../util.h" - -long -estrtol(const char *s, int base) -{ - char *end; - long n; - - errno = 0; - n = strtol(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/libutil/estrtoul.c b/libutil/estrtoul.c @@ -1,26 +0,0 @@ -/* 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/nice.c b/nice.c @@ -12,7 +12,7 @@ static void usage(void) { - eprintf("usage: nice [-n inc] cmd [arg ...]\n"); + eprintf("usage: %s [-n inc] cmd [arg ...]\n", argv0); } int @@ -23,7 +23,7 @@ main(int argc, char *argv[]) ARGBEGIN { case 'n': - val = estrtol(EARGF(usage()), 10); + val = estrtonum(EARGF(usage()), PRIO_MIN, PRIO_MAX); break; default: usage(); diff --git a/nl.c b/nl.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <limits.h> #include <regex.h> #include <stdio.h> #include <stdlib.h> @@ -37,7 +38,7 @@ main(int argc, char *argv[]) usage(); break; case 'i': - incr = estrtol(EARGF(usage()), 0); + incr = estrtonum(EARGF(usage()), 0, LONG_MAX); break; case 's': sep = EARGF(usage()); diff --git a/renice.c b/renice.c @@ -48,7 +48,7 @@ main(int argc, char *argv[]) if (argc == 0 || !adj) usage(); - val = estrtol(adj, 10); + val = estrtonum(adj, PRIO_MIN, PRIO_MAX); for (i = 0; i < argc; i++) { who = -1; if (which == PRIO_USER) { diff --git a/seq.c b/seq.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -97,7 +98,7 @@ digitsleft(const char *d) if (*d == '+') d++; exp = strpbrk(d, "eE"); - shift = exp ? estrtol(&exp[1], 10) : 0; + shift = exp ? estrtonum(&exp[1], -INT_MAX, INT_MAX) : 0; return MAX(0, strspn(d, "-0123456789") + shift); } @@ -109,7 +110,7 @@ digitsright(const char *d) int shift, after; exp = strpbrk(d, "eE"); - shift = exp ? estrtol(&exp[1], 10) : 0; + shift = exp ? estrtonum(&exp[1], -INT_MAX, INT_MAX) : 0; after = (d = strchr(d, '.')) ? strspn(&d[1], "0123456789") : 0; return MAX(0, after - shift); diff --git a/split.c b/split.c @@ -63,10 +63,10 @@ main(int argc, char *argv[]) always = 0; tmp = ARGF(); if (tmp) - size = estrtol(tmp, 10); + size = estrtonum(tmp, 0, LLONG_MAX); break; case 'a': - slen = estrtol(EARGF(usage()), 10); + slen = estrtonum(EARGF(usage()), 0, INT_MAX); break; case 'd': base = 10; diff --git a/tail.c b/tail.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -29,7 +30,7 @@ main(int argc, char *argv[]) ARGBEGIN { case 'n': lines = EARGF(usage()); - n = abs(estrtol(lines, 0)); + n = estrtonum(lines, 0, LONG_MAX); if (lines[0] == '+') tail = dropinit; break; diff --git a/touch.c b/touch.c @@ -1,6 +1,7 @@ /* See LICENSE file for copyright and license details. */ #include <errno.h> #include <fcntl.h> +#include <limits.h> #include <stdlib.h> #include <sys/stat.h> #include <time.h> @@ -64,7 +65,7 @@ main(int argc, char *argv[]) mflag = 1; break; case 't': - t = estrtol(EARGF(usage()), 0); + t = estrtonum(EARGF(usage()), 0, LLONG_MAX); break; default: usage(); diff --git a/unexpand.c b/unexpand.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <wchar.h> @@ -25,7 +26,7 @@ main(int argc, char *argv[]) ARGBEGIN { case 't': - tabsize = estrtol(EARGF(usage()), 0); + tabsize = estrtonum(EARGF(usage()), 0, INT_MAX); if (tabsize <= 0) eprintf("unexpand: invalid tabsize\n"); /* Fallthrough: -t implies -a */ diff --git a/util.h b/util.h @@ -31,8 +31,6 @@ void eprintf(const char *, ...); 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 *);