Correct fseeko64 function.


git-svn-id: svn+ssh://svn.code.sf.net/p/mingw-w64/code/trunk@242 4407c894-4637-0410-b4f5-ada5f102cad1
diff --git a/mingw-w64-crt/ChangeLog b/mingw-w64-crt/ChangeLog
index 0fb603c..da3314d 100644
--- a/mingw-w64-crt/ChangeLog
+++ b/mingw-w64-crt/ChangeLog
@@ -1,3 +1,7 @@
+2008-01-25  Kai Tietz  <kai.tietz@onevision.com>
+
+	* stdio/fseeko64.c: Correct feeko64.
+
 2008-01-23  Kai Tietz  <kai.tietz@onevision.com>
 
 	* crt64/dirent.c: Add add _tGetFileAttributes for win95.
diff --git a/mingw-w64-crt/stdio/fseeko64.c b/mingw-w64-crt/stdio/fseeko64.c
index 9a30ceb..5af2337 100644
--- a/mingw-w64-crt/stdio/fseeko64.c
+++ b/mingw-w64-crt/stdio/fseeko64.c
@@ -105,7 +105,28 @@
 

 int fseeko64 (FILE* stream, _off64_t offset, int whence)

 {

-  return _fseeki64(stream,offset,whence);

+  fpos_t pos;

+  if (whence == SEEK_CUR)

+    {

+      /* If stream is invalid, fgetpos sets errno. */

+      if (fgetpos (stream, &pos))

+        return (-1);

+      pos += (fpos_t) offset;

+    }

+  else if (whence == SEEK_END)

+    {

+      /* If writing, we need to flush before getting file length.  */

+      fflush (stream);

+      pos = (fpos_t) (_filelengthi64 (_fileno (stream)) + offset);

+    }

+  else if (whence == SEEK_SET)

+    pos = (fpos_t) offset;

+  else

+    {

+      errno = EINVAL;

+      return (-1);

+    }

+  return fsetpos (stream, &pos);

 }

 

 int __cdecl _fseeki64(FILE *str,__int64 offset,int whence)