Re: [PATCH] driver core: Add the ability to unbind drivers to devices from userspace

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

 



Jon Smirl wrote:
> Do we need to deal with UTF8 here? I did the forward loop because you
> can't parse UTF8 backwards. If UTF8 is possible I need to change the
> pointer inc function.

As others have mentioned there shouldn't be a UTF8 problem with isspace().
However, even if you wanted to scan going forwards you can do it without
the complexity of a nested loop:

	char *real_end;

	for (real_end = x; x - buffer->page < count; x++)
		if (!isspace(*x))
			real_end = x + 1;
	*real_end = '\0';
	// then fix "count"

BTW, my code I posted yesterday is incomplete since I neglected to notice
that the "count = z - x" at the end is used to repair "count" damage from
both the leading and trailing whitespace stripping.  Its actually easier
to strip the trailing whitespace first, like:

	while (count > 0 && isspace(buffer->page[count - 1]))
		count--;	/* strip trailing whitespace */
	if (count > 0 && isspace(buffer->page[0])) {
		/*
		 * We have leading whitespace but also at least one
		 * non-whitespace character
		 */
		const char *x = buffer->page;
		do {
			x++;
			count--;
		} while (isspace(*x));
		memmove(buffer->page, x, count);
	}
	buffer->page[count] = '\0';

-Mitch
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux