Re: [PATCH/WIP v3 01/31] wrapper: implement xopen()
- From
Paul Tan <pyokagan@gmail.com>
- Date
- Jul 1, 2015, 09:53 UTC
- Message-ID
- <CACRoPnR4-N6i_budk+HHoYoBxPQJELp_-Rmsm=JZwfVQGNJgBQ@mail.gmail.com>
- In-Reply-To
- <CACRoPnRqnFESb4tom1FLWxpumLz-BxfBksG=gMePqSzV44=_CQ@mail.gmail.com>
On Wed, Jul 1, 2015 at 5:41 PM, Paul Tan <pyokagan@gmail.com> wrote:
> Good point, I agree with this. I'll look into putting the error messages back.
This should work I think. It should take into account that O_RDONLY, O_WRONLY, O_RDWR is defines as 0, 1, 2 on glibc, while the POSIX spec also defines that O_RDONLY | O_WRONLY == O_RDWR.
diff --git a/wrapper.c b/wrapper.c index c867ca9..e451463 100644 --- a/wrapper.c +++ b/wrapper.c @@ -214,7 +214,13 @@ int xopen(const char *path, int oflag, ...) return fd; if (errno == EINTR) continue; - die_errno(_("could not open '%s'"), path); + + 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); + else + die_errno(_("could not open '%s' for reading"), path); } } @@ -351,7 +357,13 @@ FILE *xfopen(const char *path, const char *mode) return fp; if (errno == EINTR) continue; - die_errno(_("could not open '%s'"), path); + + if (*mode && mode[1] == '+') + die_errno(_("could not open '%s' for reading and writing"), path); + else if (*mode == 'w' || *mode == 'a') + die_errno(_("could not open '%s' for writing"), path); + else + die_errno(_("could not open '%s' for reading"), path); } }