-
Notifications
You must be signed in to change notification settings - Fork 160
/
o_largefile.c
51 lines (47 loc) · 1.11 KB
/
o_largefile.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* # O_LARGEFILE
*
* https://stackoverflow.com/questions/2888425/is-o-largefile-needed-just-to-write-a-large-file
*
* If you compile with -m32, the program only works if _FILE_OFFSET_BITS is defined.
*
* In 64-bit, it does not matter.
*
* Ubuntu 16.04.
*
* I think this passes O_LARGEFILE on the open of the 32-bit syscall.
*/
#define _FILE_OFFSET_BITS 64
#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
char buf[BUFSIZ];
int main(int argc, char **argv) {
int fd;
off_t i, imax, pow;
ssize_t ret;
if (argc > 1) {
pow = strtoumax(argv[1], NULL, 10);
} else {
pow = 32;
}
fd = open(__FILE__ ".tmp", O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
if (fd == -1) {
perror("open");
assert(0);
}
imax = ((off_t)1 << pow) / BUFSIZ;
for (i = 0; i < imax; ++i) {
ret = write(fd, buf, BUFSIZ);
if (ret == -1) {
perror("write");
assert(0);
}
}
close(fd);
return EXIT_SUCCESS;
}