diff options
author | Tim Kientzle <kientzle@FreeBSD.org> | 2005-09-10 22:58:06 +0000 |
---|---|---|
committer | Tim Kientzle <kientzle@FreeBSD.org> | 2005-09-10 22:58:06 +0000 |
commit | 1dd0aa0c181857157cc5e838f0f0cc8d288fba36 (patch) | |
tree | 2f58e10266a64d70146a7581d052bf09013f4457 /lib | |
parent | c3614b63a2080188c94a10b463cbbd04a1652b52 (diff) |
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.
Notes
Notes:
svn path=/head/; revision=149964
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libarchive/Makefile | 2 | ||||
-rw-r--r-- | lib/libarchive/archive_entry.c | 24 | ||||
-rw-r--r-- | lib/libarchive/archive_entry.h | 3 | ||||
-rw-r--r-- | lib/libarchive/archive_private.h | 2 | ||||
-rw-r--r-- | lib/libarchive/archive_read_support_format_tar.c | 27 | ||||
-rw-r--r-- | lib/libarchive/archive_write_set_format_pax.c | 1 |
6 files changed, 49 insertions, 10 deletions
diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile index 1428c82d5bb0..6aeff8fa473e 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 a3919e5bbfd4..742a2329d323 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 dec8b960d8b4..8d9fdef6a53d 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 0b96180352f8..7c03937132cb 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 882d2dfdd7d8..b79140d4b5b0 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 60288eb0bcf6..54e8581481af 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" |