]>
Commit | Line | Data |
---|---|---|
866f8763 A |
1 | // |
2 | // Copyright 2017 Apple. All rights reserved. | |
3 | // | |
4 | ||
5 | #include "AtomicFile.h" | |
6 | #include <err.h> | |
7 | ||
8 | #if 0 | |
9 | static void | |
10 | fill_disk(const char *path) | |
11 | { | |
12 | int fd = ::open(path, O_CREAT|O_RDWR, 0600); | |
13 | if (fd < 0) | |
14 | errx(1, "failed to create fill file"); | |
15 | ||
16 | uint8 buffer[1024] = {}; | |
17 | ::memset(reinterpret_cast<void *>(buffer), 0x77, sizeof(buffer)); | |
18 | ||
19 | for (unsigned count = 0; count < 1000; count++) { | |
20 | if (::write(fd, buffer, sizeof(buffer)) != sizeof(buffer)) { | |
21 | warn("write fill file failed"); | |
22 | break; | |
23 | } | |
24 | } | |
25 | if (close(fd) < 0) | |
26 | warn("close fill file failed"); | |
27 | } | |
28 | #endif | |
29 | ||
30 | int | |
31 | main(int argc, char **argv) | |
32 | { | |
33 | int fail = 0; | |
34 | ||
35 | if (argc != 2) | |
36 | errx(1, "argc != 2"); | |
37 | ||
38 | try { | |
39 | AtomicFile file(argv[1]); | |
40 | ||
41 | RefPointer<AtomicTempFile> temp = file.write(); | |
42 | ||
43 | unsigned count = 0; | |
44 | uint8 buffer[1024] = {}; | |
45 | ::memset(reinterpret_cast<void *>(buffer), 0xff, sizeof(buffer)); | |
46 | ||
47 | for (count = 0; count < 1000; count++) { | |
48 | temp->write(AtomicFile::FromEnd, 0, buffer, sizeof(buffer)); | |
49 | } | |
50 | ||
51 | temp->commit(); | |
52 | temp = NULL; | |
53 | } catch (...) { | |
54 | fail = 1; | |
55 | } | |
56 | if (fail) | |
57 | errx(1, "failed to create new file"); | |
58 | return 0; | |
59 | } | |
60 | ||
61 | ||
62 |