View Issue Details

IDProjectCategoryView StatusLast Update
0000255file[All Projects] Generalpublic2021-04-19 16:51
ReporterjovelerAssigned Tochristos 
PriorityhighSeverityblockReproducibilityalways
Status feedbackResolutionopen 
Product Version5.40 
Target VersionFixed in Version 
Summary0000255: file 5.40 compile error on MinGW/MSYS2
Descriptionfile 5.40 cannot be compiled on MinGW/MSYS2, due to ioctl / fnctl calls.

[*] fnctl calls
In funcs.c and magic.c, file calls fcntl with F_SETFD.

fcntl(fds[1], F_SETFD, FD_CLOEXEC);

MinGW does not support F_SETFD, thus fails to compile the code.

[*] ioctl calls
This issue had been already described in 0000163 (https://bugs.astron.com/view.php?id=163).

MinGW does not support ioctl call and produce compile error.

If the library is configured with `--disable-xzlib --disable-bzlib`, the code is excluded and does not block the build.

[*] Solution
I attached the diff file which excludes these code paths on MinGW build.
Tagsbuild, patch

Activities

joveler

2021-04-02 04:49

reporter  

MinGW_ioctl_fix.diff (648 bytes)
diff --git a/src/compress.c b/src/compress.c
index 9f65e4fa..6b3b1b95 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -380,7 +380,7 @@ protected ssize_t
 sread(int fd, void *buf, size_t n, int canbepipe __attribute__((__unused__)))
 {
 	ssize_t rv;
-#ifdef FIONREAD
+#if defined(FIONREAD) && !defined(WIN32)
 	int t = 0;
 #endif
 	size_t rn = n;
@@ -388,7 +388,7 @@ sread(int fd, void *buf, size_t n, int canbepipe __attribute__((__unused__)))
 	if (fd == STDIN_FILENO)
 		goto nocheck;
 
-#ifdef FIONREAD
+#if defined(FIONREAD) && !defined(WIN32)
 	if (canbepipe && (ioctl(fd, FIONREAD, &t) == -1 || t == 0)) {
 #ifdef FD_ZERO
 		ssize_t cnt;
MinGW_ioctl_fix.diff (648 bytes)
MinGW_fnctl_fix.diff (1,055 bytes)
diff --git a/src/funcs.c b/src/funcs.c
index b926625d..642fd3ac 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -812,6 +812,10 @@ file_print_guid(char *str, size_t len, const uint64_t *guid)
 protected int
 file_pipe_closexec(int *fds)
 {
+#ifdef WIN32
+	// F_SETFD is not supported on Windows
+	return 0;
+#else
 #ifdef HAVE_PIPE2
 	return pipe2(fds, O_CLOEXEC);
 #else
@@ -821,11 +825,17 @@ file_pipe_closexec(int *fds)
 	(void)fcntl(fds[1], F_SETFD, FD_CLOEXEC);
 	return 0;
 #endif
+#endif
 }
 
 protected int
 file_clear_closexec(int fd) {
+#ifdef WIN32
+	// F_SETFD is not supported on Windows
+	return 0;
+#else
 	return fcntl(fd, F_SETFD, 0);
+#endif;
 }
 
 protected char *
diff --git a/src/magic.c b/src/magic.c
index 81a0840f..5457d359 100644
--- a/src/magic.c
+++ b/src/magic.c
@@ -460,7 +460,8 @@ 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)
+		// F_SETFD is not supported on Windows
 		(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
 #endif
 	}
MinGW_fnctl_fix.diff (1,055 bytes)

joveler

2021-04-02 11:04

reporter   ~0003581

[*] Additional info of compile environment

- Platform: Windows 10 with MSYS2
- Tested Target Arch : I686, x86_64, aarch64
- Shell: MINGW32(i686) / MINGW64(x86_64, aarch64) shell of MSYS2
- Toolchain: (1) MinGW-w64 of MSYS2 (i686/x86_64) (2) llvm-mingw (aarch64)

administrator

2021-04-19 16:51

administrator   ~0003587

Better use __MINGW32__?

Issue History

Date Modified Username Field Change
2021-04-02 04:49 joveler New Issue
2021-04-02 04:49 joveler File Added: MinGW_fnctl_fix.diff
2021-04-02 04:49 joveler File Added: MinGW_ioctl_fix.diff
2021-04-02 04:49 joveler Tag Attached: build
2021-04-02 04:49 joveler Tag Attached: patch
2021-04-02 11:04 joveler Note Added: 0003581
2021-04-19 16:50 administrator Assigned To => administrator
2021-04-19 16:50 administrator Status new => assigned
2021-04-19 16:51 administrator Assigned To administrator => christos
2021-04-19 16:51 administrator Status assigned => feedback
2021-04-19 16:51 administrator Note Added: 0003587