diff options
| author | Hartmut Brandt <harti@FreeBSD.org> | 2005-03-22 12:54:46 +0000 |
|---|---|---|
| committer | Hartmut Brandt <harti@FreeBSD.org> | 2005-03-22 12:54:46 +0000 |
| commit | cbb7c3931c5c869a026e951d191ca638cd9d1fdd (patch) | |
| tree | 13dcc55d3b034812860b6a5af0987cf2d74017fc /usr.bin/make/dir.c | |
| parent | 35167ece764357ea37cc63f760aa8c37ba892409 (diff) | |
Notes
Diffstat (limited to 'usr.bin/make/dir.c')
| -rw-r--r-- | usr.bin/make/dir.c | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/usr.bin/make/dir.c b/usr.bin/make/dir.c index 15b25d423b7d..18afa42ad56a 100644 --- a/usr.bin/make/dir.c +++ b/usr.bin/make/dir.c @@ -104,7 +104,7 @@ __FBSDID("$FreeBSD$"); #include "util.h" /* - * A search path consists of a Lst of Path structures. A Path structure + * A search path consists of a Lst of Dir structures. A Dir structure * has in it the name of the directory and a hash table of all the files * in the directory. This is used to cut down on the number of system * calls necessary to find implicit dependents and their like. Since @@ -136,7 +136,7 @@ __FBSDID("$FreeBSD$"); * that UNIX OS's have taken to allowing more than 20 or 32 * file descriptors for a process, this doesn't seem acceptable * to me. - * 3) record the mtime of the directory in the Path structure and + * 3) record the mtime of the directory in the Dir structure and * verify the directory hasn't changed since the contents were * hashed. This will catch the creation or deletion of files, * but not the updating of files. However, since it is the @@ -173,6 +173,15 @@ __FBSDID("$FreeBSD$"); * in a cache for when Dir_MTime was actually called. */ +typedef struct Dir { + char *name; /* Name of directory */ + int refCount; /* Number of paths with this directory */ + int hits; /* Number of times a file in this dirextory has + * been found */ + Hash_Table files; /* Hash table of files in directory */ +} Dir; + + /* main search path */ Lst dirSearchPath = Lst_Initializer(dirSearchPath); @@ -188,7 +197,7 @@ static int misses; /* Sad, but not evil misses */ static int nearmisses; /* Found under search path */ static int bigmisses; /* Sought by itself */ -static Path *dot; /* contents of current directory */ +static Dir *dot; /* contents of current directory */ /* Results of doing a last-resort stat in Dir_FindFile -- * if we have to go to the system to find the file, we might as well @@ -296,7 +305,7 @@ Dir_HasWildcards(const char *name) /*- *----------------------------------------------------------------------- * DirMatchFiles -- - * Given a pattern and a Path structure, see if any files + * Given a pattern and a Dir structure, see if any files * match the pattern and add their names to the 'expansions' list if * any do. This is incomplete -- it doesn't take care of patterns like * src / *src / *.c properly (just *.c on any of the directories), but it @@ -311,7 +320,7 @@ Dir_HasWildcards(const char *name) *----------------------------------------------------------------------- */ static int -DirMatchFiles(const char *pattern, const Path *p, Lst *expansions) +DirMatchFiles(const char *pattern, const Dir *p, Lst *expansions) { Hash_Search search; /* Index into the directory's table */ Hash_Entry *entry; /* Current entry in the table */ @@ -468,7 +477,7 @@ DirExpandInt(const char *word, const Lst *path, Lst *expansions) LstNode *ln; /* Current node */ LST_FOREACH(ln, path) - DirMatchFiles(word, (Path *)Lst_Datum(ln), expansions); + DirMatchFiles(word, (Dir *)Lst_Datum(ln), expansions); } /*- @@ -615,7 +624,7 @@ Dir_FindFile(char *name, Lst *path) char *p2; /* pointer into name */ LstNode *ln; /* a list element */ char *file; /* the current filename to check */ - Path *p; /* current path member */ + Dir *p; /* current path member */ char *cp; /* final component of the name */ Boolean hasSlash; /* true if 'name' contains a / */ struct stat stb; /* Buffer for stat, if necessary */ @@ -932,13 +941,13 @@ Dir_MTime(GNode *gn) void Dir_AddDir(Lst *path, const char *name) { - LstNode *ln; /* node in case Path structure is found */ - Path *p; /* pointer to new Path structure */ + LstNode *ln; /* node in case Dir structure is found */ + Dir *p; /* pointer to new Path structure */ DIR *d; /* for reading directory */ struct dirent *dp; /* entry in directory */ LST_FOREACH(ln, &openDirectories) - if (strcmp(((const Path *)Lst_Datum(ln))->name, name) == 0) + if (strcmp(((const Dir *)Lst_Datum(ln))->name, name) == 0) break; if (ln != NULL) { p = Lst_Datum(ln); @@ -950,7 +959,7 @@ Dir_AddDir(Lst *path, const char *name) DEBUGF(DIR, ("Caching %s...", name)); if ((d = opendir(name)) != NULL) { - p = emalloc(sizeof(Path)); + p = emalloc(sizeof(Dir)); p->name = estrdup(name); p->hits = 0; p->refCount = 1; @@ -997,7 +1006,7 @@ Dir_AddDir(Lst *path, const char *name) * Ups the reference count for the directory. * * Results: - * Returns the Path it was given. + * Returns the Dir it was given. * * Side Effects: * The refCount of the path is incremented. @@ -1008,7 +1017,7 @@ void * Dir_CopyDir(void *p) { - ((Path *)p)->refCount += 1; + ((Dir *)p)->refCount += 1; return (p); } @@ -1037,7 +1046,7 @@ Dir_MakeFlags(const char *flag, const Lst *path) char *tstr; /* the current directory preceded by 'flag' */ char *nstr; LstNode *ln; /* the node of the current directory */ - Path *p; /* the structure describing the current directory */ + Dir *p; /* the structure describing the current directory */ str = estrdup(""); @@ -1064,14 +1073,14 @@ Dir_MakeFlags(const char *flag, const Lst *path) * * Side Effects: * If no other path references this directory (refCount == 0), - * the Path and all its data are freed. + * the Dir and all its data are freed. * *----------------------------------------------------------------------- */ void Dir_Destroy(void *pp) { - Path *p = pp; + Dir *p = pp; p->refCount -= 1; @@ -1104,7 +1113,7 @@ Dir_Destroy(void *pp) void Dir_ClearPath(Lst *path) { - Path *p; + Dir *p; while (!Lst_IsEmpty(path)) { p = Lst_DeQueue(path); @@ -1131,7 +1140,7 @@ void Dir_Concat(Lst *path1, Lst *path2) { LstNode *ln; - Path *p; + Dir *p; LST_FOREACH(ln, path2) { p = Lst_Datum(ln); @@ -1147,7 +1156,7 @@ void Dir_PrintDirectories(void) { const LstNode *ln; - const Path *p; + const Dir *p; printf("#*** Directory Cache:\n"); printf("# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n", @@ -1167,5 +1176,5 @@ Dir_PrintPath(const Lst *path) const LstNode *ln; LST_FOREACH(ln, path) - printf("%s ", ((const Path *)Lst_Datum(ln))->name); + printf("%s ", ((const Dir *)Lst_Datum(ln))->name); } |
