msvcrt._read
Eric Pouech
pouech-eric at wanadoo.fr
Fri Sep 19 15:08:30 CDT 2003
Geoff Thorpe reported that on consoles, msvcrt.fgets was kinda buggy.
msvcrt._read was in fact waiting until all buffer was filled, while it
should only handle pending character in queue
this patch fixes it
A+
--
Eric Pouech
-------------- next part --------------
Name: crtread
ChangeLog: fixed msvcrt._read to only return the pending chars but not to wait until all buffer is read (O_TEXT mode only)
License: X11
GenDate: 2003/09/19 20:05:48 UTC
ModifiedFiles: dlls/msvcrt/file.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/dlls/msvcrt/file.c,v
retrieving revision 1.51
diff -u -u -r1.51 file.c
--- dlls/msvcrt/file.c 5 Sep 2003 23:08:35 -0000 1.51
+++ dlls/msvcrt/file.c 19 Sep 2003 20:02:56 -0000
@@ -1177,56 +1177,57 @@
if (hand == INVALID_HANDLE_VALUE)
return -1;
- if (MSVCRT_flags[fd]& _O_BINARY)
- {
- if (ReadFile(hand, buf, count, &num_read, NULL))
- {
- if (num_read != count && MSVCRT_files[fd])
- {
- TRACE(":EOF\n");
- MSVCRT_flags[fd] |= MSVCRT__IOEOF;
- /*
- MSVCRT_files[fd]->_flag |= MSVCRT__IOEOF;
- */
- }
- TRACE("%s\n",debugstr_an(buf,num_read));
- return num_read;
- }
+ if (!ReadFile(hand, buf, count, &num_read, NULL))
+ {
TRACE(":failed-last error (%ld)\n",GetLastError());
if (MSVCRT_files[fd])
MSVCRT_files[fd]->_flag |= MSVCRT__IOERR;
return -1;
- }
- else
- {
- char cc, *s=(char*)buf,* buf_start=(char*)buf;
- unsigned int i;
-
- for (i = 0 , num_read = 1; i < count && (num_read == 1);)
- {
- if (ReadFile(hand, &cc, 1, &num_read, NULL))
- if (num_read == 1)
- if ((cc != '\r') || MSVCRT_flags[fd] & _O_BINARY)
- {
- *s++ = (char)cc;
- i++;
- }
- }
- if (num_read != 1)
- {
- TRACE(":EOF\n");
- if (MSVCRT_files[fd])
- MSVCRT_flags[fd] |= MSVCRT__IOEOF;
- /*
- MSVCRT_files[fd]->_flag |= MSVCRT__IOEOF;
- */
- }
-
- if (count > 4)
- TRACE("%s\n",debugstr_an(buf_start, s-buf_start));
- return s-buf_start;
- }
- return 0;
+ }
+ if (!(MSVCRT_flags[fd] & _O_BINARY))
+ {
+ char *dst, *src;
+
+ for (dst = src = (char*)buf; src < (char*)buf + num_read; src++, dst++)
+ {
+ if (*src == 26 /* CTRL-Z */)
+ {
+ if (MSVCRT_files[fd]) MSVCRT_flags[fd] |= MSVCRT__IOEOF;
+ break;
+ }
+ else if (*src == '\r')
+ {
+ if (src < (char*)buf + num_read - 1)
+ {
+ if (src[1] == '\n')
+ {
+ *dst = *++src;
+ }
+ else *dst = *src;
+ }
+ else
+ {
+ char next;
+
+ if (!ReadFile(hand, &next, 1, NULL, NULL)) *dst = '\r';
+ else
+ {
+ if (dst == buf && next == '\n') *dst = '\n';
+ else
+ {
+ if (next != '\n') *dst = '\r';
+ if (SetFilePointer(hand, (long)-1, NULL, SEEK_CUR) == INVALID_SET_FILE_POINTER)
+ FIXME(":issue: putback failed on %p (%ld)\n", hand, GetLastError());
+ }
+ }
+ }
+ }
+ else *dst = *src;
+ }
+ num_read = dst - (char*)buf; /* recompute new len */
+ TRACE("%s\n",debugstr_an(buf,num_read));
+ }
+ return num_read;
}
/*********************************************************************
More information about the wine-patches
mailing list