diff options
[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.c | 27 |
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; +} |
