Re: [PATCH 1/2] xopen: explicitly report creation failures
- From
Carlo Arenas <carenas@gmail.com>
- Date
- Aug 25, 2021, 23:46 UTC
- Message-ID
- <CAPUEspjkcV1_R5DNXCkL5wQpZCW+K4As2nGuEGu6fyeFrr15KQ@mail.gmail.com>
- In-Reply-To
- <6a5c3e8e-0216-8b63-38fa-b7b19331d752@web.de>
On Wed, Aug 25, 2021 at 2:11 PM René Scharfe <l.s.r@web.de> wrote:
Show 12 quoted lines
>
> diff --git a/wrapper.c b/wrapper.c
> index 563ad590df..7c6586af32 100644
> --- a/wrapper.c
> +++ b/wrapper.c
> @@ -193,7 +193,9 @@ int xopen(const char *path, int oflag, ...)
> if (errno == EINTR)
> continue;
>
> - if ((oflag & O_RDWR) == O_RDWR)
> + if ((oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
> + die_errno(_("unable to create '%s'"), path);probably over conservative, but && errno == EEXIST?
> + else if ((oflag & O_RDWR) == O_RDWR)
> die_errno(_("could not open '%s' for reading and writing"), path);
> else if ((oflag & O_WRONLY) == O_WRONLY)
> die_errno(_("could not open '%s' for writing"), path);Since you are already changing this code, why not take the opportunity to refactor it and remove the " == FLAG" part of these conditionals which is otherwise redundant?
Either way "Reviewed-by", and indeed a nice cleanup.
Carlo