Il 20/09/2012 09:53, Paolo Bonzini ha scritto:
>>>> Would look a bit nicer with strstart() form cutils.c instead of strncmp().
>> > strstart() works with const char pointers, but I have char pointers here
>> > which I need to modify.
> You can pass a char* to a function that accepts const char*.  In your
> case, the last argument to strstart would be NULL.

As you pointed out on IRC, you meant the last argument.  I don't think
it would be a problem to cast that from char ** to const char **.

Perhaps it would be cleaner to make qemu_gluster_parseuri and
parse_gluster_spec accept a const char *.  You can replace strtok_r +
g_strdup with strspn/strcspn followed by g_strndup.

BTW, here the second strtok_r needs to stop at "&".

> +static int parse_socket(GlusterURI *uri, char *socket)
> +{
> +    char *token, *saveptr;
> +
> +    if (!socket) {
> +        return 0;
> +    }
> +    token = strtok_r(socket, "=", &saveptr);
> +    if (!token || strcmp(token, "socket")) {
> +        return -EINVAL;
> +    }
> +    token = strtok_r(NULL, "=", &saveptr);
> +    if (!token) {
> +        return -EINVAL;
> +    }

And the same for the second strtok_r here too:

> +    /* socket */
> +    token = strtok_r(NULL, "?", &saveptr);
> +    ret = parse_socket(uri, token);
> +    if (ret < 0) {
> +        goto out;
> +     }
> +
> +    /* Flag error for extra options */
> +    token = strtok_r(NULL, "?", &saveptr);
> +    if (token) {
> +        ret = -EINVAL;
> +        goto out;
> +    }
> +

Paolo



Reply via email to