Re: [PATCH v4 1/2] mm: add kstrimdup function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]