source: trunk/libtransmission/platform.c @ 21

Last change on this file since 21 was 21, checked in by root, 15 years ago

Update 2005-12-26

File size: 3.6 KB
Line 
1/******************************************************************************
2 * Copyright (c) 2005 Eric Petit
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *****************************************************************************/
22
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    }
43
44#ifdef SYS_BEOS
45        find_directory( B_USER_SETTINGS_DIRECTORY, dev_for_path("/boot"),
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" ) );
54#endif
55
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 )
92{
93#ifdef SYS_BEOS
94    *t = spawn_thread( (void *) func, "torrent-tx", B_NORMAL_PRIORITY, arg );
95    resume_thread( *t );
96#else
97    pthread_create( t, NULL, (void *) func, arg );
98#endif
99}
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 TracBrowser for help on using the repository browser.