diff --git a/System/Posix/Terminal.hsc b/System/Posix/Terminal.hsc
index c1b3ff835de7e135df6ba42302288a37f7d68d84..0545f401995d7ce3c005f4d63c50fa2fb64d12fa 100644
--- a/System/Posix/Terminal.hsc
+++ b/System/Posix/Terminal.hsc
@@ -134,8 +134,14 @@ getSlaveTerminalName (Fd fd) = do
   s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd)
   peekFilePath s
 
+# if __GLASGOW_HASKELL__ < 800
+-- see comment in cbits/HsUnix.c
 foreign import ccall unsafe "__hsunix_ptsname"
   c_ptsname :: CInt -> IO CString
+# else
+foreign import capi unsafe "HsUnix.h ptsname"
+  c_ptsname :: CInt -> IO CString
+# endif
 #else
 getSlaveTerminalName _ =
     ioError (errnoToIOError "getSlaveTerminalName" eNOSYS Nothing Nothing)
@@ -188,11 +194,20 @@ foreign import ccall unsafe "__hsunix_push_module"
   c_push_module :: CInt -> CString -> IO CInt
 
 #ifdef HAVE_PTSNAME
+# if __GLASGOW_HASKELL__ < 800
+-- see comment in cbits/HsUnix.c
 foreign import ccall unsafe "__hsunix_grantpt"
   c_grantpt :: CInt -> IO CInt
 
 foreign import ccall unsafe "__hsunix_unlockpt"
   c_unlockpt :: CInt -> IO CInt
+# else
+foreign import capi unsafe "HsUnix.h grantpt"
+  c_grantpt :: CInt -> IO CInt
+
+foreign import capi unsafe "HsUnix.h unlockpt"
+  c_unlockpt :: CInt -> IO CInt
+# endif
 #else
 c_grantpt :: CInt -> IO CInt
 c_grantpt _ = return (fromIntegral 0)
diff --git a/System/Posix/Terminal/ByteString.hsc b/System/Posix/Terminal/ByteString.hsc
index d98a9c002878867ed99a54984e0633b64ccfe2dc..cd6e20000fd827590c2c062936cf8cda2faa3e1f 100644
--- a/System/Posix/Terminal/ByteString.hsc
+++ b/System/Posix/Terminal/ByteString.hsc
@@ -142,8 +142,14 @@ getSlaveTerminalName (Fd fd) = do
   s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd)
   peekFilePath s
 
+# if __GLASGOW_HASKELL__ < 800
+-- see comment in cbits/HsUnix.c
 foreign import ccall unsafe "__hsunix_ptsname"
   c_ptsname :: CInt -> IO CString
+# else
+foreign import capi unsafe "HsUnix.h ptsname"
+  c_ptsname :: CInt -> IO CString
+# endif
 #else
 getSlaveTerminalName _ =
     ioError (errnoToIOError "getSlaveTerminalName" eNOSYS Nothing Nothing)
@@ -195,12 +201,21 @@ pushModule (Fd fd) name =
 foreign import ccall unsafe "__hsunix_push_module"
   c_push_module :: CInt -> CString -> IO CInt
 
-#ifdef HAVE_PTSNAME
+#if HAVE_PTSNAME
+# if __GLASGOW_HASKELL__ < 800
+-- see comment in cbits/HsUnix.c
 foreign import ccall unsafe "__hsunix_grantpt"
   c_grantpt :: CInt -> IO CInt
 
 foreign import ccall unsafe "__hsunix_unlockpt"
   c_unlockpt :: CInt -> IO CInt
+# else
+foreign import capi unsafe "HsUnix.h grantpt"
+  c_grantpt :: CInt -> IO CInt
+
+foreign import capi unsafe "HsUnix.h unlockpt"
+  c_unlockpt :: CInt -> IO CInt
+# endif
 #else
 c_grantpt :: CInt -> IO CInt
 c_grantpt _ = return (fromIntegral (0::Int))
diff --git a/cbits/HsUnix.c b/cbits/HsUnix.c
index 25fd8adf528e17b9b203aa1acec83f6fa614d2f1..5742b49a99c1a10c6489ca171b9efee49e3b9987 100644
--- a/cbits/HsUnix.c
+++ b/cbits/HsUnix.c
@@ -16,25 +16,14 @@ void *__hsunix_rtldNext (void) {return RTLD_NEXT;}
 void *__hsunix_rtldDefault (void) {return RTLD_DEFAULT;}
 #endif
 
-#ifdef HAVE_PTSNAME
+#if HAVE_PTSNAME && (__GLASGOW_HASKELL__ < 800)
 // On Linux (and others), <stdlib.h> needs to be included while
 // `_XOPEN_SOURCE` is already defined. However, GHCs before GHC 8.0
 // didn't do that yet for CApiFFI, so we need this workaround here.
 
-char *__hsunix_ptsname(int fd)
-{
-    return ptsname(fd);
-}
-
-int __hsunix_grantpt(int fd)
-{
-    return grantpt(fd);
-}
-
-int __hsunix_unlockpt(int fd)
-{
-    return unlockpt(fd);
-}
+char *__hsunix_ptsname(int fd)   { return ptsname(fd);  }
+int   __hsunix_grantpt(int fd)   { return grantpt(fd);  }
+int   __hsunix_unlockpt(int fd)  { return unlockpt(fd); }
 #endif
 
 // push a SVR4 STREAMS module; do nothing if STREAMS not available
@@ -71,7 +60,6 @@ HsInt __hsunix_long_path_size(void) {
 #endif
 }
 
-
 /*
  * read an entry from the directory stream; opt for the
  * re-entrant friendly way of doing this, if available.
diff --git a/include/HsUnix.h b/include/HsUnix.h
index 2f77d283d67263d93e7f6599340dbb8de9648f58..fb19f99f90454a35c68891903e850ed9207fe694 100644
--- a/include/HsUnix.h
+++ b/include/HsUnix.h
@@ -113,12 +113,6 @@ fall back to O_FSYNC, which should be the same */
 # define WCOREDUMP(s) 0
 #endif
 
-#ifdef HAVE_PTSNAME
-char *__hsunix_ptsname(int fd);
-int __hsunix_grantpt(int fd);
-int __hsunix_unlockpt(int fd);
-#endif
-
 // push a SVR4 STREAMS module; do nothing if STREAMS not available
 int __hsunix_push_module(int fd, const char *module);