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.

Location:
trunk/src/kmk/kmkbuiltin
Files:
4 edited

Legend:

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

    r2466 r2702  
    8383
    8484#if defined(_MSC_VER) || defined(__gnu_linux__) || defined(__linux__)
    85 extern char *strlcpy(char *, const char *, size_t);
     85extern size_t strlcpy(char *, const char *, size_t);
    8686#endif
    8787
  • 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 
  • trunk/src/kmk/kmkbuiltin/mscfakes.h

    r2592 r2702  
    3939#include <io.h>
    4040#include <direct.h>
     41#include "nt/ntstat.h"
    4142#if defined(MSC_DO_64_BIT_IO) && _MSC_VER >= 1400 /* We want 64-bit file lengths here when possible. */
    4243# define off_t __int64
    43 # undef stat
    44 # define stat  _stat64
    45 # define fstat _fstat64
    4644# define lseek _lseeki64
    47 #else
    48 # ifndef STAT_REDEFINED_ALREADY
    49 #  define STAT_REDEFINED_ALREADY
    50 #  undef stat
    51 #  define stat(_path, _st) bird_w32_stat(_path, _st)
    52 extern int bird_w32_stat(const char *, struct stat *);
    53 # endif
    5445#endif
    55 
    56 #ifndef S_ISDIR
    57 # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
    58 #endif
    59 #ifndef S_ISREG
    60 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
    61 #endif
    62 #define S_ISLNK(m)  0
    63 #define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC)
    64 #define S_IXUSR _S_IEXEC
    65 #define S_IWUSR _S_IWRITE
    66 #define S_IRUSR _S_IREAD
    67 #define S_IRWXG 0000070
    68 #define S_IRGRP 0000040
    69 #define S_IWGRP 0000020
    70 #define S_IXGRP 0000010
    71 #define S_IRWXO 0000007
    72 #define S_IROTH 0000004
    73 #define S_IWOTH 0000002
    74 #define S_IXOTH 0000001
    75 #define S_ISUID 0004000
    76 #define S_ISGID 0002000
    77 #define ALLPERMS 0000777
    7846
    7947#undef  PATH_MAX
     
    141109#define geteuid()  0
    142110#define getegid()  0
    143 #define lstat(path, s) stat(path, s)
    144111int lchmod(const char *path, mode_t mode);
    145112int msc_chmod(const char *path, mode_t mode);
     
    172139int writev(int fd, const struct iovec *vector, int count);
    173140
     141
     142
     143/*
     144 * MSC fake internals / helpers.
     145 */
     146int birdSetErrno(unsigned dwErr);
     147
    174148#endif /* _MSC_VER */
    175149#endif
  • trunk/src/kmk/kmkbuiltin/rm.c

    r2546 r2702  
    499499                                rval = undelete(f);
    500500                                operation = "undelete";
     501#ifndef _MSC_VER
    501502                        } else if (S_ISDIR(sb.st_mode)) {
     503#else
     504                        } else if (S_ISDIR(sb.st_mode) || sb.st_dirsymlink) {
     505#endif
    502506                                rval = rmdir(f);
    503507                                operation = "rmdir";
Note: See TracChangeset for help on using the changeset viewer.