summaryrefslogtreecommitdiffstats
path: root/commands/cmp.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-10-08 16:22:33 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-11-04 12:36:19 +0100
commit6aaba64b0c7044c242329499d5d4c53c3d0cde3a (patch)
tree958a1d47f0252440ced0eb7974d2900a27c21646 /commands/cmp.c
parent6cf5b986d98a19a8c05f6813b8944a4f5f784dd0 (diff)
downloadbarebox-6aaba64b0c7044c242329499d5d4c53c3d0cde3a.tar.gz
commands: implement 'cmp' command
This command compares two files. It does not show the differences, it only returns successfully if both files are identical and with an error if they differ. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/cmp.c')
-rw-r--r--commands/cmp.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/commands/cmp.c b/commands/cmp.c
new file mode 100644
index 0000000..c493988
--- /dev/null
+++ b/commands/cmp.c
@@ -0,0 +1,42 @@
+/*
+ * cmp - determine if two files differ
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <common.h>
+#include <command.h>
+#include <complete.h>
+#include <libfile.h>
+
+static int do_cmp(int argc, char *argv[])
+{
+ if (argc != 3)
+ return COMMAND_ERROR_USAGE;
+
+ return compare_file(argv[1], argv[2]);
+}
+
+BAREBOX_CMD_HELP_START(cmp)
+BAREBOX_CMD_HELP_TEXT("Returns successfully if the two files are the same, return with an error if not")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(cmp)
+ .cmd = do_cmp,
+ BAREBOX_CMD_DESC("compare two files")
+ BAREBOX_CMD_OPTS("FILE1 FILE2")
+ BAREBOX_CMD_GROUP(CMD_GRP_FILE)
+ BAREBOX_CMD_HELP(cmd_cmp_help)
+BAREBOX_CMD_END