diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ffaf20f..f0eaf8de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,6 +160,9 @@ else() else() list(APPEND yquake2LinkerFlags "-lnetwork") endif() + if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + list(APPEND yquake2LinkerFlags "-lsocket -lnsl") + endif() endif() if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") diff --git a/Makefile b/Makefile index 16f03503..180622ff 100755 --- a/Makefile +++ b/Makefile @@ -339,6 +339,8 @@ else ifeq ($(YQ2_OSTYPE), Darwin) override LDFLAGS += -arch $(YQ2_ARCH) else ifeq ($(YQ2_OSTYPE), Haiku) override LDFLAGS += -lm -lnetwork +else ifeq ($(YQ2_OSTYPE), SunOS) +override LDFLAGS += -lm -lsocket -lnsl endif ifneq ($(YQ2_OSTYPE), Darwin) diff --git a/src/backends/generic/misc.c b/src/backends/generic/misc.c index a97a20cf..a0741c5f 100644 --- a/src/backends/generic/misc.c +++ b/src/backends/generic/misc.c @@ -29,7 +29,7 @@ #include "../../common/header/shared.h" -#if defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +#if defined(__linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun) #include // readlink(), amongst others #endif @@ -73,14 +73,18 @@ static void SetExecutablePath(char* exePath) exePath[0] = '\0'; } -#elif defined(__linux) +#elif defined(__linux) || defined(__sun) // all the platforms that have /proc/$pid/exe or similar that symlink the // real executable - basiscally Linux and the BSDs except for FreeBSD which // doesn't enable proc by default and has a sysctl() for this. OpenBSD once // had /proc but removed it for security reasons. char buf[PATH_MAX] = {0}; +#if defined(__linux) snprintf(buf, sizeof(buf), "/proc/%d/exe", getpid()); +#else + snprintf(buf, sizeof(buf), "/proc/%ld/path/a.out", getpid()); +#endif // readlink() doesn't null-terminate! int len = readlink(buf, exePath, PATH_MAX-1); if (len <= 0) diff --git a/src/backends/unix/network.c b/src/backends/unix/network.c index f0f2a6b9..afeebd3e 100644 --- a/src/backends/unix/network.c +++ b/src/backends/unix/network.c @@ -34,6 +34,12 @@ #include #include #include +#if defined(__sun) +#include +#if !defined(MAX) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif +#endif #include #include #include