functional: add mntent test
[libc-test.git] / src / regression / fflush-exit.c
blob967f6af3eda2596d84938b6de78041dc27ce7b8e
1 // gcc 4.9.0 introduced an invalid optimization for local weak alias symbols
2 // which drops stdout fflush from exit in musl
3 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144
4 #include <errno.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include <sys/wait.h>
10 #include "test.h"
12 #define ASSERT(c) do { \
13 errno = 0; \
14 if (!(c)) \
15 t_error("%s failed (errno: %s)\n", #c, strerror(errno)); \
16 } while(0)
18 int main(void)
20 char tmp[] = "/tmp/testsuite-XXXXXX";
21 int fd, pid, status;
22 char c;
24 ASSERT((fd = mkstemp(tmp)) > 2);
25 ASSERT((pid = fork()) >= 0);
26 if (pid == 0) {
27 ASSERT(close(1) == 0);
28 ASSERT(dup(fd) == 1);
29 ASSERT(fwrite("x", 1, 1, stdout) == 1);
30 exit(t_status);
32 ASSERT(waitpid(pid, &status, 0) == pid);
33 ASSERT(WIFEXITED(status) && WEXITSTATUS(status) == 0);
34 ASSERT(pread(fd, &c, 1, 0) == 1);
35 ASSERT(c == 'x');
36 ASSERT(unlink(tmp) == 0);
37 return t_status;