Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use capi for syscalls that break under musl's handling of 64-bit time_t #252

Merged
merged 3 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions System/Posix/DynamicLinker/Prim.hsc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE Trustworthy #-}
{-# OPTIONS_GHC -Wno-trustworthy-safe #-}

Expand Down Expand Up @@ -84,10 +85,17 @@ data RTLDFlags
| RTLD_LOCAL
deriving (Show, Read)

foreign import ccall unsafe "dlopen" c_dlopen :: CString -> CInt -> IO (Ptr ())
#if defined(HAVE_DLFCN_H)
foreign import capi safe "dlfcn.h dlopen" c_dlopen :: CString -> CInt -> IO (Ptr ())
foreign import capi unsafe "dlfcn.h dlsym" c_dlsym :: Ptr () -> CString -> IO (FunPtr a)
foreign import capi unsafe "dlfcn.h dlerror" c_dlerror :: IO CString
foreign import capi safe "dlfcn.h dlclose" c_dlclose :: (Ptr ()) -> IO CInt
#else
foreign import ccall safe "dlopen" c_dlopen :: CString -> CInt -> IO (Ptr ())
foreign import ccall unsafe "dlsym" c_dlsym :: Ptr () -> CString -> IO (FunPtr a)
foreign import ccall unsafe "dlerror" c_dlerror :: IO CString
foreign import ccall unsafe "dlclose" c_dlclose :: (Ptr ()) -> IO CInt
foreign import ccall safe "dlclose" c_dlclose :: (Ptr ()) -> IO CInt
#endif // HAVE_DLFCN_H

packRTLDFlags :: [RTLDFlags] -> CInt
packRTLDFlags flags = foldl (\ s f -> (packRTLDFlag f) .|. s) 0 flags
Expand Down
11 changes: 6 additions & 5 deletions System/Posix/Files/Common.hsc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE Trustworthy #-}

-----------------------------------------------------------------------------
Expand Down Expand Up @@ -452,12 +453,12 @@ toCTimeSpec t = CTimeSpec (CTime sec) (truncate $ 10^(9::Int) * frac)
#endif

#ifdef HAVE_UTIMENSAT
foreign import ccall unsafe "utimensat"
foreign import capi unsafe "sys/stat.h utimensat"
c_utimensat :: CInt -> CString -> Ptr CTimeSpec -> CInt -> IO CInt
#endif

#if HAVE_FUTIMENS
foreign import ccall unsafe "futimens"
foreign import capi unsafe "sys/stat.h futimens"
c_futimens :: CInt -> Ptr CTimeSpec -> IO CInt
#endif

Expand All @@ -480,16 +481,16 @@ toCTimeVal t = CTimeVal sec (truncate $ 10^(6::Int) * frac)
(sec, frac) = if (frac' < 0) then (sec' - 1, frac' + 1) else (sec', frac')
(sec', frac') = properFraction $ toRational t

foreign import ccall unsafe "utimes"
foreign import capi unsafe "sys/time.h utimes"
c_utimes :: CString -> Ptr CTimeVal -> IO CInt

#ifdef HAVE_LUTIMES
foreign import ccall unsafe "lutimes"
foreign import capi unsafe "sys/time.h lutimes"
c_lutimes :: CString -> Ptr CTimeVal -> IO CInt
#endif

#if HAVE_FUTIMES
foreign import ccall unsafe "futimes"
foreign import capi unsafe "sys/time.h futimes"
c_futimes :: CInt -> Ptr CTimeVal -> IO CInt
#endif

Expand Down