diff --git a/CMakeLists.txt b/CMakeLists.txt index 91eff4d10..8f2a86ec4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,10 @@ IF(UNIX) ADD_DEFINITIONS(-DFREEBSD) SET(FREEBSD TRUE) ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + IF(CMAKE_SYSTEM_NAME MATCHES "Darwin") + ADD_DEFINITIONS(-DDARWIN) + SET(DARWIN TRUE) + ENDIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") ENDIF(UNIX) #use stdint.h types if they exist for this platform (we have to guess otherwise) diff --git a/client_files/export/CMakeLists.txt b/client_files/export/CMakeLists.txt index 191184013..851aa05fb 100644 --- a/client_files/export/CMakeLists.txt +++ b/client_files/export/CMakeLists.txt @@ -26,7 +26,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(export_client_files "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(export_client_files "z") TARGET_LINK_LIBRARIES(export_client_files "m") - TARGET_LINK_LIBRARIES(export_client_files "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(export_client_files "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(export_client_files "pthread") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/client_files/import/CMakeLists.txt b/client_files/import/CMakeLists.txt index 94875302d..0b6c45b57 100644 --- a/client_files/import/CMakeLists.txt +++ b/client_files/import/CMakeLists.txt @@ -26,7 +26,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(import_client_files "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(import_client_files "z") TARGET_LINK_LIBRARIES(import_client_files "m") - TARGET_LINK_LIBRARIES(import_client_files "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(import_client_files "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(import_client_files "pthread") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/common/TCPConnection.cpp b/common/TCPConnection.cpp index e576f953a..1e5f49600 100644 --- a/common/TCPConnection.cpp +++ b/common/TCPConnection.cpp @@ -30,6 +30,10 @@ #ifdef FREEBSD //Timothy Whitman - January 7, 2003 #define MSG_NOSIGNAL 0 #endif +#ifdef DARWIN + #define MSG_NOSIGNAL SO_NOSIGPIPE // Corysia Taware - Sept. 27, 2013 + // See http://lists.apple.com/archives/macnetworkprog/2002/Dec/msg00091.html +#endif // DARWIN #ifdef _WINDOWS InitWinsock winsock; diff --git a/common/TCPServer.cpp b/common/TCPServer.cpp index cfba6e94a..2e3abfe2f 100644 --- a/common/TCPServer.cpp +++ b/common/TCPServer.cpp @@ -97,8 +97,12 @@ void BaseTCPServer::ListenNewConnections() { from.sin_family = AF_INET; fromlen = sizeof(from); LockMutex lock(&MSock); +#ifndef DARWIN // Corysia - On OSX, 0 is a valid fd. if (!sock) return; +#else + if (sock == -1) return; +#endif // Check for pending connects #ifdef _WINDOWS diff --git a/common/ipc_mutex.cpp b/common/ipc_mutex.cpp index 1ac88538c..331144eca 100644 --- a/common/ipc_mutex.cpp +++ b/common/ipc_mutex.cpp @@ -55,10 +55,17 @@ namespace EQEmu { std::string final_name = name; final_name += ".lock"; +#ifdef __DARWIN +#if __DARWIN_C_LEVEL < 200809L imp_->fd_ = open(final_name.c_str(), - O_RDWR | O_CREAT | O_CLOEXEC, + O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); - +#else + imp_->fd_ = open(final_name.c_str(), + O_RDWR | O_CREAT | O_CLOEXEC, + S_IRUSR | S_IWUSR); +#endif +#endif if(imp_->fd_ == -1) { EQ_EXCEPT("IPC Mutex", "Could not create mutex."); } diff --git a/eqlaunch/CMakeLists.txt b/eqlaunch/CMakeLists.txt index 0f0114c88..b636a18cf 100644 --- a/eqlaunch/CMakeLists.txt +++ b/eqlaunch/CMakeLists.txt @@ -30,7 +30,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(eqlaunch "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(eqlaunch "z") TARGET_LINK_LIBRARIES(eqlaunch "m") - TARGET_LINK_LIBRARIES(eqlaunch "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(eqlaunch "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(eqlaunch "pthread") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/loginserver/CMakeLists.txt b/loginserver/CMakeLists.txt index ba96b1f61..9ded859e5 100644 --- a/loginserver/CMakeLists.txt +++ b/loginserver/CMakeLists.txt @@ -58,7 +58,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(loginserver "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(loginserver "z") TARGET_LINK_LIBRARIES(loginserver "m") - TARGET_LINK_LIBRARIES(loginserver "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(loginserver "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(loginserver "pthread") TARGET_LINK_LIBRARIES(loginserver "EQEmuAuthCrypto") TARGET_LINK_LIBRARIES(loginserver "cryptopp") diff --git a/queryserv/CMakeLists.txt b/queryserv/CMakeLists.txt index a8480ca94..33be865e0 100644 --- a/queryserv/CMakeLists.txt +++ b/queryserv/CMakeLists.txt @@ -36,7 +36,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(queryserv "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(queryserv "z") TARGET_LINK_LIBRARIES(queryserv "m") - TARGET_LINK_LIBRARIES(queryserv "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(queryserv "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(queryserv "pthread") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/shared_memory/CMakeLists.txt b/shared_memory/CMakeLists.txt index 863b5633f..3d23a1b01 100644 --- a/shared_memory/CMakeLists.txt +++ b/shared_memory/CMakeLists.txt @@ -38,7 +38,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(shared_memory "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(shared_memory "z") TARGET_LINK_LIBRARIES(shared_memory "m") - TARGET_LINK_LIBRARIES(shared_memory "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(shared_memory "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(shared_memory "pthread") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 80f6a2f1d..aef5124c9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(tests "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(tests "z") TARGET_LINK_LIBRARIES(tests "m") - TARGET_LINK_LIBRARIES(tests "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(loginserver "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(tests "pthread") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/ucs/CMakeLists.txt b/ucs/CMakeLists.txt index 27a8a072d..44681831c 100644 --- a/ucs/CMakeLists.txt +++ b/ucs/CMakeLists.txt @@ -38,7 +38,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(ucs "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(ucs "z") TARGET_LINK_LIBRARIES(ucs "m") - TARGET_LINK_LIBRARIES(ucs "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(ucs "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(ucs "pthread") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/world/CMakeLists.txt b/world/CMakeLists.txt index 2decbf4c9..3ac008267 100644 --- a/world/CMakeLists.txt +++ b/world/CMakeLists.txt @@ -84,7 +84,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(world "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(world "z") TARGET_LINK_LIBRARIES(world "m") - TARGET_LINK_LIBRARIES(world "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(world "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(world "pthread") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/world/net.cpp b/world/net.cpp index 3c5df74a2..d7179bffe 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -56,7 +56,7 @@ #include #include #include - #ifndef FREEBSD + #if not defined (FREEBSD) && not defined (DARWIN) union semun { int val; struct semid_ds *buf; diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 49410f0f2..e582e0c45 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -230,7 +230,9 @@ IF(UNIX) TARGET_LINK_LIBRARIES(zone "${CMAKE_DL_LIBS}") TARGET_LINK_LIBRARIES(zone "z") TARGET_LINK_LIBRARIES(zone "m") - TARGET_LINK_LIBRARIES(zone "rt") + IF(NOT DARWIN) + TARGET_LINK_LIBRARIES(zone "rt") + ENDIF(NOT DARWIN) TARGET_LINK_LIBRARIES(zone "pthread") ADD_DEFINITIONS(-fPIC) ENDIF(UNIX) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index cde2b143f..0a50d8cdc 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -12483,7 +12483,15 @@ void Client::Handle_OP_GuildCreate(const EQApplicationPacket *app) // char *GuildName = (char *)app->pBuffer; +#ifdef DARWIN +#if __DARWIN_C_LEVEL < 200809L + if (strlen(GuildName) > 60) +#else if(strnlen(GuildName, 64) > 60) +#endif // __DARWIN_C_LEVEL +#else + if(strnlen(GuildName, 64) > 60) +#endif // DARWIN { Message(clientMessageError, "Guild name too long."); return; @@ -12941,7 +12949,15 @@ void Client::Handle_OP_LFGuild(const EQApplicationPacket *app) VERIFY_PACKET_LENGTH(OP_LFGuild, app, LFGuild_PlayerToggle_Struct); LFGuild_PlayerToggle_Struct *pts = (LFGuild_PlayerToggle_Struct *)app->pBuffer; +#ifdef DARWIN +#if __DARWIN_C_LEVEL < 200809L + if (strlen(pts->Comment) > 256) +#else if(strnlen(pts->Comment, 256) > 256) +#endif // __DARWIN_C_LEVEL +#else + if(strnlen(pts->Comment, 256) > 256) +#endif // DARWIN return; ServerPacket* pack = new ServerPacket(ServerOP_QueryServGeneric, strlen(GetName()) + strlen(pts->Comment) + 38); @@ -12968,7 +12984,15 @@ void Client::Handle_OP_LFGuild(const EQApplicationPacket *app) VERIFY_PACKET_LENGTH(OP_LFGuild, app, LFGuild_GuildToggle_Struct); LFGuild_GuildToggle_Struct *gts = (LFGuild_GuildToggle_Struct *)app->pBuffer; - if(strnlen(gts->Comment, 256) > 256) +#ifdef DARWIN +#if __DARWIN_C_LEVEL < 200809L + if (strlen(gts->Comment) > 256) +#else + if(strnlen(gts->Comment, 256) > 256) +#endif // __DARWIN_C_LEVEL +#else + if(strnlen(gts->Comment, 256) > 256) +#endif // __DARWIN return; ServerPacket* pack = new ServerPacket(ServerOP_QueryServGeneric, strlen(GetName()) + strlen(gts->Comment) + strlen(guild_mgr.GetGuildName(GuildID())) + 43);