mirror of
https://github.com/transmission/transmission
synced 2025-02-25 07:22:38 +00:00
make MAX_PATH_LENGTH private to libtransmission. add tr_dirname() and tr_basename() utility / portability wrappers
This commit is contained in:
parent
e3a5524189
commit
b04be5fb2e
13 changed files with 101 additions and 100 deletions
|
@ -308,7 +308,6 @@ main( int argc,
|
|||
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 );
|
||||
|
@ -352,11 +351,7 @@ main( int argc,
|
|||
|
||||
/* 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(
|
||||
|
|
|
@ -167,7 +167,7 @@ session_init( const char * configDir,
|
|||
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;
|
||||
|
@ -190,7 +190,7 @@ session_init( const char * configDir,
|
|||
**** 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 );
|
||||
|
@ -258,6 +258,8 @@ session_init( const char * configDir,
|
|||
|
||||
if( dict )
|
||||
tr_bencFree( &state );
|
||||
|
||||
tr_free( mycwd );
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
|
|
@ -151,9 +151,9 @@ absolutify( const char * path )
|
|||
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;
|
||||
|
|
|
@ -248,50 +248,50 @@ static void
|
|||
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
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <libgen.h> /* basename */
|
||||
#ifndef WIN32
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
@ -105,12 +104,9 @@ blocklistLoad( tr_blocklist * b )
|
|||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,13 +292,9 @@ _tr_blocklistSetContent( tr_blocklist * b,
|
|||
}
|
||||
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include <sys/resource.h> /* getrlimit */
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <libgen.h> /* dirname */
|
||||
#include <fcntl.h> /* O_LARGEFILE */
|
||||
|
||||
#include <event.h>
|
||||
|
@ -124,8 +123,8 @@ TrOpenFile( int i,
|
|||
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 )
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h> /* dirname, basename */
|
||||
#include <dirent.h>
|
||||
|
||||
#include "crypto.h" /* tr_sha1 */
|
||||
|
@ -133,14 +132,11 @@ tr_metaInfoBuilderCreate( tr_handle * handle,
|
|||
/* 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 )
|
||||
|
@ -333,7 +329,7 @@ makeInfoDict( tr_benc * dict,
|
|||
tr_metainfo_builder * builder )
|
||||
{
|
||||
uint8_t * pch;
|
||||
char base[MAX_PATH_LENGTH];
|
||||
char * base;
|
||||
|
||||
tr_bencDictReserve( dict, 5 );
|
||||
|
||||
|
@ -353,8 +349,9 @@ makeInfoDict( tr_benc * dict,
|
|||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
|
@ -519,11 +516,7 @@ tr_makeMetaInfo( tr_metainfo_builder * builder,
|
|||
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 );
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h> /* basename */
|
||||
|
||||
#include <event.h>
|
||||
|
||||
|
@ -327,7 +326,7 @@ myDebug( const char * file,
|
|||
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 ) ),
|
||||
|
@ -337,10 +336,10 @@ myDebug( const char * file,
|
|||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,13 @@
|
|||
#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;
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <libgen.h> /* basename */
|
||||
#include "transmission.h"
|
||||
#include "bencode.h"
|
||||
#include "platform.h"
|
||||
|
@ -121,9 +120,9 @@ tr_ctorSetMetainfoFromFile( tr_ctor * ctor,
|
|||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,13 +49,6 @@ extern "C" {
|
|||
|
||||
#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;
|
||||
|
|
|
@ -195,7 +195,7 @@ tr_deepLog( const char * file,
|
|||
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 ) ) );
|
||||
|
@ -204,10 +204,10 @@ tr_deepLog( const char * file,
|
|||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -456,14 +456,34 @@ tr_loadFile( const char * path,
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -524,10 +544,9 @@ tr_mkdirp( const char * path_in,
|
|||
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;
|
||||
|
|
|
@ -140,11 +140,14 @@ void tr_deepLog( const char * file,
|
|||
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().
|
||||
|
|
Loading…
Reference in a new issue