Skip to content
Snippets Groups Projects
Commit 43343c15 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel :man_dancing:
Browse files

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).
parent c46a7fec
No related branches found
No related tags found
No related merge requests found
......@@ -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 ()
......
<<<<<<< HEAD
# Changelog for [`unix` package](http://hackage.haskell.org/package/unix)
## 2.7.0.2 *TBA*
......@@ -9,6 +10,7 @@
CPP macros for required getgrgid_r and getgrnam_r functions definition
so the fix is to change from C ABI calling convention to C API calling
convention
* Fix potential type-mismatch in `telldir`/`seekdir` FFI imports
## 2.7.0.1 *Mar 2014*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment