w32: Fix qemu_ftruncate64
SetFilePointer returns INVALID_SET_FILE_POINTER when it fails. In addition, GetLastError must be checked. The first call of SetFilePointer did not use INVALID_SET_FILE_POINTER, the second call used wrong error handling. Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
1f22a6bc62
commit
2c993ec294
|
@ -41,6 +41,7 @@ typedef struct BDRVRawState {
|
||||||
int qemu_ftruncate64(int fd, int64_t length)
|
int qemu_ftruncate64(int fd, int64_t length)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER li;
|
LARGE_INTEGER li;
|
||||||
|
DWORD dw;
|
||||||
LONG high;
|
LONG high;
|
||||||
HANDLE h;
|
HANDLE h;
|
||||||
BOOL res;
|
BOOL res;
|
||||||
|
@ -53,12 +54,15 @@ int qemu_ftruncate64(int fd, int64_t length)
|
||||||
/* get current position, ftruncate do not change position */
|
/* get current position, ftruncate do not change position */
|
||||||
li.HighPart = 0;
|
li.HighPart = 0;
|
||||||
li.LowPart = SetFilePointer (h, 0, &li.HighPart, FILE_CURRENT);
|
li.LowPart = SetFilePointer (h, 0, &li.HighPart, FILE_CURRENT);
|
||||||
if (li.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR)
|
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
high = length >> 32;
|
high = length >> 32;
|
||||||
if (!SetFilePointer(h, (DWORD) length, &high, FILE_BEGIN))
|
dw = SetFilePointer(h, (DWORD) length, &high, FILE_BEGIN);
|
||||||
|
if (dw == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
res = SetEndOfFile(h);
|
res = SetEndOfFile(h);
|
||||||
|
|
||||||
/* back to old position */
|
/* back to old position */
|
||||||
|
|
Loading…
Reference in New Issue