diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 61ab181e6f..9062bbb0b5 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -258,15 +258,10 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * memcpy(ans, "[...]", max_length-1); ans[max_length-1] = 0; } else { - char *e; - t[max_length - 6] = 0; /* Chop off final spaces */ - e = strchr(t, 0); - while (e > t && isspace(e[-1])) - e--; - *e = 0; + delete_trailing_chars(t, WHITESPACE); ans = strjoin("[", t, "...]"); } diff --git a/src/basic/string-util.c b/src/basic/string-util.c index a9362bf8bd..7ea478883b 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -269,23 +269,12 @@ char *strjoin_real(const char *x, ...) { } char *strstrip(char *s) { - char *e; - if (!s) return NULL; - /* Drops trailing whitespace. Modifies the string in - * place. Returns pointer to first non-space character */ + /* Drops trailing whitespace. Modifies the string in place. Returns pointer to first non-space character */ - s += strspn(s, WHITESPACE); - - for (e = strchr(s, 0); e > s; e --) - if (!strchr(WHITESPACE, e[-1])) - break; - - *e = 0; - - return s; + return delete_trailing_chars(skip_leading_chars(s, WHITESPACE), WHITESPACE); } char *delete_chars(char *s, const char *bad) {