Changeset View
Changeset View
Standalone View
Standalone View
libraries/base/System/Posix/Internals.hs
Show First 20 Lines • Show All 398 Lines • ▼ Show 20 Line(s) | 398 | foreign import ccall unsafe "HsBase.h _dup" | |||
---|---|---|---|---|---|
399 | c_dup :: CInt -> IO CInt | 399 | c_dup :: CInt -> IO CInt | ||
400 | 400 | | |||
401 | foreign import ccall unsafe "HsBase.h _dup2" | 401 | foreign import ccall unsafe "HsBase.h _dup2" | ||
402 | c_dup2 :: CInt -> CInt -> IO CInt | 402 | c_dup2 :: CInt -> CInt -> IO CInt | ||
403 | 403 | | |||
404 | foreign import ccall unsafe "HsBase.h _isatty" | 404 | foreign import ccall unsafe "HsBase.h _isatty" | ||
405 | c_isatty :: CInt -> IO CInt | 405 | c_isatty :: CInt -> IO CInt | ||
406 | 406 | | |||
407 | -- See Note: CSsize | 407 | -- See Note: Windows types | ||
408 | foreign import capi unsafe "HsBase.h _read" | 408 | foreign import capi unsafe "HsBase.h _read" | ||
409 | c_read :: CInt -> Ptr Word8 -> CSize -> IO CSsize | 409 | c_read :: CInt -> Ptr Word8 -> CUInt -> IO CInt | ||
410 | 410 | | |||
411 | -- See Note: CSsize | 411 | -- See Note: Windows types | ||
412 | foreign import capi safe "HsBase.h _read" | 412 | foreign import capi safe "HsBase.h _read" | ||
413 | c_safe_read :: CInt -> Ptr Word8 -> CSize -> IO CSsize | 413 | c_safe_read :: CInt -> Ptr Word8 -> CUInt -> IO CInt | ||
414 | 414 | | |||
415 | foreign import ccall unsafe "HsBase.h _umask" | 415 | foreign import ccall unsafe "HsBase.h _umask" | ||
416 | c_umask :: CMode -> IO CMode | 416 | c_umask :: CMode -> IO CMode | ||
417 | 417 | | |||
418 | -- See Note: CSsize | 418 | -- See Note: Windows types | ||
419 | foreign import capi unsafe "HsBase.h _write" | 419 | foreign import capi unsafe "HsBase.h _write" | ||
420 | c_write :: CInt -> Ptr Word8 -> CSize -> IO CSsize | 420 | c_write :: CInt -> Ptr Word8 -> CUInt -> IO CInt | ||
421 | 421 | | |||
422 | -- See Note: CSsize | 422 | -- See Note: Windows types | ||
423 | foreign import capi safe "HsBase.h _write" | 423 | foreign import capi safe "HsBase.h _write" | ||
424 | c_safe_write :: CInt -> Ptr Word8 -> CSize -> IO CSsize | 424 | c_safe_write :: CInt -> Ptr Word8 -> CUInt -> IO CInt | ||
425 | 425 | | |||
426 | foreign import ccall unsafe "HsBase.h _unlink" | 426 | foreign import ccall unsafe "HsBase.h _unlink" | ||
427 | c_unlink :: CString -> IO CInt | 427 | c_unlink :: CString -> IO CInt | ||
428 | 428 | | |||
429 | foreign import ccall unsafe "HsBase.h _pipe" | 429 | foreign import ccall unsafe "HsBase.h _pipe" | ||
430 | c_pipe :: Ptr CInt -> IO CInt | 430 | c_pipe :: Ptr CInt -> IO CInt | ||
431 | 431 | | |||
432 | foreign import capi unsafe "HsBase.h _utime" | 432 | foreign import capi unsafe "HsBase.h _utime" | ||
Show All 24 Lines | 456 | foreign import ccall unsafe "HsBase.h dup" | |||
457 | c_dup :: CInt -> IO CInt | 457 | c_dup :: CInt -> IO CInt | ||
458 | 458 | | |||
459 | foreign import ccall unsafe "HsBase.h dup2" | 459 | foreign import ccall unsafe "HsBase.h dup2" | ||
460 | c_dup2 :: CInt -> CInt -> IO CInt | 460 | c_dup2 :: CInt -> CInt -> IO CInt | ||
461 | 461 | | |||
462 | foreign import ccall unsafe "HsBase.h isatty" | 462 | foreign import ccall unsafe "HsBase.h isatty" | ||
463 | c_isatty :: CInt -> IO CInt | 463 | c_isatty :: CInt -> IO CInt | ||
464 | 464 | | |||
465 | -- See Note: CSsize | 465 | -- See Note: Windows types | ||
466 | foreign import capi unsafe "HsBase.h read" | 466 | foreign import capi unsafe "HsBase.h read" | ||
467 | c_read :: CInt -> Ptr Word8 -> CSize -> IO CSsize | 467 | c_read :: CInt -> Ptr Word8 -> CSize -> IO CSsize | ||
468 | 468 | | |||
469 | -- See Note: CSsize | 469 | -- See Note: Windows types | ||
470 | foreign import capi safe "HsBase.h read" | 470 | foreign import capi safe "HsBase.h read" | ||
471 | c_safe_read :: CInt -> Ptr Word8 -> CSize -> IO CSsize | 471 | c_safe_read :: CInt -> Ptr Word8 -> CSize -> IO CSsize | ||
472 | 472 | | |||
473 | foreign import ccall unsafe "HsBase.h umask" | 473 | foreign import ccall unsafe "HsBase.h umask" | ||
474 | c_umask :: CMode -> IO CMode | 474 | c_umask :: CMode -> IO CMode | ||
475 | 475 | | |||
476 | -- See Note: CSsize | 476 | -- See Note: Windows types | ||
477 | foreign import capi unsafe "HsBase.h write" | 477 | foreign import capi unsafe "HsBase.h write" | ||
478 | c_write :: CInt -> Ptr Word8 -> CSize -> IO CSsize | 478 | c_write :: CInt -> Ptr Word8 -> CSize -> IO CSsize | ||
479 | 479 | | |||
480 | -- See Note: CSsize | 480 | -- See Note: Windows types | ||
481 | foreign import capi safe "HsBase.h write" | 481 | foreign import capi safe "HsBase.h write" | ||
482 | c_safe_write :: CInt -> Ptr Word8 -> CSize -> IO CSsize | 482 | c_safe_write :: CInt -> Ptr Word8 -> CSize -> IO CSsize | ||
483 | 483 | | |||
484 | foreign import ccall unsafe "HsBase.h unlink" | 484 | foreign import ccall unsafe "HsBase.h unlink" | ||
485 | c_unlink :: CString -> IO CInt | 485 | c_unlink :: CString -> IO CInt | ||
486 | 486 | | |||
487 | foreign import ccall unsafe "HsBase.h pipe" | 487 | foreign import ccall unsafe "HsBase.h pipe" | ||
488 | c_pipe :: Ptr CInt -> IO CInt | 488 | c_pipe :: Ptr CInt -> IO CInt | ||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Line(s) | |||||
614 | #endif | 614 | #endif | ||
615 | 615 | | |||
616 | foreign import ccall unsafe "__hscore_bufsiz" dEFAULT_BUFFER_SIZE :: Int | 616 | foreign import ccall unsafe "__hscore_bufsiz" dEFAULT_BUFFER_SIZE :: Int | ||
617 | foreign import capi unsafe "stdio.h value SEEK_CUR" sEEK_CUR :: CInt | 617 | foreign import capi unsafe "stdio.h value SEEK_CUR" sEEK_CUR :: CInt | ||
618 | foreign import capi unsafe "stdio.h value SEEK_SET" sEEK_SET :: CInt | 618 | foreign import capi unsafe "stdio.h value SEEK_SET" sEEK_SET :: CInt | ||
619 | foreign import capi unsafe "stdio.h value SEEK_END" sEEK_END :: CInt | 619 | foreign import capi unsafe "stdio.h value SEEK_END" sEEK_END :: CInt | ||
620 | 620 | | |||
621 | {- | 621 | {- | ||
622 | Note: CSsize | 622 | Note: Windows types | ||
623 | 623 | | |||
624 | On Win64, ssize_t is 64 bit, but functions like read return 32 bit | 624 | Windows' _read and _write have types that differ from POSIX. They take an | ||
625 | ints. The CAPI wrapper means the C compiler takes care of doing all | 625 | unsigned int for lengh and return a signed int where POSIX uses size_t and | ||
626 | the necessary casting. | 626 | ssize_t. Those are different on x86_64 and equivalent on x86. We import them | ||
627 | 627 | with the types in Microsoft's documentation which means that c_read, | |||
628 | When using ccall instead, when the functions failed with -1, we thought | 628 | c_safe_read, c_write and c_safe_write have different Haskell types depending on | ||
629 | they were returning with 4294967295, and so didn't throw an exception. | 629 | the OS. | ||
630 | This lead to a segfault in echo001(ghci). | | |||
631 | -} | 630 | -} | ||
632 | 631 | |