File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
System/Posix/DynamicLinker Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -102,9 +102,10 @@ withModule :: Maybe String
102
102
withModule mdir file flags p = do
103
103
let modPath = case mdir of
104
104
Nothing -> file
105
- Just dir -> dir ++ if last dir == ' /'
106
- then file
107
- else (' /' : file)
105
+ Just dir -> dir ++ case unsnoc dir of
106
+ Just (_, ' /' ) -> file
107
+ Just {} -> ' /' : file
108
+ Nothing -> error " System.Posix.DynamicLinker.Module.withModule: directory should not be Just \"\" , pass Nothing instead"
108
109
modu <- moduleOpen modPath flags
109
110
result <- p modu
110
111
moduleClose modu
@@ -116,3 +117,10 @@ withModule_ :: Maybe String
116
117
-> (Module -> IO a )
117
118
-> IO ()
118
119
withModule_ dir file flags p = withModule dir file flags p >>= \ _ -> return ()
120
+
121
+ -- Dual to 'Data.List.uncons'.
122
+ unsnoc :: [a ] -> Maybe ([a ], a )
123
+ unsnoc = foldr go Nothing
124
+ where
125
+ go x Nothing = Just ([] , x)
126
+ go x (Just (xs, lst)) = Just (x : xs, lst)
You can’t perform that action at this time.
0 commit comments