Created
July 3, 2014 11:06
-
-
Save Tarrasch/0fdbf3d2bb824ac5ca23 to your computer and use it in GitHub Desktop.
Revisions
-
Tarrasch created this gist
Jul 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -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