diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2007-10-06 22:42:14 +0800 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2007-10-06 22:42:14 +0800 |
commit | aa82f69dea2f2d5fe4337dfb12cea54fabdab175 (patch) | |
tree | 3648d6fc0a7280d8bb7d437ac3a2e6e548705599 /src/bltin | |
parent | [VAR] Remove setvarsafe (diff) | |
download | dash-aa82f69dea2f2d5fe4337dfb12cea54fabdab175.tar.gz dash-aa82f69dea2f2d5fe4337dfb12cea54fabdab175.zip |
[BUILTIN] Use intmax_t arithmetic in test
This patch adds the function atomax10 and uses it in test(1) so that we support intmax_t comparisons.
Diffstat (limited to 'src/bltin')
-rw-r--r-- | src/bltin/test.c | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/src/bltin/test.c b/src/bltin/test.c index 7d49569..bc8b175 100644 --- a/src/bltin/test.c +++ b/src/bltin/test.c @@ -11,8 +11,7 @@ #include <sys/stat.h> #include <sys/types.h> -#include <ctype.h> -#include <errno.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -145,13 +144,17 @@ static int binop(void); static int filstat(char *, enum token); static enum token t_lex(char *); static int isoperand(void); -static int getn(const char *); static int newerf(const char *, const char *); static int olderf(const char *, const char *); static int equalf(const char *, const char *); static int test_st_mode(const struct stat64 *, int); static int bash_group_member(gid_t); +static inline intmax_t getn(const char *s) +{ + return atomax10(s); +} + int testcmd(int argc, char **argv) { @@ -396,28 +399,6 @@ isoperand(void) return 0; } -/* atoi with error detection */ -static int -getn(const char *s) -{ - char *p; - long r; - - errno = 0; - r = strtol(s, &p, 10); - - if (errno != 0) - error("%s: out of range", s); - - while (isspace((unsigned char)*p)) - p++; - - if (*p) - error("%s: bad number", s); - - return (int) r; -} - static int newerf (const char *f1, const char *f2) { |