mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 20:35:36 +00:00
(libT) 1. tweak tr_bitfieldTestFast(). 2. add tr_memdup()
This commit is contained in:
@@ -588,6 +588,14 @@ tr_errorString( int code )
|
||||
*****
|
||||
****/
|
||||
|
||||
void*
|
||||
tr_memdup( const void * in, int byteCount )
|
||||
{
|
||||
void * out = tr_new( uint8_t, byteCount );
|
||||
memcpy( out, in, byteCount );
|
||||
return out;
|
||||
}
|
||||
|
||||
char*
|
||||
tr_strdup( const char * in )
|
||||
{
|
||||
@@ -692,8 +700,7 @@ tr_bitfieldDup( const tr_bitfield * in )
|
||||
{
|
||||
tr_bitfield * ret = calloc( 1, sizeof(tr_bitfield) );
|
||||
ret->len = in->len;
|
||||
ret->bits = malloc( ret->len );
|
||||
memcpy( ret->bits, in->bits, ret->len );
|
||||
ret->bits = tr_memdup( in->bits, in->len );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,7 @@ void tr_free ( void* );
|
||||
|
||||
char* tr_strdup( const char * str ) TR_GNUC_MALLOC;
|
||||
char* tr_strndup( const char * str, int len ) TR_GNUC_MALLOC;
|
||||
void* tr_memdup( const void * src, int byteCount ) TR_GNUC_MALLOC;
|
||||
char* tr_strdup_printf( const char * fmt, ... ) TR_GNUC_PRINTF( 1, 2 ) TR_GNUC_MALLOC;
|
||||
char* tr_base64_encode( const void * input, int inlen, int *outlen ) TR_GNUC_MALLOC;
|
||||
char* tr_base64_decode( const void * input, int inlen, int *outlen ) TR_GNUC_MALLOC;
|
||||
@@ -271,7 +272,7 @@ tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* );
|
||||
|
||||
/** @param high the highest nth bit you're going to access */
|
||||
#define tr_bitfieldTestFast(bitfield,high) \
|
||||
((bitfield) && ( (bitfield)->bits ) && ( ((high)>>3u) < (bitfield)->len ))
|
||||
((bitfield) && ( (bitfield)->bits ) && ( (high) <= (bitfield)->len*8 ))
|
||||
|
||||
double tr_getRatio( double numerator, double denominator );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user