From patchwork Sun Jul 12 14:44:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8748 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 9293ABDB1C for ; Sun, 12 Jul 2020 14:44:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 00217605A9; Sun, 12 Jul 2020 16:44: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="m38qBXQT"; 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 76F2660553 for ; Sun, 12 Jul 2020 16:44:46 +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 19162514 for ; Sun, 12 Jul 2020 16:44:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1594565086; bh=P8w89z8xbNHDF349DY+fLiUMnmCNQQdr8/6RU2YdgfY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=m38qBXQTtW08hPA3IljWpZU242PdgVFOs+IC2UTactlbhEgHQykD//EJnk6DV3dAl H0oQQsltVBhi5NdjHGp7Cj+Fz2XKvqUL5MKAhCsWfBvnug7r+F90zp5xvF6OdG477s E/+wR658AEuh0I6088GezhGpRBTDYXZm3XCGnGu0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 12 Jul 2020 17:44:19 +0300 Message-Id: <20200712144419.21457-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200712144419.21457-1-laurent.pinchart@ideasonboard.com> References: <20200712144419.21457-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 8bd109090919..77701666e438 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;