Lines Matching full:dir

1 /*	$NetBSD: dir.c,v 1.297 2025/06/12 18:51:05 rillig Exp $	*/
131 #include "dir.h"
134 /* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */
135 MAKE_RCSID("$NetBSD: dir.c,v 1.297 2025/06/12 18:51:05 rillig Exp $");
276 CachedDir *dir = bmake_malloc(sizeof *dir); in CachedDir_New() local
278 dir->name = bmake_strdup(name); in CachedDir_New()
279 dir->refCount = 0; in CachedDir_New()
280 dir->hits = 0; in CachedDir_New()
281 HashSet_Init(&dir->files); in CachedDir_New()
284 DEBUG2(DIR, "CachedDir %p new for \"%s\"\n", dir, dir->name); in CachedDir_New()
287 return dir; in CachedDir_New()
291 CachedDir_Ref(CachedDir *dir) in CachedDir_Ref() argument
293 dir->refCount++; in CachedDir_Ref()
296 DEBUG3(DIR, "CachedDir %p ++ %d for \"%s\"\n", in CachedDir_Ref()
297 dir, dir->refCount, dir->name); in CachedDir_Ref()
300 return dir; in CachedDir_Ref()
304 CachedDir_Unref(CachedDir *dir) in CachedDir_Unref() argument
306 dir->refCount--; in CachedDir_Unref()
309 DEBUG3(DIR, "CachedDir %p -- %d for \"%s\"\n", in CachedDir_Unref()
310 dir, dir->refCount, dir->name); in CachedDir_Unref()
313 if (dir->refCount > 0) in CachedDir_Unref()
317 DEBUG2(DIR, "CachedDir %p free for \"%s\"\n", dir, dir->name); in CachedDir_Unref()
320 OpenDirs_Remove(&openDirs, dir->name); in CachedDir_Unref()
322 free(dir->name); in CachedDir_Unref()
323 HashSet_Done(&dir->files); in CachedDir_Unref()
324 free(dir); in CachedDir_Unref()
329 CachedDir_Assign(CachedDir **var, CachedDir *dir) in CachedDir_Assign() argument
334 *var = dir; in CachedDir_Assign()
335 if (dir != NULL) in CachedDir_Assign()
336 CachedDir_Ref(dir); in CachedDir_Assign()
353 DEBUG1(DIR, "OpenDirs_Done: %u entries to remove\n", in OpenDirs_Done()
357 CachedDir *dir = ln->datum; in OpenDirs_Done() local
358 DEBUG2(DIR, "OpenDirs_Done: refCount %d for \"%s\"\n", in OpenDirs_Done()
359 dir->refCount, dir->name); in OpenDirs_Done()
360 CachedDir_Unref(dir); /* removes the dir from odirs->list */ in OpenDirs_Done()
415 DEBUG2(DIR, "Using cached time %s for %s\n", in cached_stats()
436 DEBUG2(DIR, " Caching %s for %s\n", in cached_stats()
468 CachedDir *dir; in Dir_InitCur() local
477 dir = SearchPath_Add(NULL, newCurdir); in Dir_InitCur()
478 if (dir == NULL) in Dir_InitCur()
481 CachedDir_Assign(&cur, dir); in Dir_InitCur()
491 CachedDir *dir; in Dir_InitDot() local
493 dir = SearchPath_Add(NULL, "."); in Dir_InitDot()
494 if (dir == NULL) { in Dir_InitDot()
499 CachedDir_Assign(&dot, dir); in Dir_InitDot()
543 CachedDir *dir = ln->datum; in Dir_SetPATH() local
544 if (dir == dotLast) { in Dir_SetPATH()
558 CachedDir *dir = ln->datum; in Dir_SetPATH() local
559 if (dir == dotLast) in Dir_SetPATH()
561 if (dir == dot && seenDotLast) in Dir_SetPATH()
563 Global_Append(".PATH", dir->name); in Dir_SetPATH()
585 CachedDir *dir = ln->datum; in Dir_SetSYSPATH() local
586 Global_Append(".SYSPATH", dir->name); in Dir_SetSYSPATH()
634 * See if any files as seen from 'dir' match 'pattern', and add their names
644 DirMatchFiles(const char *pattern, CachedDir *dir, StringList *expansions) in DirMatchFiles() argument
646 const char *dirName = dir->name; in DirMatchFiles()
656 HashIter_InitSet(&hi, &dir->files); in DirMatchFiles()
818 CachedDir *dir = ln->datum; in DirExpandPath() local
819 DirMatchFiles(pattern, dir, expansions); in DirExpandPath()
897 DEBUG1(DIR, "Expanding \"%s\"... ", pattern); in SearchPath_Expand()
945 if (DEBUG(DIR)) in SearchPath_Expand()
950 * Find if 'base' exists in 'dir'.
954 DirLookup(CachedDir *dir, const char *base) in DirLookup() argument
958 DEBUG1(DIR, " %s ...\n", dir->name); in DirLookup()
960 if (!HashSet_Contains(&dir->files, base)) in DirLookup()
963 file = str_concat3(dir->name, "/", base); in DirLookup()
964 DEBUG1(DIR, " returning %s\n", file); in DirLookup()
965 dir->hits++; in DirLookup()
972 * Find if 'name' exists in 'dir'.
976 DirLookupSubdir(CachedDir *dir, const char *name) in DirLookupSubdir() argument
979 char *file = dir == dot in DirLookupSubdir()
981 : str_concat3(dir->name, "/", name); in DirLookupSubdir()
983 DEBUG1(DIR, "checking %s ...\n", file); in DirLookupSubdir()
994 * Find if 'name' (which has basename 'base') exists in 'dir'.
999 DirLookupAbs(CachedDir *dir, const char *name, const char *base) in DirLookupAbs() argument
1001 const char *dnp; /* pointer into dir->name */ in DirLookupAbs()
1004 DEBUG1(DIR, " %s ...\n", dir->name); in DirLookupAbs()
1012 for (dnp = dir->name, np = name; in DirLookupAbs()
1018 if (!HashSet_Contains(&dir->files, base)) { in DirLookupAbs()
1019 DEBUG0(DIR, " must be here but isn't -- returning\n"); in DirLookupAbs()
1023 dir->hits++; in DirLookupAbs()
1025 DEBUG1(DIR, " returning %s\n", name); in DirLookupAbs()
1038 DEBUG0(DIR, " in '.'\n"); in DirFindDot()
1045 DEBUG1(DIR, " in ${.CURDIR} = %s\n", cur->name); in DirFindDot()
1062 DEBUG0(DIR, " Trying subdirectories...\n"); in FindFileRelative()
1076 CachedDir *dir = ln->datum; in FindFileRelative() local
1077 if (dir == dotLast) in FindFileRelative()
1079 if (dir == dot) { in FindFileRelative()
1084 if ((file = DirLookupSubdir(dir, name)) != NULL) in FindFileRelative()
1104 DEBUG0(DIR, " Checked . already, returning NULL\n"); in FindFileRelative()
1123 DEBUG0(DIR, " Trying exact path matches...\n"); in FindFileAbsolute()
1130 CachedDir *dir = ln->datum; in FindFileAbsolute() local
1131 if (dir == dotLast) in FindFileAbsolute()
1133 if ((file = DirLookupAbs(dir, name, base)) != NULL) in FindFileAbsolute()
1172 DEBUG1(DIR, "Searching for %s ...", name); in FindFile()
1175 DEBUG0(DIR, "couldn't open path, file not found\n"); in FindFile()
1181 CachedDir *dir = path->dirs.first->datum; in FindFile() local
1182 if (dir == dotLast) { in FindFile()
1184 DEBUG0(DIR, "[dot last]..."); in FindFile()
1187 DEBUG0(DIR, "\n"); in FindFile()
1213 CachedDir *dir = ln->datum; in FindFile() local
1214 if (dir == dotLast) in FindFile()
1216 if ((file = DirLookup(dir, base)) != NULL) in FindFile()
1225 DEBUG0(DIR, " failed.\n"); in FindFile()
1251 DEBUG1(DIR, " Looking for \"%s\" ...\n", name); in FindFile()
1257 DEBUG0(DIR, " failed. Returning NULL\n"); in FindFile()
1331 /* Truncate dirbase from the end to move up a dir. */ in Dir_FindHereOrAbove()
1389 DEBUG2(DIR, "Found '%s' as '%s'\n", in ResolveFullName()
1450 CachedDir *dir = NULL; in CacheNewDir() local
1451 DIR *d; in CacheNewDir()
1455 DEBUG1(DIR, "Caching %s ... not found\n", name); in CacheNewDir()
1456 return dir; in CacheNewDir()
1459 DEBUG1(DIR, "Caching %s ...\n", name); in CacheNewDir()
1461 dir = CachedDir_New(name); in CacheNewDir()
1475 (void)HashSet_Add(&dir->files, dp->d_name); in CacheNewDir()
1479 OpenDirs_Add(&openDirs, dir); in CacheNewDir()
1481 Lst_Append(&path->dirs, CachedDir_Ref(dir)); in CacheNewDir()
1483 DEBUG1(DIR, "Caching %s done\n", name); in CacheNewDir()
1484 return dir; in CacheNewDir()
1524 CachedDir *dir = OpenDirs_Find(&openDirs, name); in SearchPath_Add() local
1525 if (dir != NULL) { in SearchPath_Add()
1526 if (Lst_FindDatum(&path->dirs, dir) == NULL) in SearchPath_Add()
1527 Lst_Append(&path->dirs, CachedDir_Ref(dir)); in SearchPath_Add()
1528 return dir; in SearchPath_Add()
1545 CachedDir *dir = ln->datum; in Dir_CopyDirSearchPath() local
1546 Lst_Append(&path->dirs, CachedDir_Ref(dir)); in Dir_CopyDirSearchPath()
1567 CachedDir *dir = ln->datum; in SearchPath_ToFlags() local
1570 Buf_AddStr(&buf, dir->name); in SearchPath_ToFlags()
1584 CachedDir *dir = ln->datum; in SearchPath_Free() local
1585 CachedDir_Unref(dir); in SearchPath_Free()
1599 CachedDir *dir = Lst_Dequeue(&path->dirs); in SearchPath_Clear() local
1600 CachedDir_Unref(dir); in SearchPath_Clear()
1615 CachedDir *dir = ln->datum; in SearchPath_AddAll() local
1616 if (Lst_FindDatum(&dst->dirs, dir) == NULL) in SearchPath_AddAll()
1617 Lst_Append(&dst->dirs, CachedDir_Ref(dir)); in SearchPath_AddAll()
1640 CachedDir *dir = ln->datum; in Dir_PrintDirectories() local
1642 dir->refCount, dir->hits, dir->name); in Dir_PrintDirectories()
1652 const CachedDir *dir = ln->datum; in SearchPath_Print() local
1653 debug_printf("%s ", dir->name); in SearchPath_Print()