From 84f6d75d260ef7118287b2bdc16620ca4ca7a1d6 Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Sat, 21 Oct 2023 18:37:57 +0200 Subject: [PATCH] convert strcmp() to util::StrEq --- caps.cc | 2 +- contain.cc | 4 ++-- util.cc | 4 ++++ util.h | 1 + 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);