diff --git a/System/Posix/Error.hs b/System/Posix/Error.hs
--- a/System/Posix/Error.hs
+++ b/System/Posix/Error.hs
@@ -18,7 +18,7 @@
 	throwErrnoPathIf_,
 	throwErrnoPathIfNull,
 	throwErrnoPathIfMinus1,
-	throwErrnoPathIfMinus1_
+	throwErrnoPathIfMinus1_,
   ) where
 
 import Foreign.C.Error
diff --git a/System/Posix/IO.hsc b/System/Posix/IO.hsc
--- a/System/Posix/IO.hsc
+++ b/System/Posix/IO.hsc
@@ -179,7 +179,7 @@
 openFd name how maybe_mode (OpenFileFlags appendFlag exclusiveFlag nocttyFlag
 				nonBlockFlag truncateFlag) = do
    withCString name $ \s -> do
-    fd <- throwErrnoPathIfMinus1 "openFd" name (c_open s all_flags mode_w)
+    fd <- throwErrnoPathIfMinus1Retry "openFd" name (c_open s all_flags mode_w)
     return (Fd fd)
   where
     all_flags  = creat .|. flags .|. open_mode
@@ -200,6 +200,22 @@
 		   WriteOnly -> (#const O_WRONLY)
 		   ReadWrite -> (#const O_RDWR)
 
+    throwErrnoPathIfMinus1Retry :: Num a => String -> FilePath -> IO a -> IO a
+    throwErrnoPathIfMinus1Retry loc path f =
+      throwErrnoPathIfRetry (== -1) loc path f
+
+    throwErrnoPathIfRetry :: (a -> Bool) -> String -> FilePath -> IO a -> IO a
+    throwErrnoPathIfRetry pr loc path f =
+      do
+        res <- f
+        if pr res
+          then do
+            err <- getErrno
+            if err == eINTR
+              then throwErrnoPathIfRetry pr loc path f
+              else throwErrnoPath loc path
+          else return res
+
 foreign import ccall unsafe "__hscore_open"
    c_open :: CString -> CInt -> CMode -> IO CInt
 
@@ -238,7 +254,17 @@
 
 #ifdef __GLASGOW_HASKELL__
 #if __GLASGOW_HASKELL__ >= 611
-handleToFd h = withHandle "handleToFd" h $ \ h_@Handle__{haType=_,..} -> do
+handleToFd h@(FileHandle _ m) = do
+  withHandle' "handleToFd" h m $ handleToFd' h
+handleToFd h@(DuplexHandle _ r w) = do
+  _ <- withHandle' "handleToFd" h r $ handleToFd' h
+  withHandle' "handleToFd" h w $ handleToFd' h
+  -- for a DuplexHandle, make sure we mark both sides as closed,
+  -- otherwise a finalizer will come along later and close the other
+  -- side. (#3914)
+
+handleToFd' :: Handle -> Handle__ -> IO (Handle__, Fd)
+handleToFd' h h_@Handle__{haType=_,..} = do
   case cast haDevice of
     Nothing -> ioError (ioeSetErrorString (mkIOError IllegalOperation
                                            "handleToFd" (Just h) Nothing) 
diff --git a/System/Posix/SharedMem.hsc b/System/Posix/SharedMem.hsc
--- a/System/Posix/SharedMem.hsc
+++ b/System/Posix/SharedMem.hsc
@@ -21,7 +21,7 @@
 
 #include <sys/types.h>
 #include <sys/mman.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
 
 #include "HsUnix.h"
 
diff --git a/System/Posix/Signals.hsc b/System/Posix/Signals.hsc
--- a/System/Posix/Signals.hsc
+++ b/System/Posix/Signals.hsc
@@ -295,7 +295,7 @@
 raiseSignal :: Signal -> IO ()
 raiseSignal sig = throwErrnoIfMinus1_ "raiseSignal" (c_raise sig)
 
-#if defined(__GLASGOW_HASKELL__) && (defined(openbsd_HOST_OS) || defined(freebsd_HOST_OS))
+#if defined(__GLASGOW_HASKELL__) && (defined(openbsd_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS))
 foreign import ccall unsafe "genericRaise"
   c_raise :: CInt -> IO CInt
 #else
diff --git a/System/Posix/Temp.hsc b/System/Posix/Temp.hsc
--- a/System/Posix/Temp.hsc
+++ b/System/Posix/Temp.hsc
@@ -4,7 +4,7 @@
 -- Module      :  System.Posix.Temp
 -- Copyright   :  (c) Volker Stolz <vs@foldr.org>
 -- License     :  BSD-style (see the file libraries/base/LICENSE)
--- 
+--
 -- Maintainer  :  vs@foldr.org
 -- Stability   :  provisional
 -- Portability :  non-portable (requires POSIX)
@@ -15,12 +15,12 @@
 
 module System.Posix.Temp (
 
-	mkstemp
+    mkstemp
 
 {- Not ported (yet?):
-	tmpfile: can we handle FILE*?
-	tmpnam: ISO C, should go in base?
-	tempname: dito
+    tmpfile: can we handle FILE*?
+    tmpnam: ISO C, should go in base?
+    tempname: dito
 -}
 
 ) where
@@ -33,9 +33,10 @@
 import Foreign.C
 
 -- |'mkstemp' - make a unique filename and open it for
--- reading\/writing (only safe on GHC & Hugs)
-
-mkstemp :: String -> IO (String, Handle)
+-- reading\/writing (only safe on GHC & Hugs).
+-- The returned 'FilePath' is the (possibly relative) path of
+-- the created file.
+mkstemp :: String -> IO (FilePath, Handle)
 mkstemp template = do
 #if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
   withCString template $ \ ptr -> do
diff --git a/System/Posix/User.hsc b/System/Posix/User.hsc
--- a/System/Posix/User.hsc
+++ b/System/Posix/User.hsc
@@ -222,7 +222,7 @@
 getAllGroupEntries :: IO [GroupEntry]
 #ifdef HAVE_GETGRENT
 getAllGroupEntries =
-    withMVar lock $ \_ -> worker []
+    withMVar lock $ \_ -> bracket_ c_setgrent c_endgrent $ worker []
     where worker accum =
               do resetErrno
                  ppw <- throwErrnoIfNullAndError "getAllGroupEntries" $ 
@@ -234,6 +234,10 @@
 
 foreign import ccall unsafe "getgrent"
   c_getgrent :: IO (Ptr CGroup)
+foreign import ccall unsafe "setgrent"
+  c_setgrent :: IO ()
+foreign import ccall unsafe "endgrent"
+  c_endgrent :: IO ()
 #else
 getAllGroupEntries = error "System.Posix.User.getAllGroupEntries: not supported"
 #endif
diff --git a/config.guess b/config.guess
--- a/config.guess
+++ b/config.guess
@@ -1199,6 +1199,9 @@
     BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
 	echo i586-pc-beos
 	exit ;;
+    BePC:Haiku:*:*)	# BeOS running on Intel PC compatible.
+	echo i586-pc-haiku
+	exit ;;
     SX-4:SUPER-UX:*:*)
 	echo sx4-nec-superux${UNAME_RELEASE}
 	exit ;;
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -1268,6 +1268,11 @@
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
   --disable-largefile     omit support for large files
 
+Optional Packages:
+  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
+C compiler
+
 Some influential environment variables:
   CC          C compiler command
   CFLAGS      C compiler flags
@@ -1713,10 +1718,12 @@
 # Safety check: Ensure that we are in the correct source directory.
 
 
-ac_config_headers="$ac_config_headers include/HsUnixConfig.h"
 
+# Check whether --with-cc was given.
+if test "${with_cc+set}" = set; then
+  withval=$with_cc; CC=$withval
+fi
 
-# Is this a Unix system?
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -2637,6 +2644,11 @@
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
+ac_config_headers="$ac_config_headers include/HsUnixConfig.h"
+
+
+# Is this a Unix system?
+
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -5904,7 +5916,7 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include </usr/include/unistd.h>
+#include <unistd.h>
 
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
@@ -5941,7 +5953,7 @@
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-#include </usr/include/stdlib.h>
+#include <stdlib.h>
 
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -3,6 +3,11 @@
 # Safety check: Ensure that we are in the correct source directory.
 AC_CONFIG_SRCDIR([include/HsUnix.h])
 
+AC_ARG_WITH([cc],
+            [C compiler],
+            [CC=$withval])
+AC_PROG_CC()
+
 AC_CONFIG_HEADERS([include/HsUnixConfig.h])
 
 # Is this a Unix system?
@@ -66,13 +71,12 @@
 
 dnl ---------- usleep ----------
 dnl --- stolen from guile configure ---
-dnl --- FIXME: /usr/include/unistd.h can't be right?
 
 ### On some systems usleep has no return value.  If it does have one,
 ### we'd like to return it; otherwise, we'll fake it.
 AC_CACHE_CHECK([return type of usleep], fptools_cv_func_usleep_return_type,
   [AC_EGREP_HEADER(changequote(<, >)<void[      ]+usleep>changequote([, ]),
-                   /usr/include/unistd.h,
+                   unistd.h,
                    [fptools_cv_func_usleep_return_type=void],
                    [fptools_cv_func_usleep_return_type=int])])
 case "$fptools_cv_func_usleep_return_type" in
@@ -85,7 +89,7 @@
 ###  in common use return void.
 AC_CACHE_CHECK([return type of unsetenv], fptools_cv_func_unsetenv_return_type,
   [AC_EGREP_HEADER(changequote(<, >)<void[      ]+unsetenv>changequote([, ]),
-                   /usr/include/stdlib.h,
+                   stdlib.h,
                    [fptools_cv_func_unsetenv_return_type=void],
                    [fptools_cv_func_unsetenv_return_type=int])])
 case "$fptools_cv_func_unsetenv_return_type" in
diff --git a/include/HsUnixConfig.h b/include/HsUnixConfig.h
--- a/include/HsUnixConfig.h
+++ b/include/HsUnixConfig.h
@@ -140,7 +140,7 @@
 #define HAVE_LCHOWN 1
 
 /* Define to 1 if you have the <libutil.h> header file. */
-/* #undef HAVE_LIBUTIL_H */
+#define HAVE_LIBUTIL_H 1
 
 /* Define to 1 if you have the <limits.h> header file. */
 #define HAVE_LIMITS_H 1
@@ -281,7 +281,7 @@
 /* #undef USLEEP_RETURNS_VOID */
 
 /* Number of bits in a file offset, on hosts where this is settable. */
-/* #undef _FILE_OFFSET_BITS */
+#define _FILE_OFFSET_BITS 64
 
 /* Define for large files, on AIX-style hosts. */
 /* #undef _LARGE_FILES */
diff --git a/unix.cabal b/unix.cabal
--- a/unix.cabal
+++ b/unix.cabal
@@ -1,5 +1,5 @@
 name:		unix
-version:	2.4.0.0
+version:	2.4.0.1
 license:	BSD3
 license-file:	LICENSE
 maintainer:	libraries@haskell.org
@@ -47,7 +47,7 @@
         System.Posix.Signals.Exts
         System.Posix.Semaphore
         System.Posix.SharedMem
-    build-depends:	base >= 4.1 && < 4.3
+    build-depends:	base >= 4.2 && < 4.3
     extensions:	CPP, ForeignFunctionInterface, EmptyDataDecls
     include-dirs: 	include
     includes:       HsUnix.h execvpe.h
