diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-01-31 10:59:42 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-01-31 15:48:47 -0500 |
commit | 5cf9167f919dfef964b1d149731ed04941e25ebf (patch) | |
tree | 37668dde9fd4c68d80cb1bde90523b55fba4b226 /src/common | |
parent | 23054543278a8ee5db6d8dae3b3a96e2b2fd5377 (diff) | |
download | tor-5cf9167f919dfef964b1d149731ed04941e25ebf.tar.gz tor-5cf9167f919dfef964b1d149731ed04941e25ebf.zip |
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;
}
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/address.c | 10 | ||||
-rw-r--r-- | src/common/compat.c | 62 | ||||
-rw-r--r-- | src/common/compat.h | 24 | ||||
-rw-r--r-- | src/common/compat_libevent.c | 4 | ||||
-rw-r--r-- | src/common/crypto.c | 6 | ||||
-rw-r--r-- | src/common/procmon.c | 10 | ||||
-rw-r--r-- | src/common/tortls.c | 4 | ||||
-rw-r--r-- | src/common/util.c | 64 | ||||
-rw-r--r-- | src/common/util.h | 12 |
9 files changed, 98 insertions, 98 deletions
diff --git a/src/common/address.c b/src/common/address.c index e18ef95469..17cda42cb7 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 cd112035c6..64c06681da 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 4329d45369..fa1ef90eb7 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 0cedef8d5e..70e3baf9dd 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 6bc54fc44f..380dcf0abc 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 5c10e9a22b..85d2a2fe3f 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 570dd005fd..26d37145a3 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 40efff0518..ac37f1ba3f 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 b15b1ea56a..1bad24bf72 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); |