    {-# LANGUAGE ForeignFunctionInterface #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  System.Unix.Crypt
    -- Copyright   :  (c) 2010
    -- License     :  BSD3
    --
    -- Maintainer  :  jeremy@seereason.com
    -- Stability   :  provisional
    -- Portability :  non-portable (requires POSIX)
    --
    -- support for crypt() and /etc/shadow
    --
    -----------------------------------------------------------------------------

    module System.Unix.Crypt
        ( crypt
        )
        where

    import Foreign.C

    foreign import ccall unsafe "unistd.h crypt"
      c_crypt :: CString -> CString -> IO CString

    -- | calls crypt(3)
    crypt :: String -- ^ key
          -> String -- ^ salt
          -> IO String -- ^ encrypted password
    crypt :: String -> String -> IO String
    crypt String
    key String
    salt =
        String -> (CString -> IO String) -> IO String
    forall a. String -> (CString -> IO a) -> IO a
    withCString String
    key ((CString -> IO String) -> IO String)
    -> (CString -> IO String) -> IO String
    forall a b. (a -> b) -> a -> b
    $ \CString
    ckey ->
            String -> (CString -> IO String) -> IO String
    forall a. String -> (CString -> IO a) -> IO a
    withCString String
    salt ((CString -> IO String) -> IO String)
    -> (CString -> IO String) -> IO String
    forall a b. (a -> b) -> a -> b
    $ \CString
    csalt ->
                do cpassword <- String -> IO CString -> IO CString
    forall a. String -> IO (Ptr a) -> IO (Ptr a)
    throwErrnoIfNull String
    "crypt" (CString -> CString -> IO CString
    c_crypt CString
    ckey CString
    csalt)
                   peekCString cpassword