PATCH: msvcrt.ungetc

Marcus Meissner marcus at jet.franken.de
Sat Jul 21 07:04:21 CDT 2001


Hi,

This implements ungetc in a bit of hacky way.

Makes trolltechs QT Designer in the Windows QT edition get a bit further ;)

Ciao, Marcus

Changelog:
	implemented msvcrt.ungetc.

Index: include/msvcrt/stdio.h
===================================================================
RCS file: /home/wine/wine/include/msvcrt/stdio.h,v
retrieving revision 1.2
diff -u -r1.2 stdio.h
--- include/msvcrt/stdio.h	2001/05/07 18:18:34	1.2
+++ include/msvcrt/stdio.h	2001/07/21 12:43:43
@@ -72,6 +72,7 @@
   int   _charbuf;
   int   _bufsiz;
   char* _tmpfname;
+  int   _ungetc;
 } MSVCRT(FILE);
 
 typedef long MSVCRT(fpos_t);
Index: dlls/msvcrt/file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/file.c,v
retrieving revision 1.8
diff -u -r1.8 file.c
--- dlls/msvcrt/file.c	2001/07/10 19:03:46	1.8
+++ dlls/msvcrt/file.c	2001/07/21 12:44:09
@@ -885,7 +885,7 @@
  */
 int _read(int fd, void *buf, unsigned int count)
 {
-  DWORD num_read;
+  DWORD num_read, hadunget = 0;
   HANDLE hand = msvcrt_fdtoh(fd);
 
   /* Dont trace small reads, it gets *very* annoying */
@@ -900,19 +900,31 @@
   if (MSVCRT_files[fd])
     MSVCRT_files[fd]->_cnt = 0;
 
-  if (ReadFile(hand, buf, count, &num_read, NULL))
+  if (MSVCRT_files[fd] && MSVCRT_files[fd]->_ungetc) {
+      ((LPBYTE)buf)[0] = MSVCRT_files[fd]->_ungetc;
+      buf++;
+      MSVCRT_files[fd]->_ungetc = 0;
+      hadunget = 1;
+  }
+
+  if (ReadFile(hand, buf, count-hadunget, &num_read, NULL))
   {
-    if (num_read != count && MSVCRT_files[fd])
+    if (num_read != (count-hadunget) && MSVCRT_files[fd])
     {
       TRACE(":EOF\n");
       MSVCRT_files[fd]->_flag |= _IOEOF;
     }
-    return num_read;
+    return num_read+hadunget;
   }
   TRACE(":failed-last error (%ld)\n",GetLastError());
   if (MSVCRT_files[fd])
      MSVCRT_files[fd]->_flag |= _IOERR;
   return -1;
+}
+
+int MSVCRT_ungetc(int xchar, MSVCRT_FILE* file) {
+    file->_ungetc = xchar;
+    return 0;
 }
 
 /*********************************************************************
Index: dlls/msvcrt/msvcrt.spec
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/msvcrt.spec,v
retrieving revision 1.19
diff -u -r1.19 msvcrt.spec
--- dlls/msvcrt/msvcrt.spec	2001/07/11 20:13:14	1.19
+++ dlls/msvcrt/msvcrt.spec	2001/07/21 12:44:10
@@ -736,7 +736,7 @@
 @ cdecl toupper(long) toupper
 @ forward -noimport towlower ntdll.towlower
 @ forward -noimport towupper ntdll.towupper
-@ stub ungetc #(long ptr)
+@ cdecl ungetc(long ptr) MSVCRT_ungetc
 @ stub ungetwc #(long ptr)
 @ cdecl vfprintf(ptr str long) MSVCRT_vfprintf
 @ cdecl vfwprintf(ptr wstr long) MSVCRT_vfwprintf




More information about the wine-patches mailing list