diff options
author | Matt Spinler <spinler@us.ibm.com> | 2019-04-16 09:13:14 -0500 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2019-04-16 12:05:49 -0500 |
commit | 5c014d2bb76f6f6d51aecf31bea95cb9ed9b1953 (patch) | |
tree | e75292f02218abf709795205bee59954d7c3a674 | |
parent | 1f30ab2c476a473f3a78030c5dc1110c287e0789 (diff) | |
download | phosphor-hwmon-5c014d2bb76f6f6d51aecf31bea95cb9ed9b1953.tar.gz phosphor-hwmon-5c014d2bb76f6f6d51aecf31bea95cb9ed9b1953.zip |
Use std::filesystem::path::relative_path()
Use that function instead of making a relative path manually.
Change-Id: I64908353295a10af09baa91bab5d1c3a0152e994
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
-rw-r--r-- | sysfs.cpp | 21 | ||||
-rw-r--r-- | sysfs.hpp | 4 |
2 files changed, 6 insertions, 19 deletions
@@ -162,18 +162,11 @@ std::string findCalloutPath(const std::string& instancePath) return emptyString; } -std::string findHwmonFromOFPath(std::string ofNode) +std::string findHwmonFromOFPath(const std::string& ofNode) { static constexpr auto hwmonRoot = "/sys/class/hwmon"; - // Can't append an absolute path - if (!ofNode.empty() && (ofNode.front() == '/')) - { - ofNode = ofNode.substr(1); - } - - fs::path fullOfPath{ofRoot}; - fullOfPath /= ofNode; + auto fullOfPath = fs::path(ofRoot) / fs::path(ofNode).relative_path(); for (const auto& hwmonInst : fs::directory_iterator(hwmonRoot)) { @@ -209,16 +202,10 @@ std::string findHwmonFromOFPath(std::string ofNode) return emptyString; } -std::string findHwmonFromDevPath(std::string devPath) +std::string findHwmonFromDevPath(const std::string& devPath) { - // Can't append an absolute path - if (!devPath.empty() && devPath.front() == '/') - { - devPath = devPath.substr(1); - } - fs::path p{"/sys"}; - p /= devPath; + p /= fs::path(devPath).relative_path(); p /= "hwmon"; try @@ -50,7 +50,7 @@ std::string findPhandleMatch(const std::string& iochanneldir, * @returns[in] - The hwmon instance path or an empty * string if no match is found. */ -std::string findHwmonFromOFPath(std::string ofNode); +std::string findHwmonFromOFPath(const std::string& ofNode); /** @brief Find hwmon instances from a device path * @@ -63,7 +63,7 @@ std::string findHwmonFromOFPath(std::string ofNode); * @return - The hwmon instance path or an empty * string if no match is found. */ -std::string findHwmonFromDevPath(std::string devPath); +std::string findHwmonFromDevPath(const std::string& devPath); /** @brief Return the path to use for a call out. * |