From f556fe8b4a199116b5665bb5f0886e4c2962b077 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 28 May 2012 17:32:11 -0400 Subject: add line length parameter to _alpm_strip_newline If known, callers can pass the line size to this function in order to avoid an strlen call. Otherwise, they simply pass 0 and _alpm_strip_newline will do the call instead. Signed-off-by: Dave Reisner Signed-off-by: Dan McGee --- lib/libalpm/util.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/libalpm/util.c') diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 8fd7a100..c2b5d443 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -195,15 +195,17 @@ cleanup: /** Trim trailing newlines from a string (if any exist). * @param str a single line of text + * @param len size of str, if known, else 0 * @return the length of the trimmed string */ -size_t _alpm_strip_newline(char *str) +size_t _alpm_strip_newline(char *str, size_t len) { - size_t len; if(*str == '\0') { return 0; } - len = strlen(str); + if(len == 0) { + len = strlen(str); + } while(len > 0 && str[len - 1] == '\n') { len--; } -- cgit v1.2.3-24-g4f1b