Files
Odin/core/c/libc/errno.odin
Julian Fondren 9f55404845 fix core:c/libc.errno link_name for Linux and FreeBSD
Although the FreeBSD link matches Darwin, its EILSEQ still matches Linux.

Confirmed with the following program:

```odin
package main
import "core:c/libc"

main :: proc() {
	libc.printf("%d\n", libc.errno()^) // 0
	_ = libc.fopen("nonexistent file", "r")
	libc.printf("%d\n", libc.errno()^) // 2
}
```

on Linux:

	Odin: dev-2022-10:075040ae
	OS:   Manjaro Linux, Linux 5.10.147-1-MANJARO
	CPU:  Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
	RAM:  15953 MiB

and FreeBSD:

	Odin: dev-2022-10:075040ae
	OS:   FreeBSD: Unknown
	CPU:  Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
	RAM:  990 MiB

FreeBSD uname -r: 13.0-RELEASE
2022-10-17 22:32:10 -05:00

90 lines
1.6 KiB
Odin

package libc
// 7.5 Errors
when ODIN_OS == .Windows {
foreign import libc "system:libucrt.lib"
} else when ODIN_OS == .Darwin {
foreign import libc "system:System.framework"
} else {
foreign import libc "system:c"
}
// C11 standard only requires the definition of:
// EDOM,
// EILSEQ
// ERANGE
when ODIN_OS == .Linux {
@(private="file")
@(default_calling_convention="c")
foreign libc {
@(link_name="__errno_location")
_get_errno :: proc() -> ^int ---
}
EDOM :: 33
EILSEQ :: 84
ERANGE :: 34
}
when ODIN_OS == .FreeBSD {
@(private="file")
@(default_calling_convention="c")
foreign libc {
@(link_name="__error")
_get_errno :: proc() -> ^int ---
}
EDOM :: 33
EILSEQ :: 84
ERANGE :: 34
}
when ODIN_OS == .OpenBSD {
@(private="file")
@(default_calling_convention="c")
foreign libc {
@(link_name="__errno")
_get_errno :: proc() -> ^int ---
}
EDOM :: 33
EILSEQ :: 84
ERANGE :: 34
}
when ODIN_OS == .Windows {
@(private="file")
@(default_calling_convention="c")
foreign libc {
@(link_name="_errno")
_get_errno :: proc() -> ^int ---
}
EDOM :: 33
EILSEQ :: 42
ERANGE :: 34
}
when ODIN_OS == .Darwin {
@(private="file")
@(default_calling_convention="c")
foreign libc {
@(link_name="__error")
_get_errno :: proc() -> ^int ---
}
// Unknown
EDOM :: 33
EILSEQ :: 92
ERANGE :: 34
}
// Odin has no way to make an identifier "errno" behave as a function call to
// read the value, or to produce an lvalue such that you can assign a different
// error value to errno. To work around this, just expose it as a function like
// it actually is.
errno :: #force_inline proc() -> ^int {
return _get_errno()
}