SetFilePointerExt as diff -u

Rob Crittenden <[email protected]> Fri, 30 Jun 2006 13:54:58 -0400
Newsgroups gmane.comp.emulators.winex.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------080703080008010803010602
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

attached as diff -u

rob

--------------080703080008010803010602
Content-Type: text/x-diff;
 name="setfile2.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="setfile2.diff"

Index: include/winbase.h
===================================================================
RCS file: /cvsroot/winex/include/winbase.h,v
retrieving revision 1.33
diff -u -r1.33 winbase.h
--- include/winbase.h	25 Aug 2005 19:44:38 -0000	1.33
+++ include/winbase.h	30 Jun 2006 16:53:20 -0000
@@ -1481,6 +1481,7 @@
 VOID        WINAPI SetFileApisToANSI(void);
 VOID        WINAPI SetFileApisToOEM(void);
 DWORD       WINAPI SetFilePointer(HANDLE,LONG,LPLONG,DWORD);
+BOOL        WINAPI SetFilePointerEx(HANDLE,LARGE_INTEGER,PLARGE_INTEGER,DWORD);
 BOOL        WINAPI SetFileSecurityA(LPCSTR,SECURITY_INFORMATION,PSECURITY_DESCRIPTOR);
 BOOL        WINAPI SetFileSecurityW(LPCWSTR,SECURITY_INFORMATION,PSECURITY_DESCRIPTOR);
 #define     SetFileSecurity WINELIB_NAME_AW(SetFileSecurity)
Index: files/file.c
===================================================================
RCS file: /cvsroot/winex/files/file.c,v
retrieving revision 1.32
diff -u -r1.32 file.c
--- files/file.c	30 Jun 2006 12:55:18 -0000	1.32
+++ files/file.c	30 Jun 2006 16:53:23 -0000
@@ -2045,27 +2045,20 @@
 DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword,
                              DWORD method )
 {
-    DWORD ret = 0xffffffff;
+    LARGE_INTEGER newdistance, newpos;
 
     TRACE("handle %d offset %ld high %ld origin %ld\n",
           hFile, distance, highword?*highword:0, method );
 
-    SERVER_START_REQ( set_file_pointer )
-    {
-        req->handle = hFile;
-        req->low = distance;
-        req->high = highword ? *highword : (distance >= 0) ? 0 : -1;
-        /* FIXME: assumes 1:1 mapping between Windows and Unix seek constants */
-        req->whence = method;
-        SetLastError( 0 );
-        if (!wine_server_call_err( req ))
-        {
-            ret = reply->new_low;
-            if (highword) *highword = reply->new_high;
-        }
-    }
-    SERVER_END_REQ;
-    return ret;
+    newdistance.u.LowPart  = distance;
+    newdistance.u.HighPart = highword ? *highword : (distance >= 0) ? 0 : -1;
+
+    if (!SetFilePointerEx( hFile, newdistance, &newpos, method ))
+        return INVALID_SET_FILE_POINTER;
+
+    if (highword) *highword = newpos.u.HighPart;
+
+    return newpos.u.LowPart;
 }
 
 /***********************************************************************
@@ -2084,21 +2077,28 @@
         return FALSE;
     }
 
-    /* FIXME: might be better to have SetFilePointer call SetFilePointerEx, 
-       but in that case, we might also want to modify the wineserver request */
-    liDistanceToMove.u.LowPart = SetFilePointer(hFile,
-        liDistanceToMove.u.LowPart, &liDistanceToMove.u.HighPart,
-        dwMoveMethod);
+    SERVER_START_REQ( set_file_pointer )
+    {
+        req->handle = hFile;
+        req->low = liDistanceToMove.u.LowPart;
+        req->high = liDistanceToMove.u.HighPart;
+        /* FIXME: assumes 1:1 mapping between Windows and Unix seek constants */
+        req->whence = dwMoveMethod;
+        SetLastError( 0 );
+        if (!wine_server_call_err( req ))
+        {
+            if (lpNewFilePointer) {
+                lpNewFilePointer->u.LowPart = reply->new_low;
+                lpNewFilePointer->u.HighPart = reply->new_high;
+            }
+        }
+    }
+    SERVER_END_REQ;
 
     if (GetLastError() != NO_ERROR) {
         return FALSE;
     }
 
-    if (lpNewFilePointer) {
-          lpNewFilePointer->u.LowPart = liDistanceToMove.u.LowPart;
-          lpNewFilePointer->u.HighPart = liDistanceToMove.u.HighPart;
-    }
-
     return TRUE;
 }
 

--------------080703080008010803010602--