Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Operating Systems / Pract12 / tee.c
diff options
context:
space:
mode:
Commit2aacf1b28daa876123919f7fab67f2a538864ee6 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-08-24 13:02:16 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-08-24 13:02:16 +0300
Filescf6ba1b6f6028f67cfc549fa5e490b0e508e33fe /Year 2/Operating Systems/Pract12/tee.c
uni-projects-2aacf1b28daa876123919f7fab67f2a538864ee6.tar
uni-projects-2aacf1b28daa876123919f7fab67f2a538864ee6.tar.gz
uni-projects-2aacf1b28daa876123919f7fab67f2a538864ee6.zip
Parent1d1f9e1e713a8b6a786f2b191d8a9db5f1dca79f (diff)
[OS] Added some work I did a while ago
1 files changed, 27 insertions, 0 deletions
-rw-r--r--Year 2/Operating Systems/Pract12/tee.c27
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;
+}