aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-08-11 02:45:47 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-08-11 02:45:47 +0000
commit73db8be80a2bca50e0d29a162f5d431f70e227c8 (patch)
tree974bb226421e4baecba178833433ba9cb13b0bdc
parentd2c6f9a1f9d5974155f1a7224aecbafba91631a1 (diff)
downloadbusybox-w32-73db8be80a2bca50e0d29a162f5d431f70e227c8.tar.gz
busybox-w32-73db8be80a2bca50e0d29a162f5d431f70e227c8.tar.bz2
busybox-w32-73db8be80a2bca50e0d29a162f5d431f70e227c8.zip
Patch from Bastian Blank to add 64 bit support to the test command.
Example of broken usage: ./busybox test 2147483648 -gt 2147483648
-rw-r--r--coreutils/Config.in7
-rw-r--r--coreutils/test.c42
2 files changed, 35 insertions, 14 deletions
diff --git a/coreutils/Config.in b/coreutils/Config.in
index c995e55ff..e1f0516fd 100644
--- a/coreutils/Config.in
+++ b/coreutils/Config.in
@@ -455,6 +455,13 @@ if !CONFIG_ASH && !CONFIG_HUSH && !CONFIG_LASH && !CONFIG_MSH
455 and bash) have test builtin. 455 and bash) have test builtin.
456endif 456endif
457 457
458config CONFIG_FEATURE_TEST_64
459 bool " Extend test to 64 bit"
460 default n
461 depends on CONFIG_TEST
462 help
463 Enable 64-bit support in test.
464
458config CONFIG_TOUCH 465config CONFIG_TOUCH
459 bool "touch" 466 bool "touch"
460 default n 467 default n
diff --git a/coreutils/test.c b/coreutils/test.c
index 419da5101..8fa6d166f 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -155,19 +155,25 @@ static const struct t_op {
155 0, 0, 0} 155 0, 0, 0}
156}; 156};
157 157
158#ifdef CONFIG_FEATURE_TEST_64
159typedef int64_t arith_t;
160#else
161typedef int arith_t;
162#endif
163
158static char **t_wp; 164static char **t_wp;
159static struct t_op const *t_wp_op; 165static struct t_op const *t_wp_op;
160static gid_t *group_array = NULL; 166static gid_t *group_array = NULL;
161static int ngroups; 167static int ngroups;
162 168
163static enum token t_lex(char *s); 169static enum token t_lex(char *s);
164static int oexpr(enum token n); 170static arith_t oexpr(enum token n);
165static int aexpr(enum token n); 171static arith_t aexpr(enum token n);
166static int nexpr(enum token n); 172static arith_t nexpr(enum token n);
167static int binop(void); 173static int binop(void);
168static int primary(enum token n); 174static arith_t primary(enum token n);
169static int filstat(char *nm, enum token mode); 175static int filstat(char *nm, enum token mode);
170static int getn(const char *s); 176static arith_t getn(const char *s);
171static int newerf(const char *f1, const char *f2); 177static int newerf(const char *f1, const char *f2);
172static int olderf(const char *f1, const char *f2); 178static int olderf(const char *f1, const char *f2);
173static int equalf(const char *f1, const char *f2); 179static int equalf(const char *f1, const char *f2);
@@ -232,9 +238,9 @@ static void syntax(const char *op, const char *msg)
232 } 238 }
233} 239}
234 240
235static int oexpr(enum token n) 241static arith_t oexpr(enum token n)
236{ 242{
237 int res; 243 arith_t res;
238 244
239 res = aexpr(n); 245 res = aexpr(n);
240 if (t_lex(*++t_wp) == BOR) { 246 if (t_lex(*++t_wp) == BOR) {
@@ -244,9 +250,9 @@ static int oexpr(enum token n)
244 return res; 250 return res;
245} 251}
246 252
247static int aexpr(enum token n) 253static arith_t aexpr(enum token n)
248{ 254{
249 int res; 255 arith_t res;
250 256
251 res = nexpr(n); 257 res = nexpr(n);
252 if (t_lex(*++t_wp) == BAND) 258 if (t_lex(*++t_wp) == BAND)
@@ -255,16 +261,16 @@ static int aexpr(enum token n)
255 return res; 261 return res;
256} 262}
257 263
258static int nexpr(enum token n) 264static arith_t nexpr(enum token n)
259{ 265{
260 if (n == UNOT) 266 if (n == UNOT)
261 return !nexpr(t_lex(*++t_wp)); 267 return !nexpr(t_lex(*++t_wp));
262 return primary(n); 268 return primary(n);
263} 269}
264 270
265static int primary(enum token n) 271static arith_t primary(enum token n)
266{ 272{
267 int res; 273 arith_t res;
268 274
269 if (n == EOI) { 275 if (n == EOI) {
270 syntax(NULL, "argument expected"); 276 syntax(NULL, "argument expected");
@@ -441,13 +447,21 @@ static enum token t_lex(char *s)
441} 447}
442 448
443/* atoi with error detection */ 449/* atoi with error detection */
444static int getn(const char *s) 450static arith_t getn(const char *s)
445{ 451{
446 char *p; 452 char *p;
453#ifdef CONFIG_FEATURE_TEST_64
454 long long r;
455#else
447 long r; 456 long r;
457#endif
448 458
449 errno = 0; 459 errno = 0;
460#ifdef CONFIG_FEATURE_TEST_64
461 r = strtoll(s, &p, 10);
462#else
450 r = strtol(s, &p, 10); 463 r = strtol(s, &p, 10);
464#endif
451 465
452 if (errno != 0) 466 if (errno != 0)
453 bb_error_msg_and_die("%s: out of range", s); 467 bb_error_msg_and_die("%s: out of range", s);
@@ -456,7 +470,7 @@ static int getn(const char *s)
456 if (*(bb_skip_whitespace(p))) 470 if (*(bb_skip_whitespace(p)))
457 bb_error_msg_and_die("%s: bad number", s); 471 bb_error_msg_and_die("%s: bad number", s);
458 472
459 return (int) r; 473 return r;
460} 474}
461 475
462static int newerf(const char *f1, const char *f2) 476static int newerf(const char *f1, const char *f2)