commit 193e3bd7bcfead3c7345ad161f83434d3f51b11c
parent f3afd8162fad9e712b67ada1eb07763230154d78
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date: Wed, 20 Feb 2019 13:04:57 +0000
Merge "[dlang] Implement cat and echo"
Diffstat:
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/src/romfw/dlang.c b/src/romfw/dlang.c
@@ -221,10 +221,10 @@ do_help(const struct cmd *cmd, struct args *args)
static int
do_cat(const struct cmd *cmd, struct args *args)
{
-#if 0
int fd, n;
char buf[100];
- if ((fd = open(args->argv[1], OREAD)) < 0)
+
+ if ((fd = open(args->argv[1], O_READ)) < 0)
return -1;
while ((n = read(fd, buf, sizeof(buf))) > 0)
@@ -232,7 +232,6 @@ do_cat(const struct cmd *cmd, struct args *args)
if (close(fd) < 0 || n < 0)
return -1;
-#endif
return 0;
}
@@ -256,8 +255,20 @@ do_ls(const struct cmd *cmd, struct args *args)
}
static int
-do_chdir(const struct cmd *cmd, struct args *args)
+do_echo(const struct cmd *cmd, struct args *args)
{
+ int fd, n;
+ char *s;
+
+ if ((fd = open(args->argv[1], O_WRITE)) < 0)
+ return -1;
+
+ s = args->argv[2];
+ write(fd, s, strlen(s));
+
+ if (close(fd) < 0 || n < 0)
+ return -1;
+
return 0;
}
@@ -422,18 +433,25 @@ static const struct cmd cmds[] = {
.helpmsg = "Print the content of an entry: cat path",
},
{
- .name = "cd",
- .eval = do_chdir,
+ .name = "ls",
+ .eval = do_ls,
.min = 2,
.max = 2,
- .helpmsg = "change the current directory: cd path",
+ .helpmsg = "list content of a directory: ls path",
},
{
- .name = "ls",
- .eval = do_ls,
+ .name = "cat",
+ .eval = do_cat,
.min = 2,
.max = 2,
- .helpmsg = "list content of a directory: ls path",
+ .helpmsg = "read content from a file: cat path",
+ },
+ {
+ .name = "echo",
+ .eval = do_echo,
+ .min = 3,
+ .max = 3,
+ .helpmsg = "write content to a file: echo string path",
},
{
.name = NULL