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"
11 
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)
17 
main(void)18 int main(void)
19 {
20 	char tmp[] = "/data/local/tmp/testsuite-XXXXXX";
21 	int fd, pid, status;
22 	char c;
23 
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);
31 	}
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;
38 }
39