forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclose.c
More file actions
46 lines (39 loc) · 1009 Bytes
/
close.c
File metadata and controls
46 lines (39 loc) · 1009 Bytes
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
/*
* Copyright 2011 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
int main() {
int f = open(".", O_RDONLY);
int ret = fsync(f);
printf("fsync(opened): %d\n", ret);
printf("errno: %d\n", errno);
assert(ret == 0);
assert(errno == 0);
errno = 0;
ret = close(f);
printf("close(opened): %d\n", ret);
printf("errno: %d\n", errno);
assert(ret == 0);
assert(errno == 0);
errno = 0;
ret = fsync(f);
printf("fsync(closed): %d\n", ret);
printf("errno: %d\n", errno);
assert(ret == -1);
assert(errno == EBADF);
errno = 0;
ret = close(f);
printf("close(closed): %d\n", ret);
printf("errno: %d\n", errno);
assert(ret == -1);
assert(errno == EBADF);
errno = 0;
return 0;
}