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

Re: [libvirt] [PATCHv2 1/2] sysinfo: add virSkipSpacesBackwards()



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 redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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