Ignore:
Timestamp:
Oct 14, 2008, 3:39:16 AM (13 years ago)
Author:
charles
Message:

make MAX_PATH_LENGTH private to libtransmission. add tr_dirname() and tr_basename() utility / portability wrappers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/utils.c

    r6896 r6897  
    196196        char              timestr[64];
    197197        struct evbuffer * buf = evbuffer_new( );
    198         char *            myfile = tr_strdup( file );
     198        char *            base = tr_basename( file );
    199199
    200200        evbuffer_add_printf( buf, "[%s] ",
     
    205205        evbuffer_add_vprintf( buf, fmt, args );
    206206        va_end( args );
    207         evbuffer_add_printf( buf, " (%s:%d)\n", basename( myfile ), line );
     207        evbuffer_add_printf( buf, " (%s:%d)\n", base, line );
    208208        (void) fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp );
    209209
    210         tr_free( myfile );
     210        tr_free( base );
    211211        evbuffer_free( buf );
    212212    }
     
    457457
    458458char*
    459 tr_getcwd( char  * buffer,
    460            int     maxlen )
    461 {
     459tr_getcwd( void )
     460{
     461    char buf[2048];
     462    *buf = '\0';
    462463#ifdef WIN32
    463     return _getcwd( buffer, maxlen );
     464    _getcwd( buf, sizeof( buf ) );
    464465#else
    465     return getcwd( buffer, maxlen );
     466    getcwd( buf, sizeof( buf ) );
    466467#endif
     468    return tr_strdup( buf );
     469}
     470
     471char*
     472tr_basename( const char * path )
     473{
     474    char * tmp = tr_strdup( path );
     475    char * ret = tr_strdup( basename( tmp ) );
     476    tr_free( tmp );
     477    return ret;
     478}
     479
     480char*
     481tr_dirname( const char * path )
     482{
     483    char * tmp = tr_strdup( path );
     484    char * ret = tr_strdup( dirname( tmp ) );
     485    tr_free( tmp );
     486    return ret;
    467487}
    468488
     
    525545        {
    526546            /* Node exists but isn't a folder */
    527             char buf[MAX_PATH_LENGTH];
    528             tr_snprintf( buf, sizeof( buf ), _(
    529                              "File \"%s\" is in the way" ), path );
     547            char * buf = tr_strdup_printf( _( "File \"%s\" is in the way" ), path );
    530548            tr_err( _( "Couldn't create \"%1$s\": %2$s" ), path_in, buf );
     549            tr_free( buf );
    531550            tr_free( path );
    532551            errno = ENOTDIR;
Note: See TracChangeset for help on using the changeset viewer.