tr_handle * h;
tr_ctor * ctor;
tr_torrent * tor = NULL;
- char cwd[MAX_PATH_LENGTH];
printf( "Transmission %s - http://www.transmissionbt.com/\n",
LONG_VERSION_STRING );
/* if no download directory specified, use cwd instead */
if( !downloadDir )
- {
- tr_getcwd( cwd, sizeof( cwd ) );
- downloadDir = cwd;
- }
-
+ downloadDir = tr_strdup( tr_getcwd( ) );
/* Initialize libtransmission */
h = tr_sessionInitFull(
const char * password,
int blocklistEnabled )
{
- char mycwd[MAX_PATH_LENGTH];
+ char * mycwd;
tr_benc state, *dict = NULL;
int peerPort = -1, peers = -1;
int whitelistEnabled = -1;
**** If neither of those can be found, the TR_DEFAULT fields are used .
***/
- tr_getcwd( mycwd, sizeof( mycwd ) );
+ mycwd = tr_getcwd( );
getConfigStr( dict, KEY_DOWNLOAD_DIR, &downloadDir, mycwd );
getConfigInt( dict, KEY_PEX_ENABLED, &pexEnabled,
TR_DEFAULT_PEX_ENABLED );
if( dict )
tr_bencFree( &state );
+
+ tr_free( mycwd );
}
static const char *
if( *path == '/' )
buf = tr_strdup( path );
else {
- char cwd[MAX_PATH_LENGTH];
- tr_getcwd( cwd, sizeof( cwd ) );
+ char * cwd = tr_getcwd( );
buf = tr_buildPath( cwd, path, NULL );
+ tr_free( cwd );
}
return buf;
refreshFromBuilder( MakeMetaUI * ui )
{
char sizeStr[128];
- char buf[MAX_PATH_LENGTH];
+ char * buf;
tr_metainfo_builder * builder = ui->builder;
const char * filename = builder ? builder->top : NULL;
+
+ /* update the progressbar */
if( !filename )
- g_snprintf( buf, sizeof( buf ), _( "No source selected" ) );
+ buf = g_strdup( _( "No source selected" ) );
else
- g_snprintf( buf, sizeof( buf ), "%s.torrent (%d%%)", filename, 0 );
+ buf = g_strdup_printf( "%s.torrent (%d%%)", filename, 0 );
gtk_progress_bar_set_text( GTK_PROGRESS_BAR( ui->progressbar ), buf );
refreshButtons( ui );
+ g_free( buf );
+ /* update the size label */
if( !filename )
- g_snprintf( buf, sizeof( buf ), _( "<i>No source selected</i>" ) );
- else
- {
+ buf = g_strdup( "<i>No source selected</i>" );
+ else {
tr_strlsize( sizeStr, builder->totalSize, sizeof( sizeStr ) );
- g_snprintf( buf, sizeof( buf ),
- /* %1$s is the torrent size
- %2$'d is its number of files */
- ngettext( "<i>%1$s; %2$'d File</i>",
- "<i>%1$s; %2$'d Files</i>",
- builder->fileCount ),
- sizeStr, builder->fileCount );
+ buf = g_strdup_printf( /* %1$s is the torrent size
+ %2$'d is its number of files */
+ ngettext( "<i>%1$s; %2$'d File</i>",
+ "<i>%1$s; %2$'d Files</i>",
+ builder->fileCount ),
+ sizeStr, builder->fileCount );
}
gtk_label_set_markup ( GTK_LABEL( ui->size_lb ), buf );
+ g_free( buf );
+ /* update the pieces label */
if( !filename )
- *buf = '\0';
- else
- {
- char countStr[512];
- g_snprintf( countStr, sizeof( countStr ),
- ngettext( "%'d Piece", "%'d Pieces",
- builder->pieceCount ),
- builder->pieceCount );
+ buf = g_strdup( "" );
+ else {
+ char * countStr = g_strdup_printf( ngettext( "%'d Piece", "%'d Pieces",
+ builder->pieceCount ),
+ builder->pieceCount );
tr_strlsize( sizeStr, builder->pieceSize, sizeof( sizeStr ) );
- g_snprintf( buf, sizeof( buf ),
- /* %1$s is number of pieces;
- %2$s is how big each piece is */
- _( "%1$s @ %2$s" ),
- countStr,
- sizeStr );
+ buf = g_strdup_printf( /* %1$s is number of pieces;
+ %2$s is how big each piece is */
+ _( "%1$s @ %2$s" ), countStr, sizeStr );
+ g_free( countStr );
}
gtk_label_set_markup ( GTK_LABEL( ui->pieces_lb ), buf );
+ g_free( buf );
}
static void
#include <windows.h>
#endif
-#include <libgen.h> /* basename */
#ifndef WIN32
#include <sys/mman.h>
#endif
b->fd = fd;
{
- char * name;
- char buf[MAX_PATH_LENGTH];
- tr_strlcpy( buf, b->filename, sizeof( buf ) );
- name = basename( buf );
- tr_inf( _( "Blocklist \"%s\" contains %'u entries" ), name,
- (unsigned int)b->ruleCount );
+ char * base = tr_basename( b->filename );
+ tr_inf( _( "Blocklist \"%s\" contains %'zu entries" ), base, b->ruleCount );
+ tr_free( base );
}
}
}
{
- char * name;
- char buf[MAX_PATH_LENGTH];
- tr_strlcpy( buf, b->filename, sizeof( buf ) );
- name = basename( buf );
- tr_inf( _(
- "Blocklist \"%1$s\" updated with %2$'d entries" ), name,
- lineCount );
+ char * base = tr_basename( b->filename );
+ tr_inf( _( "Blocklist \"%1$s\" updated with %2$'d entries" ), base, lineCount );
+ tr_free( base );
}
#include <sys/resource.h> /* getrlimit */
#endif
#include <unistd.h>
-#include <libgen.h> /* dirname */
#include <fcntl.h> /* O_LARGEFILE */
#include <event.h>
filename = tr_buildPath( folder, torrentFile, NULL );
if( write )
{
- char * tmp = tr_strdup( filename );
- const int err = tr_mkdirp( dirname( tmp ), 0777 ) ? errno : 0;
+ char * tmp = tr_dirname( filename );
+ const int err = tr_mkdirp( tmp, 0777 ) ? errno : 0;
tr_free( tmp );
tr_free( filename );
if( err )
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
-#include <libgen.h> /* dirname, basename */
#include <dirent.h>
#include "crypto.h" /* tr_sha1 */
/* build a list of files containing topFile and,
if it's a directory, all of its children */
{
- char *dir, *base;
- char dirbuf[MAX_PATH_LENGTH];
- char basebuf[MAX_PATH_LENGTH];
- tr_strlcpy( dirbuf, topFile, sizeof( dirbuf ) );
- tr_strlcpy( basebuf, topFile, sizeof( basebuf ) );
- dir = dirname( dirbuf );
- base = basename( basebuf );
+ char * dir = tr_dirname( topFile );
+ char * base = tr_basename( topFile );
files = getFiles( dir, base, NULL );
+ tr_free( base );
+ tr_free( dir );
}
for( walk = files; walk != NULL; walk = walk->next )
tr_metainfo_builder * builder )
{
uint8_t * pch;
- char base[MAX_PATH_LENGTH];
+ char * base;
tr_bencDictReserve( dict, 5 );
}
}
- tr_strlcpy( base, builder->top, sizeof( base ) );
- tr_bencDictAddStr( dict, "name", basename( base ) );
+ base = tr_basename( builder->top );
+ tr_bencDictAddStr( dict, "name", base );
+ tr_free( base );
tr_bencDictAddInt( dict, "piece length", builder->pieceSize );
if( outputFile && *outputFile )
builder->outputFile = tr_strdup( outputFile );
else
- {
- char out[MAX_PATH_LENGTH];
- tr_snprintf( out, sizeof( out ), "%s.torrent", builder->top );
- builder->outputFile = tr_strdup( out );
- }
+ builder->outputFile = tr_strdup_printf( "%s.torrent", builder->top );
/* enqueue the builder */
lock = getQueueLock ( builder->handle );
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <libgen.h> /* basename */
#include <event.h>
va_list args;
char timestr[64];
struct evbuffer * buf = evbuffer_new( );
- char * myfile = tr_strdup( file );
+ char * base = tr_basename( file );
evbuffer_add_printf( buf, "[%s] %s - %s [%s]: ",
tr_getLogTimeStr( timestr, sizeof( timestr ) ),
va_start( args, fmt );
evbuffer_add_vprintf( buf, fmt, args );
va_end( args );
- evbuffer_add_printf( buf, " (%s:%d)\n", basename( myfile ), line );
+ evbuffer_add_printf( buf, " (%s:%d)\n", base, line );
fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp );
- tr_free( myfile );
+ tr_free( base );
evbuffer_free( buf );
}
}
#define TR_PATH_DELIMITER_STR "/"
#endif
+#ifdef __BEOS__
+ #include <StorageDefs.h>
+ #define MAX_PATH_LENGTH B_FILE_NAME_LENGTH
+#else
+ #define MAX_PATH_LENGTH 1024
+#endif
+
typedef struct tr_lock tr_lock;
typedef struct tr_thread tr_thread;
*/
#include <errno.h>
-#include <libgen.h> /* basename */
#include "transmission.h"
#include "bencode.h"
#include "platform.h"
name = NULL;
if( !name || !*name )
{
- char * tmp = tr_strdup( filename );
- tr_bencDictAddStr( info, "name", basename( tmp ) );
- tr_free( tmp );
+ char * base = tr_basename( filename );
+ tr_bencDictAddStr( info, "name", base );
+ tr_free( base );
}
}
}
#define SHA_DIGEST_LENGTH 20
-#ifdef __BEOS__
- #include <StorageDefs.h>
- #define MAX_PATH_LENGTH B_FILE_NAME_LENGTH
-#else
- #define MAX_PATH_LENGTH 1024
-#endif
-
typedef uint32_t tr_file_index_t;
typedef uint32_t tr_piece_index_t;
typedef uint64_t tr_block_index_t;
va_list args;
char timestr[64];
struct evbuffer * buf = evbuffer_new( );
- char * myfile = tr_strdup( file );
+ char * base = tr_basename( file );
evbuffer_add_printf( buf, "[%s] ",
tr_getLogTimeStr( timestr, sizeof( timestr ) ) );
va_start( args, fmt );
evbuffer_add_vprintf( buf, fmt, args );
va_end( args );
- evbuffer_add_printf( buf, " (%s:%d)\n", basename( myfile ), line );
+ evbuffer_add_printf( buf, " (%s:%d)\n", base, line );
(void) fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp );
- tr_free( myfile );
+ tr_free( base );
evbuffer_free( buf );
}
}
}
char*
-tr_getcwd( char * buffer,
- int maxlen )
+tr_getcwd( void )
{
+ char buf[2048];
+ *buf = '\0';
#ifdef WIN32
- return _getcwd( buffer, maxlen );
+ _getcwd( buf, sizeof( buf ) );
#else
- return getcwd( buffer, maxlen );
+ getcwd( buf, sizeof( buf ) );
#endif
+ return tr_strdup( buf );
+}
+
+char*
+tr_basename( const char * path )
+{
+ char * tmp = tr_strdup( path );
+ char * ret = tr_strdup( basename( tmp ) );
+ tr_free( tmp );
+ return ret;
+}
+
+char*
+tr_dirname( const char * path )
+{
+ char * tmp = tr_strdup( path );
+ char * ret = tr_strdup( dirname( tmp ) );
+ tr_free( tmp );
+ return ret;
}
int
else if( ( sb.st_mode & S_IFMT ) != S_IFDIR )
{
/* Node exists but isn't a folder */
- char buf[MAX_PATH_LENGTH];
- tr_snprintf( buf, sizeof( buf ), _(
- "File \"%s\" is in the way" ), path );
+ char * buf = tr_strdup_printf( _( "File \"%s\" is in the way" ), path );
tr_err( _( "Couldn't create \"%1$s\": %2$s" ), path_in, buf );
+ tr_free( buf );
tr_free( path );
errno = ENOTDIR;
return -1;
char* tr_getLogTimeStr( char * buf,
int buflen );
-/**
- * a portability wrapper around getcwd().
- */
-char* tr_getcwd( char * buffer,
- int maxlen );
+/** a portability wrapper for getcwd(). */
+char* tr_getcwd( void ) TR_GNUC_MALLOC;
+
+/** a portability wrapper for basename(). */
+char* tr_basename( const char * path ) TR_GNUC_MALLOC;
+
+/** a portability wrapper for dirname(). */
+char* tr_dirname( const char * path ) TR_GNUC_MALLOC;
/**
* a portability wrapper around mkdir().