Files
c3c/lib/std/libc/os/errno.c3
limit-ordinal 85166bc706 Add NetBSD Support (#2661)
* Add NetBSD Support

Includes:
- Hints to find non-compatibility libc functions
- Struct and constant definitions for sockets, polling, etc.
- Changes to the linker code to work around some quirks in the NetBSD dynamic linker
- A target triple for netbsd aarch64 so llvm builds/links the compiler properly on this platform

* Updated releasenotes and some compacting

---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2025-12-19 19:23:06 +01:00

40 lines
1.3 KiB
Plaintext

module libc::os @if(env::LIBC);
import std::core::env;
// Linux
extern fn int* __errno_location() @if(env::LINUX);
macro int errno() @if(env::LINUX) => *__errno_location();
macro void errno_set(int err) @if(env::LINUX) => *(__errno_location()) = err;
// Android 9
extern fn int* __errno() @if(env::ANDROID);
macro int errno() @if(env::ANDROID) => *__errno();
macro void errno_set(int err) @if(env::ANDROID) => *(__errno()) = err;
// OpenBSD and NetBSD
extern fn int* __errno() @if(env::OPENBSD || env::NETBSD);
macro int errno() @if(env::OPENBSD || env::NETBSD) => *__errno();
macro void errno_set(int err) @if(env::OPENBSD || env::NETBSD) => *(__errno()) = err;
// Darwin
extern fn int* __error() @if(env::DARWIN);
macro int errno() @if(env::DARWIN) => *__error();
macro void errno_set(int err) @if(env::DARWIN) => *(__error()) = err;
// Win32
macro int errno() @if(env::WIN32)
{
int holder;
_get_errno(&holder);
return holder;
}
macro void errno_set(int err) @if(env::WIN32) => _set_errno(err);
extern fn void _get_errno(int* result) @if(env::WIN32);
extern fn void _set_errno(int err) @if(env::WIN32);
// Default
module libc::os @if(!env::LIBC || !env::HAS_NATIVE_ERRNO);
tlocal int _errno_c3 = 0;
fn void errno_set(int err) => _errno_c3 = err;
fn int errno() => _errno_c3;