Signed-off-by: Pierre Habouzit <madcoder@debian.org>
char *m_strrtrim(char *s)
{
- if (s) {
- char *p = s + m_strlen(s);
+ ssize_t len = m_strlen(s);
- while (p > s && ISSPACE(p[-1])) {
- *--p = '\0';
- }
- return p;
- }
+ while (len > 1 && ISSPACE(s[len - 1]))
+ s[--len] = '\0';
- return NULL;
+ return s + len;
}
const char *m_stristrn(const char *haystack, const char *needle, ssize_t nlen)
*p++ = '\0';
case '\0':
m_strrtrim(*field);
- m_strrtrim(*value);
+ if (*value)
+ m_strrtrim(*value);
return p;
case '\\':