git.samba.org
/
tridge
/
junkcode.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
use 64bit counter
[tridge/junkcode.git]
/
write.c
1
#include <stdlib.h>
2
#include <fcntl.h>
3
4
#define LEN 0x1000
5
#define ADDR 0x0
6
7
int main()
8
{
9
int fdpair[2];
10
int fd = open("mem.dat", O_WRONLY|O_CREAT|O_TRUNC, 0600);
11
12
if (fd == -1) {
13
perror("open");
14
exit(1);
15
}
16
17
while (pipe(fdpair) == 0) {
18
if (fork()) {
19
char buf[LEN];
20
if (read(fdpair[0], buf, LEN) != LEN) {
21
perror("read");
22
exit(1);
23
}
24
if (write(fd,buf,LEN) != LEN) {
25
perror("write");
26
exit(1);
27
}
28
waitpid(-1, NULL, 0);
29
} else {
30
if (write(fdpair[1],ADDR,LEN) != LEN) {
31
perror("write");
32
exit(1);
33
}
34
_exit(0);
35
}
36
}
37
38
return 0;
39
}