FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
emscripten/tests/module/test_stdin.c 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
/
module
/
test_stdin.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (49 loc) · 1.12 KB
Breadcrumbs
emscripten
/
tests
/
module
/
test_stdin.c
Copy path
File metadata and controls
58 lines (49 loc) · 1.12 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
54
55
56
57
58
#include
<errno.h>
#include
<fcntl.h>
#include
<stdlib.h>
#include
<stdio.h>
#include
<unistd.h>
#ifdef
__EMSCRIPTEN__
#include
<emscripten.h>
#endif
int
line
=
0
;
void
main_loop
()
{
char
str
[
10
]
=
{
0
};
int
ret
;
errno
=
0
;
while
(
errno
!=
EAGAIN
) {
if
(
line
==
0
) {
ret
=
fgetc
(
stdin
);
if
(
ret
!=
EOF
)
putc
(
ret
,
stdout
);
if
(
ret
==
'\n'
)
line
++
;
}
else
if
(
line
>
0
) {
ret
=
scanf
(
"%10s"
,
str
);
if
(
ret
>
0
)
puts
(
str
);
}
int
err
=
ferror
(
stdin
);
if
(
ferror
(
stdin
)
&&
errno
!=
EAGAIN
) {
printf
(
"error %d\n"
,
err
);
exit
(
EXIT_FAILURE
);
}
if
(
feof
(
stdin
)) {
puts
(
"eof"
);
exit
(
EXIT_SUCCESS
);
}
clearerr
(
stdin
);
}
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
fcntl
(
STDIN_FILENO
,
F_SETFL
,
O_NONBLOCK
);
// SM shell doesn't implement an event loop and therefor doesn't support
// emscripten_set_main_loop. However, its stdin reads are sync so it
// should exit out after calling main_loop once.
main_loop
();
#ifdef
__EMSCRIPTEN__
emscripten_set_main_loop
(
main_loop
,
60
,
0
);
#else
while
(
1
)
main_loop
();
sleep
(
1
);
#endif
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL