--- a/action.c
+++ b/action.c
@@ -39,6 +39,7 @@
 #include <limits.h>
 #include <errno.h>
 
+#include "haiku_macros.h"
 #include "squashfs_fs.h"
 #include "mksquashfs.h"
 #include "action.h"
@@ -1953,9 +1957,12 @@ static char *get_start(char *s, int n)
 
 static int subpathname_fn(struct atom *atom, struct action_data *action_data)
 {
-	return fnmatch(atom->argv[0], get_start(strdupa(action_data->subpath),
-		count_components(atom->argv[0])),
-		FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;
+	char *dup = strdup(action_data->subpath);
+	int ret = fnmatch(atom->argv[0], get_start(dup,
+			count_components(atom->argv[0])),
+			FNM_PATHNAME|FNM_PERIOD|FNM_EXTMATCH) == 0;
+	free(dup);
+	return ret;
 }
 
 TEST_VAR_FN(filesize, ACTION_REG, action_data->buf->st_size)
--- /dev/null
+++ b/haiku_macros.h
@@ -0,0 +1,14 @@
+#ifndef HAIKU_MACROS_H
+#define HAIKU_MACROS_H
+
+/* Haiku does not provide these */
+#define major(x) ((int)(0x00ff & ((x) >> 8)))
+#define minor(x) ((int)(0xffff00ff & (x)))
+#define makedev(maj,min) ((0xff00 & ((maj)<<8))|(0xffff00ff & (min)))
+
+/* Mirroring a patch accepted to upstream after the release */
+#ifndef FNM_EXTMATCH
+#define FNM_EXTMATCH 0
+#endif
+
+#endif /* HAIKU_MACROS_H */
--- a/mksquashfs.c
+++ b/mksquashfs.c
@@ -55,7 +55,7 @@
 #define __BYTE_ORDER BYTE_ORDER
 #define __BIG_ENDIAN BIG_ENDIAN
 #define __LITTLE_ENDIAN LITTLE_ENDIAN
-#include <sys/sysctl.h>
+#include "haiku_macros.h"
 #else
 #include <endian.h>
 #include <sys/sysinfo.h>
@@ -4105,7 +4109,7 @@ void initialise_threads(int readq, int fragq, int bwriteq, int fwriteq,
 		BAD_ERROR("Failed to set signal mask in intialise_threads\n");
 
 	if(processors == -1) {
-#ifndef linux
+#if !defined(linux) && !defined(__HAIKU__)
 		int mib[2];
 		size_t len = sizeof(processors);

--- a/unsquashfs.c
+++ b/unsquashfs.c
@@ -31,7 +31,7 @@
 #include "unsquashfs_info.h"
 #include "stdarg.h"
+#include "haiku_macros.h"
 
-#include <sys/sysinfo.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/resource.h>
@@ -2190,7 +2193,7 @@ void initialise_threads(int fragment_buffer_size, int data_buffer_size)
 			"\n");
 
 	if(processors == -1) {
-#ifndef linux
+#if !defined(linux) && !defined(__HAIKU__)
 		int mib[2];
 		size_t len = sizeof(processors);
 
