summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2005-09-10 22:58:06 +0000
committerkientzle <kientzle@FreeBSD.org>2005-09-10 22:58:06 +0000
commit9d88c7f7b7004dffafb8e7e5d1d098ed506b015a (patch)
tree2f58e10266a64d70146a7581d052bf09013f4457
parent70f9da67193dd6865f9791384929a04b50f95003 (diff)
downloadFreeBSD-src-9d88c7f7b7004dffafb8e7e5d1d098ed506b015a.zip
FreeBSD-src-9d88c7f7b7004dffafb8e7e5d1d098ed506b015a.tar.gz
Style issue: Don't include <wchar.h> where it is not actually needed.
(wchar_t is defined in stddef.h, and only two files need more than that.) Portability: Since the wchar requirements are really quite modest, it's easy to define basic replacements for wcslen, wcscmp, wcscpy, etc, for use on systems that lack <wchar.h>. In particular, this allows libarchive to be used on older OpenBSD systems.
-rw-r--r--lib/libarchive/Makefile2
-rw-r--r--lib/libarchive/archive_entry.c24
-rw-r--r--lib/libarchive/archive_entry.h3
-rw-r--r--lib/libarchive/archive_private.h2
-rw-r--r--lib/libarchive/archive_read_support_format_tar.c27
-rw-r--r--lib/libarchive/archive_write_set_format_pax.c1
6 files changed, 49 insertions, 10 deletions
diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile
index 1428c82..6aeff8f 100644
--- a/lib/libarchive/Makefile
+++ b/lib/libarchive/Makefile
@@ -7,7 +7,7 @@
LIB= archive
-VERSION= 1.02.026
+VERSION= 1.02.032
ARCHIVE_API_FEATURE= 2
ARCHIVE_API_VERSION= 2
SHLIB_MAJOR= ${ARCHIVE_API_VERSION}
diff --git a/lib/libarchive/archive_entry.c b/lib/libarchive/archive_entry.c
index a3919e5..742a232 100644
--- a/lib/libarchive/archive_entry.c
+++ b/lib/libarchive/archive_entry.c
@@ -33,11 +33,33 @@ __FBSDID("$FreeBSD$");
#include <ext2fs/ext2_fs.h> /* for Linux file flags */
#endif
#include <limits.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <wchar.h>
+/* Obtain suitable wide-character manipulation functions. */
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#else
+static size_t wcslen(const wchar_t *s)
+{
+ const wchar_t *p = s;
+ while (*p != L'\0')
+ ++p;
+ return p - s;
+}
+static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2)
+{
+ wchar_t *dest = s1;
+ while((*s1 = *s2) != L'\0')
+ ++s1, ++s2;
+ return dest;
+}
+#define wmemcpy(a,b,i) (wchar_t *)memcpy((a),(b),(i)*sizeof(wchar_t))
+/* Good enough for simple equality testing, but not for sorting. */
+#define wmemcmp(a,b,i) memcmp((a),(b),(i)*sizeof(wchar_t))
+#endif
#include "archive.h"
#include "archive_entry.h"
diff --git a/lib/libarchive/archive_entry.h b/lib/libarchive/archive_entry.h
index dec8b96..8d9fdef 100644
--- a/lib/libarchive/archive_entry.h
+++ b/lib/libarchive/archive_entry.h
@@ -29,9 +29,8 @@
#ifndef ARCHIVE_ENTRY_H_INCLUDED
#define ARCHIVE_ENTRY_H_INCLUDED
+#include <stddef.h> /* for wchar_t */
#include <unistd.h>
-#include <wchar.h>
-
#ifdef __cplusplus
extern "C" {
diff --git a/lib/libarchive/archive_private.h b/lib/libarchive/archive_private.h
index 0b96180..7c03937 100644
--- a/lib/libarchive/archive_private.h
+++ b/lib/libarchive/archive_private.h
@@ -29,8 +29,6 @@
#ifndef ARCHIVE_PRIVATE_H_INCLUDED
#define ARCHIVE_PRIVATE_H_INCLUDED
-#include <wchar.h>
-
#include "archive.h"
#include "archive_string.h"
diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c
index 882d2df..b79140d 100644
--- a/lib/libarchive/archive_read_support_format_tar.c
+++ b/lib/libarchive/archive_read_support_format_tar.c
@@ -29,11 +29,31 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <errno.h>
+#include <stddef.h>
/* #include <stdint.h> */ /* See archive_platform.h */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+
+/* Obtain suitable wide-character manipulation functions. */
+#ifdef HAVE_WCHAR_H
#include <wchar.h>
+#else
+static int wcscmp(const wchar_t *s1, const wchar_t *s2)
+{
+ int diff = *s1 - *s2;
+ while(*s1 && diff == 0)
+ diff = (int)*++s1 - (int)*++s2;
+ return diff;
+}
+static size_t wcslen(const wchar_t *s)
+{
+ const wchar_t *p = s;
+ while (*p)
+ p++;
+ return p - s;
+}
+#endif
#include "archive.h"
#include "archive_entry.h"
@@ -1079,11 +1099,12 @@ pax_header(struct archive *a, struct tar *tar, struct archive_entry *entry,
}
/* Null-terminate 'key' value. */
- key = tar->pax_entry;
+ wp = key = tar->pax_entry;
if (key[0] == L'=')
return (-1);
- wp = wcschr(key, L'=');
- if (wp == NULL) {
+ while (*wp && *wp != L'=')
+ ++wp;
+ if (*wp == L'\0' || wp == NULL) {
archive_set_error(a, ARCHIVE_ERRNO_MISC,
"Invalid pax extended attributes");
return (ARCHIVE_WARN);
diff --git a/lib/libarchive/archive_write_set_format_pax.c b/lib/libarchive/archive_write_set_format_pax.c
index 60288eb..54e8581 100644
--- a/lib/libarchive/archive_write_set_format_pax.c
+++ b/lib/libarchive/archive_write_set_format_pax.c
@@ -32,7 +32,6 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <wchar.h>
#include "archive.h"
#include "archive_entry.h"
OpenPOWER on IntegriCloud