Add Magnus Damm and fix alpha sorting
[oweals/busybox.git] / test.c
diff --git a/test.c b/test.c
index 85d06a83a7f8f0ec552cdd79bb2fde4757653bd8..9c66cbb87150544fd391c70580b04aeeb75816ab 100644 (file)
--- a/test.c
+++ b/test.c
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * echo implementation for busybox
+ * test implementation for busybox
  *
  * Copyright (c) by a whole pile of folks: 
  *
  *     "This program is in the Public Domain."
  */
 
-#include "internal.h"
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <ctype.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include "busybox.h"
 
 /* test(1) accepts the following grammar:
        oexpr   ::= aexpr | aexpr "-o" oexpr ;
@@ -108,10 +107,10 @@ enum token_types {
        PAREN
 };
 
-struct t_op {
+static const struct t_op {
        const char *op_text;
        short op_num, op_type;
-} const ops [] = {
+} ops [] = {
        {"-r",  FILRD,  UNOP},
        {"-w",  FILWR,  UNOP},
        {"-x",  FILEX,  UNOP},
@@ -154,8 +153,8 @@ struct t_op {
        {0,     0,      0}
 };
 
-char **t_wp;
-struct t_op const *t_wp_op;
+static char **t_wp;
+static struct t_op const *t_wp_op;
 static gid_t *group_array = NULL;
 static int ngroups;
 
@@ -180,12 +179,11 @@ test_main(int argc, char** argv)
 {
        int     res;
 
-       if (strcmp(argv[0], "[") == 0) {
+       if (strcmp(applet_name, "[") == 0) {
                if (strcmp(argv[--argc], "]"))
-                       fatalError("missing ]");
+                       error_msg_and_die("missing ]");
                argv[argc] = NULL;
        }
-
        /* Implement special cases from POSIX.2, section 4.62.4 */
        switch (argc) {
        case 1:
@@ -223,7 +221,7 @@ test_main(int argc, char** argv)
        if (*t_wp != NULL && *++t_wp != NULL)
                syntax(*t_wp, "unknown operand");
 
-       exit( res);
+       return( res);
 }
 
 static void
@@ -232,9 +230,9 @@ syntax(op, msg)
        char    *msg;
 {
        if (op && *op)
-               fatalError("%s: %s", op, msg);
+               error_msg_and_die("%s: %s", op, msg);
        else
-               fatalError("%s", msg);
+               error_msg_and_die("%s", msg);
 }
 
 static int
@@ -360,7 +358,7 @@ filstat(nm, mode)
        enum token mode;
 {
        struct stat s;
-       int i;
+       unsigned int i;
 
        if (mode == FILSYM) {
 #ifdef S_IFLNK
@@ -469,13 +467,13 @@ getn(s)
        r = strtol(s, &p, 10);
 
        if (errno != 0)
-         fatalError("%s: out of range", s);
+         error_msg_and_die("%s: out of range", s);
 
        while (isspace(*p))
          p++;
        
        if (*p)
-         fatalError("%s: bad number", s);
+         error_msg_and_die("%s: bad number", s);
 
        return (int) r;
 }
@@ -523,7 +521,7 @@ char *path;
 int mode;
 {
        struct stat st;
-       int euid = geteuid();
+       unsigned int euid = geteuid();
 
        if (stat (path, &st) < 0)
                return (-1);
@@ -554,9 +552,7 @@ static void
 initialize_group_array ()
 {
        ngroups = getgroups(0, NULL);
-       if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
-               fatalError("Out of space");
-
+       group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
        getgroups(ngroups, group_array);
 }