From 0461c57e21dabd13e1fb25052228249efeddce75 Mon Sep 17 00:00:00 2001 From: sof Date: Tue, 11 Aug 1998 21:39:29 +0000 Subject: [PATCH] [project @ 1998-08-11 21:39:29 by sof] Moved unvectorize to here from PosixUtil --- ghc/lib/misc/Util.lhs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/ghc/lib/misc/Util.lhs b/ghc/lib/misc/Util.lhs index d09c6d7..6f134bf 100644 --- a/ghc/lib/misc/Util.lhs +++ b/ghc/lib/misc/Util.lhs @@ -87,17 +87,13 @@ module Util ( , assertPanic #endif {- COMPILING_GHC -} - ) where - -#if defined(COMPILING_GHC) + , unvectorize -CHK_Ubiq() -- debugging consistency check -IMPORT_1_3(List(zipWith4)) + ) where -import Pretty -#else import List(zipWith4) -#endif +import PackedString ( unpackCStringIO ) +import Addr infixr 9 `thenCmp` \end{code} @@ -814,3 +810,19 @@ assertPanic file line = panic ("ASSERT failed! file "++file++", line "++show lin #endif {- COMPILING_GHC -} \end{code} + +Turn a NULL-terminated vector of null-terminated strings into a string list +(ToDo: create a module of common marshaling functions) + +\begin{code} +unvectorize :: Addr -> Int -> IO [String] +unvectorize ptr n + | str == ``NULL'' = return [] + | otherwise = do + x <- unpackCStringIO str + xs <- unvectorize ptr (n+1) + return (x : xs) + where + str = indexAddrOffAddr ptr n + +\end{code} -- 1.7.10.4