--- ./src/compress.c~0	2020-12-08 23:26:00.000000000 +0200
+++ ./src/compress.c	2021-10-24 16:30:31.700000000 +0300
@@ -202,7 +202,6 @@ private const struct {
 #define ERRDATA	2
 
 private ssize_t swrite(int, const void *, size_t);
-#if HAVE_FORK
 private size_t ncompr = __arraycount(compr);
 private int uncompressbuf(int, size_t, size_t, const unsigned char *,
     unsigned char **, size_t *);
@@ -254,8 +253,10 @@ file_zmagic(struct magic_set *ms, const 
 	int fd = b->fd;
 	const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
 	size_t nbytes = b->flen;
+#ifdef SIGPIPE
 	int sa_saved = 0;
 	struct sigaction sig_act;
+#endif
 
 	if ((ms->flags & MAGIC_COMPRESS) == 0)
 		return 0;
@@ -274,6 +275,7 @@ file_zmagic(struct magic_set *ms, const 
 		if (!zm)
 			continue;
 
+#ifdef SIGPIPE
 		/* Prevent SIGPIPE death if child dies unexpectedly */
 		if (!sa_saved) {
 			//We can use sig_act for both new and old, but
@@ -282,6 +284,7 @@ file_zmagic(struct magic_set *ms, const 
 			new_act.sa_handler = SIG_IGN;
 			sa_saved = sigaction(SIGPIPE, &new_act, &sig_act) != -1;
 		}
+#endif
 
 		nsz = nbytes;
 		urv = uncompressbuf(fd, ms->bytes_max, i, buf, &newbuf, &nsz);
@@ -339,15 +342,17 @@ file_zmagic(struct magic_set *ms, const 
 out:
 	DPRINTF("rv = %d\n", rv);
 
+#ifdef SIGPIPE
 	if (sa_saved && sig_act.sa_handler != SIG_IGN)
 		(void)sigaction(SIGPIPE, &sig_act, NULL);
+#endif
 
 	free(newbuf);
 	ms->flags |= MAGIC_COMPRESS;
 	DPRINTF("Zmagic returns %d\n", rv);
 	return rv;
 }
-#endif
+
 /*
  * `safe' write for sockets and pipes.
  */
@@ -380,7 +385,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(__MINGW32__)
 	int t = 0;
 #endif
 	size_t rn = n;
@@ -388,7 +393,7 @@ sread(int fd, void *buf, size_t n, int c
 	if (fd == STDIN_FILENO)
 		goto nocheck;
 
-#ifdef FIONREAD
+#if defined(FIONREAD) && !defined(__MINGW32__)
 	if (canbepipe && (ioctl(fd, FIONREAD, &t) == -1 || t == 0)) {
 #ifdef FD_ZERO
 		ssize_t cnt;
@@ -449,7 +454,21 @@ file_pipe2file(struct magic_set *ms, int
 	ssize_t r;
 	int tfd;
 
+#ifdef WIN32
+	char *t;
+	buf[0] = '\0';
+	if ((t = getenv("TEMP")) != NULL)
+		(void)strlcpy(buf, t, sizeof buf);
+	else if ((t = getenv("TMP")) != NULL)
+		(void)strlcpy(buf, t, sizeof buf);
+	else if ((t = getenv("TMPDIR")) != NULL)
+		(void)strlcpy(buf, t, sizeof buf);
+	if (buf[0] != '\0')
+		(void)strcat(buf, "/");
+	(void)strcat(buf, "file.XXXXXX");
+#else
 	(void)strlcpy(buf, "/tmp/file.XXXXXX", sizeof buf);
+#endif
 #ifndef HAVE_MKSTEMP
 	{
 		char *ptr = mktemp(buf);
@@ -510,7 +529,7 @@ file_pipe2file(struct magic_set *ms, int
 	}
 	return fd;
 }
-#if HAVE_FORK
+
 #ifdef BUILTIN_DECOMPRESS
 
 #define FHCRC		(1 << 1)
@@ -680,7 +699,6 @@ err:
 }
 #endif
 
-
 static int
 makeerror(unsigned char **buf, size_t *len, const char *fmt, ...)
 {
@@ -701,6 +719,8 @@ makeerror(unsigned char **buf, size_t *l
 	return ERRDATA;
 }
 
+#if HAVE_FORK
+
 static void
 closefd(int *fd, size_t i)
 {
@@ -784,6 +804,8 @@ filter_error(unsigned char *ubuf, ssize_
 	return n;
 }
 
+#endif	/* HAVE_FORK */
+
 private const char *
 methodname(size_t method)
 {
@@ -803,7 +825,11 @@ methodname(size_t method)
 		return "xzlib";
 #endif
 	default:
+#if HAVE_FORK
 		return compr[method].argv[0];
+#else
+		return "unsupported compression method";
+#endif
 	}
 }
 
@@ -811,12 +837,16 @@ private int
 uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
     unsigned char **newch, size_t* n)
 {
+#if HAVE_FORK
 	int fdp[3][2];
 	int status, rv, w;
 	pid_t pid;
 	pid_t writepid = -1;
 	size_t i;
 	ssize_t r;
+#else
+	fd = fd;	/* avoid compiler warning */
+#endif
 
 	switch (method) {
 #ifdef BUILTIN_DECOMPRESS
@@ -835,9 +865,14 @@ uncompressbuf(int fd, size_t bytes_max, 
 		return uncompressxzlib(old, newch, bytes_max, n);
 #endif
 	default:
+#if !HAVE_FORK
+		return makeerror(newch, n, "Cannot uncompress");
+#else
 		break;
+#endif
 	}
 
+#if HAVE_FORK
 	(void)fflush(stdout);
 	(void)fflush(stderr);
 
@@ -984,5 +1019,5 @@ wait_err:
 	DPRINTF("Returning %p n=%" SIZE_T_FORMAT "u rv=%d\n", *newch, *n, rv);
 
 	return rv;
+#endif	/* HAVE_FORK */
 }
-#endif
--- ./src/file.h~0	2021-07-03 16:49:16.000000000 +0300
+++ ./src/file.h	2021-10-24 16:12:24.918750000 +0300
@@ -509,10 +513,8 @@ protected int file_printf(struct magic_s
 protected int file_reset(struct magic_set *, int);
 protected int file_tryelf(struct magic_set *, const struct buffer *);
 protected int file_trycdf(struct magic_set *, const struct buffer *);
-#if HAVE_FORK
 protected int file_zmagic(struct magic_set *, const struct buffer *,
     const char *);
-#endif
 protected int file_ascmagic(struct magic_set *, const struct buffer *,
     int);
 protected int file_ascmagic_with_encoding(struct magic_set *,
--- ./src/funcs.c~0	2021-07-03 16:49:16.000000000 +0300
+++ ./src/funcs.c	2021-10-24 15:27:32.575000000 +0300
@@ -38,6 +38,9 @@ FILE_RCSID("@(#)$File: funcs.c,v 1.122 2
 #include <ctype.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>	/* for pipe2() */
+#ifdef WIN32
+#define pipe(fds) _pipe(fds,0,_O_BINARY)
+#endif
 #endif
 #if defined(HAVE_WCHAR_H)
 #include <wchar.h>
@@ -359,7 +362,7 @@ file_buffer(struct magic_set *ms, int fd
 		}
 	}
 #endif
-#if HAVE_FORK
+#if HAVE_FORK || ZLIBSUPPORT || BZLIBSUPPORT || XZLIBSUPPORT
 	/* try compression stuff */
 	if ((ms->flags & MAGIC_NO_CHECK_COMPRESS) == 0) {
 		m = file_zmagic(ms, &b, inname);
@@ -484,7 +487,7 @@ simple:
 		if (file_printf(ms, "%s", code_mime) == -1)
 			rv = -1;
 	}
-#if HAVE_FORK
+#if HAVE_FORK || ZLIBSUPPORT || BZLIBSUPPORT || XZLIBSUPPORT
  done_encoding:
 #endif
 	free(rbuf);
@@ -818,15 +843,21 @@ file_pipe_closexec(int *fds)
 #else
 	if (pipe(fds) == -1)
 		return -1;
+#ifdef F_SETFD
 	(void)fcntl(fds[0], F_SETFD, FD_CLOEXEC);
 	(void)fcntl(fds[1], F_SETFD, FD_CLOEXEC);
+#endif
 	return 0;
 #endif
 }
 
 protected int
-file_clear_closexec(int fd) {
+file_clear_closexec(int fd __attribute__ ((__unused__))) {
+#ifdef F_SETFD
 	return fcntl(fd, F_SETFD, 0);
+#else
+	return 0;
+#endif
 }
 
 protected char *
