commit 99d06fe277307137bac2147ecb9b299c79b42453
Author: ssnf <ssnf@ssnf.xyz>
Date: Thu, 8 Jul 2021 22:14:33 +0000
initial commit
Diffstat:
A | cat.c | | | 23 | +++++++++++++++++++++++ |
1 file changed, 23 insertions(+), 0 deletions(-)
diff --git a/cat.c b/cat.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int
+main(int argc, char* argv[])
+{
+ char buf[4096];
+ FILE* f;
+ int i, n;
+
+ for (i = 1; i < argc; ++i) {
+ if (*argv[i] == '-' && *(argv[i]+1) == '\0')
+ f = stdin;
+ else {
+ f = fopen(argv[i], "r");
+ if (!f) {
+ perror(argv[i]);
+ return 1;
+ }
+ }
+ while (n = fread(buf, 1, sizeof(buf), f))
+ fwrite(buf, 1, n, stdout);
+ }
+}