FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 12-23-2011, 09:43 PM
Dave Reisner
 
Default 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>
---
This should make an earlier email from dan make a bit more sense
when he referred to "the new return value"

src/pacman/util.c | 18 +++++++++---------
src/pacman/util.h | 2 +-
2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 7846291..4160c44 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 == '') {
/* 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 == '') {
- 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 = '';
+ *++end = '';

- return str;
+ return end - pch;
}

/* Replace all occurances of 'needle' with 'replace' in 'str', returning
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 6ec962f..6291939 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -56,7 +56,7 @@ const char *mbasename(const char *path);
char *mdirname(const char *path);
void indentprint(const char *str, size_t indent);
char *strtoupper(char *str);
-char *strtrim(char *str);
+size_t strtrim(char *str);
char *strreplace(const char *str, const char *needle, const char *replace);
alpm_list_t *strsplit(const char *str, const char splitchar);
void string_display(const char *title, const char *string);
--
1.7.8.1
 

Thread Tools




All times are GMT. The time now is 10:07 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org