зеркало из https://github.com/microsoft/vcpkg.git
[tre, libmagic] Windows + mingw support (#17769)
* [tre] mingw support * [libmagic] Windows support * [libmagic] Apply @Neumann-A suggestions * [libmagic] Add host dependency Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com> * [libmagic] Copy the magic file to the corresponding tools dir * [ci baseline] libmagic now passes * Update ports/libmagic/portfile.cmake * [libmagic] Import patch from MSYS2 * [vcpkg baseline] Update libmagic, tre Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com> Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com>
This commit is contained in:
Родитель
0de461216d
Коммит
a29126f785
|
@ -0,0 +1,53 @@
|
|||
From e6e59f41c082be94c4fef007e276b1dffe7dc240 Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sat, 8 May 2021 19:28:01 +0700
|
||||
Subject: [PATCH 01/14] Use libtre
|
||||
|
||||
---
|
||||
configure.ac | 2 +-
|
||||
src/Makefile.am | 2 +-
|
||||
src/file.h | 2 +-
|
||||
3 files changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/configure.ac b/configure.ac
|
||||
index 02eac8f..b05c334 100644
|
||||
--- a/configure.ac
|
||||
+++ b/configure.ac
|
||||
@@ -185,7 +185,7 @@ if test "$enable_libseccomp" != "no"; then
|
||||
AC_CHECK_LIB(seccomp, seccomp_init)
|
||||
fi
|
||||
if test "$MINGW" = 1; then
|
||||
- AC_CHECK_LIB(gnurx,regexec,,AC_MSG_ERROR([libgnurx is required to build file(1) with MinGW]))
|
||||
+ AC_SEARCH_LIBS(tre_regexec,tre,,AC_MSG_ERROR([libtre is required to build file(1) with MinGW]))
|
||||
fi
|
||||
|
||||
dnl See if we are cross-compiling
|
||||
diff --git a/src/Makefile.am b/src/Makefile.am
|
||||
index 3f67f2c..34781b9 100644
|
||||
--- a/src/Makefile.am
|
||||
+++ b/src/Makefile.am
|
||||
@@ -13,7 +13,7 @@ libmagic_la_SOURCES = buffer.c magic.c apprentice.c softmagic.c ascmagic.c \
|
||||
file_opts.h elfclass.h mygetopt.h cdf.c cdf_time.c readcdf.c cdf.h
|
||||
libmagic_la_LDFLAGS = -no-undefined -version-info 1:0:0
|
||||
if MINGW
|
||||
-MINGWLIBS = -lgnurx -lshlwapi
|
||||
+MINGWLIBS = -lshlwapi
|
||||
else
|
||||
MINGWLIBS =
|
||||
endif
|
||||
diff --git a/src/file.h b/src/file.h
|
||||
index c548e97..299ac0c 100644
|
||||
--- a/src/file.h
|
||||
+++ b/src/file.h
|
||||
@@ -79,7 +79,7 @@
|
||||
#include <stdio.h> /* Include that here, to make sure __P gets defined */
|
||||
#include <errno.h>
|
||||
#include <fcntl.h> /* For open and flags */
|
||||
-#include <regex.h>
|
||||
+#include <tre/regex.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#ifndef WIN32
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
From 2fa43ece9ec7564e1fbb9867bb5852b834643aa4 Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sat, 8 May 2021 19:36:11 +0700
|
||||
Subject: [PATCH 02/14] Change zlib lib name to match CMake output
|
||||
|
||||
---
|
||||
configure.ac | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/configure.ac b/configure.ac
|
||||
index b05c334..dd4063c 100644
|
||||
--- a/configure.ac
|
||||
+++ b/configure.ac
|
||||
@@ -173,7 +173,7 @@ AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r
|
||||
|
||||
dnl Checks for libraries
|
||||
if test "$enable_zlib" != "no"; then
|
||||
- AC_CHECK_LIB(z, gzopen)
|
||||
+ AC_SEARCH_LIBS(gzopen, [z zlib zlibd], have_zlib = "yes", have_zlib = "no")
|
||||
fi
|
||||
if test "$enable_bzlib" != "no"; then
|
||||
AC_CHECK_LIB(bz2, BZ2_bzCompressInit)
|
||||
@@ -193,11 +193,11 @@ AM_CONDITIONAL(IS_CROSS_COMPILE, test "$cross_compiling" = yes)
|
||||
|
||||
dnl Final sanity checks
|
||||
if test "$enable_zlib" = "yes"; then
|
||||
- if test "$ac_cv_header_zlib_h$ac_cv_lib_z_gzopen" != "yesyes"; then
|
||||
+ if test "$ac_cv_header_zlib_h$have_zlib" != "yesyes"; then
|
||||
AC_MSG_ERROR([zlib support requested but not found])
|
||||
fi
|
||||
fi
|
||||
-if test "$ac_cv_header_zlib_h$ac_cv_lib_z_gzopen" = "yesyes"; then
|
||||
+if test "$ac_cv_header_zlib_h$have_zlib" = "yesyes"; then
|
||||
AC_DEFINE([ZLIBSUPPORT], 1, [Enable zlib compression support])
|
||||
fi
|
||||
if test "$enable_bzlib" = "yes"; then
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
From 2fffeb273ea46c1e91536f3d660982de785c8d49 Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sat, 8 May 2021 20:52:59 +0700
|
||||
Subject: [PATCH 03/14] Fix WIN32 macro checks
|
||||
|
||||
---
|
||||
src/file.h | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/file.h b/src/file.h
|
||||
index 299ac0c..2c365a6 100644
|
||||
--- a/src/file.h
|
||||
+++ b/src/file.h
|
||||
@@ -82,7 +82,7 @@
|
||||
#include <tre/regex.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
-#ifndef WIN32
|
||||
+#ifndef _WIN32
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
/* Do this here and now, because struct stat gets re-defined on solaris */
|
||||
@@ -95,7 +95,7 @@
|
||||
#define MAGIC "/etc/magic"
|
||||
#endif
|
||||
|
||||
-#if defined(__EMX__) || defined (WIN32)
|
||||
+#if defined(__EMX__) || defined (_WIN32)
|
||||
#define PATHSEP ';'
|
||||
#else
|
||||
#define PATHSEP ':'
|
||||
@@ -103,7 +103,7 @@
|
||||
|
||||
#define private static
|
||||
|
||||
-#if HAVE_VISIBILITY && !defined(WIN32)
|
||||
+#if HAVE_VISIBILITY && !defined(_WIN32)
|
||||
#define public __attribute__ ((__visibility__("default")))
|
||||
#ifndef protected
|
||||
#define protected __attribute__ ((__visibility__("hidden")))
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
From eb3dde2954dacd86ec7490540eb9b7e3530b917b Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sat, 8 May 2021 20:12:55 +0700
|
||||
Subject: [PATCH 04/14] Typedef POSIX types on Windows
|
||||
|
||||
---
|
||||
src/file.h | 6 ++++++
|
||||
1 file changed, 6 insertions(+)
|
||||
|
||||
diff --git a/src/file.h b/src/file.h
|
||||
index 2c365a6..0332506 100644
|
||||
--- a/src/file.h
|
||||
+++ b/src/file.h
|
||||
@@ -425,6 +425,12 @@ struct cont {
|
||||
|
||||
#define MAGIC_SETS 2
|
||||
|
||||
+#ifdef _MSC_VER
|
||||
+#include <BaseTsd.h>
|
||||
+typedef int mode_t;
|
||||
+typedef SSIZE_T ssize_t;
|
||||
+#endif
|
||||
+
|
||||
struct magic_set {
|
||||
struct mlist *mlist[MAGIC_SETS]; /* list of regular entries */
|
||||
struct cont c;
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
From a8f8fbfc2736419c65992cbf24de963c3b1f3107 Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sat, 8 May 2021 22:07:55 +0700
|
||||
Subject: [PATCH 05/14] Include dirent.h for S_ISREG and S_ISDIR
|
||||
|
||||
---
|
||||
src/file.h | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/src/file.h b/src/file.h
|
||||
index 0332506..4aa9f60 100644
|
||||
--- a/src/file.h
|
||||
+++ b/src/file.h
|
||||
@@ -88,6 +88,7 @@
|
||||
/* Do this here and now, because struct stat gets re-defined on solaris */
|
||||
#include <sys/stat.h>
|
||||
#include <stdarg.h>
|
||||
+#include <dirent.h>
|
||||
|
||||
#define ENABLE_CONDITIONALS
|
||||
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
From b20c8e62851f3cb53083a3e7811518092f98dc26 Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sat, 8 May 2021 22:47:32 +0700
|
||||
Subject: [PATCH 06/14] Remove/Wrap POSIX headers
|
||||
|
||||
---
|
||||
src/buffer.c | 2 ++
|
||||
src/cdf.c | 2 ++
|
||||
src/dprintf.c | 2 ++
|
||||
src/file.c | 1 -
|
||||
src/getline.c | 2 ++
|
||||
src/is_csv.c | 2 ++
|
||||
src/is_json.c | 2 ++
|
||||
src/magic.c | 2 ++
|
||||
src/memtest.c | 2 ++
|
||||
src/mygetopt.h | 2 ++
|
||||
src/pread.c | 2 ++
|
||||
src/readcdf.c | 2 ++
|
||||
12 files changed, 22 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/buffer.c b/src/buffer.c
|
||||
index 227015a..f3d8efa 100644
|
||||
--- a/src/buffer.c
|
||||
+++ b/src/buffer.c
|
||||
@@ -31,7 +31,9 @@ FILE_RCSID("@(#)$File: buffer.c,v 1.8 2020/02/16 15:52:49 christos Exp $")
|
||||
#endif /* lint */
|
||||
|
||||
#include "magic.h"
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
diff --git a/src/cdf.c b/src/cdf.c
|
||||
index bb81d63..dc9ec56 100644
|
||||
--- a/src/cdf.c
|
||||
+++ b/src/cdf.c
|
||||
@@ -43,7 +43,9 @@ FILE_RCSID("@(#)$File: cdf.c,v 1.116 2019/08/26 14:31:39 christos Exp $")
|
||||
#include <err.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
diff --git a/src/dprintf.c b/src/dprintf.c
|
||||
index 027a64f..873c547 100644
|
||||
--- a/src/dprintf.c
|
||||
+++ b/src/dprintf.c
|
||||
@@ -32,7 +32,9 @@ FILE_RCSID("@(#)$File: dprintf.c,v 1.2 2018/09/09 20:33:28 christos Exp $")
|
||||
#endif /* lint */
|
||||
|
||||
#include <assert.h>
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
diff --git a/src/file.c b/src/file.c
|
||||
index 87b9ab1..2889f8a 100644
|
||||
--- a/src/file.c
|
||||
+++ b/src/file.c
|
||||
@@ -38,7 +38,6 @@ FILE_RCSID("@(#)$File: file.c,v 1.189 2021/02/05 21:33:49 christos Exp $")
|
||||
#include "magic.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
-#include <unistd.h>
|
||||
#include <string.h>
|
||||
#ifdef RESTORE_TIME
|
||||
# if (__COHERENT__ >= 0x420)
|
||||
diff --git a/src/getline.c b/src/getline.c
|
||||
index b00de01..c2d41ca 100644
|
||||
--- a/src/getline.c
|
||||
+++ b/src/getline.c
|
||||
@@ -33,7 +33,9 @@
|
||||
#if !HAVE_GETLINE
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
diff --git a/src/is_csv.c b/src/is_csv.c
|
||||
index 937ab5f..2f704c5 100644
|
||||
--- a/src/is_csv.c
|
||||
+++ b/src/is_csv.c
|
||||
@@ -166,7 +166,9 @@ file_is_csv(struct magic_set *ms, const struct buffer *b, int looks_text)
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <err.h>
|
||||
diff --git a/src/is_json.c b/src/is_json.c
|
||||
index 0b12438..997a276 100644
|
||||
--- a/src/is_json.c
|
||||
+++ b/src/is_json.c
|
||||
@@ -436,7 +436,9 @@ file_is_json(struct magic_set *ms, const struct buffer *b)
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <err.h>
|
||||
diff --git a/src/magic.c b/src/magic.c
|
||||
index 81a0840..e9aeafa 100644
|
||||
--- a/src/magic.c
|
||||
+++ b/src/magic.c
|
||||
@@ -39,7 +39,9 @@ FILE_RCSID("@(#)$File: magic.c,v 1.114 2021/02/05 21:33:49 christos Exp $")
|
||||
#include "magic.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <string.h>
|
||||
#ifdef QUICK
|
||||
#include <sys/mman.h>
|
||||
diff --git a/src/memtest.c b/src/memtest.c
|
||||
index f9506f6..ea50242 100644
|
||||
--- a/src/memtest.c
|
||||
+++ b/src/memtest.c
|
||||
@@ -34,7 +34,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <dlfcn.h>
|
||||
#include <magic.h>
|
||||
|
||||
diff --git a/src/mygetopt.h b/src/mygetopt.h
|
||||
index d766762..b8e044c 100644
|
||||
--- a/src/mygetopt.h
|
||||
+++ b/src/mygetopt.h
|
||||
@@ -39,7 +39,9 @@
|
||||
#ifndef _GETOPT_H_
|
||||
#define _GETOPT_H_
|
||||
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
|
||||
/*
|
||||
* Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions
|
||||
diff --git a/src/pread.c b/src/pread.c
|
||||
index 3ab52d1..fc48d84 100644
|
||||
--- a/src/pread.c
|
||||
+++ b/src/pread.c
|
||||
@@ -3,7 +3,9 @@
|
||||
FILE_RCSID("@(#)$File: pread.c,v 1.2 2013/04/02 16:23:07 christos Exp $")
|
||||
#endif /* lint */
|
||||
#include <fcntl.h>
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
|
||||
ssize_t
|
||||
pread(int fd, void *buf, size_t len, off_t off) {
|
||||
diff --git a/src/readcdf.c b/src/readcdf.c
|
||||
index 7622c7b..977cb75 100644
|
||||
--- a/src/readcdf.c
|
||||
+++ b/src/readcdf.c
|
||||
@@ -31,7 +31,9 @@ FILE_RCSID("@(#)$File: readcdf.c,v 1.74 2019/09/11 15:46:30 christos Exp $")
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
+#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
+#endif
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
From 1106d1523ed44bcbcca90fc1fe9fa9400777d8fe Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sun, 9 May 2021 10:28:49 +0700
|
||||
Subject: [PATCH 07/14] Substitute unistd macros for MSVC
|
||||
|
||||
---
|
||||
src/file.h | 7 +++++++
|
||||
1 file changed, 7 insertions(+)
|
||||
|
||||
diff --git a/src/file.h b/src/file.h
|
||||
index 4aa9f60..5da838c 100644
|
||||
--- a/src/file.h
|
||||
+++ b/src/file.h
|
||||
@@ -85,6 +85,13 @@
|
||||
#ifndef _WIN32
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
+#ifdef _MSC_VER
|
||||
+#include <io.h>
|
||||
+#define R_OK 4
|
||||
+#define W_OK 2
|
||||
+#define X_OK R_OK
|
||||
+#define F_OK 0
|
||||
+#endif
|
||||
/* Do this here and now, because struct stat gets re-defined on solaris */
|
||||
#include <sys/stat.h>
|
||||
#include <stdarg.h>
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
From e449e3fb47aee00f0d82782183cc7fd6b446d27b Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sun, 9 May 2021 13:24:42 +0700
|
||||
Subject: [PATCH 08/14] Add FILENO defines
|
||||
|
||||
---
|
||||
src/file.h | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/src/file.h b/src/file.h
|
||||
index 5da838c..ccfe0da 100644
|
||||
--- a/src/file.h
|
||||
+++ b/src/file.h
|
||||
@@ -91,6 +91,9 @@
|
||||
#define W_OK 2
|
||||
#define X_OK R_OK
|
||||
#define F_OK 0
|
||||
+#define STDIN_FILENO _fileno(stdin)
|
||||
+#define STDOUT_FILENO _fileno(stdout)
|
||||
+#define STDERR_FILENO _fileno(stderr)
|
||||
#endif
|
||||
/* Do this here and now, because struct stat gets re-defined on solaris */
|
||||
#include <sys/stat.h>
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
From 6d10bef865b69764f6e0ddd2b0f6a84e484cdb37 Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sun, 9 May 2021 13:25:14 +0700
|
||||
Subject: [PATCH 09/14] No fcntl in magic.c
|
||||
|
||||
---
|
||||
src/magic.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/magic.c b/src/magic.c
|
||||
index e9aeafa..382bd96 100644
|
||||
--- a/src/magic.c
|
||||
+++ b/src/magic.c
|
||||
@@ -462,7 +462,7 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
|
||||
rv = 0;
|
||||
goto done;
|
||||
}
|
||||
-#if O_CLOEXEC == 0
|
||||
+#if O_CLOEXEC == 0 && !defined(_WIN32)
|
||||
(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
#endif
|
||||
}
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
From a6bc98ce25cd9d9dba896e93ed441ff162f6793b Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sun, 9 May 2021 17:43:20 +0700
|
||||
Subject: [PATCH 10/14] Properly check for the presence of bitmasks
|
||||
|
||||
---
|
||||
src/fsmagic.c | 24 ++++++++++++------------
|
||||
1 file changed, 12 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/src/fsmagic.c b/src/fsmagic.c
|
||||
index 5204f20..7244841 100644
|
||||
--- a/src/fsmagic.c
|
||||
+++ b/src/fsmagic.c
|
||||
@@ -66,7 +66,7 @@ FILE_RCSID("@(#)$File: fsmagic.c,v 1.81 2019/07/16 13:30:32 christos Exp $")
|
||||
# define minor(dev) ((dev) & 0xff)
|
||||
#endif
|
||||
#undef HAVE_MAJOR
|
||||
-#ifdef S_IFLNK
|
||||
+#if S_IFLNK != 0
|
||||
private int
|
||||
bad_link(struct magic_set *ms, int err, char *buf)
|
||||
{
|
||||
@@ -108,7 +108,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
|
||||
int ret, did = 0;
|
||||
int mime = ms->flags & MAGIC_MIME;
|
||||
int silent = ms->flags & (MAGIC_APPLE|MAGIC_EXTENSION);
|
||||
-#ifdef S_IFLNK
|
||||
+#if S_IFLNK != 0
|
||||
char buf[BUFSIZ+4];
|
||||
ssize_t nch;
|
||||
struct stat tstatbuf;
|
||||
@@ -122,7 +122,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
|
||||
* Fstat is cheaper but fails for files you don't have read perms on.
|
||||
* On 4.2BSD and similar systems, use lstat() to identify symlinks.
|
||||
*/
|
||||
-#ifdef S_IFLNK
|
||||
+#if S_IFLNK != 0
|
||||
if ((ms->flags & MAGIC_SYMLINK) == 0)
|
||||
ret = lstat(fn, sb);
|
||||
else
|
||||
@@ -171,17 +171,17 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
|
||||
|
||||
ret = 1;
|
||||
if (!mime && !silent) {
|
||||
-#ifdef S_ISUID
|
||||
+#if S_ISUID != 0
|
||||
if (sb->st_mode & S_ISUID)
|
||||
if (file_printf(ms, "%ssetuid", COMMA) == -1)
|
||||
return -1;
|
||||
#endif
|
||||
-#ifdef S_ISGID
|
||||
+#if S_ISGID != 0
|
||||
if (sb->st_mode & S_ISGID)
|
||||
if (file_printf(ms, "%ssetgid", COMMA) == -1)
|
||||
return -1;
|
||||
#endif
|
||||
-#ifdef S_ISVTX
|
||||
+#if S_ISVTX != 0
|
||||
if (sb->st_mode & S_ISVTX)
|
||||
if (file_printf(ms, "%ssticky", COMMA) == -1)
|
||||
return -1;
|
||||
@@ -197,7 +197,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
|
||||
} else if (file_printf(ms, "%sdirectory", COMMA) == -1)
|
||||
return -1;
|
||||
break;
|
||||
-#ifdef S_IFCHR
|
||||
+#if S_IFCHR != 0
|
||||
case S_IFCHR:
|
||||
/*
|
||||
* If -s has been specified, treat character special files
|
||||
@@ -232,7 +232,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
-#ifdef S_IFBLK
|
||||
+#if S_IFBLK != 0
|
||||
case S_IFBLK:
|
||||
/*
|
||||
* If -s has been specified, treat block special files
|
||||
@@ -268,7 +268,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
|
||||
break;
|
||||
#endif
|
||||
/* TODO add code to handle V7 MUX and Blit MUX files */
|
||||
-#ifdef S_IFIFO
|
||||
+#if S_IFIFO != 0
|
||||
case S_IFIFO:
|
||||
if((ms->flags & MAGIC_DEVICES) != 0)
|
||||
break;
|
||||
@@ -280,7 +280,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
|
||||
return -1;
|
||||
break;
|
||||
#endif
|
||||
-#ifdef S_IFDOOR
|
||||
+#if S_IFDOOR != 0
|
||||
case S_IFDOOR:
|
||||
if (mime) {
|
||||
if (handle_mime(ms, mime, "door") == -1)
|
||||
@@ -290,7 +290,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
|
||||
return -1;
|
||||
break;
|
||||
#endif
|
||||
-#ifdef S_IFLNK
|
||||
+#if S_IFLNK != 0
|
||||
case S_IFLNK:
|
||||
if ((nch = readlink(fn, buf, BUFSIZ-1)) <= 0) {
|
||||
if (ms->flags & MAGIC_ERROR) {
|
||||
@@ -378,7 +378,7 @@ file_fsmagic(struct magic_set *ms, const char *fn, struct stat *sb)
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
-#ifdef S_IFSOCK
|
||||
+#if S_IFSOCK != 0
|
||||
#ifndef __COHERENT__
|
||||
case S_IFSOCK:
|
||||
if (mime) {
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
From 15b0f505ff9eefd41b74ffdd4230355e933263ca Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Sun, 9 May 2021 17:45:50 +0700
|
||||
Subject: [PATCH 11/14] Remove pipe related functions in funcs.c
|
||||
|
||||
---
|
||||
src/funcs.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/src/funcs.c b/src/funcs.c
|
||||
index b926625..b585486 100644
|
||||
--- a/src/funcs.c
|
||||
+++ b/src/funcs.c
|
||||
@@ -809,6 +809,7 @@ file_print_guid(char *str, size_t len, const uint64_t *guid)
|
||||
g->data4[6], g->data4[7]);
|
||||
}
|
||||
|
||||
+#ifndef _WIN32
|
||||
protected int
|
||||
file_pipe_closexec(int *fds)
|
||||
{
|
||||
@@ -827,6 +828,7 @@ protected int
|
||||
file_clear_closexec(int fd) {
|
||||
return fcntl(fd, F_SETFD, 0);
|
||||
}
|
||||
+#endif
|
||||
|
||||
protected char *
|
||||
file_strtrim(char *str)
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
From f0139ced57c1579450f3d09b6e3ae0159aae031b Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Mon, 10 May 2021 08:43:28 +0700
|
||||
Subject: [PATCH 12/14] Convert MSYS2 paths to Windows paths
|
||||
|
||||
---
|
||||
src/Makefile.am | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/src/Makefile.am b/src/Makefile.am
|
||||
index 34781b9..26f853f 100644
|
||||
--- a/src/Makefile.am
|
||||
+++ b/src/Makefile.am
|
||||
@@ -1,4 +1,7 @@
|
||||
MAGIC = $(pkgdatadir)/magic
|
||||
+if MINGW
|
||||
+MAGIC != cygpath -m -a -l '$(MAGIC)'
|
||||
+endif
|
||||
lib_LTLIBRARIES = libmagic.la
|
||||
nodist_include_HEADERS = magic.h
|
||||
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
From 3f10c7d31627b64b068b84ba72e706991f672560 Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Fri, 14 May 2021 08:14:05 +0700
|
||||
Subject: [PATCH 13/14] Check for backslash in argv[0] on Windows
|
||||
|
||||
---
|
||||
magic/Makefile.am | 2 +-
|
||||
src/file.c | 5 +++++
|
||||
2 files changed, 6 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/magic/Makefile.am b/magic/Makefile.am
|
||||
index 0eb5865..170bbab 100644
|
||||
--- a/magic/Makefile.am
|
||||
+++ b/magic/Makefile.am
|
||||
@@ -353,7 +353,7 @@ ${MAGIC}: $(EXTRA_DIST) $(FILE_COMPILE_DEP)
|
||||
@(if expr "${FILE_COMPILE}" : '.*/.*' > /dev/null; then \
|
||||
echo "Using ${FILE_COMPILE} to generate ${MAGIC}" > /dev/null; \
|
||||
else \
|
||||
- v=$$(${FILE_COMPILE} --version | sed -e s/file-// -e q); \
|
||||
+ v=$$(${FILE_COMPILE} --version | sed -e s/file${EXEEXT}-// -e q); \
|
||||
if [ "$$v" != "${PACKAGE_VERSION}" ]; then \
|
||||
echo "Cannot use the installed version of file ($$v) to"; \
|
||||
echo "cross-compile file ${PACKAGE_VERSION}"; \
|
||||
diff --git a/src/file.c b/src/file.c
|
||||
index 2889f8a..12a604b 100644
|
||||
--- a/src/file.c
|
||||
+++ b/src/file.c
|
||||
@@ -200,6 +200,11 @@ main(int argc, char *argv[])
|
||||
_wildcard(&argc, &argv);
|
||||
#endif
|
||||
|
||||
+#ifdef _WIN32
|
||||
+ if ((progname = strrchr(argv[0], '\\')) != NULL)
|
||||
+ progname++;
|
||||
+ else
|
||||
+#endif
|
||||
if ((progname = strrchr(argv[0], '/')) != NULL)
|
||||
progname++;
|
||||
else
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
From fa0e11f36bb0e322250e1e488ced9f2bf166874f Mon Sep 17 00:00:00 2001
|
||||
From: Long Nguyen <nguyen.long.908132@gmail.com>
|
||||
Date: Fri, 14 May 2021 18:11:39 +0700
|
||||
Subject: [PATCH 14/14] Define POSIX macros if missing
|
||||
|
||||
---
|
||||
src/file.h | 15 +++++++++++++++
|
||||
1 file changed, 15 insertions(+)
|
||||
|
||||
diff --git a/src/file.h b/src/file.h
|
||||
index ccfe0da..98cd37b 100644
|
||||
--- a/src/file.h
|
||||
+++ b/src/file.h
|
||||
@@ -100,6 +100,21 @@
|
||||
#include <stdarg.h>
|
||||
#include <dirent.h>
|
||||
|
||||
+#if !defined(S_IFBLK)
|
||||
+#define S_IFBLK 0
|
||||
+#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
|
||||
+#endif
|
||||
+
|
||||
+#if !defined(S_IFLNK)
|
||||
+#define S_IFLNK 0
|
||||
+#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
|
||||
+#endif
|
||||
+
|
||||
+#if !defined(S_IFSOCK)
|
||||
+#define S_IFSOCK 0
|
||||
+#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
|
||||
+#endif
|
||||
+
|
||||
#define ENABLE_CONDITIONALS
|
||||
|
||||
#ifndef MAGIC
|
||||
--
|
||||
2.29.2.windows.2
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
# From https://github.com/msys2/MINGW-packages/commit/3a51faadb8bacf06c7b7fd84b2ea80775d1a8b0d
|
||||
|
||||
# this is an advanced patch to fix building v5.38
|
||||
# see for details
|
||||
# this patch should be removed with the next version
|
||||
diff --git a/src/compress.c b/src/compress.c
|
||||
index 33ce2bc..f172eda 100644
|
||||
--- a/src/compress.c
|
||||
+++ b/src/compress.c
|
||||
@@ -378,7 +378,7 @@
|
||||
sread(int fd, void *buf, size_t n, int canbepipe __attribute__((__unused__)))
|
||||
{
|
||||
ssize_t rv;
|
||||
-#ifdef FIONREAD
|
||||
+#if defined(FIONREAD) && !defined(__MINGW32__) && !defined(WIN32)
|
||||
int t = 0;
|
||||
#endif
|
||||
size_t rn = n;
|
||||
@@ -386,7 +386,7 @@
|
||||
if (fd == STDIN_FILENO)
|
||||
goto nocheck;
|
||||
|
||||
-#ifdef FIONREAD
|
||||
+#if defined(FIONREAD) && !defined(__MINGW32__) && !defined(WIN32)
|
||||
if (canbepipe && (ioctl(fd, FIONREAD, &t) == -1 || t == 0)) {
|
||||
#ifdef FD_ZERO
|
||||
ssize_t cnt;
|
|
@ -1,5 +0,0 @@
|
|||
Source: libmagic
|
||||
Version: 5.37
|
||||
Port-Version: 2
|
||||
Homepage: https://github.com/file/file
|
||||
Description: This library can be used to classify files according to magic number tests.
|
|
@ -1,22 +1,67 @@
|
|||
if(VCPKG_TARGET_IS_WINDOWS)
|
||||
set(PATCHES
|
||||
"0001-Use-libtre.patch"
|
||||
"0002-Change-zlib-lib-name-to-match-CMake-output.patch"
|
||||
"0003-Fix-WIN32-macro-checks.patch"
|
||||
"0004-Typedef-POSIX-types-on-Windows.patch"
|
||||
"0005-Include-dirent.h-for-S_ISREG-and-S_ISDIR.patch"
|
||||
"0006-Remove-Wrap-POSIX-headers.patch"
|
||||
"0007-Substitute-unistd-macros-for-MSVC.patch"
|
||||
"0008-Add-FILENO-defines.patch"
|
||||
"0009-No-fcntl-in-magic.c.patch"
|
||||
"0010-Properly-check-for-the-presence-of-bitmasks.patch"
|
||||
"0011-Remove-pipe-related-functions-in-funcs.c.patch"
|
||||
"0012-Convert-MSYS2-paths-to-Windows-paths.patch"
|
||||
"0013-Check-for-backslash-in-argv-0-on-Windows.patch"
|
||||
"0014-Define-POSIX-macros-if-missing.patch"
|
||||
"0015-MSYS2-Remove-ioctl-call.patch"
|
||||
)
|
||||
endif()
|
||||
|
||||
vcpkg_from_github(
|
||||
OUT_SOURCE_PATH SOURCE_PATH
|
||||
REPO file/file
|
||||
REF a0d5b0e4e9f97d74a9911e95cedd579852e25398
|
||||
SHA512 bd20a7f3a3117da10556a1f746f691d2e26b23b30cb70a6c08e05110eb415d457b82265dd910a7b05fc30bc34ba9019a33b1c59a34d844c14c2df7ba1eea060e
|
||||
HEAD_REF mater
|
||||
REF FILE5_40
|
||||
SHA512 d76bfe5326e1b40368e055c2e049a24b4ffdbd727371f4f3aa1dd3f53787d16b88550b3cc71ecf02151e2fb3e567eb2598e4707badab8c391eb71113c2dcc319
|
||||
HEAD_REF master
|
||||
PATCHES ${PATCHES}
|
||||
)
|
||||
|
||||
if(VCPKG_TARGET_IS_WINDOWS)
|
||||
set(VCPKG_C_FLAGS "${VCPKG_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS")
|
||||
set(VCPKG_CXX_FLAGS "${VCPKG_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS")
|
||||
endif()
|
||||
|
||||
vcpkg_configure_make(
|
||||
AUTOCONFIG
|
||||
SOURCE_PATH ${SOURCE_PATH}
|
||||
)
|
||||
vcpkg_install_make()
|
||||
vcpkg_copy_pdbs()
|
||||
|
||||
if(VCPKG_CROSSCOMPILING)
|
||||
vcpkg_add_to_path(PREPEND ${CURRENT_HOST_INSTALLED_DIR}/tools/libmagic/bin)
|
||||
elseif(VCPKG_TARGET_IS_WINDOWS AND VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
|
||||
set(EXTRA_ARGS "ADD_BIN_TO_PATH")
|
||||
endif()
|
||||
|
||||
vcpkg_install_make(${EXTRA_ARGS})
|
||||
vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT}/bin)
|
||||
vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug/bin)
|
||||
|
||||
if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
|
||||
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin)
|
||||
endif()
|
||||
|
||||
if(VCPKG_TARGET_IS_WINDOWS)
|
||||
if(NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
|
||||
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/tools/${PORT}/share/misc)
|
||||
file(COPY ${CURRENT_PACKAGES_DIR}/share/${PORT}/misc/magic.mgc DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT}/share/misc)
|
||||
endif()
|
||||
if(NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
|
||||
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug/share/misc)
|
||||
file(COPY ${CURRENT_PACKAGES_DIR}/share/${PORT}/misc/magic.mgc DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug/share/misc)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
|
||||
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
|
||||
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/share/${PORT}/man5)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "libmagic",
|
||||
"version-string": "5.40",
|
||||
"description": "This library can be used to classify files according to magic number tests.",
|
||||
"homepage": "https://github.com/file/file",
|
||||
"dependencies": [
|
||||
{
|
||||
"name": "dirent",
|
||||
"platform": "windows"
|
||||
},
|
||||
{
|
||||
"name": "getopt",
|
||||
"platform": "windows"
|
||||
},
|
||||
{
|
||||
"name": "libmagic",
|
||||
"host": true
|
||||
},
|
||||
{
|
||||
"name": "tre",
|
||||
"platform": "windows | mingw"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
Source: tre
|
||||
Version: 0.8.0-1
|
||||
Version: 0.8.0
|
||||
Port-Version: 2
|
||||
Homepage: https://github.com/laurikari/tre
|
||||
Description: TRE is a lightweight, robust, and efficient POSIX compliant regexp matching library with some exciting features such as approximate (fuzzy) matching.
|
||||
|
|
|
@ -10,6 +10,10 @@ file(READ ${SOURCE_PATH}/win32/config.h CONFIG_H)
|
|||
string(REPLACE "#define snprintf sprintf_s" "" CONFIG_H ${CONFIG_H})
|
||||
file(WRITE ${SOURCE_PATH}/win32/config.h "${CONFIG_H}")
|
||||
|
||||
if(VCPKG_TARGET_IS_MINGW)
|
||||
vcpkg_replace_string(${SOURCE_PATH}/win32/tre.def "tre.dll" "libtre.dll")
|
||||
endif()
|
||||
|
||||
file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})
|
||||
|
||||
vcpkg_configure_cmake(
|
||||
|
|
|
@ -643,8 +643,6 @@ liblsl:arm-uwp=fail
|
|||
liblsl:x64-uwp=fail
|
||||
libmad:arm-uwp=fail
|
||||
libmad:x64-uwp=fail
|
||||
libmagic:x86-windows=fail
|
||||
libmagic:x64-windows=fail
|
||||
libmagic:x64-windows-static=fail
|
||||
libmagic:x64-windows-static-md=fail
|
||||
libmagic:x64-uwp=fail
|
||||
|
|
|
@ -3273,8 +3273,8 @@
|
|||
"port-version": 0
|
||||
},
|
||||
"libmagic": {
|
||||
"baseline": "5.37",
|
||||
"port-version": 2
|
||||
"baseline": "5.40",
|
||||
"port-version": 0
|
||||
},
|
||||
"libmariadb": {
|
||||
"baseline": "3.1.12",
|
||||
|
@ -6177,8 +6177,8 @@
|
|||
"port-version": 0
|
||||
},
|
||||
"tre": {
|
||||
"baseline": "0.8.0-1",
|
||||
"port-version": 0
|
||||
"baseline": "0.8.0",
|
||||
"port-version": 2
|
||||
},
|
||||
"treehopper": {
|
||||
"baseline": "1.11.3-4",
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
{
|
||||
"versions": [
|
||||
{
|
||||
"git-tree": "0645b6d33816b293de3dae3b84828b97d06bd0ea",
|
||||
"version-string": "5.40",
|
||||
"port-version": 0
|
||||
},
|
||||
{
|
||||
"git-tree": "65fc18d3b2ed34a290f7774c58e480e7d06bebe3",
|
||||
"version-string": "5.37",
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
{
|
||||
"versions": [
|
||||
{
|
||||
"git-tree": "c6f1211065eff34d7d62934884cfbfe20af3c446",
|
||||
"version-string": "0.8.0",
|
||||
"port-version": 2
|
||||
},
|
||||
{
|
||||
"git-tree": "7a1459b0be7679facdc6a9afc15b1531c5f61440",
|
||||
"version-string": "0.8.0-1",
|
||||
|
|
Загрузка…
Ссылка в новой задаче