summaryrefslogtreecommitdiff
path: root/libraries/base/tests/IO/T17414.hs
blob: 59d40720ec47cb0acb62cbc825f6eeca87f23c44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{-# LANGUAGE ScopedTypeVariables #-}
import Foreign.Ptr (Ptr)
import Foreign.Marshal.Alloc (mallocBytes, free)
import System.IO (hPutBuf, withBinaryFile, IOMode (WriteMode))

-- more than 2GiB
numBytes :: Int
numBytes = 2264375889

main :: IO ()
main = do
  (ptr :: Ptr ()) <- mallocBytes numBytes
  -- the next line produces the exception on macOS
  withBinaryFile "test.out" WriteMode (\h -> hPutBuf h ptr numBytes)
  free ptr

  -- Truncate file in case it doesn't get deleted
  writeFile "test.out" ""