From: Sungbae Yoo Date: Thu, 27 Jul 2017 05:15:21 +0000 (+0900) Subject: Add readlink method in filesystem API X-Git-Tag: submit/tizen/20170727.084517~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e7cbed1000c38adf83d81fe45cf8d8320e7c8374;p=platform%2Fcore%2Fsecurity%2Fklay.git Add readlink method in filesystem API Signed-off-by: Sungbae Yoo Change-Id: I86dda70ea0201a0a2f4ec4b0bfd58a5af86e9ae0 --- diff --git a/include/klay/filesystem.h b/include/klay/filesystem.h index 5b5282a..3c62f04 100644 --- a/include/klay/filesystem.h +++ b/include/klay/filesystem.h @@ -112,6 +112,8 @@ public: void chown(uid_t uid, gid_t gid, bool recursive = false); void chmod(mode_t mode, bool recursive = false); + const std::string readlink() const; + const std::string& getPath() const { return path; diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 7becd1d..5fb0f19 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -381,6 +381,15 @@ void File::chmod(mode_t mode, bool recursive) } } +const std::string File::readlink() const +{ + char buf[PATH_MAX]; + if (::readlink(path.c_str(), buf, PATH_MAX) == -1) { + throw runtime::Exception(runtime::GetSystemErrorMessage()); + } + return buf; +} + void File::lock() const { if (::flock(descriptor, LOCK_EX) == -1) {