summaryrefslogtreecommitdiff
path: root/block/raw-win32.c
diff options
context:
space:
mode:
authorFabien Chouteau <chouteau@adacore.com>2012-12-10 12:56:22 +0100
committerKevin Wolf <kwolf@redhat.com>2012-12-11 11:36:57 +0100
commitfbcad04d6bfdff937536eb23088a01a280a1a3af (patch)
tree3ffaa692e073c9b8aab4d82747a2da5d204a4174 /block/raw-win32.c
parent473c7f0255920bcaf37411990a3725898772817f (diff)
downloadqemu-fbcad04d6bfdff937536eb23088a01a280a1a3af.tar.gz
Fix error code checking for SetFilePointer() call
An error has occurred if the return value is invalid_set_file_pointer and getlasterror doesn't return no_error. Signed-off-by: Fabien Chouteau <chouteau@adacore.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'block/raw-win32.c')
-rw-r--r--block/raw-win32.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/block/raw-win32.c b/block/raw-win32.c
index 0c05c58c5a..ce207a3109 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -303,13 +303,24 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset)
{
BDRVRawState *s = bs->opaque;
LONG low, high;
+ DWORD dwPtrLow;
low = offset;
high = offset >> 32;
- if (!SetFilePointer(s->hfile, low, &high, FILE_BEGIN))
- return -EIO;
- if (!SetEndOfFile(s->hfile))
+
+ /*
+ * An error has occurred if the return value is INVALID_SET_FILE_POINTER
+ * and GetLastError doesn't return NO_ERROR.
+ */
+ dwPtrLow = SetFilePointer(s->hfile, low, &high, FILE_BEGIN);
+ if (dwPtrLow == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR) {
+ fprintf(stderr, "SetFilePointer error: %d\n", GetLastError());
+ return -EIO;
+ }
+ if (SetEndOfFile(s->hfile) == 0) {
+ fprintf(stderr, "SetEndOfFile error: %d\n", GetLastError());
return -EIO;
+ }
return 0;
}