]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_test.c
LG Optimus Black (P970) codename sniper support
[karo-tx-uboot.git] / common / cmd_test.c
index b927d09eb3e01204b928a4900219e45b63dca24e..7285f75469fb15f7cf0daa1e9541ca6b3c887834 100644 (file)
@@ -5,17 +5,9 @@
  * SPDX-License-Identifier:    GPL-2.0+
  */
 
-/*
- * Define _STDBOOL_H here to avoid macro expansion of true and false.
- * If the future code requires macro true or false, remove this define
- * and undef true and false before U_BOOT_CMD. This define and comment
- * shall be removed if change to U_BOOT_CMD is made to take string
- * instead of stringifying it.
- */
-#define _STDBOOL_H
-
 #include <common.h>
 #include <command.h>
+#include <fs.h>
 
 #define OP_INVALID     0
 #define OP_NOT         1
@@ -33,6 +25,7 @@
 #define OP_INT_LE      13
 #define OP_INT_GT      14
 #define OP_INT_GE      15
+#define OP_FILE_EXISTS 16
 
 const struct {
        int arg;
@@ -55,6 +48,7 @@ const struct {
        {0, "-a", OP_AND, 1},
        {0, "-z", OP_STR_EMPTY, 2},
        {0, "-n", OP_STR_NEMPTY, 2},
+       {0, "-e", OP_FILE_EXISTS, 4},
 };
 
 static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -77,7 +71,7 @@ static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        left = argc - 1;
        ap = argv + 1;
-       expr = -1;
+       expr = 0;
        last_unop = OP_INVALID;
        last_binop = OP_INVALID;
        last_expr = -1;
@@ -143,6 +137,9 @@ static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                        expr = simple_strtol(ap[0], NULL, 10) >=
                                        simple_strtol(ap[2], NULL, 10);
                        break;
+               case OP_FILE_EXISTS:
+                       expr = file_exists(ap[1], ap[2], ap[3], FS_TYPE_ANY);
+                       break;
                }
 
                switch (op) {
@@ -185,6 +182,9 @@ static int do_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        return expr;
 }
 
+#undef true
+#undef false
+
 U_BOOT_CMD(
        test,   CONFIG_SYS_MAXARGS,     1,      do_test,
        "minimal test like /bin/sh",