From 9d3ddfc96e699429bf99c3f1d39ebd0f220942b4 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 23 Dec 2013 00:04:38 +0100 Subject: [PATCH] More MinGW trickery... Poor man's attempt at making 4e002d9a92ecd7cec0fb98b0bedbace8aad81f6e play nice with MinGW. Dry coded for the fastest solution, there's probably a much better way to handle that sanely & properly. --- libarchive/archive_pack_dev.c | 29 +++++++++++++++++++++++++++-- libarchive/archive_windows.c | 23 +++++++++++++++++++---- libarchive/archive_windows.h | 6 ++++-- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/libarchive/archive_pack_dev.c b/libarchive/archive_pack_dev.c index 474f962ba..5295da2a1 100644 --- a/libarchive/archive_pack_dev.c +++ b/libarchive/archive_pack_dev.c @@ -76,14 +76,39 @@ static const char iMajorError[] = "invalid major number"; static const char iMinorError[] = "invalid minor number"; static const char tooManyFields[] = "too many fields for format"; - /* exported */ +/* This is balatantly stolen from libarchive/archive_entry.c, + * in an attempt to get this to play nice on MinGW... */ +#if !defined(HAVE_MAJOR) && !defined(major) +/* Replacement for major/minor/makedev. */ +#define major(x) ((int)(0x00ff & ((x) >> 8))) +#define minor(x) ((int)(0xffff00ff & (x))) +#define makedev(maj,min) ((0xff00 & ((maj)<<8)) | (0xffff00ff & (min))) +#endif + +/* Play games to come up with a suitable makedev() definition. */ +#ifdef __QNXNTO__ +/* QNX. */ +#include +#define apd_makedev(maj, min) makedev(ND_LOCAL_NODE, (maj), (min)) +#elif defined makedev +/* There's a "makedev" macro. */ +#define apd_makedev(maj, min) makedev((maj), (min)) +#elif defined mkdev || ((defined _WIN32 || defined __WIN32__) && !defined(__CYGWIN__)) +/* Windows. */ +#define apd_makedev(maj, min) mkdev((maj), (min)) +#else +/* There's a "makedev" function. */ +#define apd_makedev(maj, min) makedev((maj), (min)) +#endif + +/* exported */ dev_t pack_native(int n, u_long numbers[], const char **error) { dev_t dev = 0; if (n == 2) { - dev = makedev(numbers[0], numbers[1]); + dev = apd_makedev(numbers[0], numbers[1]); if ((u_long)major(dev) != numbers[0]) *error = iMajorError; else if ((u_long)minor(dev) != numbers[1]) diff --git a/libarchive/archive_windows.c b/libarchive/archive_windows.c index c033abde8..1b36f51a2 100644 --- a/libarchive/archive_windows.c +++ b/libarchive/archive_windows.c @@ -301,7 +301,7 @@ __la_open(const char *path, int flags, ...) ws = NULL; if ((flags & ~O_BINARY) == O_RDONLY) { /* - * When we open a directory, _open function returns + * When we open a directory, _open function returns * "Permission denied" error. */ attr = GetFileAttributesA(path); @@ -515,9 +515,9 @@ __hstat(HANDLE handle, struct ustat *st) else mode |= S_IFREG; st->st_mode = mode; - + fileTimeToUTC(&info.ftLastAccessTime, &t, &ns); - st->st_atime = t; + st->st_atime = t; st->st_atime_nsec = ns; fileTimeToUTC(&info.ftLastWriteTime, &t, &ns); st->st_mtime = t; @@ -525,7 +525,7 @@ __hstat(HANDLE handle, struct ustat *st) fileTimeToUTC(&info.ftCreationTime, &t, &ns); st->st_ctime = t; st->st_ctime_nsec = ns; - st->st_size = + st->st_size = ((int64_t)(info.nFileSizeHigh) * ((int64_t)MAXDWORD + 1)) + (int64_t)(info.nFileSizeLow); #ifdef SIMULATE_WIN_STAT @@ -905,4 +905,19 @@ __la_dosmaperr(unsigned long e) return; } +/* Taken from http://unixpapa.com/incnote/string.html */ +char * +__la_strsep(char **sp, char *sep) +{ + char *p, *s; + if (sp == NULL || *sp == NULL || **sp == '\0') + return(NULL); + s = *sp; + p = s + strcspn(s, sep); + if (*p != '\0') + *p++ = '\0'; + *sp = p; + return(s); +} + #endif /* _WIN32 && !__CYGWIN__ */ diff --git a/libarchive/archive_windows.h b/libarchive/archive_windows.h index c6f5bc510..1ef4fa048 100644 --- a/libarchive/archive_windows.h +++ b/libarchive/archive_windows.h @@ -89,7 +89,7 @@ /* Alias the Windows _function to the POSIX equivalent. */ #define close _close -#define fcntl(fd, cmd, flg) /* No operation. */ +#define fcntl(fd, cmd, flg) /* No operation. */ #ifndef fileno #define fileno _fileno #endif @@ -203,7 +203,7 @@ #define _S_IXGRP (_S_IXUSR >> 3) /* read permission, group */ #define _S_IWGRP (_S_IWUSR >> 3) /* write permission, group */ #define _S_IRGRP (_S_IRUSR >> 3) /* execute/search permission, group */ -#define _S_IRWXO (_S_IRWXG >> 3) +#define _S_IRWXO (_S_IRWXG >> 3) #define _S_IXOTH (_S_IXGRP >> 3) /* read permission, other */ #define _S_IWOTH (_S_IWGRP >> 3) /* write permission, other */ #define _S_IROTH (_S_IRGRP >> 3) /* execute/search permission, other */ @@ -277,6 +277,8 @@ extern wchar_t *__la_win_permissive_name(const char *name); extern wchar_t *__la_win_permissive_name_w(const wchar_t *wname); extern void __la_dosmaperr(unsigned long e); #define la_dosmaperr(e) __la_dosmaperr(e) +extern char *__la_strsep(char **sp, char *sep); +#define strsep(sp, sep) __la_strsep(sp, sep) extern struct archive_entry *__la_win_entry_in_posix_pathseparator( struct archive_entry *); -- 2.47.2