1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-19 02:05:32 +00:00

uninteresting minor stuff like adding const. this commit is just to reduce the shear between trunk and what lands in the file-selection branch.

This commit is contained in:
Charles Kerr 2007-06-09 15:36:46 +00:00
parent 7b28aa2156
commit 3b8d1e13c4
11 changed files with 36 additions and 41 deletions

View file

@ -56,7 +56,7 @@ tr_choking_t * tr_chokingInit( tr_handle_t * h )
{
tr_choking_t * c;
c = calloc( sizeof( tr_choking_t ), 1 );
c = calloc( 1, sizeof( tr_choking_t ) );
c->h = h;
c->slots = 4242;
tr_lockInit( &c->lock );

View file

@ -162,7 +162,7 @@ void tr_cpDownloaderRem( tr_completion_t * cp, int block )
}
}
int tr_cpBlockIsComplete( tr_completion_t * cp, int block )
int tr_cpBlockIsComplete( const tr_completion_t * cp, int block )
{
return tr_bitfieldHas( cp->blockBitfield, block );
}
@ -257,9 +257,9 @@ float tr_cpPercentBlocksInPiece( tr_completion_t * cp, int piece )
return (float)complete / (float)blockCount;
}
int tr_cpMissingBlockInPiece( tr_completion_t * cp, int piece )
int tr_cpMissingBlockInPiece( const tr_completion_t * cp, int piece )
{
tr_torrent_t * tor = cp->tor;
const tr_torrent_t * tor = cp->tor;
int start, count, end, i;
start = tr_pieceStartBlock( piece );

View file

@ -54,17 +54,17 @@ void tr_cpPieceRem( tr_completion_t *, int piece );
/* Blocks */
void tr_cpDownloaderAdd( tr_completion_t *, int block );
void tr_cpDownloaderRem( tr_completion_t *, int block );
int tr_cpBlockIsComplete( tr_completion_t *, int block );
int tr_cpBlockIsComplete( const tr_completion_t *, int block );
void tr_cpBlockAdd( tr_completion_t *, int block );
void tr_cpBlockRem( tr_completion_t *, int block );
tr_bitfield_t * tr_cpBlockBitfield( tr_completion_t * );
void tr_cpBlockBitfieldSet( tr_completion_t *, tr_bitfield_t * );
float tr_cpPercentBlocksInPiece( tr_completion_t * cp, int piece );
/* Missing = we don't have it and we are not getting it from any peer yet */
static inline int tr_cpMissingBlocksForPiece( tr_completion_t * cp, int piece )
static inline int tr_cpMissingBlocksForPiece( const tr_completion_t * cp, int piece )
{
return cp->missingBlocks[piece];
}
int tr_cpMissingBlockInPiece( tr_completion_t *, int piece );
int tr_cpMissingBlockInPiece( const tr_completion_t *, int piece );
int tr_cpMostMissingBlockInPiece( tr_completion_t *, int piece,
int * downloaders );

View file

@ -67,7 +67,7 @@ static tr_fd_t * gFd = NULL;
/***********************************************************************
* Local prototypes
**********************************************************************/
static int OpenFile( int i, char * folder, char * name, int write );
static int OpenFile( int i, const char * folder, const char * name, int write );
static void CloseFile( int i );
@ -84,7 +84,7 @@ void tr_fdInit()
return;
}
gFd = calloc( sizeof( tr_fd_t ), 1 );
gFd = calloc( 1, sizeof( tr_fd_t ) );
/* Init lock and cond */
tr_lockInit( &gFd->lock );
@ -125,7 +125,7 @@ void tr_fdInit()
/***********************************************************************
* tr_fdFileOpen
**********************************************************************/
int tr_fdFileOpen( char * folder, char * name, int write )
int tr_fdFileOpen( const char * folder, const char * name, int write )
{
int i, winner, ret;
uint64_t date;
@ -241,7 +241,7 @@ void tr_fdFileRelease( int file )
/***********************************************************************
* tr_fdFileClose
**********************************************************************/
void tr_fdFileClose( char * folder, char * name )
void tr_fdFileClose( const char * folder, const char * name )
{
int i;
@ -410,11 +410,11 @@ void tr_fdClose()
***********************************************************************
*
**********************************************************************/
static int OpenFile( int i, char * folder, char * name, int write )
static int OpenFile( int i, const char * folder, const char * name, int write )
{
tr_openFile_t * file = &gFd->open[i];
struct stat sb;
char * path;
char path[MAX_PATH_LENGTH];
int ret;
tr_dbg( "Opening %s in %s (%d)", name, folder, write );
@ -425,7 +425,7 @@ static int OpenFile( int i, char * folder, char * name, int write )
return TR_ERROR_IO_PARENT;
}
asprintf( &path, "%s/%s", folder, name );
snprintf( path, sizeof(path), "%s/%s", folder, name );
/* Create subfolders, if any */
if( write )
@ -442,7 +442,6 @@ static int OpenFile( int i, char * folder, char * name, int write )
{
ret = tr_ioErrorFromErrno();
tr_err( "Could not create folder '%s'", path );
free( path );
return ret;
}
}
@ -451,7 +450,6 @@ static int OpenFile( int i, char * folder, char * name, int write )
if( !S_ISDIR( sb.st_mode ) )
{
tr_err( "Is not a folder: '%s'", path );
free( path );
return TR_ERROR_IO_OTHER;
}
}
@ -465,11 +463,9 @@ static int OpenFile( int i, char * folder, char * name, int write )
if( file->file < 0 )
{
ret = tr_ioErrorFromErrno();
free( path );
tr_err( "Could not open %s in %s (%d, %d)", name, folder, write, ret );
return ret;
}
free( path );
return TR_OK;
}

