From 9d88c7f7b7004dffafb8e7e5d1d098ed506b015a Mon Sep 17 00:00:00 2001 From: kientzle Date: Sat, 10 Sep 2005 22:58:06 +0000 Subject: Style issue: Don't include 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 . In particular, this allows libarchive to be used on older OpenBSD systems. --- lib/libarchive/Makefile | 2 +- lib/libarchive/archive_entry.c | 24 ++++++++++++++++++++- lib/libarchive/archive_entry.h | 3 +-- lib/libarchive/archive_private.h | 2 -- lib/libarchive/archive_read_support_format_tar.c | 27 +++++++++++++++++++++--- lib/libarchive/archive_write_set_format_pax.c | 1 - 6 files changed, 49 insertions(+), 10 deletions(-) (limited to 'lib') 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 /* for Linux file flags */ #endif #include +#include #include #include #include -#include +/* Obtain suitable wide-character manipulation functions. */ +#ifdef HAVE_WCHAR_H +#include +#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 /* for wchar_t */ #include -#include - #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 - #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 #include +#include /* #include */ /* See archive_platform.h */ #include #include #include + +/* Obtain suitable wide-character manipulation functions. */ +#ifdef HAVE_WCHAR_H #include +#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 #include #include -#include #include "archive.h" #include "archive_entry.h" -- cgit v1.1