Some pre-POSIX systems don't have unistd.h (but e.g. lib.c).
Allow configuring the name of that header file.
diff --git a/crypto/bf/bf_opts.c b/crypto/bf/bf_opts.c
index a0663b5..5f330cc 100644
--- a/crypto/bf/bf_opts.c
+++ b/crypto/bf/bf_opts.c
@@ -64,12 +64,11 @@
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern void exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
 #ifndef _IRIX
 #include <time.h>
diff --git a/crypto/bf/bfspeed.c b/crypto/bf/bfspeed.c
index bc6cd8d..9b893e9 100644
--- a/crypto/bf/bfspeed.c
+++ b/crypto/bf/bfspeed.c
@@ -64,12 +64,11 @@
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern int exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
 #ifndef _IRIX
 #include <time.h>
diff --git a/crypto/cast/cast_spd.c b/crypto/cast/cast_spd.c
index 47af963..c072690 100644
--- a/crypto/cast/cast_spd.c
+++ b/crypto/cast/cast_spd.c
@@ -64,12 +64,11 @@
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern int exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
 #ifndef _IRIX
 #include <time.h>
diff --git a/crypto/cast/castopts.c b/crypto/cast/castopts.c
index 25c40af..642e972 100644
--- a/crypto/cast/castopts.c
+++ b/crypto/cast/castopts.c
@@ -64,12 +64,11 @@
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern void exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
 #ifndef _IRIX
 #include <time.h>
diff --git a/crypto/des/des.c b/crypto/des/des.c
index 91d7967..32ddf1b 100644
--- a/crypto/des/des.c
+++ b/crypto/des/des.c
@@ -60,7 +60,8 @@
 #include <stdlib.h>
 #ifndef MSDOS
 #ifndef VMS
-#include <unistd.h>
+#include <openssl/opensslconf.h>
+#include OPENSSL_UNISTD
 #else /* VMS */
 #ifdef __DECC
 #include <unistd.h>
diff --git a/crypto/des/des_locl.h b/crypto/des/des_locl.h
index c9312f8..a44da79 100644
--- a/crypto/des/des_locl.h
+++ b/crypto/des/des_locl.h
@@ -67,15 +67,16 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#include <openssl/opensslconf.h>
+
 #ifndef MSDOS
 #if !defined(VMS) || defined(__DECC)
-#include <unistd.h>
+#include OPENSSL_UNISTD
 #endif
 #endif
 #include <openssl/des.h>
 
-#include <openssl/opensslconf.h>
-
 #ifdef MSDOS		/* Visual C++ 2.1 (Windows NT/95) */
 #include <stdlib.h>
 #include <errno.h>
diff --git a/crypto/des/des_opts.c b/crypto/des/des_opts.c
index 500509e..746c456 100644
--- a/crypto/des/des_opts.c
+++ b/crypto/des/des_opts.c
@@ -65,7 +65,8 @@
 
 #include <stdio.h>
 #ifndef MSDOS
-#include <unistd.h>
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD
 #else
 #include <io.h>
 extern void exit();
diff --git a/crypto/des/destest.c b/crypto/des/destest.c
index 0054fb9..d92fabd 100644
--- a/crypto/des/destest.c
+++ b/crypto/des/destest.c
@@ -66,7 +66,8 @@
 #include <stdlib.h>
 #ifndef MSDOS
 #if !defined(VMS) || defined(__DECC)
-#include <unistd.h>
+#include <openssl/opensslconf.h>
+#include OPENSSL_UNISTD
 #endif /* VMS */
 #else
 #include <io.h>
diff --git a/crypto/des/read_pwd.c b/crypto/des/read_pwd.c
index d280aa1..7639fc0 100644
--- a/crypto/des/read_pwd.c
+++ b/crypto/des/read_pwd.c
@@ -57,7 +57,8 @@
  */
 
 #if !defined(MSDOS) && !defined(VMS) && !defined(WIN32)
-#include <unistd.h>
+#include <openssl/opensslconf.h>
+#include OPENSSL_UNISTD
 /* If unistd.h defines _POSIX_VERSION, we conclude that we
  * are on a POSIX system and have sigaction and termios. */
 #if defined(_POSIX_VERSION)
diff --git a/crypto/des/speed.c b/crypto/des/speed.c
index ed3b760..da41abc 100644
--- a/crypto/des/speed.c
+++ b/crypto/des/speed.c
@@ -64,12 +64,11 @@
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern int exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
 #ifndef _IRIX
 #include <time.h>
diff --git a/crypto/idea/idea_spd.c b/crypto/idea/idea_spd.c
index 3c24ff5..5f79f93 100644
--- a/crypto/idea/idea_spd.c
+++ b/crypto/idea/idea_spd.c
@@ -64,12 +64,11 @@
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern int exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
 #ifndef _IRIX
 #include <time.h>
diff --git a/crypto/opensslconf.h.in b/crypto/opensslconf.h.in
index 5c9ee25..e4a8f8a 100644
--- a/crypto/opensslconf.h.in
+++ b/crypto/opensslconf.h.in
@@ -10,6 +10,8 @@
 #endif
 #endif
 
+#define OPENSSL_UNISTD <unistd.h>
+
 #if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
 #define IDEA_INT unsigned int
 #endif
diff --git a/crypto/rc2/rc2speed.c b/crypto/rc2/rc2speed.c
index 5e747c9..c3da63e 100644
--- a/crypto/rc2/rc2speed.c
+++ b/crypto/rc2/rc2speed.c
@@ -64,12 +64,11 @@
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern int exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
 #ifndef _IRIX
 #include <time.h>
diff --git a/crypto/rc4/rc4speed.c b/crypto/rc4/rc4speed.c
index 40d153a..4fb5ebf 100644
--- a/crypto/rc4/rc4speed.c
+++ b/crypto/rc4/rc4speed.c
@@ -64,12 +64,11 @@
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern int exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
 #ifndef _IRIX
 #include <time.h>
diff --git a/crypto/rc5/rc5speed.c b/crypto/rc5/rc5speed.c
index ae263a1..c563662 100644
--- a/crypto/rc5/rc5speed.c
+++ b/crypto/rc5/rc5speed.c
@@ -64,12 +64,11 @@
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern int exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
 #ifndef _IRIX
 #include <time.h>