summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-03-25 21:13:23 +0000
committerAurelien Foret <aurelien@archlinux.org>2005-03-25 21:13:23 +0000
commit6e63ccfd0fdd19b6d710eb8dc84c85aaf25c3006 (patch)
treeda824e959c8a118cf61ada3aa296fba7ef0809a0 /lib/libalpm/util.c
parente010e1bba62b3e542740ebe63e640048a9052729 (diff)
downloadpacman-6e63ccfd0fdd19b6d710eb8dc84c85aaf25c3006.tar.xz
backported fixes for trim() from pacman 2.9.5
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 053d7b98..bebc996a 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -145,6 +145,11 @@ char *_alpm_strtrim(char *str)
{
char *pch = str;
+ if(*str == '\0') {
+ /* string is empty, so we're done. */
+ return(str);
+ }
+
while(isspace(*pch)) {
pch++;
}
@@ -152,13 +157,18 @@ char *_alpm_strtrim(char *str)
memmove(str, pch, (strlen(pch) + 1));
}
+ /* check if there wasn't anything but whitespace in the string. */
+ if(*str == '\0') {
+ return(str);
+ }
+
pch = (char*)(str + (strlen(str) - 1));
while(isspace(*pch)) {
pch--;
}
*++pch = '\0';
- return str;
+ return(str);
}
/* A cheap grep for text files, returns 1 if a substring