VirtualBox

Changeset 2702 in kBuild for trunk/src/kmk


Ignore:
Timestamp:
Nov 21, 2013 12:11:08 AM (11 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
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.kmk

    r2667 r2702  
    130130        w32/subproc/sub_proc.c \
    131131        w32/subproc/w32err.c \
    132         w32/compat/dirent.c \
    133132        w32/pathstuff.c \
    134133        w32/imagecache.c
  • trunk/src/kmk/config.h.win

    r2592 r2702  
    273273
    274274/* Define to 1 if you have the <sys/stat.h> header file. */
    275 /* #define HAVE_SYS_STAT_H 1 */
     275#define HAVE_SYS_STAT_H 1
    276276
    277277/* Define to 1 if you have the <sys/timeb.h> header file. */
     
    384384
    385385/* Define if struct stat contains a nanoseconds field */
    386 /* #undef ST_MTIM_NSEC */
     386#define ST_MTIM_NSEC tv_nsec
    387387
    388388/* Define to 1 on System V Release 4. */
     
    523523#endif
    524524
    525 /* bird hacks - similar in mscfakes.h */
    526 #include <sys/stat.h>
     525/* bird stat hacks. */
    527526#include <io.h>
    528527#include <direct.h>
    529 #ifndef STAT_REDEFINED_ALREADY
    530 # define STAT_REDEFINED_ALREADY
    531 # undef stat
    532 # define stat(_path, _st) bird_w32_stat(_path, _st)
    533 extern int bird_w32_stat(const char *, struct stat *);
    534 #endif
     528#include "nt/ntstat.h"
     529
     530/* bird dirent hack. */
     531#define _DIRENT_H /* see w32/dirent.h */
     532#include "nt/ntdir.h"
     533#define _DIRENT_HAVE_D_NAMLEN 1
     534#define _DIRENT_HAVE_D_TYPE   1
     535
    535536
    536537/* cygwin sucks to much in one end or the other. */
  • trunk/src/kmk/dir.c

    r2591 r2702  
    121121
    122122#ifdef WINDOWS32
     123#include <Windows.h>
    123124#include "pathstuff.h"
    124125#endif
     
    244245# define FS_NTFS     0x2
    245246# define FS_UNKNOWN  0x4
     247# ifdef KMK
     248    time_t last_updated; /**< The last time the directory was re-read. */
     249# endif
    246250#else
    247251# ifdef VMS
     
    611615              dc->ctime = st.st_ctime;
    612616              dc->mtime = st.st_mtime;
     617# ifdef KMK
     618              dc->last_updated = time(NULL);
     619# endif
    613620
    614621              /*
     
    691698  struct dirent *d;
    692699#ifdef WINDOWS32
     700# ifndef KMK
    693701  struct stat st;
     702# endif
    694703  int rehash = 0;
    695704#endif
     
    745754  if (dir->dirstream == 0)
    746755    {
    747 #ifdef WINDOWS32
     756#if defined(WINDOWS32) && !defined(KMK)
    748757      /*
    749758       * Check to see if directory has changed since last read. FAT
     
    751760       * on directories (ugh!).
    752761       */
     762# ifdef KMK
     763      if (dir->path_key && time(NULL) > dc->last_updated + 2) /* KMK: Only recheck every 2 seconds. */
     764# else
    753765      if (dir->path_key)
     766# endif
    754767        {
    755768          if ((dir->fs_flags & FS_FAT) != 0)
     
    758771              rehash = 1;
    759772            }
     773# ifdef KMK
     774          else if (   birdStatModTimeOnly (dir->path_key, &st.st_mtim, 1) == 0
     775                   && st.st_mtime > dir->mtime)
     776# else
    760777          else if (stat (dir->path_key, &st) == 0 && st.st_mtime > dir->mtime)
     778# endif
    761779            {
    762780              /* reset date stamp to show most recent re-process.  */
     
    765783            }
    766784
     785
    767786          /* If it has been already read in, all done.  */
    768787          if (!rehash)
     
    773792          if (!dir->dirstream)
    774793            return 0;
     794# ifdef KMK
     795          dc->last_updated = time(NULL);
     796# endif
    775797        }
    776798      else
     
    14001422#endif
    14011423
     1424#ifdef KMK
     1425static int dir_exists_p (const char *dirname)
     1426{
     1427  if (file_exists_p (dirname))
     1428    {
     1429      struct directory *dir = find_directory (dirname);
     1430      if (dir != NULL && dir->contents && dir->contents->dirfiles.ht_vec != NULL)
     1431        return 1;
     1432    }
     1433  return 0;
     1434}
     1435#endif
     1436
    14021437void
    14031438dir_setup_glob (glob_t *gl)
     
    14091444#ifdef __EMX__ /* The FreeBSD implementation actually uses gl_lstat!! */
    14101445  gl->gl_lstat = local_stat;
     1446#endif
     1447#ifdef KMK
     1448  gl->gl_exists = file_exists_p;
     1449  gl->gl_isdir = dir_exists_p;
    14111450#endif
    14121451  /* We don't bother setting gl_lstat, since glob never calls it.
     
    14361475#endif /* CONFIG_WITH_ALLOC_CACHES */
    14371476}
     1477
  • trunk/src/kmk/function.c

    r2698 r2702  
    44384438                  const char *src = comp;
    44394439                  const char *end = strchr (comp, PATH_SEPARATOR_CHAR);
    4440                   size_t comp_len = end ? (size_t)(end - comp) : strlen (comp);
    4441                   if (!comp_len)
     4440                  size_t src_len = end ? (size_t)(end - comp) : strlen (comp);
     4441                  if (!src_len)
    44424442                    {
    4443                       comp_len = 1;
     4443                      src_len = 1;
    44444444                      src = ".";
    44454445                    }
    4446                   if (len + comp_len + 2 + 4 < GET_PATH_MAX) /* +4 for .exe */
     4446                  if (len + src_len + 2 + 4 < GET_PATH_MAX) /* +4 for .exe */
    44474447                    {
    4448                       memcpy (buf, comp, comp_len);
    4449                       buf [comp_len] = '/';
    4450                       memcpy (&buf[comp_len + 1], cur, len);
    4451                       buf[comp_len + 1 + len] = '\0';
     4448                      memcpy (buf, src, src_len);
     4449                      buf [src_len] = '/';
     4450                      memcpy (&buf[src_len + 1], cur, len);
     4451                      buf[src_len + 1 + len] = '\0';
    44524452
    44534453                      if (func_which_test_x (buf))
  • trunk/src/kmk/glob/glob.c

    r2591 r2702  
    807807      /* Return the directory if we don't check for error or if it exists.  */
    808808      if ((flags & GLOB_NOCHECK)
     809#ifdef KMK
     810          || (flags & GLOB_ALTDIRFUNC
     811              ? (*pglob->gl_isdir) (dirname)
     812              : __stat (dirname, &st) == 0 && S_ISDIR (st.st_mode))
     813#else
    809814          || (((flags & GLOB_ALTDIRFUNC)
    810815               ? (*pglob->gl_stat) (dirname, &st)
    811816               : __stat (dirname, &st)) == 0
    812               && S_ISDIR (st.st_mode)))
     817              && S_ISDIR (st.st_mode))
     818#endif
     819          )
    813820        {
    814821          pglob->gl_pathv
     
    954961
    955962                  /* First check whether this really is a directory.  */
     963#ifdef KMK
     964                  if (flags & GLOB_ALTDIRFUNC
     965                      ? !pglob->gl_isdir (dir)
     966                      : __stat (dir, &st) != 0 || !S_ISDIR (st.st_mode))
     967#else
    956968                  if (((flags & GLOB_ALTDIRFUNC)
    957969                       ? (*pglob->gl_stat) (dir, &st) : __stat (dir, &st)) != 0
    958970                      || !S_ISDIR (st.st_mode))
     971#endif
    959972                    /* No directory, ignore this entry.  */
    960973                    continue;
     
    10291042      struct stat st;
    10301043      for (i = oldcount; i < pglob->gl_pathc; ++i)
     1044#ifdef KMK
     1045        if (flags & GLOB_ALTDIRFUNC
     1046            ? pglob->gl_isdir (pglob->gl_pathv[i])
     1047            : __stat (pglob->gl_pathv[i], &st) == 0 && S_ISDIR (st.st_mode) )
     1048#else
    10311049        if (((flags & GLOB_ALTDIRFUNC)
    10321050             ? (*pglob->gl_stat) (pglob->gl_pathv[i], &st)
    10331051             : __stat (pglob->gl_pathv[i], &st)) == 0
    10341052            && S_ISDIR (st.st_mode))
     1053#endif
    10351054          {
    10361055            size_t len = strlen (pglob->gl_pathv[i]) + 2;
     
    12621281          memcpy (&fullname[dirlen + 1], pattern, patlen + 1);
    12631282# endif
     1283# ifdef KMK
     1284          if (flags & GLOB_ALTDIRFUNC ? pglob->gl_exists (fullname) : __stat (fullname, &st) == 0)
     1285# else
    12641286          if (((flags & GLOB_ALTDIRFUNC)
    12651287               ? (*pglob->gl_stat) (fullname, &st)
    12661288               : __stat (fullname, &st)) == 0)
     1289# endif
    12671290            /* We found this file to be existing.  Now tell the rest
    12681291               of the function to copy this name into the result.  */
  • trunk/src/kmk/glob/glob.h

    r1993 r2702  
    137137    int (*gl_stat) __PMT ((__const char *, struct stat *));
    138138#endif
     139#ifdef KMK
     140    int (*gl_exists) __PMT ((__const char *));
     141    int (*gl_isdir) __PMT ((__const char *));
     142#endif
    139143  } glob_t;
    140144
  • 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";
  • trunk/src/kmk/w32/include/dirent.h

    r2591 r2702  
    1818#ifndef _DIRENT_H
    1919#define _DIRENT_H
     20
     21#ifdef KMK
     22# include <windows.h>
     23# include "nt/ntdir.h"
     24
     25#else /* !KMK */
    2026
    2127#ifdef __MINGW32__
     
    5864
    5965#endif  /* !__MINGW32__ */
     66#endif  /* !KMK */
    6067#endif
Note: See TracChangeset for help on using the changeset viewer.

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