[MSVCRT] Fix get/set pos (fixes Supreme Snowboarding demo).

Lionel Ulmer lionel.ulmer at free.fr
Fri Dec 24 11:36:07 CST 2004


This is the same patch than before except that now the tests directory in
the msvcrt directory builds (I had to add the 'basestd.h' include to stdio.h
to get the __int64 type).

Note that this is still not as elaborate as what Dmitry showed us but well,
at least it is aligned with what native MSVCRT.DLL does (I checked on a
small test program and 'fgetpos' expects a pointer to a 64 bit value when
run with the native DLL).

     Lionel

PS: there may be some 'fuzz factor' when applying the patch as there are
    some additionnal TRACEs I did that I did not send.

Changelog:
 - fpos_t should be 64 bits (verified with native MSVCRT.DLL)
 - handle buffering in fgetpos / fsetpos
  
-- 
		 Lionel Ulmer - http://www.bbrox.org/
-------------- next part --------------
Index: include/msvcrt/stdio.h
===================================================================
RCS file: /home/wine/wine/include/msvcrt/stdio.h,v
retrieving revision 1.20
diff -u -r1.20 stdio.h
--- include/msvcrt/stdio.h	25 Jun 2004 01:19:15 -0000	1.20
+++ include/msvcrt/stdio.h	24 Dec 2004 17:30:33 -0000
@@ -11,6 +11,8 @@
 #define __WINE_USE_MSVCRT
 #endif
 
+#include <basetsd.h>
+
 #ifndef RC_INVOKED
 #include <stdarg.h>
 #endif
@@ -71,7 +73,7 @@
 #endif  /* _FILE_DEFINED */
 
 #ifndef _FPOS_T_DEFINED
-typedef long fpos_t;
+typedef __int64 fpos_t;
 #define _FPOS_T_DEFINED
 #endif
 
Index: dlls/msvcrt/file.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/file.c,v
retrieving revision 1.78
diff -u -r1.78 file.c
--- dlls/msvcrt/file.c	14 Dec 2004 11:59:43 -0000	1.78
+++ dlls/msvcrt/file.c	24 Dec 2004 17:30:34 -0000
@@ -2518,7 +2530,20 @@
  */
 int MSVCRT_fsetpos(MSVCRT_FILE* file, MSVCRT_fpos_t *pos)
 {
-  return _lseek(file->_file,*pos,SEEK_SET);
+  /* Note that all this has been lifted 'as is' from fseek */
+  if(file->_flag & MSVCRT__IOWRT)
+	msvcrt_flush_buffer(file);
+
+  /* Discard buffered input */
+  file->_cnt = 0;
+  file->_ptr = file->_base;
+  
+  /* Reset direction of i/o */
+  if(file->_flag & MSVCRT__IORW) {
+        file->_flag &= ~(MSVCRT__IOREAD|MSVCRT__IOWRT);
+  }
+
+  return _lseeki64(file->_file,*pos,SEEK_SET);
 }
 
 /*********************************************************************
@@ -2545,8 +2570,23 @@
  */
 int MSVCRT_fgetpos(MSVCRT_FILE* file, MSVCRT_fpos_t *pos)
 {
-  *pos = MSVCRT_ftell(file);
-  return (*pos == -1? -1 : 0);
+  /* This code has been lifted form the MSVCRT_ftell function */
+  int off=0;
+
+  *pos = _lseeki64(file->_file,0,SEEK_CUR);
+
+  if (*pos == -1) return -1;
+  
+  if(file->_bufsiz)  {
+	if( file->_flag & MSVCRT__IOWRT ) {
+		off = file->_ptr - file->_base;
+	} else {
+		off = -file->_cnt;
+	}
+  }
+  *pos += off;
+  
+  return 0;
 }
 
 /*********************************************************************
Index: dlls/msvcrt/msvcrt.h
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/msvcrt.h,v
retrieving revision 1.33
diff -u -r1.33 msvcrt.h
--- dlls/msvcrt/msvcrt.h	14 Dec 2004 15:13:54 -0000	1.33
+++ dlls/msvcrt/msvcrt.h	24 Dec 2004 17:30:35 -0000
@@ -55,7 +55,7 @@
 typedef int  MSVCRT__off_t;
 typedef long MSVCRT_clock_t;
 typedef long MSVCRT_time_t;
-typedef long MSVCRT_fpos_t;
+typedef __int64 MSVCRT_fpos_t;
 
 typedef void (*MSVCRT_terminate_handler)();
 typedef void (*MSVCRT_terminate_function)();


More information about the wine-patches mailing list