summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/archive_write_set_format_pax.c
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2006-11-10 06:39:46 +0000
committerkientzle <kientzle@FreeBSD.org>2006-11-10 06:39:46 +0000
commit50bb724108b7417b0df3bbf7029c43dbd734df49 (patch)
treef89881956f7ca553a6834444961e2cb90388cc29 /lib/libarchive/archive_write_set_format_pax.c
parent56ac4302e20c910a87bfc933138eb38f4c21af7a (diff)
downloadFreeBSD-src-50bb724108b7417b0df3bbf7029c43dbd734df49.zip
FreeBSD-src-50bb724108b7417b0df3bbf7029c43dbd734df49.tar.gz
Portability and style fixes:
* Actually use the HAVE_<header>_H macros to conditionally include system headers. They've been defined for a long time, but only used in a few places. Now they're used pretty consistently throughout. * Fill in a lot of missing casts for conversions from void*. Although Standard C doesn't require this, some people have been trying to use C++ compilers with this code, and they do require it. Bit-for-bit, the compiled object files are identical, except for one assert() whose line number changed, so I'm pretty confident I didn't break anything. ;-)
Diffstat (limited to 'lib/libarchive/archive_write_set_format_pax.c')
-rw-r--r--lib/libarchive/archive_write_set_format_pax.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/libarchive/archive_write_set_format_pax.c b/lib/libarchive/archive_write_set_format_pax.c
index c256cb2..81a43b7 100644
--- a/lib/libarchive/archive_write_set_format_pax.c
+++ b/lib/libarchive/archive_write_set_format_pax.c
@@ -27,7 +27,9 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
+#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
+#endif
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#else
@@ -35,10 +37,18 @@ __FBSDID("$FreeBSD$");
#include <sys/sysmacros.h>
#endif
#endif
+#ifdef HAVE_ERRNO_H
#include <errno.h>
+#endif
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
#include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include "archive.h"
#include "archive_entry.h"
@@ -103,7 +113,7 @@ archive_write_set_format_pax(struct archive *a)
if (a->format_finish != NULL)
(a->format_finish)(a);
- pax = malloc(sizeof(*pax));
+ pax = (struct pax *)malloc(sizeof(*pax));
if (pax == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate pax data");
return (ARCHIVE_FATAL);
@@ -218,7 +228,7 @@ utf8_encode(const wchar_t *wval)
/* Ignore larger values; UTF-8 can't encode them. */
}
- utf8_value = malloc(utf8len + 1);
+ utf8_value = (char *)malloc(utf8len + 1);
if (utf8_value == NULL) {
__archive_errx(1, "Not enough memory for attributes");
return (NULL);
@@ -346,7 +356,7 @@ archive_write_pax_header_xattrs(struct pax *pax, struct archive_entry *entry)
if (url_encoded_name != NULL) {
/* Convert narrow-character to wide-character. */
int wcs_length = strlen(url_encoded_name);
- wcs_name = malloc((wcs_length + 1) * sizeof(wchar_t));
+ wcs_name = (wchar_t *)malloc((wcs_length + 1) * sizeof(wchar_t));
if (wcs_name == NULL)
__archive_errx(1, "No memory for xattr conversion");
mbstowcs(wcs_name, url_encoded_name, wcs_length);
@@ -358,7 +368,7 @@ archive_write_pax_header_xattrs(struct pax *pax, struct archive_entry *entry)
free(wcs_name); /* Done with wchar_t name. */
}
- encoded_value = base64_encode(value, size);
+ encoded_value = base64_encode((const char *)value, size);
if (encoded_name != NULL && encoded_value != NULL) {
archive_string_init(&s);
@@ -397,7 +407,7 @@ archive_write_pax_header(struct archive *a,
char pax_entry_name[256];
need_extension = 0;
- pax = a->format_data;
+ pax = (struct pax *)a->format_data;
pax->written = 1;
st_original = archive_entry_stat(entry_original);
@@ -1035,7 +1045,7 @@ archive_write_pax_finish(struct archive *a)
int r;
r = ARCHIVE_OK;
- pax = a->format_data;
+ pax = (struct pax *)a->format_data;
if (pax->written && a->compression_write != NULL)
r = write_nulls(a, 512 * 2);
archive_string_free(&pax->pax_header);
@@ -1050,7 +1060,7 @@ archive_write_pax_finish_entry(struct archive *a)
struct pax *pax;
int ret;
- pax = a->format_data;
+ pax = (struct pax *)a->format_data;
ret = write_nulls(a, pax->entry_bytes_remaining + pax->entry_padding);
pax->entry_bytes_remaining = pax->entry_padding = 0;
return (ret);
@@ -1077,7 +1087,7 @@ archive_write_pax_data(struct archive *a, const void *buff, size_t s)
struct pax *pax;
int ret;
- pax = a->format_data;
+ pax = (struct pax *)a->format_data;
pax->written = 1;
if (s > pax->entry_bytes_remaining)
s = pax->entry_bytes_remaining;
@@ -1143,12 +1153,16 @@ static char *
base64_encode(const char *s, size_t len)
{
static const char digits[64] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
+ 'P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d',
+ 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s',
+ 't','u','v','w','x','y','z','0','1','2','3','4','5','6','7',
+ '8','9','+','/' };
int v;
char *d, *out;
/* 3 bytes becomes 4 chars, but round up and allow for trailing NUL */
- out = malloc((len * 4 + 2) / 3 + 1);
+ out = (char *)malloc((len * 4 + 2) / 3 + 1);
if (out == NULL)
return (NULL);
d = out;
OpenPOWER on IntegriCloud