From b6353e6be65f19aa378be4a896629e0f7b807a81 Mon Sep 17 00:00:00 2001
From: Daniel Salzman <daniel.salzman@nic.cz>
Date: Wed, 2 Dec 2015 13:05:26 +0100
Subject: [PATCH] contrib: move strlcat and strcpy from internal

---
 Knot.files                                     |  8 ++++----
 src/Makefile.am                                |  8 ++++----
 .../internal => contrib/openbsd}/strlcat.c     |  3 +--
 .../internal => contrib/openbsd}/strlcat.h     |  0
 .../internal => contrib/openbsd}/strlcpy.c     |  3 +--
 .../internal => contrib/openbsd}/strlcpy.h     |  2 --
 src/knot/common/log.c                          |  2 +-
 src/knot/conf/conf.c                           |  2 +-
 src/knot/conf/confdb.c                         |  1 +
 src/knot/conf/confio.c                         |  2 +-
 src/knot/ctl/remote.c                          |  2 +-
 src/knot/nameserver/query_module.c             | 18 +++++++++++++++++-
 src/libknot/internal/sockaddr.c                |  2 +-
 src/utils/common/exec.c                        |  2 +-
 src/utils/common/params.c                      |  2 +-
 src/utils/knot1to2/cf-lex.c                    |  2 +-
 src/utils/knot1to2/cf-lex.l                    |  2 +-
 src/utils/knot1to2/cf-parse.tab.c              |  4 ++--
 src/utils/knot1to2/cf-parse.y                  |  4 ++--
 src/utils/knsupdate/knsupdate_exec.c           |  2 +-
 tests/base32hex.c                              |  2 +-
 tests/base64.c                                 |  2 +-
 tests/confio.c                                 |  2 +-
 tests/namedb.c                                 |  2 +-
 tests/zonedb.c                                 |  4 ++--
 25 files changed, 48 insertions(+), 35 deletions(-)
 rename src/{libknot/internal => contrib/openbsd}/strlcat.c (94%)
 rename src/{libknot/internal => contrib/openbsd}/strlcat.h (100%)
 rename src/{libknot/internal => contrib/openbsd}/strlcpy.c (94%)
 rename src/{libknot/internal => contrib/openbsd}/strlcpy.h (96%)

diff --git a/Knot.files b/Knot.files
index a49f32f4e..66add8be6 100644
--- a/Knot.files
+++ b/Knot.files
@@ -31,6 +31,10 @@ libtap/tap/float.h
 libtap/tap/macros.h
 samples/Makefile.am
 src/Makefile.am
+src/contrib/openbsd/strlcat.c
+src/contrib/openbsd/strlcat.h
+src/contrib/openbsd/strlcpy.c
+src/contrib/openbsd/strlcpy.h
 src/contrib/ucw/array-sort.h
 src/contrib/ucw/binsearch.h
 src/contrib/ucw/heap.c
@@ -375,10 +379,6 @@ src/libknot/internal/print.c
 src/libknot/internal/print.h
 src/libknot/internal/sockaddr.c
 src/libknot/internal/sockaddr.h
-src/libknot/internal/strlcat.c
-src/libknot/internal/strlcat.h
-src/libknot/internal/strlcpy.c
-src/libknot/internal/strlcpy.h
 src/libknot/internal/tolower.c
 src/libknot/internal/tolower.h
 src/libknot/internal/trie/hat-trie.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 094e60107..fa3bfa830 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,6 +24,8 @@ AM_LDFLAGS = $(CODE_COVERAGE_LDFLAGS)
 
 libcontrib_ladir = $(includedir)
 nobase_libcontrib_la_HEADERS =			\
+	contrib/openbsd/strlcat.h		\
+	contrib/openbsd/strlcpy.h		\
 	contrib/ucw/array-sort.h		\
 	contrib/ucw/binsearch.h			\
 	contrib/ucw/heap.h			\
@@ -84,8 +86,6 @@ nobase_libknot_internal_la_HEADERS = 		\
 	libknot/internal/net.h			\
 	libknot/internal/print.h		\
 	libknot/internal/sockaddr.h		\
-	libknot/internal/strlcat.h		\
-	libknot/internal/strlcpy.h		\
 	libknot/internal/tolower.h		\
 	libknot/internal/trie/hat-trie.h	\
 	libknot/internal/trie/murmurhash3.h	\
@@ -101,6 +101,8 @@ nobase_libknot_yparser_la_HEADERS = 		\
 
 # dynamic: libknot sources
 libcontrib_la_SOURCES = 			\
+	contrib/openbsd/strlcat.c		\
+	contrib/openbsd/strlcpy.c		\
 	contrib/ucw/heap.c			\
 	contrib/ucw/mempool.c			\
 	$(nobase_libcontrib_la_HEADERS)
