From 2f6b56671f265bc960582c94d1da2c255d5501f3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 11 Jan 2009 17:02:04 +0000 Subject: [PATCH] (trunk libT) win32 portability patch from Alexey --- libtransmission/bandwidth.c | 2 +- libtransmission/bandwidth.h | 16 +++++----- libtransmission/bencode.h | 18 +++++++---- libtransmission/completion.h | 20 ++++++------- libtransmission/net.c | 55 ++++++++++++++++++++++++++++++++++ libtransmission/net.h | 18 ++++++----- libtransmission/peer-io.h | 38 +++++++++++------------ libtransmission/peer-mgr.c | 10 +++---- libtransmission/peer-msgs.c | 14 ++++----- libtransmission/platform.c | 2 +- libtransmission/ptrarray.h | 10 +++---- libtransmission/ratecontrol.h | 4 +-- libtransmission/torrent.c | 4 +-- libtransmission/torrent.h | 24 +++++++-------- libtransmission/transmission.h | 10 ++++--- libtransmission/utils.h | 26 ++++++++-------- 16 files changed, 170 insertions(+), 101 deletions(-) diff --git a/libtransmission/bandwidth.c b/libtransmission/bandwidth.c index 95b3b9ad1..e0bba899b 100644 --- a/libtransmission/bandwidth.c +++ b/libtransmission/bandwidth.c @@ -71,7 +71,7 @@ bytesUsed( const uint64_t now, struct bratecontrol * r, size_t size ) ******* ******/ -static inline int +static TR_INLINE int comparePointers( const void * a, const void * b ) { if( a != b ) diff --git a/libtransmission/bandwidth.h b/libtransmission/bandwidth.h index 2e76bfcd9..ae27ed301 100644 --- a/libtransmission/bandwidth.h +++ b/libtransmission/bandwidth.h @@ -117,7 +117,7 @@ tr_bandwidth* tr_bandwidthConstruct( tr_bandwidth * bandwidth, tr_bandwidth * parent ); /** @brief create a new tr_bandwidth object */ -static inline tr_bandwidth* tr_bandwidthNew( tr_session * session, tr_bandwidth * parent ) +static TR_INLINE tr_bandwidth* tr_bandwidthNew( tr_session * session, tr_bandwidth * parent ) { return tr_bandwidthConstruct( tr_new0( tr_bandwidth, 1 ), session, parent ); } @@ -125,13 +125,13 @@ static inline tr_bandwidth* tr_bandwidthNew( tr_session * session, tr_bandwidth tr_bandwidth* tr_bandwidthDestruct( tr_bandwidth * bandwidth ); /** @brief free a tr_bandwidth object */ -static inline void tr_bandwidthFree( tr_bandwidth * bandwidth ) +static TR_INLINE void tr_bandwidthFree( tr_bandwidth * bandwidth ) { tr_free( tr_bandwidthDestruct( bandwidth ) ); } /** @brief test to see if the pointer refers to a live bandwidth object */ -static inline tr_bool tr_isBandwidth( const tr_bandwidth * b ) +static TR_INLINE tr_bool tr_isBandwidth( const tr_bandwidth * b ) { return ( b != NULL ) && ( b->magicNumber == MAGIC_NUMBER ); } @@ -145,7 +145,7 @@ static inline tr_bool tr_isBandwidth( const tr_bandwidth * b ) * @see tr_bandwidthAllocate * @see tr_bandwidthGetDesiredSpeed */ -static inline void tr_bandwidthSetDesiredSpeed( tr_bandwidth * bandwidth, +static TR_INLINE void tr_bandwidthSetDesiredSpeed( tr_bandwidth * bandwidth, tr_direction dir, double desiredSpeed ) { @@ -156,7 +156,7 @@ static inline void tr_bandwidthSetDesiredSpeed( tr_bandwidth * bandwidth, * @brief Get the desired speed (in KiB/s) for ths bandwidth subtree. * @see tr_bandwidthSetDesiredSpeed */ -static inline double +static TR_INLINE double tr_bandwidthGetDesiredSpeed( const tr_bandwidth * bandwidth, tr_direction dir ) { @@ -166,7 +166,7 @@ tr_bandwidthGetDesiredSpeed( const tr_bandwidth * bandwidth, /** * @brief Set whether or not this bandwidth should throttle its peer-io's speeds */ -static inline void tr_bandwidthSetLimited( tr_bandwidth * bandwidth, +static TR_INLINE void tr_bandwidthSetLimited( tr_bandwidth * bandwidth, tr_direction dir, tr_bool isLimited ) { @@ -176,7 +176,7 @@ static inline void tr_bandwidthSetLimited( tr_bandwidth * bandwidth, /** * @return nonzero if this bandwidth throttles its peer-ios speeds */ -static inline tr_bool tr_bandwidthIsLimited( const tr_bandwidth * bandwidth, +static TR_INLINE tr_bool tr_bandwidthIsLimited( const tr_bandwidth * bandwidth, tr_direction dir ) { return bandwidth->band[dir].isLimited; @@ -232,7 +232,7 @@ void tr_bandwidthSetParent ( tr_bandwidth * bandwidth, * But when we set a torrent's speed mode to TR_SPEEDLIMIT_UNLIMITED, then * in that particular case we want to ignore the global speed limit... */ -static inline void tr_bandwidthHonorParentLimits ( tr_bandwidth * bandwidth, +static TR_INLINE void tr_bandwidthHonorParentLimits ( tr_bandwidth * bandwidth, tr_direction direction, tr_bool isEnabled ) { diff --git a/libtransmission/bencode.h b/libtransmission/bencode.h index ad19f7ad8..2781085b3 100644 --- a/libtransmission/bencode.h +++ b/libtransmission/bencode.h @@ -45,6 +45,10 @@ typedef struct tr_benc } val; } tr_benc; +#ifdef __cplusplus +extern "C" { +#endif + /*** **** ***/ @@ -156,11 +160,11 @@ tr_bool tr_bencGetInt( const tr_benc * val, int64_t * setme ); tr_bool tr_bencGetStr( const tr_benc * val, const char ** setme ); -static inline tr_bool tr_bencIsType ( const tr_benc * b, int type ) { return ( b != NULL ) && ( b->type == type ); } -static inline tr_bool tr_bencIsInt ( const tr_benc * b ) { return tr_bencIsType( b, TYPE_INT ); } -static inline tr_bool tr_bencIsDict ( const tr_benc * b ) { return tr_bencIsType( b, TYPE_DICT ); } -static inline tr_bool tr_bencIsList ( const tr_benc * b ) { return tr_bencIsType( b, TYPE_LIST ); } -static inline tr_bool tr_bencIsString( const tr_benc * b ) { return tr_bencIsType( b, TYPE_STR ); } +static TR_INLINE tr_bool tr_bencIsType ( const tr_benc * b, int type ) { return ( b != NULL ) && ( b->type == type ); } +static TR_INLINE tr_bool tr_bencIsInt ( const tr_benc * b ) { return tr_bencIsType( b, TYPE_INT ); } +static TR_INLINE tr_bool tr_bencIsDict ( const tr_benc * b ) { return tr_bencIsType( b, TYPE_DICT ); } +static TR_INLINE tr_bool tr_bencIsList ( const tr_benc * b ) { return tr_bencIsType( b, TYPE_LIST ); } +static TR_INLINE tr_bool tr_bencIsString( const tr_benc * b ) { return tr_bencIsType( b, TYPE_STR ); } /** *** Treat these as private -- they're only made public here @@ -184,4 +188,8 @@ int tr_bencParseStr( const uint8_t * buf, void tr_bencMergeDicts( tr_benc * target, const tr_benc * source ); +#ifdef __cplusplus +} +#endif + #endif diff --git a/libtransmission/completion.h b/libtransmission/completion.h index 174eeb27d..70637acfa 100644 --- a/libtransmission/completion.h +++ b/libtransmission/completion.h @@ -61,12 +61,12 @@ tr_completion * tr_cpConstruct( tr_completion *, tr_torrent * ); tr_completion * tr_cpDestruct( tr_completion * ); -static inline tr_completion* tr_cpNew( tr_torrent * tor ) +static TR_INLINE tr_completion* tr_cpNew( tr_torrent * tor ) { return tr_cpConstruct( tr_new0( tr_completion, 1 ), tor ); } -static inline void tr_cpFree( tr_completion * cp ) +static TR_INLINE void tr_cpFree( tr_completion * cp ) { tr_free( tr_cpDestruct( cp ) ); } @@ -87,27 +87,27 @@ void tr_cpGetAmountDone( const tr_completion * completio float * tab, int tabCount ); -static inline uint64_t tr_cpHaveTotal( const tr_completion * cp ) +static TR_INLINE uint64_t tr_cpHaveTotal( const tr_completion * cp ) { return cp->sizeNow; } -static inline uint64_t tr_cpLeftUntilComplete( const tr_completion * cp ) +static TR_INLINE uint64_t tr_cpLeftUntilComplete( const tr_completion * cp ) { return tr_torrentInfo(cp->tor)->totalSize - cp->sizeNow; } -static inline uint64_t tr_cpLeftUntilDone( const tr_completion * cp ) +static TR_INLINE uint64_t tr_cpLeftUntilDone( const tr_completion * cp ) { return tr_cpSizeWhenDone( cp ) - cp->sizeNow; } -static inline float tr_cpPercentComplete( const tr_completion * cp ) +static TR_INLINE float tr_cpPercentComplete( const tr_completion * cp ) { return tr_getRatio( cp->sizeNow, tr_torrentInfo(cp->tor)->totalSize ); } -static inline float tr_cpPercentDone( const tr_completion * cp ) +static TR_INLINE float tr_cpPercentDone( const tr_completion * cp ) { return tr_getRatio( cp->sizeNow, tr_cpSizeWhenDone( cp ) ); } @@ -132,7 +132,7 @@ void tr_cpPieceRem( tr_completion * completion, *** Blocks **/ -static inline int tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) { +static TR_INLINE int tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) { return tr_bitfieldHas( &cp->blockBitfield, block ); } @@ -146,11 +146,11 @@ tr_bool tr_cpBlockBitfieldSet( tr_completion * completion, **** ***/ -static inline const struct tr_bitfield * tr_cpPieceBitfield( const tr_completion * cp ) { +static TR_INLINE const struct tr_bitfield * tr_cpPieceBitfield( const tr_completion * cp ) { return &cp->pieceBitfield; } -static inline const struct tr_bitfield * tr_cpBlockBitfield( const tr_completion * cp ) { +static TR_INLINE const struct tr_bitfield * tr_cpBlockBitfield( const tr_completion * cp ) { assert( cp ); assert( cp->blockBitfield.bits ); assert( cp->blockBitfield.bitCount ); diff --git a/libtransmission/net.c b/libtransmission/net.c index 2657274ce..979953475 100644 --- a/libtransmission/net.c +++ b/libtransmission/net.c @@ -58,6 +58,61 @@ const tr_address tr_inaddr_any = { TR_AF_INET, { { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } }; +#ifdef WIN32 +static const char * +inet_ntop(int af, const void *src, char *dst, socklen_t cnt) +{ + if (af == AF_INET) + { + struct sockaddr_in in; + memset(&in, 0, sizeof(in)); + in.sin_family = AF_INET; + memcpy(&in.sin_addr, src, sizeof(struct in_addr)); + getnameinfo((struct sockaddr *)&in, sizeof(struct + sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST); + return dst; + } + else if (af == AF_INET6) + { + struct sockaddr_in6 in; + memset(&in, 0, sizeof(in)); + in.sin6_family = AF_INET6; + memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); + getnameinfo((struct sockaddr *)&in, sizeof(struct + sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST); + return dst; + } + return NULL; +} + +static int +inet_pton(int af, const char *src, void *dst) +{ + struct addrinfo hints; + struct addrinfo *res; + struct addrinfo *ressave; + + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = af; + + if (getaddrinfo(src, NULL, &hints, &res) != 0) + return -1; + + ressave = res; + + while (res) + { + memcpy(dst, res->ai_addr, res->ai_addrlen); + res = res->ai_next; + } + + freeaddrinfo(ressave); + return 0; +} + +#endif + + void tr_netInit( void ) { diff --git a/libtransmission/net.h b/libtransmission/net.h index 2aa161908..90bd63fcb 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -42,13 +42,15 @@ #endif #ifdef WIN32 - #define ECONNREFUSED WSAECONNREFUSED - #define ECONNRESET WSAECONNRESET - #define EHOSTUNREACH WSAEHOSTUNREACH - #define EINPROGRESS WSAEINPROGRESS - #define ENOTCONN WSAENOTCONN - #define EWOULDBLOCK WSAEWOULDBLOCK - #define sockerrno WSAGetLastError( ) + #define ECONNREFUSED WSAECONNREFUSED + #define ECONNRESET WSAECONNRESET + #define EHOSTUNREACH WSAEHOSTUNREACH + #define EINPROGRESS WSAEINPROGRESS + #define ENOTCONN WSAENOTCONN + #define EWOULDBLOCK WSAEWOULDBLOCK + #define EAFNOSUPPORT WSAEAFNOSUPPORT + #define ENETUNREACH WSAENETUNREACH + #define sockerrno WSAGetLastError( ) #else #include #define sockerrno errno @@ -88,7 +90,7 @@ void tr_normalizeV4Mapped( tr_address * const addr ); void tr_suspectAddress( const tr_address * a, const char * source ); -static inline tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); } +static TR_INLINE tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); } typedef struct tr_net_af_support { diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index 436b7ed3e..e04c57db0 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -126,7 +126,7 @@ tr_bool tr_isPeerIo ( const tr_peerIo * io ); void tr_peerIoEnableLTEP( tr_peerIo * io, tr_bool flag ); -static inline tr_bool tr_peerIoSupportsLTEP( const tr_peerIo * io ) +static TR_INLINE tr_bool tr_peerIoSupportsLTEP( const tr_peerIo * io ) { assert( tr_isPeerIo( io ) ); @@ -135,7 +135,7 @@ static inline tr_bool tr_peerIoSupportsLTEP( const tr_peerIo * io ) void tr_peerIoEnableFEXT( tr_peerIo * io, tr_bool flag ); -static inline tr_bool tr_peerIoSupportsFEXT( const tr_peerIo * io ) +static TR_INLINE tr_bool tr_peerIoSupportsFEXT( const tr_peerIo * io ) { assert( tr_isPeerIo( io ) ); @@ -146,7 +146,7 @@ static inline tr_bool tr_peerIoSupportsFEXT( const tr_peerIo * io ) *** **/ -static inline tr_session* tr_peerIoGetSession ( tr_peerIo * io ) +static TR_INLINE tr_session* tr_peerIoGetSession ( tr_peerIo * io ) { assert( tr_isPeerIo( io ) ); assert( io->session ); @@ -157,7 +157,7 @@ static inline tr_session* tr_peerIoGetSession ( tr_peerIo * io ) const char* tr_peerIoAddrStr( const struct tr_address * addr, tr_port port ); -static inline const char* tr_peerIoGetAddrStr( const tr_peerIo * io ) +static TR_INLINE const char* tr_peerIoGetAddrStr( const tr_peerIo * io ) { return tr_peerIoAddrStr( &io->addr, io->port ); } @@ -174,12 +174,12 @@ void tr_peerIoSetTorrentHash( tr_peerIo * io, int tr_peerIoReconnect( tr_peerIo * io ); -static inline tr_bool tr_peerIoIsIncoming( const tr_peerIo * io ) +static TR_INLINE tr_bool tr_peerIoIsIncoming( const tr_peerIo * io ) { return io->isIncoming; } -static inline int tr_peerIoGetAge( const tr_peerIo * io ) +static TR_INLINE int tr_peerIoGetAge( const tr_peerIo * io ) { return time( NULL ) - io->timeCreated; } @@ -192,7 +192,7 @@ static inline int tr_peerIoGetAge( const tr_peerIo * io ) void tr_peerIoSetPeersId( tr_peerIo * io, const uint8_t * peer_id ); -static inline const uint8_t* tr_peerIoGetPeersId( const tr_peerIo * io ) +static TR_INLINE const uint8_t* tr_peerIoGetPeersId( const tr_peerIo * io ) { assert( tr_isPeerIo( io ) ); assert( io->peerIdIsSet ); @@ -229,7 +229,7 @@ void tr_peerIoWriteBuf ( tr_peerIo * io, *** **/ -static inline struct tr_crypto * tr_peerIoGetCrypto( tr_peerIo * io ) +static TR_INLINE struct tr_crypto * tr_peerIoGetCrypto( tr_peerIo * io ) { return io->crypto; } @@ -245,7 +245,7 @@ EncryptionMode; void tr_peerIoSetEncryption( tr_peerIo * io, int encryptionMode ); -static inline tr_bool tr_peerIoIsEncrypted( const tr_peerIo * io ) +static TR_INLINE tr_bool tr_peerIoIsEncrypted( const tr_peerIo * io ) { return ( io != NULL ) && ( io->encryptionMode == PEER_ENCRYPTION_RC4 ); } @@ -255,14 +255,14 @@ void tr_peerIoWriteBytes( tr_peerIo * io, const void * bytes, size_t byteCount ); -static inline void tr_peerIoWriteUint8( tr_peerIo * io, +static TR_INLINE void tr_peerIoWriteUint8( tr_peerIo * io, struct evbuffer * outbuf, uint8_t writeme ) { tr_peerIoWriteBytes( io, outbuf, &writeme, sizeof( uint8_t ) ); } -static inline void tr_peerIoWriteUint16( tr_peerIo * io, +static TR_INLINE void tr_peerIoWriteUint16( tr_peerIo * io, struct evbuffer * outbuf, uint16_t writeme ) { @@ -270,7 +270,7 @@ static inline void tr_peerIoWriteUint16( tr_peerIo * io, tr_peerIoWriteBytes( io, outbuf, &tmp, sizeof( uint16_t ) ); } -static inline void tr_peerIoWriteUint32( tr_peerIo * io, +static TR_INLINE void tr_peerIoWriteUint32( tr_peerIo * io, struct evbuffer * outbuf, uint32_t writeme ) { @@ -283,14 +283,14 @@ void tr_peerIoReadBytes( tr_peerIo * io, void * bytes, size_t byteCount ); -static inline void tr_peerIoReadUint8( tr_peerIo * io, +static TR_INLINE void tr_peerIoReadUint8( tr_peerIo * io, struct evbuffer * inbuf, uint8_t * setme ) { tr_peerIoReadBytes( io, inbuf, setme, sizeof( uint8_t ) ); } -static inline void tr_peerIoReadUint16( tr_peerIo * io, +static TR_INLINE void tr_peerIoReadUint16( tr_peerIo * io, struct evbuffer * inbuf, uint16_t * setme ) { @@ -299,7 +299,7 @@ static inline void tr_peerIoReadUint16( tr_peerIo * io, *setme = ntohs( tmp ); } -static inline void tr_peerIoReadUint32( tr_peerIo * io, +static TR_INLINE void tr_peerIoReadUint32( tr_peerIo * io, struct evbuffer * inbuf, uint32_t * setme ) { @@ -318,7 +318,7 @@ void tr_peerIoDrain( tr_peerIo * io, size_t tr_peerIoGetWriteBufferSpace( const tr_peerIo * io, uint64_t now ); -static inline void tr_peerIoSetParent( tr_peerIo * io, +static TR_INLINE void tr_peerIoSetParent( tr_peerIo * io, struct tr_bandwidth * parent ) { assert( tr_isPeerIo( io ) ); @@ -331,7 +331,7 @@ void tr_peerIoBandwidthUsed( tr_peerIo * io, size_t byteCount, int isPieceData ); -static inline tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io, +static TR_INLINE tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io, tr_direction dir ) { assert( tr_isPeerIo( io ) ); @@ -339,7 +339,7 @@ static inline tr_bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io, return tr_bandwidthClamp( &io->bandwidth, dir, 1024 ) > 0; } -static inline double tr_peerIoGetPieceSpeed( const tr_peerIo * io, uint64_t now, tr_direction dir ) +static TR_INLINE double tr_peerIoGetPieceSpeed( const tr_peerIo * io, uint64_t now, tr_direction dir ) { assert( tr_isPeerIo( io ) ); assert( tr_isDirection( dir ) ); @@ -363,7 +363,7 @@ ssize_t tr_peerIoFlush( tr_peerIo * io, *** **/ -static inline struct evbuffer * tr_peerIoGetReadBuffer( tr_peerIo * io ) +static TR_INLINE struct evbuffer * tr_peerIoGetReadBuffer( tr_peerIo * io ) { return io->inbuf; } diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index cf3ce8f5a..21271d444 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -159,31 +159,31 @@ struct tr_peerMgr *** **/ -static inline void +static TR_INLINE void managerLock( const struct tr_peerMgr * manager ) { tr_globalLock( manager->session ); } -static inline void +static TR_INLINE void managerUnlock( const struct tr_peerMgr * manager ) { tr_globalUnlock( manager->session ); } -static inline void +static TR_INLINE void torrentLock( Torrent * torrent ) { managerLock( torrent->manager ); } -static inline void +static TR_INLINE void torrentUnlock( Torrent * torrent ) { managerUnlock( torrent->manager ); } -static inline int +static TR_INLINE int torrentIsLocked( const Torrent * t ) { return tr_globalIsLocked( t->manager->session ); diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 3af9f2ba1..f0dca57ac 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -246,7 +246,7 @@ pokeBatchPeriod( tr_peermsgs * msgs, } } -static inline void +static TR_INLINE void dbgOutMessageLen( tr_peermsgs * msgs ) { dbgmsg( msgs, "outMessage size is now %zu", EVBUFFER_LENGTH( msgs->outMessages ) ); @@ -819,7 +819,7 @@ pumpRequestQueue( tr_peermsgs * msgs, const time_t now ) fireNeedReq( msgs ); } -static inline int +static TR_INLINE int requestQueueIsFull( const tr_peermsgs * msgs ) { const int req_max = msgs->maxActiveRequests; @@ -1506,7 +1506,7 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ) return READ_NOW; } -static inline void +static TR_INLINE void decrementDownloadedCount( tr_peermsgs * msgs, uint32_t byteCount ) { tr_torrent * tor = msgs->torrent; @@ -1514,7 +1514,7 @@ decrementDownloadedCount( tr_peermsgs * msgs, uint32_t byteCount ) tor->downloadedCur -= MIN( tor->downloadedCur, byteCount ); } -static inline void +static TR_INLINE void clientGotUnwantedBlock( tr_peermsgs * msgs, const struct peer_request * req ) { decrementDownloadedCount( msgs, req->length ); @@ -1882,7 +1882,7 @@ pexAddedCb( void * vpex, } } -static inline void +static TR_INLINE void pexDroppedCb( void * vpex, void * userData ) { @@ -1895,7 +1895,7 @@ pexDroppedCb( void * vpex, } } -static inline void +static TR_INLINE void pexElementCb( void * vpex, void * userData ) { @@ -2067,7 +2067,7 @@ sendPex( tr_peermsgs * msgs ) } } -static inline int +static TR_INLINE int pexPulse( void * vpeer ) { sendPex( vpeer ); diff --git a/libtransmission/platform.c b/libtransmission/platform.c index b6c5b5d79..b2412613d 100644 --- a/libtransmission/platform.c +++ b/libtransmission/platform.c @@ -239,7 +239,7 @@ getHomeDir( void ) #ifdef WIN32 char appdata[MAX_PATH]; /* SHGetFolderPath() requires MAX_PATH */ *appdata = '\0'; - SHGetFolderPath( NULL, CSIDL_MYDOCUMENTS, NULL, 0, appdata ); + SHGetFolderPath( NULL, CSIDL_PERSONAL, NULL, 0, appdata ); home = tr_strdup( appdata ); #else struct passwd * pw = getpwuid( getuid( ) ); diff --git a/libtransmission/ptrarray.h b/libtransmission/ptrarray.h index 72a376b71..8bc436742 100644 --- a/libtransmission/ptrarray.h +++ b/libtransmission/ptrarray.h @@ -66,13 +66,13 @@ void* tr_ptrArrayBack( tr_ptrArray * array ); void** tr_ptrArrayPeek( tr_ptrArray * array, int * size ); -static inline void tr_ptrArrayClear( tr_ptrArray * a ) { a->n_items = 0; } +static TR_INLINE void tr_ptrArrayClear( tr_ptrArray * a ) { a->n_items = 0; } int tr_ptrArrayInsert( tr_ptrArray * array, void * insertMe, int pos ); -static inline int tr_ptrArrayAppend( tr_ptrArray * array, void * appendMe ) +static TR_INLINE int tr_ptrArrayAppend( tr_ptrArray * array, void * appendMe ) { return tr_ptrArrayInsert( array, appendMe, -1 ); } @@ -83,17 +83,17 @@ void tr_ptrArrayErase( tr_ptrArray * array, int begin, int end ); -static inline void** tr_ptrArrayBase( const tr_ptrArray * a ) +static TR_INLINE void** tr_ptrArrayBase( const tr_ptrArray * a ) { return a->items; } -static inline int tr_ptrArraySize( const tr_ptrArray * a ) +static TR_INLINE int tr_ptrArraySize( const tr_ptrArray * a ) { return a->n_items; } -static inline tr_bool tr_ptrArrayEmpty( const tr_ptrArray * a ) +static TR_INLINE tr_bool tr_ptrArrayEmpty( const tr_ptrArray * a ) { return tr_ptrArraySize(a) == 0; } diff --git a/libtransmission/ratecontrol.h b/libtransmission/ratecontrol.h index d35705e4f..fc32e0f40 100644 --- a/libtransmission/ratecontrol.h +++ b/libtransmission/ratecontrol.h @@ -63,9 +63,9 @@ tr_ratecontrol; **** ***/ -static inline void tr_rcConstruct ( tr_ratecontrol * rc ) { memset( rc, 0, sizeof( tr_ratecontrol ) ); } +static TR_INLINE void tr_rcConstruct ( tr_ratecontrol * rc ) { memset( rc, 0, sizeof( tr_ratecontrol ) ); } -static inline void tr_rcDestruct ( tr_ratecontrol * rc ) { memset( rc, 0xDEAD, sizeof( tr_ratecontrol ) ); } +static TR_INLINE void tr_rcDestruct ( tr_ratecontrol * rc ) { memset( rc, 0xDEAD, sizeof( tr_ratecontrol ) ); } void tr_rcTransferred ( tr_ratecontrol * ratecontrol, size_t byteCount ); diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index b3859196a..3dbc5eaf0 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -377,7 +377,7 @@ struct RandomTracker /* the tiers will be sorted from lowest to highest, * and trackers are randomized within the tiers */ -static inline int +static TR_INLINE int compareRandomTracker( const void * va, const void * vb ) { @@ -653,7 +653,7 @@ tr_torrentChangeMyPort( tr_torrent * tor ) tr_trackerChangeMyPort( tor->tracker ); } -static inline void +static TR_INLINE void tr_torrentManualUpdateImpl( void * vtor ) { tr_torrent * tor = vtor; diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index e473b26cf..d69485cd9 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -196,21 +196,21 @@ struct tr_torrent }; /* get the index of this piece's first block */ -static inline tr_block_index_t +static TR_INLINE tr_block_index_t tr_torPieceFirstBlock( const tr_torrent * tor, const tr_piece_index_t piece ) { return piece * tor->blockCountInPiece; } /* what piece index is this block in? */ -static inline tr_piece_index_t +static TR_INLINE tr_piece_index_t tr_torBlockPiece( const tr_torrent * tor, const tr_block_index_t block ) { return block / tor->blockCountInPiece; } /* how many blocks are in this piece? */ -static inline uint32_t +static TR_INLINE uint32_t tr_torPieceCountBlocks( const tr_torrent * tor, const tr_piece_index_t piece ) { return piece == tor->info.pieceCount - 1 ? tor->blockCountInLastPiece @@ -218,7 +218,7 @@ tr_torPieceCountBlocks( const tr_torrent * tor, const tr_piece_index_t piece ) } /* how many bytes are in this piece? */ -static inline uint32_t +static TR_INLINE uint32_t tr_torPieceCountBytes( const tr_torrent * tor, const tr_piece_index_t piece ) { return piece == tor->info.pieceCount - 1 ? tor->lastPieceSize @@ -226,46 +226,46 @@ tr_torPieceCountBytes( const tr_torrent * tor, const tr_piece_index_t piece ) } /* how many bytes are in this block? */ -static inline uint32_t +static TR_INLINE uint32_t tr_torBlockCountBytes( const tr_torrent * tor, const tr_block_index_t block ) { return block == tor->blockCount - 1 ? tor->lastBlockSize : tor->blockSize; } -static inline void tr_torrentLock( const tr_torrent * tor ) +static TR_INLINE void tr_torrentLock( const tr_torrent * tor ) { tr_globalLock( tor->session ); } -static inline void tr_torrentUnlock( const tr_torrent * tor ) +static TR_INLINE void tr_torrentUnlock( const tr_torrent * tor ) { tr_globalUnlock( tor->session ); } -static inline tr_bool +static TR_INLINE tr_bool tr_torrentExists( const tr_session * session, const uint8_t * torrentHash ) { return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL; } -static inline tr_bool +static TR_INLINE tr_bool tr_torrentIsSeed( const tr_torrent * tor ) { return tor->completeness != TR_LEECH; } -static inline tr_bool tr_torrentIsPrivate( const tr_torrent * tor ) +static TR_INLINE tr_bool tr_torrentIsPrivate( const tr_torrent * tor ) { return ( tor != NULL ) && tor->info.isPrivate; } -static inline tr_bool tr_torrentAllowsPex( const tr_torrent * tor ) +static TR_INLINE tr_bool tr_torrentAllowsPex( const tr_torrent * tor ) { return ( tor != NULL ) && tor->session->isPexEnabled && !tr_torrentIsPrivate( tor ); } -static inline tr_bool tr_torrentIsPieceChecked( const tr_torrent * tor, tr_piece_index_t i ) +static TR_INLINE tr_bool tr_torrentIsPieceChecked( const tr_torrent * tor, tr_piece_index_t i ) { return tr_bitfieldHas( &tor->checkedPieces, i ); } diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 58ace7532..d36da10eb 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -50,8 +50,10 @@ extern "C" { #endif #include /* time_t */ -#if defined(_MSC_VER) && !defined( __cplusplus ) - #define inline __inline +#if defined( WIN32 ) && defined(_MSC_VER) + #define TR_INLINE __inline +#else + #define TR_INLINE inline #endif #define SHA_DIGEST_LENGTH 20 @@ -1422,10 +1424,10 @@ void tr_torrentSetDoneDate( tr_torrent * torrent, time_t doneDate ); /** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */ -static inline tr_bool tr_isDirection( tr_direction d ) { return d==TR_UP || d==TR_DOWN; } +static TR_INLINE tr_bool tr_isDirection( tr_direction d ) { return d==TR_UP || d==TR_DOWN; } /** @brief Sanity checker to test that a bool is TRUE or FALSE */ -static inline tr_bool tr_isBool( tr_bool b ) { return b==1 || b==0; } +static TR_INLINE tr_bool tr_isBool( tr_bool b ) { return b==1 || b==0; } /** @} */ diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 6a95fba23..2d5da3604 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -274,20 +274,20 @@ void tr_releaseBuffer( struct evbuffer * buf ); **** ***/ -static inline void* tr_malloc( size_t size ) +static TR_INLINE void* tr_malloc( size_t size ) { return size ? malloc( size ) : NULL; } -static inline void* tr_malloc0( size_t size ) +static TR_INLINE void* tr_malloc0( size_t size ) { return size ? calloc( 1, size ) : NULL; } -static inline void tr_free( void * p ) +static TR_INLINE void tr_free( void * p ) { if( p != NULL ) free( p ); } -static inline void* tr_memdup( const void * src, int byteCount ) +static TR_INLINE void* tr_memdup( const void * src, int byteCount ) { return memcpy( tr_malloc( byteCount ), src, byteCount ); } @@ -301,11 +301,13 @@ static inline void* tr_memdup( const void * src, int byteCount ) #define tr_renew( struct_type, mem, n_structs ) \ ( (struct_type *) realloc ( ( mem ), ( (size_t) sizeof ( struct_type ) ) * ( ( size_t) ( n_structs ) ) ) ) -char* tr_strndup( const void * str, int len ) TR_GNUC_MALLOC; +/** @param in is a void* so that callers can pass in both signed & unsigned without a cast */ +char* tr_strndup( const void * in, int len ) TR_GNUC_MALLOC; -static inline char* tr_strdup( const void * in ) +/** @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 ) { - return tr_strndup( in, in ? strlen( in ) : 0 ); + return tr_strndup( in, in ? strlen( (const char *) in ) : 0 ); } /* @brief same argument list as bsearch() */ @@ -387,12 +389,12 @@ tr_bitfield* tr_bitfieldConstruct( tr_bitfield*, size_t bitcount ); tr_bitfield* tr_bitfieldDestruct( tr_bitfield* ); -static inline tr_bitfield* tr_bitfieldNew( size_t bitcount ) +static TR_INLINE tr_bitfield* tr_bitfieldNew( size_t bitcount ) { return tr_bitfieldConstruct( tr_new0( tr_bitfield, 1 ), bitcount ); } -static inline void tr_bitfieldFree( tr_bitfield * b ) +static TR_INLINE void tr_bitfieldFree( tr_bitfield * b ) { tr_free( tr_bitfieldDestruct( b ) ); } @@ -422,20 +424,20 @@ tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* ); has none of tr_bitfieldHas()'s safety checks, so you need to call tr_bitfieldTestFast() first before you start looping. */ -static inline tr_bool tr_bitfieldHasFast( const tr_bitfield * b, const size_t nth ) +static TR_INLINE tr_bool tr_bitfieldHasFast( const tr_bitfield * b, const size_t nth ) { return ( b->bits[nth>>3u] << ( nth & 7u ) & 0x80 ) != 0; } /** @param high the highest nth bit you're going to access */ -static inline tr_bool tr_bitfieldTestFast( const tr_bitfield * b, const size_t high ) +static TR_INLINE tr_bool tr_bitfieldTestFast( const tr_bitfield * b, const size_t high ) { return ( b != NULL ) && ( b->bits != NULL ) && ( high < b->bitCount ); } -static inline tr_bool tr_bitfieldHas( const tr_bitfield * b, size_t nth ) +static TR_INLINE tr_bool tr_bitfieldHas( const tr_bitfield * b, size_t nth ) { return tr_bitfieldTestFast( b, nth ) && tr_bitfieldHasFast( b, nth ); }