Ignore:
Timestamp:
Nov 21, 2013, 1:11:08 AM (12 years ago)
Author:
bird
Message:

kmk/WindowsNT: Avoiding unnecessary stat() calls. Reimplemented stat(), lstat(), fstat(), opendir(), readdir(), and closedir() using native NT APIs.

File:
1 edited

Legend:

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

    r2645 r2702  
    109109
    110110
    111 static int
    112 msc_set_errno(DWORD dwErr)
     111int
     112birdSetErrno(DWORD dwErr)
    113113{
    114114    switch (dwErr)
     
    184184    DWORD fAttr = GetFileAttributes(pszPath);
    185185    if (fAttr == INVALID_FILE_ATTRIBUTES)
    186         rc = msc_set_errno(GetLastError());
     186        rc = birdSetErrno(GetLastError());
    187187    else if (fMustBeDir & !(fAttr & FILE_ATTRIBUTE_DIRECTORY))
    188188    {
     
    200200            fAttr |= FILE_ATTRIBUTE_READONLY;
    201201        if (!SetFileAttributes(pszPath, fAttr))
    202             rc = msc_set_errno(GetLastError());
     202            rc = birdSetErrno(GetLastError());
    203203    }
    204204
     
    224224    DWORD fAttr = GetFileAttributes(pszPath);
    225225    if (fAttr == INVALID_FILE_ATTRIBUTES)
    226         rc = msc_set_errno(GetLastError());
     226        rc = birdSetErrno(GetLastError());
    227227    else if (fMustBeDir & !(fAttr & FILE_ATTRIBUTE_DIRECTORY))
    228228    {
     
    245245            fAttr |= FILE_ATTRIBUTE_READONLY;
    246246        if (!SetFileAttributes(pszPath, fAttr))
    247             rc = msc_set_errno(GetLastError());
     247            rc = birdSetErrno(GetLastError());
    248248    }
    249249
     
    283283    if (s_pfnCreateHardLinkA(pszLink, pszDst, NULL))
    284284        return 0;
    285     return msc_set_errno(GetLastError());
     285    return birdSetErrno(GetLastError());
    286286}
    287287
     
    535535
    536536
    537 /*
    538  * Workaround for directory names with trailing slashes.
    539  */
    540 #undef stat
    541 int
    542 bird_w32_stat(const char *path, struct stat *st)
    543 {
    544     int rc = stat(path, st);
    545     if (    rc != 0
    546         &&  errno == ENOENT
    547         &&  *path != '\0')
    548     {
    549         char *slash = strchr(path, '\0') - 1;
    550         if (*slash == '/' || *slash == '\\')
    551         {
    552             size_t len_path = slash - path + 1;
    553             char *tmp = alloca(len_path + 4);
    554             memcpy(tmp, path, len_path);
    555             tmp[len_path] = '.';
    556             tmp[len_path + 1] = '\0';
    557             errno = 0;
    558             rc = stat(tmp, st);
    559             if (    rc == 0
    560                 &&  !S_ISDIR(st->st_mode))
    561             {
    562                 errno = ENOTDIR;
    563                 rc = -1;
    564             }
    565         }
    566     }
    567 #ifdef KMK_PRF
    568     {
    569         int err = errno;
    570         fprintf(stderr, "stat(%s,) -> %d/%d\n", path, rc, errno);
    571         errno = err;
    572     }
    573 #endif
    574     return rc;
    575 }
    576 
Note: See TracChangeset for help on using the changeset viewer.