View file

@ -39,7 +39,7 @@ void tr_fdInit();
* Returns the file descriptor if successful, otherwise returns
* one of the TR_ERROR_IO_*.
**********************************************************************/
int tr_fdFileOpen( char * folder, char * name, int write );
int tr_fdFileOpen( const char * folder, const char * name, int write );
/***********************************************************************
* tr_fdFileRelease
@ -55,7 +55,7 @@ void tr_fdFileRelease( int file );
* If the file 'name' in directory 'folder' was open, closes it,
* flushing data on disk.
**********************************************************************/
void tr_fdFileClose( char * folder, char * name );
void tr_fdFileClose( const char * folder, const char * name );
/***********************************************************************
* Sockets

View file

@ -735,7 +735,7 @@ void tr_peerBlame( tr_peer_t * peer, int piece, int success )
tr_bitfieldRem( peer->blamefield, piece );
}
int tr_peerGetConnectable( tr_torrent_t * tor, uint8_t ** _buf )
int tr_peerGetConnectable( const tr_torrent_t * tor, uint8_t ** _buf )
{
int count = 0;
uint8_t * buf;

View file

@ -57,6 +57,6 @@ void tr_peerSetOptimistic ( tr_peer_t *, int );
int tr_peerIsOptimistic ( tr_peer_t * );
void tr_peerBlame ( tr_peer_t *, int piece, int success );
struct in_addr * tr_peerAddress ( tr_peer_t * );
int tr_peerGetConnectable( tr_torrent_t *, uint8_t ** );
int tr_peerGetConnectable( const tr_torrent_t *, uint8_t ** );
#endif

View file

@ -75,7 +75,7 @@ tr_ratecontrol_t * tr_rcInit()
{
tr_ratecontrol_t * r;
r = calloc( sizeof( tr_ratecontrol_t ), 1 );
r = calloc( 1, sizeof( tr_ratecontrol_t ) );
r->limit = -1;
tr_lockInit( &r->lock );

View file

@ -629,7 +629,7 @@ static void readAnswer( tr_tracker_t * tc, const char * data, int len,
tr_httpParse( data, len, hdr );
address = calloc( sizeof( char ), hdr->len+1 );
address = calloc( hdr->len+1, sizeof( char ) );
snprintf( address, hdr->len+1, "%s", hdr->data );
tc->shouldChangeAnnounce = TC_CHANGE_REDIRECT;
@ -871,7 +871,7 @@ static void readScrapeAnswer( tr_tracker_t * tc, const char * data, int len )
tr_httpParse( data, len, hdr );
address = calloc( sizeof( char ), hdr->len+1 );
address = calloc( hdr->len+1, sizeof( char ) );
snprintf( address, hdr->len+1, "%s", hdr->data );
/* Needs a new scrape */

