--- a/backend/abaton.c
+++ b/backend/abaton.c
@@ -57,7 +57,9 @@
 
 #include <sys/time.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 
 #include "../include/_stdint.h"
 
--- a/backend/apple.c
+++ b/backend/apple.c
@@ -55,7 +55,9 @@
 
 #include <sys/time.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 
 #include "../include/_stdint.h"
 
--- a/backend/canon630u.c
+++ b/backend/canon630u.c
@@ -51,7 +51,9 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/types.h>
 
 #include "../include/sane/sane.h"
--- a/backend/canon_lide70.c
+++ b/backend/canon_lide70.c
@@ -31,7 +31,9 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 
 #include "../include/sane/sane.h"
 #include "../include/sane/sanei.h"
--- a/backend/canon_pp.c
+++ b/backend/canon_pp.c
@@ -1760,7 +1760,11 @@
 				return -1;
 			path = strdup(file);
 			*(path + (tmp-file)) = '\0';
+#ifndef _WIN32
 			i = mkdir(path, 0777);
+#else
+			i = mkdir(path);
+#endif
 			free(path);
 			if (i) return -1;
 			/* Path has been created, now try this again.. */
--- a/backend/dell1600n_net.c
+++ b/backend/dell1600n_net.c
@@ -64,10 +64,16 @@
 
 /* :NOTE: these are likely to be platform-specific! */
 #include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
 #include <sys/time.h>
+#ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
 #include <netdb.h>
+#endif
 
 #include <jpeglib.h>
 #include <tiffio.h>
--- a/backend/epson.h
+++ b/backend/epson.h
@@ -51,7 +51,9 @@
 #ifndef epson_h
 #define epson_h
 
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 
 #include <sys/types.h>
 
--- a/backend/epsonds.c
+++ b/backend/epsonds.c
@@ -48,7 +48,9 @@
 # include <sys/time.h>
 #endif
 #include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
 #include <unistd.h>
 #include <math.h>
 
--- a/backend/hp4200.c
+++ b/backend/hp4200.c
@@ -50,7 +50,9 @@
 
 #include "../include/sane/config.h"
 
+#ifdef HAVE_NETINET_IN_H
 #include <sys/ioctl.h>
+#endif
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
--- a/backend/hp5400_internal.c
+++ b/backend/hp5400_internal.c
@@ -59,7 +59,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <math.h>
+#ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>		/* for htons */
+#endif
 #include <string.h>
 
 
--- a/backend/hpljm1005.c
+++ b/backend/hpljm1005.c
@@ -57,7 +57,9 @@
 #include  <unistd.h>
 #include  <errno.h>
 #include  <stdint.h>
+#ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
+#endif
 #define  BACKEND_NAME hpljm1005
 #include  "../include/sane/sanei_backend.h"
 #include  "../include/sane/sanei_usb.h"
--- a/backend/kvs1025.c
+++ b/backend/kvs1025.c
@@ -18,7 +18,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/backend/kvs1025_low.c
+++ b/backend/kvs1025_low.c
@@ -17,7 +17,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/backend/kvs1025_opt.c
+++ b/backend/kvs1025_opt.c
@@ -17,7 +17,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/backend/kvs1025_usb.c
+++ b/backend/kvs1025_usb.c
@@ -17,9 +17,13 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 
 #include "../include/sane/sane.h"
 #include "../include/sane/saneopts.h"
--- a/backend/leo.c
+++ b/backend/leo.c
@@ -61,7 +61,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/backend/lexmark.h
+++ b/backend/lexmark.h
@@ -54,7 +54,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <time.h>
 #include <unistd.h>
 #include <fcntl.h>
--- a/backend/matsushita.c
+++ b/backend/matsushita.c
@@ -65,7 +65,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/backend/mustek_usb.c
+++ b/backend/mustek_usb.c
@@ -60,7 +60,9 @@
 
 #include <sys/time.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 
 #include "../include/sane/sane.h"
 #include "../include/sane/sanei.h"
--- a/backend/mustek_usb2.c
+++ b/backend/mustek_usb2.c
@@ -61,7 +61,9 @@
 
 #include <sys/time.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 
 #include "../include/sane/sane.h"
 #include "../include/sane/sanei.h"
--- a/backend/niash.c
+++ b/backend/niash.c
@@ -32,7 +32,9 @@
 #include <string.h>             /* memcpy */
 #include <stdio.h>
 #include <sys/time.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 
 /* definitions for debug */
 #define BACKEND_NAME niash
--- a/backend/sceptre.c
+++ b/backend/sceptre.c
@@ -63,7 +63,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/backend/stv680.c
+++ b/backend/stv680.c
@@ -77,7 +77,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/backend/teco1.c
+++ b/backend/teco1.c
@@ -61,7 +61,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/backend/teco2.c
+++ b/backend/teco2.c
@@ -80,7 +80,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/backend/teco3.c
+++ b/backend/teco3.c
@@ -61,7 +61,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 
 #include "../include/sane/sane.h"
