[libvirt] [PATCHv2 1/2] sysinfo: add virSkipSpacesBackwards()
Eric Blake
eblake at redhat.com
Wed Jun 29 17:14:15 UTC 2011
On 06/29/2011 11:04 AM, Eric Blake wrote:
> void
> virTrimSpaces(char *str, char **endp)
> {
> char *end;
>
> if (!endp || !*endp)
> end = str + strlen(str);
else
end = *endp;
> while (end > str && c_isspace(end[-1]))
> end--;
> if (endp) {
> if (!*endp)
> *end = '\0';
> *endp = end;
> } else {
> *end = '\0';
> }
> }
> /**
> * virSkipSpacesBackwards:
> * @str: start of string
> * @endp: on entry, must point to a location with @str, on exit,
> * will be adjusted to skip trailing spaces
> *
> * Returns 0 on success, -1 on error
> */
> int
> virSkipSpacesBackwards(const char *str, char **endp)
Actually, looking at how you used this in patch 2/2, you want to trim
all spaces up to either the newline (*endp is non-NULL) or the end of
the string (*endp is NULL), all without modifying str, so this would
need a modification:
> {
> if (!endp || !*endp)
> return -1;
if (!endp)
return -1;
if (!*endp)
*endp = (char*)str + strlen(str);
> /* Casting away const is safe, since virTrimSpaces does not
> * modify string with this particular usage. */
> virTrimSpaces((char *)str), endp);
> return 0;
> }
--
Eric Blake eblake at redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110629/8d473353/attachment-0001.sig>
More information about the libvir-list
mailing list