From bc4bd179bda49b615a1c40df7402ddf80bf775b2 Mon Sep 17 00:00:00 2001
From: Herbert Valerio Riedel <hvr@gnu.org>
Date: Thu, 7 Aug 2014 12:33:51 +0200
Subject: [PATCH] Use CAPI FFI imports for `truncate`

This makes sure we pick up the LFS version of `truncate` in case `off_t`
is affected by CPP defines such as `_FILE_OFFSET_BITS`.
---
 System/Posix/Files.hsc            | 4 +++-
 System/Posix/Files/ByteString.hsc | 4 +++-
 changelog.md                      | 2 ++
 configure.ac                      | 3 +++
 4 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/System/Posix/Files.hsc b/System/Posix/Files.hsc
index c8b5ddf..1822294 100644
--- a/System/Posix/Files.hsc
+++ b/System/Posix/Files.hsc
@@ -1,6 +1,8 @@
 #ifdef __GLASGOW_HASKELL__
 {-# LANGUAGE Trustworthy #-}
 #endif
+{-# LANGUAGE CApiFFI #-}
+
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  System.Posix.Files
@@ -420,7 +422,7 @@ setFileSize file off =
   withFilePath file $ \s ->
     throwErrnoPathIfMinus1_ "setFileSize" file (c_truncate s off)
 
-foreign import ccall unsafe "truncate"
+foreign import capi unsafe "HsUnix.h truncate"
   c_truncate :: CString -> COff -> IO CInt
 
 -- -----------------------------------------------------------------------------
diff --git a/System/Posix/Files/ByteString.hsc b/System/Posix/Files/ByteString.hsc
index 80f0bea..cb68668 100644
--- a/System/Posix/Files/ByteString.hsc
+++ b/System/Posix/Files/ByteString.hsc
@@ -1,6 +1,8 @@
 #ifdef __GLASGOW_HASKELL__
 {-# LANGUAGE Trustworthy #-}
 #endif
+{-# LANGUAGE CApiFFI #-}
+
 -----------------------------------------------------------------------------
 -- |
 -- Module      :  System.Posix.Files.ByteString
@@ -420,7 +422,7 @@ setFileSize file off =
   withFilePath file $ \s ->
     throwErrnoPathIfMinus1_ "setFileSize" file (c_truncate s off)
 
-foreign import ccall unsafe "truncate"
+foreign import capi unsafe "HsUnix.h truncate"
   c_truncate :: CString -> COff -> IO CInt
 
 -- -----------------------------------------------------------------------------
diff --git a/changelog.md b/changelog.md
index c481922..66caaeb 100644
--- a/changelog.md
+++ b/changelog.md
@@ -12,6 +12,8 @@
     convention
   * Fix potential type-mismatch in `telldir`/`seekdir` FFI imports
 
+  * Use CAPI FFI import for `truncate` to make sure the LFS-version is used.
+
 ## 2.7.0.1  *Mar 2014*
 
   * Bundled with GHC 7.8.1
diff --git a/configure.ac b/configure.ac
index 41274dc..c10bf89 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,6 +18,9 @@ AC_C_CONST
 
 dnl ** Enable large file support.  NB. do this before testing the type of
 dnl    off_t, because it will affect the result of that test.
+dnl
+dnl WARNING: It's essential this check agrees with HsBaseConfig.h as otherwise
+dnl          the definitions of COff/coff_t don't line up
 AC_SYS_LARGEFILE
 
 AC_CHECK_HEADERS([dirent.h fcntl.h grp.h limits.h pwd.h signal.h string.h])
-- 
GitLab