From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjARw-0000kp-HR for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:12:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TjARR-0005zL-QJ for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:11:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59327) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjARR-0005zF-Gm for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:11:17 -0500 From: Kevin Wolf Date: Thu, 13 Dec 2012 16:10:29 +0100 Message-Id: <1355411450-12761-23-git-send-email-kwolf@redhat.com> In-Reply-To: <1355411450-12761-1-git-send-email-kwolf@redhat.com> References: <1355411450-12761-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 22/43] Fix error code checking for SetFilePointer() call List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Fabien Chouteau 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 Acked-by: Stefan Hajnoczi --- block/raw-win32.c | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-) diff --git a/block/raw-win32.c b/block/raw-win32.c index 0c05c58..ce207a3 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; } -- 1.7.6.5