summaryrefslogtreecommitdiffstats
path: root/common/ratp/getenv.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2018-02-24 16:01:17 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-03-01 09:39:42 +0100
commit884eeea4082b36e8cca56f2886947d934bf40238 (patch)
tree88bce3b0d85bc907a8548f14a29693994587d971 /common/ratp/getenv.c
parentec42940ea194f3089c5b2d29a06d61d7d03e94d9 (diff)
downloadbarebox-884eeea4082b36e8cca56f2886947d934bf40238.tar.gz
barebox-884eeea4082b36e8cca56f2886947d934bf40238.tar.xz
ratp: implement getenv as a standard ratp command
Also, use xstrndup() instead of the custom xmemdup_add_zero() as we're working with strings anyway. Signed-off-by: Aleksander Morgado <aleksander@aleksander.es> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/ratp/getenv.c')
-rw-r--r--common/ratp/getenv.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/common/ratp/getenv.c b/common/ratp/getenv.c
new file mode 100644
index 0000000000..b409634886
--- /dev/null
+++ b/common/ratp/getenv.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2018 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+/*
+ * RATP getenv
+ */
+
+#include <common.h>
+#include <ratp_bb.h>
+#include <malloc.h>
+#include <environment.h>
+
+static int ratp_cmd_getenv(const struct ratp_bb *req, int req_len,
+ struct ratp_bb **rsp, int *rsp_len)
+{
+ int dlen = req_len - sizeof (struct ratp_bb);
+ char *varname;
+ const char *value;
+
+ varname = xstrndup ((const char *)req->data, dlen);
+ value = getenv (varname);
+ free (varname);
+
+ dlen = strlen (value);
+
+ *rsp_len = sizeof(struct ratp_bb) + dlen;
+ *rsp = xzalloc(*rsp_len);
+ (*rsp)->type = cpu_to_be16(BB_RATP_TYPE_GETENV_RETURN);
+ memcpy ((*rsp)->data, value, dlen);
+ return 0;
+}
+
+BAREBOX_RATP_CMD_START(GETENV)
+ .request_id = BB_RATP_TYPE_GETENV,
+ .response_id = BB_RATP_TYPE_GETENV_RETURN,
+ .cmd = ratp_cmd_getenv
+BAREBOX_RATP_CMD_END