aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-06-13 22:49:08 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-06-13 22:49:08 +0200
commit16635cc2e052897ce7c2d4989acd0b706c3ac3dd (patch)
tree35af25c96f7f6e6340c043a91b10f46593c6afce /coreutils
parenta3dcee3e8a2d41e90cc235fd407dff9fe99d8604 (diff)
downloadbusybox-w32-16635cc2e052897ce7c2d4989acd0b706c3ac3dd.tar.gz
busybox-w32-16635cc2e052897ce7c2d4989acd0b706c3ac3dd.tar.bz2
busybox-w32-16635cc2e052897ce7c2d4989acd0b706c3ac3dd.zip
test, tcpsvd, tcpsvd: shrink
function old new delta nexpr 825 826 +1 tcpudpsvd_main 1830 1822 -8 test_main 257 247 -10 binop 584 525 -59 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 1/-77) Total: -76 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/test.c52
1 files changed, 33 insertions, 19 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index ae40192a2..cfaf4ca5d 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -51,39 +51,49 @@
51 51
52enum token { 52enum token {
53 EOI, 53 EOI,
54 FILRD, 54
55 FILRD, /* file access */
55 FILWR, 56 FILWR,
56 FILEX, 57 FILEX,
58
57 FILEXIST, 59 FILEXIST,
58 FILREG, 60
61 FILREG, /* file type */
59 FILDIR, 62 FILDIR,
60 FILCDEV, 63 FILCDEV,
61 FILBDEV, 64 FILBDEV,
62 FILFIFO, 65 FILFIFO,
63 FILSOCK, 66 FILSOCK,
67
64 FILSYM, 68 FILSYM,
65 FILGZ, 69 FILGZ,
66 FILTT, 70 FILTT,
67 FILSUID, 71
72 FILSUID, /* file bit */
68 FILSGID, 73 FILSGID,
69 FILSTCK, 74 FILSTCK,
70 FILNT, 75
76 FILNT, /* file ops */
71 FILOT, 77 FILOT,
72 FILEQ, 78 FILEQ,
79
73 FILUID, 80 FILUID,
74 FILGID, 81 FILGID,
75 STREZ, 82
83 STREZ, /* str ops */
76 STRNZ, 84 STRNZ,
77 STREQ, 85 STREQ,
78 STRNE, 86 STRNE,
79 STRLT, 87 STRLT,
80 STRGT, 88 STRGT,
81 INTEQ, 89
90 INTEQ, /* int ops */
82 INTNE, 91 INTNE,
83 INTGE, 92 INTGE,
84 INTGT, 93 INTGT,
85 INTLE, 94 INTLE,
86 INTLT, 95 INTLT,
96
87 UNOT, 97 UNOT,
88 BAND, 98 BAND,
89 BOR, 99 BOR,
@@ -385,8 +395,8 @@ static int binop(void)
385 return val1 > val2; 395 return val1 > val2;
386 if (op->op_num == INTLE) 396 if (op->op_num == INTLE)
387 return val1 <= val2; 397 return val1 <= val2;
388 if (op->op_num == INTLT) 398 /*if (op->op_num == INTLT)*/
389 return val1 < val2; 399 return val1 < val2;
390 } 400 }
391 if (is_str_op(op->op_num)) { 401 if (is_str_op(op->op_num)) {
392 val1 = strcmp(opnd1, opnd2); 402 val1 = strcmp(opnd1, opnd2);
@@ -396,8 +406,8 @@ static int binop(void)
396 return val1 != 0; 406 return val1 != 0;
397 if (op->op_num == STRLT) 407 if (op->op_num == STRLT)
398 return val1 < 0; 408 return val1 < 0;
399 if (op->op_num == STRGT) 409 /*if (op->op_num == STRGT)*/
400 return val1 > 0; 410 return val1 > 0;
401 } 411 }
402 /* We are sure that these three are by now the only binops we didn't check 412 /* We are sure that these three are by now the only binops we didn't check
403 * yet, so we do not check if the class is correct: 413 * yet, so we do not check if the class is correct:
@@ -412,25 +422,29 @@ static int binop(void)
412 return b1.st_mtime > b2.st_mtime; 422 return b1.st_mtime > b2.st_mtime;
413 if (op->op_num == FILOT) 423 if (op->op_num == FILOT)
414 return b1.st_mtime < b2.st_mtime; 424 return b1.st_mtime < b2.st_mtime;
415 if (op->op_num == FILEQ) 425 /*if (op->op_num == FILEQ)*/
416 return b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino; 426 return b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino;
417 } 427 }
418 return 1; /* NOTREACHED */ 428 /*return 1; - NOTREACHED */
419} 429}
420 430
421 431
422static void initialize_group_array(void) 432static void initialize_group_array(void)
423{ 433{
424 ngroups = getgroups(0, NULL); 434 int n;
425 if (ngroups > 0) { 435
436 /* getgroups may be expensive, try to use it only once */
437 ngroups = 32;
438 do {
426 /* FIXME: ash tries so hard to not die on OOM, 439 /* FIXME: ash tries so hard to not die on OOM,
427 * and we spoil it with just one xrealloc here */ 440 * and we spoil it with just one xrealloc here */
428 /* We realloc, because test_main can be entered repeatedly by shell. 441 /* We realloc, because test_main can be entered repeatedly by shell.
429 * Testcase (ash): 'while true; do test -x some_file; done' 442 * Testcase (ash): 'while true; do test -x some_file; done'
430 * and watch top. (some_file must have owner != you) */ 443 * and watch top. (some_file must have owner != you) */
431 group_array = xrealloc(group_array, ngroups * sizeof(gid_t)); 444 n = ngroups;
432 getgroups(ngroups, group_array); 445 group_array = xrealloc(group_array, n * sizeof(gid_t));
433 } 446 ngroups = getgroups(n, group_array);
447 } while (ngroups > n);
434} 448}
435 449
436 450
@@ -717,7 +731,7 @@ int test_main(int argc, char **argv)
717 * isn't likely in the case of a shell. paranoia 731 * isn't likely in the case of a shell. paranoia
718 * prevails... 732 * prevails...
719 */ 733 */
720 ngroups = 0; 734 /*ngroups = 0; - done by INIT_S() */
721 735
722 //argc--; 736 //argc--;
723 argv++; 737 argv++;