{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash #-}
module Database.PostgreSQL.LibPQ.Compat where

import Data.ByteString.Internal (ByteString(..))
import Data.Word (Word8)
import Foreign.ForeignPtr (ForeignPtr)

#if MIN_VERSION_bytestring(0,11,0)
import Data.ByteString.Internal (plusForeignPtr)
#endif

withPS :: ByteString -> (ForeignPtr Word8 -> Int -> Int -> r) -> r
#if MIN_VERSION_bytestring(0,11,0)
withPS (BS fp len)     kont = kont fp 0   len
#else
withPS :: ByteString -> (ForeignPtr Word8 -> Int -> Int -> r) -> r
withPS (PS ForeignPtr Word8
fp Int
off Int
len) ForeignPtr Word8 -> Int -> Int -> r
kont = ForeignPtr Word8 -> Int -> Int -> r
kont ForeignPtr Word8
fp Int
off Int
len
#endif
{-# INLINE withPS #-}

mkPS :: ForeignPtr Word8 -> Int -> Int -> ByteString
#if MIN_VERSION_bytestring(0,11,0)
mkPS fp off len = BS (plusForeignPtr fp off) len
#else
mkPS :: ForeignPtr Word8 -> Int -> Int -> ByteString
mkPS ForeignPtr Word8
fp Int
off Int
len = ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fp Int
off Int
len
#endif
{-# INLINE mkPS #-}