FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
emscripten/tests/fs/test_getdents64.cpp at incoming · JavaScriptIOT/emscripten · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
JavaScriptIOT
/
emscripten
Public
forked from
emscripten-core/emscripten
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
emscripten
/
tests
/
fs
/
test_getdents64.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (46 loc) · 1.63 KB
Breadcrumbs
emscripten
/
tests
/
fs
/
test_getdents64.cpp
Copy path
File metadata and controls
53 lines (46 loc) · 1.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<
dirent.h
>
#
include
<
fcntl.h
>
#
include
<
stdio.h
>
#
include
<
unistd.h
>
#
include
<
assert.h
>
#
include
<
stdlib.h
>
#
include
<
sys/stat.h
>
#
include
<
sys/syscall.h
>
#
define
BUF_SIZE
(
sizeof
(dirent)*
2
)
int
main
(
int
argc,
char
*argv[])
{
int
fd =
open
(
"
.
"
,
O_RDONLY
|
O_DIRECTORY
);
assert
(fd >
0
);
printf
(
"
sizeof(dirent): %d, sizeof(buffer): %d
\n
"
,
sizeof
(dirent),
BUF_SIZE
);
bool
first =
true
;
for
(;;)
{
char
buf[
BUF_SIZE
];
int
nread =
getdents
(fd, (dirent*)buf,
BUF_SIZE
);
assert
(nread != -
1
);
if
(nread ==
0
)
break
;
//
In this test, we provide enough space to read two dirent entries at a time.
//
Test that on the first iteration of the loop we get exactly two entries. (there's at least "." and ".." in each directory)
assert
(nread ==
BUF_SIZE
|| !first);
first =
false
;
printf
(
"
--------------- nread=%d ---------------
\n
"
, nread);
printf
(
"
i-node# file type d_reclen d_off d_name
\n
"
);
int
bpos =
0
;
while
(bpos < nread)
{
dirent *d = (dirent *)(buf + bpos);
printf
(
"
%8ld
"
, (
long
)d->
d_ino
);
char
d_type = *(buf + bpos + d->
d_reclen
-
1
);
printf
(
"
%-10s
"
, (d_type ==
DT_REG
) ?
"
regular
"
:
(d_type ==
DT_DIR
) ?
"
directory
"
:
(d_type ==
DT_FIFO
) ?
"
FIFO
"
:
(d_type ==
DT_SOCK
) ?
"
socket
"
:
(d_type ==
DT_LNK
) ?
"
symlink
"
:
(d_type ==
DT_BLK
) ?
"
block dev
"
:
(d_type ==
DT_CHR
) ?
"
char dev
"
:
"
???
"
);
printf
(
"
%4d %10lld %s
\n
"
, d->
d_reclen
, (
long
long
) d->
d_off
, d->
d_name
);
bpos += d->
d_reclen
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL