summaryrefslogtreecommitdiffstats
path: root/commands/seed.c
diff options
context:
space:
mode:
authorOleksij Rempel <o.rempel@pengutronix.de>2017-03-22 10:14:39 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-03-30 08:23:20 +0200
commitb0a0d7c05dde1476b249aa8d6d36de0189e9eeab (patch)
tree03652cb3484dc69b97b46e449cc8d37d1b3c3992 /commands/seed.c
parenteba85be0f25dd1af9cdab3af2a4f98b14fe9c41e (diff)
downloadbarebox-b0a0d7c05dde1476b249aa8d6d36de0189e9eeab.tar.gz
add seed command
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/seed.c')
-rw-r--r--commands/seed.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/commands/seed.c b/commands/seed.c
new file mode 100644
index 0000000..e378cd7
--- /dev/null
+++ b/commands/seed.c
@@ -0,0 +1,44 @@
+/*
+ * (c) 2017 Oleksij Rempel <kernel@pengutronix.de>
+ *
+ * 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 <stdlib.h>
+#include <linux/ctype.h>
+
+static int do_seed(int argc, char *argv[])
+{
+ if (argc < 2)
+ return COMMAND_ERROR_USAGE;
+
+ if (isdigit(*argv[1])) {
+ srand(simple_strtoul(argv[1], NULL, 0));
+ return 0;
+ }
+
+ printf("numerical parameter expected\n");
+ return 1;
+}
+
+BAREBOX_CMD_HELP_START(seed)
+BAREBOX_CMD_HELP_TEXT("Seed the pseudo random number generator")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(seed)
+ .cmd = do_seed,
+ BAREBOX_CMD_DESC("seed the PRNG")
+ BAREBOX_CMD_OPTS("VALUE")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_HELP(cmd_seed_help)
+BAREBOX_CMD_END