/*
* test implementation for busybox
*
- * Copyright (c) by a whole pile of folks:
+ * Copyright (c) by a whole pile of folks:
*
- * test(1); version 7-like -- author Erik Baalbergen
- * modified by Eric Gisin to be used as built-in.
- * modified by Arnold Robbins to add SVR3 compatibility
- * (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
- * modified by J.T. Conklin for NetBSD.
- * modified by Herbert Xu to be used as built-in in ash.
- * modified by Erik Andersen <andersen@codepoet.org> to be used
- * in busybox.
+ * test(1); version 7-like -- author Erik Baalbergen
+ * modified by Eric Gisin to be used as built-in.
+ * modified by Arnold Robbins to add SVR3 compatibility
+ * (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
+ * modified by J.T. Conklin for NetBSD.
+ * modified by Herbert Xu to be used as built-in in ash.
+ * modified by Erik Andersen <andersen@codepoet.org> to be used
+ * in busybox.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original copyright notice states:
- * "This program is in the Public Domain."
+ * "This program is in the Public Domain."
*/
#include <sys/types.h>
unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"|
"-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S";
- binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
+ binary-operator ::= "="|"=="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
"-nt"|"-ot"|"-ef";
operand ::= <any legal UNIX file name>
*/
"-L", FILSYM, UNOP}, {
"-S", FILSOCK, UNOP}, {
"=", STREQ, BINOP}, {
+ "==", STREQ, BINOP}, {
"!=", STRNE, BINOP}, {
"<", STRLT, BINOP}, {
">", STRGT, BINOP}, {
0, 0, 0}
};
+#ifdef CONFIG_FEATURE_TEST_64
+typedef int64_t arith_t;
+#else
+typedef int arith_t;
+#endif
+
static char **t_wp;
static struct t_op const *t_wp_op;
static gid_t *group_array = NULL;
static int ngroups;
static enum token t_lex(char *s);
-static int oexpr(enum token n);
-static int aexpr(enum token n);
-static int nexpr(enum token n);
+static arith_t oexpr(enum token n);
+static arith_t aexpr(enum token n);
+static arith_t nexpr(enum token n);
static int binop(void);
-static int primary(enum token n);
+static arith_t primary(enum token n);
static int filstat(char *nm, enum token mode);
-static int getn(const char *s);
+static arith_t getn(const char *s);
static int newerf(const char *f1, const char *f2);
static int olderf(const char *f1, const char *f2);
static int equalf(const char *f1, const char *f2);
static int is_a_group_member(gid_t gid);
static void initialize_group_array(void);
-extern int test_main(int argc, char **argv)
+int test_main(int argc, char **argv)
{
int res;
bb_error_msg_and_die("missing ]");
argv[argc] = NULL;
}
+ if (strcmp(bb_applet_name, "[[") == 0) {
+ if (strcmp(argv[--argc], "]]"))
+ bb_error_msg_and_die("missing ]]");
+ argv[argc] = NULL;
+ }
/* Implement special cases from POSIX.2, section 4.62.4 */
switch (argc) {
case 1:
}
}
-static int oexpr(enum token n)
+static arith_t oexpr(enum token n)
{
- int res;
+ arith_t res;
res = aexpr(n);
if (t_lex(*++t_wp) == BOR) {
return res;
}
-static int aexpr(enum token n)
+static arith_t aexpr(enum token n)
{
- int res;
+ arith_t res;
res = nexpr(n);
if (t_lex(*++t_wp) == BAND)
return res;
}
-static int nexpr(enum token n)
+static arith_t nexpr(enum token n)
{
if (n == UNOT)
return !nexpr(t_lex(*++t_wp));
return primary(n);
}
-static int primary(enum token n)
+static arith_t primary(enum token n)
{
- int res;
+ arith_t res;
if (n == EOI) {
syntax(NULL, "argument expected");
return strlen(*t_wp) > 0;
}
-static int binop()
+static int binop(void)
{
const char *opnd1, *opnd2;
struct t_op const *op;
}
/* atoi with error detection */
-static int getn(const char *s)
+static arith_t getn(const char *s)
{
char *p;
+#ifdef CONFIG_FEATURE_TEST_64
+ long long r;
+#else
long r;
+#endif
errno = 0;
+#ifdef CONFIG_FEATURE_TEST_64
+ r = strtoll(s, &p, 10);
+#else
r = strtol(s, &p, 10);
+#endif
if (errno != 0)
bb_error_msg_and_die("%s: out of range", s);
if (*(bb_skip_whitespace(p)))
bb_error_msg_and_die("%s: bad number", s);
- return (int) r;
+ return r;
}
static int newerf(const char *f1, const char *f2)
return (-1);
}
-static void initialize_group_array()
+static void initialize_group_array(void)
{
ngroups = getgroups(0, NULL);
group_array = xrealloc(group_array, ngroups * sizeof(gid_t));