@@ -153,8 +155,6 @@ libknot_internal_la_SOURCES = 			\
 	libknot/internal/net.c			\
 	libknot/internal/print.c		\
 	libknot/internal/sockaddr.c		\
-	libknot/internal/strlcat.c		\
-	libknot/internal/strlcpy.c		\
 	libknot/internal/tolower.c		\
 	libknot/internal/trie/hat-trie.c	\
 	libknot/internal/trie/murmurhash3.c	\
diff --git a/src/libknot/internal/strlcat.c b/src/contrib/openbsd/strlcat.c
similarity index 94%
rename from src/libknot/internal/strlcat.c
rename to src/contrib/openbsd/strlcat.c
index 1485dbfc8..140906253 100644
--- a/src/libknot/internal/strlcat.c
+++ b/src/contrib/openbsd/strlcat.c
@@ -17,8 +17,7 @@
 #include <sys/types.h>
 #include <string.h>
 
-#include "libknot/internal/macros.h"
-#include "libknot/internal/strlcat.h"
+#include "contrib/openbsd/strlcat.h"
 
 size_t
 knot_strlcat(char *dst, const char *src, size_t siz)
diff --git a/src/libknot/internal/strlcat.h b/src/contrib/openbsd/strlcat.h
similarity index 100%
rename from src/libknot/internal/strlcat.h
rename to src/contrib/openbsd/strlcat.h
diff --git a/src/libknot/internal/strlcpy.c b/src/contrib/openbsd/strlcpy.c
similarity index 94%
rename from src/libknot/internal/strlcpy.c
rename to src/contrib/openbsd/strlcpy.c
index 2e276e556..eafc0e4b8 100644
--- a/src/libknot/internal/strlcpy.c
+++ b/src/contrib/openbsd/strlcpy.c
@@ -17,8 +17,7 @@
 #include <sys/types.h>
 #include <string.h>
 
-#include "libknot/internal/macros.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcpy.h"
 
 size_t
 knot_strlcpy(char *dst, const char *src, size_t siz)
diff --git a/src/libknot/internal/strlcpy.h b/src/contrib/openbsd/strlcpy.h
similarity index 96%
rename from src/libknot/internal/strlcpy.h
rename to src/contrib/openbsd/strlcpy.h
index 73343e4ab..6421068eb 100644
--- a/src/libknot/internal/strlcpy.h
+++ b/src/contrib/openbsd/strlcpy.h
@@ -20,8 +20,6 @@
 #define strlcpy(dst, src, size) knot_strlcpy(dst, src, size)
 #endif
 
-#include "libknot/internal/macros.h"
-
 /*
  * Copy src to string dst of size siz.  At most siz-1 characters
  * will be copied.  Always NUL terminates (unless siz == 0).
diff --git a/src/knot/common/log.c b/src/knot/common/log.c
index 5d5d58cfd..25820c4be 100644
--- a/src/knot/common/log.c
+++ b/src/knot/common/log.c
@@ -33,7 +33,7 @@
 #include "libknot/libknot.h"
 #include "libknot/internal/lists.h"
 #include "libknot/internal/macros.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcpy.h"
 
 /* Single log message buffer length (one line). */
 #define LOG_BUFLEN 512
diff --git a/src/knot/conf/conf.c b/src/knot/conf/conf.c
index e6c1e3946..3341764db 100644
--- a/src/knot/conf/conf.c
+++ b/src/knot/conf/conf.c
@@ -26,8 +26,8 @@
 #include "libknot/internal/macros.h"
 #include "libknot/internal/mem.h"
 #include "libknot/internal/sockaddr.h"
-#include "libknot/internal/strlcat.h"
 #include "libknot/yparser/yptrafo.h"
+#include "contrib/openbsd/strlcat.h"
 
 /*! Configuration specific logging. */
 #define CONF_LOG(severity, msg, ...) do { \
diff --git a/src/knot/conf/confdb.c b/src/knot/conf/confdb.c
index 2f9c79027..05c610823 100644
--- a/src/knot/conf/confdb.c
+++ b/src/knot/conf/confdb.c
@@ -28,6 +28,7 @@
 #include "knot/conf/confdb.h"
 #include "libknot/errcode.h"
 #include "libknot/yparser/yptrafo.h"
