{-# LINE 1 "libraries/unix/System/Posix/DynamicLinker/Module/ByteString.hsc" #-}
{-# LANGUAGE Safe #-}
module System.Posix.DynamicLinker.Module.ByteString (
Module
, moduleOpen
, moduleSymbol
, moduleClose
, moduleError
, withModule
, withModule_
)
where
import System.Posix.DynamicLinker.Module hiding (moduleOpen)
import System.Posix.DynamicLinker.Prim
import System.Posix.DynamicLinker.Common
import Foreign
import System.Posix.ByteString.FilePath
moduleOpen :: RawFilePath -> [RTLDFlags] -> IO Module
moduleOpen :: RawFilePath -> [RTLDFlags] -> IO Module
moduleOpen RawFilePath
file [RTLDFlags]
flags = do
Ptr ()
modPtr <- RawFilePath -> (CString -> IO (Ptr ())) -> IO (Ptr ())
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
file ((CString -> IO (Ptr ())) -> IO (Ptr ()))
-> (CString -> IO (Ptr ())) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ \ CString
modAddr -> CString -> CInt -> IO (Ptr ())
c_dlopen CString
modAddr ([RTLDFlags] -> CInt
packRTLDFlags [RTLDFlags]
flags)
if (Ptr ()
modPtr Ptr () -> Ptr () -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr ()
forall a. Ptr a
nullPtr)
then IO String
moduleError IO String -> (String -> IO Module) -> IO Module
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ String
err -> IOError -> IO Module
forall a. IOError -> IO a
ioError (String -> IOError
userError (String
"dlopen: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err))
else Module -> IO Module
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Module -> IO Module) -> Module -> IO Module
forall a b. (a -> b) -> a -> b
$ Ptr () -> Module
Module Ptr ()
modPtr