further win32 portability fixes from Spry

This commit is contained in:
Charles Kerr 2008-10-19 17:43:04 +00:00
parent 071c6733e5
commit 67282cb794
6 changed files with 82 additions and 32 deletions

View File

@ -150,5 +150,6 @@ version.h:
echo '#define PEERID_PREFIX "'@PEERID_PREFIX@'"' > version.h
echo '#define USERAGENT_PREFIX "'@USERAGENT_PREFIX@'"' >> version.h
echo '#define SVN_REVISION "'`svn info | grep "Revision" | awk -F': ' '{print $$2}'`'"' >> version.h
echo '#define SVN_REVISION_NUM '`svn info | grep "Revision" | awk -F': ' '{print $$2}'`'' >> version.h
echo '#define SHORT_VERSION_STRING "'@USERAGENT_PREFIX@'"' >> version.h
echo '#define LONG_VERSION_STRING "'@USERAGENT_PREFIX@' ('`svn info | grep "Revision" | awk -F': ' '{print $$2}'`')"' >> version.h

View File

@ -489,6 +489,7 @@ tr_fdClose( void )
tr_lockFree( gFd->lock );
tr_free( gFd );
gFd = NULL;
}
void

View File

@ -28,19 +28,19 @@
#ifdef WIN32
#include <inttypes.h>
#include <winsock2.h>
typedef int socklen_t;
typedef uint16_t tr_port_t;
typedef int socklen_t;
typedef uint16_t tr_port_t;
#elif defined( __BEOS__ )
#include <sys/socket.h>
#include <netinet/in.h>
typedef unsigned short tr_port_t;
typedef int socklen_t;
typedef unsigned short tr_port_t;
typedef int socklen_t;
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
typedef in_port_t tr_port_t;
typedef in_port_t tr_port_t;
#endif
#ifdef WIN32

View File

@ -465,9 +465,9 @@ tr_getDefaultConfigDir( void )
s = tr_buildPath( getHomeDir( ), "Library",
"Application Support", "Transmission", NULL );
#elif defined( WIN32 )
char appdata[MAX_PATH_LENGTH];
SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata );
s = tr_buildPath( appdata, "Transmission", NULL );
char configDir[MAX_PATH_LENGTH];
GetModuleFileName( GetModuleHandle( NULL ), configDir, sizeof( configDir ) );
s = tr_buildPath( basename( configDir ), "Transmission", NULL );
#else
if( ( s = getenv( "XDG_CONFIG_HOME" ) ) )
s = tr_buildPath( s, "transmission", NULL );
@ -513,24 +513,59 @@ tr_getClutchDir( const tr_session * session UNUSED )
}
else
{
#ifdef SYS_DARWIN
CFURLRef appURL = CFBundleCopyBundleURL(
CFBundleGetMainBundle( ) );
CFStringRef appRef = CFURLCopyFileSystemPath(
appURL, kCFURLPOSIXPathStyle );
const char * appString = CFStringGetCStringPtr(
appRef, CFStringGetFastestEncoding( appRef ) );
CFURLRef appURL = CFBundleCopyBundleURL( CFBundleGetMainBundle( ) );
CFStringRef appRef = CFURLCopyFileSystemPath( appURL,
kCFURLPOSIXPathStyle );
const char * appString = CFStringGetCStringPtr( appRef,
CFStringGetFastestEncoding( appRef ) );
CFRelease( appURL );
CFRelease( appRef );
s = tr_buildPath( appString, "Contents", "Resources", "web", NULL );
#elif defined( WIN32 )
#warning hey win32 people is this good or is there a better implementation of the next four lines
char appdata[MAX_PATH_LENGTH];
SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata );
s = tr_buildPath( appdata, "Transmission", NULL );
#else
/* SHGetFolderPath explicitly requires MAX_PATH length */
char dir[MAX_PATH];
/* Generally, Web interface should be stored in a Web subdir of
* calling executable dir. */
if( s == NULL ) {
/* First, we should check personal AppData/Transmission/Web */
SHGetFolderPath( NULL, CSIDL_COMMON_APPDATA, NULL, 0, dir );
s = tr_buildPath( dir, "Transmission", "Web", NULL );
if( !isClutchDir( s ) ) {
tr_free( s );
s = NULL;
}
}
if( s == NULL ) {
/* check personal AppData */
SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, dir );
s = tr_buildPath( dir, "Transmission", "Web", NULL );
if( !isClutchDir( s ) ) {
tr_free( s );
s = NULL;
}
}
if( s == NULL) {
/* check calling module place */
GetModuleFileName( GetModuleHandle( NULL ), dir, sizeof( dir ) );
s = tr_buildPath( dirname( dir ), "Web", NULL );
if( !isClutchDir( s ) ) {
tr_free( s );
s = NULL;
}
}
#else /* everyone else, follow the XDG spec */
tr_list *candidates = NULL, *l;
/* XDG_DATA_HOME should be the first in the list of candidates */
@ -573,7 +608,9 @@ tr_getClutchDir( const tr_session * session UNUSED )
}
tr_list_free( &candidates, tr_free );
#endif
}
}

