shell: generalise interface of mufs write/mufs append by reading stdin

master
S.J.R. van Schaik 7 years ago
parent 3df8a7afdf
commit b006de37ad
  1. 27
      source/shell/mufs.c

@ -205,18 +205,9 @@ int shell_write(struct console *con, size_t argc, const char **argv)
return -1;
}
#if CONFIG_USER_ECHO
fprintf(con->fp, "> ");
#endif
while ((ret = console_read(con, data, sizeof data)) > 0) {
if ((ret = console_read(con, data, sizeof data)) > 0)
mufs_write(file, data, ret);
#if CONFIG_USER_ECHO
fprintf(con->fp, "\n> ");
#endif
}
mufs_close(file);
return 0;
@ -224,12 +215,12 @@ int shell_write(struct console *con, size_t argc, const char **argv)
int shell_append(struct console *con, size_t argc, const char **argv)
{
struct mufs_file *file;
char data[256];
size_t n;
struct mufs_file *file;
ssize_t ret;
if (argc < 2) {
fprintf(con->fp, "usage: mufs append <path> <line>\n");
if (argc < 1) {
fprintf(con->fp, "usage: mufs append <path>\n");
return -1;
}
@ -243,13 +234,9 @@ int shell_append(struct console *con, size_t argc, const char **argv)
return -1;
}
n = strlen(argv[1]);
memcpy(data, argv[1], n);
data[n] = '\n';
data[n + 1] = '\0';
if ((ret = console_read(con, data, sizeof data)) > 0)
mufs_write(file, data, ret);
mufs_write(file, data, n + 1);
mufs_close(file);
return 0;

Loading…
Cancel
Save