summaryrefslogtreecommitdiffstats
path: root/linux
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-03 21:20:43 +0200
committerChristian Göttsche <cgzones@googlemail.com>2020-10-19 15:38:45 +0200
commit4c66eb6d4cbdddc658e5f0274d8130155c6013f1 (patch)
tree8446343e944911b68b590a4bb5f834476f13230b /linux
parent577416d1a946382ab9f0c523e5fae755f9d71f69 (diff)
XUtils string related updates
- allow count out-parameter of String_split() to be NULL - introduce xStrndup() - do not allow NULL pointers passed to String_eq() it is not used in any code - implement String_startsWith(), String_contains_i() and String_eq() as inline header functions - adjust several conversion issues
Diffstat (limited to 'linux')
-rw-r--r--linux/Battery.c4
-rw-r--r--linux/LinuxProcessList.c18
-rw-r--r--linux/Platform.c2
3 files changed, 12 insertions, 12 deletions
diff --git a/linux/Battery.c b/linux/Battery.c
index f3e2ff24..956a7397 100644
--- a/linux/Battery.c
+++ b/linux/Battery.c
@@ -53,7 +53,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
if (!dirEntry)
break;
char* entryName = dirEntry->d_name;
- if (strncmp(entryName, "BAT", 3))
+ if (String_startsWith(entryName, "BAT"))
continue;
batteries[nBatteries] = xStrdup(entryName);
nBatteries++;
@@ -128,7 +128,7 @@ static ACPresence procAcpiCheck(void) {
char *isOnline = String_getToken(line, 2);
free(line);
- if (strcmp(isOnline, "on-line") == 0) {
+ if (String_eq(isOnline, "on-line")) {
isOn = AC_PRESENT;
} else {
isOn = AC_ABSENT;
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 1ed13826..4e3a804f 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -419,9 +419,9 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
while ((line = strsep(&buf, "\n")) != NULL) {
switch (line[0]) {
case 'r':
- if (line[1] == 'c' && strncmp(line+2, "har: ", 5) == 0)
+ if (line[1] == 'c' && String_startsWith(line+2, "har: "))
process->io_rchar = strtoull(line+7, NULL, 10);
- else if (strncmp(line+1, "ead_bytes: ", 11) == 0) {
+ else if (String_startsWith(line+1, "ead_bytes: ")) {
process->io_read_bytes = strtoull(line+12, NULL, 10);
process->io_rate_read_bps =
((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000);
@@ -429,9 +429,9 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
}
break;
case 'w':
- if (line[1] == 'c' && strncmp(line+2, "har: ", 5) == 0)
+ if (line[1] == 'c' && String_startsWith(line+2, "har: "))
process->io_wchar = strtoull(line+7, NULL, 10);
- else if (strncmp(line+1, "rite_bytes: ", 12) == 0) {
+ else if (String_startsWith(line+1, "rite_bytes: ")) {
process->io_write_bytes = strtoull(line+13, NULL, 10);
process->io_rate_write_bps =
((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000);
@@ -439,14 +439,14 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
}
break;
case 's':
- if (line[4] == 'r' && strncmp(line+1, "yscr: ", 6) == 0) {
+ if (line[4] == 'r' && String_startsWith(line+1, "yscr: ")) {
process->io_syscr = strtoull(line+7, NULL, 10);
- } else if (strncmp(line+1, "yscw: ", 6) == 0) {
+ } else if (String_startsWith(line+1, "yscw: ")) {
process->io_syscw = strtoull(line+7, NULL, 10);
}
break;
case 'c':
- if (strncmp(line+1, "ancelled_write_bytes: ", 22) == 0) {
+ if (String_startsWith(line+1, "ancelled_write_bytes: ")) {
process->io_cancelled_write_bytes = strtoull(line+23, NULL, 10);
}
}
@@ -598,7 +598,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d
switch(field) {
case 1:
foundEnvID = true;
- if(0 != strcmp(name_value_sep, process->ctid ? process->ctid : "")) {
+ if(!String_eq(name_value_sep, process->ctid ? process->ctid : "")) {
free(process->ctid);
process->ctid = xStrdup(name_value_sep);
}
@@ -762,7 +762,7 @@ static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char*
char *newline = strchr(buffer, '\n');
if (newline)
*newline = '\0';
- if (process->secattr && 0 == strcmp(process->secattr, buffer))
+ if (process->secattr && String_eq(process->secattr, buffer))
return;
free(process->secattr);
process->secattr = xStrdup(buffer);
diff --git a/linux/Platform.c b/linux/Platform.c
index 1bb476ab..afa2b7fd 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -376,7 +376,7 @@ void Platform_getNetworkIO(unsigned long int *bytesReceived,
&packetsTransmittedParsed) != 5)
continue;
- if (0 == strcmp(interfaceName, "lo:"))
+ if (String_eq(interfaceName, "lo:"))
continue;
bytesReceivedSum += bytesReceivedParsed;