openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/libmount/src/optstr.c
int mnt_optstr_set_option(char** optstr, const char* name, const char* value)
{
    struct libmnt_optloc ol;
    char* nameend;
    int rc = 1;

    if (!optstr || !name)
        return -EINVAL;

    mnt_init_optloc(&ol);

    if (*optstr)
        rc = mnt_optstr_locate_option(*optstr, name, &ol);
    if (rc < 0)
        return rc; /* parse error */
    if (rc == 1)
        return mnt_optstr_append_option(optstr, name, value); /* not found */

    nameend = ol.begin + ol.namesz;

    if (value == NULL && ol.value && ol.valsz)
        /* remove unwanted "=value" */
        mnt_optstr_remove_option_at(optstr, nameend, ol.end);

    else if (value && ol.value == NULL)
        /* insert "=value" */
        rc = insert_value(optstr, nameend, value, NULL);

    else if (value && ol.value && strlen(value) == ol.valsz)
        /* simply replace =value */
        memcpy(ol.value, value, ol.valsz);

    else if (value && ol.value)
    {
        mnt_optstr_remove_option_at(optstr, nameend, ol.end);
        rc = insert_value(optstr, nameend, value, NULL);
    }
    return rc;
}
/**
 * mnt_optstr_set_option:
 * @optstr: string with a comma separated list of options
 * @name: requested option
 * @value: new value or NULL
 *
 * Set or unset the option @value.
 *
 * Returns: 0 on success, 1 when not found the @name or negative number in case
 * of error.
 */
@optstr: string with a comma separated list of options
@name: requested option
@value: new value or NULL

Set or unset the option @value.

0 on success, 1 when not found the @name or negative number in case
of error.
@optstr : string with a comma separated list of options @name : requested option @value : new value or NULL Set or unset the option @value . 0 on success 1 when not found the @name or negative number in case of error .
int mnt_optstr_set_option(char** optstr, const char* name, const char* value)
{
    struct libmnt_optloc ol;
    char* nameend;
    int rc = 1;
    if (!optstr || !name)
        return -EINVAL;
    mnt_init_optloc(&ol);
    if (*optstr)
        rc = mnt_optstr_locate_option(*optstr, name, &ol);
    if (rc < 0)
        return rc; 
    if (rc == 1)
        return mnt_optstr_append_option(optstr, name, value); 
    nameend = ol.begin + ol.namesz;
    if (value == NULL && ol.value && ol.valsz)
        mnt_optstr_remove_option_at(optstr, nameend, ol.end);
    else if (value && ol.value == NULL)
        rc = insert_value(optstr, nameend, value, NULL);
    else if (value && ol.value && strlen(value) == ol.valsz)
        memcpy(ol.value, value, ol.valsz);
    else if (value && ol.value)
    {
        mnt_optstr_remove_option_at(optstr, nameend, ol.end);
        rc = insert_value(optstr, nameend, value, NULL);
    }
    return rc;
}
int mnt_optstr_set_option ( char * * optstr , const char * name , const char * value ) { struct libmnt_optloc ol ; char * nameend ; int rc = 1 ; if ( ! optstr || ! name ) return - EINVAL ; mnt_init_optloc ( & ol ) ; if ( * optstr ) rc = mnt_optstr_locate_option ( * optstr , name , & ol ) ; if ( rc < 0 ) return rc ; if ( rc == 1 ) return mnt_optstr_append_option ( optstr , name , value ) ; nameend = ol . begin + ol . namesz ; if ( value == NULL && ol . value && ol . valsz ) mnt_optstr_remove_option_at ( optstr , nameend , ol . end ) ; else if ( value && ol . value == NULL ) rc = insert_value ( optstr , nameend , value , NULL ) ; else if ( value && ol . value && strlen ( value ) == ol . valsz ) memcpy ( ol . value , value , ol . valsz ) ; else if ( value && ol . value ) { mnt_optstr_remove_option_at ( optstr , nameend , ol . end ) ; rc = insert_value ( optstr , nameend , value , NULL ) ; } return rc ; }
mnt_optstr_set_option:
 @optstr: string with a comma separated list of options
 @name: requested option
 @value: new value or NULL
mnt_optstr_set_option : @optstr : string with a comma separated list of options @name : requested option @value : new value or NULL
/* parse error */ /* not found */ /* remove unwanted "=value" */ /* insert "=value" */ /* simply replace =value */