From 43343c151f9824a44bd6e353610fdeb23f910c72 Mon Sep 17 00:00:00 2001 From: Herbert Valerio Riedel Date: Thu, 7 Aug 2014 12:23:07 +0200 Subject: Use correct POSIX offset-type for tell/seekdir This fixes the FFI imports to use the proper `CLong` type over the previous incorrect `COff` type, as using the wrong argument type can cause problems when the `long` and `off_t` types have different size. Historic note from the manual page: In glibc up to version 2.1.1, the return type of telldir() was off_t. POSIX.1-2001 specifies long, and this is the type used since glibc 2.1.2 (released in 1999). --- System/Posix/Directory/Common.hsc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'System') diff --git a/System/Posix/Directory/Common.hsc b/System/Posix/Directory/Common.hsc index 86d87ca..7cc61af 100644 --- a/System/Posix/Directory/Common.hsc +++ b/System/Posix/Directory/Common.hsc @@ -62,20 +62,20 @@ newtype DirStreamOffset = DirStreamOffset COff #ifdef HAVE_SEEKDIR seekDirStream :: DirStream -> DirStreamOffset -> IO () seekDirStream (DirStream dirp) (DirStreamOffset off) = - c_seekdir dirp off + c_seekdir dirp (fromIntegral off) -- TODO: check for CLong/COff overflow foreign import ccall unsafe "seekdir" - c_seekdir :: Ptr CDir -> COff -> IO () + c_seekdir :: Ptr CDir -> CLong -> IO () #endif #ifdef HAVE_TELLDIR tellDirStream :: DirStream -> IO DirStreamOffset tellDirStream (DirStream dirp) = do off <- c_telldir dirp - return (DirStreamOffset off) + return (DirStreamOffset (fromIntegral off)) -- TODO: check for overflow foreign import ccall unsafe "telldir" - c_telldir :: Ptr CDir -> IO COff + c_telldir :: Ptr CDir -> IO CLong #endif changeWorkingDirectoryFd :: Fd -> IO () -- cgit v1.2.3