aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/DynamicLinker.hsc
diff options
context:
space:
mode:
authorGravatar Simon Marlow <marlowsd@gmail.com>2011-11-11 16:18:48 +0000
committerGravatar Simon Marlow <marlowsd@gmail.com>2011-11-22 12:36:48 +0000
commit34c7bf896f19b182cf6fa104e057f1df9df1254a (patch)
treeabdb8264ae52c62263fc0fb4b395906a64acb104 /System/Posix/DynamicLinker.hsc
parentc213ae2ec6d9c71266aebc8e5b2326a9625fba7a (diff)
Provide a raw ByteString version of FilePath and environment APIs
The new module System.Posix.ByteString provides exactly the same API as System.Posix, except that: - There is a new type: RawFilePath = ByteString - All functions mentioning FilePath in the System.Posix API use RawFilePath in the System.Posix.ByteString API - RawFilePaths are not subject to Unicode locale encoding and decoding, unlike FilePaths. They are the exact bytes passed to and returned from the underlying POSIX API. - Similarly for functions that deal in environment strings (System.Posix.Env): these use untranslated ByteStrings in System.Posix.Environment - There is a new function System.Posix.ByteString.getArgs :: [ByteString] returning the raw untranslated arguments as passed to exec() when the program was started.
Diffstat (limited to 'System/Posix/DynamicLinker.hsc')
-rw-r--r--System/Posix/DynamicLinker.hsc40
1 files changed, 5 insertions, 35 deletions
diff --git a/System/Posix/DynamicLinker.hsc b/System/Posix/DynamicLinker.hsc
index ac6efb0..7683fc3 100644
--- a/System/Posix/DynamicLinker.hsc
+++ b/System/Posix/DynamicLinker.hsc
@@ -48,13 +48,14 @@ module System.Posix.DynamicLinker (
where
+import System.Posix.DynamicLinker.Common
+import System.Posix.DynamicLinker.Prim
+
#include "HsUnix.h"
-import System.Posix.DynamicLinker.Prim
-import Control.Exception ( bracket )
+import Control.Exception ( bracket )
import Control.Monad ( liftM )
-import Foreign.Ptr ( Ptr, nullPtr, FunPtr, nullFunPtr )
-import Foreign.C.String
+import Foreign
#if __GLASGOW_HASKELL__ > 611
import System.Posix.Internals ( withFilePath )
#else
@@ -67,39 +68,8 @@ dlopen path flags = do
withFilePath path $ \ p -> do
liftM DLHandle $ throwDLErrorIf "dlopen" (== nullPtr) $ c_dlopen p (packRTLDFlags flags)
-dlclose :: DL -> IO ()
-dlclose (DLHandle h) = throwDLErrorIf_ "dlclose" (/= 0) $ c_dlclose h
-dlclose h = error $ "dlclose: invalid argument" ++ (show h)
-
-dlerror :: IO String
-dlerror = c_dlerror >>= peekCString
-
--- |'dlsym' returns the address binding of the symbol described in @symbol@,
--- as it occurs in the shared object identified by @source@.
-
-dlsym :: DL -> String -> IO (FunPtr a)
-dlsym source symbol = do
- withCAString symbol $ \ s -> do
- throwDLErrorIf "dlsym" (== nullFunPtr) $ c_dlsym (packDL source) s
-
withDL :: String -> [RTLDFlags] -> (DL -> IO a) -> IO a
withDL file flags f = bracket (dlopen file flags) (dlclose) f
withDL_ :: String -> [RTLDFlags] -> (DL -> IO a) -> IO ()
withDL_ file flags f = withDL file flags f >> return ()
-
--- |'undl' obtains the raw handle. You mustn't do something like
--- @withDL mod flags $ liftM undl >>= \ p -> use p@
-
-undl :: DL -> Ptr ()
-undl = packDL
-
-throwDLErrorIf :: String -> (a -> Bool) -> IO a -> IO a
-throwDLErrorIf s p f = do
- r <- f
- if (p r)
- then dlerror >>= \ err -> ioError (userError ( s ++ ": " ++ err))
- else return r
-
-throwDLErrorIf_ :: String -> (a -> Bool) -> IO a -> IO ()
-throwDLErrorIf_ s p f = throwDLErrorIf s p f >> return ()