]> 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 06:05:18 +0000 (17:05 +1100)
(cherry picked from commit 5f07fe8cbb9d3696e94bb9c64625e23721c95c4e)

config.h.in
configure
configure.ac
lib/isc/include/isc/string.h
lib/isc/string.c
lib/isc/win32/libisc.def.in

index 945e12318bce3d45170dd5e7ebb81a3918aab75c..7806015d2425d3aca445fd388ca27ee0c60e09e7 100644 (file)
 /* Define to 1 if you have the `strlcpy' function. */
 #undef HAVE_STRLCPY
 
+/* Define to 1 if you have the `strnstr' function. */
+#undef HAVE_STRNSTR
+
 /* Define to 1 if you have the `sysconf' function. */
 #undef HAVE_SYSCONF
 
index b1491f6c0c2013fbb79f162ffd650fbaf77c7c79..9113596b8fa0f1c1f981f4a518cfd4273f094b0a 100755 (executable)
--- a/configure
+++ b/configure
@@ -19633,7 +19633,7 @@ fi
 #
 # Check for some other useful functions that are not ever-present.
 #
-for ac_func in strlcpy strlcat
+for ac_func in strlcpy strlcat strnstr
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
index 21b087adbf8d0754ff9d610a4a083d31d98b1694..eaad0097eceb2413cf11851cbb3097c2c0210347 100644 (file)
@@ -1701,7 +1701,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])
 
 AC_SUBST(READLINE_LIB)
 
index 2d7f8df9494c692511b2b62235912f7a7474e334..1bc569309119565286d48269adf4c2e93501b488 100644 (file)
@@ -32,6 +32,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 d307758a239dd7884a0ef7827fffc4b4e68ed622..5de6d88b2754ee182f9828a03de680289978e3df 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:
@@ -48,6 +54,7 @@
 #include <string.h>
 
 #include <isc/string.h> /* IWYU pragma: keep */
+#include <isc/util.h>
 
 #if !defined(HAVE_STRLCPY)
 size_t
@@ -109,6 +116,29 @@ 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, *r;
+       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--;
+       }
+       DE_CONST(s, r);
+       return (r);
+}
+#endif
+
 int
 isc_string_strerror_r(int errnum, char *buf, size_t buflen) {
 #if defined(_WIN32) || defined(_WIN64)
index 56358f3c64652aa500ab3d6334f9ee420935052c..a98ae707c6735b8e6e4eb6a046905a3161b5656c 100644 (file)
@@ -778,6 +778,7 @@ pkcs_C_VerifyUpdate
 @END PKCS11
 strlcat
 strlcpy
+strnstr
 syslog
 
 @IF NOLONGER