[beast/win32] Make code compile under windows, sometimes using ugly ifdefs.



commit 277343cda8e4a52bac8ea0bc62b8afcb5012f956
Author: Stefan Westerfeld <stefan space twc de>
Date:   Tue Sep 1 19:37:38 2009 +0200

    Make code compile under windows, sometimes using ugly ifdefs.

 bse/bseengine.c         |    4 ++++
 bse/bseenginemaster.c   |    7 ++++++-
 bse/bsemididevice-oss.c |    5 +++++
 bse/bsepcmdevice-oss.c  |    2 +-
 bse/bseplugin.c         |    4 ++--
 bse/bsesequencer.cc     |    9 ++++++++-
 bse/bseserver.c         |    4 ++++
 bse/gslcommon.c         |   12 +++++++-----
 bse/gsldatahandle-mad.c |    2 ++
 bse/gslfilehash.c       |    4 ++++
 sfi/tests/misctests.c   |    2 ++
 11 files changed, 45 insertions(+), 10 deletions(-)
---
diff --git a/bse/bseengine.c b/bse/bseengine.c
index 5fd68ac..42b1889 100644
--- a/bse/bseengine.c
+++ b/bse/bseengine.c
@@ -1442,8 +1442,11 @@ bse_engine_init (gboolean run_threaded)
   
   if (bse_engine_threaded)
     {
+#ifndef WIN32
       gint err = pipe (master_data.wakeup_pipe);
+#endif
       master_data.user_thread = sfi_thread_self ();
+#ifndef WIN32
       if (!err)
 	{
 	  glong d_long = fcntl (master_data.wakeup_pipe[0], F_GETFL, 0);
@@ -1460,6 +1463,7 @@ bse_engine_init (gboolean run_threaded)
 	}
       if (err)
 	g_error ("failed to create wakeup pipe: %s", g_strerror (errno));
+#endif
       master_thread = sfi_thread_run ("DSP #1", (BirnetThreadFunc) bse_engine_master_thread, &master_data);
       if (!master_thread)
 	g_error ("failed to create master thread");
diff --git a/bse/bseenginemaster.c b/bse/bseenginemaster.c
index 542443b..be3616e 100644
--- a/bse/bseenginemaster.c
+++ b/bse/bseenginemaster.c
@@ -24,7 +24,9 @@
 #include "bseieee754.h"
 #include <string.h>
 #include <unistd.h>
+#ifndef WIN32
 #include <sys/poll.h>
+#endif
 #include <sys/time.h>
 #include <errno.h>
 
@@ -1143,6 +1145,7 @@ bse_engine_master_thread (EngineMasterData *mdata)
 {
   bse_message_setup_thread_handler ();
 
+#ifndef WIN32
   /* assert pollfd equality, since we're simply casting structures */
   BIRNET_STATIC_ASSERT (sizeof (struct pollfd) == sizeof (GPollFD));
   BIRNET_STATIC_ASSERT (G_STRUCT_OFFSET (GPollFD, fd) == G_STRUCT_OFFSET (struct pollfd, fd));
@@ -1158,6 +1161,7 @@ bse_engine_master_thread (EngineMasterData *mdata)
   master_pollfds[0].fd = mdata->wakeup_pipe[0];
   master_pollfds[0].events = G_IO_IN;
   master_n_pollfds = 1;
+#endif
   master_pollfds_changed = TRUE;
   
   toyprof_stampinit ();
@@ -1171,12 +1175,13 @@ bse_engine_master_thread (EngineMasterData *mdata)
       
       if (!need_dispatch)
 	{
+#ifndef WIN32
 	  gint err = poll ((struct pollfd*) loop.fds, loop.n_fds, loop.timeout);
 	  if (err >= 0)
 	    loop.revents_filled = TRUE;
 	  else if (errno != EINTR)
 	    g_printerr ("%s: poll() error: %s\n", G_STRFUNC, g_strerror (errno));
-	  
+#endif
 	  if (loop.revents_filled)
 	    need_dispatch = _engine_master_check (&loop);
 	}
diff --git a/bse/bsemididevice-oss.c b/bse/bsemididevice-oss.c
index cc9a7c7..a6d2c57 100644
--- a/bse/bsemididevice-oss.c
+++ b/bse/bsemididevice-oss.c
@@ -30,7 +30,9 @@ BSE_DUMMY_TYPE (BseMidiDeviceOSS);
 #elif HAVE_SOUNDCARD_H
 #include <soundcard.h>
 #endif
+#ifndef WIN32
 #include <sys/ioctl.h>
+#endif
 #include <sys/types.h>
 #include <sys/time.h>
 #include <unistd.h>
@@ -40,6 +42,9 @@ BSE_DUMMY_TYPE (BseMidiDeviceOSS);
 
 static SFI_MSG_TYPE_DEFINE (debug_midi, "midi", SFI_MSG_DEBUG, NULL);
 #define MIDI_DEBUG(...) sfi_debug (debug_midi, __VA_ARGS__)
+#ifdef WIN32
+#define O_NONBLOCK 0
+#endif
 
 
 /* --- structs --- */
diff --git a/bse/bsepcmdevice-oss.c b/bse/bsepcmdevice-oss.c
index 3e63db7..11de33e 100644
--- a/bse/bsepcmdevice-oss.c
+++ b/bse/bsepcmdevice-oss.c
@@ -21,7 +21,7 @@
 #include	"gsldatautils.h"
 #include	"gslcommon.h" // FIXME: remove
 
-#ifndef	BSE_PCM_DEVICE_CONF_OSS
+#if !defined(BSE_PCM_DEVICE_CONF_OSS) || defined (WIN32)
 BSE_DUMMY_TYPE (BsePcmDeviceOSS);
 #else   /* BSE_PCM_DEVICE_CONF_OSS */
 
diff --git a/bse/bseplugin.c b/bse/bseplugin.c
index 5e90f23..e6c2718 100644
--- a/bse/bseplugin.c
+++ b/bse/bseplugin.c
@@ -611,8 +611,8 @@ bse_plugin_check_load (const gchar *const_file_name)
       /* open libtool archive */
       gint fd = open (const_file_name, O_RDONLY, 0);
       if (fd < 0)
-        return (errno == ENOENT || errno == ENOTDIR || errno == ELOOP ?
-                bse_error_blurb (BSE_ERROR_FILE_NOT_FOUND) :
+        return (errno == ENOENT || errno == ENOTDIR || errno == SFI_OS_ELOOP 
+             ? bse_error_blurb (BSE_ERROR_FILE_NOT_FOUND) :
                 "Unable to access plugin");
       
       /* and search libtool's dlname specification */
diff --git a/bse/bsesequencer.cc b/bse/bsesequencer.cc
index 94d57a7..680d59f 100644
--- a/bse/bsesequencer.cc
+++ b/bse/bsesequencer.cc
@@ -24,7 +24,9 @@
 #include "bsemidireceiver.h"
 #include "bsemain.h"
 #include "bseieee754.h"
+#ifndef WIN32
 #include <sys/poll.h>
+#endif
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -63,12 +65,14 @@ bse_sequencer_init_thread (void)
 
   sfi_cond_init (&current_watch_cond);
 
+#ifndef WIN32
   if (pipe (sequencer_wake_up_pipe) < 0)
     g_error ("failed to create sequencer wake-up pipe: %s", strerror (errno));
   glong flags = fcntl (sequencer_wake_up_pipe[0], F_GETFL, 0);
   fcntl (sequencer_wake_up_pipe[0], F_SETFL, O_NONBLOCK | flags);
   flags = fcntl (sequencer_wake_up_pipe[1], F_GETFL, 0);
   fcntl (sequencer_wake_up_pipe[1], F_SETFL, O_NONBLOCK | flags);
+#endif
 
   /* initialize BseSequencer */
   static BseSequencer sseq = { 0, };
@@ -185,7 +189,7 @@ public:
     watches.erase (watches.begin() + i);
     return true;
   }
-  
+#ifndef WIN32 
   BIRNET_STATIC_ASSERT (sizeof (GPollFD) == sizeof (struct pollfd));
   BIRNET_STATIC_ASSERT (offsetof (GPollFD, fd) == offsetof (struct pollfd, fd));
   BIRNET_STATIC_ASSERT (sizeof (((GPollFD*) 0)->fd) == sizeof (((struct pollfd*) 0)->fd));
@@ -193,6 +197,7 @@ public:
   BIRNET_STATIC_ASSERT (sizeof (((GPollFD*) 0)->events) == sizeof (((struct pollfd*) 0)->events));
   BIRNET_STATIC_ASSERT (offsetof (GPollFD, revents) == offsetof (struct pollfd, revents));
   BIRNET_STATIC_ASSERT (sizeof (((GPollFD*) 0)->revents) == sizeof (((struct pollfd*) 0)->revents));
+#endif
 };
 } // Anon
 
