summaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorJudd Vinet <judd@archlinux.org>2005-01-12 00:14:16 +0100
committerJudd Vinet <judd@archlinux.org>2005-01-12 00:14:16 +0100
commitd48cc3bf5d0bc9aef5e816c81d3a0f6b8e2680c7 (patch)
treed58b94b8ec3f7909fbf7fd819c0f4a5b873d1285 /src/util.c
parentad39cd7bd6858841ebaa4809f151ba03c0e9f3bf (diff)
downloadpacman-d48cc3bf5d0bc9aef5e816c81d3a0f6b8e2680c7.tar.gz
pacman-d48cc3bf5d0bc9aef5e816c81d3a0f6b8e2680c7.tar.xz
Imported from pacman-2.9.5.tar.gz
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index 0c922096..08241691 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,7 +1,7 @@
/*
* util.c
*
- * Copyright (c) 2002-2004 by Judd Vinet <jvinet@zeroflux.org>
+ * Copyright (c) 2002-2005 by Judd Vinet <jvinet@zeroflux.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -281,12 +281,22 @@ char* strtoupper(char *str)
char* trim(char *str)
{
char *pch = str;
+
+ if(*str == '\0')
+ /* string is empty, so we're done. */
+ return(str);
+
while(isspace(*pch)) {
pch++;
}
if(pch != 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)) {
@@ -294,7 +304,7 @@ char* trim(char *str)
}
*++pch = '\0';
- return str;
+ return(str);
}
/* A cheap grep for text files, returns 1 if a substring