5
5
#include <stdio.h>
6
6
#include <errno.h>
7
7
8
- #ifdef SDL_PLATFORM_WINDOWS
9
- #include <windows.h>
10
- #else
11
- #include <fcntl.h>
12
- #include <unistd.h>
13
- #endif
14
-
15
8
int main (int argc , char * argv []) {
16
9
SDLTest_CommonState * state ;
17
10
int i ;
@@ -101,6 +94,7 @@ int main(int argc, char *argv[]) {
101
94
for (print_i = 0 ; i + print_i < argc ; print_i ++ ) {
102
95
fprintf (stdout , "|%d=%s|\r\n" , print_i , argv [i + print_i ]);
103
96
}
97
+ fflush (stdout );
104
98
}
105
99
106
100
if (print_environment ) {
@@ -111,30 +105,33 @@ int main(int argc, char *argv[]) {
111
105
}
112
106
SDL_free (env );
113
107
}
108
+ fflush (stdout );
114
109
}
115
110
116
- #ifdef SDL_PLATFORM_WINDOWS
117
- {
118
- DWORD mode ;
119
- HANDLE stdout_handle = GetStdHandle (STD_INPUT_HANDLE );
120
- GetConsoleMode (stdout_handle , & mode );
121
- SetConsoleMode (stdout_handle , mode & ~(ENABLE_LINE_INPUT ));
122
- }
123
- #else
124
- fcntl (STDIN_FILENO , F_SETFL , fcntl (STDIN_FILENO , F_GETFL , 0 ) & ~(O_NONBLOCK ));
125
- #endif
126
-
127
111
if (stdin_to_stdout || stdin_to_stderr || read_stdin ) {
128
112
for (;;) {
129
113
char buffer [4 * 4096 ];
130
114
size_t result ;
131
115
132
116
result = fread (buffer , 1 , sizeof (buffer ), stdin );
133
117
if (result == 0 ) {
134
- if (errno == EAGAIN ) {
135
- clearerr (stdin );
136
- SDL_Delay (20 );
137
- continue ;
118
+ if (!feof (stdin )) {
119
+ char error [128 ];
120
+
121
+ if (errno == EAGAIN ) {
122
+ clearerr (stdin );
123
+ SDL_Delay (20 );
124
+ continue ;
125
+ }
126
+
127
+ #ifdef SDL_PLATFORM_WINDOWS
128
+ if (strerror_s (error , sizeof (error ), errno ) != 0 ) {
129
+ SDL_strlcpy (error , "Unknown error" , sizeof (error ));
130
+ }
131
+ #else
132
+ SDL_strlcpy (error , strerror (errno ), sizeof (error ));
133
+ #endif
134
+ SDL_Log ("Error reading from stdin: %s\n" , error );
138
135
}
139
136
break ;
140
137
}
0 commit comments