Skip to content

Commit

Permalink
add directory caching for Win32
Browse files Browse the repository at this point in the history
-opendir/readdir aren't available on Win32, so use
 http://www.softagalleria.net/dirent.php , another alternative source of
 readdir would be Win32 Perl's readdir, but the perl interp would need to
 be removed from the code to use it, using this plain C solution is the
 easiest ATM

CacheStat:
-reuse the private (but it isnt private, since we have the src in dirent.h)
 stat-like info by peaking inside the opaque DIR *, avoid doing more kernel
 calls and filename ASCII to Unicode conversions
-don't do strlen twice
-use GetFileAttributesEx instead of _stat, MS CRT _stat uses
 FindFirstFile/FindClose which contains 3 syscalls to the kernel (open dir,
 query entry in dir, close) GetFileAttributesEx is more efficient since
 it doesn't create a kernel handle with NT Object Manager, and uses a
 kernel C stack alloced FILE_OBJECT instead of kernel malloc FILE_OBJECT

-add WIN32_LEAN_AND_MEAN so a .i file is a couple hundred KB smaller
 this makes my IDE more responsive in greping a dmake .i file
  • Loading branch information
bulk88 authored and mohawk2 committed Mar 9, 2015
1 parent 6f6ace5 commit 942d008
Show file tree
Hide file tree
Showing 20 changed files with 889 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Expand Up @@ -54,7 +54,7 @@ if OSTYPEWIN32
dmake_SOURCES += win95/dchdir.c win95/switchar.c \
msdos/dstrlwr.c msdos/arlib.c \
msdos/dirbrk.c unix/runargv.c \
unix/rmprq.c \
unix/rmprq.c unix/dcache.c \
win95/microsft/ruletab.c
AM_CPPFLAGS += -I$(top_srcdir)/@OS_TYPE@/@OS_VERSION@ -I$(top_srcdir)/@OS_TYPE@
endif
Expand Down
5 changes: 5 additions & 0 deletions extern.h
Expand Up @@ -30,6 +30,7 @@
/* For MSVC++ needs to include windows.h first to avoid problems with
* type redefinitions. Include it also for MinGW for consistency. */
#if defined(__MINGW32__) || defined(_MSC_VER)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

Expand Down Expand Up @@ -167,6 +168,10 @@ char *cygdospath(char *src, int winpath);
#endif
#endif

#ifdef _WIN32
# define FileTimeTo_time_t(ft) ((time_t)((*((unsigned __int64 *)ft) - 116444736000000000ULL)/10000000ULL))
#endif

/* Get the working directory fall back code */
#if ! HAVE_GETCWD
#if HAVE_GETWD
Expand Down
34 changes: 29 additions & 5 deletions unix/dcache.c
Expand Up @@ -87,7 +87,11 @@ CacheStat(path, force)
char *path;
int force;
{
#ifdef _WIN32
WIN32_FILE_ATTRIBUTE_DATA FileInformation;
#else
struct stat stbuf;
#endif
DirEntryPtr dp;
EntryPtr ep;
uint32 hkey;
Expand Down Expand Up @@ -163,9 +167,16 @@ int force;

ep->next = dp->entries;
dp->entries = ep;
#ifdef _WIN32
ep->isdir = (direntp->d_type & DT_DIR);
/* internal to win32 readdir, stat-like data is already available from
FindNextFile()/win32 readdir */
ep->mtime = FileTimeTo_time_t(&((DIR*)direntp)->wdirp->data.ftLastWriteTime);
#else
DMSTAT(direntp->d_name,&stbuf);
ep->isdir = (stbuf.st_mode & S_IFDIR);
ep->mtime = stbuf.st_mtime;
#endif
}
closedir(dirp);
}
Expand All @@ -185,14 +196,20 @@ int force;
ep = NULL;

if( force && !loaded) {
if (strlen(comp) > NameMax || DMSTAT(spath,&stbuf) != 0) {
/* Either file to long or the stat failed. */
if (strlen(comp) > NameMax)
Warning( "File [%s] longer than value of NAMEMAX [%d].\n\
if (strlen(comp) > NameMax) {
Warning( "File [%s] longer than value of NAMEMAX [%d].\n\
Assume unix time 0.\n", comp, NameMax );
if(ep)
ep->mtime = 0L;
}
#ifdef _WIN32
else if (GetFileAttributesEx(spath, GetFileExInfoStandard, &FileInformation) == 0) {
#else
else if (DMSTAT(spath,&stbuf) != 0) {
#endif
if(ep)
ep->mtime = 0L;
}
else {
if (!ep) {
TALLOC(ep,1,Entry);
Expand All @@ -201,11 +218,18 @@ int force;
strlwr(ep->name);
Hash(ep->name, &ep->hkey);
ep->next = dp->entries;
#ifdef _WIN32
ep->isdir = FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
#else
ep->isdir = (stbuf.st_mode & S_IFDIR);
#endif
dp->entries = ep;
}

#ifdef _WIN32
ep->mtime = FileTimeTo_time_t(&(FileInformation.ftLastWriteTime));
#else
ep->mtime = stbuf.st_mtime;
#endif
}

if( Verbose & V_DIR_CACHE )
Expand Down
3 changes: 3 additions & 0 deletions win95/borland/bcc50/mk.bat
Expand Up @@ -20,6 +20,9 @@ del hash.obj
bcc32 -c -I. -Iwin95 -Iwin95\borland -d -O -N- -w-nod -A- -w-pro -Iwin95\borland\bcc50 dag.c
copy dag.obj objects
del dag.obj
bcc32 -c -I. -Iwin95 -Iwin95\borland -d -O -N- -w-nod -A- -w-pro -Iwin95\borland\bcc50 unix\dcache.c
copy dcache.obj objects
del dcache.obj
bcc32 -c -I. -Iwin95 -Iwin95\borland -d -O -N- -w-nod -A- -w-pro -Iwin95\borland\bcc50 dmake.c
copy dmake.obj objects
del dmake.obj
Expand Down
1 change: 1 addition & 0 deletions win95/borland/bcc50/obj.rsp
Expand Up @@ -6,6 +6,7 @@ objects\expand.obj+
objects\dmstring.obj+
objects\hash.obj+
objects\dag.obj+
objects\dcache.obj+
objects\dmake.obj+
objects\path.obj+
objects\imacs.obj+
Expand Down
1 change: 0 additions & 1 deletion win95/borland/sysintf.h
Expand Up @@ -39,7 +39,6 @@ extern char * getcwd();
** DOS interface standard items
*/
#define chdir(p) dchdir(p)
#define CacheStat(A,B) really_dostat(A,&buf)

/*
** make parameters
Expand Down

0 comments on commit 942d008

Please sign in to comment.