summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Reinauer <stepan@coresystems.de>2010-04-24 01:15:17 +0200
committerLuc Verhaegen <libv@skynet.be>2010-04-24 01:15:17 +0200
commit6ed57e5682e50088766faaaa680767d16be537a2 (patch)
treeb667e3ee8d6add4c7f275cbcc24a175ff8d1f1ef
parent0d7005b34a36b7d2b575dcfbfe5cbe7ec8bb1fee (diff)
Add compatibility code for OSX.
-rw-r--r--Makefile2
-rw-r--r--ami.c1
-rw-r--r--award.c1
-rw-r--r--bios_extract.c2
-rw-r--r--compat.c65
-rw-r--r--compat.h45
-rw-r--r--lh5_extract.c14
-rw-r--r--phoenix.c1
8 files changed, 114 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index d381c1d..0313dad 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ CC = gcc
all: bios_extract bcpvpd ami_slab
-BIOS_EXTRACT_OBJS = lh5_extract.o ami.o award.o phoenix.o bios_extract.o
+BIOS_EXTRACT_OBJS = lh5_extract.o ami.o award.o phoenix.o bios_extract.o compat.o
bios_extract: $(BIOS_EXTRACT_OBJS)
$(CC) $(CFLAGS) $(BIOS_EXTRACT_OBJS) -o bios_extract
diff --git a/ami.c b/ami.c
index 644d965..57cc064 100644
--- a/ami.c
+++ b/ami.c
@@ -27,7 +27,6 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
-#include <endian.h>
#include "bios_extract.h"
#include "lh5_extract.h"
diff --git a/award.c b/award.c
index 479cfce..3108bea 100644
--- a/award.c
+++ b/award.c
@@ -23,6 +23,7 @@
#include <string.h>
#include <sys/mman.h>
+#include "compat.h"
#include "bios_extract.h"
#include "lh5_extract.h"
diff --git a/bios_extract.c b/bios_extract.c
index 32b5aab..cd87ee8 100644
--- a/bios_extract.c
+++ b/bios_extract.c
@@ -25,7 +25,7 @@
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
-
+#include "compat.h"
#include "bios_extract.h"
static void
diff --git a/compat.c b/compat.c
new file mode 100644
index 0000000..8b05ed5
--- /dev/null
+++ b/compat.c
@@ -0,0 +1,65 @@
+/*
+ * Decompression utility for AMI BIOSes.
+ *
+ * Copyright (C) 2009-2010 coresystems GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __APPLE__
+void *memmem(const void *haystack, size_t haystacklen, const void *needle,
+ size_t needlelen)
+{
+ char *searchpointer = (char *) haystack;
+ char *patternpointer = (char *) needle;
+ char *endofsearch = searchpointer + haystacklen - needlelen;
+
+ if (!(haystack && needle && haystacklen && needlelen))
+ return NULL;
+
+ while (searchpointer <= endofsearch) {
+ if (*searchpointer == *patternpointer)
+ if (memcmp
+ (searchpointer, patternpointer,
+ needlelen) == 0)
+ return searchpointer;
+
+ searchpointer++;
+ }
+
+ return NULL;
+}
+
+size_t strnlen(const char *s, size_t maxlen)
+{
+ const char *end = memchr(s, '\0', maxlen);
+ return end ? (size_t) (end - s) : maxlen;
+}
+
+char *strndup(const char *s, size_t n)
+{
+ size_t len = strnlen(s, n);
+ char *new = malloc(len + 1);
+
+ if (new == NULL)
+ return NULL;
+
+ new[len] = '\0';
+ return memcpy(new, s, len);
+}
+#endif
diff --git a/compat.h b/compat.h
new file mode 100644
index 0000000..12cbae7
--- /dev/null
+++ b/compat.h
@@ -0,0 +1,45 @@
+/*
+ * Decompression utility for AMI BIOSes.
+ *
+ * Copyright (C) 2009-2010 coresystems GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifdef __APPLE__
+void *memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen);
+size_t strnlen(const char *s, size_t maxlen);
+char *strndup(const char *s, size_t n);
+#endif
+
+// "endian.h" does not exist on (at least) these platforms:
+// FreeBSD, NetBSD, OSF/Tru64, HP-UX 10, Solaris, A/UX, Ultrix and
+// AIX. It exists on Linux and Irix
+#ifdef __linux__
+#include <endian.h>
+#endif
+
+#if !defined(le32toh) || !defined(le16toh)
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define le32toh(x) (x)
+#define le16toh(x) (x)
+#else
+#include <byteswap.h>
+#define le32toh(x) bswap_32(x)
+#define le16toh(x) bswap_16(x)
+#endif
+#endif
+
+
diff --git a/lh5_extract.c b/lh5_extract.c
index 0df2c3d..fb83383 100644
--- a/lh5_extract.c
+++ b/lh5_extract.c
@@ -32,21 +32,9 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <endian.h>
-
+#include "compat.h"
#include "lh5_extract.h"
-#if !defined(le32toh) || !defined(le16toh)
-#if BYTE_ORDER == LITTLE_ENDIAN
-#define le32toh(x) (x)
-#define le16toh(x) (x)
-#else
-#include <byteswap.h>
-#define le32toh(x) bswap_32(x)
-#define le16toh(x) bswap_16(x)
-#endif
-#endif
-
/*
*
* LHA header parsing.
diff --git a/phoenix.c b/phoenix.c
index dd630a1..afdc376 100644
--- a/phoenix.c
+++ b/phoenix.c
@@ -26,7 +26,6 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/mman.h>
-#include <endian.h>
#include "bios_extract.h"
#include "lh5_extract.h"