Changeset 6896
- Timestamp:
- Oct 14, 2008, 3:03:29 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/daemon.c
r6892 r6896 32 32 static int closing = FALSE; 33 33 static tr_handle * mySession; 34 static char myConfigFilename[MAX_PATH_LENGTH];34 static char * myConfigFilename = NULL; 35 35 36 36 #define KEY_BLOCKLIST "blocklist-enabled" … … 478 478 &rpcPort, &whitelist, &authRequired, &username, &password, 479 479 &blocklistEnabled ); 480 if( configDir == NULL)480 if( configDir ) 481 481 configDir = freeme = tr_strdup_printf( "%s-daemon", 482 482 tr_getDefaultConfigDir( ) ); 483 tr_buildPath( myConfigFilename, sizeof( myConfigFilename ), 484 configDir, CONFIG_FILE, NULL ); 483 myConfigFilename = tr_buildPath( configDir, CONFIG_FILE, NULL ); 485 484 486 485 if( !nofork ) … … 506 505 507 506 tr_free( freeme ); 507 tr_free( myConfigFilename ); 508 508 return 0; 509 509 } -
trunk/daemon/remote.c
r6892 r6896 145 145 146 146 static char* 147 absolutify( c har * buf,148 size_t len, 149 const char * path )150 { 147 absolutify( const char * path ) 148 { 149 char * buf; 150 151 151 if( *path == '/' ) 152 tr_strlcpy( buf, path, len ); 153 else 154 { 152 buf = tr_strdup( path ); 153 else { 155 154 char cwd[MAX_PATH_LENGTH]; 156 155 tr_getcwd( cwd, sizeof( cwd ) ); 157 tr_buildPath( buf, len, cwd, path, NULL ); 158 } 156 buf = tr_buildPath( cwd, path, NULL ); 157 } 158 159 159 return buf; 160 160 } … … 273 273 { 274 274 int i, n; 275 char buf[MAX_PATH_LENGTH];276 275 int addArg = TRUE; 277 276 tr_benc top, *args, *fields; … … 422 421 break; 423 422 424 case 'w': 425 tr_bencDictAddStr( &top, "method", "session-set" ); 426 tr_bencDictAddStr( args, "download-dir", 427 absolutify( buf, sizeof( buf ), optarg ) ); 428 break; 423 case 'w': { 424 char * path = absolutify( optarg ); 425 tr_bencDictAddStr( &top, "method", "session-set" ); 426 tr_bencDictAddStr( args, "download-dir", path ); 427 tr_free( path ); 428 break; 429 } 429 430 430 431 case 'x': -
trunk/libtransmission/fastresume.c
r6840 r6896 122 122 #define FR_SPEED_LEN ( 2 * ( sizeof( uint16_t ) + sizeof( uint8_t ) ) ) 123 123 124 #if 0125 static void126 fastResumeFileName( char * buf,127 size_t buflen,128 const tr_torrent * tor,129 int tag )130 {131 const char * cacheDir = tr_getResumeDir( tor->handle );132 const char * hash = tor->info.hashString;133 134 if( !tag )135 {136 tr_buildPath( buf, buflen, cacheDir, hash, NULL );137 }138 else139 {140 char base[1024];141 tr_snprintf( base, sizeof( base ), "%s-%s", hash, tor->handle->tag );142 tr_buildPath( buf, buflen, cacheDir, base, NULL );143 }144 }145 146 #endif147 148 124 static tr_time_t* 149 125 getMTimes( const tr_torrent * tor, … … 156 132 for( i = 0; i < n; ++i ) 157 133 { 158 char fname[MAX_PATH_LENGTH];159 134 struct stat sb; 160 tr_buildPath( fname, sizeof( fname ), 161 tor->downloadDir, tor->info.files[i].name, NULL ); 135 char * fname = tr_buildPath( tor->downloadDir, tor->info.files[i].name, NULL ); 162 136 if( !stat( fname, &sb ) && S_ISREG( sb.st_mode ) ) 163 137 { … … 168 142 #endif 169 143 } 144 tr_free( fname ); 170 145 } 171 146 … … 173 148 return m; 174 149 } 175 176 #if 0177 static void178 fastResumeWriteData( uint8_t id,179 const void * data,180 uint32_t size,181 uint32_t count,182 FILE * file )183 {184 uint32_t datalen = size * count;185 186 fwrite( &id, 1, 1, file );187 fwrite( &datalen, 4, 1, file );188 fwrite( data, size, count, file );189 }190 191 void192 tr_fastResumeSave( const tr_torrent * tor )193 {194 char path[MAX_PATH_LENGTH];195 FILE * file;196 const int version = 1;197 uint64_t total;198 199 fastResumeFileName( path, sizeof path, tor, 1 );200 file = fopen( path, "wb+" );201 if( !file )202 {203 tr_torerr( tor, _(204 "Couldn't open \"%1$s\": %2$s" ), path,205 tr_strerror( errno ) );206 return;207 }208 209 /* Write format version */210 fwrite( &version, 4, 1, file );211 212 if( TRUE ) /* FR_ID_DOWNLOAD_DIR */213 {214 const char * d = tor->downloadDir ? tor->downloadDir : "";215 const int byteCount = strlen( d ) + 1;216 fastResumeWriteData( FR_ID_DOWNLOAD_DIR, d, 1, byteCount, file );217 }218 219 /* Write progress data */220 {221 int i, n;222 tr_time_t * mtimes;223 uint8_t * buf = malloc( FR_PROGRESS_LEN( tor ) );224 uint8_t * walk = buf;225 const tr_bitfield * bitfield;226 227 /* mtimes */228 mtimes = getMTimes( tor, &n );229 for( i = 0; i < n; ++i )230 if( !tr_torrentIsFileChecked( tor, i ) )231 mtimes[i] = ~(tr_time_t)0; /* force a recheck next time */232 memcpy( walk, mtimes, n * sizeof( tr_time_t ) );233 walk += n * sizeof( tr_time_t );234 235 /* completion bitfield */236 bitfield = tr_cpBlockBitfield( tor->completion );237 assert( (unsigned)FR_BLOCK_BITFIELD_LEN( tor ) == bitfield->len );238 memcpy( walk, bitfield->bits, bitfield->len );239 walk += bitfield->len;240 241 /* write it */242 assert( walk - buf == (int)FR_PROGRESS_LEN( tor ) );243 fastResumeWriteData( FR_ID_PROGRESS, buf, 1, walk - buf, file );244 245 /* cleanup */246 free( mtimes );247 free( buf );248 }249 250 251 /* Write the priorities and DND flags */252 if( TRUE )253 {254 int i;255 const int n = tor->info.fileCount;256 char * buf = tr_new0( char, n * 2 );257 char * walk = buf;258 259 /* priorities */260 for( i = 0; i < n; ++i )261 {262 char ch;263 const int priority = tor->info.files[i].priority;264 switch( priority )265 {266 case TR_PRI_LOW:267 ch = 'l'; break; /* low */268 269 case TR_PRI_HIGH:270 ch = 'h'; break; /* high */271 272 default:273 ch = 'n'; break; /* normal */274 }275 *walk++ = ch;276 }277 278 /* dnd flags */279 for( i = 0; i < n; ++i )280 *walk++ = tor->info.files[i].dnd ? 't' : 'f';281 282 /* write it */283 assert( walk - buf == 2 * n );284 fastResumeWriteData( FR_ID_PRIORITY, buf, 1, walk - buf, file );285 286 /* cleanup */287 tr_free( buf );288 }289 290 291 /* Write the torrent ul/dl speed caps */292 if( TRUE )293 {294 const int len = FR_SPEED_LEN;295 char * buf = tr_new0( char, len );296 char * walk = buf;297 uint16_t i16;298 uint8_t i8;299 300 i16 = (uint16_t) tr_torrentGetSpeedLimit( tor, TR_DOWN );301 memcpy( walk, &i16, 2 ); walk += 2;302 i8 = (uint8_t) tr_torrentGetSpeedMode( tor, TR_DOWN );303 memcpy( walk, &i8, 1 ); walk += 1;304 i16 = (uint16_t) tr_torrentGetSpeedLimit( tor, TR_UP );305 memcpy( walk, &i16, 2 ); walk += 2;306 i8 = (uint8_t) tr_torrentGetSpeedMode( tor, TR_UP );307 memcpy( walk, &i8, 1 ); walk += 1;308 309 assert( walk - buf == len );310 fastResumeWriteData( FR_ID_SPEED, buf, 1, walk - buf, file );311 tr_free( buf );312 }313 314 if( TRUE ) /* FR_ID_RUN */315 {316 const char is_running = tor->isRunning ? 't' : 'f';317 fastResumeWriteData( FR_ID_RUN, &is_running, 1, 1, file );318 }319 320 /* Write download and upload totals */321 322 total = tor->downloadedCur + tor->downloadedPrev;323 fastResumeWriteData( FR_ID_DOWNLOADED, &total, 8, 1, file );324 325 total = tor->uploadedCur + tor->uploadedPrev;326 fastResumeWriteData( FR_ID_UPLOADED, &total, 8, 1, file );327 328 total = tor->corruptCur + tor->corruptPrev;329 fastResumeWriteData( FR_ID_CORRUPT, &total, 8, 1, file );330 331 fastResumeWriteData( FR_ID_MAX_PEERS,332 &tor->maxConnectedPeers,333 sizeof( uint16_t ), 1, file );334 335 if( !tor->info.isPrivate )336 {337 tr_pex * pex;338 const int count = tr_peerMgrGetPeers( tor->handle->peerMgr,339 tor->info.hash,340 &pex );341 if( count > 0 )342 fastResumeWriteData( FR_ID_PEERS, pex, sizeof( tr_pex ), count,343 file );344 tr_free( pex );345 }346 347 fclose( file );348 }349 350 #endif351 150 352 151 /*** … … 712 511 { 713 512 uint8_t * ret = NULL; 714 char path[MAX_PATH_LENGTH];715 513 const char * cacheDir = tr_getResumeDir( tor->session ); 716 514 const char * hash = tor->info.hashString; … … 718 516 if( !ret && tor->session->tag ) 719 517 { 720 char base[1024]; 721 tr_snprintf( base, sizeof( base ), "%s-%s", hash, tor->session->tag ); 722 tr_buildPath( path, sizeof( path ), cacheDir, base, NULL ); 518 char * path = tr_strdup_printf( "%s" TR_PATH_DELIMITER_STR "%s-%s", cacheDir, hash, tor->session->tag ); 723 519 ret = tr_loadFile( path, len ); 724 }725 520 tr_free( path ); 521 } 726 522 if( !ret ) 727 523 { 728 tr_buildPath( path, sizeof( path ),cacheDir, hash, NULL );524 char * path = tr_buildPath( cacheDir, hash, NULL ); 729 525 ret = tr_loadFile( path, len ); 526 tr_free( path ); 730 527 } 731 528 … … 775 572 tr_fastResumeRemove( const tr_torrent * tor ) 776 573 { 777 char path[MAX_PATH_LENGTH];778 574 const char * cacheDir = tr_getResumeDir( tor->session ); 779 575 const char * hash = tor->info.hashString; … … 781 577 if( tor->session->tag ) 782 578 { 783 char base[1024]; 784 tr_snprintf( base, sizeof( base ), "%s-%s", hash, tor->session->tag ); 785 tr_buildPath( path, sizeof( path ), cacheDir, base, NULL ); 579 char * path = tr_strdup_printf( "%s" TR_PATH_DELIMITER_STR "%s-%s", cacheDir, hash, tor->session->tag ); 786 580 unlink( path ); 581 tr_free( path ); 787 582 } 788 583 else 789 584 { 790 tr_buildPath( path, sizeof( path ),cacheDir, hash, NULL );585 char * path = tr_buildPath( cacheDir, hash, NULL ); 791 586 unlink( path ); 792 } 793 } 794 587 tr_free( path ); 588 } 589 } 590 -
trunk/libtransmission/fdlimit.c
r6893 r6896 114 114 struct tr_openfile * file = &gFd->open[i]; 115 115 int flags; 116 char filename[MAX_PATH_LENGTH];116 char * filename; 117 117 struct stat sb; 118 118 … … 122 122 123 123 /* create subfolders, if any */ 124 tr_buildPath ( filename, sizeof( filename ),folder, torrentFile, NULL );124 filename = tr_buildPath( folder, torrentFile, NULL ); 125 125 if( write ) 126 126 { … … 128 128 const int err = tr_mkdirp( dirname( tmp ), 0777 ) ? errno : 0; 129 129 tr_free( tmp ); 130 tr_free( filename ); 130 131 if( err ) 131 132 return err; … … 146 147 tr_err( _( "Couldn't open \"%1$s\": %2$s" ), filename, 147 148 tr_strerror( err ) ); 149 tr_free( filename ); 148 150 return err; 149 151 } 150 152 153 tr_free( filename ); 151 154 return 0; 152 155 } … … 186 189 int i, winner = -1; 187 190 struct tr_openfile * o; 188 char filename[MAX_PATH_LENGTH];191 char * filename; 189 192 190 193 assert( folder && *folder ); … … 192 195 assert( write == 0 || write == 1 ); 193 196 194 tr_buildPath ( filename, sizeof( filename ),folder, torrentFile, NULL );197 filename = tr_buildPath( folder, torrentFile, NULL ); 195 198 dbgmsg( "looking for file '%s', writable %c", filename, 196 199 write ? 'y' : 'n' ); … … 284 287 if( err ) { 285 288 tr_lockUnlock( gFd->lock ); 289 tr_free( filename ); 286 290 errno = err; 287 291 return -1; … … 298 302 o->closeWhenDone = 0; 299 303 o->date = tr_date( ); 304 tr_free( filename ); 300 305 tr_lockUnlock( gFd->lock ); 301 306 return o->fd; -
trunk/libtransmission/inout.c
r6894 r6896 58 58 iofunc func = ioMode == 59 59 TR_IO_READ ? (iofunc)read : (iofunc)write; 60 char path[MAX_PATH_LENGTH];60 char * path; 61 61 struct stat sb; 62 62 int fd = -1; … … 68 68 assert( fileOffset + buflen <= file->length ); 69 69 70 tr_buildPath ( path, sizeof( path ),tor->downloadDir, file->name, NULL );70 path = tr_buildPath( tor->downloadDir, file->name, NULL ); 71 71 fileExists = !stat( path, &sb ); 72 tr_free( path ); 72 73 73 74 if( !file->length ) -
trunk/libtransmission/makemeta.c
r6808 r6896 48 48 { 49 49 int i; 50 char buf[MAX_PATH_LENGTH];50 char * buf; 51 51 struct stat sb; 52 52 DIR * odir = NULL; … … 54 54 sb.st_size = 0; 55 55 56 tr_buildPath( buf, sizeof( buf ),dir, base, NULL );56 buf = tr_buildPath( dir, base, NULL ); 57 57 i = stat( buf, &sb ); 58 58 if( i ) 59 59 { 60 tr_err( _( 61 "Torrent Creator is skipping file \"%s\": %s" ), buf,62 tr_strerror( errno ));60 tr_err( _( "Torrent Creator is skipping file \"%s\": %s" ), 61 buf, tr_strerror( errno ) ); 62 tr_free( buf ); 63 63 return list; 64 64 } … … 84 84 } 85 85 86 tr_free( buf ); 86 87 return list; 87 88 } -
trunk/libtransmission/platform.c
r6892 r6896 296 296 if( !path ) 297 297 { 298 #ifdef __BEOS__ 298 299 char buf[MAX_PATH_LENGTH]; 299 #ifdef __BEOS__300 300 find_directory( B_USER_SETTINGS_DIRECTORY, 301 301 dev_for_path( "/boot" ), true, 302 302 buf, sizeof( buf ) ); 303 strcat( buf, "/Transmission");303 path = tr_buildPath( buf, "Transmission", NULL ); 304 304 #elif defined( SYS_DARWIN ) 305 tr_buildPath ( buf, sizeof( buf ), getHomeDir( ),306 "Library","Application Support",307 "Transmission", NULL );305 path = tr_buildPath( getHomeDir( ), "Library", 306 "Application Support", 307 "Transmission", NULL ); 308 308 #elif defined( __AMIGAOS4__ ) 309 tr_strlcpy( buf, "PROGDIR:.transmission", sizeof( buf ));309 path = tr_strdup( "PROGDIR:.transmission" ); 310 310 #elif defined( WIN32 ) 311 311 char appdata[MAX_PATH_LENGTH]; 312 312 SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata ); 313 tr_buildPath( buf, sizeof( buf ), 314 appdata, "Transmission", NULL ); 315 #else 316 tr_buildPath ( buf, sizeof( buf ), 317 getHomeDir( ), ".transmission", NULL ); 318 #endif 319 path = tr_strdup( buf ); 313 path = tr_buildPath( appdata, "Transmission", NULL ); 314 #else 315 path = tr_buildPath( getHomeDir( ), ".transmission", NULL ); 316 #endif 320 317 } 321 318 322 319 return path; 323 320 } 321 322 #if defined(SYS_DARWIN) || defined(WIN32) 323 #define RESUME_SUBDIR "Resume" 324 #define TORRENT_SUBDIR "Torrents" 325 #else 326 #define RESUME_SUBDIR "resume" 327 #define TORRENT_SUBDIR "torrents" 328 #endif 324 329 325 330 static const char * … … 329 334 330 335 if( !path ) 331 { 332 char buf[MAX_PATH_LENGTH]; 333 const char * p = getOldConfigDir( ); 334 #if defined( __BEOS__ ) || defined( WIN32 ) || defined( SYS_DARWIN ) 335 tr_buildPath( buf, sizeof( buf ), p, "Torrents", NULL ); 336 #else 337 tr_buildPath( buf, sizeof( buf ), p, "torrents", NULL ); 338 #endif 339 340 path = tr_strdup( buf ); 341 } 336 path = tr_buildPath( getOldConfigDir( ), TORRENT_SUBDIR, NULL ); 342 337 343 338 return path; … … 351 346 if( !path ) 352 347 { 353 char buf[MAX_PATH_LENGTH];354 348 #if defined( __BEOS__ ) || defined( WIN32 ) 355 const char * p = getOldConfigDir( ); 356 tr_buildPath( buf, sizeof( buf ), p, "Cache", NULL ); 349 path = tr_buildPath( getOldConfigDir( ), "Cache", NULL ); 357 350 #elif defined( SYS_DARWIN ) 358 tr_buildPath( buf, sizeof( buf ), getHomeDir( ), 359 "Library", "Caches", "Transmission", NULL ); 360 #else 361 const char * p = getOldConfigDir( ); 362 tr_buildPath( buf, sizeof( buf ), p, "cache", NULL ); 363 #endif 364 path = tr_strdup( buf ); 351 path = tr_buildPath( getHomeDir( ), "Library", "Caches", "Transmission", NULL ); 352 #else 353 path = tr_buildPath( getOldConfigDir( ), "cache", NULL ); 354 #endif 365 355 } 366 356 … … 384 374 "." ) && strcmp( dirp->d_name, ".." ) ) 385 375 { 386 char o[MAX_PATH_LENGTH]; 387 char n[MAX_PATH_LENGTH]; 388 tr_buildPath( o, sizeof( o ), oldDir, dirp->d_name, 389 NULL ); 390 tr_buildPath( n, sizeof( n ), newDir, dirp->d_name, 391 NULL ); 376 char * o = tr_buildPath( oldDir, dirp->d_name, NULL ); 377 char * n = tr_buildPath( newDir, dirp->d_name, NULL ); 392 378 rename( o, n ); 393 379 ++count; 380 tr_free( n ); 381 tr_free( o ); 394 382 } 395 383 } … … 424 412 } 425 413 426 #if defined(SYS_DARWIN) || defined(WIN32)427 #define RESUME_SUBDIR "Resume"428 #define TORRENT_SUBDIR "Torrents"429 #else430 #define RESUME_SUBDIR "resume"431 #define TORRENT_SUBDIR "torrents"432 #endif433 434 414 void 435 415 tr_setConfigDir( tr_handle * handle, 436 416 const char * configDir ) 437 417 { 438 char buf[MAX_PATH_LENGTH];418 char * path; 439 419 440 420 handle->configDir = tr_strdup( configDir ); 441 421 442 tr_buildPath( buf, sizeof( buf ),configDir, RESUME_SUBDIR, NULL );443 tr_mkdirp( buf, 0777 );444 handle->resumeDir = tr_strdup( buf );445 446 tr_buildPath( buf, sizeof( buf ),configDir, TORRENT_SUBDIR, NULL );447 tr_mkdirp( buf, 0777 );448 handle->torrentDir = tr_strdup( buf );422 path = tr_buildPath( configDir, RESUME_SUBDIR, NULL ); 423 tr_mkdirp( path, 0777 ); 424 handle->resumeDir = path; 425 426 path = tr_buildPath( configDir, TORRENT_SUBDIR, NULL ); 427 tr_mkdirp( path, 0777 ); 428 handle->torrentDir = path; 449 429 450 430 migrateFiles( handle ); … … 476 456 if( !s ) 477 457 { 478 char path[MAX_PATH_LENGTH];479 480 458 if( ( s = getenv( "TRANSMISSION_HOME" ) ) ) 481 459 { 482 tr_strlcpy( path, s, sizeof( path ));460 s = tr_strdup( s ); 483 461 } 484 462 else 485 463 { 486 464 #ifdef SYS_DARWIN 487 tr_buildPath( path, sizeof( path ), 488 getHomeDir( ), "Library", "Application Support", 489 "Transmission", NULL ); 465 s = tr_buildPath( getHomeDir( ), "Library", 466 "Application Support", "Transmission", NULL ); 490 467 #elif defined( WIN32 ) 491 468 char appdata[MAX_PATH_LENGTH]; 492 469 SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata ); 493 tr_buildPath( path, sizeof( path ), 494 appdata, "Transmission", NULL ); 470 s = tr_buildPath( appdata, "Transmission", NULL ); 495 471 #else 496 472 if( ( s = getenv( "XDG_CONFIG_HOME" ) ) ) 497 tr_buildPath( path, sizeof( path ), 498 s, "transmission", NULL ); 473 s = tr_buildPath( s, "transmission", NULL ); 499 474 else 500 tr_buildPath( path, sizeof( path ), 501 getHomeDir( ), ".config", "transmission", 502 NULL ); 475 s = tr_buildPath( getHomeDir( ), ".config", "transmission", NULL ); 503 476 #endif 504 477 } 505 506 s = tr_strdup( path );507 478 } 508 479 … … 518 489 { 519 490 struct stat sb; 520 char tmp[MAX_PATH_LENGTH]; 521 522 tr_buildPath( tmp, sizeof( tmp ), path, "javascript", "transmission.js", 523 NULL ); 491 char * tmp = tr_buildPath( path, "javascript", "transmission.js", NULL ); 492 const int ret = !stat( tmp, &sb ); 524 493 tr_inf( _( "Searching for web interface file \"%s\"" ), tmp ); 525 return !stat( tmp, &sb ); 494 tr_free( tmp ); 495 return ret; 496 526 497 } 527 498 … … 533 504 if( !s ) 534 505 { 535 char path[MAX_PATH_LENGTH] = { '\0' };536 537 506 if( ( s = getenv( "CLUTCH_HOME" ) ) ) 538 507 { 539 tr_strlcpy( path, s, sizeof( path ));508 s = tr_strdup( s ); 540 509 } 541 510 else if( ( s = getenv( "TRANSMISSION_WEB_HOME" ) ) ) 542 511 { 543 tr_strlcpy( path, s, sizeof( path ));512 s = tr_strdup( s ); 544 513 } 545 514 else … … 555 524 CFRelease( appRef ); 556 525 557 tr_buildPath( path, sizeof( path ), appString, "Contents", 558 "Resources", "web", 559 NULL ); 560 #elif defined( WIN32 ) 561 562 #warning\ 563 hey win32 people is this good or is there a better implementation of the next four lines 564 char appdata[MAX_PATH_LENGTH]; 526 s = tr_buildPath( appString, "Contents", "Resources", "web", NULL ); 527 #elif defined( WIN32 ) 528 529 #warning hey win32 people is this good or is there a better implementation of the next four lines 530 char appdata[MAX_PATH_LENGTH]; 565 531 SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata ); 566 tr_buildPath( path, sizeof( path ), 567 appdata, "Transmission", NULL ); 532 s = tr_buildPath( appdata, "Transmission", NULL ); 568 533 #else 569 534 tr_list *candidates = NULL, *l; … … 573 538 if( s && *s ) 574 539 tr_list_append( &candidates, tr_strdup( s ) ); 575 else 576 { 577 char tmp[MAX_PATH_LENGTH]; 578 tr_buildPath( tmp, sizeof( tmp ), 579 getHomeDir( ), ".local", "share", NULL ); 580 tr_list_append( &candidates, tr_strdup( tmp ) ); 540 else { 541 char * dhome = tr_buildPath( getHomeDir( ), ".local", "share", NULL ); 542 tr_list_append( &candidates, dhome ); 581 543 } 582 544 … … 602 564 for( l = candidates; l; l = l->next ) 603 565 { 604 tr_buildPath( path, sizeof( path ), l->data, "transmission", 605 "web", 606 NULL ); 607 if( isClutchDir( path ) ) 566 char * path = tr_buildPath( l->data, "transmission", "web", NULL ); 567 const int found = isClutchDir( path ); 568 tr_free( path ); 569 if( found ) { 570 s = path; 608 571 break; 609 *path = '\0';572 } 610 573 } 611 574 … … 613 576 #endif 614 577 } 615 616 s = tr_strdup( path );617 578 } 618 579 -
trunk/libtransmission/session.c
r6895 r6896 123 123 int newCount = 0; 124 124 struct stat sb; 125 char dirname[MAX_PATH_LENGTH];125 char * dirname; 126 126 DIR * odir = NULL; 127 127 tr_list * list = NULL; … … 129 129 130 130 /* walk through the directory and find blocklists */ 131 tr_buildPath( dirname, sizeof( dirname ), session->configDir, 132 "blocklists", 133 NULL ); 131 dirname = tr_buildPath( session->configDir, "blocklists", NULL ); 134 132 if( !stat( dirname, 135 133 &sb ) && S_ISDIR( sb.st_mode ) … … 139 137 for( d = readdir( odir ); d; d = readdir( odir ) ) 140 138 { 141 char filename[MAX_PATH_LENGTH];139 char * filename; 142 140 143 141 if( !d->d_name || d->d_name[0] == '.' ) /* skip dotfiles, ., and .. … … 145 143 continue; 146 144 147 tr_buildPath( filename, sizeof( filename ), dirname, d->d_name, 148 NULL ); 145 filename = tr_buildPath( dirname, d->d_name, NULL ); 149 146 150 147 if( tr_stringEndsWith( filename, ".bin" ) ) … … 177 174 ++newCount; 178 175 } 176 177 tr_free( filename ); 179 178 } 180 179 … … 188 187 if( newCount ) 189 188 tr_dbg( "Found %d new blocklists in \"%s\"", newCount, dirname ); 189 190 tr_free( dirname ); 190 191 } 191 192 … … 230 231 { 231 232 tr_handle * h; 232 char filename[MAX_PATH_LENGTH];233 char * filename; 233 234 234 235 #ifndef WIN32 … … 286 287 287 288 /* initialize the blocklist */ 288 tr_buildPath( filename, sizeof( filename ), h->configDir, "blocklists", 289 NULL ); 289 filename = tr_buildPath( h->configDir, "blocklists", NULL ); 290 290 tr_mkdirp( filename, 0777 ); 291 tr_free( filename ); 291 292 h->isBlocklistEnabled = isBlocklistEnabled; 292 293 loadBlocklists( h ); … … 657 658 { 658 659 tr_torrent * tor; 659 char filename[MAX_PATH_LENGTH]; 660 tr_buildPath( filename, sizeof( filename ), dirname, 661 d->d_name, 662 NULL ); 663 664 tr_ctorSetMetainfoFromFile( ctor, filename ); 665 tor = tr_torrentNew( h, ctor, NULL ); 666 if( tor ) 660 char * path = tr_buildPath( dirname, d->d_name, NULL ); 661 tr_ctorSetMetainfoFromFile( ctor, path ); 662 if(( tor = tr_torrentNew( h, ctor, NULL ))) 667 663 { 668 664 tr_list_append( &list, tor ); 669 665 ++n; 670 666 } 667 tr_free( path ); 671 668 } 672 669 } … … 795 792 if( !b ) 796 793 { 797 char filename[MAX_PATH_LENGTH]; 798 tr_buildPath( filename, sizeof( filename ), session->configDir, 799 "blocklists", defaultName, 800 NULL ); 801 b = _tr_blocklistNew( filename, session->isBlocklistEnabled ); 794 char * path = tr_buildPath( session->configDir, "blocklists", defaultName, NULL ); 795 b = _tr_blocklistNew( path, session->isBlocklistEnabled ); 802 796 tr_list_append( &session->blocklists, b ); 797 tr_free( path ); 803 798 } 804 799 … … 890 885 { 891 886 tr_info inf; 892 char filename[MAX_PATH_LENGTH]; 893 tr_buildPath( filename, sizeof( filename ), dirname, 894 d->d_name, 895 NULL ); 896 tr_ctorSetMetainfoFromFile( ctor, filename ); 887 char * path = tr_buildPath( dirname, d->d_name, NULL ); 888 tr_ctorSetMetainfoFromFile( ctor, path ); 897 889 if( !tr_torrentParse( h, ctor, &inf ) ) 898 890 { 899 891 tr_list_append( &list, tr_strdup( inf.hashString ) ); 900 tr_list_append( &list, tr_strdup( filename) );892 tr_list_append( &list, tr_strdup( path ) ); 901 893 tr_metainfoFree( &inf ); 902 894 } 895 tr_free( path ); 903 896 } 904 897 } -
trunk/libtransmission/stats.c
r6795 r6896 31 31 32 32 static char* 33 getOldFilename( const tr_handle * handle, 34 char * buf, 35 size_t buflen ) 36 { 37 tr_buildPath( buf, buflen, tr_sessionGetConfigDir( handle ), 38 "stats.benc", 39 NULL ); 40 return buf; 33 getOldFilename( const tr_handle * handle ) 34 { 35 return tr_buildPath( tr_sessionGetConfigDir( handle ), "stats.benc", NULL ); 41 36 } 42 37 43 38 static char* 44 getFilename( const tr_handle * handle, 45 char * buf, 46 size_t buflen ) 47 { 48 tr_buildPath( buf, buflen, tr_sessionGetConfigDir( handle ), 49 "stats.json", 50 NULL ); 51 return buf; 39 getFilename( const tr_handle * handle ) 40 { 41 return tr_buildPath( tr_sessionGetConfigDir( handle ), "stats.json", NULL ); 52 42 } 53 43 … … 57 47 { 58 48 int loaded = FALSE; 59 char filename[MAX_PATH_LENGTH];49 char * filename; 60 50 tr_benc top; 61 51 62 getFilename( handle, filename, sizeof( filename ));52 filename = getFilename( handle ); 63 53 loaded = !tr_bencLoadJSONFile( filename, &top ); 54 tr_free( filename ); 55 64 56 if( !loaded ) 65 57 { 66 getOldFilename( handle, filename, sizeof( filename ));58 filename = getOldFilename( handle ); 67 59 loaded = !tr_bencLoadFile( filename, &top ); 60 tr_free( filename ); 68 61 } 62 69 63 if( loaded ) 70 64 { … … 90 84 const tr_session_stats * s ) 91 85 { 92 char filename[MAX_PATH_LENGTH];86 char * filename; 93 87 tr_benc top; 94 88 … … 100 94 tr_bencDictAddInt( &top, "uploaded-bytes", s->uploadedBytes ); 101 95 102 getFilename( handle, filename, sizeof( filename ) ); 103 tr_deepLog( __FILE__, __LINE__, NULL, "Saving stats to \"%s\"", 104 filename ); 96 filename = getFilename( handle ); 97 tr_deepLog( __FILE__, __LINE__, NULL, "Saving stats to \"%s\"", filename ); 105 98 tr_bencSaveJSONFile( filename, &top ); 106 99 100 tr_free( filename ); 107 101 tr_bencFree( &top ); 108 102 } -
trunk/libtransmission/torrent.c
r6842 r6896 1160 1160 for( i = 0; i < tor->info.fileCount; ++i ) 1161 1161 { 1162 char path[MAX_PATH_LENGTH];1163 1162 const tr_file * file = &tor->info.files[i]; 1164 tr_buildPath( path, sizeof( path ), tor->downloadDir, file->name, 1165 NULL ); 1163 char * path = tr_buildPath( tor->downloadDir, file->name, NULL ); 1166 1164 tr_fdFileClose( path ); 1165 tr_free( path ); 1167 1166 } 1168 1167 } … … 1646 1645 for( i = 0; i < n; ++i ) 1647 1646 { 1648 char fname[MAX_PATH_LENGTH];1649 1647 struct stat sb; 1650 tr_buildPath( fname, sizeof( fname ), 1651 tor->downloadDir, tor->info.files[i].name, NULL ); 1652 if( !stat( fname, &sb ) ) 1648 char * path = tr_buildPath( tor->downloadDir, tor->info.files[i].name, NULL ); 1649 if( !stat( path, &sb ) ) 1653 1650 { 1654 1651 #ifdef SYS_DARWIN … … 1658 1655 #endif 1659 1656 } 1657 tr_free( path ); 1660 1658 } 1661 1659 -
trunk/libtransmission/utils.c
r6892 r6896 546 546 } 547 547 548 void 549 tr_buildPath( char * buf, 550 size_t buflen, 551 const char *first_element, 552 ... ) 553 { 548 char* 549 tr_buildPath( const char *first_element, ... ) 550 { 551 char * ret; 554 552 struct evbuffer * evbuf; 555 const char *element = first_element;553 const char * element = first_element; 556 554 va_list vl; 557 555 … … 567 565 } 568 566 569 if( EVBUFFER_LENGTH( evbuf ) )570 tr_strlcpy( buf, EVBUFFER_DATA( evbuf ), buflen );571 else572 *buf = '\0';573 574 567 va_end( vl ); 568 ret = tr_strndup( EVBUFFER_DATA( evbuf ), EVBUFFER_LENGTH( evbuf ) ); 575 569 evbuffer_free( evbuf ); 570 return ret; 576 571 } 577 572 -
trunk/libtransmission/utils.h
r6893 r6896 177 177 /* creates a filename from a series of elements using the 178 178 correct separator for filenames. */ 179 void tr_buildPath( char* buf, 180 size_t buflen, 181 const char * first_element, 182 ... ) 183 TR_GNUC_NULL_TERMINATED; 179 char* tr_buildPath( const char * first_element, ... ) 180 TR_GNUC_NULL_TERMINATED 181 TR_GNUC_MALLOC; 184 182 185 183 struct timeval tr_timevalMsec( uint64_t milliseconds ); -
trunk/libtransmission/verify.c
r6838 r6896 68 68 int nofile; 69 69 struct stat sb; 70 char path[MAX_PATH_LENGTH];71 const tr_file *file = &tor->info.files[fileIndex];72 73 tr_buildPath ( path, sizeof( path ),tor->downloadDir, file->name, NULL );70 char * path; 71 const tr_file * file = &tor->info.files[fileIndex]; 72 73 path = tr_buildPath( tor->downloadDir, file->name, NULL ); 74 74 nofile = stat( path, &sb ) || !S_ISREG( sb.st_mode ); 75 75 … … 111 111 } 112 112 113 tr_free( path ); 114 113 115 return changed; 114 116 }
Note: See TracChangeset
for help on using the changeset viewer.