{-# LINE 1 "System/Posix/DynamicLinker/ByteString.hsc" #-}{-# LANGUAGE Safe #-}------------------------------------------------------------------------------- |-- Module : System.Posix.DynamicLinker.ByteString-- Copyright : (c) Volker Stolz <vs@foldr.org> 2003-- License : BSD-style (see the file libraries/base/LICENSE)---- Maintainer : vs@foldr.org-- Stability : provisional-- Portability : non-portable (requires POSIX)---- Dynamic linker support through dlopen()-----------------------------------------------------------------------------moduleSystem.Posix.DynamicLinker.ByteString(moduleSystem.Posix.DynamicLinker.Prim,dlopen,dlsym,dlerror,dlclose,withDL,withDL_,undl,)-- Usage:-- ******---- Let's assume you want to open a local shared library \'foo\' (.\/libfoo.so)-- offering a function-- @char \* mogrify (char\*,int)@-- and invoke @str = mogrify("test",1)@:------ type Fun = CString -> Int -> IO CString-- foreign import dynamic unsafe fun__ :: FunPtr Fun -> Fun---- withDL "libfoo.so" [RTLD_NOW] \$ \\ mod -> do-- funptr <- dlsym mod "mogrify"-- let fun = fun__ funptr-- withCString "test" \$ \\ str -> do-- strptr <- fun str 1-- strstr <- peekCString strptr-- ...--whereimportSystem.Posix.DynamicLinker.CommonimportSystem.Posix.DynamicLinker.PrimimportControl.Exception(bracket)importForeignimportSystem.Posix.ByteString.FilePathdlopen::RawFilePath->[RTLDFlags]->IODLdlopenpathflags=withFilePathpath$\p->DLHandle<$>throwDLErrorIf"dlopen"(==nullPtr)(c_dlopenp(packRTLDFlagsflags))withDL::RawFilePath->[RTLDFlags]->(DL->IOa)->IOawithDLfileflagsf=bracket(dlopenfileflags)(dlclose)fwithDL_::RawFilePath->[RTLDFlags]->(DL->IOa)->IO()withDL_fileflagsf=withDLfileflagsf>>return()