further win32 portability fixes from Spry
This commit is contained in:
parent
071c6733e5
commit
67282cb794
|
@ -150,5 +150,6 @@ version.h:
|
||||||
echo '#define PEERID_PREFIX "'@PEERID_PREFIX@'"' > version.h
|
echo '#define PEERID_PREFIX "'@PEERID_PREFIX@'"' > version.h
|
||||||
echo '#define USERAGENT_PREFIX "'@USERAGENT_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 "'`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 SHORT_VERSION_STRING "'@USERAGENT_PREFIX@'"' >> version.h
|
||||||
echo '#define LONG_VERSION_STRING "'@USERAGENT_PREFIX@' ('`svn info | grep "Revision" | awk -F': ' '{print $$2}'`')"' >> version.h
|
echo '#define LONG_VERSION_STRING "'@USERAGENT_PREFIX@' ('`svn info | grep "Revision" | awk -F': ' '{print $$2}'`')"' >> version.h
|
||||||
|
|
|
@ -489,6 +489,7 @@ tr_fdClose( void )
|
||||||
tr_lockFree( gFd->lock );
|
tr_lockFree( gFd->lock );
|
||||||
|
|
||||||
tr_free( gFd );
|
tr_free( gFd );
|
||||||
|
gFd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -28,19 +28,19 @@
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
typedef uint16_t tr_port_t;
|
typedef uint16_t tr_port_t;
|
||||||
#elif defined( __BEOS__ )
|
#elif defined( __BEOS__ )
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
typedef unsigned short tr_port_t;
|
typedef unsigned short tr_port_t;
|
||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
#else
|
#else
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
typedef in_port_t tr_port_t;
|
typedef in_port_t tr_port_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
|
@ -465,9 +465,9 @@ tr_getDefaultConfigDir( void )
|
||||||
s = tr_buildPath( getHomeDir( ), "Library",
|
s = tr_buildPath( getHomeDir( ), "Library",
|
||||||
"Application Support", "Transmission", NULL );
|
"Application Support", "Transmission", NULL );
|
||||||
#elif defined( WIN32 )
|
#elif defined( WIN32 )
|
||||||
char appdata[MAX_PATH_LENGTH];
|
char configDir[MAX_PATH_LENGTH];
|
||||||
SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata );
|
GetModuleFileName( GetModuleHandle( NULL ), configDir, sizeof( configDir ) );
|
||||||
s = tr_buildPath( appdata, "Transmission", NULL );
|
s = tr_buildPath( basename( configDir ), "Transmission", NULL );
|
||||||
#else
|
#else
|
||||||
if( ( s = getenv( "XDG_CONFIG_HOME" ) ) )
|
if( ( s = getenv( "XDG_CONFIG_HOME" ) ) )
|
||||||
s = tr_buildPath( s, "transmission", NULL );
|
s = tr_buildPath( s, "transmission", NULL );
|
||||||
|
@ -513,24 +513,59 @@ tr_getClutchDir( const tr_session * session UNUSED )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef SYS_DARWIN
|
#ifdef SYS_DARWIN
|
||||||
CFURLRef appURL = CFBundleCopyBundleURL(
|
|
||||||
CFBundleGetMainBundle( ) );
|
CFURLRef appURL = CFBundleCopyBundleURL( CFBundleGetMainBundle( ) );
|
||||||
CFStringRef appRef = CFURLCopyFileSystemPath(
|
CFStringRef appRef = CFURLCopyFileSystemPath( appURL,
|
||||||
appURL, kCFURLPOSIXPathStyle );
|
kCFURLPOSIXPathStyle );
|
||||||
const char * appString = CFStringGetCStringPtr(
|
const char * appString = CFStringGetCStringPtr( appRef,
|
||||||
appRef, CFStringGetFastestEncoding( appRef ) );
|
CFStringGetFastestEncoding( appRef ) );
|
||||||
CFRelease( appURL );
|
CFRelease( appURL );
|
||||||
CFRelease( appRef );
|
CFRelease( appRef );
|
||||||
|
|
||||||
s = tr_buildPath( appString, "Contents", "Resources", "web", NULL );
|
s = tr_buildPath( appString, "Contents", "Resources", "web", NULL );
|
||||||
|
|
||||||
#elif defined( WIN32 )
|
#elif defined( WIN32 )
|
||||||
|
|
||||||
#warning hey win32 people is this good or is there a better implementation of the next four lines
|
/* SHGetFolderPath explicitly requires MAX_PATH length */
|
||||||
char appdata[MAX_PATH_LENGTH];
|
char dir[MAX_PATH];
|
||||||
SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata );
|
|
||||||
s = tr_buildPath( appdata, "Transmission", NULL );
|
/* Generally, Web interface should be stored in a Web subdir of
|
||||||
#else
|
* 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;
|
tr_list *candidates = NULL, *l;
|
||||||
|
|
||||||
/* XDG_DATA_HOME should be the first in the list of candidates */
|
/* 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 );
|
tr_list_free( &candidates, tr_free );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ typedef uint64_t tr_block_index_t;
|
||||||
* - otherwise, if we're running on Darwin,
|
* - otherwise, if we're running on Darwin,
|
||||||
* "$HOME/Library/Application Support/Transmission" is returned.
|
* "$HOME/Library/Application Support/Transmission" is returned.
|
||||||
* - otherwise, if we're running on WIN32,
|
* - otherwise, if we're running on WIN32,
|
||||||
* "$CSIDL_APPDATA/Transmission" is returned.
|
* "$EXE_FOLDER/Transmission" is returned.
|
||||||
* - otherwise, if XDG_CONFIG_HOME is set,
|
* - otherwise, if XDG_CONFIG_HOME is set,
|
||||||
* "$XDG_CONFIG_HOME/transmission" is returned.
|
* "$XDG_CONFIG_HOME/transmission" is returned.
|
||||||
* - lastly, $HOME/.config/transmission" is used.
|
* - lastly, $HOME/.config/transmission" is used.
|
||||||
|
|
|
@ -55,6 +55,12 @@ static int messageQueuing = FALSE;
|
||||||
static tr_msg_list * messageQueue = NULL;
|
static tr_msg_list * messageQueue = NULL;
|
||||||
static tr_msg_list ** messageQueueTail = &messageQueue;
|
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
|
void
|
||||||
tr_msgInit( 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*
|
char*
|
||||||
tr_getLogTimeStr( char * buf,
|
tr_getLogTimeStr( char * buf,
|
||||||
int buflen )
|
int buflen )
|
||||||
|
@ -169,11 +188,7 @@ tr_getLogTimeStr( char * buf,
|
||||||
now = time( NULL );
|
now = time( NULL );
|
||||||
gettimeofday( &tv, NULL );
|
gettimeofday( &tv, NULL );
|
||||||
|
|
||||||
#ifdef WIN32
|
tr_localtime_r( &now, &now_tm );
|
||||||
now_tm = *localtime( &now );
|
|
||||||
#else
|
|
||||||
localtime_r( &now, &now_tm );
|
|
||||||
#endif
|
|
||||||
strftime( tmp, sizeof( tmp ), "%H:%M:%S", &now_tm );
|
strftime( tmp, sizeof( tmp ), "%H:%M:%S", &now_tm );
|
||||||
milliseconds = (int)( tv.tv_usec / 1000 );
|
milliseconds = (int)( tv.tv_usec / 1000 );
|
||||||
tr_snprintf( buf, buflen, "%s.%03d", tmp, milliseconds );
|
tr_snprintf( buf, buflen, "%s.%03d", tmp, milliseconds );
|
||||||
|
@ -189,11 +204,7 @@ tr_deepLog( const char * file,
|
||||||
... )
|
... )
|
||||||
{
|
{
|
||||||
FILE * fp = tr_getLog( );
|
FILE * fp = tr_getLog( );
|
||||||
#ifdef WIN32
|
|
||||||
if( fp || IsDebuggerPresent( ) )
|
if( fp || IsDebuggerPresent( ) )
|
||||||
#else
|
|
||||||
if( fp )
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char timestr[64];
|
char timestr[64];
|
||||||
|
@ -208,11 +219,9 @@ tr_deepLog( const char * file,
|
||||||
evbuffer_add_vprintf( buf, fmt, args );
|
evbuffer_add_vprintf( buf, fmt, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
evbuffer_add_printf( buf, " (%s:%d)\n", base, line );
|
evbuffer_add_printf( buf, " (%s:%d)\n", base, line );
|
||||||
#ifdef WIN32
|
|
||||||
OutputDebugString( EVBUFFER_DATA( buf ) );
|
OutputDebugString( EVBUFFER_DATA( buf ) );
|
||||||
if(fp)
|
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 );
|
tr_free( base );
|
||||||
evbuffer_free( buf );
|
evbuffer_free( buf );
|
||||||
|
@ -255,6 +264,8 @@ tr_msg( const char * file,
|
||||||
evbuffer_add_vprintf( buf, fmt, ap );
|
evbuffer_add_vprintf( buf, fmt, ap );
|
||||||
va_end( ap );
|
va_end( ap );
|
||||||
|
|
||||||
|
OutputDebugString( EVBUFFER_DATA( buf ) );
|
||||||
|
|
||||||
if( EVBUFFER_LENGTH( buf ) )
|
if( EVBUFFER_LENGTH( buf ) )
|
||||||
{
|
{
|
||||||
if( messageQueuing )
|
if( messageQueuing )
|
||||||
|
|
Loading…
Reference in New Issue