dlls/msvcrt/files.c: Flush stdio buffers
wine.larry.engholm at xoxy.net
wine.larry.engholm at xoxy.net
Mon May 9 15:45:55 CDT 2005
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.
-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 7 May 2005 03:04:04 -0000
@@ -608,16 +608,29 @@ int _close(int fd)
TRACE(":fd (%d) handle (%p)\n",fd,hand);
if (hand == INVALID_HANDLE_VALUE)
ret = -1;
- else if (!CloseHandle(hand))
- {
- WARN(":failed-last error (%ld)\n",GetLastError());
- msvcrt_set_errno(GetLastError());
- ret = -1;
- }
else
{
- msvcrt_free_fd(fd);
- ret = 0;
+ /* flush stdio buffers */
+ if (MSVCRT_fstreams[fd])
+ {
+ if (MSVCRT_fstreams[fd]->_flag & MSVCRT__IOWRT)
+ MSVCRT_fflush(MSVCRT_fstreams[fd]);
+
+ if (MSVCRT_fstreams[fd]->_flag & MSVCRT__IOMYBUF)
+ MSVCRT_free(MSVCRT_fstreams[fd]->_base);
+ }
+
+ if (!CloseHandle(hand))
+ {
+ WARN(":failed-last error (%ld)\n",GetLastError());
+ msvcrt_set_errno(GetLastError());
+ ret = -1;
+ }
+ else
+ {
+ msvcrt_free_fd(fd);
+ ret = 0;
+ }
}
UNLOCK_FILES();
TRACE(":ok\n");
@@ -2075,11 +2088,6 @@ int MSVCRT_fclose(MSVCRT_FILE* file)
MSVCRT_free(file->_tmpfname);
file->_tmpfname = NULL;
}
- /* flush stdio buffers */
- if(file->_flag & MSVCRT__IOWRT)
- MSVCRT_fflush(file);
- if(file->_flag & MSVCRT__IOMYBUF)
- MSVCRT_free(file->_base);
r=_close(file->_file);
More information about the wine-patches
mailing list