Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Operating Systems / Pract12
diff options
context:
space:
mode:
5 files changed, 49 insertions, 0 deletions
-rwxr-xr-xYear 2/Operating Systems/Pract12/cat-mybin0 -> 15744 bytes
-rw-r--r--Year 2/Operating Systems/Pract12/cat.c21
-rwxr-xr-xYear 2/Operating Systems/Pract12/tee-mybin0 -> 15736 bytes
-rw-r--r--Year 2/Operating Systems/Pract12/tee.c27
-rw-r--r--Year 2/Operating Systems/Pract12/test.txt1
diff --git a/Year 2/Operating Systems/Pract12/cat-my b/Year 2/Operating Systems/Pract12/cat-my
new file mode 100755
index 0000000..36409be
--- /dev/null
+++ b/Year 2/Operating Systems/Pract12/cat-my
Binary files differ
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;
+}
diff --git a/Year 2/Operating Systems/Pract12/tee-my b/Year 2/Operating Systems/Pract12/tee-my
new file mode 100755
index 0000000..8773ef6
--- /dev/null
+++ b/Year 2/Operating Systems/Pract12/tee-my
Binary files differ
diff --git a/Year 2/Operating Systems/Pract12/tee.c b/Year 2/Operating Systems/Pract12/tee.c
new file mode 100644
index 0000000..34e9884
--- /dev/null
+++ b/Year 2/Operating Systems/Pract12/tee.c
@@ -0,0 +1,27 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+const size_t BUFF_SIZE = 1024;
+
+int main(int argc, char* argv[]) {
+ int fd_in = 0;
+
+ int fd_outs[BUFF_SIZE];
+ fd_outs[0] = 1; // stdout
+ for (int i = 1; i < argc; i++) {
+ fd_outs[i] = open(argv[i], O_WRONLY | O_TRUNC | O_CREAT, 0766);
+ }
+
+ char buf[BUFF_SIZE];
+ int actual = read(fd_in, buf, BUFF_SIZE);
+ while (actual > 0) {
+ for (int i = 0; i < argc; i++) {
+ write(fd_outs[i], buf, actual);
+ }
+ actual = read(fd_in, buf, BUFF_SIZE);
+ }
+ return 0;
+}
diff --git a/Year 2/Operating Systems/Pract12/test.txt b/Year 2/Operating Systems/Pract12/test.txt
new file mode 100644
index 0000000..58c2a86
--- /dev/null
+++ b/Year 2/Operating Systems/Pract12/test.txt
@@ -0,0 +1 @@
+123f