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