Quoting Joe Perches (2014-01-29 19:50:59)
What should the return be to this string? " " Should it be "" or " " or NULL?
I don't think it should be NULL. I don't think it should be " ".
Right, thanks for pointing that out. It should match how trim behaves :)
Your original looks good. removing the begin declaration adds an extra line, and I think it reads nicely the way you had it.
size_t len; s = skip_spaces(s); len = strlen(begin);
This is what I have now, basically your original with the len > 1 check and the '\0' replacing 0.
char *kstrimdup(const char *s, gfp_t gfp) { char *buf; char *begin = skip_spaces(s); size_t len = strlen(begin);
while (len > 1 && isspace(begin[len - 1])) len--;
buf = kmalloc_track_caller(len + 1, gfp); if (!buf) return NULL;
memcpy(buf, begin, len); buf[len] = '\0';
return buf; }
Any other comments?
Thanks!
Sebastian