Re: [PATCH/WIP v3 01/31] wrapper: implement xopen()
From: Paul Tan <hidden>
Date: 2016-06-15 23:05:36
Subsystem:
the rest · Maintainer:
Linus Torvalds
On Wed, Jul 1, 2015 at 5:41 PM, Paul Tan [off-list ref] 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); } }