aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-27 20:16:20 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-27 20:16:20 +0000
commit30cf2d013179e7e5e9129cf2a669f99774dc2be9 (patch)
tree8c65f2cffa53fd325a2345ddc914713e56228b76
parentf35292f38aec12b8f1c6a022ccb89fe15dfb5e4a (diff)
downloadpaludis-30cf2d013179e7e5e9129cf2a669f99774dc2be9.tar.gz
paludis-30cf2d013179e7e5e9129cf2a669f99774dc2be9.tar.xz
Add readlink member function to FSEntry
-rw-r--r--paludis/util/fs_entry.cc9
-rw-r--r--paludis/util/fs_entry.hh8
2 files changed, 17 insertions, 0 deletions
diff --git a/paludis/util/fs_entry.cc b/paludis/util/fs_entry.cc
index 362befb..134e918 100644
--- a/paludis/util/fs_entry.cc
+++ b/paludis/util/fs_entry.cc
@@ -378,3 +378,12 @@ FSEntry::unlink()
throw FSError("unlink '" + _path + "' failed: " + ::strerror(e));
}
+std::string
+FSEntry::readlink() const
+{
+ char buf[PATH_MAX + 1];
+ std::memset(buf, 0, PATH_MAX + 1);
+ if (-1 == ::readlink(_path.c_str(), buf, PATH_MAX))
+ throw FSError("readlink '" + _path + "' failed: " + ::strerror(errno));
+ return buf;
+}
diff --git a/paludis/util/fs_entry.hh b/paludis/util/fs_entry.hh
index 6e722c0..a2882b8 100644
--- a/paludis/util/fs_entry.hh
+++ b/paludis/util/fs_entry.hh
@@ -206,6 +206,14 @@ namespace paludis
FSEntry realpath() const;
/**
+ * Return our destination, if we are a symlink.
+ *
+ * \exception FSError if we are not a symlink, or if the system call
+ * fails.
+ */
+ std::string readlink() const;
+
+ /**
* Return the time the filesystem entry was created
* \exception FSError if there was a problem accessing the filesystem entry
*/