-------- Original Message --------
Subject: Re: Interest in Sane or LibUSB
From: Richard W.M. Jones <[email protected]>
To: Fedora MinGW (Windows cross-compiler) project <[email protected]>
Date: 03/24/2009 03:34 PM


Yes to both.  Hans Niederman (ndim on #fedora-mingw) already took a
look at libusb-win32.


Attached. Upstream already has the sane patches. I had to add some #undefs for u_char, u_long, and u_int for Fedora as I was getting conflicts with the winsock(2).h defines. It seems MinGW in Fedora is adding them, but I don't see them in any system header.

 > BSOD from userspace??

Yes, isn't Vista grand? ;) This is widely reported by Vista users[1] and affects an in-house Vista machine with me.

Probably best to file a bug against the native Fedora package if you
want it to be updated.

Since libusb-0.1.x is deprecated, I doubt we'll see fixes for this issue. I'm not sure if all packages relying on libusb in Fedora are ready for libusb-1.0 as it is an ABI change. However, there is a libusb-compat-0.1 package to make the transition easy. I haven't tried compiling libusb-1.0 in MinGW yet though. I haven't found anyone who has so I'm not sure how well it will compile. When more free time comes up I'll attempt a build.


[1] http://www.shaddihasan.com/blog/2008/11/09/lejos-libusb-win32-vista-and-usbhubsys/
%define __strip %{_mingw32_strip}
%define __objdump %{_mingw32_objdump}
%define _use_internal_dependency_generator 0
%define __find_requires %{_mingw32_findrequires}
%define __find_provides %{_mingw32_findprovides}

Name:           mingw32-libusb-win32
Version:        0.1.12.1
Release:        1%{?dist}
Summary:        A library which allows userspace access to USB devices

License:        LGPLv2+
Group:          System Environment/Libraries
URL:            http://libusb-win32.sourceforge.net/
Source0:        
http://download.sourceforge.net/libusb-win32/libusb-win32-src-%{version}.tar.gz
Patch0:         mingw32-libusb-win32.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildArch:      noarch

BuildRequires:  mingw32-filesystem >= 33
BuildRequires:  mingw32-gcc
BuildRequires:  mingw32-binutils
BuildRequires:  autoconf, automake, libtool


%description
This package provides a way for applications to access USB devices.


%prep
%setup -q -n libusb-win32-src-%{version}
%patch0 -p0

chmod -x COPYING_GPL.txt
chmod -x COPYING_LGPL.txt


%build
host_prefix=%{_mingw32_target} \
make


%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{_mingw32_bindir}
mkdir -p $RPM_BUILD_ROOT/%{_mingw32_libdir}
mkdir -p $RPM_BUILD_ROOT/%{_mingw32_includedir}
mkdir -p $RPM_BUILD_ROOT/%{_mingw32_datadir}/libusb-win32
cp -p inf-wizard.exe install-filter.exe testlibusb.exe testlibusb-win.exe 
libusb0.dll libusb0.sys $RPM_BUILD_ROOT/%{_mingw32_bindir}
cp -p libusb.a libusbd.a $RPM_BUILD_ROOT/%{_mingw32_libdir}
cp -p src/usb.h $RPM_BUILD_ROOT/%{_mingw32_includedir}
cp -p COPYING_GPL.txt COPYING_LGPL.txt 
$RPM_BUILD_ROOT/%{_mingw32_datadir}/libusb-win32

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root)
%{_mingw32_bindir}/libusb0.dll
%{_mingw32_bindir}/libusb0.sys
%{_mingw32_bindir}/inf-wizard.exe
%{_mingw32_bindir}/install-filter.exe
%{_mingw32_bindir}/testlibusb.exe
%{_mingw32_bindir}/testlibusb-win.exe
%{_mingw32_libdir}/libusb.a
%{_mingw32_libdir}/libusbd.a
%{_mingw32_includedir}/usb.h
%{_mingw32_datadir}/libusb-win32/COPYING_GPL.txt
%{_mingw32_datadir}/libusb-win32/COPYING_LGPL.txt


