MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / main_loop

Function main_loop

test/module/test_stdin.c:20–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18int line = 0;
19
20void main_loop() {
21 char str[10] = {0};
22 int ret;
23
24 errno = 0;
25 while (errno != EAGAIN) {
26 if (line == 0) {
27 ret = fgetc(stdin);
28 if (ret != EOF) putc(ret, stdout);
29 if (ret == '\n') line++;
30 } else if (line > 0) {
31 ret = scanf("%9s", str);
32 if (ret > 0) puts(str);
33 }
34
35 int err = ferror(stdin);
36 if (err && errno != EAGAIN) {
37 printf("error %s\n", strerror(errno));
38 exit(EXIT_FAILURE);
39 }
40
41 if (feof(stdin)) {
42 puts("eof");
43 exit(EXIT_SUCCESS);
44 }
45
46 clearerr(stdin);
47 }
48}
49
50int main(int argc, char const *argv[]) {
51 fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);

Callers 1

mainFunction · 0.70

Calls 10

fgetcFunction · 0.85
putcFunction · 0.85
scanfFunction · 0.85
putsFunction · 0.85
ferrorFunction · 0.85
printfFunction · 0.85
strerrorFunction · 0.85
feofFunction · 0.85
clearerrFunction · 0.85
exitFunction · 0.50

Tested by

no test coverage detected