diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2016-11-07 23:15:07 +0100 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2016-12-12 15:32:32 +0100 |
commit | 8c6d0b51c719e1817e308375d129b17ede3b82fc (patch) | |
tree | 8aa23d1db5e4198f6aeed5091ad6adedc12fea35 /src/OSSupport | |
parent | Merge pull request #3476 from Seadragon91/patch-1 (diff) | |
download | cuberite-8c6d0b51c719e1817e308375d129b17ede3b82fc.tar cuberite-8c6d0b51c719e1817e308375d129b17ede3b82fc.tar.gz cuberite-8c6d0b51c719e1817e308375d129b17ede3b82fc.tar.bz2 cuberite-8c6d0b51c719e1817e308375d129b17ede3b82fc.tar.lz cuberite-8c6d0b51c719e1817e308375d129b17ede3b82fc.tar.xz cuberite-8c6d0b51c719e1817e308375d129b17ede3b82fc.tar.zst cuberite-8c6d0b51c719e1817e308375d129b17ede3b82fc.zip |
Diffstat (limited to 'src/OSSupport')
-rw-r--r-- | src/OSSupport/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/OSSupport/Errors.cpp | 2 | ||||
-rw-r--r-- | src/OSSupport/File.cpp | 6 | ||||
-rw-r--r-- | src/OSSupport/NetworkInterfaceEnum.cpp | 14 | ||||
-rw-r--r-- | src/OSSupport/NetworkSingleton.cpp | 15 | ||||
-rw-r--r-- | src/OSSupport/StackTrace.cpp | 4 |
6 files changed, 30 insertions, 19 deletions
diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index 876b4f789..22699f7cd 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -43,12 +43,4 @@ endif() if(NOT MSVC) add_library(OSSupport ${SRCS} ${HDRS}) - - if(UNIX) - if(NOT APPLE) - target_link_libraries(OSSupport rt) - endif() - - target_link_libraries(OSSupport pthread event_core event_extra) - endif() endif() diff --git a/src/OSSupport/Errors.cpp b/src/OSSupport/Errors.cpp index a05650111..004cbaccc 100644 --- a/src/OSSupport/Errors.cpp +++ b/src/OSSupport/Errors.cpp @@ -22,7 +22,7 @@ AString GetOSErrorString( int a_ErrNo) // According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r(): - #if defined(__GLIBC__) && defined( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r() + #if defined(__GLIBC__) && defined( _GNU_SOURCE) && !defined(ANDROID) // GNU version of strerror_r() char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer)); if (res != nullptr) diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp index a59f599ae..062161144 100644 --- a/src/OSSupport/File.cpp +++ b/src/OSSupport/File.cpp @@ -653,9 +653,13 @@ unsigned cFile::GetLastModificationTime(const AString & a_FileName) { return 0; } - #ifdef _WIN32 + #if defined(_WIN32) // Windows returns times in local time already return static_cast<unsigned>(st.st_mtime); + #elif defined(ANDROID) + // Identical to Linux below, but st_mtime is an unsigned long, so cast is needed: + auto Time = static_cast<time_t>(st.st_mtime); + return static_cast<unsigned>(mktime(localtime(&Time))); #else // Linux returns UTC time, convert to local timezone: return static_cast<unsigned>(mktime(localtime(&st.st_mtime))); diff --git a/src/OSSupport/NetworkInterfaceEnum.cpp b/src/OSSupport/NetworkInterfaceEnum.cpp index d3a254c23..439710c38 100644 --- a/src/OSSupport/NetworkInterfaceEnum.cpp +++ b/src/OSSupport/NetworkInterfaceEnum.cpp @@ -7,10 +7,10 @@ #include "Network.h" #include "event2/util.h" -#ifdef _WIN32 +#if defined(_WIN32) #include <IPHlpApi.h> #pragma comment(lib, "IPHLPAPI.lib") -#else // _WIN32 +#elif !defined(ANDROID) // _WIN32 #include <sys/types.h> #include <ifaddrs.h> #include <netinet/in.h> @@ -21,7 +21,7 @@ -#ifdef _WIN32 +#if defined(_WIN32) /** Converts the SOCKET_ADDRESS structure received from the OS into an IP address string. */ static AString PrintAddress(SOCKET_ADDRESS & a_Addr) @@ -50,7 +50,7 @@ static AString PrintAddress(SOCKET_ADDRESS & a_Addr) return IP; } -#else // _WIN32 +#elif !defined(ANDROID) // _WIN32 static AString PrintAddress(ifaddrs * InterfaceAddress) { @@ -82,7 +82,7 @@ static AString PrintAddress(ifaddrs * InterfaceAddress) } } -#endif // else _WIN32 +#endif // else !ANDROID @@ -92,7 +92,7 @@ AStringVector cNetwork::EnumLocalIPAddresses(void) { AStringVector res; - #ifdef _WIN32 + #if defined(_WIN32) // Query the OS for all adapters' addresses: char buffer[64 KiB]; // A buffer backing the address list @@ -129,7 +129,7 @@ AStringVector cNetwork::EnumLocalIPAddresses(void) } // for pUnicast } // for pCurrAddresses - #else // _WIN32 + #elif !defined(ANDROID) // _WIN32 struct ifaddrs * ifAddrStruct = nullptr; getifaddrs(&ifAddrStruct); diff --git a/src/OSSupport/NetworkSingleton.cpp b/src/OSSupport/NetworkSingleton.cpp index dcf17bccb..3a8dbbdc7 100644 --- a/src/OSSupport/NetworkSingleton.cpp +++ b/src/OSSupport/NetworkSingleton.cpp @@ -13,6 +13,11 @@ #include "IPLookup.h" #include "HostnameLookup.h" +#ifdef ANDROID + // For DNS server retrieval + #include <sys/system_properties.h> +#endif + @@ -89,6 +94,16 @@ void cNetworkSingleton::Initialise(void) abort(); } + #ifdef ANDROID + char PropertyBuffer[PROP_VALUE_MAX]; + + __system_property_get("net.dns1", PropertyBuffer); + evdns_base_nameserver_ip_add(m_DNSBase, PropertyBuffer); + + __system_property_get("net.dns2", PropertyBuffer); + evdns_base_nameserver_ip_add(m_DNSBase, PropertyBuffer); + #endif + // Create the event loop thread: m_HasTerminated = false; m_EventLoopThread = std::thread(RunEventLoop, this); diff --git a/src/OSSupport/StackTrace.cpp b/src/OSSupport/StackTrace.cpp index 030566065..c84e2cbca 100644 --- a/src/OSSupport/StackTrace.cpp +++ b/src/OSSupport/StackTrace.cpp @@ -7,7 +7,7 @@ #include "StackTrace.h" #ifdef _WIN32 #include "../StackWalker.h" -#else +#elif !defined(ANDROID) // The Android NDK has no execinfo header #ifdef __GLIBC__ #include <execinfo.h> #endif @@ -32,7 +32,7 @@ void PrintStackTrace(void) } } sw; sw.ShowCallstack(); - #else + #elif !defined(ANDROID) #ifdef __GLIBC__ // Use the backtrace() function to get and output the stackTrace: // Code adapted from https://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes |