summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@gmail.com>2014-10-22 18:46:20 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-10-24 14:26:04 +0000
commit694a481360edeb0146c02362385af59f0371eb97 (patch)
tree4c4a47f5a7942f9cbb3736269205b0960e86ef12 /scripts
parent8036c2ddfdbf9f6b35ea76244b98a10b1d76c55b (diff)
downloadmorph-694a481360edeb0146c02362385af59f0371eb97.tar.gz
test-shell: add create file command
Diffstat (limited to 'scripts')
-rw-r--r--scripts/test-shell.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/scripts/test-shell.c b/scripts/test-shell.c
index e3ef1ff1..d1a10e5b 100644
--- a/scripts/test-shell.c
+++ b/scripts/test-shell.c
@@ -107,6 +107,17 @@ cleanup:
return ret;
}
+int copy_file_objects(FILE *source, FILE *target) {
+ char buffer[BUFSIZ];
+ size_t read;
+ do {
+ read = fread(buffer, 1, sizeof(buffer), source);
+ fprintf(stderr, "Read: %*s\n", read, buffer);
+ fwrite(buffer, 1, read, target);
+ } while (!feof(source));
+ return ferror(source) ? -1 : 0;
+}
+
int main(int argc, char *argv[]) {
int ret = 1;
if (argc != 3 || strcmp(argv[1], "-c") != 0) {
@@ -139,6 +150,15 @@ int main(int argc, char *argv[]) {
ret = 1;
break;
}
+ } else if (strstr(line, "create file ") == line) {
+ char const *filename = line + sizeof("create file ") -1;
+ FILE *outfile = fopen(filename, "w");
+ if (copy_file_objects(cmdstream, outfile) < 0) {
+ ret = 1;
+ fclose(outfile);
+ break;
+ }
+ fclose(outfile);
} else {
ret = 127;
break;