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_deduplicate_option(char** optstr, const char* name)
{
    int rc;
    char *begin = NULL, *end = NULL, *opt;

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

    opt = *optstr;
    do
    {
        struct libmnt_optloc ol;

        mnt_init_optloc(&ol);

        rc = mnt_optstr_locate_option(opt, name, &ol);
        if (!rc)
        {
            if (begin)
            {
                /* remove the previous instance */
                size_t shift = strlen(*optstr);

                mnt_optstr_remove_option_at(optstr, begin, end);

                /* now all the offsets are not valid anymore - recount */
                shift -= strlen(*optstr);
                ol.begin -= shift;
                ol.end -= shift;
            }
            begin = ol.begin;
            end = ol.end;
            opt = end && *end ? end + 1 : NULL;
        }
    } while (rc == 0 && opt && *opt);

    return rc < 0 ? rc : begin ? 0 : 1;
}
/**
 * mnt_optstr_deduplicate_option:
 * @optstr: string with a comma separated list of options
 * @name: requested option name
 *
 * Removes all instances of @name except the last one.
 *
 * 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 name

Removes all instances of @name except the last one.

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 name Removes all instances of @name except the last one . 0 on success 1 when not found the @name or negative number in case of error .
int mnt_optstr_deduplicate_option(char** optstr, const char* name)
{
    int rc;
    char *begin = NULL, *end = NULL, *opt;
    if (!optstr || !name)
        return -EINVAL;
    opt = *optstr;
    do
    {
        struct libmnt_optloc ol;
        mnt_init_optloc(&ol);
        rc = mnt_optstr_locate_option(opt, name, &ol);
        if (!rc)
        {
            if (begin)
            {
                size_t shift = strlen(*optstr);
                mnt_optstr_remove_option_at(optstr, begin, end);
                shift -= strlen(*optstr);
                ol.begin -= shift;
                ol.end -= shift;
            }
            begin = ol.begin;
            end = ol.end;
            opt = end && *end ? end + 1 : NULL;
        }
    } while (rc == 0 && opt && *opt);
    return rc < 0 ? rc : begin ? 0 : 1;
}
int mnt_optstr_deduplicate_option ( char * * optstr , const char * name ) { int rc ; char * begin = NULL , * end = NULL , * opt ; if ( ! optstr || ! name ) return - EINVAL ; opt = * optstr ; do { struct libmnt_optloc ol ; mnt_init_optloc ( & ol ) ; rc = mnt_optstr_locate_option ( opt , name , & ol ) ; if ( ! rc ) { if ( begin ) { size_t shift = strlen ( * optstr ) ; mnt_optstr_remove_option_at ( optstr , begin , end ) ; shift -= strlen ( * optstr ) ; ol . begin -= shift ; ol . end -= shift ; } begin = ol . begin ; end = ol . end ; opt = end && * end ? end + 1 : NULL ; } } while ( rc == 0 && opt && * opt ) ; return rc < 0 ? rc : begin ? 0 : 1 ; }
mnt_optstr_deduplicate_option:
 @optstr: string with a comma separated list of options
 @name: requested option name
mnt_optstr_deduplicate_option : @optstr : string with a comma separated list of options @name : requested option name
/* remove the previous instance */ /* now all the offsets are not valid anymore - recount */