%changelog
* Tue Mar 24 2009 Michael Cronenworth <[email protected]> - 0.1.12.1-1
- Initial RPM release.
%define __strip %{_mingw32_strip}
%define __objdump %{_mingw32_objdump}
%define _use_internal_dependency_generator 0
%define __find_requires %{_mingw32_findrequires}
%define __find_provides %{_mingw32_findprovides}

Name:           mingw32-sane-backends
Version:        1.0.19
Release:        1%{?dist}
Summary:        Scanner access software

License:        GPLv2+ and GPLv2+ with exceptions and Public Domain
Group:          System Environment/Libraries
URL:            http://www.sane-project.org
Source0:        
ftp://ftp.sane-project.org/pub/sane/sane-backends-%{version}/sane-backends-%{version}.tar.gz
Patch0:         sane-win32-backend.patch
Patch1:         sane-win32-frontend.patch
Patch2:         sane-win32-lib.patch
Patch3:         sane-win32-sanei.patch
Patch4:         sane-win32-tools.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildArch:      noarch

BuildRequires:  mingw32-filesystem >= 33
BuildRequires:  mingw32-gcc
BuildRequires:  mingw32-binutils
BuildRequires:  mingw32-libusb-win32


%description
Scanner Access Now Easy (SANE) is a universal scanner interface.  The
SANE application programming interface (API) provides standardized
access to any raster image scanner hardware (flatbed scanner,
hand-held scanner, video and still cameras, frame-grabbers, etc.).


%prep
%setup -q -n sane-backends-%{version}
%patch0 -p0
%patch1 -p0
%patch2 -p0
%patch3 -p0
%patch4 -p0

chmod -x COPYING


%build
export BACKENDS=fujitsu \
%{_mingw32_configure}
make %{?_smp_mflags}
touch backend/.libs/libsane-fujitsu-1.dll
touch backend/.libs/libsane-dll-1.dll


%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

# Remove documentation which duplicates that found in the native package.
rm -r $RPM_BUILD_ROOT/%{_mingw32_prefix}/doc
rm -r $RPM_BUILD_ROOT/%{_mingw32_prefix}/share

# Delete temp files
rm -r $RPM_BUILD_ROOT/%{_mingw32_libdir}/bin
rm -r $RPM_BUILD_ROOT/%{_mingw32_libdir}/sane

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root)
%doc COPYING
%{_mingw32_bindir}/libsane-1.dll
%{_mingw32_bindir}/gamma4scanimage
%{_mingw32_bindir}/sane-config
%{_mingw32_bindir}/sane-find-scanner
%{_mingw32_bindir}/scanimage
%{_mingw32_libdir}/libsane.dll.a
%{_mingw32_libdir}/libsane.la
%{_mingw32_includedir}/sane/sane.h
%{_mingw32_includedir}/sane/saneopts.h
%{_mingw32_sysconfdir}/sane.d/dll.conf
%{_mingw32_sysconfdir}/sane.d/fujitsu.conf
%{_mingw32_sysconfdir}/sane.d/saned.conf


%changelog
* Tue Mar 24 2009 Michael Cronenworth <[email protected]> - 1.0.19-1
- Initial RPM release.
--- Makefile.orig	2007-03-20 05:33:29.000000000 -0500
+++ Makefile	2009-03-24 11:55:16.410910424 -0500
@@ -108,7 +108,7 @@
 WINDRES_FLAGS = -I./src -DRC_VERSION='$(RC_VERSION)' \
 								-DRC_VERSION_STR=$(RC_VERSION_STR)
 
-LDFLAGS = -s -mno-cygwin -L. -lusb -lgdi32 -luser32 -lcfgmgr32 \
+LDFLAGS = -s -mno-cygwin -L. -lusb0 -lgdi32 -luser32 -lcfgmgr32 \
 	 				-lsetupapi -lcomctl32
 WIN_LDFLAGS = $(LDFLAGS) -mwindows
 
--- backend/abaton.c	2007-10-26 09:56:37 -0500
+++ backend/abaton.c	2009-01-12 18:23:47 -0600
@@ -59,7 +59,9 @@
 
 #include <sys/time.h>
 #include <sys/types.h>
+#ifndef WIN32
 #include <sys/wait.h>
+#endif
 
 #include "sane/sane.h"
 #include "sane/sanei.h"
