Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
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