Re: [PATCH/WIP v3 01/31] wrapper: implement xopen()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 1, 2015 at 5:41 PM, Paul Tan <pyokagan@xxxxxxxxx> 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);
     }
 }
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]