Mike Duigou wrote:
Would it be possible to call GetFileSizeEx() (or add a call to GetLastError())
MSDN:
Note that if the return value is INVALID_FILE_SIZE (0xffffffff), an application
must call GetLastError to determine whether the function has succeeded or
failed. The reason the function may appear to fail when it has not is that
lpFileSizeHigh could be non-NULL or the file size could be 0xffffffff. In this
case, GetLastError will return NO_ERROR (0) upon success. Because of this
behavior, it is recommended that you use GetFileSizeEx instead.
There is a similar problem for for SetFilePosition():
MSDN:
Note Because INVALID_SET_FILE_POINTER is a valid value for the low-order DWORD
of the new file pointer, you must check both the return value of the function
and the error code returned by GetLastError to determine whether or not an
error has occurred. If an error has occurred, the return value of
SetFilePointer is INVALID_SET_FILE_POINTER and GetLastError returns a value
other than NO_ERROR. For a code example that demonstrates how to check for
failure, see the Remarks section in this topic.
Mike
I agree with Mike's suggestion to use GetFileSizeEx. Also, well spotted
that the SetFilePointer usage is missing a check to GetLastError. I
quickly checked the other usages of this clunky API and they seem to
check the error.
Do you plan to include a regression test for this? I know it's not nice
for tests to be create multi-GB files but this is one that we should
have caught a long time ago. If we create it as a sparse file then the
test should be relatively quick.
-Alan.