diff --git a/lib/libarchive/archive_platform.h b/lib/libarchive/archive_platform.h index ee6c08e00914..0f651e87bda6 100644 --- a/lib/libarchive/archive_platform.h +++ b/lib/libarchive/archive_platform.h @@ -49,6 +49,7 @@ #define HAVE_CHFLAGS 1 #define HAVE_LUTIMES 1 #define HAVE_LCHMOD 1 +#define HAVE_POSIX_STRERROR_R 1 #define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE #define ARCHIVE_ERRNO_PROGRAMMER EINVAL #define ARCHIVE_ERRNO_MISC (-1) @@ -85,6 +86,7 @@ #define st_atimespec st_atim #define st_mtimespec st_mtim #define st_ctimespec st_ctim +#define HAVE_GLIBC_STRERROR_R 1 #endif /* diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c index 24c7f42e26f7..47bfc55898e9 100644 --- a/lib/libarchive/archive_read_support_format_tar.c +++ b/lib/libarchive/archive_read_support_format_tar.c @@ -81,9 +81,7 @@ struct tar { int header_recursion_depth; }; -static size_t UTF8_mbrtowc(wchar_t * __restrict pwc, - const char * __restrict s, size_t n, - mbstate_t * __restrict ps __unused); +static size_t UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n); static int archive_block_is_null(const unsigned char *p); static int header_Solaris_ACL(struct archive *, struct tar *, struct archive_entry *, struct stat *, const void *); @@ -640,9 +638,10 @@ static int header_pax_extensions(struct archive *a, struct tar *tar, struct archive_entry *entry, struct stat *st, const void *h) { - read_body_to_string(a, &(tar->pax_header), h); int err, err2; + read_body_to_string(a, &(tar->pax_header), h); + /* Parse the next header. */ err = tar_read_header(a, tar, entry, st); @@ -1085,7 +1084,7 @@ utf8_decode(wchar_t *dest, const char *src, size_t length) err = 0; while(length > 0) { - n = UTF8_mbrtowc(dest, src, length, NULL); + n = UTF8_mbrtowc(dest, src, length); if (n == 0) break; if (n > 8) { @@ -1106,8 +1105,7 @@ utf8_decode(wchar_t *dest, const char *src, size_t length) * Copied from FreeBSD libc/locale. */ static size_t -UTF8_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, - mbstate_t * __restrict ps __unused) +UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n) { int ch, i, len, mask; wchar_t lbound, wch; diff --git a/lib/libarchive/archive_util.c b/lib/libarchive/archive_util.c index 587e8af803b4..11d151abd887 100644 --- a/lib/libarchive/archive_util.c +++ b/lib/libarchive/archive_util.c @@ -84,6 +84,7 @@ archive_set_error(struct archive *a, int error_number, const char *fmt, ...) { va_list ap; char errbuff[512]; + char *errp; a->archive_error_number = error_number; if (fmt == NULL) { @@ -95,8 +96,16 @@ archive_set_error(struct archive *a, int error_number, const char *fmt, ...) archive_string_vsprintf(&(a->error_string), fmt, ap); if(error_number > 0) { archive_strcat(&(a->error_string), ": "); +#if defined(HAVE_GLIBC_STRERROR_R) + errp = strerror_r(error_number, errbuff, sizeof(errbuff)); +#elif defined(HAVE_POSIX_STRERROR_R) strerror_r(error_number, errbuff, sizeof(errbuff)); - archive_strcat(&(a->error_string), errbuff); + errp = errbuff; +#else + /* Note: this is not threadsafe! */ + errp = strerror(error_number); +#endif + archive_strcat(&(a->error_string), errp); } a->error = a->error_string.s; va_end(ap);