int doPreallocate,
uint64_t desiredFileSize )
{
- int i, winner = -1;
+ int i, winner = -1;
struct tr_openfile * o;
- char * filename;
+ char filename[MAX_PATH_LENGTH];
assert( folder && *folder );
assert( torrentFile && *torrentFile );
assert( doWrite == 0 || doWrite == 1 );
- filename = tr_buildPath( folder, torrentFile, NULL );
- dbgmsg( "looking for file '%s', writable %c", filename,
- doWrite ? 'y' : 'n' );
+ tr_snprintf( filename, sizeof( filename ), "%s%c%s", folder, TR_PATH_DELIMITER, torrentFile );
+ dbgmsg( "looking for file '%s', writable %c", filename, doWrite ? 'y' : 'n' );
tr_lockLock( gFd->lock );
const int err = TrOpenFile( winner, folder, torrentFile, doWrite, doPreallocate, desiredFileSize );
if( err ) {
tr_lockUnlock( gFd->lock );
- tr_free( filename );
errno = err;
return -1;
}
o->isCheckedOut = 1;
o->closeWhenDone = 0;
o->date = tr_date( );
- tr_free( filename );
tr_lockUnlock( gFd->lock );
return o->fd;
}
const tr_file * file = &info->files[fileIndex];
typedef size_t ( *iofunc )( int, void *, size_t );
- iofunc func = ioMode ==
- TR_IO_READ ? (iofunc)read : (iofunc)write;
- char * path;
+ iofunc func = ioMode == TR_IO_READ ? (iofunc)read : (iofunc)write;
struct stat sb;
int fd = -1;
int err;
assert( !file->length || ( fileOffset < file->length ) );
assert( fileOffset + buflen <= file->length );
- path = tr_buildPath( tor->downloadDir, file->name, NULL );
- fileExists = !stat( path, &sb );
- tr_free( path );
+ {
+ char path[MAX_PATH_LENGTH];
+ tr_snprintf( path, sizeof( path ), "%s%c%s", tor->downloadDir, TR_PATH_DELIMITER, file->name );
+ fileExists = !stat( path, &sb );
+ }
if( !file->length )
return 0;
#include <windows.h>
#define MAX_PATH_LENGTH MAX_PATH
#else
- #define MAX_PATH_LENGTH 1024
+ #define MAX_PATH_LENGTH 2048
#endif
#define MAX_STACK_ARRAY_SIZE 7168
}
char*
-tr_strdup_printf( const char * fmt,
- ... )
+tr_strdup_printf( const char * fmt, ... )
{
char * ret = NULL;
struct evbuffer * buf;