View file

@ -38,7 +38,7 @@ tr_handle_t * tr_init( const char * tag )
tr_msgInit();
tr_netResolveThreadInit();
h = calloc( sizeof( tr_handle_t ), 1 );
h = calloc( 1, sizeof( tr_handle_t ) );
if( NULL == h )
{
return NULL;
@ -180,4 +180,3 @@ void tr_close( tr_handle_t * h )
tr_netResolveThreadClose();
}

View file

@ -169,16 +169,16 @@ static inline void tr_bitfieldRem( tr_bitfield_t * bitfield, int piece )
}
#define tr_blockPiece(a) _tr_blockPiece(tor,a)
static inline int _tr_blockPiece( tr_torrent_t * tor, int block )
static inline int _tr_blockPiece( const tr_torrent_t * tor, int block )
{
tr_info_t * inf = &tor->info;
const tr_info_t * inf = &tor->info;
return block / ( inf->pieceSize / tor->blockSize );
}
#define tr_blockSize(a) _tr_blockSize(tor,a)
static inline int _tr_blockSize( tr_torrent_t * tor, int block )
static inline int _tr_blockSize( const tr_torrent_t * tor, int block )
{
tr_info_t * inf = &tor->info;
const tr_info_t * inf = &tor->info;
int dummy;
if( block != tor->blockCount - 1 ||
@ -191,17 +191,17 @@ static inline int _tr_blockSize( tr_torrent_t * tor, int block )
}
#define tr_blockPosInPiece(a) _tr_blockPosInPiece(tor,a)
static inline int _tr_blockPosInPiece( tr_torrent_t * tor, int block )
static inline int _tr_blockPosInPiece( const tr_torrent_t * tor, int block )
{
tr_info_t * inf = &tor->info;
const tr_info_t * inf = &tor->info;
return tor->blockSize *
( block % ( inf->pieceSize / tor->blockSize ) );
}
#define tr_pieceCountBlocks(a) _tr_pieceCountBlocks(tor,a)
static inline int _tr_pieceCountBlocks( tr_torrent_t * tor, int piece )
static inline int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece )
{
tr_info_t * inf = &tor->info;
const tr_info_t * inf = &tor->info;
if( piece < inf->pieceCount - 1 ||
!( tor->blockCount % ( inf->pieceSize / tor->blockSize ) ) )
{
@ -211,16 +211,16 @@ static inline int _tr_pieceCountBlocks( tr_torrent_t * tor, int piece )
}
#define tr_pieceStartBlock(a) _tr_pieceStartBlock(tor,a)
static inline int _tr_pieceStartBlock( tr_torrent_t * tor, int piece )
static inline int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece )
{
tr_info_t * inf = &tor->info;
const tr_info_t * inf = &tor->info;
return piece * ( inf->pieceSize / tor->blockSize );
}
#define tr_pieceSize(a) _tr_pieceSize(tor,a)
static inline int _tr_pieceSize( tr_torrent_t * tor, int piece )
static inline int _tr_pieceSize( const tr_torrent_t * tor, int piece )
{
tr_info_t * inf = &tor->info;
const tr_info_t * inf = &tor->info;
if( piece < inf->pieceCount - 1 ||
!( inf->totalSize % inf->pieceSize ) )
{
@ -230,9 +230,9 @@ static inline int _tr_pieceSize( tr_torrent_t * tor, int piece )
}
#define tr_block(a,b) _tr_block(tor,a,b)
static inline int _tr_block( tr_torrent_t * tor, int index, int begin )
static inline int _tr_block( const tr_torrent_t * tor, int index, int begin )
{
tr_info_t * inf = &tor->info;
const tr_info_t * inf = &tor->info;
return index * ( inf->pieceSize / tor->blockSize ) +
begin / tor->blockSize;
}