diff --git a/src/backend.c b/src/backend.c
index 03fe4536e4fe0eaa19de13964e2a0006921a4348..b0017f348942f7a3c86b77ca9794a349efcd9e40 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -6,7 +6,9 @@
 #include "global.h"
 #include "backend.h"
 #include <errno.h>
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif
 #include <sys/param.h>
 #include <string.h>
 #include "interpret.h"
diff --git a/src/compilation.h b/src/compilation.h
index 4237e2a744284ad4241db1f38b27b675b6f7fa84..51cd82409547567fcd6485caa24722d8474979e8 100644
--- a/src/compilation.h
+++ b/src/compilation.h
@@ -58,7 +58,7 @@
 #define SNAME(X,Y) { \
       struct X *oLd; \
       oLd=Y; Y=oLd->previous;
-#define SEND free(oLd); \
+#define SEND free((char *)oLd); \
     }
 #define PCODE(X) X
 #else
diff --git a/src/configure.in b/src/configure.in
index 31c67ff4e2810e4b16186e8dee8b9808548ed52b..b9ac3554a110c8253d54fbd419eaf965f6ddcf13 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -243,8 +243,8 @@ rm -rf conftest.y y.tab.c y.tab.h conftest.out
 
 AC_HEADER_TIME
 AC_HEADER_STDC
-AC_CHECK_HEADERS(sys/rusage.h time.h sys/time.h unistd.h stdlib.h memory.h \
-values.h string.h fcntl.h sys/filio.h sys/sockio.h crypt.h locale.h \
+AC_CHECK_HEADERS(sys/rusage.h time.h sys/time.h sys/types.h unistd.h stdlib.h \
+memory.h values.h string.h fcntl.h sys/filio.h sys/sockio.h crypt.h locale.h \
 sys/resource.h sys/select.h sys/mman.h setjmp.h)
 
 AC_SIZEOF_TYPE(char *)
diff --git a/src/machine.h.in b/src/machine.h.in
index 4ac151d2ab988022156d565021a418f901038102..97518b9e1ddb7a936651b50ff46053ce190d4f57 100644
--- a/src/machine.h.in
+++ b/src/machine.h.in
@@ -40,6 +40,9 @@
 /* Define if you have the <sys/time.h> header file.  */
 #undef HAVE_SYS_TIME_H
 
+/* Define if you have the <sys/types.h> header file.  */
+#undef HAVE_SYS_TYPES_H
+
 /* Define if you have the <time.h> header file.  */
 #undef HAVE_TIME_H
 
diff --git a/src/modules/files/file.c b/src/modules/files/file.c
index ecbb2d7f32ab7845ace4200bee5b3932760a7e57..d62ea0c98778dab617020c10ea650ceb358169e7 100644
--- a/src/modules/files/file.c
+++ b/src/modules/files/file.c
@@ -22,7 +22,10 @@
 #include "signal_handler.h"
 #include "pike_types.h"
 
+#ifdef HAVE_SYS_TYPE_H
 #include <sys/types.h>
+#endif
+
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <errno.h>
@@ -50,6 +53,10 @@
 #define SEEK_SET 0
 #endif
 
+#ifndef SEEK_SET
+#define SEEK_CUR 1
+#endif
+
 #ifndef SEEK_END
 #define SEEK_END 2
 #endif
diff --git a/src/modules/files/socket.c b/src/modules/files/socket.c
index 6e39273feb4629304c6b145898e7b8bd15960631..803f785b2106f27017821266d6e47aa8e15e20f8 100644
--- a/src/modules/files/socket.c
+++ b/src/modules/files/socket.c
@@ -17,7 +17,10 @@
 #include "file_machine.h"
 #include "file.h"
 
+#ifdef HAVE_SYS_TYPE_H
 #include <sys/types.h>
+#endif
+
 #include <sys/param.h>
 #include <errno.h>
 #include <fcntl.h>
diff --git a/src/opcodes.c b/src/opcodes.c
index 17a81447a7e3b4973040d2177746c586f6457bc6..7ab306973767ba794405f3d3afae38f8a4e4b481 100644
--- a/src/opcodes.c
+++ b/src/opcodes.c
@@ -16,6 +16,7 @@
 #include "object.h"
 #include "error.h"
 #include "pike_types.h"
+#include "memory.h"
 
 void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind)
 {
diff --git a/src/port.c b/src/port.c
index caaa44824c731d07830ecd707f3893113870836c..2a5cf63e36b1e217cc25bda000c7573df44574aa 100644
--- a/src/port.c
+++ b/src/port.c
@@ -8,7 +8,9 @@
 #include "time_stuff.h"
 #include <ctype.h>
 #include <math.h>
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif
 #include <errno.h>
 #include <float.h>
 #include <string.h>
diff --git a/src/port.h b/src/port.h
index 765c4790bc76752a3ff3dbda3f09f6b37531ba78..af8fc0ddbb89805f992d4609a5f69d8491eb6dbd 100644
--- a/src/port.h
+++ b/src/port.h
@@ -77,7 +77,7 @@ char *MEMMOVE(char *b,const char *a,int s);
 #ifndef HAVE_MEMCMP
 int MEMCMP(const char *b,const char *a,int s);
 #else
-#  define MEMCMP memcmp
+#  define MEMCMP(X,Y,Z) memcmp((char*)(X),(char*)(Y),(char*)(Z))
 #endif
 
 #ifndef HAVE_MEMCHR
diff --git a/src/rusage.c b/src/rusage.c
index ae7b796f51204b66c7dc355f0bc628d5fa8c94ac..01b946f810f79dc5dd256aabb0ef492a88d27159 100644
--- a/src/rusage.c
+++ b/src/rusage.c
@@ -4,7 +4,9 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
+#ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif
 #include <sys/stat.h>
 #include "time_stuff.h"
 #include <fcntl.h>
diff --git a/src/types.h b/src/types.h
index 5702bf9643b16e897ef6cdc064d59c6aac767128..511d470f0fafbb99884e5aff0152d521c0fddc89 100644
--- a/src/types.h
+++ b/src/types.h
@@ -31,4 +31,10 @@
 
 #define FLOAT_TYPE float
 
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#undef HAVE_SYS_TYPES_H
+#endif
+
 #endif