aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Swiecki <robert@swiecki.net>2023-10-21 18:37:57 +0200
committerRobert Swiecki <robert@swiecki.net>2023-10-21 18:37:57 +0200
commit84f6d75d260ef7118287b2bdc16620ca4ca7a1d6 (patch)
tree43a90759a52968d3af0f8ca6e61963672471692e
parent98ec95ca85b18bdae6238019b52ed06ca9bb2542 (diff)
downloadnsjail-84f6d75d260ef7118287b2bdc16620ca4ca7a1d6.tar.gz
convert strcmp() to util::StrEq
-rw-r--r--caps.cc2
-rw-r--r--contain.cc4
-rw-r--r--util.cc4
-rw-r--r--util.h1
4 files changed, 8 insertions, 3 deletions
diff --git a/caps.cc b/caps.cc
index ee9c98a..d3ec85f 100644
--- a/caps.cc
+++ b/caps.cc
@@ -99,7 +99,7 @@ struct {
int nameToVal(const char* name) {
for (const auto& cap : capNames) {
- if (strcmp(name, cap.name) == 0) {
+ if (util::StrEq(name, cap.name)) {
return cap.val;
}
}
diff --git a/contain.cc b/contain.cc
index 6ac5c4a..8f55d52 100644
--- a/contain.cc
+++ b/contain.cc
@@ -253,10 +253,10 @@ static bool containMakeFdsCOEProc(nsjconf_t* nsjconf) {
if (entry == nullptr) {
break;
}
- if (strcmp(".", entry->d_name) == 0) {
+ if (util::StrEq(".", entry->d_name)) {
continue;
}
- if (strcmp("..", entry->d_name) == 0) {
+ if (util::StrEq("..", entry->d_name)) {
continue;
}
errno = 0;
diff --git a/util.cc b/util.cc
index 1e86d9c..25d5e5b 100644
--- a/util.cc
+++ b/util.cc
@@ -215,6 +215,10 @@ bool isANumber(const char* s) {
return true;
}
+bool StrEq(const std::string_view& s1, const std::string_view& s2) {
+ return (s1 == s2);
+}
+
static __thread pthread_once_t rndThreadOnce = PTHREAD_ONCE_INIT;
static __thread uint64_t rndX;
diff --git a/util.h b/util.h
index b1de1d7..7b17758 100644
--- a/util.h
+++ b/util.h
@@ -62,6 +62,7 @@ std::string* StrAppend(std::string* str, const char* format, ...)
__attribute__((format(printf, 2, 3)));
std::string StrPrintf(const char* format, ...) __attribute__((format(printf, 1, 2)));
const std::string StrQuote(const std::string& str);
+bool StrEq(const std::string_view& s1, const std::string_view& s2);
bool isANumber(const char* s);
uint64_t rnd64(void);
const std::string sigName(int signo);