Re: [PATCH] opening files in remote.c should ensure it is opening a file
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Feb 8, 2008, 20:38 UTC
- Message-ID
- <alpine.LSU.1.00.0802082035460.11591@racer.site>
- In-Reply-To
- <7vhcgjjjlh.fsf@gitster.siamese.dyndns.org>
Hi,
On Fri, 8 Feb 2008, Junio C Hamano wrote:
Show 16 quoted lines
> "H.Merijn Brand" <h.m.brand@xs4all.nl> writes:
>
> > HP-UX allows directories to be opened with fopen (path, "r"), which
> > will cause some translations that expect to read files, read dirs
> > instead. This patch makes sure the two fopen () calls in remote.c
> > only open the file if it is a file.
>
> > +static FILE *open_file(char *full_path)
> > +{
> > + struct stat st_buf;
> > + if (stat(full_path, &st_buf) || !S_ISREG(st_buf.st_mode))
> > + return NULL;
> > + return (fopen(full_path, "r"));
> > +}
>
> Can we make this a platform specific "compat" hack?You mean something like
#ifdef FOPEN_OPENS_DIRECTORIES
inline static FILE *fopen_compat(const char *path, const char *mode)
{
struct stat st_buf;
if (stat(path, &st_buf) || !S_ISREG(st_buf.st_mode))
return NULL;
return (fopen(path, mode));
}
#define fopen fopen_compat
#endifin git-compat-util.h, right?
Yeah, I can see that, even if I think the overhead would not be _that_ crucial. But it is a nice way of fixing _all_ fopen() calls at the same time.
Ciao, Dscho