From baf81ffd65139a9df8e45ebc1590b282528b8f7a Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen@gmail.com>
Date: Mon, 21 Feb 2022 12:39:18 +0000
Subject: [PATCH] netbsd build fix/update.

hmac is already defined in this platform.
Sys_FindExecutableName implementation close enough from FreeBSD's
---
 hmac.c       | 2 +-
 hmac.h       | 6 +++---
 sys_shared.c | 6 +++++-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/hmac.c b/hmac.c
index 8b6d2f62..561e5efc 100644
--- a/hmac.c
+++ b/hmac.c
@@ -1,7 +1,7 @@
 #include "darkplaces.h"
 #include "hmac.h"
 
-qbool hmac(
+qbool d_hmac(
 	hashfunc_t hfunc, int hlen, int hblock,
 	unsigned char *out,
 	const unsigned char *in, int n,
diff --git a/hmac.h b/hmac.h
index 71108ab6..2d3f4f05 100644
--- a/hmac.h
+++ b/hmac.h
@@ -4,14 +4,14 @@
 #include "qtypes.h"
 
 typedef void (*hashfunc_t) (unsigned char *out, const unsigned char *in, int n);
-qbool hmac(
+qbool d_hmac(
 	hashfunc_t hfunc, int hlen, int hblock,
 	unsigned char *out,
 	const unsigned char *in, int n,
 	const unsigned char *key, int k
 );
 
-#define HMAC_MDFOUR_16BYTES(out, in, n, key, k) hmac(mdfour, 16, 64, out, in, n, key, k)
-#define HMAC_SHA256_32BYTES(out, in, n, key, k) hmac(sha256, 32, 64, out, in, n, key, k)
+#define HMAC_MDFOUR_16BYTES(out, in, n, key, k) d_hmac(mdfour, 16, 64, out, in, n, key, k)
+#define HMAC_SHA256_32BYTES(out, in, n, key, k) d_hmac(sha256, 32, 64, out, in, n, key, k)
 
 #endif
diff --git a/sys_shared.c b/sys_shared.c
index 39c9bf8b..c9f9c32f 100644
--- a/sys_shared.c
+++ b/sys_shared.c
@@ -18,7 +18,7 @@
 #pragma comment(lib, "winmm.lib")
 #endif
 #else
-# ifdef __FreeBSD__
+# if defined(__FreeBSD__) || defined(__NetBSD__)
 #  include <sys/sysctl.h>
 # endif
 # include <unistd.h>
@@ -552,8 +552,12 @@ static const char *Sys_FindExecutableName(void)
 #else
 	static char exenamebuf[MAX_OSPATH+1];
 	ssize_t n = -1;
+#if defined(__FreeBSD__) || defined(__NetBSD__)
 #if defined(__FreeBSD__)
 	int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+#else
+	int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME};
+#endif
 	size_t exenamebuflen = sizeof(exenamebuf)-1;
 	if (sysctl(mib, 4, exenamebuf, &exenamebuflen, NULL, 0) == 0)
 	{
-- 
2.39.5