Use unsafeUseAsCStringout Data.ByteString.Unsafe. It has type:
ByteString -> (CString -> IO a) -> IO a
So you can use unsafeUseAsCString bs returnto just get the pointer. It will not end in zero if it does not ByteString, and it will have a type CString(that is Ptr CChar) instead Ptr Word8, but you can use castPtrfrom Foreign.Ptrto get around if this is a problem.
source
share