diff options
author | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-30 00:43:37 +0000 |
---|---|---|
committer | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-30 00:43:37 +0000 |
commit | 2e733d10715fe3fd5bffd60e345f5999ae225000 (patch) | |
tree | 9839ff0aaf6f481d530c91df41f6358333ad0db9 /base/file_util_posix.cc | |
parent | efe3ddc3dde5349e50a96bd445a0d6569215a139 (diff) | |
download | chromium_src-2e733d10715fe3fd5bffd60e345f5999ae225000.zip chromium_src-2e733d10715fe3fd5bffd60e345f5999ae225000.tar.gz chromium_src-2e733d10715fe3fd5bffd60e345f5999ae225000.tar.bz2 |
Some additions to support symlinks better on platforms that support them.
BUG=none
TEST=Ran new unit test, passed trybots.
Review URL: http://codereview.chromium.org/5349007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r-- | base/file_util_posix.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index e0a1a55..e71051e 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -373,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. |