aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2016-06-05 15:57:18 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2016-06-05 15:57:18 +0000
commite944e081cfc62fe8f19f5ba9c0d964daee437925 (patch)
treeb3a79b3f77f2eadb163e5ec2c5c1f137d28ca2c5 /main.c
parente917534a842fe9ce606f648cd65fd6ea433c7013 (diff)
downloadsrc-e944e081cfc62fe8f19f5ba9c0d964daee437925.tar.gz
src-e944e081cfc62fe8f19f5ba9c0d964daee437925.zip
Notes
Diffstat (limited to 'main.c')
-rw-r--r--main.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/main.c b/main.c
index 0a89d94af0fd..57a59cbfa77e 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.244 2016/04/05 04:25:43 sjg Exp $ */
+/* $NetBSD: main.c,v 1.245 2016/06/03 01:21:59 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.244 2016/04/05 04:25:43 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.245 2016/06/03 01:21:59 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: main.c,v 1.244 2016/04/05 04:25:43 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.245 2016/06/03 01:21:59 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -1014,7 +1014,7 @@ main(int argc, char **argv)
/*
* A relative path, canonicalize it.
*/
- p1 = realpath(argv[0], mdpath);
+ p1 = cached_realpath(argv[0], mdpath);
if (!p1 || *p1 != '/' || stat(p1, &sb) < 0) {
p1 = argv[0]; /* realpath failed */
}
@@ -1884,6 +1884,40 @@ usage(void)
}
+/*
+ * realpath(3) can get expensive, cache results...
+ */
+char *
+cached_realpath(const char *pathname, char *resolved)
+{
+ static GNode *cache;
+ char *rp, *cp;
+
+ if (!pathname || !pathname[0])
+ return NULL;
+
+ if (!cache) {
+ cache = Targ_NewGN("Realpath");
+#ifndef DEBUG_REALPATH_CACHE
+ cache->flags = INTERNAL;
+#endif
+ }
+
+ rp = Var_Value(pathname, cache, &cp);
+ if (rp) {
+ /* a hit */
+ if (resolved)
+ strlcpy(resolved, rp, MAXPATHLEN);
+ else
+ resolved = bmake_strdup(rp);
+ } else {
+ if ((rp = realpath(pathname, resolved))) {
+ Var_Set(pathname, rp, cache, 0);
+ }
+ }
+ return rp ? resolved : NULL;
+}
+
int
PrintAddr(void *a, void *b)
{