--- backend/agfafocus.c	2008-02-03 19:20:01 -0600
+++ backend/agfafocus.c	2009-01-13 08:57:10 -0600
@@ -31,6 +31,10 @@
 #include <string.h>
 #include <sys/types.h>
 
+#ifdef WIN32
+#include <windows.h>
+#endif
+
 #include "sane/sane.h"
 #include "sane/sanei.h"
 #include "sane/sanei_config.h"
@@ -352,7 +356,17 @@
 	  else if (left < 200)
 	    usleep (left * 5000);
 	  else
+#ifdef WIN32
+               {
+            HANDLE Handle;
+            if ( ( Handle = CreateSemaphore( NULL, 0, 2, NULL ) ) != NULL ) {
+               WaitForSingleObject( Handle, ( left * 1000000 ) / 200 );
+               CloseHandle( Handle );
+            }
+          }
+#else
 	    sleep (left / 200);
+#endif
 	}
     }
 
@@ -1791,22 +1805,30 @@
   int i;
   sigset_t sigterm_set;
   sigset_t ignore_set;
+#ifndef WIN32
   struct SIGACTION act;
+#endif
 
   if (sanei_thread_is_forked()) close (s->pipe);
 
   sigfillset (&ignore_set);
+#ifndef WIN32
   sigdelset (&ignore_set, SIGTERM);
+#endif
 #if defined (__APPLE__) && defined (__MACH__)
   sigdelset (&ignore_set, SIGUSR2);
 #endif
   sigprocmask (SIG_SETMASK, &ignore_set, 0);
 
+#ifndef WIN32
   memset (&act, 0, sizeof (act));
   sigaction (SIGTERM, &act, 0);
+#endif
 
   sigemptyset (&sigterm_set);
+#ifndef WIN32
   sigaddset (&sigterm_set, SIGTERM);
+#endif
 
   if (!s->hw->disconnect)
     wait_ready (s->fd);
@@ -2002,7 +2024,9 @@
 	}
     }
 
+#ifndef WIN32
   if (pipe (fds) < 0)
+#endif
     return SANE_STATUS_IO_ERROR;
 
   s->pipe = fds[0];
@@ -2065,7 +2089,9 @@
   if (!s->scanning)
     return SANE_STATUS_INVAL;
 
+#ifndef WIN32
   if (fcntl (s->pipe, F_SETFL, non_blocking ? O_NONBLOCK : 0) < 0)
+#endif
     return SANE_STATUS_IO_ERROR;
 
   return SANE_STATUS_GOOD;
--- backend/apple.c	2007-10-26 09:56:37 -0500
+++ backend/apple.c	2009-01-13 08:58:50 -0600
@@ -57,7 +57,9 @@
 
 #include <sys/time.h>
 #include <sys/types.h>
+#ifndef WIN32
 #include <sys/wait.h>
+#endif
 
 #include "sane/sane.h"
 #include "sane/sanei.h"
--- backend/artec.c	2007-10-26 09:56:37 -0500
+++ backend/artec.c	2009-01-13 09:01:27 -0600
@@ -629,7 +629,11 @@
 
       if (status == SANE_STATUS_DEVICE_BUSY)
 	{
+#ifdef WIN32
+          usleep(999999);
+#else
 	  sleep (1);
+#endif
 	  continue;
 	}
 
--- backend/artec_eplus48u.c	2007-11-18 04:59:17 -0600
+++ backend/artec_eplus48u.c	2009-01-13 10:05:47 -0600
@@ -85,7 +85,9 @@
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#ifndef WIN32
 #include <sys/ioctl.h>
+#endif
 
 
 #include "../include/sane/sane.h"
@@ -3394,7 +3396,9 @@
   int fd = s->reader_pipe;
 
   SANE_Status status;
+#ifndef WIN32
   struct SIGACTION act;
+#endif
   sigset_t ignore_set;
   ssize_t bytes_written = 0;
 
@@ -3403,13 +3407,16 @@
   if (sanei_thread_is_forked()) close (s->pipe);
 
   sigfillset (&ignore_set);
+#ifndef WIN32
   sigdelset (&ignore_set, SIGTERM);
   sigdelset (&ignore_set, SIGUSR1);
