Skip to contentSkip to conversation

perf lib: Introduce rtrim

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Jun 20, 2012 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  cb1a28a0cbf9dac5a7a0ca02ebebc12db260d2f8
Gitweb:     http://git.kernel.org/tip/cb1a28a0cbf9dac5a7a0ca02ebebc12db260d2f8
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Thu, 7 Jun 2012 18:23:31 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 19 Jun 2012 13:06:19 -0300

perf lib: Introduce rtrim

Remove the trailing whitespaces.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/string.c |   22 ++++++++++++++++++++++
 tools/perf/util/util.h   |    2 ++
 2 files changed, 24 insertions(+), 0 deletions(-)
tools/perf/util/string.c +22 -0
index d583638..199bc4d 100644
@@ -313,3 +313,25 @@ int strtailcmp(const char *s1, const char *s2)
 	return 0;
 }
 
+/**
+ * rtrim - Removes trailing whitespace from @s.
+ * @s: The string to be stripped.
+ *
+ * Note that the first trailing whitespace is replaced with a %NUL-terminator
+ * in the given string @s. Returns @s.
+ */
+char *rtrim(char *s)
+{
+	size_t size = strlen(s);
+	char *end;
+
+	if (!size)
+		return s;
+
+	end = s + size - 1;
+	while (end >= s && isspace(*end))
+		end--;
+	*(end + 1) = '\0';
+
+	return s;
+}
tools/perf/util/util.h +2 -0
index 2daaedb..b13c733 100644
@@ -264,4 +264,6 @@ bool is_power_of_2(unsigned long n)
 
 size_t hex_width(u64 v);
 
+char *rtrim(char *s);
+
 #endif