Received: from eggs.gnu.org ([2001:4830:134:3::10]:51428) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS5t3-0005zO-N3 for qemu-devel@nongnu.org; Tue, 26 Jul 2016 13:11:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bS5sw-0005g9-Hf for qemu-devel@nongnu.org; Tue, 26 Jul 2016 13:11:20 -0400 Received: from qemu.weilnetz.de ([2a03:4000:2:362::1]:54055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bS5sw-0005f3-B7 for qemu-devel@nongnu.org; Tue, 26 Jul 2016 13:11:14 -0400 From: Stefan Weil Date: Tue, 26 Jul 2016 19:11:09 +0200 Message-Id: <1469553069-15350-1-git-send-email-sw@weilnetz.de> Subject: [Qemu-devel] [PATCH for-2.7] wxx: Truncate files used for character devices List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developer Cc: Peter Maydell , Paolo Bonzini , Benjamin David Lunt , Stefan Weil On Windows, such files were not truncated like on all other hosts. Now we also test whether truncation is needed when running on Windows. Reported-by: Benjamin David Lunt Signed-off-by: Stefan Weil --- qemu-char.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qemu-char.c b/qemu-char.c index e4b8448..7de63c8 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -4197,14 +4197,23 @@ static CharDriverState *qmp_chardev_open_file(const char *id, ChardevFile *file = backend->u.file.data; ChardevCommon *common = qapi_ChardevFile_base(file); HANDLE out; + DWORD flags; if (file->has_in) { error_setg(errp, "input file not supported"); return NULL; } + if (file->has_append && file->append) { + /* Append to file if it already exists. */ + flags = OPEN_ALWAYS; + } else { + /* Truncate file if it already exists. */ + flags = CREATE_ALWAYS; + } + out = CreateFile(file->out, GENERIC_WRITE, FILE_SHARE_READ, NULL, - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + flags, FILE_ATTRIBUTE_NORMAL, NULL); if (out == INVALID_HANDLE_VALUE) { error_setg(errp, "open %s failed", file->out); return NULL; -- 2.1.4