Skip to content

Commit 1966206

Browse files
committed
Fix fflush() & exit() order bug
1 parent a475229 commit 1966206

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

examples/stdlib.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -704,18 +704,6 @@ static int execve(const char *filename, char *const argv[],
704704
return (int)syscall(SYS_execve, filename, argv, envp);
705705
}
706706

707-
static void exit(int status)
708-
{
709-
fflush(stdin);
710-
fclose(stdin);
711-
fflush(stdout);
712-
fclose(stdout);
713-
fflush(stderr);
714-
fclose(stderr);
715-
(void)syscall(SYS_exit, status);
716-
__builtin_unreachable();
717-
}
718-
719707
static pid_t waitpid(pid_t pid, int *status, int options)
720708
{
721709
return (pid_t)syscall(SYS_wait4, pid, status, options, NULL);
@@ -3774,6 +3762,18 @@ static char *getenv(const char *name)
37743762
return NULL;
37753763
}
37763764

3765+
static __attribute__((__noreturn__)) void exit(int status)
3766+
{
3767+
fflush(stdin);
3768+
fclose(stdin);
3769+
fflush(stdout);
3770+
fclose(stdout);
3771+
fflush(stderr);
3772+
fclose(stderr);
3773+
(void)syscall(SYS_exit, status);
3774+
__builtin_unreachable();
3775+
}
3776+
37773777
static __attribute__((__noreturn__)) void abort(void)
37783778
{
37793779
kill(getpid(), SIGABRT);

0 commit comments

Comments
 (0)