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";
#define CPIO_WINDOWS_H 1
#include <io.h>
+#include <string.h>
#define getgrgid(id) NULL
#define getgrnam(name) NULL
#ifdef _MSC_VER
#define snprintf sprintf_s
#define strdup _strdup
+#define open _open
+#define read _read
+#define close _close
#endif
struct passwd {
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)
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.
*/
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);
}
#include <string.h> /* Must include before redefining 'strdup' */
#define strdup _strdup
+#define read _read
+#define getcwd _getcwd
#define chdir __tar_chdir
int __tar_chdir(const char *);