@@ -272,6 +277,7 @@ bse_sequencer_poll_Lm (gint timeout_ms)
   pfds[0].revents = 0;
   sequencer_poll_pool.fill_pfds (n_pfds - 1, pfds + 1); /* rest used for io watch array */
   BSE_SEQUENCER_UNLOCK ();
+#ifndef WIN32
   gint result = poll ((struct pollfd*) pfds, n_pfds, timeout_ms);
   if (result < 0 && errno != EINTR)
     g_printerr ("%s: poll() error: %s\n", G_STRFUNC, g_strerror (errno));
@@ -304,6 +310,7 @@ bse_sequencer_poll_Lm (gint timeout_ms)
           sfi_cond_broadcast (&current_watch_cond);     /* wake up threads in bse_sequencer_remove_io_watch() */
         }
     }
+#endif
   return !sfi_thread_aborted();
 }
 
diff --git a/bse/bseserver.c b/bse/bseserver.c
index 4e7c79e..0689f45 100644
--- a/bse/bseserver.c
+++ b/bse/bseserver.c
@@ -26,7 +26,9 @@
 #include "bsemididevice-null.h"
 #include "bsejanitor.h"
 #include <sys/time.h>
+#ifndef WIN32
 #include <sys/resource.h>
+#endif
 #include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
