Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Operating Systems / Pract12 / cat.c
diff options
context:
space:
mode:
1 files changed, 21 insertions, 0 deletions
-rw-r--r--Year 2/Operating Systems/Pract12/cat.c21
diff --git a/Year 2/Operating Systems/Pract12/cat.c b/Year 2/Operating Systems/Pract12/cat.c
new file mode 100644
index 0000000..353e2ca
--- /dev/null
+++ b/Year 2/Operating Systems/Pract12/cat.c
@@ -0,0 +1,21 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+const size_t BUFF_SIZE = 1024;
+
+int main(int argc, char* argv[]) {
+ int fd_in = 0;
+ if (argc > 1)
+ fd_in = open(argv[1], O_RDONLY);
+
+ char buf[BUFF_SIZE];
+ int actual = read(fd_in, buf, BUFF_SIZE);
+ while (actual > 0) {
+ printf("%s", buf);
+ actual = read(fd_in, buf, BUFF_SIZE);
+ }
+ return 0;
+}