Re: [PATCH 6/8] fchmodat: don’t mishandle AT_EMPTY_PATH

Bruno Haible via Gnulib discussion list <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Organization GNU
Message-ID <2361370.3ZeAukHxDK@nimes>
Paul Eggert wrote:
> >>   int
> >>   fchmodat (int dir, char const *file, mode_t mode, int flags)
> >>   {
> >> +  if (file && *file)
> >> +    flags &= ~AT_EMPTY_PATH;
> >> +  else if (! (flags & AT_EMPTY_PATH))
> >> +    {
> >> +      errno = ENOENT;
> >> +      return -1;
> >> +    }
> >> +  else if (! (flags & AT_SYMLINK_NOFOLLOW))
> >> +    return fchmod (dir, mode);
> > Shouldn't the last line read
> > 
> >         return fchmod (dir == AT_FDCWD ? "." : dir, mode);
> 
> Thanks, good catch, though the fix isn't quite right. First, fchmod 
> needs an int not a string. Second, 'return dir == AT_FDCWD ? chmod (".", 
> mode) : fchmod (dir, mode);' wouldn't be quite right either, as the 
> chmod would wrongly fail when the working directory is not searchable.

Yeah, I had not thought through all cases and requirements.

Btw, since you are renaming parameters 'int flag' to 'int flags', how
about also renaming 'int dir' to 'int dirfd' ? I am used to declarations
  const char *dir;
  DIR *dir;

Bruno
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.