commit 5cf9167f919dfef964b1d149731ed04941e25ebf Author: Nick Mathewson nickm@torproject.org Date: Tue Jan 31 10:59:42 2012 -0500
Use the standard _WIN32, not the Torism MS_WINDOWS or deprecated WIN32
This commit is completely mechanical; I used this perl script to make it:
#!/usr/bin/perl -w -i.bak -p
if (/^\s*#/) { s/MS_WINDOWS/_WIN32/g; s/\bWIN32\b/_WIN32/g; } --- src/common/address.c | 10 ++-- src/common/compat.c | 62 +++++++++++----------- src/common/compat.h | 24 +++++----- src/common/compat_libevent.c | 4 +- src/common/crypto.c | 6 +- src/common/procmon.c | 10 ++-- src/common/tortls.c | 4 +- src/common/util.c | 64 ++++++++++++------------ src/common/util.h | 12 ++-- src/or/buffers.c | 4 +- src/or/config.c | 22 ++++---- src/or/connection.c | 4 +- src/or/control.c | 14 +++--- src/or/dns.c | 4 +- src/or/eventdns.c | 14 +++--- src/or/eventdns.h | 2 +- src/or/eventdns_tor.h | 6 +- src/or/main.c | 24 +++++----- src/or/ntmain.h | 2 +- src/or/or.h | 4 +- src/or/reasons.c | 2 +- src/or/transports.c | 16 +++--- src/test/test-child.c | 6 +- src/test/test.c | 4 +- src/test/test_microdesc.c | 4 +- src/test/test_util.c | 28 +++++----- src/tools/tor-fw-helper/tor-fw-helper-natpmp.c | 4 +- src/tools/tor-fw-helper/tor-fw-helper-upnp.c | 2 +- src/tools/tor-fw-helper/tor-fw-helper.c | 4 +- src/tools/tor-resolve.c | 2 +- src/win32/orconfig.h | 3 +- 31 files changed, 185 insertions(+), 186 deletions(-)
diff --git a/src/common/address.c b/src/common/address.c index e18ef95..17cda42 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -15,7 +15,7 @@ #include "torlog.h" #include "container.h"
-#ifdef MS_WINDOWS +#ifdef _WIN32 #include <process.h> #include <windows.h> #include <winsock2.h> @@ -275,7 +275,7 @@ tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr) ent = err ? NULL : &hent; #else ent = gethostbyname(name); -#ifdef MS_WINDOWS +#ifdef _WIN32 err = WSAGetLastError(); #else err = h_errno; @@ -291,7 +291,7 @@ tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr) } return 0; } -#ifdef MS_WINDOWS +#ifdef _WIN32 return (err == WSATRY_AGAIN) ? 1 : -1; #else return (err == TRY_AGAIN) ? 1 : -1; @@ -1101,7 +1101,7 @@ tor_addr_port_lookup(const char *s, tor_addr_t *addr_out, uint16_t *port_out) return -1; }
-#ifdef MS_WINDOWS +#ifdef _WIN32 typedef ULONG (WINAPI *GetAdaptersAddresses_fn_t)( ULONG, ULONG, PVOID, PIP_ADAPTER_ADDRESSES, PULONG); #endif @@ -1140,7 +1140,7 @@ get_interface_addresses_raw(int severity)
freeifaddrs(ifa); return result; -#elif defined(MS_WINDOWS) +#elif defined(_WIN32) /* Windows XP began to provide GetAdaptersAddresses. Windows 2000 had a "GetAdaptersInfo", but that's deprecated; let's just try GetAdaptersAddresses and fall back to connect+getsockname. diff --git a/src/common/compat.c b/src/common/compat.c index cd11203..64c0668 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -21,7 +21,7 @@
#include "compat.h"
-#ifdef MS_WINDOWS +#ifdef _WIN32 #include <process.h> #include <windows.h> #include <sys/locking.h> @@ -205,7 +205,7 @@ tor_munmap_file(tor_mmap_t *handle) munmap((char*)handle->data, handle->mapping_size); tor_free(handle); } -#elif defined(MS_WINDOWS) +#elif defined(_WIN32) tor_mmap_t * tor_mmap_file(const char *filename) { @@ -341,7 +341,7 @@ tor_vsnprintf(char *str, size_t size, const char *format, va_list args) return -1; /* no place for the NUL */ if (size > SIZE_T_CEILING) return -1; -#ifdef MS_WINDOWS +#ifdef _WIN32 r = _vsnprintf(str, size, format, args); #else r = vsnprintf(str, size, format, args); @@ -570,7 +570,7 @@ tor_strtok_r_impl(char *str, const char *sep, char **lasts) return start; }
-#ifdef MS_WINDOWS +#ifdef _WIN32 /** Take a filename and return a pointer to its final element. This * function is called on __FILE__ to fix a MSVC nit where __FILE__ * contains the full path to the file. This is bad, because it @@ -670,7 +670,7 @@ set_uint64(void *cp, uint64_t v) int replace_file(const char *from, const char *to) { -#ifndef MS_WINDOWS +#ifndef _WIN32 return rename(from,to); #else switch (file_status(to)) @@ -739,7 +739,7 @@ tor_lockfile_lock(const char *filename, int blocking, int *locked_out) return NULL; }
-#ifdef WIN32 +#ifdef _WIN32 _lseek(fd, 0, SEEK_SET); if (_locking(fd, blocking ? _LK_LOCK : _LK_NBLCK, 1) < 0) { if (errno != EACCES && errno != EDEADLOCK) @@ -788,7 +788,7 @@ tor_lockfile_unlock(tor_lockfile_t *lockfile) tor_assert(lockfile);
log_info(LD_FS, "Unlocking "%s"", lockfile->filename); -#ifdef WIN32 +#ifdef _WIN32 _lseek(lockfile->fd, 0, SEEK_SET); if (_locking(lockfile->fd, _LK_UNLCK, 1) < 0) { log_warn(LD_FS,"Error unlocking "%s": %s", lockfile->filename, @@ -824,7 +824,7 @@ tor_lockfile_unlock(tor_lockfile_t *lockfile) off_t tor_fd_getpos(int fd) { -#ifdef WIN32 +#ifdef _WIN32 return (off_t) _lseek(fd, 0, SEEK_CUR); #else return (off_t) lseek(fd, 0, SEEK_CUR); @@ -835,7 +835,7 @@ tor_fd_getpos(int fd) int tor_fd_seekend(int fd) { -#ifdef WIN32 +#ifdef _WIN32 return _lseek(fd, 0, SEEK_END) < 0 ? -1 : 0; #else return lseek(fd, 0, SEEK_END) < 0 ? -1 : 0; @@ -888,7 +888,7 @@ tor_close_socket(tor_socket_t s) * tor_close_socket to close sockets, and always using close() on * files. */ -#if defined(MS_WINDOWS) +#if defined(_WIN32) r = closesocket(s); #else r = close(s); @@ -909,7 +909,7 @@ tor_close_socket(tor_socket_t s) } else { int err = tor_socket_errno(-1); log_info(LD_NET, "Close returned an error: %s", tor_socket_strerror(err)); -#ifdef WIN32 +#ifdef _WIN32 if (err != WSAENOTSOCK) --n_sockets_open; #else @@ -1016,7 +1016,7 @@ get_n_open_sockets(void) void set_socket_nonblocking(tor_socket_t socket) { -#if defined(MS_WINDOWS) +#if defined(_WIN32) unsigned long nonblocking = 1; ioctlsocket(socket, FIONBIO, (unsigned long*) &nonblocking); #else @@ -1045,7 +1045,7 @@ int tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2]) { //don't use win32 socketpairs (they are always bad) -#if defined(HAVE_SOCKETPAIR) && !defined(MS_WINDOWS) +#if defined(HAVE_SOCKETPAIR) && !defined(_WIN32) int r; #ifdef SOCK_CLOEXEC type |= SOCK_CLOEXEC; @@ -1089,7 +1089,7 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2]) || family != AF_UNIX #endif ) { -#ifdef MS_WINDOWS +#ifdef _WIN32 return -WSAEAFNOSUPPORT; #else return -EAFNOSUPPORT; @@ -1149,7 +1149,7 @@ tor_socketpair(int family, int type, int protocol, tor_socket_t fd[2]) return 0;
abort_tidy_up_and_fail: -#ifdef MS_WINDOWS +#ifdef _WIN32 saved_errno = WSAECONNABORTED; #else saved_errno = ECONNABORTED; /* I hope this is portable and appropriate. */ @@ -1191,7 +1191,7 @@ set_max_file_descriptors(rlim_t limit, int *max_out) #if defined(CYGWIN) || defined(__CYGWIN__) const char *platform = "Cygwin"; const unsigned long MAX_CONNECTIONS = 3200; -#elif defined(MS_WINDOWS) +#elif defined(_WIN32) const char *platform = "Windows"; const unsigned long MAX_CONNECTIONS = 15000; #else @@ -1274,7 +1274,7 @@ set_max_file_descriptors(rlim_t limit, int *max_out) return 0; }
-#ifndef MS_WINDOWS +#ifndef _WIN32 /** Log details of current user and group credentials. Return 0 on * success. Logs and return -1 on failure. */ @@ -1380,7 +1380,7 @@ log_credential_status(void) int switch_id(const char *user) { -#ifndef MS_WINDOWS +#ifndef _WIN32 struct passwd *pw = NULL; uid_t old_uid; gid_t old_gid; @@ -1591,7 +1591,7 @@ get_parent_directory(char *fname) char *cp; int at_end = 1; tor_assert(fname); -#ifdef MS_WINDOWS +#ifdef _WIN32 /* If we start with, say, c:, then don't consider that the start of the path */ if (fname[0] && fname[1] == ':') { @@ -1608,7 +1608,7 @@ get_parent_directory(char *fname) at_end = 1; while (--cp > fname) { int is_sep = (*cp == '/' -#ifdef MS_WINDOWS +#ifdef _WIN32 || *cp == '\' #endif ); @@ -1628,7 +1628,7 @@ get_parent_directory(char *fname) char * make_path_absolute(char *fname) { -#ifdef MS_WINDOWS +#ifdef _WIN32 char *absfname_malloced = _fullpath(NULL, fname, 1);
/* We don't want to assume that tor_free can free a string allocated @@ -1900,7 +1900,7 @@ tor_lookup_hostname(const char *name, uint32_t *addr) void tor_init_weak_random(unsigned seed) { -#ifdef MS_WINDOWS +#ifdef _WIN32 srand(seed); #else srandom(seed); @@ -1913,7 +1913,7 @@ tor_init_weak_random(unsigned seed) long tor_weak_random(void) { -#ifdef MS_WINDOWS +#ifdef _WIN32 return rand(); #else return random(); @@ -1942,7 +1942,7 @@ get_uname(void) } else #endif { -#ifdef MS_WINDOWS +#ifdef _WIN32 OSVERSIONINFOEX info; int i; const char *plat = NULL; @@ -2144,7 +2144,7 @@ spawn_exit(void) static int compute_num_cpus_impl(void) { -#ifdef MS_WINDOWS +#ifdef _WIN32 SYSTEM_INFO info; memset(&info, 0, sizeof(info)); GetSystemInfo(&info); @@ -2192,7 +2192,7 @@ compute_num_cpus(void) void tor_gettimeofday(struct timeval *timeval) { -#ifdef MS_WINDOWS +#ifdef _WIN32 /* Epoch bias copied from perl: number of units between windows epoch and * Unix epoch. */ #define EPOCH_BIAS U64_LITERAL(116444736000000000) @@ -2237,7 +2237,7 @@ tor_gettimeofday(struct timeval *timeval) return; }
-#if defined(TOR_IS_MULTITHREADED) && !defined(MS_WINDOWS) +#if defined(TOR_IS_MULTITHREADED) && !defined(_WIN32) /** Defined iff we need to add locks when defining fake versions of reentrant * versions of time-related functions. */ #define TIME_FNS_NEED_LOCKS @@ -2781,7 +2781,7 @@ in_main_thread(void) * should call tor_socket_errno <em>at most once</em> on the failing * socket to get the error. */ -#if defined(MS_WINDOWS) +#if defined(_WIN32) int tor_socket_errno(tor_socket_t sock) { @@ -2797,7 +2797,7 @@ tor_socket_errno(tor_socket_t sock) } #endif
-#if defined(MS_WINDOWS) +#if defined(_WIN32) #define E(code, s) { code, (s " [" #code " ]") } struct { int code; const char *msg; } windows_socket_errors[] = { E(WSAEINTR, "Interrupted function call"), @@ -2879,7 +2879,7 @@ tor_socket_strerror(int e) int network_init(void) { -#ifdef MS_WINDOWS +#ifdef _WIN32 /* This silly exercise is necessary before windows will allow * gethostbyname to work. */ WSADATA WSAData; @@ -2901,7 +2901,7 @@ network_init(void) return 0; }
-#ifdef MS_WINDOWS +#ifdef _WIN32 /** Return a newly allocated string describing the windows system error code * <b>err</b>. Note that error codes are different from errno. Error codes * come from GetLastError() when a winapi call fails. errno is set only when diff --git a/src/common/compat.h b/src/common/compat.h index 4329d45..fa1ef90 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -8,7 +8,7 @@
#include "orconfig.h" #include "torint.h" -#ifdef MS_WINDOWS +#ifdef _WIN32 #ifndef WIN32_WINNT #define WIN32_WINNT 0x400 #endif @@ -35,7 +35,7 @@ #ifdef HAVE_STRING_H #include <string.h> #endif -#if defined(HAVE_PTHREAD_H) && !defined(MS_WINDOWS) +#if defined(HAVE_PTHREAD_H) && !defined(_WIN32) #include <pthread.h> #endif #include <stdarg.h> @@ -89,7 +89,7 @@ #endif
/* inline is __inline on windows. */ -#ifdef MS_WINDOWS +#ifdef _WIN32 #define INLINE __inline #else #define INLINE inline @@ -196,7 +196,7 @@ extern INLINE double U64_TO_DBL(uint64_t x) { #endif
/* ===== String compatibility */ -#ifdef MS_WINDOWS +#ifdef _WIN32 /* Windows names string functions differently from most other platforms. */ #define strncasecmp _strnicmp #define strcasecmp _stricmp @@ -249,7 +249,7 @@ typedef struct tor_mmap_t { #ifdef HAVE_SYS_MMAN_H size_t mapping_size; /**< Size of the actual mapping. (This is this file * size, rounded up to the nearest page.) */ -#elif defined MS_WINDOWS +#elif defined _WIN32 HANDLE file_handle; HANDLE mmap_handle; #endif @@ -307,7 +307,7 @@ char *tor_strtok_r_impl(char *str, const char *sep, char **lasts); #define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts) #endif
-#ifdef MS_WINDOWS +#ifdef _WIN32 #define _SHORT_FILE_ (tor_fix_source_file(__FILE__)) const char *tor_fix_source_file(const char *fname); #else @@ -386,7 +386,7 @@ void tor_lockfile_unlock(tor_lockfile_t *lockfile); off_t tor_fd_getpos(int fd); int tor_fd_seekend(int fd);
-#ifdef MS_WINDOWS +#ifdef _WIN32 #define PATH_SEPARATOR "\" #else #define PATH_SEPARATOR "/" @@ -398,7 +398,7 @@ int tor_fd_seekend(int fd); typedef int socklen_t; #endif
-#ifdef MS_WINDOWS +#ifdef _WIN32 /* XXX Actually, this should arguably be SOCKET; we use intptr_t here so that * any inadvertant checks for the socket being <= 0 or > 0 will probably * still work. */ @@ -499,7 +499,7 @@ int network_init(void); * errnos against expected values, and use tor_socket_errno to find * the actual errno after a socket operation fails. */ -#if defined(MS_WINDOWS) +#if defined(_WIN32) /** Return true if e is EAGAIN or the local equivalent. */ #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == WSAEWOULDBLOCK) /** Return true if e is EINPROGRESS or the local equivalent. */ @@ -584,7 +584,7 @@ char *make_path_absolute(char *fname); int spawn_func(void (*func)(void *), void *data); void spawn_exit(void) ATTR_NORETURN;
-#if defined(ENABLE_THREADS) && defined(MS_WINDOWS) +#if defined(ENABLE_THREADS) && defined(_WIN32) #define USE_WIN32_THREADS #define TOR_IS_MULTITHREADED 1 #elif (defined(ENABLE_THREADS) && defined(HAVE_PTHREAD_H) && \ @@ -666,14 +666,14 @@ void tor_cond_signal_all(tor_cond_t *cond); #endif
/* Platform-specific helpers. */ -#ifdef MS_WINDOWS +#ifdef _WIN32 char *format_win32_error(DWORD err); #endif
/*for some reason my compiler doesn't have these version flags defined a nice homework assignment for someone one day is to define the rest*/ //these are the values as given on MSDN -#ifdef MS_WINDOWS +#ifdef _WIN32
#ifndef VER_SUITE_EMBEDDEDNT #define VER_SUITE_EMBEDDEDNT 0x00000040 diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c index 0cedef8..70e3baf 100644 --- a/src/common/compat_libevent.c +++ b/src/common/compat_libevent.c @@ -205,7 +205,7 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg) cfg = event_config_new(); tor_assert(cfg);
-#if defined(MS_WINDOWS) && defined(USE_BUFFEREVENTS) +#if defined(_WIN32) && defined(USE_BUFFEREVENTS) if (! torcfg->disable_iocp) { evthread_use_windows_threads(); event_config_set_flag(cfg, EVENT_BASE_FLAG_STARTUP_IOCP); @@ -241,7 +241,7 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg) /* This could be a socketpair() failure, which can happen sometimes on * windows boxes with obnoxious firewall rules. Downgrade and try * again. */ -#if defined(MS_WINDOWS) && defined(USE_BUFFEREVENTS) +#if defined(_WIN32) && defined(USE_BUFFEREVENTS) if (torcfg->disable_iocp == 0) { log_warn(LD_GENERAL, "Unable to initialize Libevent. Trying again " "with IOCP disabled."); diff --git a/src/common/crypto.c b/src/common/crypto.c index 6bc54fc..380dcf0 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -12,7 +12,7 @@
#include "orconfig.h"
-#ifdef MS_WINDOWS +#ifdef _WIN32 #ifndef WIN32_WINNT #define WIN32_WINNT 0x400 #endif @@ -2409,7 +2409,7 @@ crypto_seed_rng(int startup) int rand_poll_status = 0;
/* local variables */ -#ifdef MS_WINDOWS +#ifdef _WIN32 unsigned char buf[ADD_ENTROPY]; static int provider_set = 0; static HCRYPTPROV provider; @@ -2431,7 +2431,7 @@ crypto_seed_rng(int startup) log_warn(LD_CRYPTO, "RAND_poll() failed."); }
-#ifdef MS_WINDOWS +#ifdef _WIN32 if (!provider_set) { if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { diff --git a/src/common/procmon.c b/src/common/procmon.c index 5c10e9a..85d2a2f 100644 --- a/src/common/procmon.c +++ b/src/common/procmon.c @@ -21,7 +21,7 @@ #include <errno.h> #endif
-#ifdef MS_WINDOWS +#ifdef _WIN32 #include <windows.h>
/* Windows does not define pid_t, but _getpid() returns an int. */ @@ -91,7 +91,7 @@ struct tor_process_monitor_t { * polls. */ pid_t pid;
-#ifdef MS_WINDOWS +#ifdef _WIN32 /** Windows-only: Should we poll hproc? If false, poll pid * instead. */ int poll_hproc; @@ -192,7 +192,7 @@ tor_process_monitor_new(struct event_base *base,
procmon->pid = ppspec.pid;
-#ifdef MS_WINDOWS +#ifdef _WIN32 procmon->hproc = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, procmon->pid); @@ -246,7 +246,7 @@ tor_process_monitor_poll_cb(evutil_socket_t unused1, short unused2,
tor_assert(procmon != NULL);
-#ifdef MS_WINDOWS +#ifdef _WIN32 if (procmon->poll_hproc) { DWORD exit_code; if (!GetExitCodeProcess(procmon->hproc, &exit_code)) { @@ -323,7 +323,7 @@ tor_process_monitor_free(tor_process_monitor_t *procmon) if (procmon == NULL) return;
-#ifdef MS_WINDOWS +#ifdef _WIN32 if (procmon->hproc != NULL) CloseHandle(procmon->hproc); #endif diff --git a/src/common/tortls.c b/src/common/tortls.c index 570dd00..26d3714 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -21,7 +21,7 @@ #endif
#include <assert.h> -#ifdef MS_WINDOWS /*wrkard for dtls1.h >= 0.9.8m of "#include <winsock.h>"*/ +#ifdef _WIN32 /*wrkard for dtls1.h >= 0.9.8m of "#include <winsock.h>"*/ #ifndef WIN32_WINNT #define WIN32_WINNT 0x400 #endif @@ -333,7 +333,7 @@ tls_log_errors(tor_tls_t *tls, int severity, int domain, const char *doing) static int tor_errno_to_tls_error(int e) { -#if defined(MS_WINDOWS) +#if defined(_WIN32) switch (e) { case WSAECONNRESET: // most common return TOR_TLS_ERROR_CONNRESET; diff --git a/src/common/util.c b/src/common/util.c index 40efff0..ac37f1b 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -26,7 +26,7 @@ #include "container.h" #include "address.h"
-#ifdef MS_WINDOWS +#ifdef _WIN32 #include <io.h> #include <direct.h> #include <process.h> @@ -915,7 +915,7 @@ tor_parse_uint64(const char *s, int base, uint64_t min,
#ifdef HAVE_STRTOULL r = (uint64_t)strtoull(s, &endptr, base); -#elif defined(MS_WINDOWS) +#elif defined(_WIN32) #if defined(_MSC_VER) && _MSC_VER < 1300 tor_assert(base <= 10); r = (uint64_t)_atoi64(s); @@ -1731,7 +1731,7 @@ read_all(tor_socket_t fd, char *buf, size_t count, int isSocket) static void clean_name_for_stat(char *name) { -#ifdef MS_WINDOWS +#ifdef _WIN32 size_t len = strlen(name); if (!len) return; @@ -1790,7 +1790,7 @@ check_private_dir(const char *dirname, cpd_check_t check, int r; struct stat st; char *f; -#ifndef MS_WINDOWS +#ifndef _WIN32 int mask; struct passwd *pw = NULL; uid_t running_uid; @@ -1812,7 +1812,7 @@ check_private_dir(const char *dirname, cpd_check_t check, } if (check & CPD_CREATE) { log_info(LD_GENERAL, "Creating directory %s", dirname); -#if defined (MS_WINDOWS) && !defined (WINCE) +#if defined (_WIN32) && !defined (WINCE) r = mkdir(dirname); #else r = mkdir(dirname, 0700); @@ -1834,7 +1834,7 @@ check_private_dir(const char *dirname, cpd_check_t check, log_warn(LD_FS, "%s is not a directory", dirname); return -1; } -#ifndef MS_WINDOWS +#ifndef _WIN32 if (effective_user) { /* Look up the user and group information. * If we have a problem, bail out. */ @@ -1921,7 +1921,7 @@ check_private_dir(const char *dirname, cpd_check_t check, int write_str_to_file(const char *fname, const char *str, int bin) { -#ifdef MS_WINDOWS +#ifdef _WIN32 if (!bin && strchr(str, '\r')) { log_warn(LD_BUG, "We're writing a text string that already contains a CR."); @@ -2263,7 +2263,7 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out) } string[r] = '\0'; /* NUL-terminate the result. */
-#ifdef MS_WINDOWS +#ifdef _WIN32 if (!bin && strchr(string, '\r')) { log_debug(LD_FS, "We didn't convert CRLF to LF as well as we hoped " "when reading %s. Coping.", @@ -2544,7 +2544,7 @@ char * expand_filename(const char *filename) { tor_assert(filename); -#ifdef MS_WINDOWS +#ifdef _WIN32 return tor_strdup(filename); #else if (*filename == '~') { @@ -2780,7 +2780,7 @@ smartlist_t * tor_listdir(const char *dirname) { smartlist_t *result; -#ifdef MS_WINDOWS +#ifdef _WIN32 char *pattern=NULL; TCHAR tpattern[MAX_PATH] = {0}; char name[MAX_PATH] = {0}; @@ -2843,7 +2843,7 @@ path_is_relative(const char *filename) { if (filename && filename[0] == '/') return 0; -#ifdef MS_WINDOWS +#ifdef _WIN32 else if (filename && filename[0] == '\') return 0; else if (filename && strlen(filename)>3 && TOR_ISALPHA(filename[0]) && @@ -2858,7 +2858,7 @@ path_is_relative(const char *filename) * Process helpers * ===== */
-#ifndef MS_WINDOWS +#ifndef _WIN32 /* Based on code contributed by christian grothoff */ /** True iff we've called start_daemon(). */ static int start_daemon_called = 0; @@ -2995,7 +2995,7 @@ write_pidfile(char *filename) log_warn(LD_FS, "Unable to open "%s" for writing: %s", filename, strerror(errno)); } else { -#ifdef MS_WINDOWS +#ifdef _WIN32 fprintf(pidfile, "%d\n", (int)_getpid()); #else fprintf(pidfile, "%d\n", (int)getpid()); @@ -3004,7 +3004,7 @@ write_pidfile(char *filename) } }
-#ifdef MS_WINDOWS +#ifdef _WIN32 HANDLE load_windows_system_library(const TCHAR *library_name) { @@ -3191,7 +3191,7 @@ format_helper_exit_status(unsigned char child_state, int saved_errno, int tor_terminate_process(process_handle_t *process_handle) { -#ifdef MS_WINDOWS +#ifdef _WIN32 if (tor_get_exit_code(process_handle, 0, NULL) == PROCESS_EXIT_RUNNING) { HANDLE handle; /* If the signal is outside of what GenerateConsoleCtrlEvent can use, @@ -3217,14 +3217,14 @@ tor_terminate_process(process_handle_t *process_handle) int tor_process_get_pid(process_handle_t *process_handle) { -#ifdef MS_WINDOWS +#ifdef _WIN32 return (int) process_handle->pid.dwProcessId; #else return (int) process_handle->pid; #endif }
-#ifdef MS_WINDOWS +#ifdef _WIN32 HANDLE tor_process_get_stdout_pipe(process_handle_t *process_handle) { @@ -3243,7 +3243,7 @@ process_handle_new(void) { process_handle_t *out = tor_malloc_zero(sizeof(process_handle_t));
-#ifndef MS_WINDOWS +#ifndef _WIN32 out->stdout_pipe = -1; out->stderr_pipe = -1; #endif @@ -3284,14 +3284,14 @@ process_handle_new(void) */ int tor_spawn_background(const char *const filename, const char **argv, -#ifdef MS_WINDOWS +#ifdef _WIN32 LPVOID envp, #else const char **envp, #endif process_handle_t **process_handle_out) { -#ifdef MS_WINDOWS +#ifdef _WIN32 HANDLE stdout_pipe_read = NULL; HANDLE stdout_pipe_write = NULL; HANDLE stderr_pipe_read = NULL; @@ -3393,7 +3393,7 @@ tor_spawn_background(const char *const filename, const char **argv, /* TODO: Close pipes on exit */ *process_handle_out = process_handle; return status; -#else // MS_WINDOWS +#else // _WIN32 pid_t pid; int stdout_pipe[2]; int stderr_pipe[2]; @@ -3574,7 +3574,7 @@ tor_spawn_background(const char *const filename, const char **argv,
*process_handle_out = process_handle; return process_handle->status; -#endif // MS_WINDOWS +#endif // _WIN32 }
/** Destroy all resources allocated by the process handle in @@ -3600,7 +3600,7 @@ tor_process_handle_destroy(process_handle_t *process_handle,
process_handle->status = PROCESS_STATUS_NOTRUNNING;
-#ifdef MS_WINDOWS +#ifdef _WIN32 if (process_handle->stdout_pipe) CloseHandle(process_handle->stdout_pipe);
@@ -3632,7 +3632,7 @@ int tor_get_exit_code(const process_handle_t *process_handle, int block, int *exit_code) { -#ifdef MS_WINDOWS +#ifdef _WIN32 DWORD retval; BOOL success;
@@ -3687,12 +3687,12 @@ tor_get_exit_code(const process_handle_t *process_handle,
if (exit_code != NULL) *exit_code = WEXITSTATUS(stat_loc); -#endif // MS_WINDOWS +#endif // _WIN32
return PROCESS_EXIT_EXITED; }
-#ifdef MS_WINDOWS +#ifdef _WIN32 /** Read from a handle <b>h</b> into <b>buf</b>, up to <b>count</b> bytes. If * <b>hProcess</b> is NULL, the function will return immediately if there is * nothing more to read. Otherwise <b>hProcess</b> should be set to the handle @@ -3814,7 +3814,7 @@ ssize_t tor_read_all_from_process_stdout(const process_handle_t *process_handle, char *buf, size_t count) { -#ifdef MS_WINDOWS +#ifdef _WIN32 return tor_read_all_handle(process_handle->stdout_pipe, buf, count, process_handle); #else @@ -3828,7 +3828,7 @@ ssize_t tor_read_all_from_process_stderr(const process_handle_t *process_handle, char *buf, size_t count) { -#ifdef MS_WINDOWS +#ifdef _WIN32 return tor_read_all_handle(process_handle->stderr_pipe, buf, count, process_handle); #else @@ -3890,7 +3890,7 @@ tor_split_lines(smartlist_t *sl, char *buf, int len) return smartlist_len(sl); }
-#ifdef MS_WINDOWS +#ifdef _WIN32 /** Read from stream, and send lines to log at the specified log level. * Returns -1 if there is a error reading, and 0 otherwise. * If the generated stream is flushed more often than on new lines, or @@ -4103,7 +4103,7 @@ tor_check_port_forwarding(const char *filename, int dir_port, int or_port, child_handle = NULL; }
-#ifdef MS_WINDOWS +#ifdef _WIN32 /* Passing NULL as lpApplicationName makes Windows search for the .exe */ status = tor_spawn_background(NULL, argv, NULL, &child_handle); #else @@ -4126,7 +4126,7 @@ tor_check_port_forwarding(const char *filename, int dir_port, int or_port, if (child_handle && PROCESS_STATUS_RUNNING == child_handle->status) { /* Read from stdout/stderr and log result */ retval = 0; -#ifdef MS_WINDOWS +#ifdef _WIN32 stdout_status = log_from_handle(child_handle->stdout_pipe, LOG_INFO); stderr_status = log_from_handle(child_handle->stderr_pipe, LOG_WARN); /* If we got this far (on Windows), the process started */ @@ -4146,7 +4146,7 @@ tor_check_port_forwarding(const char *filename, int dir_port, int or_port, if (-1 == stdout_status || -1 == stderr_status) /* There was a failure */ retval = -1; -#ifdef MS_WINDOWS +#ifdef _WIN32 else if (!child_handle || tor_get_exit_code(child_handle, 0, NULL) != PROCESS_EXIT_RUNNING) { /* process has exited or there was an error */ diff --git a/src/common/util.h b/src/common/util.h index b15b1ea..1bad24b 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -364,7 +364,7 @@ void tor_check_port_forwarding(const char *filename,
typedef struct process_handle_t process_handle_t; int tor_spawn_background(const char *const filename, const char **argv, -#ifdef MS_WINDOWS +#ifdef _WIN32 LPVOID envp, #else const char **envp, @@ -373,7 +373,7 @@ int tor_spawn_background(const char *const filename, const char **argv,
#define SPAWN_ERROR_MESSAGE "ERR: Failed to spawn background process - code "
-#ifdef MS_WINDOWS +#ifdef _WIN32 HANDLE load_windows_system_library(const TCHAR *library_name); #endif
@@ -388,7 +388,7 @@ HANDLE load_windows_system_library(const TCHAR *library_name); /*DOCDOC*/ struct process_handle_t { int status; -#ifdef MS_WINDOWS +#ifdef _WIN32 HANDLE stdout_pipe; HANDLE stderr_pipe; PROCESS_INFORMATION pid; @@ -398,7 +398,7 @@ struct process_handle_t { FILE *stdout_handle; FILE *stderr_handle; pid_t pid; -#endif // MS_WINDOWS +#endif // _WIN32 }; #endif
@@ -409,7 +409,7 @@ struct process_handle_t { int tor_get_exit_code(const process_handle_t *process_handle, int block, int *exit_code); int tor_split_lines(struct smartlist_t *sl, char *buf, int len); -#ifdef MS_WINDOWS +#ifdef _WIN32 ssize_t tor_read_all_handle(HANDLE h, char *buf, size_t count, const process_handle_t *process); #else @@ -424,7 +424,7 @@ ssize_t tor_read_all_from_process_stderr( char *tor_join_win_cmdline(const char *argv[]);
int tor_process_get_pid(process_handle_t *process_handle); -#ifdef MS_WINDOWS +#ifdef _WIN32 HANDLE tor_process_get_stdout_pipe(process_handle_t *process_handle); #else FILE *tor_process_get_stdout_pipe(process_handle_t *process_handle); diff --git a/src/or/buffers.c b/src/or/buffers.c index dbecf12..d4fc44b 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -633,7 +633,7 @@ read_to_chunk(buf_t *buf, chunk_t *chunk, tor_socket_t fd, size_t at_most, if (read_result < 0) { int e = tor_socket_errno(fd); if (!ERRNO_IS_EAGAIN(e)) { /* it's a real error */ -#ifdef MS_WINDOWS +#ifdef _WIN32 if (e == WSAENOBUFS) log_warn(LD_NET,"recv() failed: WSAENOBUFS. Not enough ram?"); #endif @@ -790,7 +790,7 @@ flush_chunk(tor_socket_t s, buf_t *buf, chunk_t *chunk, size_t sz, if (write_result < 0) { int e = tor_socket_errno(s); if (!ERRNO_IS_EAGAIN(e)) { /* it's a real error */ -#ifdef MS_WINDOWS +#ifdef _WIN32 if (e == WSAENOBUFS) log_warn(LD_NET,"write() failed: WSAENOBUFS. Not enough ram?"); #endif diff --git a/src/or/config.c b/src/or/config.c index 4b21b6c..d341d63 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -36,7 +36,7 @@ #include "util.h" #include "routerlist.h" #include "transports.h" -#ifdef MS_WINDOWS +#ifdef _WIN32 #include <shlobj.h> #endif
@@ -289,7 +289,7 @@ static config_var_t _option_vars[] = { V(FetchHidServDescriptors, BOOL, "1"), V(FetchUselessDescriptors, BOOL, "0"), V(FetchV2Networkstatus, BOOL, "0"), -#ifdef WIN32 +#ifdef _WIN32 V(GeoIPFile, FILENAME, "<default>"), #else V(GeoIPFile, FILENAME, @@ -573,7 +573,7 @@ typedef struct { *(uint32_t*)STRUCT_VAR_P(cfg,fmt->magic_offset)); \ STMT_END
-#ifdef MS_WINDOWS +#ifdef _WIN32 static char *get_windows_conf_root(void); #endif static void config_line_append(config_line_t **lst, @@ -1644,7 +1644,7 @@ options_act(const or_options_t *old_options) * understand prefixes somehow. -NM */ /* XXXX023 Reload GeoIPFile on SIGHUP. -NM */ char *actual_fname = tor_strdup(options->GeoIPFile); -#ifdef WIN32 +#ifdef _WIN32 if (!strcmp(actual_fname, "<default>")) { const char *conf_root = get_windows_conf_root(); tor_free(actual_fname); @@ -3357,7 +3357,7 @@ options_validate(or_options_t *old_options, or_options_t *options, REJECT("Failed to resolve/guess local address. See logs for details."); }
-#ifndef MS_WINDOWS +#ifndef _WIN32 if (options->RunAsDaemon && torrc_fname && path_is_relative(torrc_fname)) REJECT("Can't use a relative path to torrc when RunAsDaemon is set."); #endif @@ -4247,7 +4247,7 @@ options_transition_affects_descriptor(const or_options_t *old_options, return 0; }
-#ifdef MS_WINDOWS +#ifdef _WIN32 /** Return the directory on windows where we expect to find our application * data. */ static char * @@ -4310,7 +4310,7 @@ get_windows_conf_root(void) static const char * get_default_conf_file(int defaults_file) { -#ifdef MS_WINDOWS +#ifdef _WIN32 if (defaults_file) { static char defaults_path[MAX_PATH+1]; tor_snprintf(defaults_path, MAX_PATH, "%s\torrc-defaults", @@ -4400,7 +4400,7 @@ find_torrc_filename(int argc, char **argv, if (dflt && file_status(dflt) == FN_FILE) { fname = tor_strdup(dflt); } else { -#ifndef MS_WINDOWS +#ifndef _WIN32 char *fn = NULL; if (!defaults_file) fn = expand_filename("~/.torrc"); @@ -4789,7 +4789,7 @@ options_init_logs(or_options_t *options, int validate_only) int ok; smartlist_t *elts; int daemon = -#ifdef MS_WINDOWS +#ifdef _WIN32 0; #else options->RunAsDaemon; @@ -5964,7 +5964,7 @@ check_server_ports(const smartlist_t *ports, } else { continue; } -#ifndef MS_WINDOWS +#ifndef _WIN32 if (!port->no_advertise && port->port < 1024) ++n_low_port; #endif @@ -6041,7 +6041,7 @@ get_first_advertised_port_by_type_af(int listener_type, int address_family) static int normalize_data_directory(or_options_t *options) { -#ifdef MS_WINDOWS +#ifdef _WIN32 char *p; if (options->DataDirectory) return 0; /* all set */ diff --git a/src/or/connection.c b/src/or/connection.c index c51e7fb..bf65e8e 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -837,7 +837,7 @@ check_location_for_unix_socket(const or_options_t *options, const char *path) static void make_socket_reuseable(tor_socket_t sock) { -#ifdef MS_WINDOWS +#ifdef _WIN32 (void) sock; #else int one=1; @@ -1317,7 +1317,7 @@ connection_connect(connection_t *conn, const char *address, * Warn if we do, and refuse to make the connection. */ static ratelim_t disablenet_violated = RATELIM_INIT(30*60); char *m; -#ifdef MS_WINDOWS +#ifdef _WIN32 *socket_error = WSAENETUNREACH; #else *socket_error = ENETUNREACH; diff --git a/src/or/control.c b/src/or/control.c index b7c46e9..9a07777 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -34,7 +34,7 @@ #include "routerlist.h" #include "routerparse.h"
-#ifndef MS_WINDOWS +#ifndef _WIN32 #include <pwd.h> #include <sys/resource.h> #endif @@ -542,7 +542,7 @@ control_ports_write_to_file(void) log_warn(LD_CONTROL, "Writing %s failed: %s", options->ControlPortWriteToFile, strerror(errno)); } -#ifndef MS_WINDOWS +#ifndef _WIN32 if (options->ControlPortFileGroupReadable) { if (chmod(options->ControlPortWriteToFile, 0640)) { log_warn(LD_FS,"Unable to make %s group-readable.", @@ -1392,7 +1392,7 @@ getinfo_helper_misc(control_connection_t *conn, const char *question, } else if (!strcmp(question, "process/pid")) { int myPid = -1;
- #ifdef MS_WINDOWS + #ifdef _WIN32 myPid = _getpid(); #else myPid = getpid(); @@ -1400,14 +1400,14 @@ getinfo_helper_misc(control_connection_t *conn, const char *question,
tor_asprintf(answer, "%d", myPid); } else if (!strcmp(question, "process/uid")) { - #ifdef MS_WINDOWS + #ifdef _WIN32 *answer = tor_strdup("-1"); #else int myUid = geteuid(); tor_asprintf(answer, "%d", myUid); #endif } else if (!strcmp(question, "process/user")) { - #ifdef MS_WINDOWS + #ifdef _WIN32 *answer = tor_strdup(""); #else int myUid = geteuid(); @@ -1435,7 +1435,7 @@ getinfo_helper_misc(control_connection_t *conn, const char *question, } #elif defined(CYGWIN) || defined(__CYGWIN__) *answer = tor_strdup("3200"); - #elif defined(MS_WINDOWS) + #elif defined(_WIN32) *answer = tor_strdup("15000"); #else *answer = tor_strdup("15000"); @@ -4231,7 +4231,7 @@ init_cookie_authentication(int enabled) tor_free(fname); return -1; } -#ifndef MS_WINDOWS +#ifndef _WIN32 if (get_options()->CookieAuthFileGroupReadable) { if (chmod(fname, 0640)) { log_warn(LD_FS,"Unable to make %s group-readable.", escaped(fname)); diff --git a/src/or/dns.c b/src/or/dns.c index ddf9841..2b7d3e3 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -1183,7 +1183,7 @@ configure_nameservers(int force) int r; options = get_options(); conf_fname = options->ServerDNSResolvConfFile; -#ifndef MS_WINDOWS +#ifndef _WIN32 if (!conf_fname) conf_fname = "/etc/resolv.conf"; #endif @@ -1251,7 +1251,7 @@ configure_nameservers(int force) if (nameservers_configured) evdns_base_resume(the_evdns_base); } -#ifdef MS_WINDOWS +#ifdef _WIN32 else { if (nameservers_configured) { evdns_base_search_clear(the_evdns_base); diff --git a/src/or/eventdns.c b/src/or/eventdns.c index 7cd5d80..61a2836 100644 --- a/src/or/eventdns.c +++ b/src/or/eventdns.c @@ -96,7 +96,7 @@
#include "eventdns.h"
-#ifdef WIN32 +#ifdef _WIN32 #include <windows.h> #include <winsock2.h> #include <iphlpapi.h> @@ -110,7 +110,7 @@ #include <netinet/in6.h> #endif
-#ifdef WIN32 +#ifdef _WIN32 typedef int socklen_t; #endif
@@ -343,7 +343,7 @@ static void server_port_ready_callback(int fd, short events, void *arg);
static int strtoint(const char *const str);
-#ifdef WIN32 +#ifdef _WIN32 static int last_error(int sock) { @@ -432,7 +432,7 @@ _evdns_log(int warn, const char *fmt, ...) if (!evdns_log_fn) return; va_start(args,fmt); -#ifdef WIN32 +#ifdef _WIN32 _vsnprintf(buf, sizeof(buf), fmt, args); #else vsnprintf(buf, sizeof(buf), fmt, args); @@ -2298,7 +2298,7 @@ _evdns_nameserver_add_impl(const struct sockaddr *address,
ns->socket = tor_open_socket(address->sa_family, SOCK_DGRAM, 0); if (ns->socket < 0) { err = 1; goto out1; } -#ifdef WIN32 +#ifdef _WIN32 { u_long nonblocking = 1; ioctlsocket(ns->socket, FIONBIO, &nonblocking); @@ -3101,7 +3101,7 @@ out1: return err; }
-#ifdef WIN32 +#ifdef _WIN32 /* Add multiple nameservers from a space-or-comma-separated list. */ static int evdns_nameserver_ip_add_line(const char *ips) { @@ -3309,7 +3309,7 @@ int evdns_init(void) { int res = 0; -#ifdef WIN32 +#ifdef _WIN32 evdns_config_windows_nameservers(); #else res = evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf"); diff --git a/src/or/eventdns.h b/src/or/eventdns.h index 3ff8bba..1c130b2 100644 --- a/src/or/eventdns.h +++ b/src/or/eventdns.h @@ -273,7 +273,7 @@ int evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_ty int evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr); int evdns_set_option(const char *option, const char *val, int flags); int evdns_resolv_conf_parse(int flags, const char *); -#ifdef MS_WINDOWS +#ifdef _WIN32 int evdns_config_windows_nameservers(void); #endif void evdns_search_clear(void); diff --git a/src/or/eventdns_tor.h b/src/or/eventdns_tor.h index 6a17893..b3bdde0 100644 --- a/src/or/eventdns_tor.h +++ b/src/or/eventdns_tor.h @@ -9,14 +9,14 @@ typedef unsigned int uint; #ifndef HAVE_U_CHAR typedef unsigned char u_char; #endif -#ifdef MS_WINDOWS +#ifdef _WIN32 #define inline __inline #endif #include "torint.h"
-#if defined(MS_WINDOWS) && !defined(WIN32) +#if defined(_WIN32) && !defined(_WIN32) /* How did _this_ happen? */ -#define WIN32 +#define _WIN32 #endif
/* These are for debugging possible memory leaks. */ diff --git a/src/or/main.c b/src/or/main.c index e2480dc..7ef14aa 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -196,7 +196,7 @@ free_old_inbuf(connection_t *conn) } #endif
-#if defined(MS_WINDOWS) && defined(USE_BUFFEREVENTS) +#if defined(_WIN32) && defined(USE_BUFFEREVENTS) /** Remove the kernel-space send and receive buffers for <b>s</b>. For use * with IOCP only. */ static int @@ -237,7 +237,7 @@ connection_add_impl(connection_t *conn, int is_connecting) if (connection_type_uses_bufferevent(conn)) { if (SOCKET_OK(conn->s) && !conn->linked) {
-#ifdef MS_WINDOWS +#ifdef _WIN32 if (tor_libevent_using_iocp_bufferevents() && get_options()->UserspaceIOCPBuffers) { set_buffer_lengths_to_zero(conn->s); @@ -701,7 +701,7 @@ conn_read_callback(evutil_socket_t fd, short event, void *_conn)
if (connection_handle_read(conn) < 0) { if (!conn->marked_for_close) { -#ifndef MS_WINDOWS +#ifndef _WIN32 log_warn(LD_BUG,"Unhandled error on read for %s connection " "(fd %d); removing", conn_type_to_string(conn->type), (int)conn->s); @@ -1689,7 +1689,7 @@ refill_callback(periodic_timer_t *timer, void *arg) } #endif
-#ifndef MS_WINDOWS +#ifndef _WIN32 /** Called when a possibly ignorable libevent error occurs; ensures that we * don't get into an infinite loop by ignoring too many errors from * libevent. */ @@ -1908,7 +1908,7 @@ do_main_loop(void) if (nt_service_is_stopping()) return 0;
-#ifndef MS_WINDOWS +#ifndef _WIN32 /* Make it easier to tell whether libevent failure is our fault or not. */ errno = 0; #endif @@ -1932,7 +1932,7 @@ do_main_loop(void) log_err(LD_NET,"libevent call with %s failed: %s [%d]", tor_libevent_get_method(), tor_socket_strerror(e), e); return -1; -#ifndef MS_WINDOWS +#ifndef _WIN32 } else if (e == EINVAL) { log_warn(LD_NET, "EINVAL from libevent: should you upgrade libevent?"); if (got_libevent_error()) @@ -1951,7 +1951,7 @@ do_main_loop(void) } }
-#ifndef MS_WINDOWS /* Only called when we're willing to use signals */ +#ifndef _WIN32 /* Only called when we're willing to use signals */ /** Libevent callback: invoked when we get a signal. */ static void @@ -2168,7 +2168,7 @@ exit_function(void) { /* NOTE: If we ever daemonize, this gets called immediately. That's * okay for now, because we only use this on Windows. */ -#ifdef MS_WINDOWS +#ifdef _WIN32 WSACleanup(); #endif } @@ -2177,7 +2177,7 @@ exit_function(void) void handle_signals(int is_parent) { -#ifndef MS_WINDOWS /* do signal stuff only on Unix */ +#ifndef _WIN32 /* do signal stuff only on Unix */ int i; static const int signals[] = { SIGINT, /* do a controlled slow shutdown */ @@ -2300,7 +2300,7 @@ tor_init(int argc, char *argv[]) return -1; }
-#ifndef MS_WINDOWS +#ifndef _WIN32 if (geteuid()==0) log_warn(LD_GENERAL,"You are running Tor as root. You don't need to, " "and you probably shouldn't."); @@ -2342,7 +2342,7 @@ try_locking(const or_options_t *options, int err_if_locked) log_warn(LD_GENERAL, "It looks like another Tor process is running " "with the same data directory. Waiting 5 seconds to see " "if it goes away."); -#ifndef WIN32 +#ifndef _WIN32 sleep(5); #else Sleep(5000); @@ -2578,7 +2578,7 @@ tor_main(int argc, char *argv[]) } #endif
-#ifdef MS_WINDOWS +#ifdef _WIN32 /* Call SetProcessDEPPolicy to permanently enable DEP. The function will not resolve on earlier versions of Windows, and failure is not dangerous. */ diff --git a/src/or/ntmain.h b/src/or/ntmain.h index acd0e1d..6d95a09 100644 --- a/src/or/ntmain.h +++ b/src/or/ntmain.h @@ -12,7 +12,7 @@ #ifndef _TOR_NTMAIN_H #define _TOR_NTMAIN_H
-#ifdef MS_WINDOWS +#ifdef _WIN32 #if !defined (WINCE) #define NT_SERVICE #endif diff --git a/src/or/or.h b/src/or/or.h index 9ac8717..33324f5 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -22,7 +22,7 @@ #endif #endif
-#ifdef MS_WINDOWS +#ifdef _WIN32 #ifndef WIN32_WINNT #define WIN32_WINNT 0x400 #endif @@ -79,7 +79,7 @@ #include <time.h> #endif
-#ifdef MS_WINDOWS +#ifdef _WIN32 #include <io.h> #include <process.h> #include <direct.h> diff --git a/src/or/reasons.c b/src/or/reasons.c index 319e6c0..bcf15ff 100644 --- a/src/or/reasons.c +++ b/src/or/reasons.c @@ -143,7 +143,7 @@ stream_end_reason_to_socks5_response(int reason) * E_CASE is for errors where windows has both a EFOO and a WSAEFOO * version, and S_CASE is for errors where windows has only a WSAEFOO * version. (The E is for 'error', the S is for 'socket'). */ -#ifdef MS_WINDOWS +#ifdef _WIN32 #define E_CASE(s) case s: case WSA ## s #define S_CASE(s) case WSA ## s #else diff --git a/src/or/transports.c b/src/or/transports.c index 0bc67ba..3e5501e 100644 --- a/src/or/transports.c +++ b/src/or/transports.c @@ -91,7 +91,7 @@ #include "util.h" #include "router.h"
-#ifdef MS_WINDOWS +#ifdef _WIN32 static void set_managed_proxy_environment(LPVOID *envp, const managed_proxy_t *mp); #else @@ -263,7 +263,7 @@ launch_managed_proxy(managed_proxy_t *mp) { int retval;
-#ifdef MS_WINDOWS +#ifdef _WIN32
LPVOID envp=NULL;
@@ -349,7 +349,7 @@ pt_configure_remaining_proxies(void) } SMARTLIST_FOREACH_END(mp); }
-#ifdef MS_WINDOWS +#ifdef _WIN32
/** Attempt to continue configuring managed proxy <b>mp</b>. */ static void @@ -406,7 +406,7 @@ configure_proxy(managed_proxy_t *mp) smartlist_free(lines); }
-#else /* MS_WINDOWS */ +#else /* _WIN32 */
/** Attempt to continue configuring managed proxy <b>mp</b>. */ static void @@ -451,7 +451,7 @@ configure_proxy(managed_proxy_t *mp) } }
-#endif /* MS_WINDOWS */ +#endif /* _WIN32 */
/** Register server managed proxy <b>mp</b> transports to state */ static void @@ -941,7 +941,7 @@ get_bindaddr_for_server_proxy(const managed_proxy_t *mp) return bindaddr_result; }
-#ifdef MS_WINDOWS +#ifdef _WIN32
/** Prepare the environment <b>envp</b> of managed proxy <b>mp</b>. * <b>envp</b> is allocated on the heap and should be freed by the @@ -1043,7 +1043,7 @@ set_managed_proxy_environment(LPVOID *envp, const managed_proxy_t *mp) smartlist_free(envs); }
-#else /* MS_WINDOWS */ +#else /* _WIN32 */
/** Prepare the environment <b>envp</b> of managed proxy <b>mp</b>. * <b>envp</b> is allocated on the heap and should be freed by the @@ -1104,7 +1104,7 @@ set_managed_proxy_environment(char ***envp, const managed_proxy_t *mp) return r; }
-#endif /* MS_WINDOWS */ +#endif /* _WIN32 */
/** Create and return a new managed proxy for <b>transport</b> using * <b>proxy_argv</b>. If <b>is_server</b> is true, it's a server diff --git a/src/test/test-child.c b/src/test/test-child.c index 1b9c5e3..b57d8ca 100644 --- a/src/test/test-child.c +++ b/src/test/test-child.c @@ -1,6 +1,6 @@ #include <stdio.h> #include "orconfig.h" -#ifdef MS_WINDOWS +#ifdef _WIN32 #define WINDOWS_LEAN_AND_MEAN #include <windows.h> #else @@ -23,13 +23,13 @@ main(int argc, char **argv) succeed. Otherwise ReadFile() will get the entire output in one */ // XXX: Can we make stdio flush on newline? fflush(stdout); -#ifdef MS_WINDOWS +#ifdef _WIN32 Sleep(1000); #else sleep(1); #endif fprintf(stdout, "DONE\n"); -#ifdef MS_WINDOWS +#ifdef _WIN32 Sleep(1000); #else sleep(1); diff --git a/src/test/test.c b/src/test/test.c index 9d369c0..2ecf6ff 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -19,7 +19,7 @@ const char tor_git_revision[] = ""; #include <fcntl.h> #endif
-#ifdef MS_WINDOWS +#ifdef _WIN32 /* For mkdir() */ #include <direct.h> #else @@ -83,7 +83,7 @@ setup_directory(void) int r; if (is_setup) return;
-#ifdef MS_WINDOWS +#ifdef _WIN32 { char buf[MAX_PATH]; const char *tmp = buf; diff --git a/src/test/test_microdesc.c b/src/test/test_microdesc.c index dcc6f9c..9326c03 100644 --- a/src/test/test_microdesc.c +++ b/src/test/test_microdesc.c @@ -9,7 +9,7 @@
#include "test.h"
-#ifdef MS_WINDOWS +#ifdef _WIN32 /* For mkdir() */ #include <direct.h> #else @@ -66,7 +66,7 @@ test_md_cache(void *data) /* Possibly, turn this into a test setup/cleanup pair */ tor_free(options->DataDirectory); options->DataDirectory = tor_strdup(get_fname("md_datadir_test")); -#ifdef MS_WINDOWS +#ifdef _WIN32 tt_int_op(0, ==, mkdir(options->DataDirectory)); #else tt_int_op(0, ==, mkdir(options->DataDirectory, 0700)); diff --git a/src/test/test_util.c b/src/test/test_util.c index 670d87d..508c155 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -530,7 +530,7 @@ test_util_threads(void) char *s1 = NULL, *s2 = NULL; int done = 0, timedout = 0; time_t started; -#ifndef MS_WINDOWS +#ifndef _WIN32 struct timeval tv; tv.tv_sec=0; tv.tv_usec=10; @@ -564,7 +564,7 @@ test_util_threads(void) timedout = done = 1; } tor_mutex_release(_thread_test_mutex); -#ifndef MS_WINDOWS +#ifndef _WIN32 /* Prevent the main thread from starving the worker threads. */ select(0, NULL, NULL, NULL, &tv); #endif @@ -735,7 +735,7 @@ test_util_mmap(void) test_assert(mapping); test_eq(mapping->size, strlen("Short file.")); test_streq(mapping->data, "Short file."); -#ifdef MS_WINDOWS +#ifdef _WIN32 tor_munmap_file(mapping); mapping = NULL; test_assert(unlink(fname1) == 0); @@ -1260,7 +1260,7 @@ test_util_parent_dir(void *ptr) tor_free(cp); }
-#ifdef MS_WINDOWS +#ifdef _WIN32 static void test_util_load_win_lib(void *ptr) { @@ -1312,7 +1312,7 @@ test_util_exit_status(void *ptr) ; }
-#ifndef MS_WINDOWS +#ifndef _WIN32 /** Check that fgets waits until a full line, and not return a partial line, on * a EAGAIN with a non-blocking pipe */ static void @@ -1412,7 +1412,7 @@ run_util_spawn_background(const char *argv[], const char *expected_out, int status;
/* Start the program */ -#ifdef MS_WINDOWS +#ifdef _WIN32 status = tor_spawn_background(NULL, argv, NULL, &process_handle); #else status = tor_spawn_background(argv[0], argv, NULL, &process_handle); @@ -1459,7 +1459,7 @@ run_util_spawn_background(const char *argv[], const char *expected_out, static void test_util_spawn_background_ok(void *ptr) { -#ifdef MS_WINDOWS +#ifdef _WIN32 const char *argv[] = {"test-child.exe", "--test", NULL}; const char *expected_out = "OUT\r\n--test\r\nSLEEPING\r\nDONE\r\n"; const char *expected_err = "ERR\r\n"; @@ -1483,7 +1483,7 @@ test_util_spawn_background_fail(void *ptr) const char *expected_err = ""; char expected_out[1024]; char code[32]; -#ifdef MS_WINDOWS +#ifdef _WIN32 const int expected_status = PROCESS_STATUS_ERROR; #else /* TODO: Once we can signal failure to exec, set this to be @@ -1515,7 +1515,7 @@ test_util_spawn_background_partial_read(void *ptr) process_handle_t *process_handle=NULL; int status; char stdout_buf[100], stderr_buf[100]; -#ifdef MS_WINDOWS +#ifdef _WIN32 const char *argv[] = {"test-child.exe", "--test", NULL}; const char *expected_out[] = { "OUT\r\n--test\r\nSLEEPING\r\n", "DONE\r\n", @@ -1533,7 +1533,7 @@ test_util_spawn_background_partial_read(void *ptr) (void)ptr;
/* Start the program */ -#ifdef MS_WINDOWS +#ifdef _WIN32 status = tor_spawn_background(NULL, argv, NULL, &process_handle); #else status = tor_spawn_background(argv[0], argv, NULL, &process_handle); @@ -1544,7 +1544,7 @@ test_util_spawn_background_partial_read(void *ptr)
/* Check stdout */ for (expected_out_ctr = 0; expected_out[expected_out_ctr] != NULL;) { -#ifdef MS_WINDOWS +#ifdef _WIN32 pos = tor_read_all_handle(process_handle->stdout_pipe, stdout_buf, sizeof(stdout_buf) - 1, NULL); #else @@ -1567,7 +1567,7 @@ test_util_spawn_background_partial_read(void *ptr) }
/* The process should have exited without writing more */ -#ifdef MS_WINDOWS +#ifdef _WIN32 pos = tor_read_all_handle(process_handle->stdout_pipe, stdout_buf, sizeof(stdout_buf) - 1, process_handle); @@ -1881,11 +1881,11 @@ struct testcase_t util_tests[] = { UTIL_TEST(asprintf, 0), UTIL_TEST(listdir, 0), UTIL_TEST(parent_dir, 0), -#ifdef MS_WINDOWS +#ifdef _WIN32 UTIL_TEST(load_win_lib, 0), #endif UTIL_TEST(exit_status, 0), -#ifndef MS_WINDOWS +#ifndef _WIN32 UTIL_TEST(fgets_eagain, TT_SKIP), #endif UTIL_TEST(spawn_background_ok, 0), diff --git a/src/tools/tor-fw-helper/tor-fw-helper-natpmp.c b/src/tools/tor-fw-helper/tor-fw-helper-natpmp.c index a3a52d1..ed79fd2 100644 --- a/src/tools/tor-fw-helper/tor-fw-helper-natpmp.c +++ b/src/tools/tor-fw-helper/tor-fw-helper-natpmp.c @@ -9,14 +9,14 @@
#include "orconfig.h" #ifdef NAT_PMP -#ifdef MS_WINDOWS +#ifdef _WIN32 #define STATICLIB #endif #include <stdint.h> #include <stdio.h> #include <string.h> #include <errno.h> -#ifndef MS_WINDOWS +#ifndef _WIN32 #include <arpa/inet.h> #endif
diff --git a/src/tools/tor-fw-helper/tor-fw-helper-upnp.c b/src/tools/tor-fw-helper/tor-fw-helper-upnp.c index c4b14a8..442eae5 100644 --- a/src/tools/tor-fw-helper/tor-fw-helper-upnp.c +++ b/src/tools/tor-fw-helper/tor-fw-helper-upnp.c @@ -9,7 +9,7 @@
#include "orconfig.h" #ifdef MINIUPNPC -#ifdef MS_WINDOWS +#ifdef _WIN32 #define STATICLIB #endif #include <stdint.h> diff --git a/src/tools/tor-fw-helper/tor-fw-helper.c b/src/tools/tor-fw-helper/tor-fw-helper.c index 0022397..ea5ae7f 100644 --- a/src/tools/tor-fw-helper/tor-fw-helper.c +++ b/src/tools/tor-fw-helper/tor-fw-helper.c @@ -21,7 +21,7 @@ #include <time.h> #include <string.h>
-#ifdef MS_WINDOWS +#ifdef _WIN32 #include <winsock2.h> #endif
@@ -229,7 +229,7 @@ tor_fw_add_dir_port(tor_fw_options_t *tor_fw_options, static int network_init(void) { -#ifdef MS_WINDOWS +#ifdef _WIN32 /* This silly exercise is necessary before windows will allow * gethostbyname to work. */ WSADATA WSAData; diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c index f1220d9..73352fe 100644 --- a/src/tools/tor-resolve.c +++ b/src/tools/tor-resolve.c @@ -32,7 +32,7 @@ #include <errno.h> #endif
-#ifdef MS_WINDOWS +#ifdef _WIN32 #if defined(_MSC_VER) && (_MSC_VER <= 1300) #include <winsock.h> #else diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h index 9891c8e..bf33c81 100644 --- a/src/win32/orconfig.h +++ b/src/win32/orconfig.h @@ -3,8 +3,7 @@ */
/* Windows-only defines. */ -#define MS_WINDOWS -#define MS_WIN32 +#define _WIN32 #define CONFDIR ""
/* Define to 1 if you have the <arpa/inet.h> header file. */