From patchwork Tue Jul 14 09:09:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8774 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E73EFBDB1C for ; Tue, 14 Jul 2020 09:09:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AAB696081A; Tue, 14 Jul 2020 11:09:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Kq8j6yyH"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E6C30607BD for ; Tue, 14 Jul 2020 11:09:47 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 93DF671D for ; Tue, 14 Jul 2020 11:09:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594717787; bh=HvbYpu1YRVVxXvEgooF8Tm0ef3WHzKwJTs2u3t7qwUI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Kq8j6yyHzDWwFCWj5lb1rlGVOTx+1VsXe+Np/ZOyGNmRSS26XZ7qC53GyoDwYnQfj eszIeKZ1RXqAjGX0j1Ti+o1kmpgTrD7CfnNbk5s+nngsEiCXy+IqsWtLoJgGy53m/h /5lkzqfCQ2CuEHIItHFb6YFRspImlqfnGMCePGVw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 14 Jul 2020 12:09:36 +0300 Message-Id: <20200714090936.9562-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714090936.9562-1-laurent.pinchart@ideasonboard.com> References: <20200714090936.9562-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/4] libcamera: file: Create the file on open() if it doesn't exist X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When a file is opened in WriteOnly or ReadWrite mode, create it if it doesn't exist. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- src/libcamera/file.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libcamera/file.cpp b/src/libcamera/file.cpp index d99a1806e1c8..04b0cb61a1bf 100644 --- a/src/libcamera/file.cpp +++ b/src/libcamera/file.cpp @@ -148,8 +148,9 @@ bool File::exists() const * \param[in] mode The open mode * * This function opens the file specified by fileName() in \a mode. If the file - * doesn't exist and the mode is WriteOnly or ReadWrite, this - * function will attempt to create the file. + * doesn't exist and the mode is WriteOnly or ReadWrite, this function will + * attempt to create the file with initial permissions set to 0666 (modified by + * the process' umask). * * The error() status is updated. * @@ -163,8 +164,10 @@ bool File::open(File::OpenMode mode) } int flags = (mode & ReadWrite) - 1; + if (mode & WriteOnly) + flags |= O_CREAT; - fd_ = ::open(name_.c_str(), flags); + fd_ = ::open(name_.c_str(), flags, 0666); if (fd_ < 0) { error_ = -errno; return false;