From 8098ed899a3648897c0de925c974e21883a76b8d Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 30 Mar 2011 00:55:45 -0400 Subject: [PATCH] Fixed windows build more, including ldap --- CMakeLists.txt | 4 +-- include/services.h | 48 +----------------------------------- include/sysconf.h.cmake | 2 -- modules/extra/m_ldap.cpp | 2 +- src/logger.cpp | 2 -- src/win32/anope_windows.h | 51 +++++++++++++++++++++++++++++++++++++++ src/win32/windows.cpp | 16 ++++++++++++ 7 files changed, 71 insertions(+), 54 deletions(-) create mode 100644 src/win32/anope_windows.h diff --git a/CMakeLists.txt b/CMakeLists.txt index afedb7371..0f76306ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -227,6 +227,8 @@ include_directories(${Anope_BINARY_DIR}/include ${Anope_SOURCE_DIR}/include ${An # If using Windows, always add the _WIN32 define if(WIN32) add_definitions(-D_WIN32) + # And include the windows specific folder for our anope_windows.h + include_directories(${Anope_SOURCE_DIR}/src/win32) endif(WIN32) # If using Visual Studio, set the C++ flags accordingly @@ -329,11 +331,9 @@ endif(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEB # Check for the existance of the following include files check_include_file(sys/types.h HAVE_SYS_TYPES_H) check_include_file(strings.h HAVE_STRINGS_H) -check_include_file(sys/select.h HAVE_SYS_SELECT_H) check_include_file(sys/eventfd.h HAVE_SYS_EVENTFD_H) # Check for the existance of the following functions -check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) check_function_exists(setgrent HAVE_SETGRENT) check_function_exists(strcasecmp HAVE_STRCASECMP) check_function_exists(stricmp HAVE_STRICMP) diff --git a/include/services.h b/include/services.h index f5a787a24..1285b188e 100644 --- a/include/services.h +++ b/include/services.h @@ -46,12 +46,6 @@ #if GETTEXT_FOUND # include # define _(x) anope_gettext(x) -# ifdef _WIN32 - /* Redefine snprintf and undefine vsnprintf because liblintl defines it to its own function */ -# undef snprintf -# define snprintf _snprintf -# undef vsnprintf -# endif #else # define _(x) x #endif @@ -72,31 +66,7 @@ # define MARK_DEPRECATED __attribute((deprecated)) # define DeleteFile unlink #else -# include -# include -# include -# include -# include -# include -# ifdef MODULE_COMPILE -# define CoreExport __declspec(dllimport) -# define DllExport __declspec(dllexport) -# else -# define CoreExport __declspec(dllexport) -# define DllExport __declspec(dllimport) -# endif -/* VS2008 hates having this define before its own */ -# define vsnprintf _vsnprintf -/* We have our own inet_pton and inet_ntop (Windows doesn't have its own) */ -# define inet_pton inet_pton_ -# define inet_ntop inet_ntop_ -# define setenv(x, y, z) SetEnvironmentVariable(x, y) -# define unsetenv(x) SetEnvironmentVariable(x, NULL) -# define MARK_DEPRECATED - -extern CoreExport USHORT WindowsGetLanguage(const char *lang); -extern CoreExport int inet_pton(int af, const char *src, void *dst); -extern CoreExport const char *inet_ntop(int af, const void *src, char *dst, size_t size); +# include "anope_windows.h" #endif /* Telling compilers about printf()-like functions: */ @@ -114,10 +84,6 @@ extern CoreExport const char *inet_ntop(int af, const void *src, char *dst, size # include #endif -#if HAVE_SYS_SELECT_H -# include -#endif - #ifdef _AIX /* Some AIX boxes seem to have bogus includes that don't have these * prototypes. */ @@ -141,18 +107,6 @@ extern int strncasecmp(const char *, const char *, size_t); #define tolower tolower_ #define toupper toupper_ -#ifdef __WINS__ -# ifndef BKCHECK -# define BKCHECK -extern "C" void __pfnBkCheck() {} -# endif -#endif - -#if INTTYPE_WORKAROUND -# undef int16 -# undef int32 -#endif - /** This definition is used as shorthand for the various classes * and functions needed to make a module loadable by the OS. * It defines the class factory and external AnopeInit and AnopeFini functions. diff --git a/include/sysconf.h.cmake b/include/sysconf.h.cmake index 17aa98674..78150a82d 100644 --- a/include/sysconf.h.cmake +++ b/include/sysconf.h.cmake @@ -8,14 +8,12 @@ #cmakedefine HAVE_STDINT_H 1 #cmakedefine HAVE_STDDEF_H 1 #cmakedefine HAVE_BACKTRACE 1 -#cmakedefine HAVE_GETTIMEOFDAY 1 #cmakedefine HAVE_SETGRENT 1 #cmakedefine HAVE_STRCASECMP 1 #cmakedefine HAVE_STRICMP 1 #cmakedefine HAVE_STRINGS_H 1 #cmakedefine HAVE_STRLCAT 1 #cmakedefine HAVE_STRLCPY 1 -#cmakedefine HAVE_SYS_SELECT_H 1 #cmakedefine HAVE_UMASK 1 #cmakedefine HAVE_EVENTFD 1 #cmakedefine GETTEXT_FOUND 1 diff --git a/modules/extra/m_ldap.cpp b/modules/extra/m_ldap.cpp index aeb0500e3..aa7e5212e 100644 --- a/modules/extra/m_ldap.cpp +++ b/modules/extra/m_ldap.cpp @@ -1,4 +1,4 @@ -/* RequiredLibraries: ldap */ +/* RequiredLibraries: ldap,lber */ #include "module.h" #include "ldap.h" diff --git a/src/logger.cpp b/src/logger.cpp index 1265dc3e2..a74a219d9 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -52,7 +52,6 @@ static Anope::string GetTimeStamp() if (time(&t) < 0) throw CoreException("time() failed"); tm tm = *localtime(&t); -#if HAVE_GETTIMEOFDAY if (debug) { char *s; @@ -64,7 +63,6 @@ static Anope::string GetTimeStamp() strftime(s, sizeof(tbuf) - (s - tbuf) - 1, " %Y]", &tm); } else -#endif strftime(tbuf, sizeof(tbuf) - 1, "[%b %d %H:%M:%S %Y]", &tm); return tbuf; diff --git a/src/win32/anope_windows.h b/src/win32/anope_windows.h new file mode 100644 index 000000000..3abe8bd13 --- /dev/null +++ b/src/win32/anope_windows.h @@ -0,0 +1,51 @@ + /* POSIX emulation layer for Windows. + * + * Copyright (C) 2008-2011 Robin Burchell + * Copyright (C) 2008-2011 Anope Team + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + + #ifndef WINDOWS_H + #define WINDOWS_H + #ifdef _WIN32 + +#include +#include +#include +#include +#include +#include +#ifdef MODULE_COMPILE +# define CoreExport __declspec(dllimport) +# define DllExport __declspec(dllexport) +#else +# define CoreExport __declspec(dllexport) +# define DllExport __declspec(dllimport) +#endif +/* We have our own inet_pton and inet_ntop (Windows XP doesn't have its own) */ +#define inet_pton inet_pton_ +#define inet_ntop inet_ntop_ +#define setenv(x, y, z) SetEnvironmentVariable(x, y) +#define unsetenv(x) SetEnvironmentVariable(x, NULL) +#define MARK_DEPRECATED +#if GETTEXT_FOUND +/* Undefine some functions libintl defines */ +# undef snprintf +# undef vsnprintf +# undef printf +#endif +#define snprintf _snprintf +/* VS2008 hates having this define before its own */ +#define vsnprintf _vsnprintf + +extern CoreExport USHORT WindowsGetLanguage(const char *lang); +extern CoreExport int inet_pton(int af, const char *src, void *dst); +extern CoreExport const char *inet_ntop(int af, const void *src, char *dst, size_t size); +extern CoreExport int gettimeofday(timeval *tv, char *); + + #endif // _WIN32 + #endif // WINDOWS_H \ No newline at end of file diff --git a/src/win32/windows.cpp b/src/win32/windows.cpp index a443472f9..b57171dec 100644 --- a/src/win32/windows.cpp +++ b/src/win32/windows.cpp @@ -123,4 +123,20 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size) return NULL; } +/** Like gettimeofday(), but it works on Windows. + * @param tv A timeval struct + * @param tz Should be NULL, it is not used + * @return 0 on success + */ +int gettimeofday(timeval *tv, char *) +{ + SYSTEMTIME st; + GetSystemTime(&st); + + tv->tv_sec = Anope::CurTime; + tv->tv_usec = st.wMilliseconds; + + return 0; +} + #endif