Re: [PATCH/WIP 1/8] wrapper: implement xopen()
- From
Paul Tan <pyokagan@gmail.com>
- Date
- Jun 4, 2015, 12:05 UTC
- Message-ID
- <CACRoPnRn5ynmt1UXct6BzXpr_aioAtLpXfwjZKMBUs4-sGP63A@mail.gmail.com>
- In-Reply-To
- <55661513.8000306@web.de>
On Thu, May 28, 2015 at 3:03 AM, Torsten Bögershausen <tboegi@web.de> wrote:
Show 15 quoted lines
> On 2015-05-27 15.33, Paul Tan wrote:
>> +/**
>> + * 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