From patchwork Tue May 14 21:53:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 243842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 56AD82C00AE for ; Wed, 15 May 2013 07:59:16 +1000 (EST) Received: from localhost ([::1]:37179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcNFa-0004A6-K8 for incoming@patchwork.ozlabs.org; Tue, 14 May 2013 17:59:14 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcNCU-0007Na-9A for qemu-devel@nongnu.org; Tue, 14 May 2013 17:56:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcNCS-0003yz-JO for qemu-devel@nongnu.org; Tue, 14 May 2013 17:56:02 -0400 Received: from mail-ie0-x22a.google.com ([2607:f8b0:4001:c03::22a]:63003) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcNCS-0003yn-F5; Tue, 14 May 2013 17:56:00 -0400 Received: by mail-ie0-f170.google.com with SMTP id aq17so2229907iec.15 for ; Tue, 14 May 2013 14:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=F+oYeGBL2I8JBYeJXA1+0SPjCkEynHGAR940yaeVU38=; b=yZX5uircEUS2h81Ko2WGjHIOlnOEyDlkxZoW17kZof+mWLGx1HhrSq99F+zKrlhV31 M5q2MMhbhDM3q66mgKDCqEu+YFpZjNp7uMkp27FmAzLAYOd/01XnBjc7Xl/CAeP7PopG +RndvLSqYcxbqDSrcxlfi3HhTzfCI+mW83sHd6WaSOkz59ngxbB7xOVx+f4C2NDWcJjo 06K5GBiq/5K0/MjCAqKKotXaMiRgzXPsx1liH32h8TeWae9Y2dKwJzn2X1vb/UCXGfBX 5EzepD4YAN6wgsMOCb1dtinKGweMmy9n2uiX77J4V09kv6bMZrv2tmqQiG5/Nv23/HQJ zBug== X-Received: by 10.50.13.98 with SMTP id g2mr3576905igc.11.1368568559826; Tue, 14 May 2013 14:55:59 -0700 (PDT) Received: from localhost (cpe-72-177-121-217.austin.res.rr.com. [72.177.121.217]) by mx.google.com with ESMTPSA id c2sm26096930igv.1.2013.05.14.14.55.58 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 14 May 2013 14:55:59 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 14 May 2013 16:53:11 -0500 Message-Id: <1368568392-2127-15-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1368568392-2127-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1368568392-2127-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c03::22a Cc: aliguori@us.ibm.com, qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 14/15] qga: distinguish binary modes in "guest_file_open_modes" map X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Laszlo Ersek In Windows guests this may make a difference. Since the original patch (commit c689b4f1) sought to be pedantic and to consider theoretical corner cases of portability, we should fix it up where it failed to come through in that pursuit. Suggested-by: Eric Blake Reviewed-by: Eric Blake Signed-off-by: Laszlo Ersek Reviewed-by: Luiz Capitulino Signed-off-by: Michael Roth (cherry picked from commit 8fe6bbca7176c9dfb35083a71bda95c1856e2ed5) Signed-off-by: Michael Roth --- qga/commands-posix.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 08f3473..933c700 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -164,17 +164,27 @@ static GuestFileHandle *guest_file_handle_find(int64_t id, Error **err) typedef const char * const ccpc; +#ifndef O_BINARY +#define O_BINARY 0 +#endif + /* http://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html */ static const struct { ccpc *forms; int oflag_base; } guest_file_open_modes[] = { - { (ccpc[]){ "r", "rb", NULL }, O_RDONLY }, - { (ccpc[]){ "w", "wb", NULL }, O_WRONLY | O_CREAT | O_TRUNC }, - { (ccpc[]){ "a", "ab", NULL }, O_WRONLY | O_CREAT | O_APPEND }, - { (ccpc[]){ "r+", "rb+", "r+b", NULL }, O_RDWR }, - { (ccpc[]){ "w+", "wb+", "w+b", NULL }, O_RDWR | O_CREAT | O_TRUNC }, - { (ccpc[]){ "a+", "ab+", "a+b", NULL }, O_RDWR | O_CREAT | O_APPEND } + { (ccpc[]){ "r", NULL }, O_RDONLY }, + { (ccpc[]){ "rb", NULL }, O_RDONLY | O_BINARY }, + { (ccpc[]){ "w", NULL }, O_WRONLY | O_CREAT | O_TRUNC }, + { (ccpc[]){ "wb", NULL }, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY }, + { (ccpc[]){ "a", NULL }, O_WRONLY | O_CREAT | O_APPEND }, + { (ccpc[]){ "ab", NULL }, O_WRONLY | O_CREAT | O_APPEND | O_BINARY }, + { (ccpc[]){ "r+", NULL }, O_RDWR }, + { (ccpc[]){ "rb+", "r+b", NULL }, O_RDWR | O_BINARY }, + { (ccpc[]){ "w+", NULL }, O_RDWR | O_CREAT | O_TRUNC }, + { (ccpc[]){ "wb+", "w+b", NULL }, O_RDWR | O_CREAT | O_TRUNC | O_BINARY }, + { (ccpc[]){ "a+", NULL }, O_RDWR | O_CREAT | O_APPEND }, + { (ccpc[]){ "ab+", "a+b", NULL }, O_RDWR | O_CREAT | O_APPEND | O_BINARY } }; static int