diff --git a/src/regression/fflush-exit.c b/src/regression/fflush-exit.c new file mode 100644 index 0000000..967f6af --- /dev/null +++ b/src/regression/fflush-exit.c @@ -0,0 +1,38 @@ +// gcc 4.9.0 introduced an invalid optimization for local weak alias symbols +// which drops stdout fflush from exit in musl +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144 +#include +#include +#include +#include +#include +#include +#include "test.h" + +#define ASSERT(c) do { \ + errno = 0; \ + if (!(c)) \ + t_error("%s failed (errno: %s)\n", #c, strerror(errno)); \ +} while(0) + +int main(void) +{ + char tmp[] = "/tmp/testsuite-XXXXXX"; + int fd, pid, status; + char c; + + ASSERT((fd = mkstemp(tmp)) > 2); + ASSERT((pid = fork()) >= 0); + if (pid == 0) { + ASSERT(close(1) == 0); + ASSERT(dup(fd) == 1); + ASSERT(fwrite("x", 1, 1, stdout) == 1); + exit(t_status); + } + ASSERT(waitpid(pid, &status, 0) == pid); + ASSERT(WIFEXITED(status) && WEXITSTATUS(status) == 0); + ASSERT(pread(fd, &c, 1, 0) == 1); + ASSERT(c == 'x'); + ASSERT(unlink(tmp) == 0); + return t_status; +}