Kaynağa Gözat

Just use normal stdio for the child process

Make sure we flush all output so it's seen by the parent as it happens.
Sam Lantinga 6 ay önce
ebeveyn
işleme
8db3b47482
1 değiştirilmiş dosya ile 19 ekleme ve 22 silme
  1. 19 22
      test/childprocess.c

+ 19 - 22
test/childprocess.c

@@ -5,13 +5,6 @@
 #include <stdio.h>
 #include <errno.h>
 
-#ifdef SDL_PLATFORM_WINDOWS
-#include <windows.h>
-#else
-#include <fcntl.h>
-#include <unistd.h>
-#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;
             }