From f1c5641ed0824fdb31c0afd3e1e8aa314890bf3d Mon Sep 17 00:00:00 2001 From: mrbesen Date: Thu, 10 Dec 2020 21:09:20 +0100 Subject: [PATCH] realPath --- inc/files.h | 2 ++ src/files.cpp | 8 ++++++++ tests/utilstest.cpp | 3 +++ 3 files changed, 13 insertions(+) diff --git a/inc/files.h b/inc/files.h index 2431a6f..1e8396b 100644 --- a/inc/files.h +++ b/inc/files.h @@ -36,4 +36,6 @@ bool readFile(int fd, std::ostream& output, unsigned int maxsize = 0); bool copy(int fd_from, int fd_to); bool copy(const std::string& from, const std::string& to); +std::string realPath(const std::string& str); + } \ No newline at end of file diff --git a/src/files.cpp b/src/files.cpp index 7364e2f..61538c4 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -145,3 +145,11 @@ bool mrbesen::files::copy(const std::string& from, const std::string& to) { return r; } + +std::string mrbesen::files::realPath(const std::string& str) { + char buffer[PATH_MAX]; + char* ret = ::realpath(str.c_str(), buffer); + if(ret == nullptr) return ""; + + return std::string(buffer); +} \ No newline at end of file diff --git a/tests/utilstest.cpp b/tests/utilstest.cpp index 1b24713..00172e6 100644 --- a/tests/utilstest.cpp +++ b/tests/utilstest.cpp @@ -23,6 +23,7 @@ int testUtil_equalsIgnoreCase() { std::string a = "abcdefg"; std::string b = "AbCdEHI"; std::string c = "AbCdEHIJ"; + std::string d = "aBcDeFg"; ASSERT(!equalsIgnoreCase(a, b), ""); ASSERT(!equalsIgnoreCase(a, b, 10000), ""); @@ -36,6 +37,8 @@ int testUtil_equalsIgnoreCase() { ASSERT(!equalsIgnoreCase(a, c, 8), ""); ASSERT(equalsIgnoreCase(a, c, 5), ""); + ASSERT(equalsIgnoreCase(a, d), ""); + return TESTGOOD; }