aboutsummaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-06-16 13:33:38 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-06-16 13:33:38 +0000
commit822794001cb4260b8c04a7bd2d50d890edae709a (patch)
treec4c3a86f638422c8d756752050ebcbb45eba2ee7 /src/util.cc
parentb9f09b3268bf0c3d9ecd512dd3a0aa1247550cc2 (diff)
* Started implementing the new evaluation model.
* Lots of refactorings. * Unit tests.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc52
1 files changed, 30 insertions, 22 deletions
diff --git a/src/util.cc b/src/util.cc
index 299fc942f..8c397aace 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1,47 +1,55 @@
+#include <iostream>
+
#include "util.hh"
string thisSystem = SYSTEM;
-string nixHomeDir = "/nix";
-string nixHomeDirEnvVar = "NIX";
+SysError::SysError(string msg)
+{
+ char * sysMsg = strerror(errno);
+ err = msg + ": " + sysMsg;
+}
+
-string absPath(string filename, string dir)
+string absPath(string path, string dir)
{
- if (filename[0] != '/') {
+ if (path[0] != '/') {
if (dir == "") {
char buf[PATH_MAX];
if (!getcwd(buf, sizeof(buf)))
- throw Error("cannot get cwd");
+ throw SysError("cannot get cwd");
dir = buf;
}
- filename = dir + "/" + filename;
+ path = dir + "/" + path;
/* !!! canonicalise */
char resolved[PATH_MAX];
- if (!realpath(filename.c_str(), resolved))
- throw Error("cannot canonicalise path " + filename);
- filename = resolved;
+ if (!realpath(path.c_str(), resolved))
+ throw SysError("cannot canonicalise path " + path);
+ path = resolved;
}
- return filename;
+ return path;
+}
+
+
+string dirOf(string path)
+{
+ unsigned int pos = path.rfind('/');
+ if (pos == string::npos) throw Error("invalid file name: " + path);
+ return string(path, 0, pos);
}
-/* Return the directory part of the given path, i.e., everything
- before the final `/'. */
-string dirOf(string s)
+string baseNameOf(string path)
{
- unsigned int pos = s.rfind('/');
- if (pos == string::npos) throw Error("invalid file name");
- return string(s, 0, pos);
+ unsigned int pos = path.rfind('/');
+ if (pos == string::npos) throw Error("invalid file name: " + path);
+ return string(path, pos + 1);
}
-/* Return the base name of the given path, i.e., everything following
- the final `/'. */
-string baseNameOf(string s)
+void debug(string s)
{
- unsigned int pos = s.rfind('/');
- if (pos == string::npos) throw Error("invalid file name");
- return string(s, pos + 1);
+ cerr << "debug: " << s << endl;
}