+#endif
 #if defined (__APPLE__) && defined (__MACH__)
   sigdelset (&ignore_set, SIGUSR2);
 #endif
   sigprocmask (SIG_SETMASK, &ignore_set, 0);
 
+#ifndef WIN32
   memset (&act, 0, sizeof (act));
   sigaction (SIGTERM, &act, 0);
   sigaction (SIGUSR1, &act, 0);
@@ -3430,6 +3437,7 @@
 
   XDBG ((2, "(child) reader_process: s=%p, fd=%d\n", (void *) s, fd));
 
+#endif 
   /*read line by line into buffer */
   /*copy buffer pointers to line_buffer */
   XDBG ((2, "(child) reader_process: byte_cnt %d\n", (int) s->byte_cnt));
@@ -3477,7 +3485,9 @@
 static SANE_Status
 do_cancel (Artec48U_Scanner * s, SANE_Bool closepipe)
 {
+#ifndef WIN32
   struct SIGACTION act;
+#endif
   pid_t res;
   XDBG ((1, "do_cancel\n"));
 
@@ -3487,6 +3497,7 @@
     {
       /*parent */
       XDBG ((1, "killing reader_process\n"));
+#ifndef WIN32
       /* tell the driver to stop scanning */
       sigemptyset (&(act.sa_mask));
       act.sa_flags = 0;
@@ -3502,6 +3513,7 @@
 	XDBG ((1, "sanei_thread_kill() failed !\n"));
       res = sanei_thread_waitpid (s->reader_pid, 0);
       alarm (0);
+#endif
 
       if (res != s->reader_pid)
 	{
@@ -4269,6 +4281,7 @@
 	    s->lineart_buffer = (SANE_Byte *) malloc (s->params.pixel_xs * 2);
 	}
     }
+#ifndef WIN32
   if (pipe (fds) < 0)
     {
       s->scanning = SANE_FALSE;
@@ -4296,6 +4309,7 @@
   if (sanei_thread_is_forked()) close (s->reader_pipe);
 
   XDBG ((1, "sane_start done\n"));
+#endif
 
   return SANE_STATUS_GOOD;	/* parent */
 }
@@ -4390,11 +4404,13 @@
       return SANE_STATUS_UNSUPPORTED;
     }
 
+#ifndef WIN32
   if (fcntl (s->pipe, F_SETFL, non_blocking ? O_NONBLOCK : 0) < 0)
     {
       XDBG ((4, "ERROR: can?t set to non-blocking mode !\n"));
       return SANE_STATUS_IO_ERROR;
     }
+#endif
 
   XDBG ((1, "sane_set_io_mode done\n"));
   return SANE_STATUS_GOOD;
--- backend/umax_pp_low.c	2006-09-17 23:59:52 -0500
+++ backend/umax_pp_low.c	2009-01-13 10:24:58 -0600
@@ -6049,7 +6049,12 @@
       CMDSETGET (4, 0x08, op03);
       CMDSYNC (0x40);
       CMDSYNC (0xC2);
+#ifdef WIN32
+      usleep (999999);
+      usleep (999999);
+#else
       sleep (2);
+#endif
     }
 
   /* move backward */
@@ -6061,7 +6066,12 @@
   CMDSETGET (4, 0x08, op03);
   CMDSYNC (0x40);
   CMDSYNC (0xC2);
+#ifdef WIN32
+  usleep (999999);
+  usleep (999999);
+#else
   sleep (2);
+#endif
 
   /* means 'CONTINUE MOVE' */
   CMDSYNC (0x00);
@@ -6091,7 +6101,19 @@
       CMDSETGET (4, 0x08, op03);
       CMDSYNC (0x40);
       CMDSYNC (0xC2);
+#ifdef WIN32
+      usleep (999999);
+      usleep (999999);
+      usleep (999999);
+      usleep (999999);
+      usleep (999999);
+      usleep (999999);
+      usleep (999999);
+      usleep (999999);
+      usleep (999999);
+#else
       sleep (9);
+#endif
     }
 
   CMDSYNC (0x00);
@@ -6224,7 +6246,11 @@
 	  CMDSYNC (0x40);
 	  do
 	    {
+#ifdef WIN32
+              usleep (999999);
+#else
 	      sleep (1);
+#endif
 	      CMDSYNC (0xC2);
 	    }
 	  while ((sanei_umax_pp_scannerStatus () & 0x90) != 0x90);
@@ -6240,7 +6266,11 @@
 	  CMDSYNC (0x40);
 	  do
 	    {
+#ifdef WIN32
+              usleep (999999);
+#else
 	      sleep (1);
+#endif
 	      CMDSYNC (0xC2);
 	    }
 	  while ((sanei_umax_pp_scannerStatus () & 0x90) != 0x90);
@@ -6320,7 +6350,13 @@
 	      /* the sleep is here to prevent */
 	      /* excessive CPU usage, can be  */
 	      /* removed, if we don't care    */
+#ifdef WIN32
+              usleep (999999);
+              usleep (999999);
+              usleep (999999);
+#else
 	      sleep (3);
+#endif
 	      CMDSYNC (0xC2);
 	      DBG (16, "PARKING polling status is 0x%02X   (%s:%d)\n",
 		   sanei_umax_pp_scannerStatus (), __FILE__, __LINE__);
@@ -11672,7 +11708,11 @@
       /* poll parking */
       do
 	{
-	  sleep (1);
+#ifdef WIN32
+          usleep (999999);
+#else
+          sleep (1);
+#endif
 	  CMDSYNC (0x40);
 	}
       while ((sanei_umax_pp_scannerStatus () & MOTOR_BIT) == 0x00);
--- frontend/scanimage.c	2007-12-29 15:36:25 -0600
+++ frontend/scanimage.c	2009-01-13 10:17:06 -0600
@@ -278,7 +278,9 @@
 
   if (query_user == 1)
     {
+#ifndef WIN32
       strcpy (password, (wipe = getpass ("Enter password: ")));
+#endif
       memset (wipe, 0, strlen (password));
     }
 
@@ -2109,10 +2111,12 @@
   if (output_format != OUTPUT_PNM)
     resolution_value = get_resolution ();
 
+#ifndef WIN32
   signal (SIGHUP, sighandler);
   signal (SIGINT, sighandler);
   signal (SIGPIPE, sighandler);
   signal (SIGTERM, sighandler);
