% -----------------------------------------------------------------------------
-% $Id: PrelCString.lhs,v 1.3 2001/04/14 22:28:46 qrczak Exp $
+% $Id: PrelCString.lhs,v 1.4 2001/05/18 16:54:05 simonmar Exp $
%
% (c) The FFI task force, 2000
%
Utilities for primitive marshaling
\begin{code}
-module PrelCString where
+{-# OPTIONS -fno-implicit-prelude #-}
-import Monad
+module PrelCString where
+#ifdef __GLASGOW_HASKELL__
import PrelMarshalArray
import PrelPtr
import PrelStorable
import PrelWord
import PrelByteArr
import PrelPack
+import PrelList
+import PrelReal
+import PrelNum
+import PrelIOBase
import PrelBase
-
-#ifdef __GLASGOW_HASKELL__
-import PrelIOBase hiding (malloc, _malloc)
#endif
-----------------------------------------------------------------------------
-- marshal a NUL terminated C string into a Haskell string
--
peekCString :: CString -> IO String
-peekCString cp = liftM cCharsToChars $ peekArray0 nUL cp
+peekCString cp = do cs <- peekArray0 nUL cp; return (cCharsToChars cs)
-- marshal a C string with explicit length into a Haskell string
--
peekCStringLen :: CStringLen -> IO String
-peekCStringLen (cp, len) = liftM cCharsToChars $ peekArray len cp
+peekCStringLen (cp, len) = do cs <- peekArray len cp; return (cCharsToChars cs)
-- marshal a Haskell string into a NUL terminated C strings
--
-- * new storage is allocated for the C string and must be explicitly freed
--
newCStringLen :: String -> IO CStringLen
-newCStringLen str = liftM (pairLength str) $ newArray (charsToCChars str)
+newCStringLen str = do a <- newArray (charsToCChars str)
+ return (pairLength str a)
-- marshal a Haskell string into a NUL terminated C strings using temporary
-- storage