summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2023-10-09 10:48:38 +1100
committerNathan Scott <nathans@redhat.com>2023-10-10 09:18:47 +1100
commit4103c23327359a0bd6385c2f891554f206fec397 (patch)
tree30eec810c157643b63713af1776d9bfb1de141c6
parent2978af01a79d1627d7fa90fda0efec9cf774d901 (diff)
strchrnul is a GNU libc extension, add a wrapper for other platforms
-rw-r--r--XUtils.h11
-rw-r--r--configure.ac1
-rw-r--r--linux/CGroupUtils.c10
-rw-r--r--linux/LinuxProcessTable.c4
4 files changed, 19 insertions, 7 deletions
diff --git a/XUtils.h b/XUtils.h
index fd1087d5..7526df3e 100644
--- a/XUtils.h
+++ b/XUtils.h
@@ -56,6 +56,17 @@ void String_freeArray(char** s);
char* String_readLine(FILE* fd) ATTR_MALLOC;
+static inline char* String_strchrnul(const char* s, int c) {
+#ifdef HAVE_STRCHRNUL
+ return strchrnul(s, c);
+#else
+ char* result = strchr(s, c);
+ if (result)
+ return result;
+ return strchr(s, '\0');
+#endif
+}
+
/* Always null-terminates dest. Caller must pass a strictly positive size. */
ATTR_ACCESS3_W(1, 3)
ATTR_ACCESS3_R(2, 3)
diff --git a/configure.ac b/configure.ac
index c05f4d62..16d1fb9a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -297,6 +297,7 @@ AC_CHECK_FUNCS([ \
readlinkat \
sched_getscheduler \
sched_setscheduler \
+ strchrnul \
])
if test "$my_htop_platform" = darwin; then
diff --git a/linux/CGroupUtils.c b/linux/CGroupUtils.c
index c11c4608..e8d5f1de 100644
--- a/linux/CGroupUtils.c
+++ b/linux/CGroupUtils.c
@@ -94,7 +94,7 @@ static bool CGroup_filterName_internal(const char* cgroup, StrBuf_state* s, StrB
}
const char* labelStart = cgroup;
- const char* nextSlash = strchrnul(labelStart, '/');
+ const char* nextSlash = String_strchrnul(labelStart, '/');
const size_t labelLen = nextSlash - labelStart;
if (Label_checkEqual(labelStart, labelLen, str_system_slice)) {
@@ -104,7 +104,7 @@ static bool CGroup_filterName_internal(const char* cgroup, StrBuf_state* s, StrB
return false;
if (String_startsWith(cgroup, str_system_slice_prefix)) {
- cgroup = strchrnul(cgroup + 1, '/');
+ cgroup = String_strchrnul(cgroup + 1, '/');
continue;
}
@@ -129,7 +129,7 @@ static bool CGroup_filterName_internal(const char* cgroup, StrBuf_state* s, StrB
if (!String_startsWith(cgroup, str_user_slice_prefix))
continue;
- const char* userSliceSlash = strchrnul(cgroup + strlen(str_user_slice_prefix), '/');
+ const char* userSliceSlash = String_strchrnul(cgroup + strlen(str_user_slice_prefix), '/');
const char* sliceSpec = userSliceSlash - strlen(str_slice_suffix);
if (!String_startsWith(sliceSpec, str_slice_suffix))
@@ -212,7 +212,7 @@ static bool CGroup_filterName_internal(const char* cgroup, StrBuf_state* s, StrB
while (*labelStart == '/')
labelStart++;
- nextSlash = strchrnul(labelStart, '/');
+ nextSlash = String_strchrnul(labelStart, '/');
if (nextSlash - labelStart > 0) {
if (!StrBuf_putsz(s, w, isMonitor ? "[LXC:" : "[lxc:"))
return false;
@@ -276,7 +276,7 @@ static bool CGroup_filterName_internal(const char* cgroup, StrBuf_state* s, StrB
continue;
} else if (Label_checkPrefix(labelStart, scopeNameLen, str_snap_scope_prefix)) {
- const char* nextDot = strchrnul(labelStart + strlen(str_snap_scope_prefix), '.');
+ const char* nextDot = String_strchrnul(labelStart + strlen(str_snap_scope_prefix), '.');
if (!StrBuf_putsz(s, w, "!snap:"))
return false;
diff --git a/linux/LinuxProcessTable.c b/linux/LinuxProcessTable.c
index 962274c9..582b5228 100644
--- a/linux/LinuxProcessTable.c
+++ b/linux/LinuxProcessTable.c
@@ -856,13 +856,13 @@ static void LinuxProcessTable_readCGroupFile(LinuxProcess* process, openat_arg_t
char* group = buffer;
for (size_t i = 0; i < 2; i++) {
- group = strchrnul(group, ':');
+ group = String_strchrnul(group, ':');
if (!*group)
break;
group++;
}
- char* eol = strchrnul(group, '\n');
+ char* eol = String_strchrnul(group, '\n');
*eol = '\0';
if (at != output) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy