@@ -3057,6 +3057,64 @@ static void test_ioinfo_flags(void)
3057
3057
free (tempf );
3058
3058
}
3059
3059
3060
+ static void test_std_stream_buffering (void )
3061
+ {
3062
+ int dup_fd , ret , pos ;
3063
+ FILE * file ;
3064
+ char ch ;
3065
+
3066
+ dup_fd = _dup (STDOUT_FILENO );
3067
+ ok (dup_fd != -1 , "_dup failed\n" );
3068
+
3069
+ file = freopen ("std_stream_test.tmp" , "w" , stdout );
3070
+ ok (file != NULL , "freopen failed\n" );
3071
+
3072
+ ret = fprintf (stdout , "test" );
3073
+ pos = _telli64 (STDOUT_FILENO );
3074
+
3075
+ fflush (stdout );
3076
+ _dup2 (dup_fd , STDOUT_FILENO );
3077
+ close (dup_fd );
3078
+ setvbuf (stdout , NULL , _IONBF , 0 );
3079
+
3080
+ ok (ret == 4 , "fprintf(stdout) returned %d\n" , ret );
3081
+ ok (!pos , "expected stdout to be buffered\n" );
3082
+
3083
+ dup_fd = _dup (STDERR_FILENO );
3084
+ ok (dup_fd != -1 , "_dup failed\n" );
3085
+
3086
+ file = freopen ("std_stream_test.tmp" , "w" , stderr );
3087
+ ok (file != NULL , "freopen failed\n" );
3088
+
3089
+ ret = fprintf (stderr , "test" );
3090
+ ok (ret == 4 , "fprintf(stderr) returned %d\n" , ret );
3091
+ pos = _telli64 (STDERR_FILENO );
3092
+ ok (!pos , "expected stderr to be buffered\n" );
3093
+
3094
+ fflush (stderr );
3095
+ _dup2 (dup_fd , STDERR_FILENO );
3096
+ close (dup_fd );
3097
+
3098
+ dup_fd = _dup (STDIN_FILENO );
3099
+ ok (dup_fd != -1 , "_dup failed\n" );
3100
+
3101
+ file = freopen ("std_stream_test.tmp" , "r" , stdin );
3102
+ ok (file != NULL , "freopen failed\n" );
3103
+
3104
+ ch = 0 ;
3105
+ ret = fscanf (stdin , "%c" , & ch );
3106
+ ok (ret == 1 , "fscanf returned %d\n" , ret );
3107
+ ok (ch == 't' , "ch = 0x%x\n" , (unsigned char )ch );
3108
+ pos = _telli64 (STDIN_FILENO );
3109
+ ok (pos == 4 , "pos = %d\n" , pos );
3110
+
3111
+ fflush (stdin );
3112
+ _dup2 (dup_fd , STDIN_FILENO );
3113
+ close (dup_fd );
3114
+
3115
+ ok (DeleteFileA ("std_stream_test.tmp" ), "DeleteFile failed\n" );
3116
+ }
3117
+
3060
3118
START_TEST (file )
3061
3119
{
3062
3120
int arg_c ;
@@ -3133,6 +3191,7 @@ START_TEST(file)
3133
3191
test_fopen_hints ();
3134
3192
test_open_hints ();
3135
3193
test_ioinfo_flags ();
3194
+ test_std_stream_buffering ();
3136
3195
3137
3196
/* Wait for the (_P_NOWAIT) spawned processes to finish to make sure the report
3138
3197
* file contains lines in the correct order
0 commit comments