diff --git a/test/childprocess.c b/test/childprocess.c index e30ba52e912c9..dede17717d59c 100644 --- a/test/childprocess.c +++ b/test/childprocess.c @@ -5,13 +5,6 @@ #include #include -#ifdef SDL_PLATFORM_WINDOWS -#include -#else -#include -#include -#endif - int main(int argc, char *argv[]) { SDLTest_CommonState *state; int i; @@ -101,6 +94,7 @@ int main(int argc, char *argv[]) { for (print_i = 0; i + print_i < argc; print_i++) { fprintf(stdout, "|%d=%s|\r\n", print_i, argv[i + print_i]); } + fflush(stdout); } if (print_environment) { @@ -111,19 +105,9 @@ int main(int argc, char *argv[]) { } SDL_free(env); } + fflush(stdout); } -#ifdef SDL_PLATFORM_WINDOWS - { - DWORD mode; - HANDLE stdout_handle = GetStdHandle(STD_INPUT_HANDLE); - GetConsoleMode(stdout_handle, &mode); - SetConsoleMode(stdout_handle, mode & ~(ENABLE_LINE_INPUT)); - } -#else - fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) & ~(O_NONBLOCK)); -#endif - if (stdin_to_stdout || stdin_to_stderr || read_stdin) { for (;;) { char buffer[4 * 4096]; @@ -131,10 +115,23 @@ int main(int argc, char *argv[]) { result = fread(buffer, 1, sizeof(buffer), stdin); if (result == 0) { - if (errno == EAGAIN) { - clearerr(stdin); - SDL_Delay(20); - continue; + if (!feof(stdin)) { + char error[128]; + + if (errno == EAGAIN) { + clearerr(stdin); + SDL_Delay(20); + continue; + } + +#ifdef SDL_PLATFORM_WINDOWS + if (strerror_s(error, sizeof(error), errno) != 0) { + SDL_strlcpy(error, "Unknown error", sizeof(error)); + } +#else + SDL_strlcpy(error, strerror(errno), sizeof(error)); +#endif + SDL_Log("Error reading from stdin: %s\n", error); } break; }