2009-01-07 06:53:29 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
|
2006-07-16 19:39:23 +00:00
|
|
|
*
|
2009-01-07 06:53:29 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2009-08-10 20:04:08 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2009-01-07 06:53:29 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2006-07-16 19:39:23 +00:00
|
|
|
*
|
2009-01-07 06:53:29 +00:00
|
|
|
* $Id$
|
|
|
|
*/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
#ifndef TR_UTILS_H
|
|
|
|
#define TR_UTILS_H 1
|
|
|
|
|
2007-08-04 00:43:47 +00:00
|
|
|
#include <inttypes.h>
|
2007-07-14 05:28:35 +00:00
|
|
|
#include <stdarg.h>
|
2009-01-02 20:12:23 +00:00
|
|
|
#include <stddef.h> /* size_t */
|
2007-09-20 23:33:46 +00:00
|
|
|
#include <stdio.h> /* FILE* */
|
2009-01-02 20:12:23 +00:00
|
|
|
#include <string.h> /* memcpy()* */
|
|
|
|
#include <stdlib.h> /* malloc() */
|
2008-06-16 22:11:50 +00:00
|
|
|
#include <time.h> /* time_t* */
|
2007-07-14 05:28:35 +00:00
|
|
|
|
2009-01-02 20:12:23 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
|
2008-09-19 17:17:34 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-05-15 15:44:51 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/**
|
|
|
|
* @addtogroup utils Utilities
|
2009-08-10 20:04:08 +00:00
|
|
|
* @{
|
2009-05-29 19:17:12 +00:00
|
|
|
*/
|
|
|
|
|
2008-05-18 16:44:30 +00:00
|
|
|
#ifndef FALSE
|
2008-09-23 19:11:04 +00:00
|
|
|
#define FALSE 0
|
2008-05-18 16:44:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef TRUE
|
2008-09-23 19:11:04 +00:00
|
|
|
#define TRUE 1
|
2008-05-18 16:44:30 +00:00
|
|
|
#endif
|
|
|
|
|
2008-10-23 02:37:21 +00:00
|
|
|
#ifndef UNUSED
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define UNUSED __attribute__ ( ( unused ) )
|
|
|
|
#else
|
|
|
|
#define UNUSED
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef TR_GNUC_PRINTF
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define TR_GNUC_PRINTF( fmt,\
|
|
|
|
args ) __attribute__ ( ( format ( printf, fmt,\
|
|
|
|
args ) ) )
|
|
|
|
#else
|
|
|
|
#define TR_GNUC_PRINTF( fmt, args )
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef TR_GNUC_NULL_TERMINATED
|
|
|
|
#if __GNUC__ >= 4
|
|
|
|
#define TR_GNUC_NULL_TERMINATED __attribute__ ( ( __sentinel__ ) )
|
|
|
|
#else
|
|
|
|
#define TR_GNUC_NULL_TERMINATED
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __GNUC__ > 2 || ( __GNUC__ == 2 && __GNUC_MINOR__ >= 96 )
|
|
|
|
#define TR_GNUC_PURE __attribute__ ( ( __pure__ ) )
|
|
|
|
#define TR_GNUC_MALLOC __attribute__ ( ( __malloc__ ) )
|
|
|
|
#else
|
|
|
|
#define TR_GNUC_PURE
|
|
|
|
#define TR_GNUC_MALLOC
|
|
|
|
#endif
|
|
|
|
|
2008-05-15 15:44:51 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2006-08-22 02:12:58 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
#if !defined( _ )
|
2009-02-07 14:46:43 +00:00
|
|
|
#if defined( HAVE_LIBINTL_H ) && !defined( SYS_DARWIN )
|
2008-03-04 02:02:25 +00:00
|
|
|
#include <libintl.h>
|
2008-09-23 19:11:04 +00:00
|
|
|
#define _( a ) gettext ( a )
|
|
|
|
#else
|
|
|
|
#define _( a ) ( a )
|
|
|
|
#endif
|
2008-03-05 01:05:42 +00:00
|
|
|
#endif
|
2008-03-04 02:02:25 +00:00
|
|
|
|
2008-08-21 21:04:57 +00:00
|
|
|
/* #define DISABLE_GETTEXT */
|
2008-10-22 17:16:12 +00:00
|
|
|
#if defined(TR_EMBEDDED) && !defined(DISABLE_GETTEXT)
|
|
|
|
#define DISABLE_GETTEXT
|
|
|
|
#endif
|
2008-08-21 21:04:57 +00:00
|
|
|
#ifdef DISABLE_GETTEXT
|
2008-10-22 17:16:12 +00:00
|
|
|
const char * tr_strip_positional_args( const char * fmt );
|
2008-09-23 19:11:04 +00:00
|
|
|
#undef _
|
|
|
|
#define _( a ) tr_strip_positional_args( a )
|
2008-08-21 21:04:57 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-29 18:11:56 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
2008-10-13 22:45:05 +00:00
|
|
|
|
2009-01-25 16:14:11 +00:00
|
|
|
void tr_assertImpl( const char * file, int line, const char * test, const char * fmt, ... ) TR_GNUC_PRINTF( 4, 5 );
|
|
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#define tr_assert( test, fmt, ... )
|
|
|
|
#else
|
|
|
|
#define tr_assert( test, fmt, ... ) \
|
2009-02-07 14:49:01 +00:00
|
|
|
do { if( ! ( test ) ) tr_assertImpl( __FILE__, __LINE__, #test, fmt, __VA_ARGS__ ); } while( 0 )
|
2009-01-25 16:14:11 +00:00
|
|
|
#endif
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2008-12-29 18:11:56 +00:00
|
|
|
int tr_msgLoggingIsActive( int level );
|
2008-05-15 15:44:51 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_msg( const char * file,
|
|
|
|
int line,
|
|
|
|
int level,
|
|
|
|
const char * torrent,
|
|
|
|
const char * fmt,
|
|
|
|
... ) TR_GNUC_PRINTF( 5, 6 );
|
2008-05-15 15:44:51 +00:00
|
|
|
|
2008-12-29 18:11:56 +00:00
|
|
|
#define tr_nerr( n, ... ) \
|
|
|
|
do { \
|
|
|
|
if( tr_msgLoggingIsActive( TR_MSG_ERR ) ) \
|
|
|
|
tr_msg( __FILE__, __LINE__, TR_MSG_ERR, n, __VA_ARGS__ ); \
|
|
|
|
} while( 0 )
|
|
|
|
|
|
|
|
#define tr_ninf( n, ... ) \
|
|
|
|
do { \
|
|
|
|
if( tr_msgLoggingIsActive( TR_MSG_INF) ) \
|
|
|
|
tr_msg( __FILE__, __LINE__, TR_MSG_INF, n, __VA_ARGS__ ); \
|
|
|
|
} while( 0 )
|
|
|
|
|
|
|
|
#define tr_ndbg( n, ... ) \
|
|
|
|
do { \
|
|
|
|
if( tr_msgLoggingIsActive( TR_MSG_DBG) ) \
|
|
|
|
tr_msg( __FILE__, __LINE__, TR_MSG_DBG, n, __VA_ARGS__ ); \
|
|
|
|
} while( 0 )
|
|
|
|
|
|
|
|
#define tr_torerr( tor, ... ) \
|
|
|
|
do { \
|
|
|
|
if( tr_msgLoggingIsActive( TR_MSG_ERR ) ) \
|
|
|
|
tr_msg( __FILE__, __LINE__, TR_MSG_ERR, tor->info.name, __VA_ARGS__ ); \
|
|
|
|
} while( 0 )
|
|
|
|
|
|
|
|
#define tr_torinf( tor, ... ) \
|
|
|
|
do { \
|
|
|
|
if( tr_msgLoggingIsActive( TR_MSG_INF ) ) \
|
|
|
|
tr_msg( __FILE__, __LINE__, TR_MSG_INF, tor->info.name, __VA_ARGS__ ); \
|
|
|
|
} while( 0 )
|
|
|
|
|
|
|
|
#define tr_tordbg( tor, ... ) \
|
|
|
|
do { \
|
|
|
|
if( tr_msgLoggingIsActive( TR_MSG_DBG ) ) \
|
|
|
|
tr_msg( __FILE__, __LINE__, TR_MSG_DBG, tor->info.name, __VA_ARGS__ ); \
|
|
|
|
} while( 0 )
|
|
|
|
|
|
|
|
#define tr_err( ... ) \
|
|
|
|
do { \
|
|
|
|
if( tr_msgLoggingIsActive( TR_MSG_ERR ) ) \
|
|
|
|
tr_msg( __FILE__, __LINE__, TR_MSG_ERR, NULL, __VA_ARGS__ ); \
|
|
|
|
} while( 0 )
|
|
|
|
|
|
|
|
#define tr_inf( ... ) \
|
|
|
|
do { \
|
|
|
|
if( tr_msgLoggingIsActive( TR_MSG_INF ) ) \
|
|
|
|
tr_msg( __FILE__, __LINE__, TR_MSG_INF, NULL, __VA_ARGS__ ); \
|
|
|
|
} while( 0 )
|
|
|
|
|
|
|
|
#define tr_dbg( ... ) \
|
|
|
|
do { \
|
|
|
|
if( tr_msgLoggingIsActive( TR_MSG_DBG ) ) \
|
|
|
|
tr_msg( __FILE__, __LINE__, TR_MSG_DBG, NULL, __VA_ARGS__ ); \
|
|
|
|
} while( 0 )
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
FILE* tr_getLog( void );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2009-01-03 02:43:17 +00:00
|
|
|
tr_bool tr_deepLoggingIsActive( void );
|
2008-10-26 15:39:04 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_deepLog( const char * file,
|
|
|
|
int line,
|
|
|
|
const char * name,
|
|
|
|
const char * fmt,
|
|
|
|
... ) TR_GNUC_PRINTF( 4, 5 );
|
2008-04-25 02:57:33 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
char* tr_getLogTimeStr( char * buf,
|
|
|
|
int buflen );
|
2007-10-06 18:20:52 +00:00
|
|
|
|
2008-12-29 18:11:56 +00:00
|
|
|
|
|
|
|
int tr_wildmat( const char * text,
|
|
|
|
const char * pattern );
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief Portability wrapper for basename() that uses the system implementation if available */
|
|
|
|
char* tr_basename( const char * path ) TR_GNUC_MALLOC;
|
2008-10-14 03:39:16 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief Portability wrapper for dirname() that uses the system implementation if available */
|
|
|
|
char* tr_dirname( const char * path ) TR_GNUC_MALLOC;
|
2008-10-13 22:26:02 +00:00
|
|
|
|
2008-01-18 01:40:41 +00:00
|
|
|
/**
|
2009-05-29 19:17:12 +00:00
|
|
|
* @brief Portability wrapper for mkdir()
|
|
|
|
*
|
2008-01-18 01:40:41 +00:00
|
|
|
* a portability wrapper around mkdir().
|
|
|
|
* On WIN32, the `permissions' argument is unused.
|
|
|
|
*
|
|
|
|
* @return zero on success, or -1 if an error occurred
|
|
|
|
* (in which case errno is set appropriately).
|
|
|
|
*/
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_mkdir( const char * path,
|
|
|
|
int permissions );
|
2008-01-18 01:40:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Like mkdir, but makes parent directories as needed.
|
|
|
|
*
|
|
|
|
* @return zero on success, or -1 if an error occurred
|
|
|
|
* (in which case errno is set appropriately).
|
|
|
|
*/
|
2009-05-29 19:17:12 +00:00
|
|
|
int tr_mkdirp( const char * path, int permissions );
|
2007-08-01 00:40:49 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2008-10-03 04:49:06 +00:00
|
|
|
/**
|
2009-05-29 19:17:12 +00:00
|
|
|
* @brief Loads a file and returns its contents.
|
2008-10-03 04:49:06 +00:00
|
|
|
* On failure, NULL is returned and errno is set.
|
|
|
|
*/
|
2009-05-29 19:17:12 +00:00
|
|
|
uint8_t* tr_loadFile( const char * filename, size_t * size ) TR_GNUC_MALLOC;
|
2007-10-15 20:15:34 +00:00
|
|
|
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief build a filename from a series of elements using the
|
|
|
|
platform's correct directory separator. */
|
|
|
|
char* tr_buildPath( const char * first_element, ... ) TR_GNUC_NULL_TERMINATED
|
|
|
|
TR_GNUC_MALLOC;
|
2007-06-18 19:39:52 +00:00
|
|
|
|
2008-10-15 16:43:51 +00:00
|
|
|
struct timeval;
|
|
|
|
|
2009-06-12 23:01:35 +00:00
|
|
|
tr_bool tr_isTimeval( const struct timeval * tv );
|
|
|
|
|
|
|
|
void tr_timevalMsec( uint64_t milliseconds, struct timeval * setme );
|
|
|
|
|
|
|
|
void tr_timevalSet( struct timeval * setme, int seconds, int microseconds );
|
2007-08-23 20:33:01 +00:00
|
|
|
|
2009-06-15 03:24:40 +00:00
|
|
|
struct event;
|
|
|
|
|
|
|
|
void tr_timerAdd( struct event * timer, int seconds, int milliseconds );
|
|
|
|
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief return the current date in milliseconds */
|
2008-10-23 02:37:21 +00:00
|
|
|
uint64_t tr_date( void );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief wait the specified number of milliseconds */
|
2008-10-23 02:37:21 +00:00
|
|
|
void tr_wait( uint64_t delay_milliseconds );
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/**
|
|
|
|
* @brief make a copy of 'str' whose non-utf8 content has been corrected or stripped
|
|
|
|
* @param str the string to make a clean copy of
|
|
|
|
* @param len the length of the string to copy. If -1, the entire string is used.
|
|
|
|
* @param err if an error occurs and err is non-NULL, it's set to TRUE.
|
|
|
|
*/
|
|
|
|
char* tr_utf8clean( const char * str, int len, tr_bool * err ) TR_GNUC_MALLOC;
|
2009-01-10 22:48:58 +00:00
|
|
|
|
|
|
|
|
2007-07-19 11:54:37 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/* Sometimes the system defines MAX/MIN, sometimes not.
|
|
|
|
In the latter case, define those here since we will use them */
|
2007-07-19 11:54:37 +00:00
|
|
|
#ifndef MAX
|
2008-09-23 19:11:04 +00:00
|
|
|
#define MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
|
2007-07-19 11:54:37 +00:00
|
|
|
#endif
|
|
|
|
#ifndef MIN
|
2008-09-23 19:11:04 +00:00
|
|
|
#define MIN( a, b ) ( ( a ) > ( b ) ? ( b ) : ( a ) )
|
2007-07-19 11:54:37 +00:00
|
|
|
#endif
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE void* tr_malloc( size_t size )
|
2009-01-02 20:12:23 +00:00
|
|
|
{
|
|
|
|
return size ? malloc( size ) : NULL;
|
|
|
|
}
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE void* tr_malloc0( size_t size )
|
2009-01-02 20:12:23 +00:00
|
|
|
{
|
|
|
|
return size ? calloc( 1, size ) : NULL;
|
|
|
|
}
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE void tr_free( void * p )
|
2009-01-02 20:12:23 +00:00
|
|
|
{
|
|
|
|
if( p != NULL )
|
|
|
|
free( p );
|
|
|
|
}
|
2009-01-11 17:02:04 +00:00
|
|
|
static TR_INLINE void* tr_memdup( const void * src, int byteCount )
|
2009-01-02 20:12:23 +00:00
|
|
|
{
|
|
|
|
return memcpy( tr_malloc( byteCount ), src, byteCount );
|
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-02 20:12:23 +00:00
|
|
|
#define tr_new( struct_type, n_structs ) \
|
|
|
|
( (struct_type *) tr_malloc ( ( (size_t) sizeof ( struct_type ) ) * ( ( size_t) ( n_structs ) ) ) )
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-02 20:12:23 +00:00
|
|
|
#define tr_new0( struct_type, n_structs ) \
|
|
|
|
( (struct_type *) tr_malloc0 ( ( (size_t) sizeof ( struct_type ) ) * ( ( size_t) ( n_structs ) ) ) )
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-02 20:12:23 +00:00
|
|
|
#define tr_renew( struct_type, mem, n_structs ) \
|
|
|
|
( (struct_type *) realloc ( ( mem ), ( (size_t) sizeof ( struct_type ) ) * ( ( size_t) ( n_structs ) ) ) )
|
2007-06-27 05:14:38 +00:00
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
/** @param in is a void* so that callers can pass in both signed & unsigned without a cast */
|
2009-01-19 14:05:43 +00:00
|
|
|
char* tr_strndup( const void * in, int len ) TR_GNUC_MALLOC;
|
2007-06-27 05:14:38 +00:00
|
|
|
|
2009-01-11 17:02:04 +00:00
|
|
|
/** @param in is a void* so that callers can pass in both signed & unsigned without a cast */
|
|
|
|
static TR_INLINE char* tr_strdup( const void * in )
|
2009-01-02 20:12:23 +00:00
|
|
|
{
|
2009-01-11 17:02:04 +00:00
|
|
|
return tr_strndup( in, in ? strlen( (const char *) in ) : 0 );
|
2009-01-02 20:12:23 +00:00
|
|
|
}
|
2008-05-20 17:33:54 +00:00
|
|
|
|
2009-01-04 16:29:44 +00:00
|
|
|
/* @brief same argument list as bsearch() */
|
|
|
|
int tr_lowerBound( const void * key,
|
|
|
|
const void * base,
|
|
|
|
size_t nmemb,
|
|
|
|
size_t size,
|
|
|
|
int (* compar)(const void* key, const void* arrayMember),
|
|
|
|
tr_bool * exact_match );
|
|
|
|
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
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;
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief Portability wrapper for strlcpy() that uses the system implementation if available */
|
|
|
|
size_t tr_strlcpy( char * dst, const void * src, size_t siz );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief Portability wrapper for snprintf() that uses the system implementation if available */
|
|
|
|
int tr_snprintf( char * buf, size_t buflen,
|
|
|
|
const char * fmt, ... ) TR_GNUC_PRINTF( 3, 4 );
|
2008-05-18 16:44:30 +00:00
|
|
|
|
2008-10-23 02:37:21 +00:00
|
|
|
const char* tr_strerror( int );
|
2008-02-19 04:16:04 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief strips leading and trailing whitspace from a string
|
|
|
|
@return the stripped string */
|
|
|
|
char* tr_strstrip( char * str );
|
2008-09-05 19:11:30 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief Portability wrapper for memmem() that uses the system implementation if available */
|
2009-05-19 04:48:33 +00:00
|
|
|
const char* tr_memmem( const char * haystack, size_t haystack_len,
|
|
|
|
const char * needle, size_t needle_len );
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
typedef void ( tr_set_func )( void * element, void * userData );
|
2007-09-20 16:32:01 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_set_compare( const void * a,
|
|
|
|
size_t aCount,
|
|
|
|
const void * b,
|
|
|
|
size_t bCount,
|
|
|
|
int compare( const void * a, const void * b ),
|
|
|
|
size_t elementSize,
|
|
|
|
tr_set_func in_a_cb,
|
|
|
|
tr_set_func in_b_cb,
|
|
|
|
tr_set_func in_both_cb,
|
|
|
|
void * userData );
|
2008-08-22 01:27:00 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
void tr_sha1_to_hex( char * out,
|
|
|
|
const uint8_t * sha1 );
|
2008-02-25 20:21:22 +00:00
|
|
|
|
2008-03-24 15:58:06 +00:00
|
|
|
|
2009-08-12 19:44:32 +00:00
|
|
|
tr_bool tr_httpIsValidURL( const char * url );
|
2008-04-24 01:42:53 +00:00
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
int tr_httpParseURL( const char * url,
|
|
|
|
int url_len,
|
|
|
|
char ** setme_host,
|
|
|
|
int * setme_port,
|
|
|
|
char ** setme_path );
|
2008-03-24 15:58:06 +00:00
|
|
|
|
2008-12-29 21:17:48 +00:00
|
|
|
double tr_getRatio( double numerator, double denominator );
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
int* tr_parseNumberRange( const char * str, int str_len, int * setmeCount ) TR_GNUC_MALLOC;
|
2009-02-09 17:25:48 +00:00
|
|
|
|
2008-12-29 21:17:48 +00:00
|
|
|
|
|
|
|
int tr_ptr2int( void* );
|
|
|
|
|
|
|
|
void* tr_int2ptr( int );
|
2008-01-04 19:13:30 +00:00
|
|
|
|
2009-07-14 20:09:46 +00:00
|
|
|
/* truncate a double value at a given number of decimal places.
|
|
|
|
this can be used to prevent a printf() call from rounding up:
|
|
|
|
call with the decimal_places argument equal to the number of
|
|
|
|
decimal places in the printf()'s precision:
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2009-07-14 20:09:46 +00:00
|
|
|
- printf("%.2f%%", 99.999 ) ==> "100.00%"
|
2009-07-17 18:00:29 +00:00
|
|
|
|
2009-07-14 20:09:46 +00:00
|
|
|
- printf("%.2f%%", tr_truncd(99.999, 2)) ==> "99.99%"
|
2009-07-17 18:00:29 +00:00
|
|
|
^ ^
|
|
|
|
| These should match |
|
|
|
|
+------------------------+
|
2009-07-14 20:09:46 +00:00
|
|
|
*/
|
|
|
|
double tr_truncd( double x, int decimal_places );
|
|
|
|
|
2009-03-04 16:16:02 +00:00
|
|
|
/**
|
|
|
|
* @param buf the buffer to write the string to
|
|
|
|
* @param buflef buf's size
|
|
|
|
* @param ratio the ratio to convert to a string
|
|
|
|
* @param the string represntation of "infinity"
|
|
|
|
*/
|
|
|
|
char* tr_strratio( char * buf, size_t buflen, double ratio, const char * infinity );
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @brief Portability wrapper for localtime_r() that uses the system implementation if available */
|
2009-03-25 18:42:39 +00:00
|
|
|
struct tm * tr_localtime_r( const time_t *_clock, struct tm *_result );
|
|
|
|
|
|
|
|
|
2009-05-13 15:54:04 +00:00
|
|
|
/** on success, return 0. on failure, return -1 and set errno */
|
2009-10-27 23:00:34 +00:00
|
|
|
int tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed );
|
2009-05-13 15:54:04 +00:00
|
|
|
|
2009-03-04 16:16:02 +00:00
|
|
|
|
2008-09-19 17:17:34 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @} */
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
#endif
|