openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libnl/1_3.4.0-r0/libnl-3.4.0/lib/utils.c
long nl_size2int(const char* str)
{
    char* p;
    long l = strtol(str, &p, 0);
    if (p == str)
        return -NLE_INVAL;

    if (*p)
    {
        if (!strcasecmp(p, "kb") || !strcasecmp(p, "k"))
            l *= 1024;
        else if (!strcasecmp(p, "gb") || !strcasecmp(p, "g"))
            l *= 1024 * 1024 * 1024;
        else if (!strcasecmp(p, "gbit"))
            l *= 1000000000L / 8;
        else if (!strcasecmp(p, "mb") || !strcasecmp(p, "m"))
            l *= 1024 * 1024;
        else if (!strcasecmp(p, "mbit"))
            l *= 1000000 / 8;
        else if (!strcasecmp(p, "kbit"))
            l *= 1000 / 8;
        else if (!strcasecmp(p, "bit"))
            l /= 8;
        else if (strcasecmp(p, "b") != 0)
            return -NLE_INVAL;
    }

    return l;
}
/**
 * Convert a character string to a size
 * @arg str		size encoded as character string
 *
 * Converts the specified size as character to the corresponding
 * number of bytes.
 *
 * Supported formats are:
 *  - b,kb/k,m/mb,gb/g for bytes
 *  - bit,kbit/mbit/gbit
 *
 * This function assume 1000 bits in one kilobit and
 * 1024 bytes in one kilobyte
 *
 * @return The number of bytes or -1 if the string is unparseable
 */
Convert a character string to a size
@arg str             size encoded as character string

Converts the specified size as character to the corresponding
number of bytes.



This function assume 1000 bits in one kilobit and
1024 bytes in one kilobyte

@return The number of bytes or -1 if the string is unparseable
Convert a character string to a size @arg str size encoded as character string Converts the specified size as character to the corresponding number of bytes . This function assume 1000 bits in one kilobit and 1024 bytes in one kilobyte @return The number of bytes or - 1 if the string is unparseable
long nl_size2int(const char* str)
{
    char* p;
    long l = strtol(str, &p, 0);
    if (p == str)
        return -NLE_INVAL;
    if (*p)
    {
        if (!strcasecmp(p, "kb") || !strcasecmp(p, "k"))
            l *= 1024;
        else if (!strcasecmp(p, "gb") || !strcasecmp(p, "g"))
            l *= 1024 * 1024 * 1024;
        else if (!strcasecmp(p, "gbit"))
            l *= 1000000000L / 8;
        else if (!strcasecmp(p, "mb") || !strcasecmp(p, "m"))
            l *= 1024 * 1024;
        else if (!strcasecmp(p, "mbit"))
            l *= 1000000 / 8;
        else if (!strcasecmp(p, "kbit"))
            l *= 1000 / 8;
        else if (!strcasecmp(p, "bit"))
            l /= 8;
        else if (strcasecmp(p, "b") != 0)
            return -NLE_INVAL;
    }
    return l;
}
long nl_size2int ( const char * str ) { char * p ; long l = strtol ( str , & p , 0 ) ; if ( p == str ) return - NLE_INVAL ; if ( * p ) { if ( ! strcasecmp ( p , " " ) || ! strcasecmp ( p , " " ) ) l *= 1024 ; else if ( ! strcasecmp ( p , " " ) || ! strcasecmp ( p , " " ) ) l *= 1024 * 1024 * 1024 ; else if ( ! strcasecmp ( p , " " ) ) l *= 1000000000L / 8 ; else if ( ! strcasecmp ( p , " " ) || ! strcasecmp ( p , " " ) ) l *= 1024 * 1024 ; else if ( ! strcasecmp ( p , " " ) ) l *= 1000000 / 8 ; else if ( ! strcasecmp ( p , " " ) ) l *= 1000 / 8 ; else if ( ! strcasecmp ( p , " " ) ) l /= 8 ; else if ( strcasecmp ( p , " " ) != 0 ) return - NLE_INVAL ; } return l ; }
Convert a character string to a size
 @arg str             size encoded as character string
Convert a character string to a size @arg str size encoded as character string