]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use strnstr implementation from FreeBSD if not provided by OS
authorMark Andrews <marka@isc.org>
Thu, 15 Sep 2022 07:03:50 +0000 (17:03 +1000)
committerMark Andrews <marka@isc.org>
Tue, 4 Oct 2022 03:21:41 +0000 (14:21 +1100)
configure.ac
lib/isc/include/isc/string.h
lib/isc/string.c

index 037b10a0b69af45d126549392cbbbf41497cf619..04d400f8dea4aeb21989b5af253c6be073f9b4c1 100644 (file)
@@ -991,7 +991,7 @@ AS_IF([test "$enable_tcp_fastopen" = "yes"],
 #
 # Check for some other useful functions that are not ever-present.
 #
-AC_CHECK_FUNCS([strlcpy strlcat])
+AC_CHECK_FUNCS([strlcpy strlcat strnstr])
 
 #
 # Check for readline support
index 5469d69a0e2087861111b72c23c73d93fd1a2b63..fbf6129cbef29a180dd4ecf84afa9597fd7e2e8e 100644 (file)
@@ -31,6 +31,11 @@ size_t
 strlcat(char *dst, const char *src, size_t size);
 #endif /* if !defined(HAVE_STRLCAT) */
 
+#if !defined(HAVE_STRNSTR)
+char *
+strnstr(const char *s, const char *find, size_t slen);
+#endif /* if !defined(HAVE_STRNSTR) */
+
 int
 isc_string_strerror_r(int errnum, char *buf, size_t buflen);
 
index f1ee7748cd6503528381535371120e2e3f9a23f6..09cf5d636c1248891aa3ae2f718a198384936d63 100644 (file)
  */
 
 /*
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
  * Copyright (c) 1990, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -109,6 +115,28 @@ strlcat(char *dst, const char *src, size_t size) {
 }
 #endif /* !defined(HAVE_STRLCAT) */
 
+#if !defined(HAVE_STRNSTR)
+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
+
 int
 isc_string_strerror_r(int errnum, char *buf, size_t buflen) {
        return (strerror_r(errnum, buf, buflen));