dlls/msvcrt/files.c: Flush stdio buffers

wine.larry.engholm at xoxy.net wine.larry.engholm at xoxy.net
Wed May 11 15:41:40 CDT 2005


With the current Wine, this program writes only "Hello,\n" rather than
"Hello,\nworld\n".
#include <iostream>
int main()
{
 std::cout << "Hello," << std::endl << "world." << "\n";
 return 0;
}

One of the changes to file.c for revision 1.66 (2004/05/12) moved the
code to flush output buffers from _close() to MSVCRT_fclose().  The
latter function isn't called by msvcrt_free_io() which is called by
DllMain() for DLL_PROCESS_DETACH, so buffers are no longer flushed
when a program exits.

Alexandre kindly pointed out that my previous fix (posted May 9) was
incorrect.  This patch has msvcrt_free_io() call MSVCRT_fclose()
rather than _close() for stdin, stdout, and stderr.

-Larry

Changelog:
 Flush output buffers from _close() rather than MSVCRT_fclose().

Index: file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/file.c,v
retrieving revision 1.84
diff -u -p -r1.84 file.c
--- file.c      5 May 2005 16:48:28 -0000       1.84
+++ file.c      11 May 2005 19:57:24 -0000
@@ -773,9 +773,13 @@ int MSVCRT__fcloseall(void)
 void msvcrt_free_io(void)
 {
     MSVCRT__fcloseall();
-    _close(0);
-    _close(1);
-    _close(2);
+    /* The Win32 _fcloseall() function explicitly doesn't close stdin,
+     * stdout, and stderr (unlike GNU), so we need to fclose() them here
+     * or they won't get flushed.
+     */
+    MSVCRT_fclose(&MSVCRT__iob[0]);
+    MSVCRT_fclose(&MSVCRT__iob[1]);
+    MSVCRT_fclose(&MSVCRT__iob[2]);
     DeleteCriticalSection(&MSVCRT_file_cs);
 }




More information about the wine-patches mailing list