Lines Matching defs:dir
1 /* $NetBSD: dir.c,v 1.295 2024/07/07 07:50:57 rillig Exp $ */
131 #include "dir.h"
134 /* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */
135 MAKE_RCSID("$NetBSD: dir.c,v 1.295 2024/07/07 07:50:57 rillig Exp $");
276 CachedDir *dir = bmake_malloc(sizeof *dir);
278 dir->name = bmake_strdup(name);
279 dir->refCount = 0;
280 dir->hits = 0;
281 HashSet_Init(&dir->files);
284 DEBUG2(DIR, "CachedDir %p new for \"%s\"\n", dir, dir->name);
287 return dir;
291 CachedDir_Ref(CachedDir *dir)
293 dir->refCount++;
297 dir, dir->refCount, dir->name);
300 return dir;
304 CachedDir_Unref(CachedDir *dir)
306 dir->refCount--;
310 dir, dir->refCount, dir->name);
313 if (dir->refCount > 0)
317 DEBUG2(DIR, "CachedDir %p free for \"%s\"\n", dir, dir->name);
320 OpenDirs_Remove(&openDirs, dir->name);
322 free(dir->name);
323 HashSet_Done(&dir->files);
324 free(dir);
329 CachedDir_Assign(CachedDir **var, CachedDir *dir)
334 *var = dir;
335 if (dir != NULL)
336 CachedDir_Ref(dir);
357 CachedDir *dir = ln->datum;
359 dir->refCount, dir->name);
360 CachedDir_Unref(dir); /* removes the dir from odirs->list */
468 CachedDir *dir;
477 dir = SearchPath_Add(NULL, newCurdir);
478 if (dir == NULL)
481 CachedDir_Assign(&cur, dir);
491 CachedDir *dir;
493 dir = SearchPath_Add(NULL, ".");
494 if (dir == NULL) {
499 CachedDir_Assign(&dot, dir);
543 CachedDir *dir = ln->datum;
544 if (dir == dotLast) {
558 CachedDir *dir = ln->datum;
559 if (dir == dotLast)
561 if (dir == dot && seenDotLast)
563 Global_Append(".PATH", dir->name);
585 CachedDir *dir = ln->datum;
586 Global_Append(".SYSPATH", dir->name);
634 * See if any files as seen from 'dir' match 'pattern', and add their names
644 DirMatchFiles(const char *pattern, CachedDir *dir, StringList *expansions)
646 const char *dirName = dir->name;
656 HashIter_InitSet(&hi, &dir->files);
818 CachedDir *dir = ln->datum;
819 DirMatchFiles(pattern, dir, expansions);
950 * Find if 'base' exists in 'dir'.
954 DirLookup(CachedDir *dir, const char *base)
958 DEBUG1(DIR, " %s ...\n", dir->name);
960 if (!HashSet_Contains(&dir->files, base))
963 file = str_concat3(dir->name, "/", base);
965 dir->hits++;
972 * Find if 'name' exists in 'dir'.
976 DirLookupSubdir(CachedDir *dir, const char *name)
979 char *file = dir == dot
981 : str_concat3(dir->name, "/", name);
994 * Find if 'name' (which has basename 'base') exists in 'dir'.
999 DirLookupAbs(CachedDir *dir, const char *name, const char *base)
1001 const char *dnp; /* pointer into dir->name */
1004 DEBUG1(DIR, " %s ...\n", dir->name);
1012 for (dnp = dir->name, np = name;
1018 if (!HashSet_Contains(&dir->files, base)) {
1023 dir->hits++;
1076 CachedDir *dir = ln->datum;
1077 if (dir == dotLast)
1079 if (dir == dot) {
1084 if ((file = DirLookupSubdir(dir, name)) != NULL)
1130 CachedDir *dir = ln->datum;
1131 if (dir == dotLast)
1133 if ((file = DirLookupAbs(dir, name, base)) != NULL)
1181 CachedDir *dir = path->dirs.first->datum;
1182 if (dir == dotLast) {
1213 CachedDir *dir = ln->datum;
1214 if (dir == dotLast)
1216 if ((file = DirLookup(dir, base)) != NULL)
1331 /* Truncate dirbase from the end to move up a dir. */
1450 CachedDir *dir = NULL;
1456 return dir;
1461 dir = CachedDir_New(name);
1475 (void)HashSet_Add(&dir->files, dp->d_name);
1479 OpenDirs_Add(&openDirs, dir);
1481 Lst_Append(&path->dirs, CachedDir_Ref(dir));
1484 return dir;
1524 CachedDir *dir = OpenDirs_Find(&openDirs, name);
1525 if (dir != NULL) {
1526 if (Lst_FindDatum(&path->dirs, dir) == NULL)
1527 Lst_Append(&path->dirs, CachedDir_Ref(dir));
1528 return dir;
1545 CachedDir *dir = ln->datum;
1546 Lst_Append(&path->dirs, CachedDir_Ref(dir));
1567 CachedDir *dir = ln->datum;
1570 Buf_AddStr(&buf, dir->name);
1584 CachedDir *dir = ln->datum;
1585 CachedDir_Unref(dir);
1599 CachedDir *dir = Lst_Dequeue(&path->dirs);
1600 CachedDir_Unref(dir);
1615 CachedDir *dir = ln->datum;
1616 if (Lst_FindDatum(&dst->dirs, dir) == NULL)
1617 Lst_Append(&dst->dirs, CachedDir_Ref(dir));
1640 CachedDir *dir = ln->datum;
1642 dir->refCount, dir->hits, dir->name);
1652 const CachedDir *dir = ln->datum;
1653 debug_printf("%s ", dir->name);