diff options
author | Daniel Wilhelm <shieldwed@outlook.com> | 2017-04-20 16:55:28 -0600 |
---|---|---|
committer | Daniel Wilhelm <shieldwed@outlook.com> | 2017-04-20 16:59:56 -0600 |
commit | 823740e1ffa2b3bd39f8dea8062f5c5a0d9c741b (patch) | |
tree | 63222010af3b90a36f29c1c9c360116973cdff38 /zen/symlink_target.h | |
parent | add .gitattributes for less line ending hassles (diff) | |
download | FreeFileSync-823740e1ffa2b3bd39f8dea8062f5c5a0d9c741b.tar.gz FreeFileSync-823740e1ffa2b3bd39f8dea8062f5c5a0d9c741b.tar.bz2 FreeFileSync-823740e1ffa2b3bd39f8dea8062f5c5a0d9c741b.zip |
normalize most lineendings
Diffstat (limited to 'zen/symlink_target.h')
-rwxr-xr-x | zen/symlink_target.h | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/zen/symlink_target.h b/zen/symlink_target.h index 4620e7cc..84b8452a 100755 --- a/zen/symlink_target.h +++ b/zen/symlink_target.h @@ -1,75 +1,75 @@ -// *****************************************************************************
-// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
-// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
-// *****************************************************************************
-
-#ifndef SYMLINK_TARGET_H_801783470198357483
-#define SYMLINK_TARGET_H_801783470198357483
-
-#include "scope_guard.h"
-#include "file_error.h"
-
- #include <unistd.h>
- #include <stdlib.h> //realpath
-
-
-namespace zen
-{
-
-Zstring getResolvedSymlinkPath(const Zstring& linkPath); //throw FileError; Win: requires Vista or later!
-Zstring getSymlinkTargetRaw (const Zstring& linkPath); //throw FileError
-}
-
-
-
-
-
-
-
-
-
-//################################ implementation ################################
-
-namespace
-{
-//retrieve raw target data of symlink or junction
-Zstring getSymlinkRawTargetString_impl(const Zstring& linkPath) //throw FileError
-{
- using namespace zen;
- const size_t BUFFER_SIZE = 10000;
- std::vector<char> buffer(BUFFER_SIZE);
-
- const ssize_t bytesWritten = ::readlink(linkPath.c_str(), &buffer[0], BUFFER_SIZE);
- if (bytesWritten < 0)
- THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot resolve symbolic link %x."), L"%x", fmtPath(linkPath)), L"readlink");
- if (bytesWritten >= static_cast<ssize_t>(BUFFER_SIZE)) //detect truncation, not an error for readlink!
- throw FileError(replaceCpy(_("Cannot resolve symbolic link %x."), L"%x", fmtPath(linkPath)), L"readlink: buffer truncated.");
-
- return Zstring(&buffer[0], bytesWritten); //readlink does not append 0-termination!
-}
-
-
-Zstring getResolvedSymlinkPath_impl(const Zstring& linkPath) //throw FileError
-{
- using namespace zen;
- char* targetPath = ::realpath(linkPath.c_str(), nullptr);
- if (!targetPath)
- THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot determine final path for %x."), L"%x", fmtPath(linkPath)), L"realpath");
- ZEN_ON_SCOPE_EXIT(::free(targetPath));
- return targetPath;
-}
-}
-
-
-namespace zen
-{
-inline
-Zstring getSymlinkTargetRaw(const Zstring& linkPath) { return getSymlinkRawTargetString_impl(linkPath); }
-
-inline
-Zstring getResolvedSymlinkPath(const Zstring& linkPath) { return getResolvedSymlinkPath_impl(linkPath); }
-
-}
-
-#endif //SYMLINK_TARGET_H_801783470198357483
+// ***************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * +// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * +// ***************************************************************************** + +#ifndef SYMLINK_TARGET_H_801783470198357483 +#define SYMLINK_TARGET_H_801783470198357483 + +#include "scope_guard.h" +#include "file_error.h" + + #include <unistd.h> + #include <stdlib.h> //realpath + + +namespace zen +{ + +Zstring getResolvedSymlinkPath(const Zstring& linkPath); //throw FileError; Win: requires Vista or later! +Zstring getSymlinkTargetRaw (const Zstring& linkPath); //throw FileError +} + + + + + + + + + +//################################ implementation ################################ + +namespace +{ +//retrieve raw target data of symlink or junction +Zstring getSymlinkRawTargetString_impl(const Zstring& linkPath) //throw FileError +{ + using namespace zen; + const size_t BUFFER_SIZE = 10000; + std::vector<char> buffer(BUFFER_SIZE); + + const ssize_t bytesWritten = ::readlink(linkPath.c_str(), &buffer[0], BUFFER_SIZE); + if (bytesWritten < 0) + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot resolve symbolic link %x."), L"%x", fmtPath(linkPath)), L"readlink"); + if (bytesWritten >= static_cast<ssize_t>(BUFFER_SIZE)) //detect truncation, not an error for readlink! + throw FileError(replaceCpy(_("Cannot resolve symbolic link %x."), L"%x", fmtPath(linkPath)), L"readlink: buffer truncated."); + + return Zstring(&buffer[0], bytesWritten); //readlink does not append 0-termination! +} + + +Zstring getResolvedSymlinkPath_impl(const Zstring& linkPath) //throw FileError +{ + using namespace zen; + char* targetPath = ::realpath(linkPath.c_str(), nullptr); + if (!targetPath) + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot determine final path for %x."), L"%x", fmtPath(linkPath)), L"realpath"); + ZEN_ON_SCOPE_EXIT(::free(targetPath)); + return targetPath; +} +} + + +namespace zen +{ +inline +Zstring getSymlinkTargetRaw(const Zstring& linkPath) { return getSymlinkRawTargetString_impl(linkPath); } + +inline +Zstring getResolvedSymlinkPath(const Zstring& linkPath) { return getResolvedSymlinkPath_impl(linkPath); } + +} + +#endif //SYMLINK_TARGET_H_801783470198357483 |