sbase

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

commit 954106050f5e4550393eafda57822fb195dadb1e
parent 61247e3595d0684b3b311b87d54c2e8c74ecd5be
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Fri Jun 10 14:55:01 +0100

rename estrtol
Diffstat:
Makefile | 2+-
chmod.c | 2+-
date.c | 2+-
fold.c | 2+-
head.c | 2+-
kill.c | 4++--
nl.c | 2+-
sleep.c | 2+-
tail.c | 2+-
touch.c | 2+-
util.h | 2+-
util/estrtol.c | 20++++++++++++++++++++
util/strnum.c | 20--------------------
13 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/Makefile b/Makefile @@ -7,9 +7,9 @@ LIB = \ util/concat.o \ util/enmasse.o \ util/eprintf.o \ + util/estrtol.o \ util/putword.o \ util/recurse.o \ - util/strnum.o \ SRC = \ basename.c \ diff --git a/chmod.c b/chmod.c @@ -28,7 +28,7 @@ main(int argc, char *argv[]) } if(optind == argc) eprintf("usage: %s [-Rr] mode [file...]\n", argv[0]); - octal = strnum(argv[optind++], 8); + octal = estrtol(argv[optind++], 8); /* posix doesn't specify modal bits */ if(octal & 04000) mode |= S_ISUID; diff --git a/date.c b/date.c @@ -17,7 +17,7 @@ main(int argc, char *argv[]) while((c = getopt(argc, argv, "d:")) != -1) switch(c) { case 'd': - t = strnum(optarg, 0); + t = estrtol(optarg, 0); break; default: exit(EXIT_FAILURE); diff --git a/fold.c b/fold.c @@ -29,7 +29,7 @@ main(int argc, char *argv[]) sflag = true; break; case 'w': - width = strnum(optarg, 0); + width = estrtol(optarg, 0); break; default: exit(EXIT_FAILURE); diff --git a/head.c b/head.c @@ -17,7 +17,7 @@ main(int argc, char *argv[]) while((c = getopt(argc, argv, "n:")) != -1) switch(c) { case 'n': - n = strnum(optarg, 0); + n = estrtol(optarg, 0); break; default: exit(EXIT_FAILURE); diff --git a/kill.c b/kill.c @@ -53,14 +53,14 @@ main(int argc, char *argv[]) eprintf("usage: %s [-s signal] [pid...]\n" " %s -l [signum]\n", argv[0], argv[0]); - sig = (optind == argc) ? 0 : strnum(argv[optind], 0); + sig = (optind == argc) ? 0 : estrtol(argv[optind], 0); for(i = 0; i < LEN(sigs); i++) if(sigs[i].sig == sig || sig == 0) putword(sigs[i].name); putchar('\n'); } else for(; optind < argc; optind++) { - pid = strnum(argv[optind], 0); + pid = estrtol(argv[optind], 0); if(kill(pid, sig) == -1) eprintf("kill %d:", pid); } diff --git a/nl.c b/nl.c @@ -30,7 +30,7 @@ main(int argc, char *argv[]) eprintf("usage: %s [-b mode] [-i increment] [-s separator] [file...]\n", argv[0]); break; case 'i': - incr = strnum(optarg, 0); + incr = estrtol(optarg, 0); break; case 's': sep = optarg; diff --git a/sleep.c b/sleep.c @@ -13,7 +13,7 @@ main(int argc, char *argv[]) if(optind != argc-1) eprintf("usage: %s seconds\n", argv[0]); - seconds = strnum(argv[optind], 0); + seconds = estrtol(argv[optind], 0); while((seconds = sleep(seconds)) > 0) ; return EXIT_SUCCESS; diff --git a/tail.c b/tail.c @@ -20,7 +20,7 @@ main(int argc, char *argv[]) while((c = getopt(argc, argv, "n:")) != -1) switch(c) { case 'n': - n = abs(strnum(optarg, 0)); + n = abs(estrtol(optarg, 0)); if(optarg[0] == '+') tail = dropinit; break; diff --git a/touch.c b/touch.c @@ -26,7 +26,7 @@ main(int argc, char *argv[]) cflag = true; break; case 't': - t = strnum(optarg, 0); + t = estrtol(optarg, 0); break; default: exit(EXIT_FAILURE); diff --git a/util.h b/util.h @@ -5,6 +5,6 @@ char *agetcwd(void); void enmasse(int, char **, int (*)(const char *, const char *)); void eprintf(const char *, ...); +long estrtol(const char *, int); void putword(const char *); void recurse(const char *, void (*)(const char *)); -long strnum(const char *, int); diff --git a/util/estrtol.c b/util/estrtol.c @@ -0,0 +1,20 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdio.h> +#include <stdlib.h> +#include "../util.h" + +long +estrtol(const char *s, int base) +{ + char *end; + long n; + + n = strtol(s, &end, base); + if(*end != '\0') { + if(base == 0) + eprintf("%s: not a number\n", s); + else + eprintf("%s: not a base %d number\n", s, base); + } + return n; +} diff --git a/util/strnum.c b/util/strnum.c @@ -1,20 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include <stdio.h> -#include <stdlib.h> -#include "../util.h" - -long -strnum(const char *s, int base) -{ - char *end; - long n; - - n = strtol(s, &end, base); - if(*end != '\0') { - if(base == 0) - eprintf("%s: not a number\n", s); - else - eprintf("%s: not a base %d number\n", s, base); - } - return n; -}