src/ber_int.c
int ber_encinteger(ODR o, Odr_int val)
{
    unsigned long long uval = val;
    unsigned char tmp[sizeof(uval)];
    int len;
    size_t i;
    for (i = sizeof(uval); i > 0; )
    {
        tmp[--i] = (unsigned char ) uval; /* only want lower 8 bits */
        uval >>= 8;
    }
    for (i = 0; i < sizeof(uval)-1; i++)
        if (!((tmp[i] == 0 && !(tmp[i+1] & 0x80))
              ||
              (tmp[i] == 0xFF && (tmp[i+1] & 0x80))))
            break;
    len = sizeof(uval) - i;
    if (ber_enclen(o, len, 1, 1) != 1)
        return -1;
    if (odr_write(o, (const char *) tmp + i, len) < 0)
        return -1;
    return 0;
}
/*
 * Returns: number of bytes written or -1 for error (out of bounds).
 */
number of bytes written or -1 for error (out of bounds).
number of bytes written or - 1 for error ( out of bounds ) .
int ber_encinteger(ODR o, Odr_int val)
{
    unsigned long long uval = val;
    unsigned char tmp[sizeof(uval)];
    int len;
    size_t i;
    for (i = sizeof(uval); i > 0; )
    {
        tmp[--i] = (unsigned char ) uval; 
        uval >>= 8;
    }
    for (i = 0; i < sizeof(uval)-1; i++)
        if (!((tmp[i] == 0 && !(tmp[i+1] & 0x80))
              ||
              (tmp[i] == 0xFF && (tmp[i+1] & 0x80))))
            break;
    len = sizeof(uval) - i;
    if (ber_enclen(o, len, 1, 1) != 1)
        return -1;
    if (odr_write(o, (const char *) tmp + i, len) < 0)
        return -1;
    return 0;
}
int ber_encinteger ( ODR o , Odr_int val ) { unsigned long long uval = val ; unsigned char tmp [ sizeof ( uval ) ] ; int len ; size_t i ; for ( i = sizeof ( uval ) ; i > 0 ; ) { tmp [ -- i ] = ( unsigned char ) uval ; uval >>= 8 ; } for ( i = 0 ; i < sizeof ( uval ) - 1 ; i ++ ) if ( ! ( ( tmp [ i ] == 0 && ! ( tmp [ i + 1 ] & 0x80 ) ) || ( tmp [ i ] == 0xFF && ( tmp [ i + 1 ] & 0x80 ) ) ) ) break ; len = sizeof ( uval ) - i ; if ( ber_enclen ( o , len , 1 , 1 ) != 1 ) return -1 ; if ( odr_write ( o , ( const char * ) tmp + i , len ) < 0 ) return -1 ; return 0 ; }
Returns: number of bytes written or -1 for error (out of bounds).
Returns : number of bytes written or - 1 for error ( out of bounds ) .
/* only want lower 8 bits */