[dev] [PATCH] Add compatibility for OpenBSD in tar

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Fri, 19 Jul 2013 00:31:29 +0200

From: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>

OpenBSD defines strlcpy function, and the declaration is a bit different
of the static declartion found in tar.c. The duplication of symbol name
with different type (one extern and other static, one returning int and
the other returning size_t) caused tar couldn't compile in OpenBSD.
---
 Makefile       |  1 +
 tar.c          |  8 ++------
 util/strlcpy.c | 11 +++++++++++
 3 files changed, 14 insertions(+), 6 deletions(-)
 create mode 100644 util/strlcpy.c
diff --git a/Makefile b/Makefile
index bd0c38c..882f2a6 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -20,6 +20,7 @@ LIB = \
 	util/putword.o   \
 	util/recurse.o   \
 	util/rm.o        \
+	util/strlcpy.o   \
 	util/sha1.o
 
 SRC = \
diff --git a/tar.c b/tar.c
index 3481942..00d1ae0 100644
--- a/tar.c
+++ b/tar.c
_AT_@ -39,8 +39,9 @@ enum Type {
 	BLOCKDEV = '4', DIRECTORY = '5', FIFO = '6' 
 };
 
+extern size_t strlcpy(char *dst, const char *src, size_t n);
+
 static void putoctal(char *, unsigned, int);
-static int strlcpy(char *, const char *, int n);
 static int archive(const char *, const struct stat *, int);
 static int unarchive(char *, int, char[Blksiz]);
 static int print(char *, int , char[Blksiz]);
_AT_@ -142,11 +143,6 @@ putoctal(char *dst, unsigned num, int n)
 	snprintf(dst, n, "%.*o", n-1, num);
 }
 
-int 
-strlcpy(char *dst, const char *src, int n)
-{
-	return snprintf(dst, n, "%s", src);
-}
 
 int 
 archive(const char* path, const struct stat* sta, int type)
diff --git a/util/strlcpy.c b/util/strlcpy.c
new file mode 100644
index 0000000..d0e8d2e
--- /dev/null
+++ b/util/strlcpy.c
_AT_@ -0,0 +1,11 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <stdio.h>
+#include <string.h>
+
+size_t
+strlcpy(char *dst, const char *src, size_t n)
+{
+       return snprintf(dst, n, "%s", src);
+}
+
-- 
1.8.3.2
Received on Fri Jul 19 2013 - 00:31:29 CEST

This archive was generated by hypermail 2.3.0 : Fri Jul 19 2013 - 00:36:06 CEST