From 91e946bc05b716a931530aea4f5d976c920a069b Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 7 Nov 2012 19:44:27 -0700 Subject: [PATCH] Possibly working directory auto-detection --- packages/00common/src/common.c | 26 +++++++++++++++----------- packages/tanks/tanks.mk | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/00common/src/common.c b/packages/00common/src/common.c index a84899f..67e0703 100644 --- a/packages/00common/src/common.c +++ b/packages/00common/src/common.c @@ -363,16 +363,24 @@ my_snprintf(char *buf, size_t buflen, char *fmt, ...) } } - void ctf_chdir() { - char const *ctf_base = getenv("CTF_BASE"); + static int initialized = 0; int i; - if (ctf_base) { - /* chdir to CTF_BASE */ - chdir(ctf_base); + if (initialized) { + return; + } + initialized = 1; + + /* chdir to $CTF_BASE */ + { + char const *ctf_base = getenv("CTF_BASE"); + + if (ctf_base) { + chdir(ctf_base); + } } /* Keep going up one directory until there's a packages directory */ @@ -395,17 +403,13 @@ mkpath(char const *type, char const *fmt, va_list ap) { char relpath[PATH_MAX]; static char path[PATH_MAX]; - char const *var = getenv("CTF_BASE"); + ctf_chdir(); vsnprintf(relpath, sizeof(relpath) - 1, fmt, ap); relpath[sizeof(relpath) - 1] = '\0'; - if (! var) { - var = ""; - } - /* $CTF_BASE/type/relpath */ - my_snprintf(path, sizeof(path), "%s/%s/%s", var, type, relpath); + my_snprintf(path, sizeof(path), "%s/%s", type, relpath); return path; } diff --git a/packages/tanks/tanks.mk b/packages/tanks/tanks.mk index b530520..f31ec36 100644 --- a/packages/tanks/tanks.mk +++ b/packages/tanks/tanks.mk @@ -1,7 +1,7 @@ TANKS_PKGDIR = $(TARGET)/tanks TANKS_CACHE = $(CACHE)/tanks.git TANKS_BUILDDIR = $(BUILD)/tanks -TANKS_URL = "http://dirtbags.net/projects/tanks" +TANKS_URL = "http://woozle.org/~neale/g.cgi/tanks" $(TANKS_CACHE): git clone --bare $(TANKS_URL) $@