*****
****/
+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 )
{
{
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;
}
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;
/** @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 );