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.  ;-)
This commit is contained in:
Tim Kientzle 2006-11-10 06:39:46 +00:00
parent c25789cc22
commit aa1eeda578
34 changed files with 514 additions and 214 deletions

View File

@ -27,11 +27,20 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <stdio.h>
#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_private.h"

View File

@ -27,8 +27,12 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#else
@ -39,11 +43,17 @@ __FBSDID("$FreeBSD$");
#ifdef HAVE_EXT2FS_EXT2_FS_H
#include <ext2fs/ext2_fs.h> /* for Linux file flags */
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <stddef.h>
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
/* Obtain suitable wide-character manipulation functions. */
#ifdef HAVE_WCHAR_H
@ -209,7 +219,7 @@ aes_copy(struct aes *dest, struct aes *src)
}
if (src->aes_wcs != NULL) {
dest->aes_wcs_alloc = malloc((wcslen(src->aes_wcs) + 1)
dest->aes_wcs_alloc = (wchar_t *)malloc((wcslen(src->aes_wcs) + 1)
* sizeof(wchar_t));
dest->aes_wcs = dest->aes_wcs_alloc;
if (dest->aes_wcs == NULL)
@ -231,7 +241,7 @@ aes_get_mbs(struct aes *aes)
* be a better way... XXX
*/
int mbs_length = wcslen(aes->aes_wcs) * 3 + 64;
aes->aes_mbs_alloc = malloc(mbs_length);
aes->aes_mbs_alloc = (char *)malloc(mbs_length);
aes->aes_mbs = aes->aes_mbs_alloc;
if (aes->aes_mbs == NULL)
__archive_errx(1, "No memory for aes_get_mbs()");
@ -253,7 +263,7 @@ aes_get_wcs(struct aes *aes)
*/
int wcs_length = strlen(aes->aes_mbs);
aes->aes_wcs_alloc
= malloc((wcs_length + 1) * sizeof(wchar_t));
= (wchar_t *)malloc((wcs_length + 1) * sizeof(wchar_t));
aes->aes_wcs = aes->aes_wcs_alloc;
if (aes->aes_wcs == NULL)
__archive_errx(1, "No memory for aes_get_wcs()");
@ -289,7 +299,7 @@ aes_copy_mbs(struct aes *aes, const char *mbs)
free(aes->aes_wcs_alloc);
aes->aes_wcs_alloc = NULL;
}
aes->aes_mbs_alloc = malloc((strlen(mbs) + 1) * sizeof(char));
aes->aes_mbs_alloc = (char *)malloc((strlen(mbs) + 1) * sizeof(char));
if (aes->aes_mbs_alloc == NULL)
__archive_errx(1, "No memory for aes_copy_mbs()");
strcpy(aes->aes_mbs_alloc, mbs);
@ -326,7 +336,7 @@ aes_copy_wcs(struct aes *aes, const wchar_t *wcs)
aes->aes_wcs_alloc = NULL;
}
aes->aes_mbs = NULL;
aes->aes_wcs_alloc = malloc((wcslen(wcs) + 1) * sizeof(wchar_t));
aes->aes_wcs_alloc = (wchar_t *)malloc((wcslen(wcs) + 1) * sizeof(wchar_t));
if (aes->aes_wcs_alloc == NULL)
__archive_errx(1, "No memory for aes_copy_wcs()");
wcscpy(aes->aes_wcs_alloc, wcs);
@ -354,7 +364,7 @@ archive_entry_clone(struct archive_entry *entry)
struct archive_entry *entry2;
/* Allocate new structure and copy over all of the fields. */
entry2 = malloc(sizeof(*entry2));
entry2 = (struct archive_entry *)malloc(sizeof(*entry2));
if (entry2 == NULL)
return (NULL);
memset(entry2, 0, sizeof(*entry2));
@ -386,7 +396,7 @@ archive_entry_new(void)
{
struct archive_entry *entry;
entry = malloc(sizeof(*entry));
entry = (struct archive_entry *)malloc(sizeof(*entry));
if (entry == NULL)
return (NULL);
memset(entry, 0, sizeof(*entry));
@ -901,7 +911,7 @@ acl_new_entry(struct archive_entry *entry,
}
/* Add a new entry to the list. */
ap = malloc(sizeof(*ap));
ap = (struct ae_acl *)malloc(sizeof(*ap));
if (ap == NULL)
return (NULL);
memset(ap, 0, sizeof(*ap));
@ -1083,7 +1093,7 @@ archive_entry_acl_text_w(struct archive_entry *entry, int flags)
return (NULL);
/* Now, allocate the string and actually populate it. */
wp = entry->acl_text_w = malloc(length * sizeof(wchar_t));
wp = entry->acl_text_w = (wchar_t *)malloc(length * sizeof(wchar_t));
if (wp == NULL)
__archive_errx(1, "No memory to generate the text version of the ACL");
count = 0;
@ -1338,7 +1348,7 @@ __archive_entry_acl_parse_w(struct archive_entry *entry,
free(namebuff);
namebuff_length = name_end - name_start + 256;
namebuff =
malloc(namebuff_length * sizeof(wchar_t));
(wchar_t *)malloc(namebuff_length * sizeof(wchar_t));
if (namebuff == NULL)
goto fail;
}
@ -1387,16 +1397,16 @@ archive_entry_xattr_add_entry(struct archive_entry *entry,
for (xp = entry->xattr_head; xp != NULL; xp = xp->next)
;
if ((xp = malloc(sizeof(struct ae_xattr))) == NULL)
if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL)
/* XXX Error XXX */
return;
xp->name = strdup(name);
if ((xp -> value = malloc(size)) != NULL) {
memcpy(xp -> value, value, size);
xp -> size = size;
if ((xp->value = malloc(size)) != NULL) {
memcpy(xp->value, value, size);
xp->size = size;
} else
xp -> size = 0;
xp->size = 0;
xp->next = entry->xattr_head;
entry->xattr_head = xp;
@ -1632,7 +1642,7 @@ ae_fflagstostr(unsigned long bitset, unsigned long bitclear)
if (length == 0)
return (NULL);
string = malloc(length);
string = (char *)malloc(length);
if (string == NULL)
return (NULL);

View File

@ -41,8 +41,14 @@
#include "../config.h"
#else
/* A default configuration for FreeBSD, used if there is no config.h. */
/*
* If there's no 'config.h' file, check if we have a hand-coded config
* for this platform. This handles systems where the library is built
* without running the configure script, such as FreeBSD (where
* libarchive is part of the base system).
*/
#ifdef __FreeBSD__
/* Begin of hand-coded __FreeBSD__ configuration. */
#if __FreeBSD__ > 4
#define HAVE_ACL_CREATE_ENTRY 1
#define HAVE_ACL_INIT 1
@ -62,7 +68,9 @@
#define HAVE_FCHMOD 1
#define HAVE_FCHOWN 1
#define HAVE_FCNTL_H 1
#define HAVE_FSEEKO 1
#define HAVE_FUTIMES 1
#define HAVE_GRP_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_LCHFLAGS 1
#define HAVE_LCHMOD 1
@ -71,11 +79,10 @@
#define HAVE_LUTIMES 1
#define HAVE_MALLOC 1
#define HAVE_MEMMOVE 1
#define HAVE_MEMORY_H 1
#define HAVE_MEMSET 1
#define HAVE_MKDIR 1
#define HAVE_MKFIFO 1
#define HAVE_PATHS_H 1
#define HAVE_PWD_H 1
#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRCHR 1
@ -99,6 +106,7 @@
#define HAVE_ZLIB_H 1
#define STDC_HEADERS 1
#define TIME_WITH_SYS_TIME 1
/* End of __FreeBSD__ definitions. */
#else /* !__FreeBSD__ */
/* Warn if the library hasn't been (automatically or manually) configured. */
#error Oops: No config.h and no built-in configuration in archive_platform.h.
@ -115,6 +123,8 @@
#if HAVE_INTTYPES_H
#include <inttypes.h>
#elif HAVE_STDINT_H
#include <stdint.h>
#endif
/* FreeBSD 4 and earlier lack intmax_t/uintmax_t */
@ -184,9 +194,9 @@
#define ARCHIVE_STAT_ATIME_NANOS(pstat) 0
#define ARCHIVE_STAT_CTIME_NANOS(pstat) 0
#define ARCHIVE_STAT_MTIME_NANOS(pstat) 0
#define ARCHIVE_STAT_SET_ATIME_NANOS(st, n)
#define ARCHIVE_STAT_SET_CTIME_NANOS(st, n)
#define ARCHIVE_STAT_SET_MTIME_NANOS(st, n)
#define ARCHIVE_STAT_SET_ATIME_NANOS(st, n) ((void)(n))
#define ARCHIVE_STAT_SET_CTIME_NANOS(st, n) ((void)(n))
#define ARCHIVE_STAT_SET_MTIME_NANOS(st, n) ((void)(n))
#endif
#endif

View File

@ -35,11 +35,19 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stdio.h>
#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"
@ -57,7 +65,7 @@ archive_read_new(void)
struct archive *a;
unsigned char *nulls;
a = malloc(sizeof(*a));
a = (struct archive *)malloc(sizeof(*a));
if (a == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate archive object");
return (NULL);
@ -69,7 +77,7 @@ archive_read_new(void)
a->bytes_per_block = ARCHIVE_DEFAULT_BYTES_PER_BLOCK;
a->null_length = 1024;
nulls = malloc(a->null_length);
nulls = (unsigned char *)malloc(a->null_length);
if (nulls == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate archive object 'nulls' element");
free(a);
@ -399,7 +407,7 @@ archive_read_data(struct archive *a, void *buff, size_t s)
int r;
bytes_read = 0;
dest = buff;
dest = (char *)buff;
while (s > 0) {
if (a->read_data_remaining <= 0) {

View File

@ -27,7 +27,9 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "archive.h"
@ -37,7 +39,7 @@ archive_read_data_into_buffer(struct archive *a, void *d, ssize_t len)
char *dest;
ssize_t bytes_read, total_bytes;
dest = d;
dest = (char *)d;
total_bytes = 0;
bytes_read = archive_read_data(a, dest, len);
while (bytes_read > 0) {

View File

@ -27,9 +27,15 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "archive.h"
#include "archive_private.h"

View File

@ -27,7 +27,9 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_ACL_H
#include <sys/acl.h>
#endif
@ -37,24 +39,44 @@ __FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_EXT2FS_EXT2_FS_H
#include <ext2fs/ext2_fs.h> /* for Linux file flags */
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
#ifdef HAVE_LINUX_EXT2_FS_H
#include <linux/ext2_fs.h> /* for Linux file flags */
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#include <stdio.h>
#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_string.h"
@ -296,7 +318,7 @@ create_extract(struct archive *a)
{
struct extract *extract;
extract = malloc(sizeof(*extract));
extract = (struct extract *)malloc(sizeof(*extract));
if (extract == NULL) {
archive_set_error(a, ENOMEM, "Can't extract");
return (ARCHIVE_FATAL);
@ -460,7 +482,7 @@ new_fixup(struct archive *a, const char *pathname)
struct fixup_entry *fe;
extract = a->extract;
fe = malloc(sizeof(struct fixup_entry));
fe = (struct fixup_entry *)malloc(sizeof(struct fixup_entry));
if (fe == NULL)
return (NULL);
fe->next = extract->fixup_list;
@ -1381,7 +1403,7 @@ set_acls(struct archive *a, int fd, struct archive_entry *entry)
static int
set_acl(struct archive *a, int fd, struct archive_entry *entry,
acl_type_t acl_type, int ae_requested_type, const char *typename)
acl_type_t acl_type, int ae_requested_type, const char *tname)
{
acl_t acl;
acl_entry_t acl_entry;
@ -1456,7 +1478,7 @@ set_acl(struct archive *a, int fd, struct archive_entry *entry,
#endif
#endif
if (acl_set_file(name, acl_type, acl) != 0) {
archive_set_error(a, errno, "Failed to set %s acl", typename);
archive_set_error(a, errno, "Failed to set %s acl", tname);
ret = ARCHIVE_WARN;
}
acl_free(acl);

View File

@ -27,11 +27,21 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#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_private.h"
@ -52,7 +62,7 @@ archive_read_open_fd(struct archive *a, int fd, size_t block_size)
{
struct read_fd_data *mine;
mine = malloc(sizeof(*mine));
mine = (struct read_fd_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
@ -71,7 +81,7 @@ archive_read_open_fd(struct archive *a, int fd, size_t block_size)
static int
file_open(struct archive *a, void *client_data)
{
struct read_fd_data *mine = client_data;
struct read_fd_data *mine = (struct read_fd_data *)client_data;
struct stat st;
if (fstat(mine->fd, &st) != 0) {
@ -87,7 +97,7 @@ file_open(struct archive *a, void *client_data)
static ssize_t
file_read(struct archive *a, void *client_data, const void **buff)
{
struct read_fd_data *mine = client_data;
struct read_fd_data *mine = (struct read_fd_data *)client_data;
ssize_t bytes_read;
*buff = mine->buffer;
@ -101,9 +111,9 @@ file_read(struct archive *a, void *client_data, const void **buff)
static ssize_t
file_skip(struct archive *a, void *client_data, size_t request)
{
struct read_fd_data *mine = client_data;
struct read_fd_data *mine = (struct read_fd_data *)client_data;
off_t old_offset, new_offset;
/* Reduce request to the next smallest multiple of block_size */
request = (request / mine->block_size) * mine->block_size;
/*
@ -138,7 +148,7 @@ file_skip(struct archive *a, void *client_data, size_t request)
static int
file_close(struct archive *a, void *client_data)
{
struct read_fd_data *mine = client_data;
struct read_fd_data *mine = (struct read_fd_data *)client_data;
(void)a; /* UNUSED */
if (mine->buffer != NULL)

View File

@ -27,12 +27,24 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.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_private.h"
@ -57,14 +69,14 @@ archive_read_open_file(struct archive *a, const char *filename,
struct read_file_data *mine;
if (filename == NULL || filename[0] == '\0') {
mine = malloc(sizeof(*mine));
mine = (struct read_file_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
mine->filename[0] = '\0';
} else {
mine = malloc(sizeof(*mine) + strlen(filename));
mine = (struct read_file_data *)malloc(sizeof(*mine) + strlen(filename));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
@ -80,7 +92,7 @@ archive_read_open_file(struct archive *a, const char *filename,
static int
file_open(struct archive *a, void *client_data)
{
struct read_file_data *mine = client_data;
struct read_file_data *mine = (struct read_file_data *)client_data;
struct stat st;
mine->buffer = malloc(mine->block_size);
@ -117,7 +129,7 @@ file_open(struct archive *a, void *client_data)
static ssize_t
file_read(struct archive *a, void *client_data, const void **buff)
{
struct read_file_data *mine = client_data;
struct read_file_data *mine = (struct read_file_data *)client_data;
ssize_t bytes_read;
*buff = mine->buffer;
@ -135,7 +147,7 @@ file_read(struct archive *a, void *client_data, const void **buff)
static ssize_t
file_skip(struct archive *a, void *client_data, size_t request)
{
struct read_file_data *mine = client_data;
struct read_file_data *mine = (struct read_file_data *)client_data;
off_t old_offset, new_offset;
/* Reduce request to the next smallest multiple of block_size */
@ -180,7 +192,7 @@ file_skip(struct archive *a, void *client_data, size_t request)
static int
file_close(struct archive *a, void *client_data)
{
struct read_file_data *mine = client_data;
struct read_file_data *mine = (struct read_file_data *)client_data;
(void)a; /* UNUSED */

View File

@ -27,12 +27,24 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.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_private.h"
@ -57,14 +69,14 @@ archive_read_open_file(struct archive *a, const char *filename,
struct read_file_data *mine;
if (filename == NULL || filename[0] == '\0') {
mine = malloc(sizeof(*mine));
mine = (struct read_file_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
mine->filename[0] = '\0';
} else {
mine = malloc(sizeof(*mine) + strlen(filename));
mine = (struct read_file_data *)malloc(sizeof(*mine) + strlen(filename));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
@ -80,7 +92,7 @@ archive_read_open_file(struct archive *a, const char *filename,
static int
file_open(struct archive *a, void *client_data)
{
struct read_file_data *mine = client_data;
struct read_file_data *mine = (struct read_file_data *)client_data;
struct stat st;
mine->buffer = malloc(mine->block_size);
@ -117,7 +129,7 @@ file_open(struct archive *a, void *client_data)
static ssize_t
file_read(struct archive *a, void *client_data, const void **buff)
{
struct read_file_data *mine = client_data;
struct read_file_data *mine = (struct read_file_data *)client_data;
ssize_t bytes_read;
*buff = mine->buffer;
@ -135,7 +147,7 @@ file_read(struct archive *a, void *client_data, const void **buff)
static ssize_t
file_skip(struct archive *a, void *client_data, size_t request)
{
struct read_file_data *mine = client_data;
struct read_file_data *mine = (struct read_file_data *)client_data;
off_t old_offset, new_offset;
/* Reduce request to the next smallest multiple of block_size */
@ -180,7 +192,7 @@ file_skip(struct archive *a, void *client_data, size_t request)
static int
file_close(struct archive *a, void *client_data)
{
struct read_file_data *mine = client_data;
struct read_file_data *mine = (struct read_file_data *)client_data;
(void)a; /* UNUSED */

View File

@ -28,11 +28,19 @@
__FBSDID("$FreeBSD$");
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_BZLIB_H
#include <bzlib.h>
#endif
@ -81,7 +89,7 @@ bid(const void *buff, size_t len)
if (len < 1)
return (0);
buffer = buff;
buffer = (const unsigned char *)buff;
bits_checked = 0;
if (buffer[0] != 'B') /* Verify first ID byte. */
return (0);
@ -153,7 +161,7 @@ init(struct archive *a, const void *buff, size_t n)
a->compression_code = ARCHIVE_COMPRESSION_BZIP2;
a->compression_name = "bzip2";
state = malloc(sizeof(*state));
state = (struct private_data *)malloc(sizeof(*state));
if (state == NULL) {
archive_set_error(a, ENOMEM,
"Can't allocate data for %s decompression",
@ -163,7 +171,7 @@ init(struct archive *a, const void *buff, size_t n)
memset(state, 0, sizeof(*state));
state->uncompressed_buffer_size = 64 * 1024;
state->uncompressed_buffer = malloc(state->uncompressed_buffer_size);
state->uncompressed_buffer = (char *)malloc(state->uncompressed_buffer_size);
state->stream.next_out = state->uncompressed_buffer;
state->read_next = state->uncompressed_buffer;
state->stream.avail_out = state->uncompressed_buffer_size;
@ -182,7 +190,7 @@ init(struct archive *a, const void *buff, size_t n)
* next_in pointer, only reads it). The result: this ugly
* cast to remove 'const'.
*/
state->stream.next_in = (void *)(uintptr_t)(const void *)buff;
state->stream.next_in = (char *)(uintptr_t)(const void *)buff;
state->stream.avail_in = n;
a->compression_read_ahead = read_ahead;
@ -245,7 +253,7 @@ read_ahead(struct archive *a, const void **p, size_t min)
struct private_data *state;
int read_avail, was_avail, ret;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
was_avail = -1;
if (!a->client_reader) {
archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER,
@ -286,7 +294,7 @@ read_consume(struct archive *a, size_t n)
{
struct private_data *state;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
a->file_position += n;
state->read_next += n;
if (state->read_next > state->stream.next_out)
@ -304,7 +312,7 @@ finish(struct archive *a)
struct private_data *state;
int ret;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
ret = ARCHIVE_OK;
switch (BZ2_bzDecompressEnd(&(state->stream))) {
case BZ_OK:

View File

@ -67,10 +67,18 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#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_private.h"
@ -155,7 +163,7 @@ bid(const void *buff, size_t len)
if (len < 1)
return (0);
buffer = buff;
buffer = (const unsigned char *)buff;
bits_checked = 0;
if (buffer[0] != 037) /* Verify first ID byte. */
return (0);
@ -193,7 +201,7 @@ init(struct archive *a, const void *buff, size_t n)
a->compression_skip = NULL; /* not supported */
a->compression_finish = finish;
state = malloc(sizeof(*state));
state = (struct private_data *)malloc(sizeof(*state));
if (state == NULL) {
archive_set_error(a, ENOMEM,
"Can't allocate data for %s decompression",
@ -213,9 +221,9 @@ init(struct archive *a, const void *buff, size_t n)
goto fatal;
}
state->next_in = buff;
state->next_in = (const unsigned char *)buff;
state->avail_in = n;
state->read_next = state->next_out = state->uncompressed_buffer;
state->read_next = state->next_out = (unsigned char *)state->uncompressed_buffer;
state->avail_out = state->uncompressed_buffer_size;
code = getbits(a, state, 8);
@ -268,7 +276,7 @@ read_ahead(struct archive *a, const void **p, size_t min)
struct private_data *state;
int read_avail, was_avail, ret;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
was_avail = -1;
if (!a->client_reader) {
archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER,
@ -289,7 +297,7 @@ read_ahead(struct archive *a, const void **p, size_t min)
if (read_avail < (int)min) {
memmove(state->uncompressed_buffer, state->read_next,
read_avail);
state->read_next = state->uncompressed_buffer;
state->read_next = (unsigned char *)state->uncompressed_buffer;
state->next_out = state->read_next + read_avail;
state->avail_out
= state->uncompressed_buffer_size - read_avail;
@ -322,7 +330,7 @@ read_consume(struct archive *a, size_t n)
{
struct private_data *state;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
a->file_position += n;
state->read_next += n;
if (state->read_next > state->next_out)
@ -340,7 +348,7 @@ finish(struct archive *a)
struct private_data *state;
int ret = ARCHIVE_OK;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
if (state != NULL) {
if (state->uncompressed_buffer != NULL)

View File

@ -29,10 +29,18 @@
__FBSDID("$FreeBSD$");
#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
#ifdef HAVE_ZLIB_H
#include <zlib.h>
#endif
@ -83,7 +91,7 @@ bid(const void *buff, size_t len)
if (len < 1)
return (0);
buffer = buff;
buffer = (const unsigned char *)buff;
bits_checked = 0;
if (buffer[0] != 037) /* Verify first ID byte. */
return (0);
@ -154,7 +162,7 @@ init(struct archive *a, const void *buff, size_t n)
a->compression_code = ARCHIVE_COMPRESSION_GZIP;
a->compression_name = "gzip";
state = malloc(sizeof(*state));
state = (struct private_data *)malloc(sizeof(*state));
if (state == NULL) {
archive_set_error(a, ENOMEM,
"Can't allocate data for %s decompression",
@ -167,7 +175,7 @@ init(struct archive *a, const void *buff, size_t n)
state->header_done = 0; /* We've not yet begun to parse header... */
state->uncompressed_buffer_size = 64 * 1024;
state->uncompressed_buffer = malloc(state->uncompressed_buffer_size);
state->uncompressed_buffer = (unsigned char *)malloc(state->uncompressed_buffer_size);
state->stream.next_out = state->uncompressed_buffer;
state->read_next = state->uncompressed_buffer;
state->stream.avail_out = state->uncompressed_buffer_size;
@ -186,7 +194,7 @@ init(struct archive *a, const void *buff, size_t n)
* next_in pointer, only reads it). The result: this ugly
* cast to remove 'const'.
*/
state->stream.next_in = (void *)(uintptr_t)(const void *)buff;
state->stream.next_in = (Bytef *)(uintptr_t)(const void *)buff;
state->stream.avail_in = n;
a->compression_read_ahead = read_ahead;
@ -250,7 +258,7 @@ read_ahead(struct archive *a, const void **p, size_t min)
struct private_data *state;
int read_avail, was_avail, ret;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
was_avail = -1;
if (!a->client_reader) {
archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER,
@ -291,7 +299,7 @@ read_consume(struct archive *a, size_t n)
{
struct private_data *state;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
a->file_position += n;
state->read_next += n;
if (state->read_next > state->stream.next_out)
@ -309,7 +317,7 @@ finish(struct archive *a)
struct private_data *state;
int ret;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
ret = ARCHIVE_OK;
switch (inflateEnd(&(state->stream))) {
case Z_OK:

View File

@ -28,10 +28,18 @@
__FBSDID("$FreeBSD$");
#include <assert.h>
#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_private.h"
@ -110,7 +118,7 @@ archive_decompressor_none_init(struct archive *a, const void *buff, size_t n)
memset(state, 0, sizeof(*state));
state->buffer_size = BUFFER_SIZE;
state->buffer = malloc(state->buffer_size);
state->buffer = (char *)malloc(state->buffer_size);
state->next = state->buffer;
if (state->buffer == NULL) {
free(state);
@ -119,7 +127,7 @@ archive_decompressor_none_init(struct archive *a, const void *buff, size_t n)
}
/* Save reference to first block of data. */
state->client_buff = buff;
state->client_buff = (const char *)buff;
state->client_total = n;
state->client_next = state->client_buff;
state->client_avail = state->client_total;
@ -145,7 +153,7 @@ archive_decompressor_none_read_ahead(struct archive *a, const void **buff,
struct archive_decompress_none *state;
ssize_t bytes_read;
state = a->compression_data;
state = (struct archive_decompress_none *)a->compression_data;
if (state->fatal)
return (-1);
@ -242,7 +250,7 @@ archive_decompressor_none_read_consume(struct archive *a, size_t request)
{
struct archive_decompress_none *state;
state = a->compression_data;
state = (struct archive_decompress_none *)a->compression_data;
if (state->avail > 0) {
/* Read came from copy buffer. */
state->next += request;
@ -268,7 +276,7 @@ archive_decompressor_none_skip(struct archive *a, size_t request)
ssize_t bytes_skipped, total_bytes_skipped = 0;
size_t min;
state = a->compression_data;
state = (struct archive_decompress_none *)a->compression_data;
if (state->fatal)
return (-1);
/*
@ -341,7 +349,7 @@ archive_decompressor_none_finish(struct archive *a)
{
struct archive_decompress_none *state;
state = a->compression_data;
state = (struct archive_decompress_none *)a->compression_data;
free(state->buffer);
free(state);
a->compression_data = NULL;

View File

@ -27,16 +27,26 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
/* #include <stdint.h> */ /* See archive_platform.h */
#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"
@ -136,7 +146,7 @@ archive_read_support_format_cpio(struct archive *a)
struct cpio *cpio;
int r;
cpio = malloc(sizeof(*cpio));
cpio = (struct cpio *)malloc(sizeof(*cpio));
if (cpio == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate cpio data");
return (ARCHIVE_FATAL);
@ -166,7 +176,7 @@ archive_read_format_cpio_bid(struct archive *a)
const unsigned char *p;
struct cpio *cpio;
cpio = *(a->pformat_data);
cpio = (struct cpio *)*(a->pformat_data);
bid = 0;
bytes_read = (a->compression_read_ahead)(a, &h, 6);
/* Convert error code into error return. */
@ -175,7 +185,7 @@ archive_read_format_cpio_bid(struct archive *a)
if (bytes_read < 6)
return (-1);
p = h;
p = (const unsigned char *)h;
if (memcmp(p, "070707", 6) == 0) {
/* ASCII cpio archive (odc, POSIX.1) */
cpio->read_header = header_odc;
@ -231,7 +241,7 @@ archive_read_format_cpio_read_header(struct archive *a,
memset(&st, 0, sizeof(st));
cpio = *(a->pformat_data);
cpio = (struct cpio *)*(a->pformat_data);
r = (cpio->read_header(a, cpio, &st, &namelength, &name_pad));
if (r != ARCHIVE_OK)
@ -245,7 +255,7 @@ archive_read_format_cpio_read_header(struct archive *a,
if (bytes < namelength + name_pad)
return (ARCHIVE_FATAL);
(a->compression_read_consume)(a, namelength + name_pad);
archive_strncpy(&cpio->entry_name, h, namelength);
archive_strncpy(&cpio->entry_name, (const char *)h, namelength);
archive_entry_set_pathname(entry, cpio->entry_name.s);
cpio->entry_offset = 0;
@ -256,14 +266,14 @@ archive_read_format_cpio_read_header(struct archive *a,
if ((off_t)bytes < cpio->entry_bytes_remaining)
return (ARCHIVE_FATAL);
(a->compression_read_consume)(a, cpio->entry_bytes_remaining);
archive_strncpy(&cpio->entry_linkname, h,
archive_strncpy(&cpio->entry_linkname, (const char *)h,
cpio->entry_bytes_remaining);
archive_entry_set_symlink(entry, cpio->entry_linkname.s);
cpio->entry_bytes_remaining = 0;
}
/* Compare name to "TRAILER!!!" to test for end-of-archive. */
if (namelength == 11 && strcmp(h, "TRAILER!!!") == 0) {
if (namelength == 11 && strcmp((const char *)h, "TRAILER!!!") == 0) {
/* TODO: Store file location of start of block. */
archive_set_error(a, 0, NULL);
return (ARCHIVE_EOF);
@ -282,7 +292,7 @@ archive_read_format_cpio_read_data(struct archive *a,
ssize_t bytes_read;
struct cpio *cpio;
cpio = *(a->pformat_data);
cpio = (struct cpio *)*(a->pformat_data);
if (cpio->entry_bytes_remaining > 0) {
bytes_read = (a->compression_read_ahead)(a, buff, 1);
if (bytes_read <= 0)
@ -327,7 +337,7 @@ header_newc(struct archive *a, struct cpio *cpio, struct stat *st,
(a->compression_read_consume)(a, sizeof(struct cpio_newc_header));
/* Parse out hex fields into struct stat. */
header = h;
header = (const struct cpio_newc_header *)h;
if (memcmp(header->c_magic, "070701", 6) == 0) {
a->archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC;
@ -387,7 +397,7 @@ header_odc(struct archive *a, struct cpio *cpio, struct stat *st,
(a->compression_read_consume)(a, sizeof(struct cpio_odc_header));
/* Parse out octal fields into struct stat. */
header = h;
header = (const struct cpio_odc_header *)h;
st->st_dev = atol8(header->c_dev, sizeof(header->c_dev));
st->st_ino = atol8(header->c_ino, sizeof(header->c_ino));
@ -431,7 +441,7 @@ header_bin_le(struct archive *a, struct cpio *cpio, struct stat *st,
(a->compression_read_consume)(a, sizeof(struct cpio_bin_header));
/* Parse out binary fields into struct stat. */
header = h;
header = (const struct cpio_bin_header *)h;
st->st_dev = header->c_dev[0] + header->c_dev[1] * 256;
st->st_ino = header->c_ino[0] + header->c_ino[1] * 256;
@ -469,7 +479,7 @@ header_bin_be(struct archive *a, struct cpio *cpio, struct stat *st,
(a->compression_read_consume)(a, sizeof(struct cpio_bin_header));
/* Parse out binary fields into struct stat. */
header = h;
header = (const struct cpio_bin_header *)h;
st->st_dev = header->c_dev[0] * 256 + header->c_dev[1];
st->st_ino = header->c_ino[0] * 256 + header->c_ino[1];
st->st_mode = header->c_mode[0] * 256 + header->c_mode[1];
@ -492,7 +502,7 @@ archive_read_format_cpio_cleanup(struct archive *a)
{
struct cpio *cpio;
cpio = *(a->pformat_data);
cpio = (struct cpio *)*(a->pformat_data);
/* Free inode->name map */
while (cpio->links_head != NULL) {
struct links_entry *lp = cpio->links_head->next;
@ -596,7 +606,7 @@ record_hardlink(struct cpio *cpio, struct archive_entry *entry,
}
}
le = malloc(sizeof(struct links_entry));
le = (struct links_entry *)malloc(sizeof(struct links_entry));
if (le == NULL)
__archive_errx(1, "Out of memory adding file to list");
if (cpio->links_head != NULL)

View File

@ -27,15 +27,25 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
/* #include <stdint.h> */ /* See archive_platform.h */
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <time.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "archive.h"
#include "archive_entry.h"
@ -202,7 +212,7 @@ archive_read_support_format_iso9660(struct archive *a)
struct iso9660 *iso9660;
int r;
iso9660 = malloc(sizeof(*iso9660));
iso9660 = (struct iso9660 *)malloc(sizeof(*iso9660));
if (iso9660 == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate iso9660 data");
return (ARCHIVE_FATAL);
@ -235,7 +245,7 @@ archive_read_format_iso9660_bid(struct archive *a)
const void *h;
const char *p;
iso9660 = *(a->pformat_data);
iso9660 = (struct iso9660 *)*(a->pformat_data);
if (iso9660->bid >= 0)
return (iso9660->bid);
@ -300,7 +310,7 @@ archive_read_format_iso9660_read_header(struct archive *a,
ssize_t bytes_read;
int r;
iso9660 = *(a->pformat_data);
iso9660 = (struct iso9660 *)*(a->pformat_data);
if (!a->archive_format) {
a->archive_format = ARCHIVE_FORMAT_ISO9660;
@ -382,7 +392,7 @@ archive_read_format_iso9660_read_header(struct archive *a,
(a->compression_read_consume)(a, bytes_read);
iso9660->current_position += bytes_read;
iso9660->entry_bytes_remaining -= bytes_read;
for (p = block;
for (p = (const unsigned char *)block;
*p != 0 && p < (const unsigned char *)block + bytes_read;
p += *p) {
const struct iso9660_directory_record *dr
@ -420,7 +430,7 @@ archive_read_format_iso9660_read_data(struct archive *a,
ssize_t bytes_read;
struct iso9660 *iso9660;
iso9660 = *(a->pformat_data);
iso9660 = (struct iso9660 *)*(a->pformat_data);
if (iso9660->entry_bytes_remaining <= 0) {
*buff = NULL;
*size = 0;
@ -451,7 +461,7 @@ archive_read_format_iso9660_cleanup(struct archive *a)
struct iso9660 *iso9660;
struct file_info *file;
iso9660 = *(a->pformat_data);
iso9660 = (struct iso9660 *)*(a->pformat_data);
while ((file = next_entry(iso9660)) != NULL)
release_file(iso9660, file);
archive_string_free(&iso9660->pathname);
@ -474,7 +484,7 @@ parse_file_info(struct iso9660 *iso9660, struct file_info *parent,
/* TODO: Sanity check that name_len doesn't exceed length, etc. */
/* Create a new file entry and copy data from the ISO dir record. */
file = malloc(sizeof(*file));
file = (struct file_info *)malloc(sizeof(*file));
if (file == NULL)
return (NULL);
memset(file, 0, sizeof(*file));
@ -486,7 +496,7 @@ parse_file_info(struct iso9660 *iso9660, struct file_info *parent,
file->size = toi(isodirrec->size, 4);
file->mtime = isodate7(isodirrec->date);
file->ctime = file->atime = file->mtime;
file->name = malloc(isodirrec->name_len[0] + 1);
file->name = (char *)malloc(isodirrec->name_len[0] + 1);
if (file->name == NULL) {
free(file);
return (NULL);
@ -547,7 +557,7 @@ add_entry(struct iso9660 *iso9660, struct file_info *file)
if (new_size < 1024)
new_size = 1024;
new_pending_files = malloc(new_size * sizeof(new_pending_files[0]));
new_pending_files = (struct file_info **)malloc(new_size * sizeof(new_pending_files[0]));
if (new_pending_files == NULL)
__archive_errx(1, "Out of memory");
memcpy(new_pending_files, iso9660->pending_files,
@ -610,7 +620,7 @@ parse_rockridge(struct iso9660 *iso9660, struct file_info *file,
data++; /* Skip flag byte. */
data_length--;
file->name = malloc(data_length + 1);
file->name = (char *)malloc(data_length + 1);
if (file->name != NULL) {
free(old_name);
memcpy(file->name, data, data_length);

View File

@ -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,12 +37,20 @@ __FBSDID("$FreeBSD$");
#include <sys/sysmacros.h>
#endif
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stddef.h>
/* #include <stdint.h> */ /* See archive_platform.h */
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
/* Obtain suitable wide-character manipulation functions. */
#ifdef HAVE_WCHAR_H
@ -250,7 +260,7 @@ archive_read_support_format_tar(struct archive *a)
struct tar *tar;
int r;
tar = malloc(sizeof(*tar));
tar = (struct tar *)malloc(sizeof(*tar));
if (tar == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate tar data");
return (ARCHIVE_FATAL);
@ -274,7 +284,7 @@ archive_read_format_tar_cleanup(struct archive *a)
{
struct tar *tar;
tar = *(a->pformat_data);
tar = (struct tar *)*(a->pformat_data);
archive_string_free(&tar->acl_text);
archive_string_free(&tar->entry_name);
archive_string_free(&tar->entry_linkname);
@ -342,7 +352,7 @@ archive_read_format_tar_bid(struct archive *a)
}
/* If it's an end-of-archive mark, we can handle it. */
if ((*(const char *)h) == 0 && archive_block_is_null(h)) {
if ((*(const char *)h) == 0 && archive_block_is_null((const unsigned char *)h)) {
/* If it's a known tar file, end-of-archive is definite. */
if ((a->archive_format & ARCHIVE_FORMAT_BASE_MASK) ==
ARCHIVE_FORMAT_TAR)
@ -356,7 +366,7 @@ archive_read_format_tar_bid(struct archive *a)
return (0);
bid += 48; /* Checksum is usually 6 octal digits. */
header = h;
header = (const struct archive_entry_header_ustar *)h;
/* Recognize POSIX formats. */
if ((memcmp(header->magic, "ustar\0", 6) == 0)
@ -438,7 +448,7 @@ archive_read_format_tar_read_header(struct archive *a,
default_inode = 0;
}
tar = *(a->pformat_data);
tar = (struct tar *)*(a->pformat_data);
tar->entry_offset = 0;
r = tar_read_header(a, tar, entry, &st);
@ -470,7 +480,7 @@ archive_read_format_tar_read_data(struct archive *a,
struct tar *tar;
struct sparse_block *p;
tar = *(a->pformat_data);
tar = (struct tar *)*(a->pformat_data);
if (tar->sparse_list != NULL) {
/* Remove exhausted entries from sparse list. */
while (tar->sparse_list != NULL &&
@ -535,7 +545,7 @@ archive_read_format_tar_skip(struct archive *a)
off_t o;
tar = *(a->pformat_data);
tar = (struct tar *)*(a->pformat_data);
if (a->compression_skip == NULL) {
while (r == ARCHIVE_OK)
r = archive_read_format_tar_read_data(a, &b, &s, &o);
@ -593,7 +603,7 @@ tar_read_header(struct archive *a, struct tar *tar,
(a->compression_read_consume)(a, 512);
/* Check for end-of-archive mark. */
if (((*(const char *)h)==0) && archive_block_is_null(h)) {
if (((*(const char *)h)==0) && archive_block_is_null((const unsigned char *)h)) {
/* Try to consume a second all-null record, as well. */
bytes = (a->compression_read_ahead)(a, &h, 512);
if (bytes > 0)
@ -620,7 +630,7 @@ tar_read_header(struct archive *a, struct tar *tar,
}
/* Determine the format variant. */
header = h;
header = (const struct archive_entry_header_ustar *)h;
switch(header->typeflag[0]) {
case 'A': /* Solaris tar ACL */
a->archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE;
@ -684,8 +694,8 @@ checksum(struct archive *a, const void *h)
int check, i, sum;
(void)a; /* UNUSED */
bytes = h;
header = h;
bytes = (const unsigned char *)h;
header = (const struct archive_entry_header_ustar *)h;
/*
* Test the checksum. Note that POSIX specifies _unsigned_
@ -758,7 +768,7 @@ header_Solaris_ACL(struct archive *a, struct tar *tar,
p++;
p++;
wp = malloc((strlen(p) + 1) * sizeof(wchar_t));
wp = (wchar_t *)malloc((strlen(p) + 1) * sizeof(wchar_t));
if (wp != NULL) {
utf8_decode(wp, p, strlen(p));
err2 = __archive_entry_acl_parse_w(entry, wp,
@ -833,7 +843,7 @@ read_body_to_string(struct archive *a, struct tar *tar,
char *dest;
(void)tar; /* UNUSED */
header = h;
header = (const struct archive_entry_header_ustar *)h;
size = tar_atol(header->size, sizeof(header->size));
/* Read the body into the string. */
@ -878,7 +888,7 @@ header_common(struct archive *a, struct tar *tar, struct archive_entry *entry,
(void)a; /* UNUSED */
header = h;
header = (const struct archive_entry_header_ustar *)h;
if (header->linkname[0])
archive_strncpy(&(tar->entry_linkname), header->linkname,
sizeof(header->linkname));
@ -1008,7 +1018,7 @@ header_old_tar(struct archive *a, struct tar *tar, struct archive_entry *entry,
const struct archive_entry_header_ustar *header;
/* Copy filename over (to ensure null termination). */
header = h;
header = (const struct archive_entry_header_ustar *)h;
archive_strncpy(&(tar->entry_name), header->name, sizeof(header->name));
archive_entry_set_pathname(entry, tar->entry_name.s);
@ -1074,7 +1084,7 @@ header_ustar(struct archive *a, struct tar *tar, struct archive_entry *entry,
const struct archive_entry_header_ustar *header;
struct archive_string *as;
header = h;
header = (const struct archive_entry_header_ustar *)h;
/* Copy name into an internal buffer to ensure null-termination. */
as = &(tar->entry_name);
@ -1167,7 +1177,7 @@ pax_header(struct archive *a, struct tar *tar, struct archive_entry *entry,
tar->pax_entry_length *= 2;
old_entry = tar->pax_entry;
tar->pax_entry = realloc(tar->pax_entry,
tar->pax_entry = (wchar_t *)realloc(tar->pax_entry,
tar->pax_entry_length * sizeof(wchar_t));
if (tar->pax_entry == NULL) {
free(old_entry);
@ -1435,7 +1445,7 @@ header_gnutar(struct archive *a, struct tar *tar, struct archive_entry *entry,
header_common(a, tar, entry, st, h);
/* Copy filename over (to ensure null termination). */
header = h;
header = (const struct archive_entry_header_gnutar *)h;
archive_strncpy(&(tar->entry_name), header->name,
sizeof(header->name));
archive_entry_set_pathname(entry, tar->entry_name.s);
@ -1532,7 +1542,7 @@ gnu_parse_sparse_data(struct archive *a, struct tar *tar,
last = last->next;
while (length > 0 && sparse->offset[0] != 0) {
p = malloc(sizeof(*p));
p = (struct sparse_block *)malloc(sizeof(*p));
if (p == NULL)
__archive_errx(1, "Out of memory");
memset(p, 0, sizeof(*p));
@ -1799,8 +1809,12 @@ UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n)
static char *
base64_decode(const wchar_t *src, size_t len, size_t *out_len)
{
static const unsigned char digits[64] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const unsigned char digits[64] = {
'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','+','/' };
static unsigned char decode_table[128];
char *out, *d;
@ -1814,7 +1828,7 @@ base64_decode(const wchar_t *src, size_t len, size_t *out_len)
/* Allocate enough space to hold the entire output. */
/* Note that we may not use all of this... */
out = malloc((len * 3 + 3) / 4);
out = (char *)malloc((len * 3 + 3) / 4);
if (out == NULL) {
*out_len = 0;
return (NULL);
@ -1880,7 +1894,7 @@ wide_to_narrow(const wchar_t *wval)
int converted_length;
/* Guess an output buffer size and try the conversion. */
int alloc_length = wcslen(wval) * 3;
char *mbs_val = malloc(alloc_length + 1);
char *mbs_val = (char *)malloc(alloc_length + 1);
if (mbs_val == NULL)
return (NULL);
converted_length = wcstombs(mbs_val, wval, alloc_length);
@ -1889,7 +1903,7 @@ wide_to_narrow(const wchar_t *wval)
while (converted_length >= alloc_length) {
free(mbs_val);
alloc_length *= 2;
mbs_val = malloc(alloc_length + 1);
mbs_val = (char *)malloc(alloc_length + 1);
if (mbs_val == NULL)
return (NULL);
converted_length = wcstombs(mbs_val, wval, alloc_length);
@ -1906,7 +1920,7 @@ url_decode(const char *in)
char *out, *d;
const char *s;
out = malloc(strlen(in) + 1);
out = (char *)malloc(strlen(in) + 1);
if (out == NULL)
return (NULL);
for (s = in, d = out; *s != '\0'; ) {

View File

@ -27,10 +27,16 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <time.h>
#ifdef HAVE_ZLIB_H
#include <zlib.h>
@ -137,7 +143,7 @@ archive_read_support_format_zip(struct archive *a)
struct zip *zip;
int r;
zip = malloc(sizeof(*zip));
zip = (struct zip *)malloc(sizeof(*zip));
if (zip == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate zip data");
return (ARCHIVE_FATAL);
@ -172,7 +178,7 @@ archive_read_format_zip_bid(struct archive *a)
bytes_read = (a->compression_read_ahead)(a, &h, 4);
if (bytes_read < 4)
return (-1);
p = h;
p = (const char *)h;
if (p[0] == 'P' && p[1] == 'K') {
bid += 16;
@ -201,7 +207,7 @@ archive_read_format_zip_read_header(struct archive *a,
if (a->archive_format_name == NULL)
a->archive_format_name = "ZIP";
zip = *(a->pformat_data);
zip = (struct zip *)*(a->pformat_data);
zip->decompress_init = 0;
zip->end_of_entry = 0;
zip->end_of_entry_cleanup = 0;
@ -211,7 +217,7 @@ archive_read_format_zip_read_header(struct archive *a,
if (bytes_read < 4)
return (ARCHIVE_FATAL);
signature = h;
signature = (const char *)h;
if (signature[0] != 'P' || signature[1] != 'K') {
archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
"Bad ZIP file");
@ -265,7 +271,7 @@ zip_read_file_header(struct archive *a, struct archive_entry *entry,
"Truncated ZIP file header");
return (ARCHIVE_FATAL);
}
p = h;
p = (const struct zip_file_header *)h;
zip->version = p->version[0];
zip->system = p->version[1];
@ -299,7 +305,7 @@ zip_read_file_header(struct archive *a, struct archive_entry *entry,
return (ARCHIVE_FATAL);
}
archive_string_ensure(&zip->pathname, zip->filename_length);
archive_strncpy(&zip->pathname, h, zip->filename_length);
archive_strncpy(&zip->pathname, (const char *)h, zip->filename_length);
(a->compression_read_consume)(a, zip->filename_length);
archive_entry_set_pathname(entry, zip->pathname.s);
@ -369,7 +375,7 @@ archive_read_format_zip_read_data(struct archive *a,
int r;
struct zip *zip;
zip = *(a->pformat_data);
zip = (struct zip *)*(a->pformat_data);
/*
* If we hit end-of-entry last time, clean up and return
@ -388,7 +394,7 @@ archive_read_format_zip_read_data(struct archive *a,
"Truncated ZIP end-of-file record");
return (ARCHIVE_FATAL);
}
p = h;
p = (const char *)h;
zip->crc32 = i4(p + 4);
zip->compressed_size = u4(p + 8);
zip->uncompressed_size = u4(p + 12);
@ -473,7 +479,7 @@ zip_read_data_none(struct archive *a, const void **buff,
struct zip *zip;
ssize_t bytes_avail;
zip = *(a->pformat_data);
zip = (struct zip *)*(a->pformat_data);
if (zip->entry_bytes_remaining == 0) {
*buff = NULL;
@ -516,13 +522,13 @@ zip_read_data_deflate(struct archive *a, const void **buff,
const void *compressed_buff;
int r;
zip = *(a->pformat_data);
zip = (struct zip *)*(a->pformat_data);
/* If the buffer hasn't been allocated, allocate it now. */
if (zip->uncompressed_buffer == NULL) {
zip->uncompressed_buffer_size = 32 * 1024;
zip->uncompressed_buffer
= malloc(zip->uncompressed_buffer_size);
= (unsigned char *)malloc(zip->uncompressed_buffer_size);
if (zip->uncompressed_buffer == NULL) {
archive_set_error(a, ENOMEM,
"No memory for ZIP decompression");
@ -561,7 +567,7 @@ zip_read_data_deflate(struct archive *a, const void **buff,
* next_in pointer, only reads it). The result: this ugly
* cast to remove 'const'.
*/
zip->stream.next_in = (void *)(uintptr_t)(const void *)compressed_buff;
zip->stream.next_in = (Bytef *)(uintptr_t)(const void *)compressed_buff;
zip->stream.avail_in = bytes_avail;
zip->stream.total_in = 0;
zip->stream.next_out = zip->uncompressed_buffer;
@ -603,8 +609,6 @@ static int
zip_read_data_deflate(struct archive *a, const void **buff,
size_t *size, off_t *offset)
{
int r;
*buff = NULL;
*size = 0;
*offset = 0;
@ -621,7 +625,7 @@ archive_read_format_zip_read_data_skip(struct archive *a)
const void *buff = NULL;
ssize_t bytes_avail;
zip = *(a->pformat_data);
zip = (struct zip *)*(a->pformat_data);
/*
* If the length is at the end, we have no choice but
@ -664,7 +668,7 @@ archive_read_format_zip_cleanup(struct archive *a)
{
struct zip *zip;
zip = *(a->pformat_data);
zip = (struct zip *)*(a->pformat_data);
if (zip->uncompressed_buffer != NULL)
free(zip->uncompressed_buffer);
archive_string_free(&(zip->pathname));
@ -714,7 +718,7 @@ static void
process_extra(const void* extra, struct zip* zip)
{
int offset = 0;
const char *p = extra;
const char *p = (const char *)extra;
while (offset < zip->extra_length - 4)
{
unsigned short headerid = u2(p + offset);

View File

@ -32,8 +32,12 @@ __FBSDID("$FreeBSD$");
* strings while minimizing heap activity.
*/
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "archive_private.h"
#include "archive_string.h"
@ -67,7 +71,7 @@ __archive_string_ensure(struct archive_string *as, size_t s)
as->buffer_length = 32;
while (as->buffer_length < s)
as->buffer_length *= 2;
as->s = realloc(as->s, as->buffer_length);
as->s = (char *)realloc(as->s, as->buffer_length);
/* TODO: Return null instead and fix up all of our callers to
* handle this correctly. */
if (as->s == NULL)

View File

@ -31,7 +31,9 @@
#define ARCHIVE_STRING_H_INCLUDED
#include <stdarg.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif
/*
* Basic resizable/reusable string support a la Java's "StringBuffer."

View File

@ -27,9 +27,15 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "archive.h"
#include "archive_private.h"

View File

@ -35,13 +35,23 @@ __FBSDID("$FreeBSD$");
* needlessly bloating statically-linked clients.
*/
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <time.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "archive.h"
#include "archive_entry.h"
@ -56,7 +66,7 @@ archive_write_new(void)
struct archive *a;
unsigned char *nulls;
a = malloc(sizeof(*a));
a = (struct archive *)malloc(sizeof(*a));
if (a == NULL)
return (NULL);
memset(a, 0, sizeof(*a));
@ -69,7 +79,7 @@ archive_write_new(void)
/* Initialize a block of nulls for padding purposes. */
a->null_length = 1024;
nulls = malloc(a->null_length);
nulls = (unsigned char *)malloc(a->null_length);
if (nulls == NULL) {
free(a);
return (NULL);

View File

@ -27,11 +27,21 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#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_private.h"
@ -50,7 +60,7 @@ archive_write_open_fd(struct archive *a, int fd)
{
struct write_fd_data *mine;
mine = malloc(sizeof(*mine));
mine = (struct write_fd_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
@ -67,7 +77,7 @@ file_open(struct archive *a, void *client_data)
struct stat st, *pst;
pst = NULL;
mine = client_data;
mine = (struct write_fd_data *)client_data;
/*
* If client hasn't explicitly set the last block handling,
@ -113,7 +123,7 @@ file_write(struct archive *a, void *client_data, void *buff, size_t length)
struct write_fd_data *mine;
ssize_t bytesWritten;
mine = client_data;
mine = (struct write_fd_data *)client_data;
bytesWritten = write(mine->fd, buff, length);
if (bytesWritten <= 0) {
archive_set_error(a, errno, "Write error");
@ -125,7 +135,7 @@ file_write(struct archive *a, void *client_data, void *buff, size_t length)
static int
file_close(struct archive *a, void *client_data)
{
struct write_fd_data *mine = client_data;
struct write_fd_data *mine = (struct write_fd_data *)client_data;
(void)a; /* UNUSED */
free(mine);

View File

@ -27,12 +27,24 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.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_private.h"
@ -52,14 +64,14 @@ archive_write_open_file(struct archive *a, const char *filename)
struct write_file_data *mine;
if (filename == NULL || filename[0] == '\0') {
mine = malloc(sizeof(*mine));
mine = (struct write_file_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
mine->filename[0] = '\0'; /* Record that we're using stdout. */
} else {
mine = malloc(sizeof(*mine) + strlen(filename));
mine = (struct write_file_data *)malloc(sizeof(*mine) + strlen(filename));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
@ -79,7 +91,7 @@ file_open(struct archive *a, void *client_data)
struct stat st, *pst;
pst = NULL;
mine = client_data;
mine = (struct write_file_data *)client_data;
flags = O_WRONLY | O_CREAT | O_TRUNC;
if (mine->filename[0] != '\0') {
@ -144,7 +156,7 @@ file_write(struct archive *a, void *client_data, void *buff, size_t length)
struct write_file_data *mine;
ssize_t bytesWritten;
mine = client_data;
mine = (struct write_file_data *)client_data;
bytesWritten = write(mine->fd, buff, length);
if (bytesWritten <= 0) {
archive_set_error(a, errno, "Write error");
@ -156,7 +168,7 @@ file_write(struct archive *a, void *client_data, void *buff, size_t length)
static int
file_close(struct archive *a, void *client_data)
{
struct write_file_data *mine = client_data;
struct write_file_data *mine = (struct write_file_data *)client_data;
(void)a; /* UNUSED */
if (mine->filename[0] != '\0')

View File

@ -27,12 +27,24 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.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_private.h"
@ -52,14 +64,14 @@ archive_write_open_file(struct archive *a, const char *filename)
struct write_file_data *mine;
if (filename == NULL || filename[0] == '\0') {
mine = malloc(sizeof(*mine));
mine = (struct write_file_data *)malloc(sizeof(*mine));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
}
mine->filename[0] = '\0'; /* Record that we're using stdout. */
} else {
mine = malloc(sizeof(*mine) + strlen(filename));
mine = (struct write_file_data *)malloc(sizeof(*mine) + strlen(filename));
if (mine == NULL) {
archive_set_error(a, ENOMEM, "No memory");
return (ARCHIVE_FATAL);
@ -79,7 +91,7 @@ file_open(struct archive *a, void *client_data)
struct stat st, *pst;
pst = NULL;
mine = client_data;
mine = (struct write_file_data *)client_data;
flags = O_WRONLY | O_CREAT | O_TRUNC;
if (mine->filename[0] != '\0') {
@ -144,7 +156,7 @@ file_write(struct archive *a, void *client_data, void *buff, size_t length)
struct write_file_data *mine;
ssize_t bytesWritten;
mine = client_data;
mine = (struct write_file_data *)client_data;
bytesWritten = write(mine->fd, buff, length);
if (bytesWritten <= 0) {
archive_set_error(a, errno, "Write error");
@ -156,7 +168,7 @@ file_write(struct archive *a, void *client_data, void *buff, size_t length)
static int
file_close(struct archive *a, void *client_data)
{
struct write_file_data *mine = client_data;
struct write_file_data *mine = (struct write_file_data *)client_data;
(void)a; /* UNUSED */
if (mine->filename[0] != '\0')

View File

@ -31,11 +31,19 @@
__FBSDID("$FreeBSD$");
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_BZLIB_H
#include <bzlib.h>
#endif
#include "archive.h"
#include "archive_private.h"
@ -53,7 +61,7 @@ struct private_data {
* of ugly hackery to convert a const * pointer to a non-const pointer.
*/
#define SET_NEXT_IN(st,src) \
(st)->stream.next_in = (void *)(uintptr_t)(const void *)(src)
(st)->stream.next_in = (char *)(uintptr_t)(const void *)(src)
static int archive_compressor_bzip2_finish(struct archive *);
static int archive_compressor_bzip2_init(struct archive *);
@ -93,7 +101,7 @@ archive_compressor_bzip2_init(struct archive *a)
return (ret);
}
state = malloc(sizeof(*state));
state = (struct private_data *)malloc(sizeof(*state));
if (state == NULL) {
archive_set_error(a, ENOMEM,
"Can't allocate data for compression");
@ -102,7 +110,7 @@ archive_compressor_bzip2_init(struct archive *a)
memset(state, 0, sizeof(*state));
state->compressed_buffer_size = a->bytes_per_block;
state->compressed = malloc(state->compressed_buffer_size);
state->compressed = (char *)malloc(state->compressed_buffer_size);
if (state->compressed == NULL) {
archive_set_error(a, ENOMEM,
@ -163,7 +171,7 @@ archive_compressor_bzip2_write(struct archive *a, const void *buff,
{
struct private_data *state;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
if (a->client_writer == NULL) {
archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER,
"No write callback is registered? "
@ -197,7 +205,7 @@ archive_compressor_bzip2_finish(struct archive *a)
ssize_t bytes_written;
unsigned tocopy;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
ret = ARCHIVE_OK;
if (a->client_writer == NULL) {
archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER,

View File

@ -31,11 +31,19 @@
__FBSDID("$FreeBSD$");
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include <time.h>
#ifdef HAVE_ZLIB_H
#include <zlib.h>
#endif
#include "archive.h"
#include "archive_private.h"
@ -54,7 +62,7 @@ struct private_data {
* of ugly hackery to convert a const * pointer to a non-const pointer.
*/
#define SET_NEXT_IN(st,src) \
(st)->stream.next_in = (void *)(uintptr_t)(const void *)(src)
(st)->stream.next_in = (Bytef *)(uintptr_t)(const void *)(src)
static int archive_compressor_gzip_finish(struct archive *);
static int archive_compressor_gzip_init(struct archive *);
@ -105,7 +113,7 @@ archive_compressor_gzip_init(struct archive *a)
memset(state, 0, sizeof(*state));
state->compressed_buffer_size = a->bytes_per_block;
state->compressed = malloc(state->compressed_buffer_size);
state->compressed = (unsigned char *)malloc(state->compressed_buffer_size);
state->crc = crc32(0L, NULL, 0);
if (state->compressed == NULL) {
@ -186,7 +194,7 @@ archive_compressor_gzip_write(struct archive *a, const void *buff,
struct private_data *state;
int ret;
state = a->compression_data;
state = (struct private_data *)a->compression_data;
if (a->client_writer == NULL) {
archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER,
"No write callback is registered? "
@ -195,7 +203,7 @@ archive_compressor_gzip_write(struct archive *a, const void *buff,
}
/* Update statistics */
state->crc = crc32(state->crc, buff, length);
state->crc = crc32(state->crc, (const Bytef *)buff, length);
state->total_in += length;
/* Compress input data to output buffer */
@ -221,7 +229,7 @@ archive_compressor_gzip_finish(struct archive *a)
unsigned tocopy;
unsigned char trailer[8];
state = a->compression_data;
state = (struct private_data *)a->compression_data;
ret = 0;
if (a->client_writer == NULL) {
archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER,

View File

@ -27,9 +27,15 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "archive.h"
#include "archive_private.h"
@ -83,7 +89,7 @@ archive_compressor_none_init(struct archive *a)
memset(state, 0, sizeof(*state));
state->buffer_size = a->bytes_per_block;
state->buffer = malloc(state->buffer_size);
state->buffer = (char *)malloc(state->buffer_size);
if (state->buffer == NULL) {
archive_set_error(a, ENOMEM,
@ -113,8 +119,8 @@ archive_compressor_none_write(struct archive *a, const void *vbuff,
ssize_t bytes_written;
struct archive_none *state;
state = a->compression_data;
buff = vbuff;
state = (struct archive_none *)a->compression_data;
buff = (const char *)vbuff;
if (a->client_writer == NULL) {
archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER,
"No write callback is registered? "
@ -166,7 +172,7 @@ archive_compressor_none_finish(struct archive *a)
int ret2;
struct archive_none *state;
state = a->compression_data;
state = (struct archive_none *)a->compression_data;
ret = ret2 = ARCHIVE_OK;
if (a->client_writer == NULL) {
archive_set_error(a, ARCHIVE_ERRNO_PROGRAMMER,

View File

@ -27,9 +27,14 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include "archive.h"
#include "archive_private.h"

View File

@ -27,10 +27,16 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "archive.h"
#include "archive_private.h"

View File

@ -27,11 +27,19 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "archive.h"
#include "archive_entry.h"
@ -76,7 +84,7 @@ archive_write_set_format_cpio(struct archive *a)
if (a->format_finish != NULL)
(a->format_finish)(a);
cpio = malloc(sizeof(*cpio));
cpio = (struct cpio *)malloc(sizeof(*cpio));
if (cpio == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate cpio data");
return (ARCHIVE_FATAL);
@ -103,7 +111,7 @@ archive_write_cpio_header(struct archive *a, struct archive_entry *entry)
const struct stat *st;
struct cpio_header h;
cpio = a->format_data;
cpio = (struct cpio *)a->format_data;
ret = 0;
path = archive_entry_pathname(entry);
@ -165,7 +173,7 @@ archive_write_cpio_data(struct archive *a, const void *buff, size_t s)
struct cpio *cpio;
int ret;
cpio = a->format_data;
cpio = (struct cpio *)a->format_data;
if (s > cpio->entry_bytes_remaining)
s = cpio->entry_bytes_remaining;
@ -185,10 +193,10 @@ format_octal(int64_t v, void *p, int digits)
max = (((int64_t)1) << (digits * 3)) - 1;
if (v >= 0 && v <= max) {
format_octal_recursive(v, p, digits);
format_octal_recursive(v, (char *)p, digits);
ret = 0;
} else {
format_octal_recursive(max, p, digits);
format_octal_recursive(max, (char *)p, digits);
ret = -1;
}
return (ret);
@ -212,7 +220,7 @@ archive_write_cpio_finish(struct archive *a)
int er;
struct archive_entry *trailer;
cpio = a->format_data;
cpio = (struct cpio *)a->format_data;
trailer = archive_entry_new();
memset(&st, 0, sizeof(st));
st.st_nlink = 1;
@ -232,7 +240,7 @@ archive_write_cpio_finish_entry(struct archive *a)
struct cpio *cpio;
int to_write, ret;
cpio = a->format_data;
cpio = (struct cpio *)a->format_data;
ret = ARCHIVE_OK;
while (cpio->entry_bytes_remaining > 0) {
to_write = cpio->entry_bytes_remaining < a->null_length ?

View File

@ -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;

View File

@ -27,12 +27,20 @@
#include "archive_platform.h"
__FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stdarg.h>
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "archive.h"
#include "archive_entry.h"
@ -71,7 +79,7 @@ shar_printf(struct archive *a, const char *fmt, ...)
va_list ap;
int ret;
shar = a->format_data;
shar = (struct shar *)a->format_data;
va_start(ap, fmt);
archive_string_empty(&(shar->work));
archive_string_vsprintf(&(shar->work), fmt, ap);
@ -92,7 +100,7 @@ archive_write_set_format_shar(struct archive *a)
if (a->format_finish != NULL)
(a->format_finish)(a);
shar = malloc(sizeof(*shar));
shar = (struct shar *)malloc(sizeof(*shar));
if (shar == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate shar data");
return (ARCHIVE_FATAL);
@ -122,7 +130,7 @@ archive_write_set_format_shar_dump(struct archive *a)
struct shar *shar;
archive_write_set_format_shar(a);
shar = a->format_data;
shar = (struct shar *)a->format_data;
shar->dump = 1;
a->format_write_data = archive_write_shar_data_uuencode;
a->archive_format = ARCHIVE_FORMAT_SHAR_DUMP;
@ -140,7 +148,7 @@ archive_write_shar_header(struct archive *a, struct archive_entry *entry)
const struct stat *st;
int ret;
shar = a->format_data;
shar = (struct shar *)a->format_data;
if (!shar->wrote_header) {
ret = shar_printf(a, "#!/bin/sh\n");
if (ret != ARCHIVE_OK)
@ -322,11 +330,11 @@ archive_write_shar_data_sed(struct archive *a, const void *buff, size_t n)
const char *src;
int ret;
shar = a->format_data;
shar = (struct shar *)a->format_data;
if (!shar->has_data)
return (0);
src = buff;
src = (const char *)buff;
ret = ARCHIVE_OK;
shar->outpos = 0;
while (n-- > 0) {
@ -385,10 +393,10 @@ archive_write_shar_data_uuencode(struct archive *a, const void *buff,
size_t n;
int ret;
shar = a->format_data;
shar = (struct shar *)a->format_data;
if (!shar->has_data)
return (ARCHIVE_OK);
src = buff;
src = (const char *)buff;
n = length;
while (n-- > 0) {
if (shar->uuavail == 3)
@ -415,7 +423,7 @@ archive_write_shar_finish_entry(struct archive *a)
struct shar *shar;
int ret;
shar = a->format_data;
shar = (struct shar *)a->format_data;
if (shar->entry == NULL)
return (0);
@ -504,7 +512,7 @@ archive_write_shar_finish(struct archive *a)
* fix them all up at end-of-archive.
*/
shar = a->format_data;
shar = (struct shar *)a->format_data;
/*
* Only write the end-of-archive markers if the archive was

View File

@ -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,16 @@ __FBSDID("$FreeBSD$");
#include <sys/sysmacros.h>
#endif
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#include "archive.h"
#include "archive_entry.h"
@ -85,20 +93,22 @@ struct archive_entry_header_ustar {
*/
static const struct archive_entry_header_ustar template_header = {
{ "" }, /* name */
{ "000000" }, { ' ', '\0' }, /* mode, space-null termination. */
{ "000000" }, { ' ', '\0' }, /* uid, space-null termination. */
{ "000000" }, { ' ', '\0' }, /* gid, space-null termination. */
{ "00000000000" }, { ' ' }, /* size, space termination. */
{ "00000000000" }, { ' ' }, /* mtime, space termination. */
{ " " }, /* Initial checksum value. */
{ '0','0','0','0','0','0' }, { ' ', '\0' }, /* mode, space-null term.*/
{ '0','0','0','0','0','0' }, { ' ', '\0' }, /* uid, space-null term. */
{ '0','0','0','0','0','0' }, { ' ', '\0' }, /* gid, space-null term. */
{ '0','0','0','0','0','0','0','0','0','0','0' }, { ' ' },
/* size, space termination. */
{ '0','0','0','0','0','0','0','0','0','0','0' }, { ' ' },
/* mtime, space termination. */
{ ' ',' ',' ',' ',' ',' ',' ',' ' }, /* Initial checksum value. */
{ '0' }, /* default: regular file */
{ "" }, /* linkname */
{ "ustar" }, /* magic */
{ 'u','s','t','a','r' }, /* magic */
{ '0', '0' }, /* version */
{ "" }, /* uname */
{ "" }, /* gname */
{ "000000" }, { ' ', '\0' }, /* rdevmajor, space-null termination */
{ "000000" }, { ' ', '\0' }, /* rdevminor, space-null termination */
{ '0','0','0','0','0','0' }, { ' ', '\0' }, /* rdevmajor, space-null */
{ '0','0','0','0','0','0' }, { ' ', '\0' }, /* rdevminor, space-null */
{ "" }, /* prefix */
{ "" } /* padding */
};
@ -126,7 +136,7 @@ archive_write_set_format_ustar(struct archive *a)
if (a->format_finish != NULL)
(a->format_finish)(a);
ustar = malloc(sizeof(*ustar));
ustar = (struct ustar *)malloc(sizeof(*ustar));
if (ustar == NULL) {
archive_set_error(a, ENOMEM, "Can't allocate ustar data");
return (ARCHIVE_FATAL);
@ -151,7 +161,7 @@ archive_write_ustar_header(struct archive *a, struct archive_entry *entry)
int ret;
struct ustar *ustar;
ustar = a->format_data;
ustar = (struct ustar *)a->format_data;
ustar->written = 1;
/* Only regular files (not hardlinks) have data. */
@ -442,7 +452,7 @@ archive_write_ustar_finish(struct archive *a)
int r;
r = ARCHIVE_OK;
ustar = a->format_data;
ustar = (struct ustar *)a->format_data;
/*
* Suppress end-of-archive if nothing else was ever written.
* This fixes a problem where setting one format, then another
@ -461,7 +471,7 @@ archive_write_ustar_finish_entry(struct archive *a)
struct ustar *ustar;
int ret;
ustar = a->format_data;
ustar = (struct ustar *)a->format_data;
ret = write_nulls(a,
ustar->entry_bytes_remaining + ustar->entry_padding);
ustar->entry_bytes_remaining = ustar->entry_padding = 0;
@ -489,7 +499,7 @@ archive_write_ustar_data(struct archive *a, const void *buff, size_t s)
struct ustar *ustar;
int ret;
ustar = a->format_data;
ustar = (struct ustar *)a->format_data;
if (s > ustar->entry_bytes_remaining)
s = ustar->entry_bytes_remaining;
ret = (a->compression_write)(a, buff, s);