summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-05-12 09:35:51 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-05-12 09:35:51 +0000
commit8c0b42f857b53993d95c5bc077e8f8a71028c5ac (patch)
tree8911f759371585a66cfd6b5ad604fff0a97779ba /src/libutil
parentc8d3882cdc8f9e22c58af285c1996265c1af75d5 (diff)
downloadguix-8c0b42f857b53993d95c5bc077e8f8a71028c5ac.tar.gz
* An quick and dirty hack to support distributed builds.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc10
-rw-r--r--src/libutil/util.hh3
2 files changed, 11 insertions, 2 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index bf2954f534..399233983d 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -29,6 +29,13 @@ SysError::SysError(const format & f)
 }
 
 
+string getEnv(const string & key, const string & def)
+{
+    char * value = getenv(key.c_str());
+    return value ? string(value) : def;
+}
+
+
 Path absPath(Path path, Path dir)
 {
     if (path[0] != '/') {
@@ -206,8 +213,7 @@ void makePathReadOnly(const Path & path)
 static Path tempName()
 {
     static int counter = 0;
-    char * s = getenv("TMPDIR");
-    Path tmpRoot = s ? canonPath(Path(s)) : "/tmp";
+    Path tmpRoot = canonPath(getEnv("TMPDIR", "/tmp"));
     return (format("%1%/nix-%2%-%3%") % tmpRoot % getpid() % counter++).str();
 }
 
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 1b0600006a..d9ca1dac22 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -55,6 +55,9 @@ typedef set<Path> PathSet;
 extern string thisSystem;
 
 
+/* Return an environment variable. */
+string getEnv(const string & key, const string & def = "");
+
 /* Return an absolutized path, resolving paths relative to the
    specified directory, or the current directory otherwise.  The path
    is also canonicalised. */