+#endif
 
   if (test == 0)
     {
--- lib/inet_ntop.c	2002-02-14 13:53:37 -0600
+++ lib/inet_ntop.c	2009-01-12 17:22:16 -0600
@@ -3,10 +3,17 @@
 #ifndef HAVE_INET_NTOP
 
 #include <string.h>
+#ifdef WIN32
+#undef u_char
+#undef u_int
+#undef u_long
+#include <winsock2.h>
+#else
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#endif
 
 
 const char *
--- lib/inet_pton.c	2002-02-19 13:30:47 -0600
+++ lib/inet_pton.c	2009-01-12 17:24:01 -0600
@@ -3,10 +3,17 @@
 #ifndef HAVE_INET_PTON
 
 #include <string.h>
+#ifdef WIN32
+#undef u_char
+#undef u_int
+#undef u_long
+#include <winsock2.h>
+#else
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#endif
 
 int 
 inet_pton (int af, const char *src, void *dst)
--- lib/sigprocmask.c	2001-05-31 12:36:38 -0500
+++ lib/sigprocmask.c	2009-01-12 18:27:34 -0600
@@ -33,9 +33,11 @@
 
   switch (how)
     {
+#ifndef WIN32
     case 1: o = sigblock (n); break;
     case 2: o = sigsetmask (sigblock (0) & ~n); break;
     case 3: o = sigsetmask (n); break;
+#endif
     default:
       errno = EINVAL;
       return -1;
--- lib/vsyslog.c	2001-05-31 12:36:39 -0500
+++ lib/vsyslog.c	2009-01-12 17:26:36 -0600
@@ -1,7 +1,9 @@
 #include "../include/sane/config.h"
 
 #include "stdio.h"
+#ifndef WIN32
 #include <syslog.h>
+#endif
 #include <stdarg.h>
 
 #ifndef HAVE_VSYSLOG
@@ -9,9 +11,11 @@
 void
 vsyslog(int priority, const char *format, va_list args)
 {
+#ifndef WIN32
   char buf[1024];
   vsnprintf(buf, sizeof(buf), format, args);
   syslog(priority, "%s", buf);
+#endif
 }
 
 #endif /* !HAVE_VSYSLOG */
--- sanei/sanei_ab306.c	2007-10-25 08:23:52 -0500
+++ sanei/sanei_ab306.c	2009-01-12 17:39:08 -0600
@@ -55,6 +55,10 @@
 # include <asm/io.h>	/* ugly, but backwards compatible */
 #elif defined (__i386__)  && defined (__GNUC__)
 
+#ifdef WIN32
+typedef unsigned short int u_short;
+#endif
+
 static __inline__ void
 outb (u_char value, u_long port)
 {
--- sanei/sanei_init_debug.c	2005-07-15 16:59:25 -0500
+++ sanei/sanei_init_debug.c	2009-01-12 17:41:45 -0600
@@ -48,7 +48,9 @@
 #endif
 #include <string.h>
 #include <stdarg.h>
+#ifndef WIN32
 #include <syslog.h>
+#endif
 #ifdef HAVE_OS2_H
 #include <sys/types.h>
 #endif
@@ -106,13 +108,17 @@
 	  msg = (char *)malloc (sizeof(char) * (strlen(be) + strlen(fmt) + 4));
 	  if (msg == NULL)
 	    {
+#ifndef WIN32
 	      syslog (LOG_DEBUG, "[sanei_debug] malloc() failed\n");
 	      vsyslog (LOG_DEBUG, fmt, ap);
+#endif
 	    }
 	  else
 	    {
+#ifndef WIN32
 	      sprintf (msg, "[%s] %s", be, fmt);
               vsyslog(LOG_DEBUG, msg, ap);
+#endif
 	      free (msg);
 	    }
 	}
--- sanei/sanei_pio.c	2006-06-11 14:46:09 -0500
+++ sanei/sanei_pio.c	2009-01-12 17:53:26 -0600
@@ -66,6 +66,10 @@
 # include <sys/hw.h>
 #elif defined(__i386__)  && defined (__GNUC__)
 
+#ifdef WIN32
+typedef unsigned short int u_short;
+#endif
+
 static __inline__ void
 outb (u_char value, u_long port)
 {
--- sanei/sanei_scsi.c	2007-11-16 12:37:07 -0600
+++ sanei/sanei_scsi.c	2009-01-12 17:52:00 -0600
@@ -56,7 +56,9 @@
 #include <string.h>
 #include <unistd.h>
 
+#ifndef WIN32
 #include <sys/ioctl.h>
+#endif
 #include <sys/param.h>
 #include <sys/types.h>

@@ -211,6 +216,9 @@
 # endif
 #elif defined (HAVE_WINDOWS_H)
 # define USE WIN32_INTERFACE
+# undef u_char
+# undef u_int
+# undef u_long
 # include <windows.h>
 # include <ddk/scsi.h>
 # include <ddk/ntddscsi.h>
@@ -4754,6 +4762,7 @@
                 const void *src, size_t src_size,
 		void *dst, size_t * dst_size)
 {
+#ifndef WIN32
   struct pkt {
     SCSI_PASS_THROUGH_DIRECT sptd;
     unsigned char sense[255];
@@ -4827,6 +4830,7 @@
   if (dst_size) {
     *dst_size = pkt.sptd.DataTransferLength;
   }
+#endif
 
   return SANE_STATUS_GOOD;
 }
--- sanei/sanei_tcp.c	2008-01-08 17:04:04 -0600
+++ sanei/sanei_tcp.c	2009-01-12 18:19:18 -0600
@@ -46,7 +46,14 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef WIN32
+#undef u_char
+#undef u_int
+#undef u_long
+#include <winsock2.h>
+#else
 #include <sys/socket.h>
+#endif
 
 #if defined(__CYGWIN__) && !defined(MSG_WAITALL)
 #define MSG_WAITALL  0x08
@@ -110,5 +114,9 @@
 ssize_t
 sanei_tcp_read(int fd, u_char * buf, int count)
 {
+#ifdef WIN32
+	return recv(fd, buf, count, 0);
+#else
 	return recv(fd, buf, count, MSG_WAITALL);
+#endif
 }
--- sanei/sanei_thread.c	2005-07-15 16:59:25 -0500
+++ sanei/sanei_thread.c	2009-01-13 08:53:48 -0600
@@ -69,8 +69,10 @@
 # include <kernel/OS.h>
 #endif
 #if !defined USE_PTHREAD && !defined HAVE_OS2_H && !defined __BEOS__
+#ifndef WIN32
 # include <sys/wait.h>
 #endif
+#endif
 #if defined USE_PTHREAD
 # include <pthread.h>
 #endif
@@ -129,8 +131,12 @@
 #elif defined HAVE_OS2_H
 	return DosKillThread(pid);
 #else
+#ifdef WIN32
+	return -1;
+#else
 	return kill( pid, SIGTERM );
 #endif
+#endif
 }
 
 #ifdef HAVE_OS2_H
@@ -245,7 +251,11 @@
 {
 	if (sig == SIGKILL)
 		sig = SIGKILLTHR;
+#ifdef WIN32
+	return -1;
+#else
 	return kill(pid, sig);
+#endif
 }
 
 #else /* HAVE_OS2_H, __BEOS__ */
@@ -329,6 +339,7 @@
 {
 	int retval = SANE_STATUS_IO_ERROR;
 
+#ifndef WIN32
 	if( wpres == pid ) {
 
 		if( WIFEXITED(pf)) {
@@ -344,6 +355,7 @@
 			}
 		}
 	}
+#endif
 	return retval;
 }
 #endif
@@ -383,11 +395,15 @@
 	DBG( 2, "pthread_create() created thread %d\n", (int)thread );
 	return (int)thread;
 #else
+#ifdef WIN32
+        pid = 0;
+#else
 	pid = fork();
 	if( pid < 0 ) {
 		DBG( 1, "fork() failed\n" );
 		return -1;
 	}
+#endif
 
 	if( pid == 0 ) {
 
@@ -411,7 +427,11 @@
 	return pthread_kill((pthread_t)pid, sig );
 #else
 	DBG(2, "sanei_thread_sendsig() %d to process (id=%d)\n", sig, pid);
-	return kill( pid, sig );
+#ifdef WIN32
+	return -1;
+#else
+	return kill(pid, sig);
+#endif
 #endif
 }
 
@@ -451,7 +471,11 @@
 
 	restore_sigpipe();
 #else
+#ifdef WIN32
+        result = -1;
+#else
 	result = waitpid( pid, &ls, 0 );
+#endif
 	if((result < 0) && (errno == ECHILD)) {
 		stat   = SANE_STATUS_GOOD;
 		result = pid;
@@ -478,12 +502,14 @@
 	int ls, stat, result;
 
 	stat = SANE_STATUS_IO_ERROR;
+#ifndef WIN32
 	if( pid > 0 ) {
 
 		result = waitpid( pid, &ls, WNOHANG );
 
 		stat = eval_wp_result( pid, result, ls );
 	}
+#endif
 	return stat;
 #endif
 }
--- sanei/sanei_udp.c	2007-12-26 05:18:26 -0600
+++ sanei/sanei_udp.c	2009-01-12 18:21:46 -0600
@@ -46,10 +46,17 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef WIN32
+#undef u_char
+#undef u_int
+#undef u_long
+#include <winsock2.h>
+#else
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netdb.h>
 #include <arpa/inet.h>
+#endif
 
 #define BACKEND_NAME sanei_udp
 
@@ -172,7 +176,11 @@
 ssize_t
 sanei_udp_read(int fd, u_char * buf, int count)
 {
+#ifdef WIN32
+	return recv(fd, buf, count, 0);
+#else
 	return recv(fd, buf, count, MSG_WAITALL);
+#endif
 }
 
 ssize_t
@@ -184,8 +192,13 @@
 
 	fl = sizeof(from);
 
+#ifdef WIN32
+	l = recvfrom(fd, buf, count, 0,
+		(struct sockaddr *) &from, &fl);
+#else
 	l = recvfrom(fd, buf, count, MSG_DONTWAIT,
 		(struct sockaddr *) &from, &fl);
+#endif
 
 	if (l > 0 && fromp) {
 		*fromp = inet_ntoa(from.sin_addr);
--- sanei/sanei_usb.c.orig	2007-11-16 02:46:32.000000000 -0600
+++ sanei/sanei_usb.c	2009-03-24 12:23:34.911909788 -0500
@@ -52,7 +52,9 @@
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
+#ifndef WIN32
 #include <sys/ioctl.h>
+#endif
 #include <stdio.h>
 #include <dirent.h>
 
@@ -60,6 +62,9 @@
 #include <resmgr.h>
 #endif
 #ifdef HAVE_LIBUSB
+#undef u_char
+#undef u_int
+#undef u_long
 #include <usb.h>
 #endif /* HAVE_LIBUSB */
 
@@ -1046,6 +1051,7 @@
 	       devname, strerror (errno));
 	  return status;
 	}
