Commit 7ae7f9a0 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a "-a" append flag to filewrite

parent ae4e6105
...@@ -250,7 +250,9 @@ cmd_shell(CMD_ARGS) ...@@ -250,7 +250,9 @@ cmd_shell(CMD_ARGS)
* *
* Write strings to file * Write strings to file
* *
* filewrite /somefile "Hello" " " "World\n" * filewrite [-a] /somefile "Hello" " " "World\n"
*
* The -a flag opens the file in append mode.
* *
*/ */
...@@ -259,14 +261,19 @@ cmd_filewrite(CMD_ARGS) ...@@ -259,14 +261,19 @@ cmd_filewrite(CMD_ARGS)
{ {
FILE *fo; FILE *fo;
int n; int n;
const char *mode = "w";
(void)priv; (void)priv;
if (av == NULL) if (av == NULL)
return; return;
if (av[1] != NULL && !strcmp(av[1], "-a")) {
av++;
mode = "a";
}
if (av[1] == NULL) if (av[1] == NULL)
vtc_fatal(vl, "Need filename"); vtc_fatal(vl, "Need filename");
fo = fopen(av[1], "w"); fo = fopen(av[1], mode);
if (fo == NULL) if (fo == NULL)
vtc_fatal(vl, "Cannot open %s: %s", av[1], strerror(errno)); vtc_fatal(vl, "Cannot open %s: %s", av[1], strerror(errno));
for (n = 2; av[n] != NULL; n++) for (n = 2; av[n] != NULL; n++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment