Piotr Caban : msvcrt: Don' t make stdout and stderr bufferred when writing to console.

Alexandre Julliard julliard at winehq.org
Wed Jan 30 13:43:22 CST 2013


Module: wine
Branch: master
Commit: 2ee5323a91025b914c6c3c5b0c6ec87cfeb6448b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=2ee5323a91025b914c6c3c5b0c6ec87cfeb6448b

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue Jan 29 13:21:08 2013 +0100

msvcrt: Don't make stdout and stderr bufferred when writing to console.

---

 dlls/msvcrt/file.c |   67 ++++++++++++++++++++++++++-------------------------
 1 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index d9b0e19..8e2a067 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -560,20 +560,39 @@ static int msvcrt_flush_buffer(MSVCRT_FILE* file)
   return 0;
 }
 
+/*********************************************************************
+ *		_isatty (MSVCRT.@)
+ */
+int CDECL MSVCRT__isatty(int fd)
+{
+    HANDLE hand = msvcrt_fdtoh(fd);
+
+    TRACE(":fd (%d) handle (%p)\n",fd,hand);
+    if (hand == INVALID_HANDLE_VALUE)
+        return 0;
+
+    return GetFileType(hand) == FILE_TYPE_CHAR? 1 : 0;
+}
+
 /* INTERNAL: Allocate stdio file buffer */
-static void msvcrt_alloc_buffer(MSVCRT_FILE* file)
+static BOOL msvcrt_alloc_buffer(MSVCRT_FILE* file)
 {
-	file->_base = MSVCRT_calloc(MSVCRT_BUFSIZ,1);
-	if(file->_base) {
-		file->_bufsiz = MSVCRT_BUFSIZ;
-		file->_flag |= MSVCRT__IOMYBUF;
-	} else {
-		file->_base = (char*)(&file->_charbuf);
-		/* put here 2 ??? */
-		file->_bufsiz = sizeof(file->_charbuf);
-	}
-	file->_ptr = file->_base;
-	file->_cnt = 0;
+    if((file->_file==MSVCRT_STDOUT_FILENO || file->_file==MSVCRT_STDERR_FILENO)
+            && MSVCRT__isatty(file->_file))
+        return FALSE;
+
+    file->_base = MSVCRT_calloc(MSVCRT_BUFSIZ,1);
+    if(file->_base) {
+        file->_bufsiz = MSVCRT_BUFSIZ;
+        file->_flag |= MSVCRT__IOMYBUF;
+    } else {
+        file->_base = (char*)(&file->_charbuf);
+        /* put here 2 ??? */
+        file->_bufsiz = sizeof(file->_charbuf);
+    }
+    file->_ptr = file->_base;
+    file->_cnt = 0;
+    return TRUE;
 }
 
 /* INTERNAL: Convert integer to base32 string (0-9a-v), 0 becomes "" */
@@ -1619,20 +1638,6 @@ MSVCRT_intptr_t CDECL MSVCRT__get_osfhandle(int fd)
 }
 
 /*********************************************************************
- *		_isatty (MSVCRT.@)
- */
-int CDECL MSVCRT__isatty(int fd)
-{
-  HANDLE hand = msvcrt_fdtoh(fd);
-
-  TRACE(":fd (%d) handle (%p)\n",fd,hand);
-  if (hand == INVALID_HANDLE_VALUE)
-    return 0;
-
-  return GetFileType(hand) == FILE_TYPE_CHAR? 1 : 0;
-}
-
-/*********************************************************************
  *		_mktemp (MSVCRT.@)
  */
 char * CDECL MSVCRT__mktemp(char *pattern)
@@ -3661,10 +3666,8 @@ MSVCRT_size_t CDECL MSVCRT_fread(void *ptr, MSVCRT_size_t size, MSVCRT_size_t nm
     /* Fill the buffer on small reads.
      * TODO: Use a better buffering strategy.
      */
-    if (!file->_cnt && size*nmemb <= MSVCRT_BUFSIZ/2 && !(file->_flag & MSVCRT__IONBF)) {
-      if (file->_bufsiz == 0) {
-        msvcrt_alloc_buffer(file);
-      }
+    if (!file->_cnt && size*nmemb <= MSVCRT_BUFSIZ/2 && !(file->_flag & MSVCRT__IONBF)
+            && (file->_bufsiz != 0 || msvcrt_alloc_buffer(file))) {
       file->_cnt = MSVCRT__read(file->_file, file->_base, file->_bufsiz);
       file->_ptr = file->_base;
       i = (file->_cnt<rcnt) ? file->_cnt : rcnt;
@@ -4472,10 +4475,8 @@ int CDECL MSVCRT_ungetc(int c, MSVCRT_FILE * file)
         return MSVCRT_EOF;
 
     MSVCRT__lock_file(file);
-    if(file->_bufsiz == 0) {
-        msvcrt_alloc_buffer(file);
+    if(file->_bufsiz == 0 && msvcrt_alloc_buffer(file))
         file->_ptr++;
-    }
     if(file->_ptr>file->_base) {
         file->_ptr--;
         *file->_ptr=c;




More information about the wine-cvs mailing list