How to deal with C buf in Haskell?

Hi, I am warping some C libs. In one function, I do this: 183 allocaBytes bufLen $ \buf -> do 184 ret <- {# call buf_read #} 185 bluh 186 bala 187 buf 188 bufLen 189 if ret < 0 190 then userError "bufRead error" 191 else -- what should I do here? I am thinking about bytestring, to pass the content of the buf to the outside of the function. But I am not sure. What should I do? -- 竹密岂妨流水过 山高哪阻野云飞

On Tue, Dec 8, 2009 at 3:22 AM, Magicloud Magiclouds
Hi, I am warping some C libs. In one function, I do this: 183 allocaBytes bufLen $ \buf -> do 184 ret <- {# call buf_read #} 185 bluh 186 bala 187 buf 188 bufLen 189 if ret < 0 190 then userError "bufRead error" 191 else -- what should I do here?
I am thinking about bytestring, to pass the content of the buf to the outside of the function. But I am not sure. What should I do?
See: Data.ByteString.Internal.createAndTrim: http://hackage.haskell.org/packages/archive/bytestring/0.9.1.4/doc/html/Data... With that your program becomes something like: createAndTrim bufLen $ \buf -> ret <- {# call buf_read #} bluh bala buf bufLen if ret < 0 then userError "bufRead error" else return ret -- if ret indicates the number of bytes read regards, Bas
participants (2)
-
Bas van Dijk
-
Magicloud Magiclouds