Ignore:
Timestamp:
Sep 15, 2006, 9:06:56 AM (19 years ago)
Author:
bird
Message:

workaround for directory statting (overrides the stat symbol).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/w32/pathstuff.c

    r503 r508  
    233233}
    234234
     235/* Workaround for directory names with trailing slashes. */
     236int
     237stat(const char *path, struct stat *st)
     238{
     239    int rc = _stat(path, st);
     240    if (    rc != 0
     241        &&  errno == ENOENT
     242        &&  *path != '\0')
     243      {
     244        char *slash = strchr(path, '\0') - 1;
     245        if (*slash == '/' || *slash == '\\')
     246          {
     247            size_t len_path = slash - path + 1;
     248            char *tmp = alloca(len_path + 4);
     249            memcpy(tmp, path, len_path);
     250            tmp[len_path] = '.';
     251            tmp[len_path + 1] = '\0';
     252            errno = 0;
     253            rc = _stat(tmp, st);
     254            if (    rc == 0
     255                &&  !S_ISDIR(st->st_mode))
     256              {
     257                errno = ENOTDIR;
     258                rc = -1;
     259              }
     260          }
     261      }
     262    return rc;
     263}
     264
    235265#ifdef unused
    236266/*
Note: See TracChangeset for help on using the changeset viewer.