This file is part of MXE. See LICENSE.md for licensing information. Contains ad hoc patches for cross building. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001From: Jonas Kvinge <jonas@jkvinge.net>Date: Thu, 1 Apr 2021 03:41:56 +0200Subject: [PATCH 1/1] Remove use of fcntl F_SETFD for WIN32 diff --git a/src/compress.c b/src/compress.cindex 1111111..2222222 100644--- a/src/compress.c+++ b/src/compress.c@@ -924,9 +924,14 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old, * and both must have large outputs. Thus it happens not that often). * To avoid this, be sure to create pipes with O_CLOEXEC. */+#ifdef WIN32+ if ((fd == -1 && pipe(fdp[STDIN_FILENO]) == -1) ||+ pipe(fdp[STDOUT_FILENO]) == -1 || pipe(fdp[STDERR_FILENO]) == -1) {+#else if ((fd == -1 && file_pipe_closexec(fdp[STDIN_FILENO]) == -1) || file_pipe_closexec(fdp[STDOUT_FILENO]) == -1 || file_pipe_closexec(fdp[STDERR_FILENO]) == -1) {+#endif closep(fdp[STDIN_FILENO]); closep(fdp[STDOUT_FILENO]); return makeerror(newch, n, "Cannot create pipe, %s",diff --git a/src/file.h b/src/file.hindex 1111111..2222222 100644--- a/src/file.h+++ b/src/file.h@@ -581,8 +581,10 @@ public char * file_printable(struct magic_set *, char *, size_t, protected int file_os2_apptype(struct magic_set *, const char *, const void *, size_t); #endif /* __EMX__ */+#ifndef WIN32 protected int file_pipe_closexec(int *); protected int file_clear_closexec(int);+#endif protected char *file_strtrim(char *); protected void buffer_init(struct buffer *, int, const struct stat *,diff --git a/src/funcs.c b/src/funcs.cindex 1111111..2222222 100644--- a/src/funcs.c+++ b/src/funcs.c@@ -840,6 +840,7 @@ file_print_guid(char *str, size_t len, const uint64_t *guid) #endif } +#ifndef WIN32 protected int file_pipe_closexec(int *fds) {@@ -864,6 +865,7 @@ file_clear_closexec(int fd) { return 0; #endif }+#endif protected char * file_strtrim(char *str)diff --git a/src/magic.c b/src/magic.cindex 1111111..2222222 100644--- a/src/magic.c+++ b/src/magic.c@@ -478,7 +478,9 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd) goto done; } #if O_CLOEXEC == 0 && defined(F_SETFD)+#ifndef WIN32 (void)fcntl(fd, F_SETFD, FD_CLOEXEC);+#endif #endif }
This file is part of MXE. See LICENSE.md for licensing information.
Contains ad hoc patches for cross building.
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jonas Kvinge <jonas@jkvinge.net>
Date: Thu, 1 Apr 2021 03:41:56 +0200
Subject: [PATCH 1/1] Remove use of fcntl F_SETFD for WIN32
diff --git a/src/compress.c b/src/compress.c
index 1111111..2222222 100644
--- a/src/compress.c
+++ b/src/compress.c
@@ -924,9 +924,14 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
* and both must have large outputs. Thus it happens not that often).
* To avoid this, be sure to create pipes with O_CLOEXEC.
*/
+#ifdef WIN32
+ if ((fd == -1 && pipe(fdp[STDIN_FILENO]) == -1) ||
+ pipe(fdp[STDOUT_FILENO]) == -1 || pipe(fdp[STDERR_FILENO]) == -1) {
+#else
if ((fd == -1 && file_pipe_closexec(fdp[STDIN_FILENO]) == -1) ||
file_pipe_closexec(fdp[STDOUT_FILENO]) == -1 ||
file_pipe_closexec(fdp[STDERR_FILENO]) == -1) {
+#endif
closep(fdp[STDIN_FILENO]);
closep(fdp[STDOUT_FILENO]);
return makeerror(newch, n, "Cannot create pipe, %s",
diff --git a/src/file.h b/src/file.h
index 1111111..2222222 100644
--- a/src/file.h
+++ b/src/file.h
@@ -581,8 +581,10 @@ public char * file_printable(struct magic_set *, char *, size_t,
protected int file_os2_apptype(struct magic_set *, const char *, const void *,
size_t);
#endif /* __EMX__ */
+#ifndef WIN32
protected int file_pipe_closexec(int *);
protected int file_clear_closexec(int);
+#endif
protected char *file_strtrim(char *);
protected void buffer_init(struct buffer *, int, const struct stat *,
diff --git a/src/funcs.c b/src/funcs.c
index 1111111..2222222 100644
--- a/src/funcs.c
+++ b/src/funcs.c
@@ -840,6 +840,7 @@ file_print_guid(char *str, size_t len, const uint64_t *guid)
#endif
}
+#ifndef WIN32
protected int
file_pipe_closexec(int *fds)
{
@@ -864,6 +865,7 @@ file_clear_closexec(int fd) {
return 0;
#endif
}
+#endif
protected char *
file_strtrim(char *str)
diff --git a/src/magic.c b/src/magic.c
index 1111111..2222222 100644
--- a/src/magic.c
+++ b/src/magic.c
@@ -478,7 +478,9 @@ file_or_fd(struct magic_set *ms, const char *inname, int fd)
goto done;
}
#if O_CLOEXEC == 0 && defined(F_SETFD)
+#ifndef WIN32
(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
#endif
}