[PATCH 5/5] perf tools: Refactor the code to strip command name with {l,r}trim()

From: Taeung Song
Date: Fri Apr 07 2017 - 10:25:24 EST


After reading command name from /proc/<pid>/status,
use ltrim() and rtrim() to strip command name, not using
just while loop, isspace() and etc.

Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Don Zickus <dzickus@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Signed-off-by: Taeung Song <treeze.taeung@xxxxxxxxx>
---
tools/perf/util/event.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 76b9c6b..8255a26 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -106,7 +106,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
int fd;
size_t size = 0;
ssize_t n;
- char *nl, *name, *tgids, *ppids;
+ char *name, *tgids, *ppids;

*tgid = -1;
*ppid = -1;
@@ -134,14 +134,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,

if (name) {
name += 5; /* strlen("Name:") */
-
- while (*name && isspace(*name))
- ++name;
-
- nl = strchr(name, '\n');
- if (nl)
- *nl = '\0';
-
+ name = rtrim(ltrim(name));
size = strlen(name);
if (size >= len)
size = len - 1;
--
2.7.4