Changeset 14382


Ignore:
Timestamp:
Dec 13, 2014, 3:22:39 PM (6 years ago)
Author:
mikedld
Message:

Fix compilation on Windows

This should not affect non-Win32 platforms in any way.
As for Win32 (both MinGW and MSVC), this should hopefully allow for
unpatched compilation. Correct functioning is not yet guaranteed though.

Location:
trunk
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r14363 r14382  
    452452     have_msw="yes"
    453453     CXXFLAGS="$CXXFLAGS -mms-bitfields -mwin32 -mwindows"
    454      CPPFLAGS="$CPPFLAGS -DWIN32_LEAN_AND_MEAN"
     454     CPPFLAGS="$CPPFLAGS -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -DWIN32_LEAN_AND_MEAN"
     455     CPPFLAGS="$CPPFLAGS -D__USE_MINGW_ANSI_STDIO=1 -D__STDC_FORMAT_MACROS=1"
    455456     LIBS="$LIBS -liphlpapi -lshell32 -lws2_32"
    456457     transmissionlocaledir="locale"
  • trunk/daemon/daemon.c

    r14337 r14382  
    1212#include <stdlib.h> /* exit, atoi */
    1313
    14 #include <fcntl.h> /* open */
    1514#include <signal.h>
    1615#ifdef HAVE_SYSLOG
    1716#include <syslog.h>
    1817#endif
    19 #include <unistd.h> /* daemon */
     18
     19#ifdef _WIN32
     20 #include <process.h> /* getpid */
     21#else
     22 #include <fcntl.h> /* open */
     23 #include <unistd.h> /* daemon */
     24#endif
    2025
    2126#include <event2/buffer.h>
     
    172177    switch (sig)
    173178    {
     179#ifdef SIGHUP
    174180        case SIGHUP:
    175181        {
     
    201207            break;
    202208        }
     209#endif
    203210
    204211        default:
     
    434441    signal (SIGINT, gotsig);
    435442    signal (SIGTERM, gotsig);
    436 #ifndef _WIN32
     443#ifdef SIGHUP
    437444    signal (SIGHUP, gotsig);
    438445#endif
     
    616623    mySession = session;
    617624
     625#ifdef SIGHUP
    618626    /* If we got a SIGHUP during startup, process that now. */
    619627    if (seenHUP)
    620628        gotsig (SIGHUP);
     629#endif
    621630
    622631    /* maybe add a watchdir */
     
    694703
    695704    /* shutdown */
    696 #if HAVE_SYSLOG
     705#ifdef HAVE_SYSLOG
    697706    if (!foreground)
    698707    {
  • trunk/libtransmission/blocklist-test.c

    r14331 r14382  
    1111#include <stdio.h>
    1212#include <string.h> /* strlen () */
    13 #include <unistd.h> /* sync() */
    1413
    1514#include "transmission.h"
     
    4948  tr_sys_file_close (fd, NULL);
    5049
    51   sync ();
     50  libttest_sync ();
    5251}
    5352
  • trunk/libtransmission/fdlimit.c

    r14367 r14382  
    1313#include <string.h>
    1414
    15 #include <sys/time.h> /* getrlimit */
    16 #include <sys/resource.h> /* getrlimit */
     15#ifndef _WIN32
     16 #include <sys/time.h> /* getrlimit */
     17 #include <sys/resource.h> /* getrlimit */
     18#endif
    1719
    1820#include "transmission.h"
     
    356358  if (session->fdInfo == NULL)
    357359    {
    358       struct rlimit limit;
    359360      struct tr_fdInfo * i;
    360361      const int FILE_CACHE_SIZE = 32;
     
    365366      session->fdInfo = i;
    366367
     368#ifndef _WIN32
    367369      /* set the open-file limit to the largest safe size wrt FD_SETSIZE */
     370      struct rlimit limit;
    368371      if (!getrlimit (RLIMIT_NOFILE, &limit))
    369372        {
     
    378381            }
    379382        }
     383#endif
    380384    }
    381385}
     
    542546{
    543547  int fd;
    544   unsigned int len;
     548  socklen_t len;
    545549  struct tr_fdInfo * gFd;
    546550  struct sockaddr_storage sock;
  • trunk/libtransmission/file-win32.c

    r14369 r14382  
    393393  wchar_t * wide_path;
    394394  wchar_t * wide_ret = NULL;
    395   HANDLE handle;
     395  HANDLE handle = INVALID_HANDLE_VALUE;
    396396  DWORD wide_ret_size;
    397397
  • trunk/libtransmission/libtransmission-test.c

    r14359 r14382  
    99
    1010#include <assert.h>
     11#include <errno.h>
    1112#include <stdio.h>
    1213#include <stdlib.h> /* mkstemp() */
    13 
    14 #include <unistd.h>
     14#include <string.h> /* strcmp() */
     15
     16#ifndef _WIN32
     17 #include <unistd.h> /* sync() */
     18#endif
    1519
    1620#include "transmission.h"
     
    2125#include "torrent.h"
    2226#include "trevent.h"
     27#include "variant.h"
    2328#include "libtransmission-test.h"
    2429
     
    114119  return 0; /* All tests passed */
    115120}
    116 
    117 /***
    118 ****
    119 ***/
    120 
    121 #include <unistd.h> /* sync() */
    122 
    123 #include <errno.h>
    124 #include <string.h> /* strcmp() */
    125 
    126 #include "variant.h"
    127121
    128122/***
     
    399393    }
    400394
    401   sync ();
     395  libttest_sync ();
    402396  libttest_blockingTorrentVerify (tor);
    403397
     
    458452  tr_sys_file_close (fd, NULL);
    459453
    460   sync ();
     454  libttest_sync ();
    461455
    462456  errno = tmperr;
     
    493487  tr_sys_file_close (fd, NULL);
    494488
     489  libttest_sync ();
     490
     491  errno = tmperr;
     492}
     493
     494void
     495libttest_sync (void)
     496{
     497#ifndef _WIN32
    495498  sync ();
    496 
    497   errno = tmperr;
    498 }
     499#endif
     500}
  • trunk/libtransmission/libtransmission-test.h

    r14289 r14382  
    9292void         libtest_sandbox_destroy (const char * sandbox);
    9393
     94void         libttest_sync (void);
    9495
    9596#endif /* !LIBTRANSMISSION_TEST_H */
  • trunk/libtransmission/makemeta-test.c

    r14369 r14382  
    1414#include "file.h"
    1515#include "makemeta.h"
    16 
    17 #include <unistd.h> /* sync() */
    1816
    1917#include <stdlib.h> /* mktemp() */
     
    6462  /* now let's check our work: parse the  .torrent file */
    6563  ctor = tr_ctorNew (NULL);
    66   sync ();
     64  libttest_sync ();
    6765  tr_ctorSetMetainfoFromFile (ctor, torrent_file);
    6866  parse_result = tr_torrentParse (ctor, &inf);
     
    158156      totalSize += payloadSizes[i];
    159157    }
    160   sync ();
     158  libttest_sync ();
    161159
    162160  /* init the builder */
     
    185183  /* now let's check our work: parse the  .torrent file */
    186184  ctor = tr_ctorNew (NULL);
    187   sync ();
     185  libttest_sync ();
    188186  tr_ctorSetMetainfoFromFile (ctor, torrent_file);
    189187  parse_result = tr_torrentParse (ctor, &inf);
  • trunk/libtransmission/move-test.c

    r14365 r14382  
    1212#include <string.h> /* strcmp() */
    1313#include <stdio.h>
    14 
    15 #include <unistd.h> /* sync() */
    1614
    1715#include <event2/buffer.h>
     
    201199
    202200  /* confirm the filest really got moved */
    203   sync ();
     201  libttest_sync ();
    204202  for (i=0; i<tor->info.fileCount; ++i)
    205203    check_file_location (tor, i, tr_buildPath (target_dir, tor->info.files[i].name, NULL));
  • trunk/libtransmission/net.c

    r14347 r14382  
    3131
    3232#ifdef _WIN32
    33  #define _WIN32_WINNT   0x0501
    3433 #include <ws2tcpip.h>
    3534#else
  • trunk/libtransmission/net.h

    r14316 r14382  
    3939
    4040#ifdef _WIN32
     41 #undef  EADDRINUSE
    4142 #define EADDRINUSE              WSAEADDRINUSE
     43 #undef  ECONNREFUSED
    4244 #define ECONNREFUSED            WSAECONNREFUSED
     45 #undef  ECONNRESET
    4346 #define ECONNRESET              WSAECONNRESET
     47 #undef  EHOSTUNREACH
    4448 #define EHOSTUNREACH            WSAEHOSTUNREACH
     49 #undef  EINPROGRESS
    4550 #define EINPROGRESS             WSAEINPROGRESS
     51 #undef  ENOTCONN
    4652 #define ENOTCONN                WSAENOTCONN
     53 #undef  EWOULDBLOCK
    4754 #define EWOULDBLOCK             WSAEWOULDBLOCK
     55 #undef  EAFNOSUPPORT
    4856 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
     57 #undef  ENETUNREACH
    4958 #define ENETUNREACH             WSAENETUNREACH
    5059 #define sockerrno               WSAGetLastError ()
  • trunk/libtransmission/peer-common.h

    r14316 r14382  
    175175
    176176#ifdef _WIN32
     177 #undef  EMSGSIZE
    177178 #define EMSGSIZE WSAEMSGSIZE
    178179#endif
  • trunk/libtransmission/peer-io.c

    r14354 r14382  
    3131
    3232#ifdef _WIN32
     33 #undef  EAGAIN
    3334 #define EAGAIN       WSAEWOULDBLOCK
     35 #undef  EINTR
    3436 #define EINTR        WSAEINTR
     37 #undef  EINPROGRESS
    3538 #define EINPROGRESS  WSAEINPROGRESS
     39 #undef  EPIPE
    3640 #define EPIPE        WSAECONNRESET
    3741#endif
  • trunk/libtransmission/peer-mgr.c

    r14372 r14382  
    28962896        const int inc = maxIncrease * mult;
    28972897        maxPeers = s->maxPeers + inc;
    2898         tordbg (s, "time since last cancel is %lli -- increasing the "
     2898        tordbg (s, "time since last cancel is %"PRId64" -- increasing the "
    28992899                   "number of peers we're interested in by %d",
    29002900                   (long long)timeSinceCancel, inc);
  • trunk/libtransmission/platform-quota.c

    r14373 r14382  
    1111#include <stdlib.h>
    1212#include <string.h>
    13 #include <unistd.h> /* getuid() */
     13
    1414#include <event2/util.h> /* evutil_ascii_strcasecmp () */
    1515
    1616#ifndef _WIN32
     17 #include <unistd.h> /* getuid() */
    1718 #include <sys/types.h> /* types needed by quota.h */
    1819 #if defined(__FreeBSD__) || defined(__OpenBSD__)
  • trunk/libtransmission/platform.c

    r14348 r14382  
    1616#include <stdlib.h>
    1717#include <string.h>
    18 #include <unistd.h> /* getuid() */
    1918
    2019#ifdef __HAIKU__
     
    2322
    2423#ifdef _WIN32
    25  #include <w32api.h>
    26  #define WINVER  WindowsXP
     24 #include <process.h> /* _beginthreadex (), _endthreadex () */
    2725 #include <windows.h>
    2826 #include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_MYDOCUMENTS */
    2927#else
     28#include <unistd.h> /* getuid() */
    3029 #ifdef BUILD_MAC_CLIENT
    3130  #include <CoreFoundation/CoreFoundation.h>
     
    3736#endif
    3837
    39 #ifdef _WIN32
    40 #include <libgen.h> /* dirname() */
    41 #endif
    42 
    4338#include "transmission.h"
    4439#include "file.h"
     
    230225#ifdef _WIN32
    231226
    232 char *
     227static char *
    233228win32_get_special_folder (int folder_id)
    234229{
  • trunk/libtransmission/rename-test.c

    r14366 r14382  
    1212#include <stdio.h> /* fopen() */
    1313#include <string.h> /* strcmp() */
    14 
    15 #include <unistd.h> /* sync() */
    1614
    1715#include "transmission.h"
     
    203201  /* (while it's renamed: confirm that the .resume file remembers the changes) */
    204202  tr_torrentSaveResume (tor);
    205   sync ();
     203  libttest_sync ();
    206204  loaded = tr_torrentLoadResume (tor, ~0, ctor);
    207205  check_streq ("foobar", tr_torrentName(tor));
     
    255253  tr_free (path);
    256254
    257   sync ();
     255  libttest_sync ();
    258256}
    259257
     
    390388  tr_free (tmp);
    391389  tr_free (str);
    392   sync ();
     390  libttest_sync ();
    393391  libttest_blockingTorrentVerify (tor);
    394392  testFileExistsAndConsistsOfThisString (tor, 0, expected_contents[0]);
  • trunk/libtransmission/session.c

    r14354 r14382  
    1515
    1616#include <signal.h>
    17 #include <sys/types.h> /* umask () */
    18 #include <sys/stat.h> /* umask () */
     17
     18#ifndef _WIN32
     19 #include <sys/types.h> /* umask () */
     20 #include <sys/stat.h> /* umask () */
     21#endif
    1922
    2023#include <event2/dns.h> /* evdns_base_free () */
     
    772775    tr_logSetLevel (i);
    773776
     777#ifndef _WIN32
    774778  if (tr_variantDictFindInt (settings, TR_KEY_umask, &i))
    775779    {
     
    777781      umask (session->umask);
    778782    }
     783#endif
    779784
    780785  /* misc features */
  • trunk/libtransmission/torrent.c

    r14368 r14382  
    1010#include <errno.h> /* EINVAL */
    1111#include <signal.h> /* signal () */
     12
    1213#ifndef _WIN32
    1314 #include <sys/wait.h> /* wait () */
     15 #include <unistd.h> /* fork (), execvp (), _exit () */
    1416#else
    15  #include <process.h>
     17 #include <process.h> /* _spawnvpe () */
    1618#endif
    17 #include <unistd.h> /* fork (), execvp (), _exit () */
    1819
    1920#include <assert.h>
     
    20772078}
    20782079
     2080#ifndef _WIN32
     2081
    20792082static void
    20802083onSigCHLD (int i UNUSED)
    20812084{
    2082 #ifdef _WIN32
    2083 
    2084   _cwait (NULL, -1, WAIT_CHILD);
    2085 
    2086 #else
    2087 
    20882085  int rc;
    20892086  do
    20902087    rc = waitpid (-1, NULL, WNOHANG);
    20912088  while (rc>0 || (rc==-1 && errno==EINTR));
     2089}
    20922090
    20932091#endif
    2094 }
    20952092
    20962093static void
  • trunk/libtransmission/tr-dht.c

    r14355 r14382  
    3232/* posix */
    3333#include <signal.h> /* sig_atomic_t */
    34 #include <sys/time.h>
     34
    3535#ifdef _WIN32
    3636  #include <inttypes.h>
    37   #define _WIN32_WINNT  0x0501  /* freeaddrinfo (),getaddrinfo (),getnameinfo () */
    3837  #include <ws2tcpip.h>
    3938#else
     39  #include <sys/time.h>
    4040  #include <sys/types.h>
    4141  #include <sys/socket.h> /* socket (), bind () */
  • trunk/libtransmission/tr-lpd.c

    r14321 r14382  
    2828/* posix */
    2929#include <signal.h> /* sig_atomic_t */
    30 #include <sys/time.h>
    31 #include <unistd.h> /* close () */
    3230#include <ctype.h> /* toupper () */
     31
    3332#ifdef _WIN32
    34   #include <w32api.h>
    35   #define WINDOWS  WindowsXP  /* freeaddrinfo (),getaddrinfo (),getnameinfo () */
    3633  #include <inttypes.h>
    3734  #include <ws2tcpip.h>
    3835  typedef uint16_t in_port_t;                   /* all missing */
    3936#else
     37  #include <sys/time.h>
     38  #include <unistd.h> /* close () */
    4039  #include <sys/types.h>
    4140  #include <sys/socket.h> /* socket (), bind () */
     
    360359    {
    361360        const int save = errno;
    362         close (lpd_socket);
    363         close (lpd_socket2);
     361        evutil_closesocket (lpd_socket);
     362        evutil_closesocket (lpd_socket2);
    364363        lpd_socket = lpd_socket2 = -1;
    365364        session = NULL;
  • trunk/libtransmission/tr-udp.c

    r14187 r14382  
    2626#include <stdlib.h> /* malloc (), free () */
    2727
    28 #include <unistd.h> /* close () */
     28#ifdef _WIN32
     29 #include <io.h> /* dup2 () */
     30#else
     31 #include <unistd.h> /* dup2 () */
     32#endif
    2933
    3034#include <event2/event.h>
     
    163167        ss->udp6_socket = s;
    164168    } else {
     169        /* FIXME: dup2 doesn't work for sockets on Windows */
    165170        rc = dup2 (s, ss->udp6_socket);
    166171        if (rc < 0)
    167172            goto fail;
    168         close (s);
     173        tr_netCloseSocket (s);
    169174    }
    170175
     
    181186    tr_logAddNamedError ("UDP", "Couldn't rebind IPv6 socket");
    182187    if (s >= 0)
    183         close (s);
     188        tr_netCloseSocket (s);
    184189    if (ss->udp6_bound) {
    185190        free (ss->udp6_bound);
     
    262267    if (rc < 0) {
    263268        tr_logAddNamedError ("UDP", "Couldn't bind IPv4 socket");
    264         close (ss->udp_socket);
     269        tr_netCloseSocket (ss->udp_socket);
    265270        ss->udp_socket = -1;
    266271        goto ipv6;
  • trunk/libtransmission/tr-utp.c

    r14354 r14382  
    158158
    159159static void
    160 timer_callback (int s UNUSED, short type UNUSED, void *closure)
     160timer_callback (evutil_socket_t s UNUSED, short type UNUSED, void *closure)
    161161{
    162162    tr_session *ss = closure;
  • trunk/libtransmission/transmission.h

    r14316 r14382  
    3030#include <time.h> /* time_t */
    3131
    32 #ifdef _WIN32
    33  #define __USE_MINGW_ANSI_STDIO 1
    34  #define __STDC_FORMAT_MACROS 1
     32#ifdef _MSC_VER
     33 typedef intptr_t ssize_t;
    3534#endif
    3635
     
    4645
    4746#ifndef PRId64
    48  #ifdef _WIN32
     47 #if defined (_MSC_VER) || (defined (__MINGW32__) && !defined (__USE_MINGW_ANSI_STDIO))
    4948  #define PRId64 "I64"
    5049 #else
     
    5453
    5554#ifndef PRIu64
    56  #ifdef _WIN32
     55 #if defined (_MSC_VER) || (defined (__MINGW32__) && !defined (__USE_MINGW_ANSI_STDIO))
    5756  #define PRIu64 "I64u"
    5857 #else
     
    6261
    6362#ifndef PRIu32
    64  #ifdef _WIN32
     63 #if defined (_MSC_VER) || (defined (__MINGW32__) && !defined (__USE_MINGW_ANSI_STDIO))
    6564  #define PRIu32 "u"
    6665 #else
     
    7069
    7170#ifndef TR_PRIuSIZE
    72  #ifdef _MSC_VER
     71 #if defined (_MSC_VER) || (defined (__MINGW32__) && !defined (__USE_MINGW_ANSI_STDIO))
    7372  #define TR_PRIuSIZE "Iu"
    7473 #else
     
    7776#endif
    7877
    79 #if defined (_WIN32) && defined (_MSC_VER)
     78#if defined (_MSC_VER) && !defined (__cplusplus)
    8079 #define inline __inline
    8180#endif
  • trunk/libtransmission/trevent.c

    r14316 r14382  
    1414#include <signal.h>
    1515
     16#ifdef _WIN32
     17 #include <winsock2.h>
     18#else
     19 #include <unistd.h> /* read (), write (), pipe () */
     20#endif
     21
    1622#include <event2/dns.h>
    1723#include <event2/event.h>
     
    2228#include "session.h"
    2329
     30#include "transmission.h"
     31#include "platform.h" /* tr_lockLock () */
     32#include "trevent.h"
     33#include "utils.h"
     34
     35
    2436#ifdef _WIN32
    25 
    26 #include "utils.h"
    27 #include <winsock2.h>
    2837
    2938static int
     
    122131#endif
    123132
    124 #include <unistd.h> /* read (), write (), pipe () */
    125 
    126 #include "transmission.h"
    127 #include "platform.h" /* tr_lockLock () */
    128 #include "trevent.h"
    129 #include "utils.h"
    130 
    131133/***
    132134****
  • trunk/libtransmission/utils-test.c

    r14371 r14382  
    385385  check_streq ("3", buf);
    386386
     387#if !(defined (_MSC_VER) || (defined (__MINGW32__) && defined (__MSVCRT__)))
     388  /* FIXME: MSCVRT behaves differently in case of nan */
    387389  tr_snprintf (buf, sizeof (buf), "%.2f", tr_truncd (nan, 2));
    388390  check (strstr (buf, "nan") != NULL);
     391#endif
    389392
    390393  return 0;
  • trunk/libtransmission/utils.c

    r14368 r14382  
    2929#include <time.h> /* nanosleep () */
    3030
     31#ifdef _WIN32
     32 #include <windows.h> /* Sleep (), GetSystemTimeAsFileTime (), GetEnvironmentVariable () */
     33 #include <shellapi.h> /* CommandLineToArgv () */
     34#else
     35 #include <sys/time.h>
     36 #include <unistd.h> /* getpagesize () */
     37#endif
     38
    3139#ifdef HAVE_ICONV_OPEN
    3240 #include <iconv.h>
    3341#endif
    34 #include <sys/time.h>
    35 #include <unistd.h> /* getpagesize () */
    3642
    3743#include <event2/buffer.h>
    3844#include <event2/event.h>
    39 
    40 #ifdef _WIN32
    41  #include <w32api.h>
    42  #define WINVER WindowsXP /* freeaddrinfo (), getaddrinfo (), getnameinfo () */
    43  #include <windows.h> /* Sleep (), GetSystemTimeAsFileTime (), GetEnvironmentVariable () */
    44  #include <shellapi.h> /* CommandLineToArgv () */
    45 #endif
    4645
    4746#include "transmission.h"
     
    8281tr_gettimeofday (struct timeval * tv)
    8382{
    84 #ifdef _MSC_VER
    85 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
     83#ifdef _WIN32
     84#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
    8685
    8786  FILETIME ft;
     
    15171516  if (!pageSize)
    15181517    {
    1519 #ifdef HAVE_GETPAGESIZE
     1518#if defined (HAVE_GETPAGESIZE) && !defined (_WIN32)
    15201519      pageSize = (size_t) getpagesize ();
    15211520#else /* guess */
  • trunk/libtransmission/variant-test.c

    r14316 r14382  
    101101
    102102  /* string len is designed to overflow */
    103   n = tr_snprintf ((char*)buf, sizeof (buf), "%zu:boat", (size_t)(SIZE_MAX-2));
     103  n = tr_snprintf ((char*)buf, sizeof (buf), "%"TR_PRIuSIZE":boat", (size_t)(SIZE_MAX-2));
    104104  err = tr_bencParseStr (buf, buf+n, &end, &str, &len);
    105105  check_int_eq (EILSEQ, err);
Note: See TracChangeset for help on using the changeset viewer.