From 657273ac43e4dffda75d0bc58d9523907b8456b4 Mon Sep 17 00:00:00 2001
From: Ed Braaten <ed.braaten@protonmail.ch>
Date: Sat, 20 Apr 2024 15:10:11 -0700
Subject: [PATCH] Proposed fix to issue #77 Build Fail on Fedora

(https://github.com/OpenRTX/dmrconfig/issues/77)

Provides BSD strnstr() function if not defined by build
environment's C library.
---
 radio.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/radio.c b/radio.c
index e81192f..b084e30 100644
--- a/radio.c
+++ b/radio.c
@@ -63,6 +63,37 @@ int radio_progress;                     // Read/write progress counter
 
 static radio_device_t *device;          // Device-dependent interface
 
+
+// strnstr() is a BSD function not found in many GNU/Linux distros
+#ifndef strnstr
+
+/*
+ * Find the first occurrence of find in s, where the search is limited to the
+ * first slen characters of s.
+ */
+char *
+strnstr(const char *s, const char *find, size_t slen)
+{
+	char c, sc;
+	size_t len;
+
+	if ((c = *find++) != '\0') {
+		len = strlen(find);
+		do {
+			do {
+				if (slen-- < 1 || (sc = *s++) == '\0')
+					return (NULL);
+			} while (sc != c);
+			if (len > slen)
+				return (NULL);
+		} while (strncmp(s, find, len) != 0);
+		s--;
+	}
+	return ((char *)s);
+}
+#endif
+
+
 //
 // Close the serial port.
 //