Mon Nov 30 20:17:00 2020 UTC ()
make(1): document difference between 'cur' and 'dot'


(rillig)
diff -r1.243 -r1.244 src/usr.bin/make/dir.c

cvs diff -r1.243 -r1.244 src/usr.bin/make/dir.c (expand / switch to unified diff)

--- src/usr.bin/make/dir.c 2020/11/30 18:49:58 1.243
+++ src/usr.bin/make/dir.c 2020/11/30 20:17:00 1.244
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dir.c,v 1.243 2020/11/30 18:49:58 rillig Exp $ */ 1/* $NetBSD: dir.c,v 1.244 2020/11/30 20:17:00 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -126,27 +126,27 @@ @@ -126,27 +126,27 @@
126 */ 126 */
127 127
128#include <sys/types.h> 128#include <sys/types.h>
129#include <sys/stat.h> 129#include <sys/stat.h>
130 130
131#include <dirent.h> 131#include <dirent.h>
132#include <errno.h> 132#include <errno.h>
133 133
134#include "make.h" 134#include "make.h"
135#include "dir.h" 135#include "dir.h"
136#include "job.h" 136#include "job.h"
137 137
138/* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */ 138/* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */
139MAKE_RCSID("$NetBSD: dir.c,v 1.243 2020/11/30 18:49:58 rillig Exp $"); 139MAKE_RCSID("$NetBSD: dir.c,v 1.244 2020/11/30 20:17:00 rillig Exp $");
140 140
141#define DIR_DEBUG0(text) DEBUG0(DIR, text) 141#define DIR_DEBUG0(text) DEBUG0(DIR, text)
142#define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1) 142#define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
143#define DIR_DEBUG2(fmt, arg1, arg2) DEBUG2(DIR, fmt, arg1, arg2) 143#define DIR_DEBUG2(fmt, arg1, arg2) DEBUG2(DIR, fmt, arg1, arg2)
144 144
145/* A search path is a list of CachedDir structures. A CachedDir has in it the 145/* A search path is a list of CachedDir structures. A CachedDir has in it the
146 * name of the directory and the names of all the files in the directory. 146 * name of the directory and the names of all the files in the directory.
147 * This is used to cut down on the number of system calls necessary to find 147 * This is used to cut down on the number of system calls necessary to find
148 * implicit dependents and their like. Since these searches are made before 148 * implicit dependents and their like. Since these searches are made before
149 * any actions are taken, we need not worry about the directory changing due 149 * any actions are taken, we need not worry about the directory changing due
150 * to creation commands. If this hampers the style of some makefiles, they 150 * to creation commands. If this hampers the style of some makefiles, they
151 * must be changed. 151 * must be changed.
152 * 152 *
@@ -257,28 +257,30 @@ typedef enum CachedStatsFlags { @@ -257,28 +257,30 @@ typedef enum CachedStatsFlags {
257SearchPath dirSearchPath = LST_INIT; /* main search path */ 257SearchPath dirSearchPath = LST_INIT; /* main search path */
258 258
259static OpenDirs openDirs; /* all cached directories */ 259static OpenDirs openDirs; /* all cached directories */
260 260
261/* 261/*
262 * Variables for gathering statistics on the efficiency of the caching 262 * Variables for gathering statistics on the efficiency of the caching
263 * mechanism. 263 * mechanism.
264 */ 264 */
265static int hits; /* Found in directory cache */ 265static int hits; /* Found in directory cache */
266static int misses; /* Sad, but not evil misses */ 266static int misses; /* Sad, but not evil misses */
267static int nearmisses; /* Found under search path */ 267static int nearmisses; /* Found under search path */
268static int bigmisses; /* Sought by itself */ 268static int bigmisses; /* Sought by itself */
269 269
270static CachedDir *dot = NULL; /* contents of current directory */ 270/* The cached contents of ".", the relative current directory. */
271static CachedDir *cur = NULL; /* contents of current directory, if not dot */ 271static CachedDir *dot = NULL;
 272/* The cached contents of the absolute current directory. */
 273static CachedDir *cur = NULL;
272/* A fake path entry indicating we need to look for '.' last. */ 274/* A fake path entry indicating we need to look for '.' last. */
273static CachedDir *dotLast = NULL; 275static CachedDir *dotLast = NULL;
274 276
275/* Results of doing a last-resort stat in Dir_FindFile -- if we have to go to 277/* Results of doing a last-resort stat in Dir_FindFile -- if we have to go to
276 * the system to find the file, we might as well have its mtime on record. 278 * the system to find the file, we might as well have its mtime on record.
277 * 279 *
278 * XXX: If this is done way early, there's a chance other rules will have 280 * XXX: If this is done way early, there's a chance other rules will have
279 * already updated the file, in which case we'll update it again. Generally, 281 * already updated the file, in which case we'll update it again. Generally,
280 * there won't be two rules to update a single file, so this should be ok, 282 * there won't be two rules to update a single file, so this should be ok,
281 * but... */ 283 * but... */
282static HashTable mtimes; 284static HashTable mtimes;
283 285
284static HashTable lmtimes; /* same as mtimes but for lstat */ 286static HashTable lmtimes; /* same as mtimes but for lstat */
@@ -1057,27 +1059,27 @@ char * @@ -1057,27 +1059,27 @@ char *
1057Dir_FindFile(const char *name, SearchPath *path) 1059Dir_FindFile(const char *name, SearchPath *path)
1058{ 1060{
1059 char *file; /* the current filename to check */ 1061 char *file; /* the current filename to check */
1060 const char *base; /* Terminal name of file */ 1062 const char *base; /* Terminal name of file */
1061 Boolean hasLastDot = FALSE; /* true if we should search dot last */ 1063 Boolean hasLastDot = FALSE; /* true if we should search dot last */
1062 Boolean hasSlash; /* true if 'name' contains a / */ 1064 Boolean hasSlash; /* true if 'name' contains a / */
1063 struct cached_stat cst; /* Buffer for stat, if necessary */ 1065 struct cached_stat cst; /* Buffer for stat, if necessary */
1064 const char *trailing_dot = "."; 1066 const char *trailing_dot = ".";
1065 1067
1066 /* 1068 /*
1067 * Find the final component of the name and note whether it has a 1069 * Find the final component of the name and note whether it has a
1068 * slash in it (the name, I mean) 1070 * slash in it (the name, I mean)
1069 */ 1071 */
1070 base = strrchr(name, '/'); 1072 base = strrchr(name, '/'); /* XXX: confusing variable name */
1071 if (base != NULL) { 1073 if (base != NULL) {
1072 hasSlash = TRUE; 1074 hasSlash = TRUE;
1073 base++; 1075 base++;
1074 } else { 1076 } else {
1075 hasSlash = FALSE; 1077 hasSlash = FALSE;
1076 base = name; 1078 base = name;
1077 } 1079 }
1078 1080
1079 DIR_DEBUG1("Searching for %s ...", name); 1081 DIR_DEBUG1("Searching for %s ...", name);
1080 1082
1081 if (path == NULL) { 1083 if (path == NULL) {
1082 DIR_DEBUG0("couldn't open path, file not found\n"); 1084 DIR_DEBUG0("couldn't open path, file not found\n");
1083 misses++; 1085 misses++;