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

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

 



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

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]