VirtualBox

Changeset 1321 in kBuild for trunk/src/kmk/kmkbuiltin/mscfakes.c


Ignore:
Timestamp:
Dec 2, 2007 10:28:19 AM (17 years ago)
Author:
bird
Message:

Fix stat(./).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/mscfakes.c

    r1108 r1321  
    300300}
    301301
     302
     303#undef stat
     304/*
     305 * Workaround for directory names with trailing slashes.
     306 * Added by bird reasons stated.
     307 */
     308int
     309my_other_stat(const char *path, struct stat *st)
     310{
     311    int rc = stat(path, st);
     312    if (    rc != 0
     313        &&  errno == ENOENT
     314        &&  *path != '\0')
     315    {
     316        char *slash = strchr(path, '\0') - 1;
     317        if (*slash == '/' || *slash == '\\')
     318        {
     319            size_t len_path = slash - path + 1;
     320            char *tmp = alloca(len_path + 4);
     321            memcpy(tmp, path, len_path);
     322            tmp[len_path] = '.';
     323            tmp[len_path + 1] = '\0';
     324            errno = 0;
     325            rc = stat(tmp, st);
     326            if (    rc == 0
     327                &&  !S_ISDIR(st->st_mode))
     328            {
     329                errno = ENOTDIR;
     330                rc = -1;
     331            }
     332        }
     333    }
     334    return rc;
     335}
     336
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette