From d48cc3bf5d0bc9aef5e816c81d3a0f6b8e2680c7 Mon Sep 17 00:00:00 2001 From: Judd Vinet Date: Tue, 11 Jan 2005 23:14:16 +0000 Subject: Imported from pacman-2.9.5.tar.gz --- src/util.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/util.c') 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 + * Copyright (c) 2002-2005 by Judd Vinet * * 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 -- cgit v1.2.3-24-g4f1b