Don't drop characters in fget(w)s

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Changelog:
	dlls/msvcrt/file.c: fget(w)s()
	Don't drop characters when buffer is not large enough

This fixes the errors exposed by the fget(w)s test. fgetws still shows an
error with detecting EOF. It will be fixed with more patches to come.
-- 
Uwe Bonnes                bon@elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
Index: wine/dlls/msvcrt/file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/file.c,v
retrieving revision 1.52
diff -u -r1.52 file.c
--- wine/dlls/msvcrt/file.c	27 Sep 2003 02:45:39 -0000	1.52
+++ wine/dlls/msvcrt/file.c	5 Oct 2003 11:22:23 -0000
@@ -1680,27 +1680,24 @@
  */
 char *MSVCRT_fgets(char *s, int size, MSVCRT_FILE* file)
 {
-  int    cc;
+  int    cc = MSVCRT_EOF;
   char * buf_start = s;
 
   TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
 	file,file->_file,s,size);
 
-  for(cc = MSVCRT_fgetc(file); cc != MSVCRT_EOF && cc != '\n';
-      cc = MSVCRT_fgetc(file))
-    /* _read already handled the translation */
+  while ((size >1) && (cc = MSVCRT_fgetc(file)) != MSVCRT_EOF && cc != '\n')
     {
-      if (--size <= 0) break;
       *s++ = (char)cc;
+      size --;
     }
   if ((cc == MSVCRT_EOF) && (s == buf_start)) /* If nothing read, return 0*/
   {
     TRACE(":nothing read\n");
     return 0;
   }
-  if (cc == '\n')
-    if (--size > 0)
-      *s++ = '\n';
+  if ((cc != MSVCRT_EOF) && (size > 1))
+    *s++ = cc;
   *s = '\0';
   TRACE(":got '%s'\n", debugstr_a(buf_start));
   return buf_start;
@@ -1763,29 +1760,26 @@
  */
 MSVCRT_wchar_t *MSVCRT_fgetws(MSVCRT_wchar_t *s, int size, MSVCRT_FILE* file)
 {
-  int    cc;
+  int    cc = MSVCRT_WEOF;
   MSVCRT_wchar_t * buf_start = s;
 
   TRACE(":file(%p) fd (%d) str (%p) len (%d)\n",
         file,file->_file,s,size);
 
-  for(cc = MSVCRT_fgetwc(file); cc != MSVCRT_WEOF && cc != L'\n';
-      cc = MSVCRT_fgetwc(file))
-    /* _read already handled the translation */
+  while ((size >1) && (cc = MSVCRT_fgetwc(file)) != MSVCRT_WEOF && cc != '\n')
     {
-      if (--size <= 0) break;
-      *s++ = cc;
+      *s++ = (char)cc;
+      size --;
     }
   if ((cc == MSVCRT_EOF) && (s == buf_start)) /* If nothing read, return 0*/
   {
     TRACE(":nothing read\n");
     return 0;
   }
-  if (cc == L'\n')
-    if (--size > 0)
-      *s++ = '\n';
-  *s = '\0';
-/*  TRACE(":got '%s'\n", buf_start); */
+  if ((cc != MSVCRT_WEOF) && (size > 1))
+    *s++ = cc;
+  *s = L'\0';
+  TRACE(":got '%s'\n", debugstr_w(buf_start)); 
   return buf_start;
 }
 


[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux