Exit with failure status if we are unable to list any files or
[oweals/busybox.git] / coreutils / test.c
index 0ed777194463130fb9e8cc92ec40513aaa2ef661..acd6947d98de1160d15ff2c6ecd71f0453076b72 100644 (file)
  *     "This program is in the Public Domain."
  */
 
-#include "internal.h"
+#include "busybox.h"
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <ctype.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#define BB_DECLARE_EXTERN
+#define bb_need_help
+#include "messages.c"
 
 /* test(1) accepts the following grammar:
        oexpr   ::= aexpr | aexpr "-o" oexpr ;
@@ -180,18 +182,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 ]");
+                       fatalError("missing ]\n");
                argv[argc] = NULL;
        }
-       if (strcmp(argv[1], "--help") == 0) {
-               usage("test EXPRESSION\n"
-                         "or   [ EXPRESSION ]\n\n"
-                               "Checks file types and compares values returning an exit\n"
-                               "code determined by the value of EXPRESSION.\n");
-       }
-
        /* Implement special cases from POSIX.2, section 4.62.4 */
        switch (argc) {
        case 1:
@@ -229,7 +224,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
@@ -238,9 +233,9 @@ syntax(op, msg)
        char    *msg;
 {
        if (op && *op)
-               fatalError("%s: %s", op, msg);
+               fatalError("%s: %s\n", op, msg);
        else
-               fatalError("%s", msg);
+               fatalError("%s\n", msg);
 }
 
 static int
@@ -366,7 +361,7 @@ filstat(nm, mode)
        enum token mode;
 {
        struct stat s;
-       int i;
+       unsigned int i;
 
        if (mode == FILSYM) {
 #ifdef S_IFLNK
@@ -475,13 +470,13 @@ getn(s)
        r = strtol(s, &p, 10);
 
        if (errno != 0)
-         fatalError("%s: out of range", s);
+         fatalError("%s: out of range\n", s);
 
        while (isspace(*p))
          p++;
        
        if (*p)
-         fatalError("%s: bad number", s);
+         fatalError("%s: bad number\n", s);
 
        return (int) r;
 }
@@ -529,7 +524,7 @@ char *path;
 int mode;
 {
        struct stat st;
-       int euid = geteuid();
+       unsigned int euid = geteuid();
 
        if (stat (path, &st) < 0)
                return (-1);
@@ -560,9 +555,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);
 }