Fixed Win32 seeking on > 2gig files, other Cygwin issues.
This commit is contained in:
parent
4e58f93af9
commit
9ac33cdcbe
|
@ -29,8 +29,10 @@
|
||||||
#define alloca(x) __builtin_alloca(x)
|
#define alloca(x) __builtin_alloca(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LOWORDER_UINT64(pos) (PHYSFS_uint32)(pos & 0x00000000FFFFFFFF)
|
#define LOWORDER_UINT64(pos) (PHYSFS_uint32) \
|
||||||
#define HIGHORDER_UINT64(pos) (PHYSFS_uint32)(pos & 0xFFFFFFFF00000000)
|
(pos & 0x00000000FFFFFFFF)
|
||||||
|
#define HIGHORDER_UINT64(pos) (PHYSFS_uint32) \
|
||||||
|
(((pos & 0xFFFFFFFF00000000) >> 32) & 0x00000000FFFFFFFF)
|
||||||
|
|
||||||
/* GetUserProfileDirectory() is only available on >= NT4 (no 9x/ME systems!) */
|
/* GetUserProfileDirectory() is only available on >= NT4 (no 9x/ME systems!) */
|
||||||
typedef BOOL (STDMETHODCALLTYPE FAR * LPFNGETUSERPROFILEDIR) (
|
typedef BOOL (STDMETHODCALLTYPE FAR * LPFNGETUSERPROFILEDIR) (
|
||||||
|
@ -60,14 +62,11 @@ static char *userDir = NULL;
|
||||||
* for SetFilePointer() just said to compare with 0xFFFFFFFF, so this should
|
* for SetFilePointer() just said to compare with 0xFFFFFFFF, so this should
|
||||||
* work as desired
|
* work as desired
|
||||||
*/
|
*/
|
||||||
#ifndef INVALID_SET_FILE_POINTER
|
#define PHYSFS_INVALID_SET_FILE_POINTER 0xFFFFFFFF
|
||||||
# define INVALID_SET_FILE_POINTER 0xFFFFFFFF
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* just in case... */
|
/* just in case... */
|
||||||
#ifndef INVALID_FILE_ATTRIBUTES
|
#define PHYSFS_INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
|
||||||
# define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -256,7 +255,7 @@ static BOOL mediaInDrive(const char *drive)
|
||||||
DWORD tmp;
|
DWORD tmp;
|
||||||
BOOL retval;
|
BOOL retval;
|
||||||
|
|
||||||
/* Prevent windows warning message to appear when checking media size */
|
/* Prevent windows warning message appearing when checking media size */
|
||||||
oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
|
||||||
|
|
||||||
/* If this function succeeds, there's media in the drive */
|
/* If this function succeeds, there's media in the drive */
|
||||||
|
@ -398,8 +397,11 @@ int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len)
|
||||||
|
|
||||||
int __PHYSFS_platformExists(const char *fname)
|
int __PHYSFS_platformExists(const char *fname)
|
||||||
{
|
{
|
||||||
BAIL_IF_MACRO(GetFileAttributes(fname) == INVALID_FILE_ATTRIBUTES,
|
BAIL_IF_MACRO
|
||||||
win32strerror(), 0);
|
(
|
||||||
|
GetFileAttributes(fname) == PHYSFS_INVALID_FILE_ATTRIBUTES,
|
||||||
|
win32strerror(), 0
|
||||||
|
);
|
||||||
return(1);
|
return(1);
|
||||||
} /* __PHYSFS_platformExists */
|
} /* __PHYSFS_platformExists */
|
||||||
|
|
||||||
|
@ -479,7 +481,11 @@ LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
strcat(SearchPath, "*");
|
strcat(SearchPath, "*");
|
||||||
|
|
||||||
dir = FindFirstFile(SearchPath, &ent);
|
dir = FindFirstFile(SearchPath, &ent);
|
||||||
BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL);
|
BAIL_IF_MACRO
|
||||||
|
(
|
||||||
|
dir == PHYSFS_INVALID_HANDLE_VALUE,
|
||||||
|
win32strerror(), NULL
|
||||||
|
);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
@ -742,7 +748,11 @@ static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
|
||||||
fileHandle = CreateFile(fname, mode, FILE_SHARE_READ, NULL,
|
fileHandle = CreateFile(fname, mode, FILE_SHARE_READ, NULL,
|
||||||
creation, FILE_ATTRIBUTE_NORMAL, NULL);
|
creation, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
|
||||||
BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
|
BAIL_IF_MACRO
|
||||||
|
(
|
||||||
|
fileHandle == PHYSFS_INVALID_HANDLE_VALUE,
|
||||||
|
win32strerror(), NULL
|
||||||
|
);
|
||||||
|
|
||||||
retval = malloc(sizeof (win32file));
|
retval = malloc(sizeof (win32file));
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
|
@ -775,7 +785,8 @@ void *__PHYSFS_platformOpenAppend(const char *filename)
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
{
|
{
|
||||||
HANDLE h = ((win32file *) retval)->handle;
|
HANDLE h = ((win32file *) retval)->handle;
|
||||||
if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
|
DWORD rc = SetFilePointer(h, 0, NULL, FILE_END);
|
||||||
|
if (rc == PHYSFS_INVALID_SET_FILE_POINTER)
|
||||||
{
|
{
|
||||||
const char *err = win32strerror();
|
const char *err = win32strerror();
|
||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
|
@ -840,19 +851,36 @@ int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
|
||||||
{
|
{
|
||||||
HANDLE FileHandle = ((win32file *) opaque)->handle;
|
HANDLE FileHandle = ((win32file *) opaque)->handle;
|
||||||
DWORD HighOrderPos;
|
DWORD HighOrderPos;
|
||||||
|
DWORD *pHighOrderPos;
|
||||||
DWORD rc;
|
DWORD rc;
|
||||||
|
|
||||||
/* Get the high order 32-bits of the position */
|
/* Get the high order 32-bits of the position */
|
||||||
HighOrderPos = HIGHORDER_UINT64(pos);
|
HighOrderPos = HIGHORDER_UINT64(pos);
|
||||||
|
|
||||||
/* !!! FIXME: SetFilePointer needs a signed 64-bit value. */
|
/*
|
||||||
|
* MSDN: "If you do not need the high-order 32 bits, this
|
||||||
|
* pointer must be set to NULL."
|
||||||
|
*/
|
||||||
|
pHighOrderPos = (HighOrderPos) ? &HighOrderPos : NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* !!! FIXME: MSDN: "Windows Me/98/95: If the pointer
|
||||||
|
* !!! FIXME: lpDistanceToMoveHigh is not NULL, then it must
|
||||||
|
* !!! FIXME: point to either 0, INVALID_SET_FILE_POINTER, or
|
||||||
|
* !!! FIXME: the sign extension of the value of lDistanceToMove.
|
||||||
|
* !!! FIXME: Any other value will be rejected."
|
||||||
|
*/
|
||||||
|
|
||||||
/* Move pointer "pos" count from start of file */
|
/* Move pointer "pos" count from start of file */
|
||||||
rc = SetFilePointer(FileHandle, LOWORDER_UINT64(pos),
|
rc = SetFilePointer(FileHandle, LOWORDER_UINT64(pos),
|
||||||
&HighOrderPos, FILE_BEGIN);
|
pHighOrderPos, FILE_BEGIN);
|
||||||
|
|
||||||
if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
if ( (rc == PHYSFS_INVALID_SET_FILE_POINTER) &&
|
||||||
|
(GetLastError() != NO_ERROR) )
|
||||||
|
{
|
||||||
BAIL_MACRO(win32strerror(), 0);
|
BAIL_MACRO(win32strerror(), 0);
|
||||||
|
} /* if */
|
||||||
|
|
||||||
return(1); /* No error occured */
|
return(1); /* No error occured */
|
||||||
} /* __PHYSFS_platformSeek */
|
} /* __PHYSFS_platformSeek */
|
||||||
|
|
||||||
|
@ -866,7 +894,8 @@ PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
|
||||||
|
|
||||||
/* Get current position */
|
/* Get current position */
|
||||||
LowPos = SetFilePointer(FileHandle, 0, &HighPos, FILE_CURRENT);
|
LowPos = SetFilePointer(FileHandle, 0, &HighPos, FILE_CURRENT);
|
||||||
if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
if ( (LowPos == PHYSFS_INVALID_SET_FILE_POINTER) &&
|
||||||
|
(GetLastError() != NO_ERROR) )
|
||||||
{
|
{
|
||||||
BAIL_MACRO(win32strerror(), 0);
|
BAIL_MACRO(win32strerror(), 0);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -889,7 +918,8 @@ PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
|
||||||
PHYSFS_sint64 retval;
|
PHYSFS_sint64 retval;
|
||||||
|
|
||||||
SizeLow = GetFileSize(FileHandle, &SizeHigh);
|
SizeLow = GetFileSize(FileHandle, &SizeHigh);
|
||||||
if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
if ( (SizeLow == PHYSFS_INVALID_SET_FILE_POINTER) &&
|
||||||
|
(GetLastError() != NO_ERROR) )
|
||||||
{
|
{
|
||||||
BAIL_MACRO(win32strerror(), -1);
|
BAIL_MACRO(win32strerror(), -1);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
Loading…
Reference in New Issue