summaryrefslogtreecommitdiff
path: root/410user/progs/cat.c
diff options
context:
space:
mode:
Diffstat (limited to '410user/progs/cat.c')
-rw-r--r--410user/progs/cat.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/410user/progs/cat.c b/410user/progs/cat.c
new file mode 100644
index 0000000..9d2ef97
--- /dev/null
+++ b/410user/progs/cat.c
@@ -0,0 +1,30 @@
+// Simple program to print out files.
+// Michael J. Sullivan, Spring 2013
+
+#include <syscall.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define BUFSIZE 87 // "four score and seven"
+
+int main(int argc, char **argv)
+{
+ char buf[BUFSIZE];
+ int i;
+ for (i = 1; i < argc; i++) {
+ char *file = argv[i];
+ int offset = 0;
+ int amt_read;
+ while ((amt_read = readfile(file, buf, BUFSIZE, offset)) > 0) {
+ print(amt_read, buf);
+ offset += amt_read;
+ }
+ if (amt_read < 0) {
+ printf("error reading from file %s at offset %d\n",
+ file, offset);
+ return -1;
+ }
+ }
+
+ return 0;
+}