client/src/unifycr.c
static int unifycr_abtoull(char* str, unsigned long long* val)
{
    /* check that we have a string */
    if (str == NULL) {
        debug("scr_abtoull: Can't convert NULL string to bytes @ %s:%d",
            __FILE__, __LINE__
        );
        return UNIFYCR_FAILURE;
    }

    /* check that we have a value to write to */
    if (val == NULL) {
        debug("scr_abtoull: NULL address to store value @ %s:%d",
            __FILE__, __LINE__
        );
        return UNIFYCR_FAILURE;
    }

    /* pull the floating point portion of our byte string off */
    errno = 0;
    char* next = NULL;
    double num = strtod(str, &next);
    if (errno != 0) {
        debug("scr_abtoull: Invalid double: %s @ %s:%d",
            str, __FILE__, __LINE__
        );
        return UNIFYCR_FAILURE;
    }

    /* now extract any units, e.g. KB MB GB, etc */
    unsigned long long units = 1;
    if (*next != '\0') {
        switch(*next) {
        case 'k':
        case 'K':
            units = 1024;
            break;
        case 'm':
        case 'M':
            units = 1024*1024;
            break;
        case 'g':
        case 'G':
            units = 1024*1024*1024;
            break;
        default:
            debug("scr_abtoull: Unexpected byte string %s @ %s:%d",
                str, __FILE__, __LINE__
            );
            return UNIFYCR_FAILURE;
        }

        next++;

        /* handle optional b or B character, e.g. in 10KB */
        if (*next == 'b' || *next == 'B') {
            next++;
        }

        /* check that we've hit the end of the string */
        if (*next != 0) {
            debug("scr_abtoull: Unexpected byte string: %s @ %s:%d",
                str, __FILE__, __LINE__
            );
            return UNIFYCR_FAILURE;
        }
    }

    /* check that we got a positive value */
    if (num < 0) {
        debug("scr_abtoull: Byte string must be positive: %s @ %s:%d",
            str, __FILE__, __LINE__
        );
        return UNIFYCR_FAILURE;
    }

    /* multiply by our units and set out return value */
    *val = (unsigned long long) (num * (double) units);

    return UNIFYCR_SUCCESS;
}
/* converts string like 10mb to unsigned long long integer value of 10*1024*1024 */
converts string like 10mb to unsigned long long integer value of 10*1024*1024
converts string like 10mb to unsigned long long integer value of 10 * 1024 * 1024
static int unifycr_abtoull(char* str, unsigned long long* val)
{
    if (str == NULL) {
        debug("scr_abtoull: Can't convert NULL string to bytes @ %s:%d",
            __FILE__, __LINE__
        );
        return UNIFYCR_FAILURE;
    }
    if (val == NULL) {
        debug("scr_abtoull: NULL address to store value @ %s:%d",
            __FILE__, __LINE__
        );
        return UNIFYCR_FAILURE;
    }
    errno = 0;
    char* next = NULL;
    double num = strtod(str, &next);
    if (errno != 0) {
        debug("scr_abtoull: Invalid double: %s @ %s:%d",
            str, __FILE__, __LINE__
        );
        return UNIFYCR_FAILURE;
    }
    unsigned long long units = 1;
    if (*next != '\0') {
        switch(*next) {
        case 'k':
        case 'K':
            units = 1024;
            break;
        case 'm':
        case 'M':
            units = 1024*1024;
            break;
        case 'g':
        case 'G':
            units = 1024*1024*1024;
            break;
        default:
            debug("scr_abtoull: Unexpected byte string %s @ %s:%d",
                str, __FILE__, __LINE__
            );
            return UNIFYCR_FAILURE;
        }
        next++;
        if (*next == 'b' || *next == 'B') {
            next++;
        }
        if (*next != 0) {
            debug("scr_abtoull: Unexpected byte string: %s @ %s:%d",
                str, __FILE__, __LINE__
            );
            return UNIFYCR_FAILURE;
        }
    }
    if (num < 0) {
        debug("scr_abtoull: Byte string must be positive: %s @ %s:%d",
            str, __FILE__, __LINE__
        );
        return UNIFYCR_FAILURE;
    }
    *val = (unsigned long long) (num * (double) units);
    return UNIFYCR_SUCCESS;
}
static int unifycr_abtoull ( char * str , unsigned long long * val ) { if ( str == NULL ) { debug ( " " , __FILE__ , __LINE__ ) ; return UNIFYCR_FAILURE ; } if ( val == NULL ) { debug ( " " , __FILE__ , __LINE__ ) ; return UNIFYCR_FAILURE ; } errno = 0 ; char * next = NULL ; double num = strtod ( str , & next ) ; if ( errno != 0 ) { debug ( " " , str , __FILE__ , __LINE__ ) ; return UNIFYCR_FAILURE ; } unsigned long long units = 1 ; if ( * next != ' \0 ' ) { switch ( * next ) { case ' ' : case ' ' : units = 1024 ; break ; case ' ' : case ' ' : units = 1024 * 1024 ; break ; case ' ' : case ' ' : units = 1024 * 1024 * 1024 ; break ; default : debug ( " " , str , __FILE__ , __LINE__ ) ; return UNIFYCR_FAILURE ; } next ++ ; if ( * next == ' ' || * next == ' ' ) { next ++ ; } if ( * next != 0 ) { debug ( " " , str , __FILE__ , __LINE__ ) ; return UNIFYCR_FAILURE ; } } if ( num < 0 ) { debug ( " " , str , __FILE__ , __LINE__ ) ; return UNIFYCR_FAILURE ; } * val = ( unsigned long long ) ( num * ( double ) units ) ; return UNIFYCR_SUCCESS ; }
converts string like 10mb to unsigned long long integer value of 10*1024*1024
converts string like 10mb to unsigned long long integer value of 10 * 1024 * 1024
/* check that we have a string */ /* check that we have a value to write to */ /* pull the floating point portion of our byte string off */ /* now extract any units, e.g. KB MB GB, etc */ /* handle optional b or B character, e.g. in 10KB */ /* check that we've hit the end of the string */ /* check that we got a positive value */ /* multiply by our units and set out return value */