From e44c5d7f15b3f3927b84aa4e56a0ff8c0f5c895f Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sun, 13 Sep 2009 03:05:56 -0400 Subject: [PATCH] Fix some compiler warnings in VS9. SVN-Revision: 1457 --- cpio/cpio.c | 3 ++- cpio/cpio_windows.h | 4 ++++ libarchive/archive_check_magic.c | 2 +- libarchive/archive_write_set_format_cpio_newc.c | 9 ++++++--- tar/bsdtar_windows.h | 2 ++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cpio/cpio.c b/cpio/cpio.c index f3fc29adf..173809c42 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -990,7 +990,8 @@ list_item_verbose(struct cpio *cpio, struct archive_entry *entry) tim = (time_t)st->st_mtime; #if defined(_WIN32) && !defined(__CYGWIN__) /* Windows' strftime function does not support %e format. */ - if (abs(tim - now) > (365/2)*86400) + if (tim - now > 365*86400/2 + || tim - now < -365*86400/2) fmt = cpio->day_first ? "%d %b %Y" : "%b %d %Y"; else fmt = cpio->day_first ? "%d %b %H:%M" : "%b %d %H:%M"; diff --git a/cpio/cpio_windows.h b/cpio/cpio_windows.h index 9b44764c1..105bf6999 100644 --- a/cpio/cpio_windows.h +++ b/cpio/cpio_windows.h @@ -28,6 +28,7 @@ #define CPIO_WINDOWS_H 1 #include +#include #define getgrgid(id) NULL #define getgrnam(name) NULL @@ -37,6 +38,9 @@ #ifdef _MSC_VER #define snprintf sprintf_s #define strdup _strdup +#define open _open +#define read _read +#define close _close #endif struct passwd { diff --git a/libarchive/archive_check_magic.c b/libarchive/archive_check_magic.c index b94448f5a..1d4c3a6e3 100644 --- a/libarchive/archive_check_magic.c +++ b/libarchive/archive_check_magic.c @@ -94,7 +94,7 @@ write_all_states(unsigned int states) unsigned int lowbit; /* A trick for computing the lowest set bit. */ - while ((lowbit = states & (-states)) != 0) { + while ((lowbit = states & (1 + ~states)) != 0) { states &= ~lowbit; /* Clear the low bit. */ errmsg(state_name(lowbit)); if (states != 0) diff --git a/libarchive/archive_write_set_format_cpio_newc.c b/libarchive/archive_write_set_format_cpio_newc.c index a826877ae..099c4ff51 100644 --- a/libarchive/archive_write_set_format_cpio_newc.c +++ b/libarchive/archive_write_set_format_cpio_newc.c @@ -75,6 +75,9 @@ struct cpio_header_newc { char c_checksum[8]; }; +/* Logic trick: difference between 'n' and next multiple of 4 */ +#define PAD4(n) (3 & (1 + ~(n))) + /* * Set output format to 'cpio' format. */ @@ -169,21 +172,21 @@ archive_write_newc_header(struct archive_write *a, struct archive_entry *entry) ret = (a->compressor.write)(a, path, pathlength); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); - pad = 0x3 & - (pathlength + sizeof(struct cpio_header_newc)); + pad = PAD4(pathlength + sizeof(struct cpio_header_newc)); if (pad) ret = (a->compressor.write)(a, "\0\0\0", pad); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); cpio->entry_bytes_remaining = archive_entry_size(entry); - cpio->padding = 3 & (-cpio->entry_bytes_remaining); + cpio->padding = PAD4(cpio->entry_bytes_remaining); /* Write the symlink now. */ if (p != NULL && *p != '\0') { ret = (a->compressor.write)(a, p, strlen(p)); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); - pad = 0x3 & -strlen(p); + pad = PAD4(strlen(p)); ret = (a->compressor.write)(a, "\0\0\0", pad); } diff --git a/tar/bsdtar_windows.h b/tar/bsdtar_windows.h index 61fb2a95c..6480ac30c 100644 --- a/tar/bsdtar_windows.h +++ b/tar/bsdtar_windows.h @@ -41,6 +41,8 @@ #include /* Must include before redefining 'strdup' */ #define strdup _strdup +#define read _read +#define getcwd _getcwd #define chdir __tar_chdir int __tar_chdir(const char *); -- 2.47.3