From aa82f69dea2f2d5fe4337dfb12cea54fabdab175 Mon Sep 17 00:00:00 2001 From: Herbert Xu Date: Sat, 6 Oct 2007 22:42:14 +0800 Subject: [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. --- src/bltin/test.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) (limited to 'src/bltin/test.c') 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 #include -#include -#include +#include #include #include #include @@ -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) { -- cgit 1.4.1