forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.c
53 lines (39 loc) · 885 Bytes
/
stat.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
52
53
#include <sys/stat.h>
#include <assert.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#define BASE_DIR "/tmp"
#define OUTPUT_DIR BASE_DIR "/testdir"
#define PATH OUTPUT_DIR "/output.txt"
#define SIZE 500
int main(void) {
struct stat st;
int fd;
int ret;
off_t pos;
(void)st;
ret = mkdir(OUTPUT_DIR, 0755);
assert(ret == 0);
fd = open(PATH, O_CREAT | O_WRONLY, 0666);
assert(fd != -1);
pos = lseek(fd, SIZE - 1, SEEK_SET);
assert(pos == SIZE - 1);
ret = (int)write(fd, "", 1);
assert(ret == 1);
ret = fstat(fd, &st);
assert(ret == 0);
assert(st.st_size == SIZE);
ret = close(fd);
assert(ret == 0);
ret = access(PATH, R_OK);
assert(ret == 0);
ret = stat(PATH, &st);
assert(ret == 0);
assert(st.st_size == SIZE);
ret = unlink(PATH);
assert(ret == 0);
ret = stat(PATH, &st);
assert(ret == -1);
return 0;
}