View File

@ -62,7 +62,7 @@ typedef uint64_t tr_block_index_t;
* - otherwise, if we're running on Darwin,
* "$HOME/Library/Application Support/Transmission" is returned.
* - otherwise, if we're running on WIN32,
* "$CSIDL_APPDATA/Transmission" is returned.
* "$EXE_FOLDER/Transmission" is returned.
* - otherwise, if XDG_CONFIG_HOME is set,
* "$XDG_CONFIG_HOME/transmission" is returned.
* - lastly, $HOME/.config/transmission" is used.

View File

@ -55,6 +55,12 @@ static int messageQueuing = FALSE;
static tr_msg_list * messageQueue = NULL;
static tr_msg_list ** messageQueueTail = &messageQueue;
#ifndef WIN32
/* make null versions of these win32 functions */
static int IsDebuggerPresent( void ) { return FALSE; }
static void OutputDebugString( const void * unused UNUSED ) { }
#endif
void
tr_msgInit( void )
{
@ -156,6 +162,19 @@ tr_freeMessageList( tr_msg_list * list )
***
**/
static struct tm *
tr_localtime_r( time_t *_clock, struct tm *_result )
{
#ifdef HAVE_LOCALTIME_R
return localtime_r( _clock, _result );
#else
struct tm *p = localtime( _clock );
if( p )
*(_result) = *p;
return p;
#endif
}
char*
tr_getLogTimeStr( char * buf,
int buflen )
@ -169,11 +188,7 @@ tr_getLogTimeStr( char * buf,
now = time( NULL );
gettimeofday( &tv, NULL );
#ifdef WIN32
now_tm = *localtime( &now );
#else
localtime_r( &now, &now_tm );
#endif
tr_localtime_r( &now, &now_tm );
strftime( tmp, sizeof( tmp ), "%H:%M:%S", &now_tm );
milliseconds = (int)( tv.tv_usec / 1000 );
tr_snprintf( buf, buflen, "%s.%03d", tmp, milliseconds );
@ -189,11 +204,7 @@ tr_deepLog( const char * file,
... )
{
FILE * fp = tr_getLog( );
#ifdef WIN32
if( fp || IsDebuggerPresent( ) )
#else
if( fp )
#endif
{
va_list args;
char timestr[64];
@ -208,11 +219,9 @@ tr_deepLog( const char * file,
evbuffer_add_vprintf( buf, fmt, args );
va_end( args );
evbuffer_add_printf( buf, " (%s:%d)\n", base, line );
#ifdef WIN32
OutputDebugString( EVBUFFER_DATA( buf ) );
if(fp)
#endif
(void) fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp );
(void) fwrite( EVBUFFER_DATA( buf ), 1, EVBUFFER_LENGTH( buf ), fp );
tr_free( base );
evbuffer_free( buf );
@ -255,6 +264,8 @@ tr_msg( const char * file,
evbuffer_add_vprintf( buf, fmt, ap );
va_end( ap );
OutputDebugString( EVBUFFER_DATA( buf ) );
if( EVBUFFER_LENGTH( buf ) )
{
if( messageQueuing )