Ignore:
Timestamp:
Jan 12, 2006, 6:58:57 PM (15 years ago)
Author:
root
Message:

Update 2005-12-25

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r14 r20  
    2121 *****************************************************************************/
    2222
    23 #include "platform.h"
     23#ifdef SYS_BEOS
     24  #include <fs_info.h>
     25  #include <FindDirectory.h>
     26#endif
     27#ifdef SYS_DARWIN
     28  #include <sys/types.h>
     29  #include <dirent.h>
     30#endif
     31
     32#include "transmission.h"
     33
     34char * tr_getPrefsDirectory()
     35{
     36    static char prefsDirectory[MAX_PATH_LENGTH];
     37    static int  init = 0;
     38
     39    if( init )
     40    {
     41        return prefsDirectory;
     42    }
    2443
    2544#ifdef SYS_BEOS
    26 /***********************************************************************
    27  * tr_init_beos
    28  ***********************************************************************
    29  * Puts the prefsDirectory in the right place.
    30  **********************************************************************/
    31 void tr_init_beos( tr_handle_t * h )
    32 {
    33         int32 length = 0;
    34         char path[B_FILE_NAME_LENGTH];
    35        
    3645        find_directory( B_USER_SETTINGS_DIRECTORY, dev_for_path("/boot"),
    37                         true, path, length );
    38        
    39         snprintf( h->prefsDirectory, B_FILE_NAME_LENGTH,
    40                   "%s/Transmission", path );
    41         mkdir( h->prefsDirectory, 0755 );
    42 }
     46                        true, prefsDirectory, MAX_PATH_LENGTH );
     47        strcat( prefsDirectory, "/Transmission" );
     48#elif defined( SYS_DARWIN )
     49    snprintf( prefsDirectory, MAX_PATH_LENGTH,
     50              "%s/Library/Caches/Transmission", getenv( "HOME" ) );
     51#else
     52    snprintf( prefsDirectory, MAX_PATH_LENGTH, "%s/.transmission",
     53              getenv( "HOME" ) );
    4354#endif
    4455
    45 /***********************************************************************
    46  * tr_init_platform
    47  ***********************************************************************
    48  * Setup the prefsDirectory for the current platform.
    49  **********************************************************************/
    50 void tr_init_platform( tr_handle_t *h )
     56        mkdir( prefsDirectory, 0755 );
     57    init = 1;
     58
     59#ifdef SYS_DARWIN
     60    DIR * dirh;
     61    struct dirent * dirp;
     62    char oldDirectory[MAX_PATH_LENGTH];
     63    char oldFile[MAX_PATH_LENGTH];
     64    char newFile[MAX_PATH_LENGTH];
     65    snprintf( oldDirectory, MAX_PATH_LENGTH, "%s/.transmission",
     66              getenv( "HOME" ) );
     67    if( ( dirh = opendir( oldDirectory ) ) )
     68    {
     69        while( ( dirp = readdir( dirh ) ) )
     70        {
     71            if( !strcmp( ".", dirp->d_name ) ||
     72                !strcmp( "..", dirp->d_name ) )
     73            {
     74                continue;
     75            }
     76            snprintf( oldFile, MAX_PATH_LENGTH, "%s/%s",
     77                      oldDirectory, dirp->d_name );
     78            snprintf( newFile, MAX_PATH_LENGTH, "%s/%s",
     79                      prefsDirectory, dirp->d_name );
     80            rename( oldFile, newFile );
     81        }
     82
     83        closedir( dirh );
     84        rmdir( oldDirectory );
     85    }
     86#endif
     87
     88    return prefsDirectory;
     89}
     90
     91void tr_threadCreate( tr_thread_t * t, void (*func)(void *), void * arg )
    5192{
    5293#ifdef SYS_BEOS
    53         tr_init_beos( h );
     94    *t = spawn_thread( (void *) func, "torrent-tx", arg );
     95    resume_thread( *t );
    5496#else
    55     snprintf( h->prefsDirectory, sizeof( h->prefsDirectory ),
    56               "%s/.transmission", getenv( "HOME" ) );
    57     mkdir( h->prefsDirectory, 0755 );
     97    pthread_create( t, NULL, (void *) func, arg );
    5898#endif
    5999}
     100
     101void tr_threadJoin( tr_thread_t * t )
     102{
     103#ifdef SYS_BEOS
     104    long exit;
     105    wait_for_thread( *t, &exit );
     106#else
     107    pthread_join( *t, NULL );
     108#endif
     109}
     110
     111void tr_lockInit( tr_lock_t * l )
     112{
     113#ifdef SYS_BEOS
     114    *l = create_sem( 1, "" );
     115#else
     116    pthread_mutex_init( l, NULL );
     117#endif
     118}
     119
     120void tr_lockClose( tr_lock_t * l )
     121{
     122#ifdef SYS_BEOS
     123    delete_sem( *l );
     124#else
     125    pthread_mutex_destroy( l );
     126#endif
     127}
     128
Note: See TracChangeset for help on using the changeset viewer.