src/Codec/Compression/BZip/Common.chs
raw| 1 | module Codec.Compression.BZip.Common ( bzStreamInit ) where |
| 2 | |
| 3 | import Codec.Compression.BZip.Foreign.Common (BzStream) |
| 4 | import Control.Applicative |
| 5 | import Foreign.Ptr (nullFunPtr, nullPtr, Ptr) |
| 6 | import Foreign.Marshal (mallocBytes) |
| 7 | |
| 8 | #include <bzlib.h> |
| 9 | |
| 10 | bzStreamInit :: IO (Ptr BzStream) |
| 11 | bzStreamInit = do |
| 12 | p <- mallocBytes {# sizeof bz_stream #} |
| 13 | {# set bz_stream.bzalloc #} p nullFunPtr |
| 14 | {# set bz_stream.bzfree #} p nullFunPtr |
| 15 | {# set bz_stream.opaque #} p nullPtr |
| 16 | pure p |