+#include "contrib/openbsd/strlcpy.h"
 
 /*
  * A simple configuration:
diff --git a/src/knot/conf/confio.c b/src/knot/conf/confio.c
index 8d570b40b..4d8633566 100644
--- a/src/knot/conf/confio.c
+++ b/src/knot/conf/confio.c
@@ -22,7 +22,7 @@
 #include "knot/conf/tools.h"
 #include "libknot/yparser/yptrafo.h"
 #include "libknot/internal/mem.h"
-#include "libknot/internal/strlcat.h"
+#include "contrib/openbsd/strlcat.h"
 
 #define FCN(io)	(io->fcn != NULL) ? io->fcn(io) : KNOT_EOK
 
diff --git a/src/knot/ctl/remote.c b/src/knot/ctl/remote.c
index 912089782..378540472 100644
--- a/src/knot/ctl/remote.c
+++ b/src/knot/ctl/remote.c
@@ -33,8 +33,8 @@
 #include "libknot/internal/macros.h"
 #include "libknot/internal/mem.h"
 #include "libknot/internal/net.h"
-#include "libknot/internal/strlcpy.h"
 #include "libknot/yparser/yptrafo.h"
+#include "contrib/openbsd/strlcpy.h"
 
 #define KNOT_CTL_REALM "knot."
 #define KNOT_CTL_REALM_EXT ("." KNOT_CTL_REALM)
diff --git a/src/knot/nameserver/query_module.c b/src/knot/nameserver/query_module.c
index 0b6da98e7..856df413c 100644
--- a/src/knot/nameserver/query_module.c
+++ b/src/knot/nameserver/query_module.c
@@ -1,6 +1,22 @@
+/*  Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include "knot/nameserver/query_module.h"
 #include "libknot/libknot.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcpy.h"
 
 /* Compiled-in module headers. */
 #include "knot/modules/synth_record.h"
diff --git a/src/libknot/internal/sockaddr.c b/src/libknot/internal/sockaddr.c
index 0212ab4cc..4554a41dd 100644
--- a/src/libknot/internal/sockaddr.c
+++ b/src/libknot/internal/sockaddr.c
@@ -22,8 +22,8 @@
 #include "libknot/internal/utils.h"
 #include "libknot/internal/sockaddr.h"
 #include "libknot/internal/errcode.h"
-#include "libknot/internal/strlcpy.h"
 #include "libknot/internal/consts.h"