@@ -1166,10 +1168,12 @@ engine_init (BseServer *server,
       int current_priority;
       engine_is_initialized = TRUE;
       bse_engine_init (TRUE);
+#ifndef WIN32
       /* lower priorities compared to engine if our priority range permits */
       current_priority = getpriority (PRIO_PROCESS, mypid);
       if (current_priority <= -2 && mypid)
         setpriority (PRIO_PROCESS, mypid, current_priority + 1);
+#endif
     }
   bse_engine_configure (BSE_GCONFIG (synth_latency), mix_freq, BSE_GCONFIG (synth_control_freq));
 
diff --git a/bse/gslcommon.c b/bse/gslcommon.c
index 192460b..c1ab9d3 100644
--- a/bse/gslcommon.c
+++ b/bse/gslcommon.c
@@ -18,13 +18,15 @@
 
 #include "gsldatacache.h"
 #include <unistd.h>
-#include <sys/utsname.h>
 #include <string.h>
 #include <fcntl.h>
 #include <stdlib.h>
-#include <sched.h>
 #include <errno.h>
+#ifndef WIN32
+#include <sys/utsname.h>
+#include <sched.h>
 #include <sys/poll.h>
+#endif
 #include <sys/stat.h>
 #include <sys/time.h>
 
@@ -179,7 +181,7 @@ gsl_error_from_errno (gint         sys_errno,
   switch (sys_errno)
     {
     case 0:             return BSE_ERROR_NONE;
-    case ELOOP:
+    case SFI_OS_ELOOP:
     case ENAMETOOLONG:
     case ENOENT:        return BSE_ERROR_FILE_NOT_FOUND;
     case EISDIR:        return BSE_ERROR_FILE_IS_DIR;
@@ -189,7 +191,7 @@ gsl_error_from_errno (gint         sys_errno,
 #ifdef ENODATA  /* GNU/kFreeBSD lacks this */
     case ENODATA:
 #endif
-    case ENOMSG:        return BSE_ERROR_FILE_EOF;
+    case SFI_OS_ENOMSG: return BSE_ERROR_FILE_EOF;
     case ENOMEM:	return BSE_ERROR_NO_MEMORY;
     case ENOSPC:	return BSE_ERROR_NO_SPACE;
     case ENFILE:	return BSE_ERROR_NO_FILES;
@@ -198,7 +200,7 @@ gsl_error_from_errno (gint         sys_errno,
     case ESPIPE:
     case EIO:           return BSE_ERROR_IO;
     case EEXIST:        return BSE_ERROR_FILE_EXISTS;
-    case ETXTBSY:
+    case SFI_OS_ETXTBSY:
     case EBUSY:         return BSE_ERROR_FILE_BUSY;
     case EAGAIN:
     case EINTR:		return BSE_ERROR_TEMP;
diff --git a/bse/gsldatahandle-mad.c b/bse/gsldatahandle-mad.c
index f569ce7..95d549a 100644
--- a/bse/gsldatahandle-mad.c
+++ b/bse/gsldatahandle-mad.c
@@ -21,7 +21,9 @@
 #include <assert.h>
 #include <stdio.h>
 #include <unistd.h>
+#ifndef WIN32
 #include <sys/mman.h>
+#endif
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
diff --git a/bse/gslfilehash.c b/bse/gslfilehash.c
index 1fdb64e..fcd662b 100644
--- a/bse/gslfilehash.c
+++ b/bse/gslfilehash.c
@@ -127,6 +127,10 @@ gsl_hfile_open (const gchar *file_name)
     {
       gint fd;
       
+#ifdef WIN32
+#define O_NOCTTY 0
+#endif
+      
       fd = open (file_name, O_RDONLY | O_NOCTTY, 0);
       if (fd >= 0)
 	{
diff --git a/sfi/tests/misctests.c b/sfi/tests/misctests.c
index 7a2e62f..4b4ce90 100644
--- a/sfi/tests/misctests.c
+++ b/sfi/tests/misctests.c
@@ -122,6 +122,7 @@ test_time (void)
 static void
 test_com_ports (void)
 {
+#ifndef WIN32
   gint afds[2], pipe_error;
   SfiComPort *port1, *port2;
   GValue *value, *rvalue;
@@ -164,6 +165,7 @@ test_com_ports (void)
   sfi_com_port_unref (port1);
   sfi_com_port_unref (port2);
   TDONE ();
+#endif
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]