blob: 34e9884977d954cc9e30d652d2fb3c7803799f15 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}
|