aboutsummaryrefslogtreecommitdiff
path: root/base/runtime/os_specific_darwin.odin
blob: 5d2709d1ffd7328a58ad50172671ffe39461548c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//+build darwin
//+private
package runtime

foreign import libc "system:System.framework"

@(default_calling_convention="c")
foreign libc {
	@(link_name="__stderrp")
	_stderr: rawptr

	@(link_name="fwrite")
	_fwrite :: proc(ptr: rawptr, size: uint, nmemb: uint, stream: rawptr) -> uint ---

	@(link_name="__error")
	_get_errno :: proc() -> ^i32 ---
}

_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
	ret := _fwrite(raw_data(data), 1, len(data), _stderr)
	if ret < len(data) {
		err := _get_errno()
		return int(ret), _OS_Errno(err^ if err != nil else 0)
	}
	return int(ret), 0
}