(trunk libT) part of rb07's win32 portability patches from ticket #3311

This commit is contained in:
Charles Kerr
2010-06-21 16:44:35 +00:00
parent 11ccd65373
commit 08628333d1
10 changed files with 42 additions and 16 deletions

View File

@@ -11,7 +11,7 @@
#include <stddef.h>
/* Windows DLL stuff */
#ifdef _WIN32
#if defined(WIN32) && !defined(STATICLIB)
# ifdef JSON_PARSER_DLL_EXPORTS
# define JSON_PARSER_DLL_API __declspec(dllexport)
# else

View File

@@ -18,6 +18,11 @@
#include <stdlib.h> /* realpath() */
#include <string.h>
#ifdef WIN32
#include <fcntl.h>
#define fsync(fd) _commit(fd)
#endif
#include <sys/types.h> /* stat() */
#include <sys/stat.h> /* stat() */
#include <locale.h>
@@ -1638,7 +1643,7 @@ tr_bencToFile( const tr_benc * top, tr_fmt_mode mode, const char * filename )
/* follow symlinks to find the "real" file, to make sure the temporary
* we build with mkstemp() is created on the right partition */
if( realpath( filename, buf ) != NULL )
if( tr_realpath( filename, buf ) != NULL )
filename = buf;
/* if the file already exists, try to move it out of the way & keep it as a backup */

View File

@@ -125,7 +125,7 @@ preallocateFileFull( const char * filename, uint64_t length )
#ifdef WIN32
HANDLE hFile = CreateFile( filename, GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0 );
HANDLE hFile = CreateFile( filename, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0 );
if( hFile != INVALID_HANDLE_VALUE )
{
LARGE_INTEGER li;

View File

@@ -346,7 +346,7 @@ sendYa( tr_handshake * handshake )
/* send it */
setReadState( handshake, AWAITING_YB );
tr_peerIoWrite( handshake->io, outbuf, walk-outbuf, FALSE );
tr_peerIoWrite( handshake->io, outbuf, walk - outbuf, FALSE );
}
static uint32_t

View File

@@ -11,6 +11,8 @@
*/
#ifdef WIN32
#include <w32api.h>
#define WINVER WindowsXP
#include <windows.h>
#include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_MYDOCUMENTS */
#else
@@ -436,7 +438,7 @@ tr_getDefaultConfigDir( const char * appname )
s = tr_buildPath( getHomeDir( ), "Library", "Application Support",
appname, NULL );
#elif defined( WIN32 )
char appdata[TR_MAX_PATH]; /* SHGetFolderPath() requires MAX_PATH */
char appdata[TR_PATH_MAX]; /* SHGetFolderPath() requires MAX_PATH */
SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata );
s = tr_buildPath( appdata, appname, NULL );
#elif defined( __HAIKU__ )

View File

@@ -26,8 +26,8 @@
#endif
#ifdef WIN32
#include <windows.h> /* MAX_PATH */
#define TR_PATH_MAX MAX_PATH
#include <windef.h> /* MAX_PATH */
#define TR_PATH_MAX (MAX_PATH + 1)
#else
#include <limits.h> /* PATH_MAX */
#ifdef PATH_MAX

View File

@@ -859,7 +859,7 @@ portTested( tr_session * session UNUSED,
if( response_code != 200 )
{
tr_snprintf( result, sizeof( result ), "http error %ld: %s",
tr_snprintf( result, sizeof( result ), "portTested: http error %ld: %s",
response_code, tr_webGetResponseStr( response_code ) );
}
else /* success */
@@ -901,14 +901,14 @@ gotNewBlocklist( tr_session * session,
if( response_code != 200 )
{
tr_snprintf( result, sizeof( result ), "http error %ld: %s",
tr_snprintf( result, sizeof( result ), "gotNewBlocklist: http error %ld: %s",
response_code, tr_webGetResponseStr( response_code ) );
}
else /* successfully fetched the blocklist... */
{
const char * configDir = tr_sessionGetConfigDir( session );
char * filename = tr_buildPath( configDir, "blocklist.tmp", NULL );
FILE * fp = fopen( filename, "w+" );
FILE * fp = fopen( filename, "wb+" );
if( fp == NULL )
{
@@ -1022,7 +1022,7 @@ gotMetadataFromURL( tr_session * session UNUSED,
else
{
char result[1024];
tr_snprintf( result, sizeof( result ), "http error %ld: %s",
tr_snprintf( result, sizeof( result ), "gotMetadataFromURL: http error %ld: %s",
response_code, tr_webGetResponseStr( response_code ) );
tr_idle_function_done( data->data, result );
}

View File

@@ -193,7 +193,7 @@ dht_bootstrap(void *closure)
tr_buildPath(cl->session->configDir, "dht.bootstrap", NULL);
if(bootstrap_file)
f = fopen(bootstrap_file, "r");
f = fopen(bootstrap_file, "rb");
if(f != NULL) {
tr_ninf("DHT", "Attempting manual bootstrap");
for(;;) {

View File

@@ -38,6 +38,8 @@
#include "event.h"
#ifdef WIN32
#include <w32api.h>
#define WINVER WindowsXP /* freeaddrinfo(),getaddrinfo(),getnameinfo() */
#include <direct.h> /* _getcwd */
#include <windows.h> /* Sleep */
#endif
@@ -1390,7 +1392,7 @@ tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed )
char * buf;
struct stat st;
off_t bytesLeft;
off_t buflen;
const off_t buflen = 1024 * 128; /* 128 KiB buffer */
/* make sure the old file exists */
if( stat( oldpath, &st ) ) {
@@ -1425,7 +1427,6 @@ tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed )
/* copy the file */
in = tr_open_file_for_scanning( oldpath );
out = tr_open_file_for_writing( newpath );
buflen = stat( newpath, &st ) ? 4096 : st.st_blksize;
buf = tr_valloc( buflen );
while( bytesLeft > 0 )
{
@@ -1488,3 +1489,16 @@ tr_valloc( size_t bufLen )
tr_dbg( "tr_valloc(%zu) allocating %zu bytes", bufLen, allocLen );
return buf;
}
char *
tr_realpath( const char * path, char * resolved_path )
{
#ifdef WIN32
/* From a message to the Mingw-msys list, Jun 2, 2005 by Mark Junker. */
if( GetFullPathNameA( path, TR_PATH_MAX, resolved_path, NULL ) == 0 )
return NULL;
return resolved_path;
#else
return realpath( path, resolved_path );
#endif
}

View File

@@ -98,8 +98,10 @@ extern "C" {
#endif
/* #define DISABLE_GETTEXT */
#if defined(TR_EMBEDDED) && !defined(DISABLE_GETTEXT)
#define DISABLE_GETTEXT
#ifndef DISABLE_GETTEXT
#if defined(WIN32) || defined(TR_EMBEDDED)
#define DISABLE_GETTEXT
#endif
#endif
#ifdef DISABLE_GETTEXT
const char * tr_strip_positional_args( const char * fmt );
@@ -546,6 +548,9 @@ static inline time_t tr_time( void ) { return transmission_now; }
/** @brief Private libtransmission function to update tr_time()'s counter */
static inline void tr_timeUpdate( time_t now ) { transmission_now = now; }
/** @brief Portability wrapper for realpath() that uses the system implementation if available */
char* tr_realpath( const char *path, char * resolved_path );
/***
****
***/