From 9d7fd73efaf1c5a0a0fdc085af7015fd2978d495 Mon Sep 17 00:00:00 2001
From: begasus <begasus@gmail.com>
Date: Sun, 30 Apr 2017 16:59:12 +0200
Subject: [PATCH] Add check for <sys/select.h> and use it

POSIX says it's required for 'fd_set', and Haiku needs it.
---
 config.h.in  | 3 +++
 configure.in | 2 +-
 src/mms.c    | 3 +++
 src/mmsh.c   | 3 +++
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/config.h.in b/config.h.in
index 8a8fc8f..7cf91ce 100644
--- a/config.h.in
+++ b/config.h.in
@@ -30,6 +30,9 @@
 /* Define to 1 if you have the <string.h> header file. */
 #undef HAVE_STRING_H
 
+/* Define to 1 if you have the <sys/select.h> header file. */
+#undef HAVE_SYS_SELECT_H
+
 /* Define to 1 if you have the <sys/socket.h> header file. */
 #undef HAVE_SYS_SOCKET_H
 
diff --git a/configure.in b/configure.in
index 86b0e08..9dccc63 100755
--- a/configure.in
+++ b/configure.in
@@ -13,7 +13,7 @@ AC_PROG_LIBTOOL
 AC_PROG_INSTALL
 
 dnl Checks for header files.
-AC_CHECK_HEADERS([sys/socket.h netinet/in.h netdb.h windows.h winsock2.h])
+AC_CHECK_HEADERS([sys/select.h sys/socket.h netinet/in.h netdb.h windows.h winsock2.h])
 
 case $host in
     *beos*)
diff --git a/src/mms.c b/src/mms.c
index c1dbc29..1a0aff7 100644
--- a/src/mms.c
+++ b/src/mms.c
@@ -52,6 +52,9 @@
 #endif
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
diff --git a/src/mmsh.c b/src/mmsh.c
index a019f05..6562ce2 100755
--- a/src/mmsh.c
+++ b/src/mmsh.c
@@ -55,6 +55,9 @@
 #endif
 #include <string.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
-- 
2.19.1

From a9f692323e597324e6f01263c12b6f4290d5b56f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Wed, 27 Mar 2019 02:14:37 +0100
Subject: [PATCH 2/2] C89 fixes for Haiku

---
 src/mms-common-funcs.h | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/mms-common-funcs.h b/src/mms-common-funcs.h
index 9e3c21d..f273756 100644
--- a/src/mms-common-funcs.h
+++ b/src/mms-common-funcs.h
@@ -205,12 +205,14 @@ static void interp_asf_header(TYPE *this)
 
       case GUID_ASF_HEADER_EXTENSION:
         {
+          int size;
+          int j = 24 + 18 + 4;
+          int l;
+
           if ((24 + 18 + 4) > length)
             break;
 
-          int size = LE_32(this->asf_header + i + 24 + 18);
-          int j = 24 + 18 + 4;
-          int l;
+          size = LE_32(this->asf_header + i + 24 + 18);
           lprintf("Extension header data size: %d\n", size);
 
           while ((j + 24) <= length) {
@@ -249,16 +251,18 @@ static void interp_asf_header(TYPE *this)
 
                   // Loop through the number of extension system info
                   for (x = 0; x < ext_count && (ext_j + 22) <= l; x++) {
+                    int len;
                     ext_j += 18;
-                    int len = LE_16(this->asf_header + i + j + ext_j);
+                    len = LE_16(this->asf_header + i + j + ext_j);
                     ext_j += 4 + len;
                   }
 
                   lprintf("ext_j: %d\n", ext_j);
                   // Finally, we arrive at the interesting point: The optional Stream Property Object
                   if ((ext_j + 24) <= l) {
+                    int len;
                     guid = get_guid(this->asf_header, i + j + ext_j);
-                    int len = LE_64(this->asf_header + i + j + ext_j + 16);
+                    len = LE_64(this->asf_header + i + j + ext_j + 16);
                     if (guid == GUID_ASF_STREAM_PROPERTIES &&
                         (ext_j + len) <= l) {
                       interp_stream_properties(this, i + j + ext_j + 24);
-- 
2.19.1

