From a24d3e67bcb4427c8eb171c4ca90b66eff0ef2a3 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sun, 3 Apr 2022 20:36:39 -0230 Subject: [PATCH] Minor 'const' updates to POSIX classes. --- src/unix/FSNodePOSIX.cxx | 6 +++--- src/unix/SerialPortUNIX.cxx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/unix/FSNodePOSIX.cxx b/src/unix/FSNodePOSIX.cxx index 57af6051b..3ce8aa44b 100644 --- a/src/unix/FSNodePOSIX.cxx +++ b/src/unix/FSNodePOSIX.cxx @@ -37,7 +37,7 @@ FilesystemNodePOSIX::FilesystemNodePOSIX(const string& path, bool verify) // Expand '~' to the HOME environment variable if(_path[0] == '~') { - string home = BSPF::getenv("HOME"); + const string& home = BSPF::getenv("HOME"); if(home != EmptyString) _path.replace(0, 1, home); } @@ -78,7 +78,7 @@ void FilesystemNodePOSIX::setFlags() string FilesystemNodePOSIX::getShortPath() const { // If the path starts with the home directory, replace it with '~' - string home = BSPF::getenv("HOME"); + const string& home = BSPF::getenv("HOME"); if(home != EmptyString && BSPF::startsWithIgnoreCase(_path, home)) { string path = "~"; @@ -106,7 +106,7 @@ bool FilesystemNodePOSIX::getChildren(AbstractFSList& myList, ListMode mode) con return false; // Loop over dir entries using readdir - struct dirent* dp; + struct dirent* dp = nullptr; while ((dp = readdir(dirp)) != nullptr) { // Ignore all hidden files diff --git a/src/unix/SerialPortUNIX.cxx b/src/unix/SerialPortUNIX.cxx index 30ec04cda..c598e69e3 100644 --- a/src/unix/SerialPortUNIX.cxx +++ b/src/unix/SerialPortUNIX.cxx @@ -104,14 +104,14 @@ StringList SerialPortUNIX::portNames() // Check if port is valid; for now that means if it can be opened // Eventually we may extend this to do more intensive checks - auto isPortValid = [](const string& port) { + const auto isPortValid = [](const string& port) { int handle = open(port.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); if(handle > 0) close(handle); return handle > 0; }; // Get all possible devices in the '/dev' directory - FilesystemNode::NameFilter filter = [](const FilesystemNode& node) { + const FilesystemNode::NameFilter filter = [](const FilesystemNode& node) { return BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyACM") || BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyUSB"); };