aboutsummaryrefslogtreecommitdiff
path: root/block/raw-win32.c
diff options
context:
space:
mode:
authorStefan Weil <weil@mail.berlios.de>2011-08-20 12:10:05 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2011-08-22 10:19:00 -0500
commit2c993ec294893af31deed27e5d79610ce71642e1 (patch)
tree2f51b19ea8f87c8d5386af80f83559a2f5512494 /block/raw-win32.c
parent1f22a6bc62bc7b1c21a4dc5c9cf16e156ad8321e (diff)
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>
Diffstat (limited to 'block/raw-win32.c')
-rw-r--r--block/raw-win32.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/block/raw-win32.c b/block/raw-win32.c
index e47cfe0f4a..b7dd357c6d 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -41,6 +41,7 @@ typedef struct BDRVRawState {
int qemu_ftruncate64(int fd, int64_t length)
{
LARGE_INTEGER li;
+ DWORD dw;
LONG high;
HANDLE h;
BOOL res;
@@ -53,12 +54,15 @@ int qemu_ftruncate64(int fd, int64_t length)
/* get current position, ftruncate do not change position */
li.HighPart = 0;
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;
+ }
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;
+ }
res = SetEndOfFile(h);
/* back to old position */