{-| Description: c2hs-generated byte offsets for members of C structs. Copyright: (c) 2020 Sam May License: GPL-3.0-or-later Maintainer: ag@eitilt.life Stability: stable Portability: non-portable (requires libcdio) Since this library already handles marshalling to and from C types itself, the only remaining benefit to using c2hs for datatypes is not having to worry about tracking the internal byte arrangement of C structs. That can be done just as easily externally here, with the added benefit of being able to analyze coverage of the primary modules. Just note that since this isn't exposed, it /can not/ be used directly by any other c2hs-generated modules. -} module Foreign.Libcdio.Types.Offsets where import qualified Foreign.C.String as C import qualified Foreign.Ptr as C import qualified Foreign.Marshal.Array as M import qualified Foreign.Storable as S pokeCString :: String -> Int -> C.CString -> IO () pokeCString s l p = C.withCStringLen (s ++ "\NUL") $ \(c, cl) -> if l < cl then M.copyArray p c (l - 1) >> S.poke (C.plusPtr p $ l - 1) '\NUL' else M.copyArray p c cl #include "cdio/compat/cd_types.h" iaSizeOf :: Int iaSizeOf = {#sizeof cdio_iso_analysis_t#} iaAlign :: Int iaAlign = {#alignof cdio_iso_analysis_t#} iaJolietLevel :: Int iaJolietLevel = {#offsetof cdio_iso_analysis_t->joliet_level#} iaLabel :: Int iaLabel = {#offsetof cdio_iso_analysis_t->iso_label#} iaIsoSize :: Int iaIsoSize = {#offsetof cdio_iso_analysis_t->isofs_size#} iaUDFMajor :: Int iaUDFMajor = {#offsetof cdio_iso_analysis_t->UDFVerMajor#} iaUDFMinor :: Int iaUDFMinor = {#offsetof cdio_iso_analysis_t->UDFVerMinor#} #include "cdio/compat/device.h" hiSizeOf :: Int hiSizeOf = {#sizeof cdio_hwinfo#} hiAlign :: Int hiAlign = {#alignof cdio_hwinfo#} hiVendor :: Int hiVendor = {#offsetof cdio_hwinfo->psz_vendor#} hiModel :: Int hiModel = {#offsetof cdio_hwinfo->psz_model#} hiRevision :: Int hiRevision = {#offsetof cdio_hwinfo->psz_revision#} #include "cdio/compat/logging.h" leSizeOf :: Int leSizeOf = {#sizeof cdio_log_entry_t#} leAlign :: Int leAlign = {#alignof cdio_log_entry_t#} leLevel :: Int leLevel = {#offsetof cdio_log_entry_t->level#} leMessage :: Int leMessage = {#offsetof cdio_log_entry_t->message#} lePrevious :: Int lePrevious = {#offsetof cdio_log_entry_t->prev#} #include "cdio/compat/sector.h" -- c2hs can't handle the packed datatype, so get the values from C itself. msfSizeOf :: Int msfSizeOf = fromIntegral $ {#call pure sizeof_msf#} msfAlign :: Int msfAlign = {#alignof msf_t#} msfM :: Int msfM = {#offsetof msf_t->m#} msfS :: Int msfS = {#offsetof msf_t->s#} msfF :: Int msfF = {#offsetof msf_t->f#} {- Never used after definition. adrSizeOf :: Int adrSizeOf = {#sizeof cdio_cdrom_addr#} adrAlign :: Int adrAlign = {#alignof cdio_cdrom_addr#} -}