summaryrefslogtreecommitdiff
path: root/src/pacman/util.c
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2011-12-22 08:52:08 -0500
committerDan McGee <dan@archlinux.org>2011-12-23 14:37:03 -0600
commit92216c5864efccacf2daa3f4f15de3bb479054bb (patch)
treee814870fbae8ab4e953fb29c56af3b2123bae690 /src/pacman/util.c
parent7b2f68cc21df469342cb1caa7ec8fb27005cd2dd (diff)
pacman/util: return size_t from strtrim
Instead of returning the same value as the parameter to this function, return the length of the string, which can be useful to the caller when its non-zero (e.g. to find the end of the string). Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r--src/pacman/util.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 7846291e..4160c44d 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -325,13 +325,13 @@ char *strtoupper(char *str)
/* Trim whitespace and newlines from a string
*/
-char *strtrim(char *str)
+size_t strtrim(char *str)
{
- char *pch = str;
+ char *end, *pch = str;
if(str == NULL || *str == '\0') {
/* string is empty, so we're done. */
- return str;
+ return 0;
}
while(isspace((unsigned char)*pch)) {
@@ -348,16 +348,16 @@ char *strtrim(char *str)
/* check if there wasn't anything but whitespace in the string. */
if(*str == '\0') {
- return str;
+ return 0;
}
- pch = (str + (strlen(str) - 1));
- while(isspace((unsigned char)*pch)) {
- pch--;
+ end = (str + strlen(str) - 1);
+ while(isspace((unsigned char)*end)) {
+ end--;
}
- *++pch = '\0';
+ *++end = '\0';
- return str;
+ return end - pch;
}
/* Replace all occurances of 'needle' with 'replace' in 'str', returning