about summary refs log tree commit diff
path: root/src/libutil/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil/util.cc')
-rw-r--r--src/libutil/util.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 60b86b162c9c..28e276a329b3 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -109,6 +109,20 @@ bool pathExists(const Path & path)
 }
 
 
+Path readLink(const Path & path)
+{
+    struct stat st;
+    if (lstat(path.c_str(), &st))
+        throw SysError(format("getting status of `%1%'") % path);
+    if (!S_ISLNK(st.st_mode))
+        throw Error(format("`%1%' is not a symlink") % path);
+    char buf[st.st_size];
+    if (readlink(path.c_str(), buf, st.st_size) != st.st_size)
+        throw SysError(format("reading symbolic link `%1%'") % path);
+    return string(buf, st.st_size);
+}
+
+
 Strings readDirectory(const Path & path)
 {
     Strings names;