>From 6bdcc1f97eadda0966738b24c051c866d4e68f51 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Wed, 17 Mar 2010 14:49:33 +0100
Subject: [PATCH] make wtrimspace() use internal api
make wtrimspace() use wings' own function for a task
semantics change: it used to segfault given null, now it returns null.
this doesn't affect any current use (there's exactly one..). i see
no harm in this behaviour, and perceive this to me more natural.
---
WINGs/WINGs/WUtil.h | 4 ++--
WINGs/string.c | 16 +++++++---------
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h
index 6e1d4a5..ef6df84 100644
--- a/WINGs/WINGs/WUtil.h
+++ b/WINGs/WINGs/WUtil.h
@@ -257,7 +257,7 @@ void wrelease(void *ptr);
void* wretain(void *ptr);
char *wstrdup(const char *str);
-char* wstrndup(char *str, size_t len);
+char* wstrndup(const char *str, size_t len);
/* Concatenate str1 with str2 and return that in a newly malloc'ed string.
* str1 and str2 can be any strings including static and constant strings.
@@ -283,7 +283,7 @@ char* wtokenjoin(char **list, int count);
void wtokenfree(char **tokens, int count);
-char* wtrimspace(char *s);
+char* wtrimspace(const char *s);
WMRange wmkrange(int start, int count);
diff --git a/WINGs/string.c b/WINGs/string.c
index 956ad3a..8cb0b03 100644
--- a/WINGs/string.c
+++ b/WINGs/string.c
@@ -145,22 +145,20 @@ void wtokenfree(char **tokens, int count)
wfree(tokens);
}
-char *wtrimspace(char *s)
+char *wtrimspace(const char *s)
{
char *t;
- char *c;
+
+ if (s == NULL)
+ return NULL;
while (isspace(*s) && *s)
s++;
- t = s + strlen(s) - 1;
+ t = (char *)s + strlen(s) - 1;
while (t > s && isspace(*t))
t--;
- c = wmalloc(t - s + 2);
- memcpy(c, s, t - s + 1);
- c[t - s + 1] = 0;
-
- return c;
+ return wstrndup(s, t - s + 1);
}
char *wstrdup(const char *str)
@@ -170,7 +168,7 @@ char *wstrdup(const char *str)
return strcpy(wmalloc(strlen(str) + 1), str);
}
-char *wstrndup(char *str, size_t len)
+char *wstrndup(const char *str, size_t len)
{
char *copy;
--
1.7.0
--
[-]
mkdir /nonexistentFrom 6bdcc1f97eadda0966738b24c051c866d4e68f51 Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Wed, 17 Mar 2010 14:49:33 +0100
Subject: [PATCH] make wtrimspace() use internal api
make wtrimspace() use wings' own function for a task
semantics change: it used to segfault given null, now it returns null.
this doesn't affect any current use (there's exactly one..), and i see
no harm in this behaviour, and perceive this to me more natural.
---
WINGs/WINGs/WUtil.h | 4 ++--
WINGs/string.c | 16 +++++++---------
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h
index 6e1d4a5..ef6df84 100644
--- a/WINGs/WINGs/WUtil.h
+++ b/WINGs/WINGs/WUtil.h
@@ -257,7 +257,7 @@ void wrelease(void *ptr);
void* wretain(void *ptr);
char *wstrdup(const char *str);
-char* wstrndup(char *str, size_t len);
+char* wstrndup(const char *str, size_t len);
/* Concatenate str1 with str2 and return that in a newly malloc'ed string.
* str1 and str2 can be any strings including static and constant strings.
@@ -283,7 +283,7 @@ char* wtokenjoin(char **list, int count);
void wtokenfree(char **tokens, int count);
-char* wtrimspace(char *s);
+char* wtrimspace(const char *s);
WMRange wmkrange(int start, int count);
diff --git a/WINGs/string.c b/WINGs/string.c
index 956ad3a..8cb0b03 100644
--- a/WINGs/string.c
+++ b/WINGs/string.c
@@ -145,22 +145,20 @@ void wtokenfree(char **tokens, int count)
wfree(tokens);
}
-char *wtrimspace(char *s)
+char *wtrimspace(const char *s)
{
char *t;
- char *c;
+
+ if (s == NULL)
+ return NULL;
while (isspace(*s) && *s)
s++;
- t = s + strlen(s) - 1;
+ t = (char *)s + strlen(s) - 1;
while (t > s && isspace(*t))
t--;
- c = wmalloc(t - s + 2);
- memcpy(c, s, t - s + 1);
- c[t - s + 1] = 0;
-
- return c;
+ return wstrndup(s, t - s + 1);
}
char *wstrdup(const char *str)
@@ -170,7 +168,7 @@ char *wstrdup(const char *str)
return strcpy(wmalloc(strlen(str) + 1), str);
}
-char *wstrndup(char *str, size_t len)
+char *wstrndup(const char *str, size_t len)
{
char *copy;
--
1.7.0