+#ifndef WIN32
       flag = fcntl (devices[devcount].fd, F_GETFD);
       if (flag >= 0)
 	{
@@ -1053,6 +1059,7 @@
 	    DBG (1, "sanei_usb_open: fcntl of `%s' failed: %s\n",
 		 devname, strerror (errno));
 	}
+#endif
     }
   else if (devices[devcount].method == sanei_usb_method_usbcalls)
     {
--- include/sane/sanei_tcp.h.orig	2006-11-30 17:23:19.000000000 -0600
+++ include/sane/sanei_tcp.h	2009-03-24 10:08:51.638160778 -0500
@@ -20,8 +20,13 @@
 
 #include <sane/sane.h>
 
+#ifdef WIN32
+#undef socklen_t
+#include <ws2tcpip.h>
+#else
 #include <netinet/in.h>
 #include <netdb.h>
+#endif
 
 extern SANE_Status sanei_tcp_open(const char *host, int port, int *fdp);
 extern void sanei_tcp_close(int fd);
--- include/sane/sanei_udp.h.orig	2007-12-26 05:18:26.000000000 -0600
+++ include/sane/sanei_udp.h	2009-03-24 10:13:58.822909635 -0500
@@ -20,8 +20,13 @@
 
 #include <sane/sane.h>
 
+#ifdef WIN32
+#undef socklen_t
+#include <ws2tcpip.h>
+#else
 #include <netinet/in.h>
 #include <netdb.h>
+#endif
 
 extern SANE_Status sanei_udp_open(const char *host, int port, int *fdp);
 extern SANE_Status sanei_udp_open_broadcast(int *fdp);
--- tools/check-usb-chip.c.orig	2009-03-24 12:28:22.087908759 -0500
+++ tools/check-usb-chip.c	2009-03-24 12:30:42.876156194 -0500
@@ -37,6 +37,11 @@
 #define TIMEOUT 1000
 
 #ifdef HAVE_LIBUSB
+#ifdef WIN32
+#undef u_char
+#undef u_int
+#undef u_long
+#endif
 #include <usb.h>
 
 extern char *check_usb_chip (struct usb_device *dev, int verbosity,
--- tools/sane-find-scanner.c.orig	2007-11-10 09:44:41.000000000 -0600
+++ tools/sane-find-scanner.c	2009-03-24 10:49:48.854160314 -0500
@@ -31,6 +31,9 @@
 #include <errno.h>
 
 #if defined (HAVE_WINDOWS_H)
+#undef u_char
+#undef u_int
+#undef u_long
 #include <windows.h>
 #include <ddk/scsi.h>
 #include <ddk/ntddscsi.h>
@@ -1593,12 +1596,14 @@
   if (verbose > 0)
     printf ("\n  # Most Scanners connected to the parallel port or other "
 	    "proprietary ports\n  # can't be detected by this program.\n");
+#ifndef WIN32
   if (getuid ())
     if (verbose > 0)
       printf
 	("\n  # You may want to run this program as root to find all devices. "
 	 "Once you\n  # found the scanner devices, be sure to adjust access "
 	 "permissions as\n  # necessary.\n");
+#endif
 
   if (verbose > 1)
     printf ("done\n");
_______________________________________________
fedora-mingw mailing list
[email protected]
https://admin.fedoraproject.org/mailman/listinfo/fedora-mingw

Reply via email to