summaryrefslogtreecommitdiffstats
path: root/winsup/mingw/mingwex/mingw-fseek.c
diff options
context:
space:
mode:
authorDanny Smith <dannysmith@users.sourceforge.net>2004-06-30 04:51:18 +0000
committerDanny Smith <dannysmith@users.sourceforge.net>2004-06-30 04:51:18 +0000
commit81223d017f09f34680f80df398d19165ab372525 (patch)
treecd78089531e0b299775431887d9aeabb9417c36f /winsup/mingw/mingwex/mingw-fseek.c
parent76ce12c36057d9fe39bc53628891276b432a0e27 (diff)
downloadcygnal-81223d017f09f34680f80df398d19165ab372525.tar.gz
cygnal-81223d017f09f34680f80df398d19165ab372525.tar.bz2
cygnal-81223d017f09f34680f80df398d19165ab372525.zip
2004-06-30 Kees Zeelenberg <kzlg@users.sourceforge.net>
Danny Smith <dannysmith@users.sourceforge.net> * include/stdio.h (fopen64): Add inline function. (fseeko64): Add prototype. (ftello64): Add inline function. * include/io.h (lseek64): Add inline function. * include/sys/types (off64_t): Add typedef. (fpos64_t): Add typedef. * mingwex/fopen64.c: New file. * mingwex/fseeko64.c: New file. * mingwex/ftello64.c: New file. * mingwex/lseek64.c: New file. * mingwex/Makefile.in (STDIO_DISTFILES): Add fopen64.c, fseeko.64.c, ftello64.c, lseek64.c. (STDIO_OBJS): Add fopen64.o, fseeko.64.o, ftello64.o, lseek64.o. 2004-06-30 Danny Smith <dannysmith@users.sourceforge.net> * include/stdio.h (__mingw_fseeko64): Add prototype. * mingwex/mingw-fseek.c (__mingw_fseeko64): Add definition. (__mingw_fwrite): Handle huge files.
Diffstat (limited to 'winsup/mingw/mingwex/mingw-fseek.c')
-rw-r--r--winsup/mingw/mingwex/mingw-fseek.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/winsup/mingw/mingwex/mingw-fseek.c b/winsup/mingw/mingwex/mingw-fseek.c
index 1ea011fa6..ebec94295 100644
--- a/winsup/mingw/mingwex/mingw-fseek.c
+++ b/winsup/mingw/mingwex/mingw-fseek.c
@@ -30,35 +30,53 @@ __mingw_fseek (FILE *fp, long offset, int whence)
}
int
+__mingw_fseeko64 (FILE *fp, off64_t offset, int whence)
+{
+# undef fseeko64
+ __mingw_fseek_called = 1;
+ return fseeko64 (fp, offset, whence);
+}
+
+int
__mingw_fwrite (const void *buffer, size_t size, size_t count, FILE *fp)
{
# undef fwrite
if ((_osver & 0x8000) && __mingw_fseek_called)
{
- DWORD actual_length, current_position;
+ ULARGE_INTEGER actual_length;
+ LARGE_INTEGER current_position = {{0LL}};
__mingw_fseek_called = 0;
fflush (fp);
- actual_length = GetFileSize ((HANDLE) _get_osfhandle (fileno (fp)),
- NULL);
- current_position = SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)),
- 0, 0, FILE_CURRENT);
+ actual_length.LowPart = GetFileSize ((HANDLE) _get_osfhandle (fileno (fp)),
+ &actual_length.HighPart);
+ if (actual_length.LowPart == 0xFFFFFFFF
+ && GetLastError() != NO_ERROR )
+ return -1;
+ current_position.LowPart = SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)),
+ current_position.LowPart,
+ &current_position.HighPart,
+ FILE_CURRENT);
+ if (current_position.LowPart == 0xFFFFFFFF
+ && GetLastError() != NO_ERROR )
+ return -1;
+
#ifdef DEBUG
- printf ("__mingw_fwrite: current %ld, actual %ld\n",
- current_position, actual_length);
+ printf ("__mingw_fwrite: current %I64u, actual %I64u\n",
+ current_position.QuadPart, actual_length.QuadPart);
#endif /* DEBUG */
- if (current_position > actual_length)
+ if (current_position.QuadPart > actual_length.QuadPart)
{
static char __mingw_zeros[ZEROBLOCKSIZE];
- long numleft;
+ long long numleft;
SetFilePointer ((HANDLE) _get_osfhandle (fileno (fp)),
0, 0, FILE_END);
- numleft = current_position - actual_length;
+ numleft = current_position.QuadPart - actual_length.QuadPart;
#ifdef DEBUG
- printf ("__mingw_fwrite: Seeking %ld bytes past end\n", numleft);
+ printf ("__mingw_fwrite: Seeking %I64d bytes past end\n", numleft);
#endif /* DEBUG */
- while (numleft > 0)
+ while (numleft > 0LL)
{
DWORD nzeros = (numleft > ZEROBLOCKSIZE)
? ZEROBLOCKSIZE : numleft;