Changeset 10814


Ignore:
Timestamp:
Jun 21, 2010, 4:44:35 PM (12 years ago)
Author:
charles
Message:

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

Location:
trunk/libtransmission
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/JSON_parser.h

    r10492 r10814  
    1212
    1313/* Windows DLL stuff */
    14 #ifdef _WIN32
     14#if defined(WIN32) && !defined(STATICLIB)
    1515#       ifdef JSON_PARSER_DLL_EXPORTS
    1616#               define JSON_PARSER_DLL_API __declspec(dllexport)
  • trunk/libtransmission/bencode.c

    r10783 r10814  
    1818#include <stdlib.h> /* realpath() */
    1919#include <string.h>
     20
     21#ifdef WIN32
     22 #include <fcntl.h>
     23 #define fsync(fd) _commit(fd)
     24#endif
    2025
    2126#include <sys/types.h> /* stat() */
     
    16391644    /* follow symlinks to find the "real" file, to make sure the temporary
    16401645     * we build with mkstemp() is created on the right partition */
    1641     if( realpath( filename, buf ) != NULL )
     1646    if( tr_realpath( filename, buf ) != NULL )
    16421647        filename = buf;
    16431648
  • trunk/libtransmission/fdlimit.c

    r10811 r10814  
    126126#ifdef WIN32
    127127
    128     HANDLE hFile = CreateFile( filename, GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0 );
     128    HANDLE hFile = CreateFile( filename, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0 );
    129129    if( hFile != INVALID_HANDLE_VALUE )
    130130    {
  • trunk/libtransmission/handshake.c

    r10506 r10814  
    347347    /* send it */
    348348    setReadState( handshake, AWAITING_YB );
    349     tr_peerIoWrite( handshake->io, outbuf, walk-outbuf, FALSE );
     349    tr_peerIoWrite( handshake->io, outbuf, walk - outbuf, FALSE );
    350350}
    351351
  • trunk/libtransmission/platform.c

    r10736 r10814  
    1212
    1313#ifdef WIN32
     14 #include <w32api.h>
     15 #define WINVER  WindowsXP
    1416 #include <windows.h>
    1517 #include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_MYDOCUMENTS */
     
    437439                              appname, NULL );
    438440#elif defined( WIN32 )
    439             char appdata[TR_MAX_PATH]; /* SHGetFolderPath() requires MAX_PATH */
     441            char appdata[TR_PATH_MAX]; /* SHGetFolderPath() requires MAX_PATH */
    440442            SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, appdata );
    441443            s = tr_buildPath( appdata, appname, NULL );
  • trunk/libtransmission/platform.h

    r10634 r10814  
    2727
    2828#ifdef WIN32
    29  #include <windows.h> /* MAX_PATH */
    30  #define TR_PATH_MAX MAX_PATH
     29 #include <windef.h> /* MAX_PATH */
     30 #define TR_PATH_MAX (MAX_PATH + 1)
    3131#else
    3232 #include <limits.h> /* PATH_MAX */
  • trunk/libtransmission/rpcimpl.c

    r10798 r10814  
    860860    if( response_code != 200 )
    861861    {
    862         tr_snprintf( result, sizeof( result ), "http error %ld: %s",
     862        tr_snprintf( result, sizeof( result ), "portTested: http error %ld: %s",
    863863                     response_code, tr_webGetResponseStr( response_code ) );
    864864    }
     
    902902    if( response_code != 200 )
    903903    {
    904         tr_snprintf( result, sizeof( result ), "http error %ld: %s",
     904        tr_snprintf( result, sizeof( result ), "gotNewBlocklist: http error %ld: %s",
    905905                     response_code, tr_webGetResponseStr( response_code ) );
    906906    }
     
    909909        const char * configDir = tr_sessionGetConfigDir( session );
    910910        char * filename = tr_buildPath( configDir, "blocklist.tmp", NULL );
    911         FILE * fp = fopen( filename, "w+" );
     911        FILE * fp = fopen( filename, "wb+" );
    912912
    913913        if( fp == NULL )
     
    10231023    {
    10241024        char result[1024];
    1025         tr_snprintf( result, sizeof( result ), "http error %ld: %s",
     1025        tr_snprintf( result, sizeof( result ), "gotMetadataFromURL: http error %ld: %s",
    10261026                     response_code, tr_webGetResponseStr( response_code ) );
    10271027        tr_idle_function_done( data->data, result );
  • trunk/libtransmission/tr-dht.c

    r10623 r10814  
    194194
    195195        if(bootstrap_file)
    196             f = fopen(bootstrap_file, "r");
     196            f = fopen(bootstrap_file, "rb");
    197197        if(f != NULL) {
    198198            tr_ninf("DHT", "Attempting manual bootstrap");
  • trunk/libtransmission/utils.c

    r10783 r10814  
    3939
    4040#ifdef WIN32
     41 #include <w32api.h>
     42 #define WINVER WindowsXP /* freeaddrinfo(),getaddrinfo(),getnameinfo() */
    4143 #include <direct.h> /* _getcwd */
    4244 #include <windows.h> /* Sleep */
     
    13911393    struct stat st;
    13921394    off_t bytesLeft;
    1393     off_t buflen;
     1395    const off_t buflen = 1024 * 128; /* 128 KiB buffer */
    13941396
    13951397    /* make sure the old file exists */
     
    14261428    in = tr_open_file_for_scanning( oldpath );
    14271429    out = tr_open_file_for_writing( newpath );
    1428     buflen = stat( newpath, &st ) ? 4096 : st.st_blksize;
    14291430    buf = tr_valloc( buflen );
    14301431    while( bytesLeft > 0 )
     
    14891490    return buf;
    14901491}
     1492
     1493char *
     1494tr_realpath( const char * path, char * resolved_path )
     1495{
     1496#ifdef WIN32
     1497    /* From a message to the Mingw-msys list, Jun 2, 2005 by Mark Junker. */
     1498    if( GetFullPathNameA( path, TR_PATH_MAX, resolved_path, NULL ) == 0 )
     1499        return NULL;
     1500    return resolved_path;
     1501#else
     1502    return realpath( path, resolved_path );
     1503#endif
     1504}
  • trunk/libtransmission/utils.h

    r10736 r10814  
    9999
    100100/* #define DISABLE_GETTEXT */
    101 #if defined(TR_EMBEDDED) && !defined(DISABLE_GETTEXT)
    102  #define DISABLE_GETTEXT
     101#ifndef DISABLE_GETTEXT
     102 #if defined(WIN32) || defined(TR_EMBEDDED)
     103   #define DISABLE_GETTEXT
     104 #endif
    103105#endif
    104106#ifdef DISABLE_GETTEXT
     
    547549static inline void tr_timeUpdate( time_t now ) { transmission_now = now; }
    548550
     551/** @brief Portability wrapper for realpath() that uses the system implementation if available */
     552char* tr_realpath( const char *path, char * resolved_path );
     553
    549554/***
    550555****
Note: See TracChangeset for help on using the changeset viewer.