Re: [AD] About findfirst (2)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]



On Mon, 27 Aug 2001, Eric Botcazou wrote:

> > Why don't use stat() to implement file_exists()? At least on Unix/POSIX as
> > findfirst() is also emulated using stat() (and open/readdir() of course).
>
> Because of its semantics: file_exists() supports the attributes of
> files, therefore it needs the attribute emulation for POSIX that
> al_findfirst() provides.

But it's emulated using stat() (and looking for '.' for FA_HIDDEN). Why
don't we make support function (modified internals of _alemu_findnext()):

int _al_get_file_attrib (const char *fullname, const char *filename,
                         struct stat *stat_p) {
      int attrib;

      /* get file statistics */
      if (stat(fullname, stat_p))
         return -1;

      attrib = 0;
      if ((stat_p->st_uid == geteuid())) {
         if ((stat_p->st_mode & S_IWUSR) == 0)
             attrib |= FA_RDONLY;
      }
      else if ((stat_p->st_gid == getegid())) {
         if ((stat_p->st_mode & S_IWGRP) == 0)
             attrib |= FA_RDONLY;
      }
      else if ((stat_p->st_mode & S_IWOTH) == 0) {
         attrib |= FA_RDONLY;
      }
      if (S_ISDIR(stat_p->st_mode))
         attrib |= FA_DIREC;
      if ((filename[0] == '.')
          && ((filename[1] != '.')
              || (filename[2] != 0)))
         attrib |= FA_HIDDEN;

      return attrib;
}

and use it in _alemu_findnext() or your new functions? Block starting with
/* get file statistics */ and ending before /* have any attributes, not
listed in attrib? */ (lines 273-295 of libc.c) could be:

ffblk->ff_attrib = _al_get_file_attrib (filename, tempname, &(ff_info->stat));
if (ffblk->ff_attrib == -1)
   continue;

Have a nice day.

Stepan Roh



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/