]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
More MinGW trickery...
authorNiLuJe <ninuje@gmail.com>
Sun, 22 Dec 2013 23:04:38 +0000 (00:04 +0100)
committerNiLuJe <ninuje@gmail.com>
Sun, 22 Dec 2013 23:04:38 +0000 (00:04 +0100)
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
libarchive/archive_windows.c
libarchive/archive_windows.h

index 474f962ba88b479eb04ed54b908658abc2495ec8..5295da2a1e827cf289390ed36dc0d4ccffed96a7 100644 (file)
@@ -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.  <sigh> */
+#include <sys/netmgr.h>
+#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. <sigh> */
+#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])
index c033abde8c45115db08f964b01df841d19b9a4c3..1b36f51a22b9f0874af9ec4da0cc46a230bb2afd 100644 (file)
@@ -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__ */
index c6f5bc51051353aa735225aaef0d03af550ed5b7..1ef4fa048fa45ac9066074e540f9b3fa6eb75aa1 100644 (file)
@@ -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
 #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 *);