[libcamera-devel] [PATCH 4/4] libcamera: file: Create the file on open() if it doesn't exist
Niklas Söderlund
niklas.soderlund at ragnatech.se
Mon Jul 13 08:58:41 CEST 2020
Hi Laurent,
Thanks for your patch.
On 2020-07-12 17:44:19 +0300, Laurent Pinchart wrote:
> When a file is opened in WriteOnly or ReadWrite mode, create it if it
> doesn't exist.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> ---
> 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;
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
--
Regards,
Niklas Söderlund
More information about the libcamera-devel
mailing list