Thread (18 messages) flat view 18 messages, 5 authors, 2016-06-15

Re: [PATCH/WIP 1/8] wrapper: implement xopen()

From: Paul Tan <hidden>
Date: 2016-06-15 23:05:08

On Thu, May 28, 2015 at 3:03 AM, Torsten Bögershausen [off-list ref] wrote:
On 2015-05-27 15.33, Paul Tan wrote:
quoted
+/**
+ * xopen() is the same as open(), but it die()s if the open() fails.
+ */
+int xopen(const char *path, int flags, mode_t mode)
+{
+     int fd;
+
+     assert(path);
+     fd = open(path, flags, mode);
+     if (fd < 0) {
+             if ((flags & O_WRONLY) || (flags & O_RDWR))
+                     die_errno(_("could not open '%s' for writing"), path);
This is only partly true:
it could be either "writing" or "read write".
Ah right, I see now that the POSIX spec allows for, and encourages
O_RDONLY | O_WRONLY == O_RDWR.
I don't know if the info "for reading" or "for writing" is needed/helpful at all,
or if a simple "could not open" would be enough.
Yeah, I agree that it may not be helpful, but I noticed that most
error messages in git are of the form "unable to open X for writing",
"unable to open X for reading", "could not create X" etc. Or rather I
thought I noticed, but it now seems to me that there are quite a lot
of uses of "could not open X" as well.

I guess I will remove the distinction.

Thanks,
Paul
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help