Re: [PATCH] commit: ensure correct permissions of the commit message

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

 



Johannes Schindelin <Johannes.Schindelin@xxxxxx> writes:

> So maybe
>
> 	fcreate_or_truncate(const char *path)
> 	{
> 		 FILE *ret = fopen(path, "w");
>
> 		 if (!ret && errno == EPERM) {
> 			 if (!unlink(path))
> 				 ret = fopen(path, "w");
> 			 else
> 				 errno = EPERM;
> 		 }
> 		 return ret;
> 	 }
>
> ?

I do not know fcreate_or_truncate() is a good name, though.  Looking
for "fcreate(3)" seems to find something quite obscure and unrelated
to what we want (http://linux.die.net/man/3/fcreate).  Also we call
a function X_or_Y to mean "try to do our primary thing X, and do Y
instead when it fails", but what we want to do here is not that.  We
are not interested in creating (i.e. we can happily live with an
existing file opened for writing), and we do not just truncate if we
cannot open the original for writing (i.e. we do return a writable
file handle) [*1*].

In any case, obviously the return value of the function needs to be
of type "FILE *".

Other than that, the code inside the function looks exactly like
what I had in mind.

Thanks.


[Footnote]

*1* We tend to call a function sane_X() when we are fixing an
    undesirable behaviour in the underlying function X (e.g.
    sane_execvp()).  In that sense it is very tempting to call this
    sane_fopen() but our use is limited to fopen(path, "w"), i.e.
    "open for writing, while truncating if existing" use case of
    fopen().
--
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]