+#include "contrib/openbsd/strlcpy.h"
 
 int sockaddr_len(const struct sockaddr *ss)
 {
diff --git a/src/utils/common/exec.c b/src/utils/common/exec.c
index 263e980f2..9a94ad12f 100644
--- a/src/utils/common/exec.c
+++ b/src/utils/common/exec.c
@@ -27,8 +27,8 @@
 #include "libknot/internal/lists.h"
 #include "libknot/internal/print.h"
 #include "libknot/internal/sockaddr.h"
-#include "libknot/internal/strlcat.h"
 #include "libknot/internal/wire_ctx.h"
+#include "contrib/openbsd/strlcat.h"
 
 static lookup_table_t rtypes[] = {
 	{ KNOT_RRTYPE_A,      "has IPv4 address" },
diff --git a/src/utils/common/params.c b/src/utils/common/params.c
index 5b9ab8caa..bf6e68909 100644
--- a/src/utils/common/params.c
+++ b/src/utils/common/params.c
@@ -30,7 +30,7 @@
 #include "utils/common/token.h"
 #include "libknot/libknot.h"
 #include "libknot/internal/mempattern.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcpy.h"
 
 #define IPV4_REVERSE_DOMAIN	"in-addr.arpa."
 #define IPV6_REVERSE_DOMAIN	"ip6.arpa."
diff --git a/src/utils/knot1to2/cf-lex.c b/src/utils/knot1to2/cf-lex.c
index 7408cd6db..05b723e98 100644
--- a/src/utils/knot1to2/cf-lex.c
+++ b/src/utils/knot1to2/cf-lex.c
@@ -860,7 +860,7 @@ static yyconst flex_int32_t yy_rule_can_match_eol[92] =
 #include "utils/knot1to2/includes.h"
 #include "utils/knot1to2/extra.h"
 #include "utils/knot1to2/cf-parse.tab.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcpy.h"
 
 /* Imported symbols. */
 #define lval (yylval->tok)
diff --git a/src/utils/knot1to2/cf-lex.l b/src/utils/knot1to2/cf-lex.l
index 0b8737a60..4385ba5f3 100644
--- a/src/utils/knot1to2/cf-lex.l
+++ b/src/utils/knot1to2/cf-lex.l
@@ -28,7 +28,7 @@
 #include "utils/knot1to2/includes.h"
 #include "utils/knot1to2/extra.h"
 #include "utils/knot1to2/cf-parse.tab.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcpy.h"
 
 /* Imported symbols. */
 #define lval (yylval->tok)
diff --git a/src/utils/knot1to2/cf-parse.tab.c b/src/utils/knot1to2/cf-parse.tab.c
index d9929b4d1..ed13f5e90 100644
--- a/src/utils/knot1to2/cf-parse.tab.c
+++ b/src/utils/knot1to2/cf-parse.tab.c
@@ -80,8 +80,8 @@
 #include "utils/knot1to2/scheme.h"
 #include "utils/knot1to2/extra.h"
 #include "utils/knot1to2/cf-parse.tab.h"
-#include "libknot/internal/strlcat.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcat.h"
+#include "contrib/openbsd/strlcpy.h"
 
 #define DEFAULT_PORT		53
 #define DEFAULT_CTL_PORT	5533
diff --git a/src/utils/knot1to2/cf-parse.y b/src/utils/knot1to2/cf-parse.y
index 89332cf76..aad6effeb 100644
--- a/src/utils/knot1to2/cf-parse.y
+++ b/src/utils/knot1to2/cf-parse.y
@@ -24,8 +24,8 @@
 #include "utils/knot1to2/scheme.h"
 #include "utils/knot1to2/extra.h"
 #include "utils/knot1to2/cf-parse.tab.h"
-#include "libknot/internal/strlcat.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcat.h"
+#include "contrib/openbsd/strlcpy.h"
 
 #define DEFAULT_PORT		53
 #define DEFAULT_CTL_PORT	5533
diff --git a/src/utils/knsupdate/knsupdate_exec.c b/src/utils/knsupdate/knsupdate_exec.c
index df651929d..76d45eca1 100644
--- a/src/utils/knsupdate/knsupdate_exec.c
+++ b/src/utils/knsupdate/knsupdate_exec.c
@@ -34,7 +34,7 @@
 #include "libknot/internal/getline.h"
 #include "libknot/internal/macros.h"
 #include "libknot/internal/mem.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcpy.h"
 
 /* Declarations of cmd parse functions. */
 typedef int (*cmd_handle_f)(const char *lp, knsupdate_params_t *params);
diff --git a/tests/base32hex.c b/tests/base32hex.c
index c9e9198b4..442a82988 100644
--- a/tests/base32hex.c
+++ b/tests/base32hex.c
@@ -21,7 +21,7 @@
 
 #include "libknot/libknot.h"
 #include "libknot/internal/base32hex.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcpy.h"
 
 #define BUF_LEN			256
 #define MAX_BIN_DATA_LEN	((INT32_MAX / 8) * 5)
diff --git a/tests/base64.c b/tests/base64.c
index db4580999..6b680e361 100644
--- a/tests/base64.c
+++ b/tests/base64.c
@@ -21,7 +21,7 @@
 
 #include "libknot/libknot.h"
 #include "libknot/internal/base64.h"
-#include "libknot/internal/strlcpy.h"
+#include "contrib/openbsd/strlcpy.h"
 
 #define BUF_LEN			256
 #define MAX_BIN_DATA_LEN	((INT32_MAX / 4) * 3)
diff --git a/tests/confio.c b/tests/confio.c
index 9e05e5a1d..b84ac928c 100644
--- a/tests/confio.c
+++ b/tests/confio.c
@@ -20,8 +20,8 @@
 #include "knot/conf/confio.h"
 #include "knot/conf/tools.h"
 #include "knot/ctl/remote.h"
-#include "libknot/internal/strlcat.h"
 #include "libknot/internal/mem.h"
+#include "contrib/openbsd/strlcat.h"
 
 #define SKIP_OPENBSD	skip("Nested transactions are not supported on OpenBSD");
 #define OUT_LEN		1024
diff --git a/tests/namedb.c b/tests/namedb.c
index 1dbb4ca89..074657db4 100644
--- a/tests/namedb.c
+++ b/tests/namedb.c
@@ -26,8 +26,8 @@
 #include "libknot/internal/mem.h"
 #include "libknot/internal/namedb/namedb_lmdb.h"
 #include "libknot/internal/namedb/namedb_trie.h"
-#include "libknot/internal/strlcpy.h"
 #include "libknot/libknot.h"
+#include "contrib/openbsd/strlcpy.h"
 #include "contrib/ucw/mempool.h"
 
 /* UCW array sorting defines. */
diff --git a/tests/zonedb.c b/tests/zonedb.c
index f522ba478..39b583f51 100644
--- a/tests/zonedb.c
+++ b/tests/zonedb.c
@@ -16,10 +16,10 @@
 
 #include <tap/basic.h>
 
-#include "libknot/internal/strlcat.h"
-#include "libknot/internal/strlcpy.h"
 #include "knot/zone/zone.h"
 #include "knot/zone/zonedb.h"
+#include "contrib/openbsd/strlcat.h"
+#include "contrib/openbsd/strlcpy.h"
 
 #define ZONE_COUNT 10
 static const char *zone_list[ZONE_COUNT] = {
-- 
GitLab