From 4d228289ced1c7c717469d32d228128da1dd2a16 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 19 Jan 2009 14:05:43 +0000 Subject: [PATCH] (trunk libT) prefer `int' over `ssize_t' --- libtransmission/ConvertUTF.c | 3 +-- libtransmission/ConvertUTF.h | 4 +--- libtransmission/bandwidth.c | 6 +++--- libtransmission/peer-io.c | 30 +++++++++++++++--------------- libtransmission/peer-io.h | 4 ++-- libtransmission/rpcimpl.c | 6 +++--- libtransmission/rpcimpl.h | 8 +++----- libtransmission/utils-test.c | 1 - libtransmission/utils.c | 8 ++++---- libtransmission/utils.h | 4 ++-- 10 files changed, 34 insertions(+), 40 deletions(-) diff --git a/libtransmission/ConvertUTF.c b/libtransmission/ConvertUTF.c index 1a45f2a00..66f6990f1 100644 --- a/libtransmission/ConvertUTF.c +++ b/libtransmission/ConvertUTF.c @@ -43,7 +43,6 @@ #include #endif #include /* strlen() */ -#include /* ssize_t */ #include "ConvertUTF.h" static const int halfShift = 10; /* used for shifting by 10 bits */ @@ -351,7 +350,7 @@ Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) { * In addition to knowing if the sequence is legal, it also tells you the last good character. */ Boolean -tr_utf8_validate( const char * str, ssize_t max_len, const char ** end ) +tr_utf8_validate( const char * str, int max_len, const char ** end ) { const UTF8* source = (const UTF8*) str; const UTF8* sourceEnd = source; diff --git a/libtransmission/ConvertUTF.h b/libtransmission/ConvertUTF.h index 4b6ab4641..3fb616506 100644 --- a/libtransmission/ConvertUTF.h +++ b/libtransmission/ConvertUTF.h @@ -5,8 +5,6 @@ #error only libtransmission should #include this header. #endif -#include /* ssize_t */ - /* * Copyright 2001-2004 Unicode, Inc. * @@ -153,7 +151,7 @@ Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd); /* intended to work the same as g_utf8_validate */ -Boolean tr_utf8_validate( const char * str, ssize_t max_len, const char ** end ); +Boolean tr_utf8_validate( const char * str, int max_len, const char ** end ); #ifdef __cplusplus diff --git a/libtransmission/bandwidth.c b/libtransmission/bandwidth.c index e0bba899b..a584ee3ea 100644 --- a/libtransmission/bandwidth.c +++ b/libtransmission/bandwidth.c @@ -223,11 +223,11 @@ tr_bandwidthAllocate( tr_bandwidth * b, while( n > 1 ) { const size_t increment = 1024; - const ssize_t bytesUsed = tr_peerIoFlush( peers[i], dir, increment ); + const int bytesUsed = tr_peerIoFlush( peers[i], dir, increment ); - dbgmsg( "peer #%d of %d used %zd bytes in this pass", i, n, bytesUsed ); + dbgmsg( "peer #%d of %d used %d bytes in this pass", i, n, bytesUsed ); - if( bytesUsed == (ssize_t)increment ) + if( bytesUsed == (int)increment ) ++i; else { /* peer is done writing for now; move it to the end of the list */ diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index ad694de35..4409ced06 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -236,23 +236,23 @@ event_read_cb( int fd, short event UNUSED, void * vio ) } } -static ssize_t +static int tr_evbuffer_write( tr_peerIo * io, int fd, size_t howmuch ) { int e; - ssize_t n; + int n; struct evbuffer * buffer = io->outbuf; howmuch = MIN( EVBUFFER_LENGTH( buffer ), howmuch ); errno = 0; #ifdef WIN32 - n = send(fd, buffer->buffer, howmuch, 0 ); + n = (int) send(fd, buffer->buffer, howmuch, 0 ); #else - n = write(fd, buffer->buffer, howmuch ); + n = (int) write(fd, buffer->buffer, howmuch ); #endif e = errno; - dbgmsg( io, "wrote %zd to peer (%s)", n, (n==-1?strerror(e):"") ); + dbgmsg( io, "wrote %d to peer (%s)", n, (n==-1?strerror(e):"") ); if( n > 0 ) evbuffer_drain( buffer, n ); @@ -762,10 +762,10 @@ tr_peerIoDrain( tr_peerIo * io, **** ***/ -static ssize_t +static int tr_peerIoTryRead( tr_peerIo * io, size_t howmuch ) { - ssize_t res = 0; + int res = 0; if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_DOWN, howmuch ))) { @@ -774,7 +774,7 @@ tr_peerIoTryRead( tr_peerIo * io, size_t howmuch ) res = evbuffer_read( io->inbuf, io->socket, howmuch ); e = errno; - dbgmsg( io, "read %zd from peer (%s)", res, (res==-1?strerror(e):"") ); + dbgmsg( io, "read %d from peer (%s)", res, (res==-1?strerror(e):"") ); if( EVBUFFER_LENGTH( io->inbuf ) ) canReadWrapper( io ); @@ -784,7 +784,7 @@ tr_peerIoTryRead( tr_peerIo * io, size_t howmuch ) short what = EVBUFFER_READ | EVBUFFER_ERROR; if( res == 0 ) what |= EVBUFFER_EOF; - dbgmsg( io, "tr_peerIoTryRead got an error. res is %zd, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) ); + dbgmsg( io, "tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)", res, what, e, strerror( e ) ); io->gotError( io, what, io->userData ); } } @@ -792,10 +792,10 @@ tr_peerIoTryRead( tr_peerIo * io, size_t howmuch ) return res; } -static ssize_t +static int tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch ) { - ssize_t n = 0; + int n = 0; if(( howmuch = tr_bandwidthClamp( &io->bandwidth, TR_UP, howmuch ))) { @@ -810,7 +810,7 @@ tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch ) if( ( n < 0 ) && ( io->gotError ) && ( e != EPIPE ) && ( e != EAGAIN ) && ( e != EINTR ) && ( e != EINPROGRESS ) ) { const short what = EVBUFFER_WRITE | EVBUFFER_ERROR; - dbgmsg( io, "tr_peerIoTryWrite got an error. res is %zd, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) ); + dbgmsg( io, "tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)", n, what, e, strerror( e ) ); io->gotError( io, what, io->userData ); } } @@ -818,10 +818,10 @@ tr_peerIoTryWrite( tr_peerIo * io, size_t howmuch ) return n; } -ssize_t +int tr_peerIoFlush( tr_peerIo * io, tr_direction dir, size_t limit ) { - ssize_t bytesUsed; + int bytesUsed; assert( tr_isPeerIo( io ) ); assert( tr_isDirection( dir ) ); @@ -834,7 +834,7 @@ tr_peerIoFlush( tr_peerIo * io, tr_direction dir, size_t limit ) bytesUsed = tr_peerIoTryWrite( io, limit ); } - dbgmsg( io, "flushing peer-io, direction %d, limit %zu, bytesUsed %zd", (int)dir, limit, bytesUsed ); + dbgmsg( io, "flushing peer-io, direction %d, limit %zu, bytesUsed %d", (int)dir, limit, bytesUsed ); return bytesUsed; } diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index eefeae47d..f5fa28cdb 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -76,7 +76,7 @@ typedef struct tr_peerIo tr_port port; int socket; - ssize_t refCount; + int refCount; uint8_t peerId[SHA_DIGEST_LENGTH]; time_t timeCreated; @@ -360,7 +360,7 @@ void tr_peerIoSetEnabled( tr_peerIo * io, tr_direction dir, tr_bool isEnabled ); -ssize_t tr_peerIoFlush( tr_peerIo * io, +int tr_peerIoFlush( tr_peerIo * io, tr_direction dir, size_t byteLimit ); diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 85f1ed069..727ac1f66 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -980,7 +980,7 @@ request_exec( tr_session * session, void tr_rpc_request_exec_json( tr_session * session, const void * request_json, - ssize_t request_len, + int request_len, tr_rpc_response_func callback, void * callback_user_data ) { @@ -1032,7 +1032,7 @@ addToken( tr_benc * list, void tr_rpc_parse_list_str( tr_benc * setme, const char * str_in, - ssize_t len ) + int len ) { char * str = tr_strndup( str_in, len ); @@ -1079,7 +1079,7 @@ tr_rpc_parse_list_str( tr_benc * setme, void tr_rpc_request_exec_uri( tr_session * session, const void * request_uri, - ssize_t request_len, + int request_len, tr_rpc_response_func callback, void * callback_user_data ) { diff --git a/libtransmission/rpcimpl.h b/libtransmission/rpcimpl.h index 1b67c92ac..c8b3f1caf 100644 --- a/libtransmission/rpcimpl.h +++ b/libtransmission/rpcimpl.h @@ -13,8 +13,6 @@ #ifndef TR_RPC_H #define TR_RPC_H -#include /* ssize_t */ - /*** **** RPC processing ***/ @@ -28,20 +26,20 @@ typedef void( tr_rpc_response_func )( tr_session * session, /* http://www.json.org/ */ void tr_rpc_request_exec_json( tr_session * session, const void * request_json, - ssize_t request_len, + int request_len, tr_rpc_response_func callback, void * callback_user_data ); /* see the RPC spec's "Request URI Notation" section */ void tr_rpc_request_exec_uri( tr_session * session, const void * request_uri, - ssize_t request_len, + int request_len, tr_rpc_response_func callback, void * callback_user_data ); void tr_rpc_parse_list_str( struct tr_benc * setme, const char * list_str, - ssize_t list_str_len ); + int list_str_len ); #endif diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index 76ef6d21d..f053dac2e 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -1,7 +1,6 @@ #include /* fprintf */ #include /* strcmp */ #include "transmission.h" -#include /* ssize_t */ #include "ConvertUTF.h" /* tr_utf8_validate*/ #include "platform.h" #include "utils.h" diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 59abc0c12..72e37c501 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -637,7 +637,7 @@ tr_buildPath( const char *first_element, ... ) ****/ char* -tr_strndup( const void * in, ssize_t len ) +tr_strndup( const void * in, int len ) { char * out = NULL; @@ -1325,7 +1325,7 @@ tr_lowerBound( const void * key, ***/ char* -tr_utf8clean( const char * str, ssize_t max_len, tr_bool * err ) +tr_utf8clean( const char * str, int max_len, tr_bool * err ) { const char zero = '\0'; char * ret; @@ -1336,11 +1336,11 @@ tr_utf8clean( const char * str, ssize_t max_len, tr_bool * err ) *err = FALSE; if( max_len < 0 ) - max_len = (ssize_t) strlen( str ); + max_len = (int) strlen( str ); while( !tr_utf8_validate ( str, max_len, &end ) ) { - const ssize_t good_len = end - str; + const int good_len = end - str; evbuffer_add( buf, str, good_len ); max_len -= ( good_len + 1 ); diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 0e6eec9ae..f7e53fb81 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -238,7 +238,7 @@ uint64_t tr_date( void ); void tr_wait( uint64_t delay_milliseconds ); char* tr_utf8clean( const char * str, - ssize_t max_len, + int max_len, tr_bool * err ); @@ -302,7 +302,7 @@ static TR_INLINE void* tr_memdup( const void * src, int byteCount ) ( (struct_type *) realloc ( ( mem ), ( (size_t) sizeof ( struct_type ) ) * ( ( size_t) ( n_structs ) ) ) ) /** @param in is a void* so that callers can pass in both signed & unsigned without a cast */ -char* tr_strndup( const void * in, ssize_t len ) TR_GNUC_MALLOC; +char* tr_strndup( const void * in, int len ) TR_GNUC_MALLOC; /** @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 )