Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-05-28 17:32:11 -0400
committerDan McGee <dan@archlinux.org>2012-06-25 23:04:31 -0500
commitf556fe8b4a199116b5665bb5f0886e4c2962b077 (patch)
treeda359a1cea95066f32962219e4909adf325c0df4 /lib/libalpm/util.c
parent74274b5dc347ba70e4abd1f329feb41538f82ff4 (diff)
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 <dreisner@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c8
1 files changed, 5 insertions, 3 deletions
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--;
}