Changeset 6069


Ignore:
Timestamp:
Jun 6, 2008, 11:53:30 PM (14 years ago)
Author:
charles
Message:

(libT) 1. tweak tr_bitfieldTestFast(). 2. add tr_memdup()

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r6058 r6069  
    589589****/
    590590
     591void*
     592tr_memdup( const void * in, int byteCount )
     593{
     594    void * out = tr_new( uint8_t, byteCount );
     595    memcpy( out, in, byteCount );
     596    return out;
     597}
     598   
    591599char*
    592600tr_strdup( const char * in )
     
    693701    tr_bitfield * ret = calloc( 1, sizeof(tr_bitfield) );
    694702    ret->len = in->len;
    695     ret->bits = malloc( ret->len );
    696     memcpy( ret->bits, in->bits, ret->len );
     703    ret->bits = tr_memdup( in->bits, in->len );
    697704    return ret;
    698705}
  • trunk/libtransmission/utils.h

    r6058 r6069  
    191191char* tr_strdup( const char * str ) TR_GNUC_MALLOC;
    192192char* tr_strndup( const char * str, int len ) TR_GNUC_MALLOC;
     193void* tr_memdup( const void * src, int byteCount ) TR_GNUC_MALLOC;
    193194char* tr_strdup_printf( const char * fmt, ... )  TR_GNUC_PRINTF( 1, 2 ) TR_GNUC_MALLOC;
    194195char* tr_base64_encode( const void * input, int inlen, int *outlen ) TR_GNUC_MALLOC;
     
    272273/** @param high the highest nth bit you're going to access */
    273274#define tr_bitfieldTestFast(bitfield,high) \
    274     ((bitfield) && ( (bitfield)->bits ) && ( ((high)>>3u) < (bitfield)->len ))
     275    ((bitfield) && ( (bitfield)->bits ) && ( (high) <= (bitfield)->len*8 ))
    275276
    276277double tr_getRatio( double numerator, double denominator );
Note: See TracChangeset for help on using the changeset viewer.