Skip to content

Commit

Permalink
Fix fflush() & exit() order bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GJDuck committed Jun 20, 2022
1 parent a475229 commit 1966206
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions examples/stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,18 +704,6 @@ static int execve(const char *filename, char *const argv[],
return (int)syscall(SYS_execve, filename, argv, envp);
}

static void exit(int status)
{
fflush(stdin);
fclose(stdin);
fflush(stdout);
fclose(stdout);
fflush(stderr);
fclose(stderr);
(void)syscall(SYS_exit, status);
__builtin_unreachable();
}

static pid_t waitpid(pid_t pid, int *status, int options)
{
return (pid_t)syscall(SYS_wait4, pid, status, options, NULL);
Expand Down Expand Up @@ -3774,6 +3762,18 @@ static char *getenv(const char *name)
return NULL;
}

static __attribute__((__noreturn__)) void exit(int status)
{
fflush(stdin);
fclose(stdin);
fflush(stdout);
fclose(stdout);
fflush(stderr);
fclose(stderr);
(void)syscall(SYS_exit, status);
__builtin_unreachable();
}

static __attribute__((__noreturn__)) void abort(void)
{
kill(getpid(), SIGABRT);
Expand Down

0 comments on commit 1966206

Please sign in to comment.