diff options
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r-- | base/file_util_posix.cc | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index f1caa29..56b1ce0 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -33,7 +33,6 @@ #include "base/basictypes.h" #include "base/eintr_wrapper.h" #include "base/file_path.h" -#include "base/lock.h" #include "base/logging.h" #include "base/scoped_ptr.h" #include "base/singleton.h" @@ -374,6 +373,29 @@ bool ReadFromFD(int fd, char* buffer, size_t bytes) { return total_read == bytes; } +bool CreateSymbolicLink(const FilePath& target_path, + const FilePath& symlink_path) { + DCHECK(!symlink_path.empty()); + DCHECK(!target_path.empty()); + return ::symlink(target_path.value().c_str(), + symlink_path.value().c_str()) != -1; +} + +bool ReadSymbolicLink(const FilePath& symlink_path, + FilePath* target_path) { + DCHECK(!symlink_path.empty()); + DCHECK(target_path); + char buf[PATH_MAX]; + ssize_t count = ::readlink(symlink_path.value().c_str(), buf, arraysize(buf)); + + if (count <= 0) + return false; + + *target_path = FilePath(FilePath::StringType(buf, count)); + + return true; +} + // Creates and opens a temporary file in |directory|, returning the // file descriptor. |path| is set to the temporary file path. // This function does NOT unlink() the file. @@ -865,4 +887,4 @@ bool CopyFile(const FilePath& from_path, const FilePath& to_path) { } #endif // defined(OS_MACOSX) -} // namespace file_util +} // namespace file_util |