--- a/configure.ac
+++ b/configure.ac
@@ -180,10 +180,10 @@
 AC_HEADER_STDC
 AC_CHECK_HEADERS(fcntl.h unistd.h libc.h sys/dsreq.h sys/select.h \
     sys/time.h sys/shm.h sys/ipc.h sys/scanio.h os2.h \
-    sys/socket.h sys/io.h sys/hw.h sys/types.h linux/ppdev.h \
+    sys/socket.h sys/io.h sys/hw.h sys/types.h sys/wait.h linux/ppdev.h \
     dev/ppbus/ppi.h machine/cpufunc.h sys/sem.h poll.h \
-    windows.h be/kernel/OS.h limits.h sys/ioctl.h asm/types.h\
-    netinet/in.h tiffio.h ifaddrs.h pwd.h getopt.h)
+    windows.h be/kernel/OS.h limits.h sys/ioctl.h asm/types.h \
+    netdb.h netinet/in.h tiffio.h ifaddrs.h pwd.h getopt.h)
 AC_CHECK_HEADERS([asm/io.h],,,[#include <sys/types.h>])
 
 SANE_CHECK_MISSING_HEADERS
--- a/frontend/jpegtopdf.c
+++ b/frontend/jpegtopdf.c
@@ -31,6 +31,10 @@
 #include <sys/stat.h>
 #include <time.h>
 #include "jpegtopdf.h"
+
+#ifdef _WIN32
+#define localtime_r localtime_s
+#endif
 
 #ifndef PATH_MAX
 # define PATH_MAX 4096
--- a/sanei/sanei_pa4s2.c
+++ b/sanei/sanei_pa4s2.c
@@ -191,7 +191,9 @@
 
 static u_int sanei_pa4s2_interface_options = SANEI_PA4S2_OPT_DEFAULT;
 
+#if !defined (HAVE_LIBIEEE1284)
 extern int setuid (uid_t);	/* should also be in unistd.h */
+#endif
 
 static int pa4s2_open (const char *dev, SANE_Status * status);
 static void pa4s2_readbegin_epp (int fd, u_char reg);
--- a/sanei/sanei_pio.c
+++ b/sanei/sanei_pio.c
@@ -71,7 +71,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 #include <time.h>
 
@@ -129,7 +131,9 @@
     {0x278, -1, 0, 0}
   };
 
+#ifndef _WIN32
 extern int setuid (uid_t);
+#endif
 
 static inline int pio_wait (const Port port, u_char val, u_char mask);
 static inline void pio_ctrl (const Port port, u_char val);
@@ -350,6 +354,7 @@
       first_time = 0;
 
       DBG_INIT ();
+#ifndef _WIN32
       /* set root uid */
       if (0 > setuid (0))
 	{
@@ -357,6 +362,7 @@
 	  *status = SANE_STATUS_INVAL;
 	  return -1;
 	}
+#endif
     }
   /* read port number */
   {
--- a/sanei/sanei_pp.c
+++ b/sanei/sanei_pp.c
@@ -218,7 +218,9 @@
 #endif
 
 /* should also be in unistd.h */
+#if !defined (HAVE_LIBIEEE1284)
 extern int setuid (uid_t);
+#endif
 
 #if defined (HAVE_LIBIEEE1284)
 
--- backends-1.2.1/backend/genesys/genesys.cpp.orig	2024-01-16 06:44:21.772481200 +0100
+++ backends-1.2.1/backend/genesys/genesys.cpp	2024-01-16 06:44:49.795923100 +0100
@@ -4447,7 +4447,11 @@
         /* make sure .sane directory exists in existing store dir */
         size = std::snprintf(&ret.front(), ret.size(), "%s%c.sane", ptr, PATH_SEP);
         ret.resize(size);
-        mkdir(ret.c_str(), 0700);
+#ifndef _WIN32
+        mkdir(ret.c_str(), 0700);
+#else
+        mkdir(ret.c_str());
+#endif
 
         ret.resize(PATH_MAX);
 #endif
--- backends-1.2.1/acinclude.m4.orig	2024-01-16 06:41:13.923812800 +0100
+++ backends-1.2.1/acinclude.m4	2024-01-16 06:41:24.753478300 +0100
@@ -714,7 +714,7 @@
 /* Prototype for sigprocmask */
 #ifndef HAVE_SIGPROCMASK
 #define sigprocmask sanei_sigprocmask
-int sigprocmask (int how, int *new, int *old);
+int sigprocmask (int how, int *new_, int *old);
 #endif
 
 /* Prototype for snprintf */
