diff options
Diffstat (limited to 'dir.c')
| -rw-r--r-- | dir.c | 51 |
1 files changed, 43 insertions, 8 deletions
@@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.286 2023/12/29 18:53:24 rillig Exp $ */ +/* $NetBSD: dir.c,v 1.290 2024/05/20 19:14:12 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -132,7 +132,7 @@ #include "job.h" /* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: dir.c,v 1.286 2023/12/29 18:53:24 rillig Exp $"); +MAKE_RCSID("$NetBSD: dir.c,v 1.290 2024/05/20 19:14:12 sjg Exp $"); /* * A search path is a list of CachedDir structures. A CachedDir has in it the @@ -566,10 +566,12 @@ void Dir_SetSYSPATH(void) { CachedDirListNode *ln; - + SearchPath *path = Lst_IsEmpty(&sysIncPath->dirs) + ? defSysIncPath : sysIncPath; + Var_ReadOnly(".SYSPATH", false); Global_Delete(".SYSPATH"); - for (ln = sysIncPath->dirs.first; ln != NULL; ln = ln->next) { + for (ln = path->dirs.first; ln != NULL; ln = ln->next) { CachedDir *dir = ln->datum; Global_Append(".SYSPATH", dir->name); } @@ -1142,15 +1144,16 @@ found: * Input: * name the file to find * path the directories to search, or NULL + * isinclude if true, do not search .CURDIR at all * * Results: * The freshly allocated path to the file, or NULL. */ -char * -Dir_FindFile(const char *name, SearchPath *path) +static char * +FindFile(const char *name, SearchPath *path, bool isinclude) { char *file; /* the current filename to check */ - bool seenDotLast = false; /* true if we should search dot last */ + bool seenDotLast = isinclude; /* true if we should search dot last */ struct cached_stat cst; const char *trailing_dot = "."; const char *base = str_basename(name); @@ -1163,7 +1166,7 @@ Dir_FindFile(const char *name, SearchPath *path) return NULL; } - if (path->dirs.first != NULL) { + if (!seenDotLast && path->dirs.first != NULL) { CachedDir *dir = path->dirs.first->datum; if (dir == dotLast) { seenDotLast = true; @@ -1244,6 +1247,38 @@ Dir_FindFile(const char *name, SearchPath *path) return NULL; } +/* + * Find the file with the given name along the given search path. + * + * Input: + * name the file to find + * path the directories to search, or NULL + * + * Results: + * The freshly allocated path to the file, or NULL. + */ +char * +Dir_FindFile(const char *name, SearchPath *path) +{ + return FindFile(name, path, false); +} + +/* + * Find the include file with the given name along the given search path. + * + * Input: + * name the file to find + * path the directories to search, or NULL + * + * Results: + * The freshly allocated path to the file, or NULL. + */ +char * +Dir_FindInclude(const char *name, SearchPath *path) +{ + return FindFile(name, path, true); +} + /* * Search for 'needle' starting at the directory 'here' and then working our |
