From 80837524ef1b8090828a47a8e281e92d7700c8e6 Mon Sep 17 00:00:00 2001 From: nia Date: Mon, 4 May 2026 14:37:12 +0200 Subject: [PATCH 1/2] Add build support for NetBSD. Verified to also build on FreeBSD. Signed-off-by: Nia --- Makefile.shared | 8 +++++++- include/compat.h | 9 ++++++--- src/mmulti.c | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile.shared b/Makefile.shared index 118e8b0a..6901fb82 100644 --- a/Makefile.shared +++ b/Makefile.shared @@ -31,6 +31,9 @@ ifndef PLATFORM ifneq (,$(findstring -freebsd,$(TARGETMACHINE))) PLATFORM=BSD endif + ifneq (,$(findstring -netbsd,$(TARGETMACHINE))) + PLATFORM=BSD + endif ifneq (,$(findstring -mingw32,$(TARGETMACHINE))) PLATFORM=WINDOWS endif @@ -96,7 +99,10 @@ ifeq ($(RENDERTYPE),SDL) ifneq (,$(shell $(PKGCONFIG) --atleast-version=3.4 gtk+-3.0 && echo yes)) HAVE_GTK=1 GTKCONFIG_CFLAGS=-DHAVE_GTK $(shell $(PKGCONFIG) --cflags gtk+-3.0) - GTKCONFIG_LIBS=$(shell $(PKGCONFIG) --libs gtk+-3.0) -ldl + GTKCONFIG_LIBS=$(shell $(PKGCONFIG) --libs gtk+-3.0) + ifeq ($(PLATFORM),LINUX) + BUILDLDFLAGS+= -ldl + endif else HAVE_GTK=0 endif diff --git a/include/compat.h b/include/compat.h index 387f121a..807e5625 100644 --- a/include/compat.h +++ b/include/compat.h @@ -37,6 +37,9 @@ #ifndef _DARWIN_C_SOURCE # define _DARWIN_C_SOURCE 1 #endif +#ifdef __NetBSD__ +# define _NETBSD_SOURCE 1 // https://gnats.netbsd.org/60227 +#endif #if defined(_MSC_VER) #define _CRT_DECLARE_NONSTDC_NAMES 0 @@ -120,9 +123,9 @@ typedef unsigned __int64 uint64_t; # define B_LITTLE_ENDIAN 0 # define B_BIG_ENDIAN 1 # endif -# define B_SWAP64(x) __bswap64(x) -# define B_SWAP32(x) __bswap32(x) -# define B_SWAP16(x) __bswap16(x) +# define B_SWAP64(x) bswap64(x) +# define B_SWAP32(x) bswap32(x) +# define B_SWAP16(x) bswap16(x) #elif defined(__APPLE__) # if defined(__LITTLE_ENDIAN__) diff --git a/src/mmulti.c b/src/mmulti.c index 9e0e1bba..93d1fa96 100644 --- a/src/mmulti.c +++ b/src/mmulti.c @@ -911,9 +911,11 @@ static int lookuphost(const char *name, struct sockaddr *host, int warnifmany) memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_ADDRCONFIG; hints.ai_family = domain; +#ifdef AI_V4MAPPED if (domain == PF_INET6) { hints.ai_flags |= AI_V4MAPPED; } +#endif hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = IPPROTO_UDP; From 3667f17ee87fad4627d8a77c0ca64b2c5d006665 Mon Sep 17 00:00:00 2001 From: nia Date: Mon, 4 May 2026 14:37:43 +0200 Subject: [PATCH 2/2] Fix a "char subscript" compiler warning. The argument of these functions is of type int, but only a very restricted subset of values are actually valid. The argument must either be the value of the macro EOF (which has a negative value), or must be a non-negative value within the range representable as unsigned char. Passing invalid values leads to undefined behavior. Signed-off-by: Nia --- src/compat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compat.c b/src/compat.c index a1962186..621678fa 100644 --- a/src/compat.c +++ b/src/compat.c @@ -44,7 +44,7 @@ char *strlwr(char *s) { char *t = s; if (!s) return s; - while (*t) { *t = tolower(*t); t++; } + while (*t) { *t = tolower((unsigned char)*t); t++; } return s; }