mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-02 14:15:46 +01:00
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 be more natural.
This commit is contained in:
committed by
Carlos R. Mafra
parent
109e504262
commit
9911ecd985
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user