diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/crypto.c | 15 | ||||
-rw-r--r-- | src/common/log.c | 1 | ||||
-rw-r--r-- | src/common/util.c | 37 | ||||
-rw-r--r-- | src/common/util.h | 10 |
4 files changed, 41 insertions, 22 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 8d8c78a1e3..4599e0cbb6 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -4,6 +4,14 @@ #include "orconfig.h" +#ifdef MS_WINDOWS +#define WIN32_WINNT 0x400 +#define _WIN32_WINNT 0x400 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#include <wincrypt.h> +#endif + #include <string.h> #include <openssl/err.h> @@ -40,13 +48,6 @@ #include "aes.h" #include "util.h" -#ifdef MS_WINDOWS -#define WIN32_WINNT 0x400 -#define _WIN32_WINNT 0x400 -#define WIN32_LEAN_AND_MEAN -#include <wincrypt.h> -#endif - #if OPENSSL_VERSION_NUMBER < 0x00905000l #error "We require openssl >= 0.9.5" #elif OPENSSL_VERSION_NUMBER < 0x00906000l diff --git a/src/common/log.c b/src/common/log.c index 73733dccf0..9014c9394b 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -12,6 +12,7 @@ #ifdef MS_WINDOWS #define vsnprintf _vsnprintf +#define snprintf _snprintf #endif struct logfile_t; diff --git a/src/common/util.c b/src/common/util.c index 64e3a9b5a4..9c834db589 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -3,6 +3,23 @@ /* $Id$ */ #include "orconfig.h" + +#ifdef MS_WINDOWS +#define WIN32_WINNT 0x400 +#define _WIN32_WINNT 0x400 +#define WIN32_LEAN_AND_MEAN +#if _MSC_VER > 1300 +#include <winsock2.h> +#include <ws2tcpip.h> +#elif defined(_MSC_VER) +#include <winsock.h> +#endif +#include <io.h> +#include <process.h> +#include <direct.h> +#include <windows.h> +#endif + #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -27,6 +44,9 @@ #ifdef HAVE_ERRNO_H #include <errno.h> #endif +#ifdef HAVE_LIMITS_H +#include <limits.h> +#endif #ifdef HAVE_SYS_LIMITS_H #include <sys/limits.h> #endif @@ -57,17 +77,8 @@ #ifdef HAVE_GRP_H #include <grp.h> #endif - -#ifdef HAVE_WINSOCK_H -#define WIN32_WINNT 0x400 -#define _WIN32_WINNT 0x400 -#define WIN32_LEAN_AND_MEAN -#endif -#if _MSC_VER > 1300 -#include <winsock2.h> -#include <ws2tcpip.h> -#elif defined(_MSC_VER) -#include <winsock.h> +#ifdef HAVE_FCNTL_H +#include <fcntl.h> #endif /* used by inet_addr, not defined on solaris anywhere!? */ @@ -152,13 +163,13 @@ void tor_strlower(char *s) } #ifndef UNALIGNED_INT_ACCESS_OK -uint16_t get_uint16(char *cp) +uint16_t get_uint16(const char *cp) { uint16_t v; memcpy(&v,cp,2); return v; } -uint32_t get_uint32(char *cp) +uint32_t get_uint32(const char *cp) { uint32_t v; memcpy(&v,cp,4); diff --git a/src/common/util.h b/src/common/util.h index bd65a0153b..dcfe7a94dc 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -36,8 +36,14 @@ #define strncasecmp strnicmp #define strcasecmp stricmp #define INLINE __inline +#define _ARRAYSIZE(x) (((x)==0)?1:0) +/* Windows compilers before VC7 don't have __FUNCTION__. */ +#if _MSC_VER < 1300 +#define __FUNCTION__ "???" +#endif #else #define INLINE inline +#define _ARRAYSIZE(x) (x) #endif #ifdef NDEBUG @@ -76,8 +82,8 @@ void tor_strlower(char *s); #define set_uint32(cp,v) do { *(uint32_t*)(cp) = (v); } while (0) #else #if 1 -uint16_t get_uint16(char *cp); -uint32_t get_uint32(char *cp); +uint16_t get_uint16(const char *cp); +uint32_t get_uint32(const char *cp); void set_uint16(char *cp, uint16_t v); void set_uint32(char *cp, uint32_t v); #else |