dymokomi/luce-base
Source of release 0.43.0
#==============================================================================================
#
# c - C's types and errno
#
# DESCRIPTION:
# C's types live here (base.md ยง5.2); the checker supplies them, since their widths are
# the target's: `c.int` and the other fixed-width ones are Base types by another name;
# `c.char`, `c.long`, `c.ulong` and `c.wchar` are distinct; `c.va_list` is opaque; `c.str`
# is C text.
#
#==============================================================================================
import platform
extern func mac_errno as "__error"() -> i32*
extern func linux_errno as "__errno_location"() -> i32*
extern func windows_errno as "_errno"() -> i32*
## The calling thread's `errno`: the C library's account of its last failure.
pub func errno() -> i32:
if platform.windows:
return *windows_errno()
if platform.macos:
return *mac_errno()
return *linux_errno()
## Set the calling thread's errno. Clear it immediately before C calls such as
## readdir whose null result can mean either normal completion or failure.
pub func set_errno(value: i32):
if platform.windows:
*windows_errno() = value
elif platform.macos:
*mac_errno() = value
else:
*linux_errno() = value
## `EINTR`: a call a signal interrupted, to be made again. The same number on every host.
pub let interrupted: i32 = 4
## The C standard input stream; the backend supplies it.
pub func stdin() -> void*:
trap("supplied by the backend")
## The C standard output stream; the backend supplies it.
pub func stdout() -> void*:
trap("supplied by the backend")
## The C standard error stream; the backend supplies it.
pub func stderr() -> void*:
trap("supplied by the backend")