1 | #include <stdio.h>
|
---|
2 | #include <errno.h>
|
---|
3 | #include <ipc/ipc.h>
|
---|
4 | #include <fcntl.h>
|
---|
5 | #include <malloc.h>
|
---|
6 |
|
---|
7 | static int write_all(int fd, void *data, size_t len)
|
---|
8 | {
|
---|
9 | int cnt = 0;
|
---|
10 |
|
---|
11 | do {
|
---|
12 | data += cnt;
|
---|
13 | len -= cnt;
|
---|
14 | cnt = write(fd, data, len);
|
---|
15 | } while (cnt > 0 && (len - cnt) > 0);
|
---|
16 |
|
---|
17 | if (cnt < 0)
|
---|
18 | return cnt;
|
---|
19 |
|
---|
20 | if (len - cnt > 0)
|
---|
21 | return EIO;
|
---|
22 |
|
---|
23 | return EOK;
|
---|
24 | }
|
---|
25 |
|
---|
26 | static int write_tom()
|
---|
27 | {
|
---|
28 | size_t len = sizeof(int) * 1000000;
|
---|
29 | int *tmp = malloc(len);
|
---|
30 | int fd = open("/tom", O_CREAT | O_WRONLY);
|
---|
31 | if (fd <= 0) {
|
---|
32 | free(tmp);
|
---|
33 | return -1;
|
---|
34 | }
|
---|
35 |
|
---|
36 | size_t chunk_size = 32 * 1024;
|
---|
37 | size_t nread = 0;
|
---|
38 | while (nread < len) {
|
---|
39 | if (len - nread < chunk_size)
|
---|
40 | chunk_size = len - nread;
|
---|
41 | printf("CHECKPOINTER: Writing chunk, nread: %p\n", nread);
|
---|
42 | nread += chunk_size;
|
---|
43 | int rc = write_all(fd, tmp, chunk_size);
|
---|
44 | if (rc < 0) {
|
---|
45 | free(tmp);
|
---|
46 | return rc;
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | free(tmp);
|
---|
51 | return 0;
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 | int main(int argc, char **argv)
|
---|
56 | {
|
---|
57 | int rc = write_tom();
|
---|
58 | printf("rc: %i\n", rc);
|
---|
59 | return 0;
|
---|
60 | }
|
---|