KERNEL32: implement SetFilePointerEx (resend)

Mike McCormack mike at codeweavers.com
Wed Jun 9 08:17:13 CDT 2004


Dmitry Timoshkov wrote:

> %lld is not portable, Alexandre added wine_dbgstr_longlong() for
> that purpose.

OK

> MSDN states that newpos parameter is allowed to be NULL, in that case
> a new file pointer is not returned.

OK

> To avoid code duplication SetFilePointer should become just a wrapper
> for SetFilePointerEx.

Well, I'd rather leave SetFilePointer alone for now since it works, and 
let somebody rewrite both functions to use the relevant ntdll function 
later.

Mike


ChangeLog:
* implement SetFilePointerEx
-------------- next part --------------
Index: dlls/kernel/file.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/file.c,v
retrieving revision 1.20
diff -u -r1.20 file.c
--- dlls/kernel/file.c	22 May 2004 03:13:56 -0000	1.20
+++ dlls/kernel/file.c	9 Jun 2004 12:05:49 -0000
@@ -861,6 +861,52 @@
 
 
 /***********************************************************************
+ *           SetFilePointerEx   (KERNEL32.@)
+ */
+BOOL WINAPI SetFilePointerEx( HANDLE hFile, LARGE_INTEGER distance,
+                               LARGE_INTEGER *newpos, DWORD method )
+{
+    static const int whence[3] = { SEEK_SET, SEEK_CUR, SEEK_END };
+    BOOL ret = FALSE;
+    NTSTATUS status;
+    int fd;
+
+    TRACE("handle %p offset %s newpos %p origin %ld\n",
+          hFile, wine_dbgstr_longlong(distance.QuadPart), newpos, method );
+
+    if (method > FILE_END)
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return ret;
+    }
+
+    if (!(status = wine_server_handle_to_fd( hFile, 0, &fd, NULL, NULL )))
+    {
+        off_t pos, res;
+
+        pos = distance.QuadPart;
+        if ((res = lseek( fd, pos, whence[method] )) == (off_t)-1)
+        {
+            /* also check EPERM due to SuSE7 2.2.16 lseek() EPERM kernel bug */
+            if (((errno == EINVAL) || (errno == EPERM)) && (method != FILE_BEGIN) && (pos < 0))
+                SetLastError( ERROR_NEGATIVE_SEEK );
+            else
+                FILE_SetDosError();
+        }
+        else
+        {
+            ret = TRUE;
+            if( newpos )
+                newpos->QuadPart = res;
+        }
+        wine_server_release_fd( hFile, fd );
+    }
+    else SetLastError( RtlNtStatusToDosError(status) );
+
+    return ret;
+}
+
+/***********************************************************************
  *           GetFileTime   (KERNEL32.@)
  */
 BOOL WINAPI GetFileTime( HANDLE hFile, FILETIME *lpCreationTime,
Index: dlls/kernel/kernel32.spec
===================================================================
RCS file: /home/wine/wine/dlls/kernel/kernel32.spec,v
retrieving revision 1.134
diff -u -r1.134 kernel32.spec
--- dlls/kernel/kernel32.spec	2 Jun 2004 21:32:55 -0000	1.134
+++ dlls/kernel/kernel32.spec	9 Jun 2004 12:05:49 -0000
@@ -777,7 +777,7 @@
 @ stdcall SetFileAttributesA(str long)
 @ stdcall SetFileAttributesW(wstr long)
 @ stdcall SetFilePointer(long long ptr long)
-@ stub SetFilePointerEx
+@ stdcall SetFilePointerEx(long long long ptr long)
 @ stdcall SetFileTime(long ptr ptr ptr)
 @ stdcall SetHandleContext(long long)
 @ stdcall SetHandleCount(long)


More information about the wine-patches mailing list