CString

type CString = Ptr CChar
base Foreign.C.String
A C string is a reference to an array of C characters terminated by NUL.
type CStringLen = (Ptr CChar, Int)
base Foreign.C.String
A string with explicit length information in bytes instead of a terminating NUL (allowing NUL characters in the middle of the string).
newCString :: String -> IO CString
base Foreign.C.String
Marshal a Haskell string into a NUL terminated C string. * the Haskell string may not contain any NUL characters * new storage is allocated for the C string and must be explicitly freed using Foreign.Marshal.Alloc.free or Foreign.Marshal.Alloc.finalizerFree.
newCStringLen :: String -> IO CStringLen
base Foreign.C.String
Marshal a Haskell string into a C string (ie, character array) with explicit length information. * new storage is allocated for the C string and must be explicitly freed using Foreign.Marshal.Alloc.free or Foreign.Marshal.Alloc.finalizerFree.
peekCString :: CString -> IO String
base Foreign.C.String
Marshal a NUL terminated C string into a Haskell string.
peekCStringLen :: CStringLen -> IO String
base Foreign.C.String
Marshal a C string with explicit length into a Haskell string.
withCString :: String -> (CString -> IO a) -> IO a
base Foreign.C.String
Marshal a Haskell string into a NUL terminated C string using temporary storage. * the Haskell string may not contain any NUL characters * the memory is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this.
withCStringLen :: String -> (CStringLen -> IO a) -> IO a
base Foreign.C.String
Marshal a Haskell string into a C string (ie, character array) in temporary storage, with explicit length information. * the memory is freed when the subcomputation terminates (either normally or via an exception), so the pointer to the temporary storage must not be used after this.
occString :: OccName -> String
template-haskell Language.Haskell.TH.Syntax
packCString :: CString -> IO ByteString
bytestring Data.ByteString, bytestring Data.ByteString.Char8
O(n). Construct a new ByteString from a CString. The resulting ByteString is an immutable copy of the original CString, and is managed on the Haskell heap. The original CString must be null terminated.
packCStringLen :: CStringLen -> IO ByteString
bytestring Data.ByteString, bytestring Data.ByteString.Char8
O(n). Construct a new ByteString from a CStringLen. The resulting ByteString is an immutable copy of the original CStringLen. The ByteString is a normal Haskell value and will be managed on the Haskell heap.
unsafePackCString :: CString -> IO ByteString
bytestring Data.ByteString.Unsafe
O(n) Build a ByteString from a CString. This value will have no finalizer associated to it, and will not be garbage collected by Haskell. The ByteString length is calculated using strlen(3), and thus the complexity is a O(n). This function is unsafe. If the CString is later modified, this change will be reflected in the resulting ByteString, breaking referential transparency.
unsafePackCStringFinalizer :: Ptr Word8 -> Int -> IO () -> IO ByteString
bytestring Data.ByteString.Unsafe
O(1) Construct a ByteString given a Ptr Word8 to a buffer, a length, and an IO action representing a finalizer. This function is not available on Hugs. This function is unsafe, it is possible to break referential transparency by modifying the underlying buffer pointed to by the first argument. Any changes to the original buffer will be reflected in the resulting ByteString.
unsafePackCStringLen :: CStringLen -> IO ByteString
bytestring Data.ByteString.Unsafe
O(1) Build a ByteString from a CStringLen. This value will have no finalizer associated with it, and will not be garbage collected by Haskell. This operation has O(1) complexity as we already know the final size, so no strlen(3) is required. This funtion is unsafe. If the original CStringLen is later modified, this change will be reflected in the resulting ByteString, breaking referential transparency.
unsafePackMallocCString :: CString -> IO ByteString
bytestring Data.ByteString.Unsafe
O(n) Build a ByteString from a malloced CString. This value will have a free(3) finalizer associated to it. This funtion is unsafe. If the original CString is later modified, this change will be reflected in the resulting ByteString, breaking referential transparency. This function is also unsafe if you call its finalizer twice, which will result in a double free error, or if you pass it a CString not allocated with malloc.
unsafePackMallocCStringLen :: CStringLen -> IO ByteString
bytestring Data.ByteString.Unsafe
O(n) Build a ByteString from a malloced CStringLen. This value will have a free(3) finalizer associated to it. This funtion is unsafe. If the original CString is later modified, this change will be reflected in the resulting ByteString, breaking referential transparency. This function is also unsafe if you call its finalizer twice, which will result in a double free error, or if you pass it a CString not allocated with malloc.
unsafeUseAsCString :: ByteString -> (CString -> IO a) -> IO a
bytestring Data.ByteString.Unsafe
O(1) construction Use a ByteString with a function requiring a CString. This function does zero copying, and merely unwraps a ByteString to appear as a CString. It is unsafe in two ways: * After calling this function the CString shares the underlying byte buffer with the original ByteString. Thus modifying the CString, either in C, or using poke, will cause the contents of the ByteString to change, breaking referential transparency. Other ByteStrings created by sharing (such as those produced via take or drop) will also reflect these changes. Modifying the CString will break referential transparency. To avoid this, use useAsCString, which makes a copy of the original ByteString. * CStrings are often passed to functions that require them to be null-terminated. If the original ByteString wasn't null terminated, neither will the CString be. It is the programmers responsibility to guarantee that the ByteString is indeed null terminated. If in doubt, use useAsCString.
unsafeUseAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a
bytestring Data.ByteString.Unsafe
O(1) construction Use a ByteString with a function requiring a CStringLen. This function does zero copying, and merely unwraps a ByteString to appear as a CStringLen. It is unsafe: * After calling this function the CStringLen shares the underlying byte buffer with the original ByteString. Thus modifying the CStringLen, either in C, or using poke, will cause the contents of the ByteString to change, breaking referential transparency. Other ByteStrings created by sharing (such as those produced via take or drop) will also reflect these changes. Modifying the CStringLen will break referential transparency. To avoid this, use useAsCStringLen, which makes a copy of the original ByteString.
useAsCString :: ByteString -> (CString -> IO a) -> IO a
bytestring Data.ByteString, bytestring Data.ByteString.Char8
O(n) construction Use a ByteString with a function requiring a null-terminated CString. The CString will be freed automatically. This is a memcpy(3).
useAsCStringLen :: ByteString -> (CStringLen -> IO a) -> IO a
bytestring Data.ByteString, bytestring Data.ByteString.Char8
O(n) construction Use a ByteString with a function requiring a CStringLen. As for useAsCString this function makes a copy of the original ByteString.