Skip to content

Commit

Permalink
perf lib: Introduce rtrim
Browse files Browse the repository at this point in the history
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]>
Link: http://lkml.kernel.org/n/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Jun 19, 2012
1 parent e078ba1 commit cb1a28a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tools/perf/util/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions tools/perf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,6 @@ bool is_power_of_2(unsigned long n)

size_t hex_width(u64 v);

char *rtrim(char *s);

#endif

0 comments on commit cb1a28a

Please sign in to comment.