Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Hostname/Haskell/hostname-1.hs
Normal file
3
Task/Hostname/Haskell/hostname-1.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import Network.BSD
|
||||
main = do hostName <- getHostName
|
||||
putStrLn hostName
|
||||
19
Task/Hostname/Haskell/hostname-2.hs
Normal file
19
Task/Hostname/Haskell/hostname-2.hs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
module GetHostName where
|
||||
|
||||
import Foreign.Marshal.Array ( allocaArray0, peekArray0 )
|
||||
import Foreign.C.Types ( CInt(..), CSize(..) )
|
||||
import Foreign.C.String ( CString, peekCString )
|
||||
import Foreign.C.Error ( throwErrnoIfMinus1_ )
|
||||
|
||||
getHostName :: IO String
|
||||
getHostName = do
|
||||
let size = 256
|
||||
allocaArray0 size $ \ cstr -> do
|
||||
throwErrnoIfMinus1_ "getHostName" $ c_gethostname cstr (fromIntegral size)
|
||||
peekCString cstr
|
||||
|
||||
foreign import ccall "gethostname"
|
||||
c_gethostname :: CString -> CSize -> IO CInt
|
||||
|
||||
main = do hostName <- getHostName
|
||||
putStrLn hostName
|
||||
Loading…
Add table
Add a link
Reference in a new issue