mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 11:50:07 +00:00
Merge branch 'master' into extend_win32_api_types
This commit is contained in:
@@ -108,6 +108,16 @@ Application_setMainMenu :: proc "c" (self: ^Application, menu: ^Menu) {
|
||||
msgSend(nil, self, "setMainMenu:", menu)
|
||||
}
|
||||
|
||||
@(objc_type=Application, objc_name="mainWindow")
|
||||
Application_mainWindow :: proc "c" (self: ^Application) -> ^Window {
|
||||
return msgSend(^Window, self, "mainWindow")
|
||||
}
|
||||
|
||||
@(objc_type=Application, objc_name="keyWindow")
|
||||
Application_keyWindow :: proc "c" (self: ^Application) -> ^Window {
|
||||
return msgSend(^Window, self, "keyWindow")
|
||||
}
|
||||
|
||||
@(objc_type=Application, objc_name="windows")
|
||||
Application_windows :: proc "c" (self: ^Application) -> ^Array {
|
||||
return msgSend(^Array, self, "windows")
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package objc_Foundation
|
||||
|
||||
@(objc_class="NSObjectProtocol")
|
||||
ObjectProtocol :: struct {using _: Object}
|
||||
// TODO: implement NSObjectProtocol
|
||||
@@ -0,0 +1,203 @@
|
||||
package objc_Foundation
|
||||
|
||||
import "base:intrinsics"
|
||||
|
||||
import "core:c"
|
||||
|
||||
@(objc_class="NSProcessInfo")
|
||||
ProcessInfo :: struct {using _: Object}
|
||||
|
||||
// Getting the Process Information Agent
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="processInfo", objc_is_class_method=true)
|
||||
ProcessInfo_processInfo :: proc "c" () -> ^ProcessInfo {
|
||||
return msgSend(^ProcessInfo, ProcessInfo, "processInfo")
|
||||
}
|
||||
|
||||
// Accessing Process Information
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="arguments")
|
||||
ProcessInfo_arguments :: proc "c" (self: ^ProcessInfo) -> ^Array {
|
||||
return msgSend(^Array, self, "arguments")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="environment")
|
||||
ProcessInfo_environment :: proc "c" (self: ^ProcessInfo) -> ^Dictionary {
|
||||
return msgSend(^Dictionary, self, "environment")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="globallyUniqueString")
|
||||
ProcessInfo_globallyUniqueString :: proc "c" (self: ^ProcessInfo) -> ^String {
|
||||
return msgSend(^String, self, "globallyUniqueString")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="isMacCatalystApp")
|
||||
ProcessInfo_isMacCatalystApp :: proc "c" (self: ^ProcessInfo) -> bool {
|
||||
return msgSend(bool, self, "isMacCatalystApp")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="isiOSAppOnMac")
|
||||
ProcessInfo_isiOSAppOnMac :: proc "c" (self: ^ProcessInfo) -> bool {
|
||||
return msgSend(bool, self, "isiOSAppOnMac")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="processIdentifier")
|
||||
ProcessInfo_processIdentifier :: proc "c" (self: ^ProcessInfo) -> c.int {
|
||||
return msgSend(c.int, self, "processIdentifier")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="processName")
|
||||
ProcessInfo_processName :: proc "c" (self: ^ProcessInfo) -> ^String {
|
||||
return msgSend(^String, self, "processName")
|
||||
}
|
||||
|
||||
// Accessing User Information
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="userName")
|
||||
ProcessInfo_userName :: proc "c" (self: ^ProcessInfo) -> ^String {
|
||||
return msgSend(^String, self, "userName")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="fullUserName")
|
||||
ProcessInfo_fullUserName :: proc "c" (self: ^ProcessInfo) -> ^String {
|
||||
return msgSend(^String, self, "fullUserName")
|
||||
}
|
||||
|
||||
// Sudden Application Termination
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="disableSuddenTermination")
|
||||
ProcessInfo_disableSuddenTermination :: proc "c" (self: ^ProcessInfo) {
|
||||
msgSend(nil, self, "disableSuddenTermination")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="enableSuddenTermination")
|
||||
ProcessInfo_enableSuddenTermination :: proc "c" (self: ^ProcessInfo) {
|
||||
msgSend(nil, self, "enableSuddenTermination")
|
||||
}
|
||||
|
||||
// Controlling Automatic Termination
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="disableAutomaticTermination")
|
||||
ProcessInfo_disableAutomaticTermination :: proc "c" (self: ^ProcessInfo, reason: ^String) {
|
||||
msgSend(nil, self, "disableAutomaticTermination:", reason)
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="enableAutomaticTermination")
|
||||
ProcessInfo_enableAutomaticTermination :: proc "c" (self: ^ProcessInfo, reason: ^String) {
|
||||
msgSend(nil, self, "enableAutomaticTermination:", reason)
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="automaticTerminationSupportEnabled")
|
||||
ProcessInfo_automaticTerminationSupportEnabled :: proc "c" (self: ^ProcessInfo) -> bool {
|
||||
return msgSend(bool, self, "automaticTerminationSupportEnabled")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="setAutomaticTerminationSupportEnabled")
|
||||
ProcessInfo_setAutomaticTerminationSupportEnabled :: proc "c" (self: ^ProcessInfo, automaticTerminationSupportEnabled: bool) {
|
||||
msgSend(nil, self, "setAutomaticTerminationSupportEnabled:", automaticTerminationSupportEnabled)
|
||||
}
|
||||
|
||||
// Getting Host Information
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="hostName")
|
||||
ProcessInfo_hostName :: proc "c" (self: ^ProcessInfo) -> ^String {
|
||||
return msgSend(^String, self, "hostName")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="operatingSystemVersionString")
|
||||
ProcessInfo_operatingSystemVersionString :: proc "c" (self: ^ProcessInfo) -> ^String {
|
||||
return msgSend(^String, self, "operatingSystemVersionString")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="operatingSystemVersion")
|
||||
ProcessInfo_operatingSystemVersion :: proc "c" (self: ^ProcessInfo) -> OperatingSystemVersion {
|
||||
return msgSend(OperatingSystemVersion, self, "operatingSystemVersion")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="isOperatingSystemAtLeastVersion")
|
||||
ProcessInfo_isOperatingSystemAtLeastVersion :: proc "c" (self: ^ProcessInfo, version: OperatingSystemVersion) -> bool {
|
||||
return msgSend(bool, self, "isOperatingSystemAtLeastVersion:", version)
|
||||
}
|
||||
|
||||
// Getting Computer Information
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="processorCount")
|
||||
ProcessInfo_processorCount :: proc "c" (self: ^ProcessInfo) -> UInteger {
|
||||
return msgSend(UInteger, self, "processorCount")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="activeProcessorCount")
|
||||
ProcessInfo_activeProcessorCount :: proc "c" (self: ^ProcessInfo) -> UInteger {
|
||||
return msgSend(UInteger, self, "activeProcessorCount")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="physicalMemory")
|
||||
ProcessInfo_physicalMemory :: proc "c" (self: ^ProcessInfo) -> c.ulonglong {
|
||||
return msgSend(c.ulonglong, self, "physicalMemory")
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="systemUptime")
|
||||
ProcessInfo_systemUptime :: proc "c" (self: ^ProcessInfo) -> TimeInterval {
|
||||
return msgSend(TimeInterval, self, "systemUptime")
|
||||
}
|
||||
|
||||
// Managing Activities
|
||||
|
||||
@(private)
|
||||
log2 :: intrinsics.constant_log2
|
||||
|
||||
ActivityOptionsBits :: enum u64 {
|
||||
IdleDisplaySleepDisabled = log2(1099511627776), // Require the screen to stay powered on.
|
||||
IdleSystemSleepDisabled = log2(1048576), // Prevent idle sleep.
|
||||
SuddenTerminationDisabled = log2(16384), // Prevent sudden termination.
|
||||
AutomaticTerminationDisabled = log2(32768), // Prevent automatic termination.
|
||||
AnimationTrackingEnabled = log2(35184372088832), // Track activity with an animation signpost interval.
|
||||
TrackingEnabled = log2(70368744177664), // Track activity with a signpost interval.
|
||||
UserInitiated = log2(16777215), // Performing a user-requested action.
|
||||
UserInitiatedAllowingIdleSystemSleep = log2(15728639), // Performing a user-requested action, but the system can sleep on idle.
|
||||
Background = log2(255), // Initiated some kind of work, but not as the direct result of a user request.
|
||||
LatencyCritical = log2(1095216660480), // Requires the highest amount of timer and I/O precision available.
|
||||
UserInteractive = log2(1095233437695), // Responding to user interaction.
|
||||
}
|
||||
ActivityOptions :: bit_set[ActivityOptionsBits; u64]
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="beginActivityWithOptions")
|
||||
ProcessInfo_beginActivityWithOptions :: proc "c" (self: ^ProcessInfo, options: ActivityOptions, reason: ^String) -> ^ObjectProtocol {
|
||||
return msgSend(^ObjectProtocol, self, "beginActivityWithOptions:reason:", options, reason)
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="endActivity")
|
||||
ProcessInfo_endActivity :: proc "c" (self: ^ProcessInfo, activity: ^ObjectProtocol) {
|
||||
msgSend(nil, self, "endActivity:", activity)
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="performActivityWithOptions")
|
||||
ProcessInfo_performActivityWithOptions :: proc "c" (self: ^ProcessInfo, options: ActivityOptions, reason: ^String, block: proc "c" ()) {
|
||||
msgSend(nil, self, "performActivityWithOptions:reason:usingBlock:", options, reason, block)
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="performExpiringActivityWithReason")
|
||||
ProcessInfo_performExpiringActivityWithReason :: proc "c" (self: ^ProcessInfo, reason: ^String, block: proc "c" (expired: bool)) {
|
||||
msgSend(nil, self, "performExpiringActivityWithReason:usingBlock:", reason, block)
|
||||
}
|
||||
|
||||
// Getting the Thermal State
|
||||
|
||||
ProcessInfoThermalState :: enum c.long {
|
||||
Nominal,
|
||||
Fair,
|
||||
Serious,
|
||||
Critical,
|
||||
}
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="thermalState")
|
||||
ProcessInfo_thermalState :: proc "c" (self: ^ProcessInfo) -> ProcessInfoThermalState {
|
||||
return msgSend(ProcessInfoThermalState, self, "thermalState")
|
||||
}
|
||||
|
||||
// Determining Whether Low Power Mode is Enabled
|
||||
|
||||
@(objc_type=ProcessInfo, objc_name="isLowPowerModeEnabled")
|
||||
ProcessInfo_isLowPowerModeEnabled :: proc "c" (self: ^ProcessInfo) -> bool {
|
||||
return msgSend(bool, self, "isLowPowerModeEnabled")
|
||||
}
|
||||
@@ -20,7 +20,7 @@ BOOL :: bool // TODO(bill): should this be `distinct`?
|
||||
YES :: true
|
||||
NO :: false
|
||||
|
||||
OperatingSystemVersion :: struct #packed {
|
||||
OperatingSystemVersion :: struct #align(8) {
|
||||
majorVersion: Integer,
|
||||
minorVersion: Integer,
|
||||
patchVersion: Integer,
|
||||
@@ -58,4 +58,4 @@ when size_of(Float) == 8 {
|
||||
} else {
|
||||
_POINT_ENCODING :: "{NSPoint=ff}"
|
||||
_SIZE_ENCODING :: "{NSSize=ff}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,23 @@ CPU_Feature :: enum u64 {
|
||||
ssse3, // Supplemental streaming SIMD extension 3
|
||||
sse41, // Streaming SIMD extension 4 and 4.1
|
||||
sse42, // Streaming SIMD extension 4 and 4.2
|
||||
|
||||
avx512bf16, // Vector Neural Network Instructions supporting bfloat16
|
||||
avx512bitalg, // Bit Algorithms
|
||||
avx512bw, // Byte and Word instructions
|
||||
avx512cd, // Conflict Detection instructions
|
||||
avx512dq, // Doubleword and Quadword instructions
|
||||
avx512er, // Exponential and Reciprocal instructions
|
||||
avx512f, // Foundation
|
||||
avx512fp16, // Vector 16-bit float instructions
|
||||
avx512ifma, // Integer Fused Multiply Add
|
||||
avx512pf, // Prefetch instructions
|
||||
avx512vbmi, // Vector Byte Manipulation Instructions
|
||||
avx512vbmi2, // Vector Byte Manipulation Instructions 2
|
||||
avx512vl, // Vector Length extensions
|
||||
avx512vnni, // Vector Neural Network Instructions
|
||||
avx512vp2intersect, // Vector Pair Intersection to a Pair of Mask Registers
|
||||
avx512vpopcntdq, // Vector Population Count for Doubleword and Quadword
|
||||
}
|
||||
|
||||
CPU_Features :: distinct bit_set[CPU_Feature; u64]
|
||||
@@ -82,9 +99,11 @@ init_cpu_features :: proc "c" () {
|
||||
//
|
||||
// See: crbug.com/375968
|
||||
os_supports_avx := false
|
||||
os_supports_avx512 := false
|
||||
if .os_xsave in set && is_set(26, ecx1) {
|
||||
eax, _ := xgetbv(0)
|
||||
os_supports_avx = is_set(1, eax) && is_set(2, eax)
|
||||
os_supports_avx512 = is_set(5, eax) && is_set(6, eax) && is_set(7, eax)
|
||||
}
|
||||
if os_supports_avx {
|
||||
try_set(&set, .avx, 28, ecx1)
|
||||
@@ -94,11 +113,37 @@ init_cpu_features :: proc "c" () {
|
||||
return
|
||||
}
|
||||
|
||||
_, ebx7, _, _ := cpuid(7, 0)
|
||||
_, ebx7, ecx7, edx7 := cpuid(7, 0)
|
||||
try_set(&set, .bmi1, 3, ebx7)
|
||||
if os_supports_avx {
|
||||
try_set(&set, .avx2, 5, ebx7)
|
||||
}
|
||||
if os_supports_avx512 {
|
||||
try_set(&set, .avx512f, 16, ebx7)
|
||||
try_set(&set, .avx512dq, 17, ebx7)
|
||||
try_set(&set, .avx512ifma, 21, ebx7)
|
||||
try_set(&set, .avx512pf, 26, ebx7)
|
||||
try_set(&set, .avx512er, 27, ebx7)
|
||||
try_set(&set, .avx512cd, 28, ebx7)
|
||||
try_set(&set, .avx512bw, 30, ebx7)
|
||||
|
||||
// XMM/YMM are also required for 128/256-bit instructions
|
||||
if os_supports_avx {
|
||||
try_set(&set, .avx512vl, 31, ebx7)
|
||||
}
|
||||
|
||||
try_set(&set, .avx512vbmi, 1, ecx7)
|
||||
try_set(&set, .avx512vbmi2, 6, ecx7)
|
||||
try_set(&set, .avx512vnni, 11, ecx7)
|
||||
try_set(&set, .avx512bitalg, 12, ecx7)
|
||||
try_set(&set, .avx512vpopcntdq, 14, ecx7)
|
||||
|
||||
try_set(&set, .avx512vp2intersect, 8, edx7)
|
||||
try_set(&set, .avx512fp16, 23, edx7)
|
||||
|
||||
eax7_1, _, _, _ := cpuid(7, 1)
|
||||
try_set(&set, .avx512bf16, 5, eax7_1)
|
||||
}
|
||||
try_set(&set, .bmi2, 8, ebx7)
|
||||
try_set(&set, .erms, 9, ebx7)
|
||||
try_set(&set, .rdseed, 18, ebx7)
|
||||
|
||||
@@ -4,7 +4,7 @@ Made available under Odin's BSD-3 license.
|
||||
|
||||
List of contributors:
|
||||
Jeroen van Rijn: Initial implementation.
|
||||
Laytan: ARM and RISC-V CPU feature detection.
|
||||
Laytan: ARM and RISC-V CPU feature detection, iOS/macOS platform overhaul.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,581 +1,101 @@
|
||||
package sysinfo
|
||||
|
||||
import sys "core:sys/unix"
|
||||
import "core:strconv"
|
||||
import "core:strings"
|
||||
import "base:runtime"
|
||||
import "core:strconv"
|
||||
import "core:strings"
|
||||
import "core:sys/unix"
|
||||
import NS "core:sys/darwin/Foundation"
|
||||
|
||||
@(private)
|
||||
version_string_buf: [1024]u8
|
||||
|
||||
@(init, private)
|
||||
init_os_version :: proc () {
|
||||
os_version.platform = .MacOS
|
||||
init_platform :: proc() {
|
||||
ws :: strings.write_string
|
||||
wi :: strings.write_int
|
||||
|
||||
// Start building display version
|
||||
b := strings.builder_from_bytes(version_string_buf[:])
|
||||
|
||||
mib := []i32{sys.CTL_KERN, sys.KERN_OSVERSION}
|
||||
build_buf: [12]u8
|
||||
version: NS.OperatingSystemVersion
|
||||
{
|
||||
NS.scoped_autoreleasepool()
|
||||
|
||||
ok := sys.sysctl(mib, &build_buf)
|
||||
if !ok {
|
||||
strings.write_string(&b, "macOS Unknown")
|
||||
os_version.as_string = strings.to_string(b)
|
||||
return
|
||||
info := NS.ProcessInfo.processInfo()
|
||||
version = info->operatingSystemVersion()
|
||||
mem := info->physicalMemory()
|
||||
|
||||
ram.total_ram = int(mem)
|
||||
}
|
||||
|
||||
build := string(cstring(&build_buf[0]))
|
||||
macos_version = {int(version.majorVersion), int(version.minorVersion), int(version.patchVersion)}
|
||||
|
||||
// Do we have an exact match?
|
||||
match: Darwin_Match
|
||||
rel, exact := macos_release_map[build]
|
||||
|
||||
if exact {
|
||||
match = .Exact
|
||||
when ODIN_PLATFORM_SUBTARGET == .iOS {
|
||||
os_version.platform = .iOS
|
||||
ws(&b, "iOS")
|
||||
} else {
|
||||
os_version.platform = .MacOS
|
||||
switch version.majorVersion {
|
||||
case 15: ws(&b, "macOS Sequoia")
|
||||
case 14: ws(&b, "macOS Sonoma")
|
||||
case 13: ws(&b, "macOS Ventura")
|
||||
case 12: ws(&b, "macOS Monterey")
|
||||
case 11: ws(&b, "macOS Big Sur")
|
||||
case 10:
|
||||
switch version.minorVersion {
|
||||
case 15: ws(&b, "macOS Catalina")
|
||||
case 14: ws(&b, "macOS Mojave")
|
||||
case 13: ws(&b, "macOS High Sierra")
|
||||
case 12: ws(&b, "macOS Sierra")
|
||||
case 11: ws(&b, "OS X El Capitan")
|
||||
case 10: ws(&b, "OS X Yosemite")
|
||||
case:
|
||||
// `ProcessInfo.operatingSystemVersion` is 10.10 and up.
|
||||
unreachable()
|
||||
}
|
||||
case:
|
||||
// New version not yet added here.
|
||||
assert(version.majorVersion > 15)
|
||||
ws(&b, "macOS Unknown")
|
||||
}
|
||||
}
|
||||
|
||||
ws(&b, " ")
|
||||
wi(&b, int(version.majorVersion))
|
||||
ws(&b, ".")
|
||||
wi(&b, int(version.minorVersion))
|
||||
ws(&b, ".")
|
||||
wi(&b, int(version.patchVersion))
|
||||
|
||||
{
|
||||
build_buf: [12]u8
|
||||
mib := []i32{unix.CTL_KERN, unix.KERN_OSVERSION}
|
||||
ok := unix.sysctl(mib, &build_buf)
|
||||
build := string(cstring(raw_data(build_buf[:]))) if ok else "Unknown"
|
||||
|
||||
ws(&b, " (build ")
|
||||
|
||||
build_start := len(b.buf)
|
||||
ws(&b, build)
|
||||
os_version.version = string(b.buf[build_start:][:len(build)])
|
||||
}
|
||||
|
||||
{
|
||||
// Match on XNU kernel version
|
||||
mib = []i32{sys.CTL_KERN, sys.KERN_OSRELEASE}
|
||||
version_bits: [12]u8 // enough for 999.999.999\x00
|
||||
have_kernel_version := sys.sysctl(mib, &version_bits)
|
||||
mib := []i32{unix.CTL_KERN, unix.KERN_OSRELEASE}
|
||||
ok := unix.sysctl(mib, &version_bits)
|
||||
kernel := string(cstring(raw_data(version_bits[:]))) if ok else "Unknown"
|
||||
|
||||
major_ok, minor_ok, patch_ok: bool
|
||||
major, _, tail := strings.partition(kernel, ".")
|
||||
minor, _, patch := strings.partition(tail, ".")
|
||||
|
||||
tmp := runtime.default_temp_allocator_temp_begin()
|
||||
os_version.major, _ = strconv.parse_int(major, 10)
|
||||
os_version.minor, _ = strconv.parse_int(minor, 10)
|
||||
os_version.patch, _ = strconv.parse_int(patch, 10)
|
||||
|
||||
triplet := strings.split(string(cstring(&version_bits[0])), ".", context.temp_allocator)
|
||||
if len(triplet) != 3 {
|
||||
have_kernel_version = false
|
||||
} else {
|
||||
rel.darwin.x, major_ok = strconv.parse_int(triplet[0])
|
||||
rel.darwin.y, minor_ok = strconv.parse_int(triplet[1])
|
||||
rel.darwin.z, patch_ok = strconv.parse_int(triplet[2])
|
||||
|
||||
if !(major_ok && minor_ok && patch_ok) {
|
||||
have_kernel_version = false
|
||||
}
|
||||
}
|
||||
|
||||
runtime.default_temp_allocator_temp_end(tmp)
|
||||
|
||||
if !have_kernel_version {
|
||||
// We don't know the kernel version, but we do know the build
|
||||
strings.write_string(&b, "macOS Unknown (build ")
|
||||
l := strings.builder_len(b)
|
||||
strings.write_string(&b, build)
|
||||
os_version.version = strings.to_string(b)[l:]
|
||||
strings.write_rune(&b, ')')
|
||||
os_version.as_string = strings.to_string(b)
|
||||
return
|
||||
}
|
||||
rel, match = map_darwin_kernel_version_to_macos_release(build, rel.darwin)
|
||||
ws(&b, ", kernel ")
|
||||
ws(&b, kernel)
|
||||
ws(&b, ")")
|
||||
}
|
||||
|
||||
os_version.major = rel.darwin.x
|
||||
os_version.minor = rel.darwin.y
|
||||
os_version.patch = rel.darwin.z
|
||||
|
||||
macos_version = transmute(Version)rel.release.version
|
||||
|
||||
strings.write_string(&b, rel.os_name)
|
||||
if match == .Exact || match == .Nearest {
|
||||
strings.write_rune(&b, ' ')
|
||||
strings.write_string(&b, rel.release.name)
|
||||
strings.write_rune(&b, ' ')
|
||||
strings.write_int(&b, rel.release.version.x)
|
||||
if rel.release.version.y > 0 || rel.release.version.z > 0 {
|
||||
strings.write_rune(&b, '.')
|
||||
strings.write_int(&b, rel.release.version.y)
|
||||
}
|
||||
if rel.release.version.z > 0 {
|
||||
strings.write_rune(&b, '.')
|
||||
strings.write_int(&b, rel.release.version.z)
|
||||
}
|
||||
if match == .Nearest {
|
||||
strings.write_rune(&b, '?')
|
||||
}
|
||||
} else {
|
||||
strings.write_string(&b, " Unknown")
|
||||
}
|
||||
|
||||
strings.write_string(&b, " (build ")
|
||||
l := strings.builder_len(b)
|
||||
strings.write_string(&b, build)
|
||||
os_version.version = strings.to_string(b)[l:]
|
||||
|
||||
strings.write_string(&b, ", kernel ")
|
||||
strings.write_int(&b, rel.darwin.x)
|
||||
strings.write_rune(&b, '.')
|
||||
strings.write_int(&b, rel.darwin.y)
|
||||
strings.write_rune(&b, '.')
|
||||
strings.write_int(&b, rel.darwin.z)
|
||||
strings.write_rune(&b, ')')
|
||||
|
||||
os_version.as_string = strings.to_string(b)
|
||||
}
|
||||
|
||||
@(init, private)
|
||||
init_ram :: proc() {
|
||||
// Retrieve RAM info using `sysctl`
|
||||
|
||||
mib := []i32{sys.CTL_HW, sys.HW_MEMSIZE}
|
||||
mem_size: u64
|
||||
if sys.sysctl(mib, &mem_size) {
|
||||
ram.total_ram = int(mem_size)
|
||||
}
|
||||
}
|
||||
|
||||
@(private)
|
||||
Darwin_To_Release :: struct {
|
||||
darwin: [3]int, // Darwin kernel triplet
|
||||
os_name: string, // OS X, MacOS
|
||||
release: struct {
|
||||
name: string, // Monterey, Mojave, etc.
|
||||
version: [3]int, // 12.4, etc.
|
||||
},
|
||||
}
|
||||
|
||||
// Important: Order from lowest to highest kernel version
|
||||
@(private)
|
||||
macos_release_map: map[string]Darwin_To_Release = {
|
||||
// MacOS Tiger
|
||||
"8A428" = {{8, 0, 0}, "macOS", {"Tiger", {10, 4, 0}}},
|
||||
"8A432" = {{8, 0, 0}, "macOS", {"Tiger", {10, 4, 0}}},
|
||||
"8B15" = {{8, 1, 0}, "macOS", {"Tiger", {10, 4, 1}}},
|
||||
"8B17" = {{8, 1, 0}, "macOS", {"Tiger", {10, 4, 1}}},
|
||||
"8C46" = {{8, 2, 0}, "macOS", {"Tiger", {10, 4, 2}}},
|
||||
"8C47" = {{8, 2, 0}, "macOS", {"Tiger", {10, 4, 2}}},
|
||||
"8E102" = {{8, 2, 0}, "macOS", {"Tiger", {10, 4, 2}}},
|
||||
"8E45" = {{8, 2, 0}, "macOS", {"Tiger", {10, 4, 2}}},
|
||||
"8E90" = {{8, 2, 0}, "macOS", {"Tiger", {10, 4, 2}}},
|
||||
"8F46" = {{8, 3, 0}, "macOS", {"Tiger", {10, 4, 3}}},
|
||||
"8G32" = {{8, 4, 0}, "macOS", {"Tiger", {10, 4, 4}}},
|
||||
"8G1165" = {{8, 4, 0}, "macOS", {"Tiger", {10, 4, 4}}},
|
||||
"8H14" = {{8, 5, 0}, "macOS", {"Tiger", {10, 4, 5}}},
|
||||
"8G1454" = {{8, 5, 0}, "macOS", {"Tiger", {10, 4, 5}}},
|
||||
"8I127" = {{8, 6, 0}, "macOS", {"Tiger", {10, 4, 6}}},
|
||||
"8I1119" = {{8, 6, 0}, "macOS", {"Tiger", {10, 4, 6}}},
|
||||
"8J135" = {{8, 7, 0}, "macOS", {"Tiger", {10, 4, 7}}},
|
||||
"8J2135a" = {{8, 7, 0}, "macOS", {"Tiger", {10, 4, 7}}},
|
||||
"8K1079" = {{8, 7, 0}, "macOS", {"Tiger", {10, 4, 7}}},
|
||||
"8N5107" = {{8, 7, 0}, "macOS", {"Tiger", {10, 4, 7}}},
|
||||
"8L127" = {{8, 8, 0}, "macOS", {"Tiger", {10, 4, 8}}},
|
||||
"8L2127" = {{8, 8, 0}, "macOS", {"Tiger", {10, 4, 8}}},
|
||||
"8P135" = {{8, 9, 0}, "macOS", {"Tiger", {10, 4, 9}}},
|
||||
"8P2137" = {{8, 9, 0}, "macOS", {"Tiger", {10, 4, 9}}},
|
||||
"8R218" = {{8, 10, 0}, "macOS", {"Tiger", {10, 4, 10}}},
|
||||
"8R2218" = {{8, 10, 0}, "macOS", {"Tiger", {10, 4, 10}}},
|
||||
"8R2232" = {{8, 10, 0}, "macOS", {"Tiger", {10, 4, 10}}},
|
||||
"8S165" = {{8, 11, 0}, "macOS", {"Tiger", {10, 4, 11}}},
|
||||
"8S2167" = {{8, 11, 0}, "macOS", {"Tiger", {10, 4, 11}}},
|
||||
|
||||
// MacOS Leopard
|
||||
"9A581" = {{9, 0, 0}, "macOS", {"Leopard", {10, 5, 0}}},
|
||||
"9B18" = {{9, 1, 0}, "macOS", {"Leopard", {10, 5, 1}}},
|
||||
"9B2117" = {{9, 1, 1}, "macOS", {"Leopard", {10, 5, 1}}},
|
||||
"9C31" = {{9, 2, 0}, "macOS", {"Leopard", {10, 5, 2}}},
|
||||
"9C7010" = {{9, 2, 0}, "macOS", {"Leopard", {10, 5, 2}}},
|
||||
"9D34" = {{9, 3, 0}, "macOS", {"Leopard", {10, 5, 3}}},
|
||||
"9E17" = {{9, 4, 0}, "macOS", {"Leopard", {10, 5, 4}}},
|
||||
"9F33" = {{9, 5, 0}, "macOS", {"Leopard", {10, 5, 5}}},
|
||||
"9G55" = {{9, 6, 0}, "macOS", {"Leopard", {10, 5, 6}}},
|
||||
"9G66" = {{9, 6, 0}, "macOS", {"Leopard", {10, 5, 6}}},
|
||||
"9G71" = {{9, 6, 0}, "macOS", {"Leopard", {10, 5, 6}}},
|
||||
"9J61" = {{9, 7, 0}, "macOS", {"Leopard", {10, 5, 7}}},
|
||||
"9L30" = {{9, 8, 0}, "macOS", {"Leopard", {10, 5, 8}}},
|
||||
"9L34" = {{9, 8, 0}, "macOS", {"Leopard", {10, 5, 8}}},
|
||||
|
||||
// MacOS Snow Leopard
|
||||
"10A432" = {{10, 0, 0}, "macOS", {"Snow Leopard", {10, 6, 0}}},
|
||||
"10A433" = {{10, 0, 0}, "macOS", {"Snow Leopard", {10, 6, 0}}},
|
||||
"10B504" = {{10, 1, 0}, "macOS", {"Snow Leopard", {10, 6, 1}}},
|
||||
"10C540" = {{10, 2, 0}, "macOS", {"Snow Leopard", {10, 6, 2}}},
|
||||
"10D573" = {{10, 3, 0}, "macOS", {"Snow Leopard", {10, 6, 3}}},
|
||||
"10D575" = {{10, 3, 0}, "macOS", {"Snow Leopard", {10, 6, 3}}},
|
||||
"10D578" = {{10, 3, 0}, "macOS", {"Snow Leopard", {10, 6, 3}}},
|
||||
"10F569" = {{10, 4, 0}, "macOS", {"Snow Leopard", {10, 6, 4}}},
|
||||
"10H574" = {{10, 5, 0}, "macOS", {"Snow Leopard", {10, 6, 5}}},
|
||||
"10J567" = {{10, 6, 0}, "macOS", {"Snow Leopard", {10, 6, 6}}},
|
||||
"10J869" = {{10, 7, 0}, "macOS", {"Snow Leopard", {10, 6, 7}}},
|
||||
"10J3250" = {{10, 7, 0}, "macOS", {"Snow Leopard", {10, 6, 7}}},
|
||||
"10J4138" = {{10, 7, 0}, "macOS", {"Snow Leopard", {10, 6, 7}}},
|
||||
"10K540" = {{10, 8, 0}, "macOS", {"Snow Leopard", {10, 6, 8}}},
|
||||
"10K549" = {{10, 8, 0}, "macOS", {"Snow Leopard", {10, 6, 8}}},
|
||||
|
||||
// MacOS Lion
|
||||
"11A511" = {{11, 0, 0}, "macOS", {"Lion", {10, 7, 0}}},
|
||||
"11A511s" = {{11, 0, 0}, "macOS", {"Lion", {10, 7, 0}}},
|
||||
"11A2061" = {{11, 0, 2}, "macOS", {"Lion", {10, 7, 0}}},
|
||||
"11A2063" = {{11, 0, 2}, "macOS", {"Lion", {10, 7, 0}}},
|
||||
"11B26" = {{11, 1, 0}, "macOS", {"Lion", {10, 7, 1}}},
|
||||
"11B2118" = {{11, 1, 0}, "macOS", {"Lion", {10, 7, 1}}},
|
||||
"11C74" = {{11, 2, 0}, "macOS", {"Lion", {10, 7, 2}}},
|
||||
"11D50" = {{11, 3, 0}, "macOS", {"Lion", {10, 7, 3}}},
|
||||
"11E53" = {{11, 4, 0}, "macOS", {"Lion", {10, 7, 4}}},
|
||||
"11G56" = {{11, 4, 2}, "macOS", {"Lion", {10, 7, 5}}},
|
||||
"11G63" = {{11, 4, 2}, "macOS", {"Lion", {10, 7, 5}}},
|
||||
|
||||
// MacOS Mountain Lion
|
||||
"12A269" = {{12, 0, 0}, "macOS", {"Mountain Lion", {10, 8, 0}}},
|
||||
"12B19" = {{12, 1, 0}, "macOS", {"Mountain Lion", {10, 8, 1}}},
|
||||
"12C54" = {{12, 2, 0}, "macOS", {"Mountain Lion", {10, 8, 2}}},
|
||||
"12C60" = {{12, 2, 0}, "macOS", {"Mountain Lion", {10, 8, 2}}},
|
||||
"12C2034" = {{12, 2, 0}, "macOS", {"Mountain Lion", {10, 8, 2}}},
|
||||
"12C3104" = {{12, 2, 0}, "macOS", {"Mountain Lion", {10, 8, 2}}},
|
||||
"12D78" = {{12, 3, 0}, "macOS", {"Mountain Lion", {10, 8, 3}}},
|
||||
"12E55" = {{12, 4, 0}, "macOS", {"Mountain Lion", {10, 8, 4}}},
|
||||
"12E3067" = {{12, 4, 0}, "macOS", {"Mountain Lion", {10, 8, 4}}},
|
||||
"12E4022" = {{12, 4, 0}, "macOS", {"Mountain Lion", {10, 8, 4}}},
|
||||
"12F37" = {{12, 5, 0}, "macOS", {"Mountain Lion", {10, 8, 5}}},
|
||||
"12F45" = {{12, 5, 0}, "macOS", {"Mountain Lion", {10, 8, 5}}},
|
||||
"12F2501" = {{12, 5, 0}, "macOS", {"Mountain Lion", {10, 8, 5}}},
|
||||
"12F2518" = {{12, 5, 0}, "macOS", {"Mountain Lion", {10, 8, 5}}},
|
||||
"12F2542" = {{12, 5, 0}, "macOS", {"Mountain Lion", {10, 8, 5}}},
|
||||
"12F2560" = {{12, 5, 0}, "macOS", {"Mountain Lion", {10, 8, 5}}},
|
||||
|
||||
// MacOS Mavericks
|
||||
"13A603" = {{13, 0, 0}, "macOS", {"Mavericks", {10, 9, 0}}},
|
||||
"13B42" = {{13, 0, 0}, "macOS", {"Mavericks", {10, 9, 1}}},
|
||||
"13C64" = {{13, 1, 0}, "macOS", {"Mavericks", {10, 9, 2}}},
|
||||
"13C1021" = {{13, 1, 0}, "macOS", {"Mavericks", {10, 9, 2}}},
|
||||
"13D65" = {{13, 2, 0}, "macOS", {"Mavericks", {10, 9, 3}}},
|
||||
"13E28" = {{13, 3, 0}, "macOS", {"Mavericks", {10, 9, 4}}},
|
||||
"13F34" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1066" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1077" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1096" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1112" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1134" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1507" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1603" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1712" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1808" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
"13F1911" = {{13, 4, 0}, "macOS", {"Mavericks", {10, 9, 5}}},
|
||||
|
||||
// MacOS Yosemite
|
||||
"14A389" = {{14, 0, 0}, "macOS", {"Yosemite", {10, 10, 0}}},
|
||||
"14B25" = {{14, 0, 0}, "macOS", {"Yosemite", {10, 10, 1}}},
|
||||
"14C109" = {{14, 1, 0}, "macOS", {"Yosemite", {10, 10, 2}}},
|
||||
"14C1510" = {{14, 1, 0}, "macOS", {"Yosemite", {10, 10, 2}}},
|
||||
"14C2043" = {{14, 1, 0}, "macOS", {"Yosemite", {10, 10, 2}}},
|
||||
"14C1514" = {{14, 1, 0}, "macOS", {"Yosemite", {10, 10, 2}}},
|
||||
"14C2513" = {{14, 1, 0}, "macOS", {"Yosemite", {10, 10, 2}}},
|
||||
"14D131" = {{14, 3, 0}, "macOS", {"Yosemite", {10, 10, 3}}},
|
||||
"14D136" = {{14, 3, 0}, "macOS", {"Yosemite", {10, 10, 3}}},
|
||||
"14E46" = {{14, 4, 0}, "macOS", {"Yosemite", {10, 10, 4}}},
|
||||
"14F27" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F1021" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F1505" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F1509" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F1605" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F1713" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F1808" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F1909" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F1912" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F2009" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F2109" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F2315" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F2411" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
"14F2511" = {{14, 5, 0}, "macOS", {"Yosemite", {10, 10, 5}}},
|
||||
|
||||
// MacOS El Capitan
|
||||
"15A284" = {{15, 0, 0}, "macOS", {"El Capitan", {10, 11, 0}}},
|
||||
"15B42" = {{15, 0, 0}, "macOS", {"El Capitan", {10, 11, 1}}},
|
||||
"15C50" = {{15, 2, 0}, "macOS", {"El Capitan", {10, 11, 2}}},
|
||||
"15D21" = {{15, 3, 0}, "macOS", {"El Capitan", {10, 11, 3}}},
|
||||
"15E65" = {{15, 4, 0}, "macOS", {"El Capitan", {10, 11, 4}}},
|
||||
"15F34" = {{15, 5, 0}, "macOS", {"El Capitan", {10, 11, 5}}},
|
||||
"15G31" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G1004" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G1011" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G1108" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G1212" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G1217" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G1421" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G1510" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G1611" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G17023" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G18013" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G19009" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G20015" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G21013" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
"15G22010" = {{15, 6, 0}, "macOS", {"El Capitan", {10, 11, 6}}},
|
||||
|
||||
// MacOS Sierra
|
||||
"16A323" = {{16, 0, 0}, "macOS", {"Sierra", {10, 12, 0}}},
|
||||
"16B2555" = {{16, 1, 0}, "macOS", {"Sierra", {10, 12, 1}}},
|
||||
"16B2657" = {{16, 1, 0}, "macOS", {"Sierra", {10, 12, 1}}},
|
||||
"16C67" = {{16, 3, 0}, "macOS", {"Sierra", {10, 12, 2}}},
|
||||
"16C68" = {{16, 3, 0}, "macOS", {"Sierra", {10, 12, 2}}},
|
||||
"16D32" = {{16, 4, 0}, "macOS", {"Sierra", {10, 12, 3}}},
|
||||
"16E195" = {{16, 5, 0}, "macOS", {"Sierra", {10, 12, 4}}},
|
||||
"16F73" = {{16, 6, 0}, "macOS", {"Sierra", {10, 12, 5}}},
|
||||
"16F2073" = {{16, 6, 0}, "macOS", {"Sierra", {10, 12, 5}}},
|
||||
"16G29" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1036" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1114" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1212" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1314" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1408" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1510" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1618" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1710" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1815" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1917" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G1918" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G2016" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G2127" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G2128" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
"16G2136" = {{16, 7, 0}, "macOS", {"Sierra", {10, 12, 6}}},
|
||||
|
||||
// MacOS High Sierra
|
||||
"17A365" = {{17, 0, 0}, "macOS", {"High Sierra", {10, 13, 0}}},
|
||||
"17A405" = {{17, 0, 0}, "macOS", {"High Sierra", {10, 13, 0}}},
|
||||
"17B48" = {{17, 2, 0}, "macOS", {"High Sierra", {10, 13, 1}}},
|
||||
"17B1002" = {{17, 2, 0}, "macOS", {"High Sierra", {10, 13, 1}}},
|
||||
"17B1003" = {{17, 2, 0}, "macOS", {"High Sierra", {10, 13, 1}}},
|
||||
"17C88" = {{17, 3, 0}, "macOS", {"High Sierra", {10, 13, 2}}},
|
||||
"17C89" = {{17, 3, 0}, "macOS", {"High Sierra", {10, 13, 2}}},
|
||||
"17C205" = {{17, 3, 0}, "macOS", {"High Sierra", {10, 13, 2}}},
|
||||
"17C2205" = {{17, 3, 0}, "macOS", {"High Sierra", {10, 13, 2}}},
|
||||
"17D47" = {{17, 4, 0}, "macOS", {"High Sierra", {10, 13, 3}}},
|
||||
"17D2047" = {{17, 4, 0}, "macOS", {"High Sierra", {10, 13, 3}}},
|
||||
"17D102" = {{17, 4, 0}, "macOS", {"High Sierra", {10, 13, 3}}},
|
||||
"17D2102" = {{17, 4, 0}, "macOS", {"High Sierra", {10, 13, 3}}},
|
||||
"17E199" = {{17, 5, 0}, "macOS", {"High Sierra", {10, 13, 4}}},
|
||||
"17E202" = {{17, 5, 0}, "macOS", {"High Sierra", {10, 13, 4}}},
|
||||
"17F77" = {{17, 6, 0}, "macOS", {"High Sierra", {10, 13, 5}}},
|
||||
"17G65" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G2208" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G2307" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G3025" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G4015" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G5019" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G6029" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G6030" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G7024" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G8029" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G8030" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G8037" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G9016" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G10021" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G11023" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G12034" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G13033" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G13035" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G14019" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G14033" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
"17G14042" = {{17, 7, 0}, "macOS", {"High Sierra", {10, 13, 6}}},
|
||||
|
||||
// MacOS Mojave
|
||||
"18A391" = {{18, 0, 0}, "macOS", {"Mojave", {10, 14, 0}}},
|
||||
"18B75" = {{18, 2, 0}, "macOS", {"Mojave", {10, 14, 1}}},
|
||||
"18B2107" = {{18, 2, 0}, "macOS", {"Mojave", {10, 14, 1}}},
|
||||
"18B3094" = {{18, 2, 0}, "macOS", {"Mojave", {10, 14, 1}}},
|
||||
"18C54" = {{18, 2, 0}, "macOS", {"Mojave", {10, 14, 2}}},
|
||||
"18D42" = {{18, 2, 0}, "macOS", {"Mojave", {10, 14, 3}}},
|
||||
"18D43" = {{18, 2, 0}, "macOS", {"Mojave", {10, 14, 3}}},
|
||||
"18D109" = {{18, 2, 0}, "macOS", {"Mojave", {10, 14, 3}}},
|
||||
"18E226" = {{18, 5, 0}, "macOS", {"Mojave", {10, 14, 4}}},
|
||||
"18E227" = {{18, 5, 0}, "macOS", {"Mojave", {10, 14, 4}}},
|
||||
"18F132" = {{18, 6, 0}, "macOS", {"Mojave", {10, 14, 5}}},
|
||||
"18G84" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G87" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G95" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G103" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G1012" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G2022" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G3020" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G4032" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G5033" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G6020" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G6032" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G6042" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G7016" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G8012" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G8022" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G9028" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G9216" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
"18G9323" = {{18, 7, 0}, "macOS", {"Mojave", {10, 14, 6}}},
|
||||
|
||||
// MacOS Catalina
|
||||
"19A583" = {{19, 0, 0}, "macOS", {"Catalina", {10, 15, 0}}},
|
||||
"19A602" = {{19, 0, 0}, "macOS", {"Catalina", {10, 15, 0}}},
|
||||
"19A603" = {{19, 0, 0}, "macOS", {"Catalina", {10, 15, 0}}},
|
||||
"19B88" = {{19, 0, 0}, "macOS", {"Catalina", {10, 15, 1}}},
|
||||
"19C57" = {{19, 2, 0}, "macOS", {"Catalina", {10, 15, 2}}},
|
||||
"19C58" = {{19, 2, 0}, "macOS", {"Catalina", {10, 15, 2}}},
|
||||
"19D76" = {{19, 3, 0}, "macOS", {"Catalina", {10, 15, 3}}},
|
||||
"19E266" = {{19, 4, 0}, "macOS", {"Catalina", {10, 15, 4}}},
|
||||
"19E287" = {{19, 4, 0}, "macOS", {"Catalina", {10, 15, 4}}},
|
||||
"19F96" = {{19, 5, 0}, "macOS", {"Catalina", {10, 15, 5}}},
|
||||
"19F101" = {{19, 5, 0}, "macOS", {"Catalina", {10, 15, 5}}},
|
||||
"19G73" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 6}}},
|
||||
"19G2021" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 6}}},
|
||||
"19H2" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H4" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H15" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H114" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H512" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H524" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1030" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1217" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1323" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1417" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1419" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1519" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1615" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1713" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1715" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1824" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H1922" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
"19H2026" = {{19, 6, 0}, "macOS", {"Catalina", {10, 15, 7}}},
|
||||
|
||||
// MacOS Big Sur
|
||||
"20A2411" = {{20, 1, 0}, "macOS", {"Big Sur", {11, 0, 0}}},
|
||||
"20B29" = {{20, 1, 0}, "macOS", {"Big Sur", {11, 0, 1}}},
|
||||
"20B50" = {{20, 1, 0}, "macOS", {"Big Sur", {11, 0, 1}}},
|
||||
"20C69" = {{20, 2, 0}, "macOS", {"Big Sur", {11, 1, 0}}},
|
||||
"20D64" = {{20, 3, 0}, "macOS", {"Big Sur", {11, 2, 0}}},
|
||||
"20D74" = {{20, 3, 0}, "macOS", {"Big Sur", {11, 2, 1}}},
|
||||
"20D75" = {{20, 3, 0}, "macOS", {"Big Sur", {11, 2, 1}}},
|
||||
"20D80" = {{20, 3, 0}, "macOS", {"Big Sur", {11, 2, 2}}},
|
||||
"20D91" = {{20, 3, 0}, "macOS", {"Big Sur", {11, 2, 3}}},
|
||||
"20E232" = {{20, 4, 0}, "macOS", {"Big Sur", {11, 3, 0}}},
|
||||
"20E241" = {{20, 4, 0}, "macOS", {"Big Sur", {11, 3, 1}}},
|
||||
"20F71" = {{20, 5, 0}, "macOS", {"Big Sur", {11, 4, 0}}},
|
||||
"20G71" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 5, 0}}},
|
||||
"20G80" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 5, 1}}},
|
||||
"20G95" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 5, 2}}},
|
||||
"20G165" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 6, 0}}},
|
||||
"20G224" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 6, 1}}},
|
||||
"20G314" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 6, 2}}},
|
||||
"20G415" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 6, 3}}},
|
||||
"20G417" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 6, 4}}},
|
||||
"20G527" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 6, 5}}},
|
||||
"20G624" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 6, 6}}},
|
||||
"20G630" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 6, 7}}},
|
||||
"20G730" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 6, 8}}},
|
||||
"20G817" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 0}}},
|
||||
"20G918" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 1}}},
|
||||
"20G1020" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 2}}},
|
||||
"20G1116" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 3}}},
|
||||
"20G1120" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 4}}},
|
||||
"20G1225" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 5}}},
|
||||
"20G1231" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 6}}},
|
||||
"20G1345" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 7}}},
|
||||
"20G1351" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 8}}},
|
||||
"20G1426" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 9}}},
|
||||
"20G1427" = {{20, 6, 0}, "macOS", {"Big Sur", {11, 7, 10}}},
|
||||
|
||||
// MacOS Monterey
|
||||
"21A344" = {{21, 0, 1}, "macOS", {"Monterey", {12, 0, 0}}},
|
||||
"21A559" = {{21, 1, 0}, "macOS", {"Monterey", {12, 0, 1}}},
|
||||
"21C52" = {{21, 2, 0}, "macOS", {"Monterey", {12, 1, 0}}},
|
||||
"21D49" = {{21, 3, 0}, "macOS", {"Monterey", {12, 2, 0}}},
|
||||
"21D62" = {{21, 3, 0}, "macOS", {"Monterey", {12, 2, 1}}},
|
||||
"21E230" = {{21, 4, 0}, "macOS", {"Monterey", {12, 3, 0}}},
|
||||
"21E258" = {{21, 4, 0}, "macOS", {"Monterey", {12, 3, 1}}},
|
||||
"21F79" = {{21, 5, 0}, "macOS", {"Monterey", {12, 4, 0}}},
|
||||
"21F2081" = {{21, 5, 0}, "macOS", {"Monterey", {12, 4, 0}}},
|
||||
"21F2092" = {{21, 5, 0}, "macOS", {"Monterey", {12, 4, 0}}},
|
||||
"21G72" = {{21, 6, 0}, "macOS", {"Monterey", {12, 5, 0}}},
|
||||
"21G83" = {{21, 6, 0}, "macOS", {"Monterey", {12, 5, 1}}},
|
||||
"21G115" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 0}}},
|
||||
"21G217" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 1}}},
|
||||
"21G320" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 2}}},
|
||||
"21G419" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 3}}},
|
||||
"21G526" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 4}}},
|
||||
"21G531" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 5}}},
|
||||
"21G646" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 6}}},
|
||||
"21G651" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 7}}},
|
||||
"21G725" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 8}}},
|
||||
"21G726" = {{21, 6, 0}, "macOS", {"Monterey", {12, 6, 9}}},
|
||||
"21G816" = {{21, 6, 0}, "macOS", {"Monterey", {12, 7, 0}}},
|
||||
"21G920" = {{21, 6, 0}, "macOS", {"Monterey", {12, 7, 1}}},
|
||||
"21G1974" = {{21, 6, 0}, "macOS", {"Monterey", {12, 7, 2}}},
|
||||
|
||||
// MacOS Ventura
|
||||
"22A380" = {{22, 1, 0}, "macOS", {"Ventura", {13, 0, 0}}},
|
||||
"22A400" = {{22, 1, 0}, "macOS", {"Ventura", {13, 0, 1}}},
|
||||
"22C65" = {{22, 2, 0}, "macOS", {"Ventura", {13, 1, 0}}},
|
||||
"22D49" = {{22, 3, 0}, "macOS", {"Ventura", {13, 2, 0}}},
|
||||
"22D68" = {{22, 3, 0}, "macOS", {"Ventura", {13, 2, 1}}},
|
||||
"22E252" = {{22, 4, 0}, "macOS", {"Ventura", {13, 3, 0}}},
|
||||
"22E261" = {{22, 4, 0}, "macOS", {"Ventura", {13, 3, 1}}},
|
||||
"22F66" = {{22, 5, 0}, "macOS", {"Ventura", {13, 4, 0}}},
|
||||
"22F82" = {{22, 5, 0}, "macOS", {"Ventura", {13, 4, 1}}},
|
||||
"22E772610a" = {{22, 5, 0}, "macOS", {"Ventura", {13, 4, 1}}},
|
||||
"22F770820d" = {{22, 5, 0}, "macOS", {"Ventura", {13, 4, 1}}},
|
||||
"22G74" = {{22, 6, 0}, "macOS", {"Ventura", {13, 5, 0}}},
|
||||
"22G90" = {{22, 6, 0}, "macOS", {"Ventura", {13, 5, 1}}},
|
||||
"22G91" = {{22, 6, 0}, "macOS", {"Ventura", {13, 5, 2}}},
|
||||
"22G120" = {{22, 6, 0}, "macOS", {"Ventura", {13, 6, 0}}},
|
||||
"22G313" = {{22, 6, 0}, "macOS", {"Ventura", {13, 6, 1}}},
|
||||
"22G320" = {{22, 6, 0}, "macOS", {"Ventura", {13, 6, 2}}},
|
||||
|
||||
// MacOS Sonoma
|
||||
"23A344" = {{23, 0, 0}, "macOS", {"Sonoma", {14, 0, 0}}},
|
||||
"23B74" = {{23, 1, 0}, "macOS", {"Sonoma", {14, 1, 0}}},
|
||||
"23B81" = {{23, 1, 0}, "macOS", {"Sonoma", {14, 1, 1}}},
|
||||
"23B2082" = {{23, 1, 0}, "macOS", {"Sonoma", {14, 1, 1}}},
|
||||
"23B92" = {{23, 1, 0}, "macOS", {"Sonoma", {14, 1, 2}}},
|
||||
"23B2091" = {{23, 1, 0}, "macOS", {"Sonoma", {14, 1, 2}}},
|
||||
"23C64" = {{23, 2, 0}, "macOS", {"Sonoma", {14, 2, 0}}},
|
||||
"23C71" = {{23, 2, 0}, "macOS", {"Sonoma", {14, 2, 1}}},
|
||||
"23D56" = {{23, 3, 0}, "macOS", {"Sonoma", {14, 3, 0}}},
|
||||
"23D60" = {{23, 3, 0}, "macOS", {"Sonoma", {14, 3, 1}}},
|
||||
"23E214" = {{23, 4, 0}, "macOS", {"Sonoma", {14, 4, 0}}},
|
||||
"23E224" = {{23, 4, 0}, "macOS", {"Sonoma", {14, 4, 1}}},
|
||||
"23F79" = {{23, 5, 0}, "macOS", {"Sonoma", {14, 5, 0}}},
|
||||
"23G80" = {{23, 6, 0}, "macOS", {"Sonoma", {14, 6, 0}}},
|
||||
"23G93" = {{23, 6, 0}, "macOS", {"Sonoma", {14, 6, 1}}},
|
||||
"23H124" = {{23, 6, 0}, "macOS", {"Sonoma", {14, 7, 0}}},
|
||||
|
||||
// MacOS Sequoia
|
||||
"24A335" = {{24, 0, 0}, "macOS", {"Sequoia", {15, 0, 0}}},
|
||||
"24A348" = {{24, 0, 0}, "macOS", {"Sequoia", {15, 0, 1}}},
|
||||
}
|
||||
|
||||
@(private)
|
||||
Darwin_Match :: enum {
|
||||
Unknown,
|
||||
Exact,
|
||||
Nearest,
|
||||
}
|
||||
|
||||
@(private)
|
||||
map_darwin_kernel_version_to_macos_release :: proc(build: string, darwin: [3]int) -> (res: Darwin_To_Release, match: Darwin_Match) {
|
||||
// Find exact release match if possible.
|
||||
if v, v_ok := macos_release_map[build]; v_ok {
|
||||
return v, .Exact
|
||||
}
|
||||
|
||||
nearest: Darwin_To_Release
|
||||
for _, v in macos_release_map {
|
||||
// Try an exact match on XNU version first.
|
||||
if darwin == v.darwin {
|
||||
return v, .Exact
|
||||
}
|
||||
|
||||
// Major kernel version needs to match exactly,
|
||||
// otherwise the release is considered .Unknown
|
||||
if darwin.x == v.darwin.x {
|
||||
if nearest == {} {
|
||||
nearest = v
|
||||
}
|
||||
if darwin.y >= v.darwin.y && v.darwin != nearest.darwin {
|
||||
nearest = v
|
||||
if darwin.z >= v.darwin.z && v.darwin != nearest.darwin {
|
||||
nearest = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if nearest == {} {
|
||||
return {darwin, "macOS", {"Unknown", {}}}, .Unknown
|
||||
} else {
|
||||
return nearest, .Nearest
|
||||
}
|
||||
os_version.as_string = string(b.buf[:])
|
||||
}
|
||||
|
||||
+88
-36
@@ -152,43 +152,65 @@ Errno :: enum i32 {
|
||||
RDONLY flag is not present, because it has the value of 0, i.e. it is the
|
||||
default, unless WRONLY or RDWR is specified.
|
||||
*/
|
||||
Open_Flags_Bits :: enum {
|
||||
WRONLY = 0,
|
||||
RDWR = 1,
|
||||
CREAT = 6,
|
||||
EXCL = 7,
|
||||
NOCTTY = 8,
|
||||
TRUNC = 9,
|
||||
APPEND = 10,
|
||||
NONBLOCK = 11,
|
||||
DSYNC = 12,
|
||||
ASYNC = 13,
|
||||
DIRECT = 14,
|
||||
LARGEFILE = 15,
|
||||
DIRECTORY = 16,
|
||||
NOFOLLOW = 17,
|
||||
NOATIME = 18,
|
||||
CLOEXEC = 19,
|
||||
PATH = 21,
|
||||
when ODIN_ARCH != .arm64 && ODIN_ARCH != .arm32 {
|
||||
Open_Flags_Bits :: enum {
|
||||
WRONLY = 0,
|
||||
RDWR = 1,
|
||||
CREAT = 6,
|
||||
EXCL = 7,
|
||||
NOCTTY = 8,
|
||||
TRUNC = 9,
|
||||
APPEND = 10,
|
||||
NONBLOCK = 11,
|
||||
DSYNC = 12,
|
||||
ASYNC = 13,
|
||||
DIRECT = 14,
|
||||
LARGEFILE = 15,
|
||||
DIRECTORY = 16,
|
||||
NOFOLLOW = 17,
|
||||
NOATIME = 18,
|
||||
CLOEXEC = 19,
|
||||
PATH = 21,
|
||||
}
|
||||
// https://github.com/torvalds/linux/blob/7367539ad4b0f8f9b396baf02110962333719a48/include/uapi/asm-generic/fcntl.h#L19
|
||||
#assert(1 << uint(Open_Flags_Bits.WRONLY) == 0o0000000_1)
|
||||
#assert(1 << uint(Open_Flags_Bits.RDWR) == 0o0000000_2)
|
||||
#assert(1 << uint(Open_Flags_Bits.CREAT) == 0o00000_100)
|
||||
#assert(1 << uint(Open_Flags_Bits.EXCL) == 0o00000_200)
|
||||
#assert(1 << uint(Open_Flags_Bits.NOCTTY) == 0o00000_400)
|
||||
#assert(1 << uint(Open_Flags_Bits.TRUNC) == 0o0000_1000)
|
||||
#assert(1 << uint(Open_Flags_Bits.APPEND) == 0o0000_2000)
|
||||
#assert(1 << uint(Open_Flags_Bits.NONBLOCK) == 0o0000_4000)
|
||||
#assert(1 << uint(Open_Flags_Bits.DSYNC) == 0o000_10000)
|
||||
#assert(1 << uint(Open_Flags_Bits.ASYNC) == 0o000_20000)
|
||||
#assert(1 << uint(Open_Flags_Bits.DIRECT) == 0o000_40000)
|
||||
#assert(1 << uint(Open_Flags_Bits.LARGEFILE) == 0o00_100000)
|
||||
#assert(1 << uint(Open_Flags_Bits.DIRECTORY) == 0o00_200000)
|
||||
#assert(1 << uint(Open_Flags_Bits.NOFOLLOW) == 0o00_400000)
|
||||
#assert(1 << uint(Open_Flags_Bits.NOATIME) == 0o0_1000000)
|
||||
#assert(1 << uint(Open_Flags_Bits.CLOEXEC) == 0o0_2000000)
|
||||
#assert(1 << uint(Open_Flags_Bits.PATH) == 0o_10000000)
|
||||
} else {
|
||||
Open_Flags_Bits :: enum {
|
||||
WRONLY = 0,
|
||||
RDWR = 1,
|
||||
CREAT = 6,
|
||||
EXCL = 7,
|
||||
NOCTTY = 8,
|
||||
TRUNC = 9,
|
||||
APPEND = 10,
|
||||
NONBLOCK = 11,
|
||||
DSYNC = 12,
|
||||
ASYNC = 13,
|
||||
DIRECTORY = 14,
|
||||
NOFOLLOW = 15,
|
||||
DIRECT = 16,
|
||||
LARGEFILE = 17,
|
||||
NOATIME = 18,
|
||||
CLOEXEC = 19,
|
||||
PATH = 21,
|
||||
}
|
||||
}
|
||||
// https://github.com/torvalds/linux/blob/7367539ad4b0f8f9b396baf02110962333719a48/include/uapi/asm-generic/fcntl.h#L19
|
||||
#assert(1 << uint(Open_Flags_Bits.WRONLY) == 0o0000000_1)
|
||||
#assert(1 << uint(Open_Flags_Bits.RDWR) == 0o0000000_2)
|
||||
#assert(1 << uint(Open_Flags_Bits.CREAT) == 0o00000_100)
|
||||
#assert(1 << uint(Open_Flags_Bits.EXCL) == 0o00000_200)
|
||||
#assert(1 << uint(Open_Flags_Bits.NOCTTY) == 0o00000_400)
|
||||
#assert(1 << uint(Open_Flags_Bits.TRUNC) == 0o0000_1000)
|
||||
#assert(1 << uint(Open_Flags_Bits.APPEND) == 0o0000_2000)
|
||||
#assert(1 << uint(Open_Flags_Bits.NONBLOCK) == 0o0000_4000)
|
||||
#assert(1 << uint(Open_Flags_Bits.DSYNC) == 0o000_10000)
|
||||
#assert(1 << uint(Open_Flags_Bits.ASYNC) == 0o000_20000)
|
||||
#assert(1 << uint(Open_Flags_Bits.DIRECT) == 0o000_40000)
|
||||
#assert(1 << uint(Open_Flags_Bits.LARGEFILE) == 0o00_100000)
|
||||
#assert(1 << uint(Open_Flags_Bits.DIRECTORY) == 0o00_200000)
|
||||
#assert(1 << uint(Open_Flags_Bits.NOFOLLOW) == 0o00_400000)
|
||||
#assert(1 << uint(Open_Flags_Bits.NOATIME) == 0o0_1000000)
|
||||
#assert(1 << uint(Open_Flags_Bits.CLOEXEC) == 0o0_2000000)
|
||||
#assert(1 << uint(Open_Flags_Bits.PATH) == 0o_10000000)
|
||||
|
||||
/*
|
||||
Bits for FD_Flags bitset
|
||||
@@ -519,6 +541,36 @@ Fd_Poll_Events_Bits :: enum {
|
||||
RDHUP = 13,
|
||||
}
|
||||
|
||||
Inotify_Init_Bits :: enum {
|
||||
NONBLOCK = 11,
|
||||
CLOEXEC = 19,
|
||||
}
|
||||
|
||||
Inotify_Event_Bits :: enum u32 {
|
||||
ACCESS = 0,
|
||||
MODIFY = 1,
|
||||
ATTRIB = 2,
|
||||
CLOSE_WRITE = 3,
|
||||
CLOSE_NOWRITE = 4,
|
||||
OPEN = 5,
|
||||
MOVED_FROM = 6,
|
||||
MOVED_TO = 7,
|
||||
CREATE = 8,
|
||||
DELETE = 9,
|
||||
DELETE_SELF = 10,
|
||||
MOVE_SELF = 11,
|
||||
UNMOUNT = 13,
|
||||
Q_OVERFLOW = 14,
|
||||
IGNORED = 15,
|
||||
ONLYDIR = 24,
|
||||
DONT_FOLLOW = 25,
|
||||
EXCL_UNLINK = 26,
|
||||
MASK_CREATE = 28,
|
||||
MASK_ADD = 29,
|
||||
ISDIR = 30,
|
||||
ONESHOT = 31,
|
||||
}
|
||||
|
||||
/*
|
||||
Bits for Mem_Protection bitfield
|
||||
*/
|
||||
|
||||
@@ -135,6 +135,31 @@ STATX_BASIC_STATS :: Statx_Mask {
|
||||
.BLOCKS,
|
||||
}
|
||||
|
||||
IN_ALL_EVENTS :: Inotify_Event_Mask {
|
||||
.ACCESS,
|
||||
.MODIFY,
|
||||
.ATTRIB,
|
||||
.CLOSE_WRITE,
|
||||
.CLOSE_NOWRITE,
|
||||
.OPEN,
|
||||
.MOVED_FROM,
|
||||
.MOVED_TO,
|
||||
.CREATE,
|
||||
.DELETE,
|
||||
.DELETE_SELF,
|
||||
.MOVE_SELF,
|
||||
}
|
||||
|
||||
IN_CLOSE :: Inotify_Event_Mask {
|
||||
.CLOSE_WRITE,
|
||||
.CLOSE_NOWRITE,
|
||||
}
|
||||
|
||||
IN_MOVE :: Inotify_Event_Mask {
|
||||
.MOVED_FROM,
|
||||
.MOVED_TO,
|
||||
}
|
||||
|
||||
/*
|
||||
Tell `shmget` to create a new key
|
||||
*/
|
||||
|
||||
+22
-3
@@ -2536,11 +2536,30 @@ waitid :: proc "contextless" (id_type: Id_Type, id: Id, sig_info: ^Sig_Info, opt
|
||||
|
||||
// TODO(flysand): ioprio_get
|
||||
|
||||
// TODO(flysand): inotify_init
|
||||
inotify_init :: proc "contextless" () -> (Fd, Errno) {
|
||||
when ODIN_ARCH == .arm64 || ODIN_ARCH == .riscv64 {
|
||||
ret := syscall(SYS_inotify_init1, 0)
|
||||
return errno_unwrap(ret, Fd)
|
||||
} else {
|
||||
ret := syscall(SYS_inotify_init)
|
||||
return errno_unwrap(ret, Fd)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(flysand): inotify_add_watch
|
||||
inotify_init1 :: proc "contextless" (flags: Inotify_Init_Flags) -> (Fd, Errno) {
|
||||
ret := syscall(SYS_inotify_init1, transmute(i32)flags)
|
||||
return errno_unwrap(ret, Fd)
|
||||
}
|
||||
|
||||
// TODO(flysand): inotify_rm_watch
|
||||
inotify_add_watch :: proc "contextless" (fd: Fd, pathname: cstring, mask: Inotify_Event_Mask) -> (Wd, Errno) {
|
||||
ret := syscall(SYS_inotify_add_watch, fd, transmute(uintptr) pathname, transmute(u32) mask)
|
||||
return errno_unwrap(ret, Wd)
|
||||
}
|
||||
|
||||
inotify_rm_watch :: proc "contextless" (fd: Fd, wd: Wd) -> (Errno) {
|
||||
ret := syscall(SYS_inotify_rm_watch, fd, wd)
|
||||
return Errno(-ret)
|
||||
}
|
||||
|
||||
// TODO(flysand): migrate_pages
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@ Id :: distinct uint
|
||||
*/
|
||||
Fd :: distinct i32
|
||||
|
||||
/*
|
||||
Represents a watch descriptor.
|
||||
*/
|
||||
Wd :: distinct i32
|
||||
|
||||
/*
|
||||
Type for PID file descriptors.
|
||||
*/
|
||||
@@ -343,6 +348,18 @@ Poll_Fd :: struct {
|
||||
revents: Fd_Poll_Events,
|
||||
}
|
||||
|
||||
Inotify_Init_Flags :: bit_set[Inotify_Init_Bits; i32]
|
||||
|
||||
Inotify_Event :: struct {
|
||||
wd: Wd,
|
||||
mask: Inotify_Event_Mask,
|
||||
cookie: u32,
|
||||
len: u32,
|
||||
name: [0]u8,
|
||||
}
|
||||
|
||||
Inotify_Event_Mask :: bit_set[Inotify_Event_Bits; u32]
|
||||
|
||||
/*
|
||||
Specifies protection for memory pages.
|
||||
*/
|
||||
@@ -667,6 +684,14 @@ Address_Family :: distinct Protocol_Family
|
||||
*/
|
||||
Socket_Msg :: bit_set[Socket_Msg_Bits; i32]
|
||||
|
||||
/*
|
||||
Struct representing a generic socket address.
|
||||
*/
|
||||
Sock_Addr :: struct #packed {
|
||||
sa_family: Address_Family,
|
||||
sa_data: [14]u8,
|
||||
}
|
||||
|
||||
/*
|
||||
Struct representing IPv4 socket address.
|
||||
*/
|
||||
@@ -674,6 +699,7 @@ Sock_Addr_In :: struct #packed {
|
||||
sin_family: Address_Family,
|
||||
sin_port: u16be,
|
||||
sin_addr: [4]u8,
|
||||
sin_zero: [size_of(Sock_Addr) - size_of(Address_Family) - size_of(u16be) - size_of([4]u8)]u8,
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -703,6 +729,7 @@ Sock_Addr_Any :: struct #raw_union {
|
||||
family: Address_Family,
|
||||
port: u16be,
|
||||
},
|
||||
using generic: Sock_Addr,
|
||||
using ipv4: Sock_Addr_In,
|
||||
using ipv6: Sock_Addr_In6,
|
||||
using uds: Sock_Addr_Un,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build darwin, linux, freebsd, openbsd, netbsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
|
||||
+41
-26
@@ -1,3 +1,4 @@
|
||||
#+build darwin, linux, freebsd, openbsd, netbsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -29,12 +30,12 @@ foreign lib {
|
||||
panic(string(posix.strerror(posix.errno())))
|
||||
}
|
||||
defer posix.free(list)
|
||||
|
||||
|
||||
entries := list[:ret]
|
||||
for entry in entries {
|
||||
log.info(entry)
|
||||
posix.free(entry)
|
||||
}
|
||||
for entry in entries {
|
||||
log.info(entry)
|
||||
posix.free(entry)
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/scandir.html ]]
|
||||
*/
|
||||
@@ -53,15 +54,6 @@ foreign lib {
|
||||
*/
|
||||
closedir :: proc(dirp: DIR) -> result ---
|
||||
|
||||
/*
|
||||
Return a file descriptor referring to the same directory as the dirp argument.
|
||||
|
||||
// TODO: this is a macro on NetBSD?
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html ]]
|
||||
*/
|
||||
dirfd :: proc(dirp: DIR) -> FD ---
|
||||
|
||||
/*
|
||||
Equivalent to the opendir() function except that the directory is specified by a file descriptor
|
||||
rather than by a name.
|
||||
@@ -89,16 +81,16 @@ foreign lib {
|
||||
Returns nil when the end is reached or an error occurred (which sets errno).
|
||||
|
||||
Example:
|
||||
posix.set_errno(.NONE)
|
||||
entry := posix.readdir(dirp)
|
||||
if entry == nil {
|
||||
if errno := posix.errno(); errno != .NONE {
|
||||
panic(string(posix.strerror(errno)))
|
||||
} else {
|
||||
fmt.println("end of directory stream")
|
||||
}
|
||||
} else {
|
||||
fmt.println(entry)
|
||||
posix.set_errno(.NONE)
|
||||
entry := posix.readdir(dirp)
|
||||
if entry == nil {
|
||||
if errno := posix.errno(); errno != .NONE {
|
||||
panic(string(posix.strerror(errno)))
|
||||
} else {
|
||||
fmt.println("end of directory stream")
|
||||
}
|
||||
} else {
|
||||
fmt.println(entry)
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/readdir.html ]]
|
||||
@@ -160,11 +152,36 @@ when ODIN_OS == .NetBSD {
|
||||
@(private) LSCANDIR :: "__scandir30"
|
||||
@(private) LOPENDIR :: "__opendir30"
|
||||
@(private) LREADDIR :: "__readdir30"
|
||||
|
||||
/*
|
||||
Return a file descriptor referring to the same directory as the dirp argument.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html ]]
|
||||
*/
|
||||
dirfd :: proc "c" (dirp: DIR) -> FD {
|
||||
_dirdesc :: struct {
|
||||
dd_fd: FD,
|
||||
|
||||
// more stuff...
|
||||
}
|
||||
|
||||
return (^_dirdesc)(dirp).dd_fd
|
||||
}
|
||||
|
||||
} else {
|
||||
@(private) LALPHASORT :: "alphasort" + INODE_SUFFIX
|
||||
@(private) LSCANDIR :: "scandir" + INODE_SUFFIX
|
||||
@(private) LOPENDIR :: "opendir" + INODE_SUFFIX
|
||||
@(private) LREADDIR :: "readdir" + INODE_SUFFIX
|
||||
|
||||
foreign lib {
|
||||
/*
|
||||
Return a file descriptor referring to the same directory as the dirp argument.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html ]]
|
||||
*/
|
||||
dirfd :: proc(dirp: DIR) -> FD ---
|
||||
}
|
||||
}
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
@@ -210,6 +227,4 @@ when ODIN_OS == .Darwin {
|
||||
d_name: [256]c.char `fmt:"s,0"`, /* [PSX] entry name */
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build darwin, linux, freebsd, openbsd, netbsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -120,7 +121,5 @@ when ODIN_OS == .Darwin {
|
||||
_RTLD_LOCAL :: 0
|
||||
RTLD_LOCAL :: RTLD_Flags{}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build windows, darwin, linux, freebsd, openbsd, netbsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -456,7 +457,84 @@ when ODIN_OS == .Darwin {
|
||||
|
||||
EOWNERDEAD :: 130
|
||||
ENOTRECOVERABLE :: 131
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Windows {
|
||||
E2BIG :: 7
|
||||
EACCES :: 13
|
||||
EADDRINUSE :: 100
|
||||
EADDRNOTAVAIL :: 101
|
||||
EAFNOSUPPORT :: 102
|
||||
EAGAIN :: 11
|
||||
EALREADY :: 103
|
||||
EBADF :: 9
|
||||
EBADMSG :: 104
|
||||
EBUSY :: 16
|
||||
ECANCELED :: 105
|
||||
ECHILD :: 10
|
||||
ECONNABORTED :: 106
|
||||
ECONNREFUSED :: 107
|
||||
ECONNRESET :: 108
|
||||
EDEADLK :: 36
|
||||
EDESTADDRREQ :: 109
|
||||
EDQUOT :: -1 // NOTE: not defined
|
||||
EEXIST :: 17
|
||||
EFAULT :: 14
|
||||
EFBIG :: 27
|
||||
EHOSTUNREACH :: 110
|
||||
EIDRM :: 111
|
||||
EINPROGRESS :: 112
|
||||
EINTR :: 4
|
||||
EINVAL :: 22
|
||||
EIO :: 5
|
||||
EISCONN :: 113
|
||||
EISDIR :: 21
|
||||
ELOOP :: 114
|
||||
EMFILE :: 24
|
||||
EMLINK :: 31
|
||||
EMSGSIZE :: 115
|
||||
EMULTIHOP :: -1 // NOTE: not defined
|
||||
ENAMETOOLONG :: 38
|
||||
ENETDOWN :: 116
|
||||
ENETRESET :: 117
|
||||
ENETUNREACH :: 118
|
||||
ENFILE :: 23
|
||||
ENOBUFS :: 119
|
||||
ENODATA :: 120
|
||||
ENODEV :: 19
|
||||
ENOENT :: 2
|
||||
ENOEXEC :: 8
|
||||
ENOLCK :: 39
|
||||
ENOLINK :: 121
|
||||
ENOMEM :: 12
|
||||
ENOMSG :: 122
|
||||
ENOPROTOOPT :: 123
|
||||
ENOSPC :: 28
|
||||
ENOSR :: 124
|
||||
ENOSTR :: 125
|
||||
ENOSYS :: 40
|
||||
ENOTCONN :: 126
|
||||
ENOTDIR :: 20
|
||||
ENOTEMPTY :: 41
|
||||
ENOTRECOVERABLE :: 127
|
||||
ENOTSOCK :: 128
|
||||
ENOTSUP :: 129
|
||||
ENOTTY :: 25
|
||||
ENXIO :: 6
|
||||
EOPNOTSUPP :: 130
|
||||
EOVERFLOW :: 132
|
||||
EOWNERDEAD :: 133
|
||||
EPERM :: 1
|
||||
EPIPE :: 32
|
||||
EPROTO :: 134
|
||||
EPROTONOSUPPORT :: 135
|
||||
EPROTOTYPE :: 136
|
||||
EROFS :: 30
|
||||
ESPIPE :: 29
|
||||
ESRCH :: 3
|
||||
ESTALE :: -1 // NOTE: not defined
|
||||
ETIME :: 137
|
||||
ETIMEDOUT :: 138
|
||||
ETXTBSY :: 139
|
||||
EWOULDBLOCK :: 140
|
||||
EXDEV :: 18
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, openbsd, freebsd, netbsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -466,13 +467,11 @@ when ODIN_OS == .Darwin {
|
||||
AT_REMOVEDIR :: 0x200
|
||||
|
||||
flock :: struct {
|
||||
l_type: Lock_Type, /* [PSX] type of lock. */
|
||||
l_whence: c.short, /* [PSX] flag (Whence) of starting offset. */
|
||||
l_start: off_t, /* [PSX] relative offset in bytes. */
|
||||
l_len: off_t, /* [PSX] size; if 0 then until EOF. */
|
||||
l_pid: pid_t, /* [PSX] process ID of the process holding the lock. */
|
||||
l_type: Lock_Type, /* [PSX] type of lock. */
|
||||
l_whence: c.short, /* [PSX] flag (Whence) of starting offset. */
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build darwin, linux, openbsd, freebsd, netbsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -61,6 +62,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
FNM_NOESCAPE :: 0x02
|
||||
FNM_PERIOD :: 0x04
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -203,6 +204,4 @@ when ODIN_OS == .Darwin {
|
||||
GLOB_ABORTED :: 2
|
||||
GLOB_NOMATCH :: 3
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -125,6 +126,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
gr_mem: [^]cstring, /* [PSX] group members */
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
@@ -56,6 +57,7 @@ foreign lib {
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/basename.html ]]
|
||||
*/
|
||||
@(link_name=LBASENAME)
|
||||
basename :: proc(path: cstring) -> cstring ---
|
||||
|
||||
/*
|
||||
@@ -72,3 +74,9 @@ foreign lib {
|
||||
*/
|
||||
dirname :: proc(path: cstring) -> cstring ---
|
||||
}
|
||||
|
||||
when ODIN_OS == .Linux {
|
||||
@(private) LBASENAME :: "__xpg_basename"
|
||||
} else {
|
||||
@(private) LBASENAME :: "basename"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
// limits.h - implementation-defined constants
|
||||
@@ -549,6 +550,4 @@ when ODIN_OS == .Darwin {
|
||||
NL_TEXTMAX :: 2048 // 255 on glibc, 2048 on musl
|
||||
NZERO :: 20
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
+6
-126
@@ -1,131 +1,11 @@
|
||||
#+build windows, linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
import "core:c/libc"
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
} else {
|
||||
foreign import lib "system:c"
|
||||
}
|
||||
localeconv :: libc.localeconv
|
||||
setlocale :: libc.setlocale
|
||||
|
||||
// locale.h - category macros
|
||||
lconv :: libc.lconv
|
||||
|
||||
foreign lib {
|
||||
/*
|
||||
Sets the components of an object with the type lconv with the values appropriate for the
|
||||
formatting of numeric quantities (monetary and otherwise) according to the rules of the current
|
||||
locale.
|
||||
|
||||
Returns: a pointer to the lconv structure, might be invalidated by subsequent calls to localeconv() and setlocale()
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/localeconv.html ]]
|
||||
*/
|
||||
localeconv :: proc() -> ^lconv ---
|
||||
|
||||
/*
|
||||
Selects the appropriate piece of the global locale, as specified by the category and locale arguments,
|
||||
and can be used to change or query the entire global locale or portions thereof.
|
||||
|
||||
Returns: the current locale if `locale` is `nil`, the set locale otherwise
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/setlocale.html ]]
|
||||
*/
|
||||
@(link_name=LSETLOCALE)
|
||||
setlocale :: proc(category: Locale_Category, locale: cstring) -> cstring ---
|
||||
}
|
||||
|
||||
Locale_Category :: enum c.int {
|
||||
ALL = LC_ALL,
|
||||
COLLATE = LC_COLLATE,
|
||||
CTYPE = LC_CTYPE,
|
||||
MESSAGES = LC_MESSAGES,
|
||||
MONETARY = LC_MONETARY,
|
||||
NUMERIC = LC_NUMERIC,
|
||||
TIME = LC_TIME,
|
||||
}
|
||||
|
||||
when ODIN_OS == .NetBSD {
|
||||
@(private) LSETLOCALE :: "__setlocale50"
|
||||
} else {
|
||||
@(private) LSETLOCALE :: "setlocale"
|
||||
}
|
||||
|
||||
when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
|
||||
|
||||
// NOTE: All of these fields are standard ([PSX]).
|
||||
lconv :: struct {
|
||||
decimal_point: cstring,
|
||||
thousand_sep: cstring,
|
||||
grouping: cstring,
|
||||
int_curr_symbol: cstring,
|
||||
currency_symbol: cstring,
|
||||
mon_decimal_points: cstring,
|
||||
mon_thousands_sep: cstring,
|
||||
mon_grouping: cstring,
|
||||
positive_sign: cstring,
|
||||
negative_sign: cstring,
|
||||
int_frac_digits: c.char,
|
||||
frac_digits: c.char,
|
||||
p_cs_precedes: c.char,
|
||||
p_sep_by_space: c.char,
|
||||
n_cs_precedes: c.char,
|
||||
n_sep_by_space: c.char,
|
||||
p_sign_posn: c.char,
|
||||
n_sign_posn: c.char,
|
||||
int_p_cs_precedes: c.char,
|
||||
int_n_cs_precedes: c.char,
|
||||
int_p_sep_by_space: c.char,
|
||||
int_n_sep_by_space: c.char,
|
||||
int_p_sign_posn: c.char,
|
||||
int_n_sign_posn: c.char,
|
||||
}
|
||||
|
||||
LC_ALL :: 0
|
||||
LC_COLLATE :: 1
|
||||
LC_CTYPE :: 2
|
||||
LC_MESSAGES :: 6
|
||||
LC_MONETARY :: 3
|
||||
LC_NUMERIC :: 4
|
||||
LC_TIME :: 5
|
||||
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
// NOTE: All of these fields are standard ([PSX]).
|
||||
lconv :: struct {
|
||||
decimal_point: cstring,
|
||||
thousand_sep: cstring,
|
||||
grouping: cstring,
|
||||
int_curr_symbol: cstring,
|
||||
currency_symbol: cstring,
|
||||
mon_decimal_points: cstring,
|
||||
mon_thousands_sep: cstring,
|
||||
mon_grouping: cstring,
|
||||
positive_sign: cstring,
|
||||
negative_sign: cstring,
|
||||
int_frac_digits: c.char,
|
||||
frac_digits: c.char,
|
||||
p_cs_precedes: c.char,
|
||||
p_sep_by_space: c.char,
|
||||
n_cs_precedes: c.char,
|
||||
n_sep_by_space: c.char,
|
||||
p_sign_posn: c.char,
|
||||
n_sign_posn: c.char,
|
||||
int_p_cs_precedes: c.char,
|
||||
int_n_cs_precedes: c.char,
|
||||
int_p_sep_by_space: c.char,
|
||||
int_n_sep_by_space: c.char,
|
||||
int_p_sign_posn: c.char,
|
||||
int_n_sign_posn: c.char,
|
||||
}
|
||||
|
||||
LC_CTYPE :: 0
|
||||
LC_NUMERIC :: 1
|
||||
LC_TIME :: 2
|
||||
LC_COLLATE :: 3
|
||||
LC_MONETARY :: 4
|
||||
LC_MESSAGES :: 5
|
||||
LC_ALL :: 6
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
Locale_Category :: libc.Locale_Category
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -55,6 +56,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
|
||||
IF_NAMESIZE :: 16
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -472,6 +473,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
EAI_OVERFLOW :: 14
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -61,6 +62,11 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
sin6_scope_id: c.uint32_t, /* [PSX] set of interfaces for a scope */
|
||||
}
|
||||
|
||||
ipv6_mreq :: struct {
|
||||
ipv6mr_multiaddr: in6_addr, /* [PSX] IPv6 multicast address */
|
||||
ipv6mr_interface: c.uint, /* [PSX] interface index */
|
||||
}
|
||||
|
||||
IPV6_MULTICAST_IF :: 17
|
||||
IPV6_UNICAST_HOPS :: 16
|
||||
IPV6_MULTICAST_HOPS :: 18
|
||||
@@ -223,6 +229,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
)
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
// netinet/tcp.h - definitions for the Internet Transmission Control Protocol (TCP)
|
||||
@@ -6,6 +7,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
|
||||
TCP_NODELAY :: 0x01
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "base:intrinsics"
|
||||
@@ -92,7 +93,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
POLLHUP :: 0x0010
|
||||
POLLNVAL :: 0x0020
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ The struct fields that are cross-platform are documented with `[PSX]`.
|
||||
Accessing these fields on one target should be the same on others.
|
||||
Other fields are implementation specific.
|
||||
|
||||
The parts of POSIX that Windows implements are also supported here, but
|
||||
other symbols are undefined on Windows targets.
|
||||
|
||||
Most macros have been reimplemented in Odin with inlined functions.
|
||||
|
||||
Unimplemented headers:
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
} else when ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD {
|
||||
} else when ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .Linux {
|
||||
foreign import lib "system:pthread"
|
||||
} else {
|
||||
foreign import lib "system:c"
|
||||
@@ -354,12 +355,16 @@ Thread_Scope :: enum c.int {
|
||||
}
|
||||
|
||||
Cancel_State :: enum c.int {
|
||||
// Cancel takes place at next cancellation point.
|
||||
ENABLE = PTHREAD_CANCEL_ENABLE,
|
||||
// Cancel postponed.
|
||||
DISABLE = PTHREAD_CANCEL_DISABLE,
|
||||
}
|
||||
|
||||
Cancel_Type :: enum c.int {
|
||||
// Cancel waits until cancellation point.
|
||||
DEFERRED = PTHREAD_CANCEL_DEFERRED,
|
||||
// Cancel occurs immediately.
|
||||
ASYNCHRONOUS = PTHREAD_CANCEL_ASYNCHRONOUS,
|
||||
}
|
||||
|
||||
@@ -371,6 +376,12 @@ when ODIN_OS == .Darwin {
|
||||
PTHREAD_CANCEL_DISABLE :: 0x00
|
||||
PTHREAD_CANCEL_ENABLE :: 0x01
|
||||
|
||||
// PTHREAD_CANCEL_ASYNCHRONOUS :: 1
|
||||
// PTHREAD_CANCEL_DEFERRED :: 0
|
||||
//
|
||||
// PTHREAD_CANCEL_DISABLE :: 1
|
||||
// PTHREAD_CANCEL_ENABLE :: 0
|
||||
|
||||
PTHREAD_CANCELED :: rawptr(uintptr(1))
|
||||
|
||||
PTHREAD_CREATE_DETACHED :: 2
|
||||
@@ -398,6 +409,16 @@ when ODIN_OS == .Darwin {
|
||||
|
||||
pthread_key_t :: distinct c.ulong
|
||||
|
||||
pthread_mutex_t :: struct {
|
||||
__sig: c.long,
|
||||
__opaque: [56]c.char,
|
||||
}
|
||||
|
||||
pthread_cond_t :: struct {
|
||||
__sig: c.long,
|
||||
__opaque: [40]c.char,
|
||||
}
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
|
||||
_: [4]c.char,
|
||||
@@ -423,18 +444,28 @@ when ODIN_OS == .Darwin {
|
||||
PTHREAD_PRIO_NONE :: 0
|
||||
PTHREAD_PRIO_PROTECT :: 2
|
||||
|
||||
PTHREAD_PROCESS_SHARED :: 0
|
||||
PTHREAD_PROCESS_PRIVATE :: 1
|
||||
PTHREAD_PROCESS_SHARED :: 1
|
||||
PTHREAD_PROCESS_PRIVATE :: 0
|
||||
|
||||
PTHREAD_SCOPE_PROCESS :: 0
|
||||
PTHREAD_SCOPE_SYSTEM :: 2
|
||||
|
||||
pthread_t :: distinct u64
|
||||
|
||||
pthread_attr_t :: distinct rawptr
|
||||
pthread_attr_t :: struct #align(8) {
|
||||
_: [8]byte,
|
||||
}
|
||||
|
||||
pthread_key_t :: distinct c.int
|
||||
|
||||
pthread_mutex_t :: struct #align(8) {
|
||||
_: [8]byte,
|
||||
}
|
||||
|
||||
pthread_cond_t :: struct #align(8) {
|
||||
_: [8]byte,
|
||||
}
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
|
||||
}
|
||||
@@ -475,6 +506,14 @@ when ODIN_OS == .Darwin {
|
||||
|
||||
pthread_key_t :: distinct c.int
|
||||
|
||||
pthread_cond_t :: struct #align(8) {
|
||||
_: [40]byte,
|
||||
}
|
||||
|
||||
pthread_mutex_t :: struct #align(8) {
|
||||
_: [48]byte,
|
||||
}
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
|
||||
}
|
||||
@@ -505,9 +544,11 @@ when ODIN_OS == .Darwin {
|
||||
PTHREAD_SCOPE_PROCESS :: 0
|
||||
PTHREAD_SCOPE_SYSTEM :: 0x2
|
||||
|
||||
pthread_t :: distinct rawptr
|
||||
pthread_attr_t :: distinct rawptr
|
||||
pthread_key_t :: distinct c.int
|
||||
pthread_t :: distinct rawptr
|
||||
pthread_attr_t :: distinct rawptr
|
||||
pthread_key_t :: distinct c.int
|
||||
pthread_mutex_t :: distinct rawptr
|
||||
pthread_cond_t :: distinct rawptr
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
|
||||
@@ -548,6 +589,16 @@ when ODIN_OS == .Darwin {
|
||||
|
||||
pthread_key_t :: distinct c.uint
|
||||
|
||||
pthread_cond_t :: struct {
|
||||
__size: [40]c.char, // NOTE: may be smaller depending on libc or arch, but never larger.
|
||||
__align: c.long,
|
||||
}
|
||||
|
||||
pthread_mutex_t :: struct {
|
||||
__size: [32]c.char, // NOTE: may be smaller depending on libc or arch, but never larger.
|
||||
__align: c.long,
|
||||
}
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int, /* [PSX] process or thread execution scheduling priority */
|
||||
|
||||
@@ -557,6 +608,4 @@ when ODIN_OS == .Darwin {
|
||||
__reserved3: c.int,
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
+13
-2
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -163,6 +164,16 @@ when ODIN_OS == .Darwin || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
|
||||
pw_fields: c.int,
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
passwd :: struct {
|
||||
pw_name: cstring, /* [PSX] user name */
|
||||
pw_passwd: cstring, /* encrypted password */
|
||||
pw_uid: uid_t, /* [PSX] user uid */
|
||||
pw_gid: gid_t, /* [PSX] user gid */
|
||||
pw_gecos: cstring, /* Real name. */
|
||||
pw_dir: cstring, /* Home directory. */
|
||||
pw_shell: cstring, /* Shell program. */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -100,6 +101,4 @@ when ODIN_OS == .Darwin {
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_RR :: 2
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
import "core:c/libc"
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
@@ -43,12 +43,8 @@ foreign lib {
|
||||
sigsetjmp :: proc(env: ^sigjmp_buf, savemask: b32) -> c.int ---
|
||||
}
|
||||
|
||||
jmp_buf :: libc.jmp_buf
|
||||
sigjmp_buf :: distinct jmp_buf
|
||||
|
||||
longjmp :: libc.longjmp
|
||||
setjmp :: libc.setjmp
|
||||
|
||||
when ODIN_OS == .NetBSD {
|
||||
@(private) LSIGSETJMP :: "__sigsetjmp14"
|
||||
@(private) LSIGLONGJMP :: "__siglongjmp14"
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#+build windows, linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c/libc"
|
||||
|
||||
// setjmp.h - stack environment declarations
|
||||
|
||||
jmp_buf :: libc.jmp_buf
|
||||
|
||||
longjmp :: libc.longjmp
|
||||
setjmp :: libc.setjmp
|
||||
+2
-109
@@ -1,9 +1,9 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "base:intrinsics"
|
||||
|
||||
import "core:c"
|
||||
import "core:c/libc"
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
@@ -14,31 +14,6 @@ when ODIN_OS == .Darwin {
|
||||
// signal.h - signals
|
||||
|
||||
foreign lib {
|
||||
// LIBC:
|
||||
|
||||
/*
|
||||
Set a signal handler.
|
||||
|
||||
func can either be:
|
||||
- `auto_cast posix.SIG_DFL` setting the default handler for that specific signal
|
||||
- `auto_cast posix.SIG_IGN` causing the specific signal to be ignored
|
||||
- a custom signal handler
|
||||
|
||||
Returns: SIG_ERR (setting errno), the last value of func on success
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html ]]
|
||||
*/
|
||||
signal :: proc(sig: Signal, func: proc "c" (Signal)) -> proc "c" (Signal) ---
|
||||
|
||||
/*
|
||||
Raises a signal, calling its handler and then returning.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/raise.html ]]
|
||||
*/
|
||||
raise :: proc(sig: Signal) -> result ---
|
||||
|
||||
// POSIX:
|
||||
|
||||
/*
|
||||
Raise a signal to the process/group specified by pid.
|
||||
|
||||
@@ -227,72 +202,6 @@ sigval :: struct #raw_union {
|
||||
sigval_ptr: rawptr, /* [PSX] pointer signal value */
|
||||
}
|
||||
|
||||
Signal :: enum c.int {
|
||||
NONE,
|
||||
|
||||
// LIBC:
|
||||
|
||||
// Process abort signal.
|
||||
SIGABRT = SIGABRT,
|
||||
// Erronous arithemtic operation.
|
||||
SIGFPE = SIGFPE,
|
||||
// Illegal instruction.
|
||||
SIGILL = SIGILL,
|
||||
// Terminal interrupt signal.
|
||||
SIGINT = SIGINT,
|
||||
// Invalid memory reference.
|
||||
SIGSEGV = SIGSEGV,
|
||||
// Termination signal.
|
||||
SIGTERM = SIGTERM,
|
||||
|
||||
// POSIX:
|
||||
|
||||
// Process abort signal.
|
||||
SIGALRM = SIGALRM,
|
||||
// Access to an undefined portion of a memory object.
|
||||
SIGBUS = SIGBUS,
|
||||
// Child process terminated, stopped, or continued.
|
||||
SIGCHLD = SIGCHLD,
|
||||
// Continue execution, if stopped.
|
||||
SIGCONT = SIGCONT,
|
||||
// Hangup.
|
||||
SIGHUP = SIGHUP,
|
||||
// Kill (cannot be caught or ignored).
|
||||
SIGKILL = SIGKILL,
|
||||
// Write on a pipe with no one to read it.
|
||||
SIGPIPE = SIGPIPE,
|
||||
// Terminal quit signal.
|
||||
SIGQUIT = SIGQUIT,
|
||||
// Stop executing (cannot be caught or ignored).
|
||||
SIGSTOP = SIGSTOP,
|
||||
// Terminal stop process.
|
||||
SIGTSTP = SIGTSTP,
|
||||
// Background process attempting read.
|
||||
SIGTTIN = SIGTTIN,
|
||||
// Background process attempting write.
|
||||
SIGTTOU = SIGTTOU,
|
||||
// User-defined signal 1.
|
||||
SIGUSR1 = SIGUSR1,
|
||||
// User-defined signal 2.
|
||||
SIGUSR2 = SIGUSR2,
|
||||
// Pollable event.
|
||||
SIGPOLL = SIGPOLL,
|
||||
// Profiling timer expired.
|
||||
SIGPROF = SIGPROF,
|
||||
// Bad system call.
|
||||
SIGSYS = SIGSYS,
|
||||
// Trace/breakpoint trap.
|
||||
SIGTRAP = SIGTRAP,
|
||||
// High bandwidth data is available at a socket.
|
||||
SIGURG = SIGURG,
|
||||
// Virtual timer expired.
|
||||
SIGVTALRM = SIGVTALRM,
|
||||
// CPU time limit exceeded.
|
||||
SIGXCPU = SIGXCPU,
|
||||
// File size limit exceeded.
|
||||
SIGXFSZ = SIGXFSZ,
|
||||
}
|
||||
|
||||
ILL_Code :: enum c.int {
|
||||
// Illegal opcode.
|
||||
ILLOPC = ILL_ILLOPC,
|
||||
@@ -434,20 +343,6 @@ Sig :: enum c.int {
|
||||
SETMASK = SIG_SETMASK,
|
||||
}
|
||||
|
||||
// Request for default signal handling.
|
||||
SIG_DFL :: libc.SIG_DFL
|
||||
// Return value from signal() in case of error.
|
||||
SIG_ERR :: libc.SIG_ERR
|
||||
// Request that signal be ignored.
|
||||
SIG_IGN :: libc.SIG_IGN
|
||||
|
||||
SIGABRT :: libc.SIGABRT
|
||||
SIGFPE :: libc.SIGFPE
|
||||
SIGILL :: libc.SIGILL
|
||||
SIGINT :: libc.SIGINT
|
||||
SIGSEGV :: libc.SIGSEGV
|
||||
SIGTERM :: libc.SIGTERM
|
||||
|
||||
when ODIN_OS == .NetBSD {
|
||||
@(private) LSIGPROCMASK :: "__sigprocmask14"
|
||||
@(private) LSIGACTION :: "__sigaction_siginfo"
|
||||
@@ -1118,7 +1013,7 @@ when ODIN_OS == .Darwin {
|
||||
|
||||
uid_t :: distinct c.uint32_t
|
||||
sigset_t :: struct {
|
||||
[1024/(8 * size_of(c.ulong))]val,
|
||||
__val: [1024/(8 * size_of(c.ulong))]c.ulong,
|
||||
}
|
||||
|
||||
SIGHUP :: 1
|
||||
@@ -1285,6 +1180,4 @@ when ODIN_OS == .Darwin {
|
||||
SI_TIMER :: -2
|
||||
SI_MESGQ :: -3
|
||||
SI_ASYNCIO :: -4
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
#+build linux, windows, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "base:intrinsics"
|
||||
|
||||
import "core:c"
|
||||
import "core:c/libc"
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
foreign import lib "system:libucrt.lib"
|
||||
} else when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
} else {
|
||||
foreign import lib "system:c"
|
||||
}
|
||||
|
||||
// signal.h - signals
|
||||
|
||||
foreign lib {
|
||||
/*
|
||||
Set a signal handler.
|
||||
|
||||
func can either be:
|
||||
- `auto_cast posix.SIG_DFL` setting the default handler for that specific signal
|
||||
- `auto_cast posix.SIG_IGN` causing the specific signal to be ignored
|
||||
- a custom signal handler
|
||||
|
||||
Returns: SIG_ERR (setting errno), the last value of func on success
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html ]]
|
||||
*/
|
||||
signal :: proc(sig: Signal, func: proc "c" (Signal)) -> proc "c" (Signal) ---
|
||||
|
||||
/*
|
||||
Raises a signal, calling its handler and then returning.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/raise.html ]]
|
||||
*/
|
||||
raise :: proc(sig: Signal) -> result ---
|
||||
}
|
||||
|
||||
Signal :: enum c.int {
|
||||
NONE,
|
||||
|
||||
// LIBC:
|
||||
|
||||
// Process abort signal.
|
||||
SIGABRT = SIGABRT,
|
||||
// Erronous arithemtic operation.
|
||||
SIGFPE = SIGFPE,
|
||||
// Illegal instruction.
|
||||
SIGILL = SIGILL,
|
||||
// Terminal interrupt signal.
|
||||
SIGINT = SIGINT,
|
||||
// Invalid memory reference.
|
||||
SIGSEGV = SIGSEGV,
|
||||
// Termination signal.
|
||||
SIGTERM = SIGTERM,
|
||||
|
||||
// POSIX:
|
||||
|
||||
// Process abort signal.
|
||||
SIGALRM = SIGALRM,
|
||||
// Access to an undefined portion of a memory object.
|
||||
SIGBUS = SIGBUS,
|
||||
// Child process terminated, stopped, or continued.
|
||||
SIGCHLD = SIGCHLD,
|
||||
// Continue execution, if stopped.
|
||||
SIGCONT = SIGCONT,
|
||||
// Hangup.
|
||||
SIGHUP = SIGHUP,
|
||||
// Kill (cannot be caught or ignored).
|
||||
SIGKILL = SIGKILL,
|
||||
// Write on a pipe with no one to read it.
|
||||
SIGPIPE = SIGPIPE,
|
||||
// Terminal quit signal.
|
||||
SIGQUIT = SIGQUIT,
|
||||
// Stop executing (cannot be caught or ignored).
|
||||
SIGSTOP = SIGSTOP,
|
||||
// Terminal stop process.
|
||||
SIGTSTP = SIGTSTP,
|
||||
// Background process attempting read.
|
||||
SIGTTIN = SIGTTIN,
|
||||
// Background process attempting write.
|
||||
SIGTTOU = SIGTTOU,
|
||||
// User-defined signal 1.
|
||||
SIGUSR1 = SIGUSR1,
|
||||
// User-defined signal 2.
|
||||
SIGUSR2 = SIGUSR2,
|
||||
// Pollable event.
|
||||
SIGPOLL = SIGPOLL,
|
||||
// Profiling timer expired.
|
||||
SIGPROF = SIGPROF,
|
||||
// Bad system call.
|
||||
SIGSYS = SIGSYS,
|
||||
// Trace/breakpoint trap.
|
||||
SIGTRAP = SIGTRAP,
|
||||
// High bandwidth data is available at a socket.
|
||||
SIGURG = SIGURG,
|
||||
// Virtual timer expired.
|
||||
SIGVTALRM = SIGVTALRM,
|
||||
// CPU time limit exceeded.
|
||||
SIGXCPU = SIGXCPU,
|
||||
// File size limit exceeded.
|
||||
SIGXFSZ = SIGXFSZ,
|
||||
}
|
||||
|
||||
// Request for default signal handling.
|
||||
SIG_DFL :: libc.SIG_DFL
|
||||
// Return value from signal() in case of error.
|
||||
SIG_ERR :: libc.SIG_ERR
|
||||
// Request that signal be ignored.
|
||||
SIG_IGN :: libc.SIG_IGN
|
||||
|
||||
SIGABRT :: libc.SIGABRT
|
||||
SIGFPE :: libc.SIGFPE
|
||||
SIGILL :: libc.SIGILL
|
||||
SIGINT :: libc.SIGINT
|
||||
SIGSEGV :: libc.SIGSEGV
|
||||
SIGTERM :: libc.SIGTERM
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
SIGALRM :: -1
|
||||
SIGBUS :: -1
|
||||
SIGCHLD :: -1
|
||||
SIGCONT :: -1
|
||||
SIGHUP :: -1
|
||||
SIGKILL :: -1
|
||||
SIGPIPE :: -1
|
||||
SIGQUIT :: -1
|
||||
SIGSTOP :: -1
|
||||
SIGTSTP :: -1
|
||||
SIGTTIN :: -1
|
||||
SIGTTOU :: -1
|
||||
SIGUSR1 :: -1
|
||||
SIGUSR2 :: -1
|
||||
SIGPOLL :: -1
|
||||
SIGPROF :: -1
|
||||
SIGSYS :: -1
|
||||
SIGTRAP :: -1
|
||||
SIGURG :: -1
|
||||
SIGVTALRM :: -1
|
||||
SIGXCPU :: -1
|
||||
SIGXFSZ :: -1
|
||||
}
|
||||
+8
-165
@@ -1,7 +1,7 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
import "core:c/libc"
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
@@ -32,16 +32,6 @@ foreign lib {
|
||||
*/
|
||||
dprintf :: proc(fildse: FD, format: cstring, #c_vararg args: ..any) -> c.int ---
|
||||
|
||||
/*
|
||||
Equivalent to fprintf but output is written to s, it is the user's responsibility to
|
||||
ensure there is enough space.
|
||||
|
||||
Return: number of bytes written, negative (setting errno) on failure
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/dprintf.html ]]
|
||||
*/
|
||||
sprintf :: proc(s: [^]byte, format: cstring, #c_vararg args: ..any) -> c.int ---
|
||||
|
||||
/*
|
||||
Associate a stream with a file descriptor.
|
||||
|
||||
@@ -115,34 +105,6 @@ foreign lib {
|
||||
*/
|
||||
open_memstream :: proc(bufp: ^[^]byte, sizep: ^c.size_t) -> ^FILE ---
|
||||
|
||||
/*
|
||||
Equivalent to getc but unaffected by locks.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getc_unlocked.html ]]
|
||||
*/
|
||||
getc_unlocked :: proc(stream: ^FILE) -> c.int ---
|
||||
|
||||
/*
|
||||
Equivalent to getchar but unaffected by locks.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getc_unlocked.html ]]
|
||||
*/
|
||||
getchar_unlocked :: proc() -> c.int ---
|
||||
|
||||
/*
|
||||
Equivalent to putc but unaffected by locks.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getc_unlocked.html ]]
|
||||
*/
|
||||
putc_unlocked :: proc(ch: c.int, stream: ^FILE) -> c.int ---
|
||||
|
||||
/*
|
||||
Equivalent to putchar but unaffected by locks.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getc_unlocked.html ]]
|
||||
*/
|
||||
putchar_unlocked :: proc(ch: c.int) -> c.int ---
|
||||
|
||||
/*
|
||||
Read a delimited record from the stream.
|
||||
|
||||
@@ -181,60 +143,6 @@ foreign lib {
|
||||
*/
|
||||
getline :: proc(lineptr: ^cstring, n: ^c.size_t, stream: ^FILE) -> c.ssize_t ---
|
||||
|
||||
/*
|
||||
Get a string from the stdin stream.
|
||||
|
||||
It is up to the user to make sure s is big enough.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/gets.html ]]
|
||||
*/
|
||||
gets :: proc(s: [^]byte) -> cstring ---
|
||||
|
||||
/*
|
||||
Create a name for a temporary file.
|
||||
|
||||
Returns: an allocated cstring that needs to be freed, nil on failure
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/tempnam.html ]]
|
||||
*/
|
||||
tempnam :: proc(dir: cstring, pfx: cstring) -> cstring ---
|
||||
|
||||
/*
|
||||
Executes the command specified, creating a pipe and returning a pointer to a stream that can
|
||||
read or write from/to the pipe.
|
||||
|
||||
Returns: nil (setting errno) on failure or a pointer to the stream
|
||||
|
||||
Example:
|
||||
fp := posix.popen("ls *", "r")
|
||||
if fp == nil {
|
||||
/* Handle error */
|
||||
}
|
||||
|
||||
path: [1024]byte
|
||||
for posix.fgets(raw_data(path[:]), len(path), fp) != nil {
|
||||
posix.printf("%s", &path)
|
||||
}
|
||||
|
||||
status := posix.pclose(fp)
|
||||
if status == -1 {
|
||||
/* Error reported by pclose() */
|
||||
} else {
|
||||
/* Use functions described under wait() to inspect `status` in order
|
||||
to determine success/failure of the command executed by popen() */
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/popen.html ]]
|
||||
*/
|
||||
popen :: proc(command: cstring, mode: cstring) -> ^FILE ---
|
||||
|
||||
/*
|
||||
Closes a pipe stream to or from a process.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pclose.html ]]
|
||||
*/
|
||||
pclose :: proc(stream: ^FILE) -> c.int ---
|
||||
|
||||
/*
|
||||
Equivalent to rename but relative directories are resolved from their respective fds.
|
||||
|
||||
@@ -243,76 +151,6 @@ foreign lib {
|
||||
renameat :: proc(oldfd: FD, old: cstring, newfd: FD, new: cstring) -> result ---
|
||||
}
|
||||
|
||||
clearerr :: libc.clearerr
|
||||
fclose :: libc.fclose
|
||||
feof :: libc.feof
|
||||
ferror :: libc.ferror
|
||||
fflush :: libc.fflush
|
||||
fgetc :: libc.fgetc
|
||||
fgetpos :: libc.fgetpos
|
||||
fgets :: libc.fgets
|
||||
fopen :: libc.fopen
|
||||
fprintf :: libc.fprintf
|
||||
fputc :: libc.fputc
|
||||
fread :: libc.fread
|
||||
freopen :: libc.freopen
|
||||
fscanf :: libc.fscanf
|
||||
fseek :: libc.fseek
|
||||
fsetpos :: libc.fsetpos
|
||||
ftell :: libc.ftell
|
||||
fwrite :: libc.fwrite
|
||||
getc :: libc.getc
|
||||
getchar :: libc.getchar
|
||||
perror :: libc.perror
|
||||
printf :: libc.printf
|
||||
putc :: libc.puts
|
||||
putchar :: libc.putchar
|
||||
puts :: libc.puts
|
||||
remove :: libc.remove
|
||||
rename :: libc.rename
|
||||
rewind :: libc.rewind
|
||||
scanf :: libc.scanf
|
||||
setbuf :: libc.setbuf
|
||||
setvbuf :: libc.setvbuf
|
||||
snprintf :: libc.snprintf
|
||||
sscanf :: libc.sscanf
|
||||
tmpfile :: libc.tmpfile
|
||||
tmpnam :: libc.tmpnam
|
||||
vfprintf :: libc.vfprintf
|
||||
vfscanf :: libc.vfscanf
|
||||
vprintf :: libc.vprintf
|
||||
vscanf :: libc.vscanf
|
||||
vsnprintf :: libc.vsnprintf
|
||||
vsprintf :: libc.vsprintf
|
||||
vsscanf :: libc.vsscanf
|
||||
ungetc :: libc.ungetc
|
||||
|
||||
to_stream :: libc.to_stream
|
||||
|
||||
Whence :: libc.Whence
|
||||
FILE :: libc.FILE
|
||||
fpos_t :: libc.fpos_t
|
||||
|
||||
BUFSIZ :: libc.BUFSIZ
|
||||
|
||||
_IOFBF :: libc._IOFBF
|
||||
_IOLBF :: libc._IOLBF
|
||||
_IONBF :: libc._IONBF
|
||||
|
||||
SEEK_CUR :: libc.SEEK_CUR
|
||||
SEEK_END :: libc.SEEK_END
|
||||
SEEK_SET :: libc.SEEK_SET
|
||||
|
||||
FILENAME_MAX :: libc.FILENAME_MAX
|
||||
FOPEN_MAX :: libc.FOPEN_MAX
|
||||
TMP_MAX :: libc.TMP_MAX
|
||||
|
||||
EOF :: libc.EOF
|
||||
|
||||
stderr := libc.stderr
|
||||
stdin := libc.stdin
|
||||
stdout := libc.stdout
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
|
||||
L_ctermid :: 1024
|
||||
@@ -327,6 +165,11 @@ when ODIN_OS == .Darwin {
|
||||
|
||||
P_tmpdir :: "/tmp/"
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
L_ctermid :: 20 // 20 on musl, 9 on glibc
|
||||
L_tmpnam :: 20
|
||||
|
||||
P_tmpdir :: "/tmp/"
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
#+build linux, windows, linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
import "core:c/libc"
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
foreign import lib {
|
||||
"system:libucrt.lib",
|
||||
"system:legacy_stdio_definitions.lib",
|
||||
}
|
||||
} else when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
} else {
|
||||
foreign import lib "system:c"
|
||||
}
|
||||
|
||||
// stdio.h - standard buffered input/output
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
@(private) LGETC_UNLOCKED :: "_getc_nolock"
|
||||
@(private) LGETCHAR_UNLOCKED :: "_getchar_nolock"
|
||||
@(private) LPUTC_UNLOCKED :: "_putc_nolock"
|
||||
@(private) LPUTCHAR_UNLOCKED :: "_putchar_nolock"
|
||||
@(private) LTEMPNAM :: "_tempnam"
|
||||
@(private) LPOPEN :: "_popen"
|
||||
@(private) LPCLOSE :: "_pclose"
|
||||
} else {
|
||||
@(private) LGETC_UNLOCKED :: "getc_unlocked"
|
||||
@(private) LGETCHAR_UNLOCKED :: "getchar_unlocked"
|
||||
@(private) LPUTC_UNLOCKED :: "putc_unlocked"
|
||||
@(private) LPUTCHAR_UNLOCKED :: "putchar_unlocked"
|
||||
@(private) LTEMPNAM :: "tempnam"
|
||||
@(private) LPOPEN :: "popen"
|
||||
@(private) LPCLOSE :: "pclose"
|
||||
}
|
||||
|
||||
foreign lib {
|
||||
/*
|
||||
Equivalent to fprintf but output is written to s, it is the user's responsibility to
|
||||
ensure there is enough space.
|
||||
|
||||
Return: number of bytes written, negative (setting errno) on failure
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/dprintf.html ]]
|
||||
*/
|
||||
sprintf :: proc(s: [^]byte, format: cstring, #c_vararg args: ..any) -> c.int ---
|
||||
|
||||
/*
|
||||
Equivalent to getc but unaffected by locks.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getc_unlocked.html ]]
|
||||
*/
|
||||
@(link_name=LGETC_UNLOCKED)
|
||||
getc_unlocked :: proc(stream: ^FILE) -> c.int ---
|
||||
|
||||
/*
|
||||
Equivalent to getchar but unaffected by locks.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getc_unlocked.html ]]
|
||||
*/
|
||||
@(link_name=LGETCHAR_UNLOCKED)
|
||||
getchar_unlocked :: proc() -> c.int ---
|
||||
|
||||
/*
|
||||
Equivalent to putc but unaffected by locks.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getc_unlocked.html ]]
|
||||
*/
|
||||
@(link_name=LPUTC_UNLOCKED)
|
||||
putc_unlocked :: proc(ch: c.int, stream: ^FILE) -> c.int ---
|
||||
|
||||
/*
|
||||
Equivalent to putchar but unaffected by locks.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getc_unlocked.html ]]
|
||||
*/
|
||||
@(link_name=LPUTCHAR_UNLOCKED)
|
||||
putchar_unlocked :: proc(ch: c.int) -> c.int ---
|
||||
|
||||
/*
|
||||
Get a string from the stdin stream.
|
||||
|
||||
It is up to the user to make sure s is big enough.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/gets.html ]]
|
||||
*/
|
||||
gets :: proc(s: [^]byte) -> cstring ---
|
||||
|
||||
/*
|
||||
Create a name for a temporary file.
|
||||
|
||||
Returns: an allocated cstring that needs to be freed, nil on failure
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/tempnam.html ]]
|
||||
*/
|
||||
@(link_name=LTEMPNAM)
|
||||
tempnam :: proc(dir: cstring, pfx: cstring) -> cstring ---
|
||||
|
||||
/*
|
||||
Executes the command specified, creating a pipe and returning a pointer to a stream that can
|
||||
read or write from/to the pipe.
|
||||
|
||||
Returns: nil (setting errno) on failure or a pointer to the stream
|
||||
|
||||
Example:
|
||||
fp := posix.popen("ls *", "r")
|
||||
if fp == nil {
|
||||
/* Handle error */
|
||||
}
|
||||
|
||||
path: [1024]byte
|
||||
for posix.fgets(raw_data(path[:]), len(path), fp) != nil {
|
||||
posix.printf("%s", &path)
|
||||
}
|
||||
|
||||
status := posix.pclose(fp)
|
||||
if status == -1 {
|
||||
/* Error reported by pclose() */
|
||||
} else {
|
||||
/* Use functions described under wait() to inspect `status` in order
|
||||
to determine success/failure of the command executed by popen() */
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/popen.html ]]
|
||||
*/
|
||||
@(link_name=LPOPEN)
|
||||
popen :: proc(command: cstring, mode: cstring) -> ^FILE ---
|
||||
|
||||
/*
|
||||
Closes a pipe stream to or from a process.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/pclose.html ]]
|
||||
*/
|
||||
@(link_name=LPCLOSE)
|
||||
pclose :: proc(stream: ^FILE) -> c.int ---
|
||||
}
|
||||
|
||||
clearerr :: libc.clearerr
|
||||
fclose :: libc.fclose
|
||||
feof :: libc.feof
|
||||
ferror :: libc.ferror
|
||||
fflush :: libc.fflush
|
||||
fgetc :: libc.fgetc
|
||||
fgetpos :: libc.fgetpos
|
||||
fgets :: libc.fgets
|
||||
fopen :: libc.fopen
|
||||
fprintf :: libc.fprintf
|
||||
fputc :: libc.fputc
|
||||
fread :: libc.fread
|
||||
freopen :: libc.freopen
|
||||
fscanf :: libc.fscanf
|
||||
fseek :: libc.fseek
|
||||
fsetpos :: libc.fsetpos
|
||||
ftell :: libc.ftell
|
||||
fwrite :: libc.fwrite
|
||||
getc :: libc.getc
|
||||
getchar :: libc.getchar
|
||||
perror :: libc.perror
|
||||
printf :: libc.printf
|
||||
putc :: libc.puts
|
||||
putchar :: libc.putchar
|
||||
puts :: libc.puts
|
||||
remove :: libc.remove
|
||||
rename :: libc.rename
|
||||
rewind :: libc.rewind
|
||||
scanf :: libc.scanf
|
||||
setbuf :: libc.setbuf
|
||||
setvbuf :: libc.setvbuf
|
||||
snprintf :: libc.snprintf
|
||||
sscanf :: libc.sscanf
|
||||
tmpfile :: libc.tmpfile
|
||||
tmpnam :: libc.tmpnam
|
||||
vfprintf :: libc.vfprintf
|
||||
vfscanf :: libc.vfscanf
|
||||
vprintf :: libc.vprintf
|
||||
vscanf :: libc.vscanf
|
||||
vsnprintf :: libc.vsnprintf
|
||||
vsprintf :: libc.vsprintf
|
||||
vsscanf :: libc.vsscanf
|
||||
ungetc :: libc.ungetc
|
||||
|
||||
to_stream :: libc.to_stream
|
||||
|
||||
Whence :: libc.Whence
|
||||
FILE :: libc.FILE
|
||||
fpos_t :: libc.fpos_t
|
||||
|
||||
BUFSIZ :: libc.BUFSIZ
|
||||
|
||||
_IOFBF :: libc._IOFBF
|
||||
_IOLBF :: libc._IOLBF
|
||||
_IONBF :: libc._IONBF
|
||||
|
||||
SEEK_CUR :: libc.SEEK_CUR
|
||||
SEEK_END :: libc.SEEK_END
|
||||
SEEK_SET :: libc.SEEK_SET
|
||||
|
||||
FILENAME_MAX :: libc.FILENAME_MAX
|
||||
FOPEN_MAX :: libc.FOPEN_MAX
|
||||
TMP_MAX :: libc.TMP_MAX
|
||||
|
||||
EOF :: libc.EOF
|
||||
|
||||
stderr := libc.stderr
|
||||
stdin := libc.stdin
|
||||
stdout := libc.stdout
|
||||
@@ -1,9 +1,9 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "base:intrinsics"
|
||||
|
||||
import "core:c"
|
||||
import "core:c/libc"
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
@@ -11,56 +11,6 @@ when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:c"
|
||||
}
|
||||
|
||||
// stdlib.h - standard library definitions
|
||||
|
||||
atof :: libc.atof
|
||||
atoi :: libc.atoi
|
||||
atol :: libc.atol
|
||||
atoll :: libc.atoll
|
||||
strtod :: libc.strtod
|
||||
strtof :: libc.strtof
|
||||
strtol :: libc.strtol
|
||||
strtoll :: libc.strtoll
|
||||
strtoul :: libc.strtoul
|
||||
strtoull :: libc.strtoull
|
||||
|
||||
rand :: libc.rand
|
||||
srand :: libc.srand
|
||||
|
||||
calloc :: libc.calloc
|
||||
malloc :: libc.malloc
|
||||
realloc :: libc.realloc
|
||||
|
||||
abort :: libc.abort
|
||||
atexit :: libc.atexit
|
||||
at_quick_exit :: libc.at_quick_exit
|
||||
exit :: libc.exit
|
||||
_Exit :: libc._Exit
|
||||
getenv :: libc.getenv
|
||||
quick_exit :: libc.quick_exit
|
||||
system :: libc.system
|
||||
|
||||
bsearch :: libc.bsearch
|
||||
qsort :: libc.qsort
|
||||
|
||||
abs :: libc.abs
|
||||
labs :: libc.labs
|
||||
llabs :: libc.llabs
|
||||
div :: libc.div
|
||||
ldiv :: libc.ldiv
|
||||
lldiv :: libc.lldiv
|
||||
|
||||
mblen :: libc.mblen
|
||||
mbtowc :: libc.mbtowc
|
||||
wctomb :: libc.wctomb
|
||||
|
||||
mbstowcs :: libc.mbstowcs
|
||||
wcstombs :: libc.wcstombs
|
||||
|
||||
free :: #force_inline proc(ptr: $T) where intrinsics.type_is_pointer(T) || intrinsics.type_is_multi_pointer(T) || T == cstring {
|
||||
libc.free(rawptr(ptr))
|
||||
}
|
||||
|
||||
foreign lib {
|
||||
/*
|
||||
Takes a pointer to a radix-64 representation, in which the first digit is the least significant,
|
||||
@@ -342,21 +292,6 @@ foreign lib {
|
||||
*/
|
||||
unlockpt :: proc(fildes: FD) -> result ---
|
||||
|
||||
/*
|
||||
Uses the string argument to set environment variable values.
|
||||
|
||||
Returns: 0 on success, non-zero (setting errno) on failure
|
||||
|
||||
Example:
|
||||
if posix.putenv("HOME=/usr/home") != 0 {
|
||||
fmt.panicf("putenv failure: %v", posix.strerror(posix.errno()))
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/putenv.html ]]
|
||||
*/
|
||||
@(link_name=LPUTENV)
|
||||
putenv :: proc(string: cstring) -> c.int ---
|
||||
|
||||
/*
|
||||
Updates or add a variable in the environment of the calling process.
|
||||
|
||||
@@ -427,23 +362,11 @@ foreign lib {
|
||||
setkey :: proc(key: [^]byte) ---
|
||||
}
|
||||
|
||||
EXIT_FAILURE :: libc.EXIT_FAILURE
|
||||
EXIT_SUCCESS :: libc.EXIT_SUCCESS
|
||||
|
||||
RAND_MAX :: libc.RAND_MAX
|
||||
MB_CUR_MAX :: libc.MB_CUR_MAX
|
||||
|
||||
div_t :: libc.div_t
|
||||
ldiv_t :: libc.ldiv_t
|
||||
lldiv_t :: libc.lldiv_t
|
||||
|
||||
when ODIN_OS == .NetBSD {
|
||||
@(private) LPUTENV :: "__putenv50"
|
||||
@(private) LINITSTATE :: "__initstate60"
|
||||
@(private) LSRANDOM :: "__srandom60"
|
||||
@(private) LUNSETENV :: "__unsetenv13"
|
||||
} else {
|
||||
@(private) LPUTENV :: "putenv"
|
||||
@(private) LINITSTATE :: "initstate"
|
||||
@(private) LSRANDOM :: "srandom"
|
||||
@(private) LUNSETENV :: "unsetenv"
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
#+build linux, windows, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "base:intrinsics"
|
||||
|
||||
import "core:c"
|
||||
import "core:c/libc"
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
foreign import lib "system:libucrt.lib"
|
||||
} else when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
} else {
|
||||
foreign import lib "system:c"
|
||||
}
|
||||
|
||||
// stdlib.h - standard library definitions
|
||||
|
||||
atof :: libc.atof
|
||||
atoi :: libc.atoi
|
||||
atol :: libc.atol
|
||||
atoll :: libc.atoll
|
||||
strtod :: libc.strtod
|
||||
strtof :: libc.strtof
|
||||
strtol :: libc.strtol
|
||||
strtoll :: libc.strtoll
|
||||
strtoul :: libc.strtoul
|
||||
strtoull :: libc.strtoull
|
||||
|
||||
rand :: libc.rand
|
||||
srand :: libc.srand
|
||||
|
||||
calloc :: libc.calloc
|
||||
malloc :: libc.malloc
|
||||
realloc :: libc.realloc
|
||||
|
||||
abort :: libc.abort
|
||||
atexit :: libc.atexit
|
||||
at_quick_exit :: libc.at_quick_exit
|
||||
exit :: libc.exit
|
||||
_Exit :: libc._Exit
|
||||
getenv :: libc.getenv
|
||||
quick_exit :: libc.quick_exit
|
||||
system :: libc.system
|
||||
|
||||
bsearch :: libc.bsearch
|
||||
qsort :: libc.qsort
|
||||
|
||||
abs :: libc.abs
|
||||
labs :: libc.labs
|
||||
llabs :: libc.llabs
|
||||
div :: libc.div
|
||||
ldiv :: libc.ldiv
|
||||
lldiv :: libc.lldiv
|
||||
|
||||
mblen :: libc.mblen
|
||||
mbtowc :: libc.mbtowc
|
||||
wctomb :: libc.wctomb
|
||||
|
||||
mbstowcs :: libc.mbstowcs
|
||||
wcstombs :: libc.wcstombs
|
||||
|
||||
free :: #force_inline proc(ptr: $T) where intrinsics.type_is_pointer(T) || intrinsics.type_is_multi_pointer(T) || T == cstring {
|
||||
libc.free(rawptr(ptr))
|
||||
}
|
||||
|
||||
foreign lib {
|
||||
|
||||
/*
|
||||
Uses the string argument to set environment variable values.
|
||||
|
||||
Returns: 0 on success, non-zero (setting errno) on failure
|
||||
|
||||
Example:
|
||||
if posix.putenv("HOME=/usr/home") != 0 {
|
||||
fmt.panicf("putenv failure: %v", posix.strerror(posix.errno()))
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/putenv.html ]]
|
||||
*/
|
||||
@(link_name=LPUTENV)
|
||||
putenv :: proc(string: cstring) -> c.int ---
|
||||
}
|
||||
|
||||
EXIT_FAILURE :: libc.EXIT_FAILURE
|
||||
EXIT_SUCCESS :: libc.EXIT_SUCCESS
|
||||
|
||||
RAND_MAX :: libc.RAND_MAX
|
||||
MB_CUR_MAX :: libc.MB_CUR_MAX
|
||||
|
||||
div_t :: libc.div_t
|
||||
ldiv_t :: libc.ldiv_t
|
||||
lldiv_t :: libc.lldiv_t
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
@(private) LPUTENV :: "_putenv"
|
||||
} else when ODIN_OS == .NetBSD {
|
||||
@(private) LPUTENV :: "__putenv50"
|
||||
} else {
|
||||
@(private) LPUTENV :: "putenv"
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -13,16 +14,6 @@ when ODIN_OS == .Darwin {
|
||||
// NOTE: most of the symbols in this header are not useful in Odin and have been left out.
|
||||
|
||||
foreign lib {
|
||||
/*
|
||||
Map the error number to a locale-dependent error message string.
|
||||
|
||||
Returns: a string that may be invalidated by subsequent calls
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html ]]
|
||||
*/
|
||||
@(link_name="strerror")
|
||||
_strerror :: proc(errnum: Errno) -> cstring ---
|
||||
|
||||
/*
|
||||
Map the error number to a locale-dependent error message string and put it in the buffer.
|
||||
|
||||
@@ -41,7 +32,3 @@ foreign lib {
|
||||
*/
|
||||
strsignal :: proc(sig: Signal) -> cstring ---
|
||||
}
|
||||
|
||||
strerror :: #force_inline proc "contextless" (errnum: Maybe(Errno) = nil) -> cstring {
|
||||
return _strerror(errnum.? or_else errno())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#+build linux, windows, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
foreign import lib "system:libucrt.lib"
|
||||
} else when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
} else {
|
||||
foreign import lib "system:c"
|
||||
}
|
||||
|
||||
// string.h - string operations
|
||||
|
||||
// NOTE: most of the symbols in this header are not useful in Odin and have been left out.
|
||||
|
||||
foreign lib {
|
||||
/*
|
||||
Map the error number to a locale-dependent error message string.
|
||||
|
||||
Returns: a string that may be invalidated by subsequent calls
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html ]]
|
||||
*/
|
||||
@(link_name="strerror")
|
||||
_strerror :: proc(errnum: Errno) -> cstring ---
|
||||
}
|
||||
|
||||
strerror :: #force_inline proc "contextless" (errnum: Maybe(Errno) = nil) -> cstring {
|
||||
return _strerror(errnum.? or_else errno())
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -110,6 +111,4 @@ when ODIN_OS == .Darwin {
|
||||
IPC_SET :: 1
|
||||
IPC_STAT :: 2
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -115,12 +116,14 @@ Prot_Flag_Bits :: enum c.int {
|
||||
Prot_Flags :: bit_set[Prot_Flag_Bits; c.int]
|
||||
|
||||
Map_Flag_Bits :: enum c.int {
|
||||
// Map anonymous memory.
|
||||
ANONYMOUS = log2(MAP_ANONYMOUS),
|
||||
// Interpret addr exactly.
|
||||
FIXED = log2(MAP_FIXED),
|
||||
FIXED = log2(MAP_FIXED),
|
||||
// Changes are private.
|
||||
PRIVATE = log2(MAP_PRIVATE),
|
||||
PRIVATE = log2(MAP_PRIVATE),
|
||||
// Changes are shared.
|
||||
SHARED = log2(MAP_SHARED),
|
||||
SHARED = log2(MAP_SHARED),
|
||||
}
|
||||
Map_Flags :: bit_set[Map_Flag_Bits; c.int]
|
||||
|
||||
@@ -170,9 +173,10 @@ when ODIN_OS == .Darwin || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS
|
||||
PROT_READ :: 0x01
|
||||
PROT_WRITE :: 0x02
|
||||
|
||||
MAP_FIXED :: 0x0010
|
||||
MAP_PRIVATE :: 0x0002
|
||||
MAP_SHARED :: 0x0001
|
||||
MAP_FIXED :: 0x0010
|
||||
MAP_PRIVATE :: 0x0002
|
||||
MAP_SHARED :: 0x0001
|
||||
MAP_ANONYMOUS :: 0x0020 when ODIN_OS == .Linux else 0x1000
|
||||
|
||||
when ODIN_OS == .Darwin || ODIN_OS == .Linux {
|
||||
MS_INVALIDATE :: 0x0002
|
||||
@@ -206,9 +210,10 @@ when ODIN_OS == .Darwin || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS
|
||||
PROT_READ :: 0x01
|
||||
PROT_WRITE :: 0x02
|
||||
|
||||
MAP_FIXED :: 0x0010
|
||||
MAP_PRIVATE :: 0x0002
|
||||
MAP_SHARED :: 0x0001
|
||||
MAP_FIXED :: 0x0010
|
||||
MAP_PRIVATE :: 0x0002
|
||||
MAP_SHARED :: 0x0001
|
||||
MAP_ANONYMOUS :: 0x1000
|
||||
|
||||
MS_ASYNC :: 0x0001
|
||||
MS_INVALIDATE :: 0x0002
|
||||
@@ -225,6 +230,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS
|
||||
POSIX_MADV_SEQUENTIAL :: 2
|
||||
POSIX_MADV_WILLNEED :: 3
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -150,6 +151,24 @@ when ODIN_OS == .Darwin {
|
||||
msg_pad4: [4]c.long,
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
msgqnum_t :: distinct c.ulong
|
||||
msglen_t :: distinct c.ulong
|
||||
|
||||
MSG_NOERROR :: 0o10000
|
||||
|
||||
msqid_ds :: struct {
|
||||
msg_perm: ipc_perm, /* [PSX] operation permission structure */
|
||||
msg_stime: time_t, /* [PSX] time of last msgsnd() */
|
||||
msg_rtime: time_t, /* [PSX] time of last msgrcv() */
|
||||
msg_ctime: time_t, /* [PSX] time of last change */
|
||||
msg_cbytes: c.ulong,
|
||||
msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
|
||||
msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
|
||||
msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
|
||||
msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
|
||||
__unused: [2]c.ulong,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -154,6 +155,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
RLIMIT_AS :: 10
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "base:intrinsics"
|
||||
@@ -72,7 +73,7 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
|
||||
// NOTE: this seems correct for FreeBSD but they do use a set backed by the long type themselves (thus the align change).
|
||||
@(private)
|
||||
ALIGN :: align_of(c.long) when ODIN_OS == .FreeBSD else align_of(c.int32_t)
|
||||
ALIGN :: align_of(c.long) when ODIN_OS == .FreeBSD || ODIN_OS == .Linux else align_of(c.int32_t)
|
||||
|
||||
fd_set :: struct #align(ALIGN) {
|
||||
fds_bits: [(FD_SETSIZE / __NFDBITS) when (FD_SETSIZE % __NFDBITS) == 0 else (FD_SETSIZE / __NFDBITS) + 1]c.int32_t,
|
||||
@@ -115,6 +116,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
intrinsics.mem_zero(_p, size_of(fd_set))
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -153,6 +154,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
sem_flg: c.short, /* [PSX] operation flags */
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -137,6 +138,24 @@ when ODIN_OS == .Darwin {
|
||||
_shm_internal: rawptr,
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
SHM_RDONLY :: 0o10000
|
||||
SHM_RND :: 0o20000
|
||||
|
||||
SHMLBA :: 4096
|
||||
|
||||
shmatt_t :: distinct c.ulong
|
||||
|
||||
shmid_ds :: struct {
|
||||
shm_perm: ipc_perm, /* [PSX] operation permission structure */
|
||||
shm_segsz: c.size_t, /* [PSX] size of segment in bytes */
|
||||
shm_atime: time_t, /* [PSX] time of last shmat() */
|
||||
shm_dtime: time_t, /* [PSX] time of last shmdt() */
|
||||
shm_ctime: time_t, /* [PSX] time of last change by shmctl() */
|
||||
shm_cpid: pid_t, /* [PSX] process ID of creator */
|
||||
shm_lpid: pid_t, /* [PSX] process ID of last shared memory operation */
|
||||
shm_nattch: shmatt_t, /* [PSX] number of current attaches */
|
||||
_: [2]c.ulong,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -47,6 +48,12 @@ foreign libc {
|
||||
addr.sun_family = .UNIX
|
||||
copy(addr.sun_path[:], "/somepath\x00")
|
||||
|
||||
/*
|
||||
unlink the socket before binding in case
|
||||
of previous runs not cleaning up the socket
|
||||
*/
|
||||
posix.unlink("/somepath")
|
||||
|
||||
if posix.bind(sfd, (^posix.sockaddr)(&addr), size_of(addr)) != .OK {
|
||||
/* Handle error */
|
||||
}
|
||||
@@ -325,14 +332,16 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
|
||||
socklen_t :: distinct c.uint
|
||||
|
||||
_sa_family_t :: distinct c.uint8_t
|
||||
|
||||
when ODIN_OS == .Linux {
|
||||
_sa_family_t :: distinct c.ushort
|
||||
|
||||
sockaddr :: struct {
|
||||
sa_family: sa_family_t, /* [PSX] address family */
|
||||
sa_data: [14]c.char, /* [PSX] socket address */
|
||||
}
|
||||
} else {
|
||||
_sa_family_t :: distinct c.uint8_t
|
||||
|
||||
sockaddr :: struct {
|
||||
sa_len: c.uint8_t, /* total length */
|
||||
sa_family: sa_family_t, /* [PSX] address family */
|
||||
@@ -560,7 +569,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
SHUT_RDWR :: 2
|
||||
SHUT_WR :: 1
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
|
||||
+120
-67
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -280,20 +281,20 @@ when ODIN_OS == .Darwin {
|
||||
ino_t :: distinct c.uint64_t
|
||||
|
||||
stat_t :: struct {
|
||||
st_dev: dev_t, /* [XSI] ID of device containing file */
|
||||
st_mode: mode_t, /* [XSI] mode of file */
|
||||
st_nlink: nlink_t, /* [XSI] number of hard links */
|
||||
st_ino: ino_t, /* [XSI] file serial number */
|
||||
st_uid: uid_t, /* [XSI] user ID of the file */
|
||||
st_gid: gid_t, /* [XSI] group ID of the file */
|
||||
st_rdev: dev_t, /* [XSI] device ID */
|
||||
st_atim: timespec, /* [XSI] time of last access */
|
||||
st_mtim: timespec, /* [XSI] time of last data modification */
|
||||
st_ctim: timespec, /* [XSI] time of last status change */
|
||||
st_dev: dev_t, /* [PSX] ID of device containing file */
|
||||
st_mode: mode_t, /* [PSX] mode of file */
|
||||
st_nlink: nlink_t, /* [PSX] number of hard links */
|
||||
st_ino: ino_t, /* [PSX] file serial number */
|
||||
st_uid: uid_t, /* [PSX] user ID of the file */
|
||||
st_gid: gid_t, /* [PSX] group ID of the file */
|
||||
st_rdev: dev_t, /* [PSX] device ID */
|
||||
st_atim: timespec, /* [PSX] time of last access */
|
||||
st_mtim: timespec, /* [PSX] time of last data modification */
|
||||
st_ctim: timespec, /* [PSX] time of last status change */
|
||||
st_birthtimespec: timespec, /* time of file creation(birth) */
|
||||
st_size: off_t, /* [XSI] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [XSI] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [XSI] optimal blocksize for I/O */
|
||||
st_size: off_t, /* [PSX] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [PSX] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [PSX] optimal blocksize for I/O */
|
||||
st_flags: c.uint32_t, /* user defined flags for file */
|
||||
st_gen: c.uint32_t, /* file generation number */
|
||||
st_lspare: c.int32_t, /* RESERVED */
|
||||
@@ -314,47 +315,47 @@ when ODIN_OS == .Darwin {
|
||||
|
||||
when ODIN_ARCH == .i386 {
|
||||
stat_t :: struct {
|
||||
st_dev: dev_t, /* [XSI] ID of device containing file */
|
||||
st_ino: ino_t, /* [XSI] file serial number */
|
||||
st_nlink: nlink_t, /* [XSI] number of hard links */
|
||||
st_mode: mode_t, /* [XSI] mode of file */
|
||||
st_dev: dev_t, /* [PSX] ID of device containing file */
|
||||
st_ino: ino_t, /* [PSX] file serial number */
|
||||
st_nlink: nlink_t, /* [PSX] number of hard links */
|
||||
st_mode: mode_t, /* [PSX] mode of file */
|
||||
st_padding0: c.int16_t,
|
||||
st_uid: uid_t, /* [XSI] user ID of the file */
|
||||
st_gid: gid_t, /* [XSI] group ID of the file */
|
||||
st_uid: uid_t, /* [PSX] user ID of the file */
|
||||
st_gid: gid_t, /* [PSX] group ID of the file */
|
||||
st_padding1: c.int32_t,
|
||||
st_rdev: dev_t, /* [XSI] device ID */
|
||||
st_rdev: dev_t, /* [PSX] device ID */
|
||||
st_atim_ext: c.int32_t,
|
||||
st_atim: timespec, /* [XSI] time of last access */
|
||||
st_atim: timespec, /* [PSX] time of last access */
|
||||
st_mtim_ext: c.int32_t,
|
||||
st_mtim: timespec, /* [XSI] time of last data modification */
|
||||
st_mtim: timespec, /* [PSX] time of last data modification */
|
||||
st_ctim_ext: c.int32_t,
|
||||
st_ctim: timespec, /* [XSI] time of last status change */
|
||||
st_ctim: timespec, /* [PSX] time of last status change */
|
||||
st_birthtimespec: timespec, /* time of file creation(birth) */
|
||||
st_size: off_t, /* [XSI] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [XSI] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [XSI] optimal blocksize for I/O */
|
||||
st_size: off_t, /* [PSX] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [PSX] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [PSX] optimal blocksize for I/O */
|
||||
st_flags: c.uint32_t, /* user defined flags for file */
|
||||
st_gen: c.uint64_t,
|
||||
st_spare: [10]c.uint64_t,
|
||||
}
|
||||
} else {
|
||||
stat_t :: struct {
|
||||
st_dev: dev_t, /* [XSI] ID of device containing file */
|
||||
st_ino: ino_t, /* [XSI] file serial number */
|
||||
st_nlink: nlink_t, /* [XSI] number of hard links */
|
||||
st_mode: mode_t, /* [XSI] mode of file */
|
||||
st_dev: dev_t, /* [PSX] ID of device containing file */
|
||||
st_ino: ino_t, /* [PSX] file serial number */
|
||||
st_nlink: nlink_t, /* [PSX] number of hard links */
|
||||
st_mode: mode_t, /* [PSX] mode of file */
|
||||
st_padding0: c.int16_t,
|
||||
st_uid: uid_t, /* [XSI] user ID of the file */
|
||||
st_gid: gid_t, /* [XSI] group ID of the file */
|
||||
st_uid: uid_t, /* [PSX] user ID of the file */
|
||||
st_gid: gid_t, /* [PSX] group ID of the file */
|
||||
st_padding1: c.int32_t,
|
||||
st_rdev: dev_t, /* [XSI] device ID */
|
||||
st_atim: timespec, /* [XSI] time of last access */
|
||||
st_mtim: timespec, /* [XSI] time of last data modification */
|
||||
st_ctim: timespec, /* [XSI] time of last status change */
|
||||
st_rdev: dev_t, /* [PSX] device ID */
|
||||
st_atim: timespec, /* [PSX] time of last access */
|
||||
st_mtim: timespec, /* [PSX] time of last data modification */
|
||||
st_ctim: timespec, /* [PSX] time of last status change */
|
||||
st_birthtimespec: timespec, /* time of file creation(birth) */
|
||||
st_size: off_t, /* [XSI] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [XSI] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [XSI] optimal blocksize for I/O */
|
||||
st_size: off_t, /* [PSX] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [PSX] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [PSX] optimal blocksize for I/O */
|
||||
st_flags: c.uint32_t, /* user defined flags for file */
|
||||
st_gen: c.uint64_t,
|
||||
st_spare: [10]c.uint64_t,
|
||||
@@ -374,20 +375,20 @@ when ODIN_OS == .Darwin {
|
||||
ino_t :: distinct c.uint64_t
|
||||
|
||||
stat_t :: struct {
|
||||
st_dev: dev_t, /* [XSI] ID of device containing file */
|
||||
st_mode: mode_t, /* [XSI] mode of file */
|
||||
st_ino: ino_t, /* [XSI] file serial number */
|
||||
st_nlink: nlink_t, /* [XSI] number of hard links */
|
||||
st_uid: uid_t, /* [XSI] user ID of the file */
|
||||
st_gid: gid_t, /* [XSI] group ID of the file */
|
||||
st_rdev: dev_t, /* [XSI] device ID */
|
||||
st_atim: timespec, /* [XSI] time of last access */
|
||||
st_mtim: timespec, /* [XSI] time of last data modification */
|
||||
st_ctim: timespec, /* [XSI] time of last status change */
|
||||
st_dev: dev_t, /* [PSX] ID of device containing file */
|
||||
st_mode: mode_t, /* [PSX] mode of file */
|
||||
st_ino: ino_t, /* [PSX] file serial number */
|
||||
st_nlink: nlink_t, /* [PSX] number of hard links */
|
||||
st_uid: uid_t, /* [PSX] user ID of the file */
|
||||
st_gid: gid_t, /* [PSX] group ID of the file */
|
||||
st_rdev: dev_t, /* [PSX] device ID */
|
||||
st_atim: timespec, /* [PSX] time of last access */
|
||||
st_mtim: timespec, /* [PSX] time of last data modification */
|
||||
st_ctim: timespec, /* [PSX] time of last status change */
|
||||
st_birthtimespec: timespec, /* time of file creation(birth) */
|
||||
st_size: off_t, /* [XSI] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [XSI] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [XSI] optimal blocksize for I/O */
|
||||
st_size: off_t, /* [PSX] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [PSX] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [PSX] optimal blocksize for I/O */
|
||||
st_flags: c.uint32_t, /* user defined flags for file */
|
||||
st_gen: c.uint64_t,
|
||||
st_spare: [2]c.uint32_t,
|
||||
@@ -406,19 +407,19 @@ when ODIN_OS == .Darwin {
|
||||
ino_t :: distinct c.uint64_t
|
||||
|
||||
stat_t :: struct {
|
||||
st_mode: mode_t, /* [XSI] mode of file */
|
||||
st_dev: dev_t, /* [XSI] ID of device containing file */
|
||||
st_ino: ino_t, /* [XSI] file serial number */
|
||||
st_nlink: nlink_t, /* [XSI] number of hard links */
|
||||
st_uid: uid_t, /* [XSI] user ID of the file */
|
||||
st_gid: gid_t, /* [XSI] group ID of the file */
|
||||
st_rdev: dev_t, /* [XSI] device ID */
|
||||
st_atim: timespec, /* [XSI] time of last access */
|
||||
st_mtim: timespec, /* [XSI] time of last data modification */
|
||||
st_ctim: timespec, /* [XSI] time of last status change */
|
||||
st_size: off_t, /* [XSI] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [XSI] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [XSI] optimal blocksize for I/O */
|
||||
st_mode: mode_t, /* [PSX] mode of file */
|
||||
st_dev: dev_t, /* [PSX] ID of device containing file */
|
||||
st_ino: ino_t, /* [PSX] file serial number */
|
||||
st_nlink: nlink_t, /* [PSX] number of hard links */
|
||||
st_uid: uid_t, /* [PSX] user ID of the file */
|
||||
st_gid: gid_t, /* [PSX] group ID of the file */
|
||||
st_rdev: dev_t, /* [PSX] device ID */
|
||||
st_atim: timespec, /* [PSX] time of last access */
|
||||
st_mtim: timespec, /* [PSX] time of last data modification */
|
||||
st_ctim: timespec, /* [PSX] time of last status change */
|
||||
st_size: off_t, /* [PSX] file size, in bytes */
|
||||
st_blocks: blkcnt_t, /* [PSX] blocks allocated for file */
|
||||
st_blksize: blksize_t, /* [PSX] optimal blocksize for I/O */
|
||||
st_flags: c.uint32_t, /* user defined flags for file */
|
||||
st_gen: c.int32_t,
|
||||
st_birthtimespec: timespec,
|
||||
@@ -427,6 +428,58 @@ when ODIN_OS == .Darwin {
|
||||
UTIME_NOW :: -2
|
||||
UTIME_OMIT :: -1
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
dev_t :: distinct u64
|
||||
_mode_t :: distinct c.uint
|
||||
blkcnt_t :: distinct i64
|
||||
|
||||
when ODIN_ARCH == .arm64 || ODIN_ARCH == .riscv64 {
|
||||
nlink_t :: distinct c.uint
|
||||
blksize_t :: distinct c.int
|
||||
} else {
|
||||
nlink_t :: distinct c.size_t
|
||||
blksize_t :: distinct c.long
|
||||
}
|
||||
|
||||
ino_t :: distinct u64
|
||||
|
||||
when ODIN_ARCH == .amd64 {
|
||||
stat_t :: struct {
|
||||
st_dev: dev_t, /* [PSX] ID of device containing file */
|
||||
st_ino: ino_t, /* [PSX] file serial number */
|
||||
st_nlink: nlink_t, /* [PSX] number of hard links */
|
||||
st_mode: mode_t, /* [PSX] mode of file */
|
||||
st_uid: uid_t, /* [PSX] user ID of the file */
|
||||
st_gid: gid_t, /* [PSX] group ID of the file */
|
||||
_pad0: c.uint,
|
||||
st_rdev: dev_t, /* [PSX] device ID */
|
||||
st_size: off_t, /* [PSX] file size, in bytes */
|
||||
st_blksize: blksize_t, /* [PSX] optimal blocksize for I/O */
|
||||
st_blocks: blkcnt_t, /* [PSX] blocks allocated for file */
|
||||
st_atim: timespec, /* [PSX] time of last access */
|
||||
st_mtim: timespec, /* [PSX] time of last data modification */
|
||||
st_ctim: timespec, /* [PSX] time of last status change */
|
||||
__unused: [3]c.long,
|
||||
}
|
||||
} else {
|
||||
stat_t :: struct {
|
||||
st_dev: dev_t, /* [PSX] ID of device containing file */
|
||||
st_ino: ino_t, /* [PSX] file serial number */
|
||||
st_mode: mode_t, /* [PSX] mode of file */
|
||||
st_nlink: nlink_t, /* [PSX] number of hard links */
|
||||
st_uid: uid_t, /* [PSX] user ID of the file */
|
||||
st_gid: gid_t, /* [PSX] group ID of the file */
|
||||
st_rdev: dev_t, /* [PSX] device ID */
|
||||
__pad: c.ulonglong,
|
||||
st_size: off_t, /* [PSX] file size, in bytes */
|
||||
st_blksize: blksize_t, /* [PSX] optimal blocksize for I/O */
|
||||
__pad2: c.int,
|
||||
st_blocks: blkcnt_t, /* [PSX] blocks allocated for file */
|
||||
st_atim: timespec, /* [PSX] time of last access */
|
||||
st_mtim: timespec, /* [PSX] time of last data modification */
|
||||
st_ctim: timespec, /* [PSX] time of last status change */
|
||||
__unused: [2]c.uint,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -130,6 +131,27 @@ when ODIN_OS == .Darwin || ODIN_OS == .OpenBSD {
|
||||
ST_RDONLY :: 0x00000001
|
||||
ST_NOSUID :: 0x00000008
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
fsblkcnt_t :: distinct c.uint64_t
|
||||
|
||||
statvfs_t :: struct {
|
||||
f_bsize: c.ulong, /* [PSX] file system block size */
|
||||
f_frsize: c.ulong, /* [PSX] fundamental file system block size */
|
||||
f_blocks: fsblkcnt_t, /* [PSX] total number of blocks on file system in units of f_frsize */
|
||||
f_bfree: fsblkcnt_t, /* [PSX] total number of free blocks */
|
||||
f_bavail: fsblkcnt_t, /* [PSX] number of free blocks available to non-privileged process */
|
||||
f_files: fsblkcnt_t, /* [PSX] total number of file serial numbers */
|
||||
f_ffree: fsblkcnt_t, /* [PSX] total number of free file serial numbers */
|
||||
f_favail: fsblkcnt_t, /* [PSX] number of file serial numbers available to non-privileged process */
|
||||
f_fsid: c.ulong, /* [PSX] file system ID */
|
||||
_: [2*size_of(c.int)-size_of(c.long)]byte,
|
||||
f_flag: VFS_Flags, /* [PSX] bit mask of f_flag values */
|
||||
f_namemax: c.ulong, /* [PSX] maximum filename length */
|
||||
f_type: c.uint,
|
||||
__reserved: [5]c.int,
|
||||
}
|
||||
|
||||
ST_RDONLY :: 0x00000001
|
||||
ST_NOSUID :: 0x00000002
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -77,6 +78,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
ITIMER_VIRTUAL :: 1
|
||||
ITIMER_PROF :: 2
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
@@ -33,6 +34,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
tms_cstime: clock_t, /* [PSX] terminated children system CPU time */
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -37,6 +38,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
iov_len: c.size_t, /* [PSX] size of the region iov_base points to */
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -19,6 +20,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
sun_path: [108]c.char, /* [PSX] socket pathname */
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -37,15 +38,10 @@ foreign lib {
|
||||
uname :: proc(uname: ^utsname) -> c.int ---
|
||||
}
|
||||
|
||||
when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD || ODIN_OS == .Linux {
|
||||
when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
|
||||
|
||||
when ODIN_OS == .Linux {
|
||||
@(private)
|
||||
_SYS_NAMELEN :: 65
|
||||
} else {
|
||||
@(private)
|
||||
_SYS_NAMELEN :: 256
|
||||
}
|
||||
@(private)
|
||||
_SYS_NAMELEN :: 256
|
||||
|
||||
utsname :: struct {
|
||||
sysname: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of OS */
|
||||
@@ -55,6 +51,17 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
machine: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] hardware type */
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
@(private)
|
||||
_SYS_NAMELEN :: 65
|
||||
|
||||
utsname :: struct {
|
||||
sysname: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of OS */
|
||||
nodename: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] name of this network node */
|
||||
release: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] release level */
|
||||
version: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] version level */
|
||||
machine: [_SYS_NAMELEN]c.char `fmt:"s,0"`, /* [PSX] hardware type */
|
||||
__domainname: [_SYS_NAMELEN]c.char `fmt:"s,0"`,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -391,6 +392,54 @@ when ODIN_OS == .Darwin {
|
||||
return (x & _WCONTINUED) == _WCONTINUED
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
id_t :: distinct c.uint
|
||||
|
||||
WCONTINUED :: 8
|
||||
WNOHANG :: 1
|
||||
WUNTRACED :: 2
|
||||
|
||||
WEXITED :: 4
|
||||
WNOWAIT :: 0x1000000
|
||||
WSTOPPED :: 2
|
||||
|
||||
_P_ALL :: 0
|
||||
_P_PID :: 1
|
||||
_P_PGID :: 2
|
||||
|
||||
@(private)
|
||||
_WIFEXITED :: #force_inline proc "contextless" (x: c.int) -> bool {
|
||||
return _WTERMSIG(x) == nil
|
||||
}
|
||||
|
||||
@(private)
|
||||
_WEXITSTATUS :: #force_inline proc "contextless" (x: c.int) -> c.int {
|
||||
return (x & 0xff00) >> 8
|
||||
}
|
||||
|
||||
@(private)
|
||||
_WIFSIGNALED :: #force_inline proc "contextless" (x: c.int) -> bool {
|
||||
return (x & 0xffff) - 1 < 0xff
|
||||
}
|
||||
|
||||
@(private)
|
||||
_WTERMSIG :: #force_inline proc "contextless" (x: c.int) -> Signal {
|
||||
return Signal(x & 0x7f)
|
||||
}
|
||||
|
||||
@(private)
|
||||
_WIFSTOPPED :: #force_inline proc "contextless" (x: c.int) -> bool {
|
||||
return ((x & 0xffff) * 0x10001) >> 8 > 0x7f00
|
||||
}
|
||||
|
||||
@(private)
|
||||
_WSTOPSIG :: #force_inline proc "contextless" (x: c.int) -> Signal {
|
||||
return Signal(_WEXITSTATUS(x))
|
||||
}
|
||||
|
||||
@(private)
|
||||
_WIFCONTINUED :: #force_inline proc "contextless" (x: c.int) -> bool {
|
||||
return x == 0xffff
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -152,7 +153,7 @@ CControl_Flag_Bits :: enum tcflag_t {
|
||||
CControl_Flags :: bit_set[CControl_Flag_Bits; tcflag_t]
|
||||
|
||||
// character size mask
|
||||
CSIZE :: CControl_Flags{ .CS6, .CS7, .CS8 }
|
||||
CSIZE :: transmute(CControl_Flags)tcflag_t(_CSIZE)
|
||||
|
||||
COutput_Flag_Bits :: enum tcflag_t {
|
||||
OPOST = log2(OPOST), /* enable following output processing */
|
||||
@@ -181,17 +182,17 @@ COutput_Flag_Bits :: enum tcflag_t {
|
||||
COutput_Flags :: bit_set[COutput_Flag_Bits; tcflag_t]
|
||||
|
||||
// \n delay mask
|
||||
NLDLY :: COutput_Flags{ .NL1, COutput_Flag_Bits(9) }
|
||||
NLDLY :: transmute(COutput_Flags)tcflag_t(_NLDLY)
|
||||
// \r delay mask
|
||||
CRDLY :: COutput_Flags{ .CR1, .CR2, .CR3 }
|
||||
CRDLY :: transmute(COutput_Flags)tcflag_t(_CRDLY)
|
||||
// horizontal tab delay mask
|
||||
TABDLY :: COutput_Flags{ .TAB1, .TAB3, COutput_Flag_Bits(2) }
|
||||
TABDLY :: transmute(COutput_Flags)tcflag_t(_TABDLY)
|
||||
// \b delay mask
|
||||
BSDLY :: COutput_Flags{ .BS1 }
|
||||
BSDLY :: transmute(COutput_Flags)tcflag_t(_BSDLY)
|
||||
// vertical tab delay mask
|
||||
VTDLY :: COutput_Flags{ .VT1 }
|
||||
VTDLY :: transmute(COutput_Flags)tcflag_t(_VTDLY)
|
||||
// form feed delay mask
|
||||
FFDLY :: COutput_Flags{ .FF1 }
|
||||
FFDLY :: transmute(COutput_Flags)tcflag_t(_FFDLY)
|
||||
|
||||
speed_t :: enum _speed_t {
|
||||
B0 = B0,
|
||||
@@ -596,6 +597,4 @@ when ODIN_OS == .Darwin {
|
||||
TCOOFF :: 0
|
||||
TCOON :: 1
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -229,6 +230,16 @@ when ODIN_OS == .Darwin {
|
||||
|
||||
getdate_err: Errno = .ENOSYS // NOTE: looks like it's not a thing on OpenBSD.
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
} else when ODIN_OS == .Linux {
|
||||
|
||||
clockid_t :: distinct c.int
|
||||
|
||||
CLOCK_MONOTONIC :: 1
|
||||
CLOCK_PROCESS_CPUTIME_ID :: 2
|
||||
CLOCK_REALTIME :: 0
|
||||
CLOCK_THREAD_CPUTIME_ID :: 3
|
||||
|
||||
foreign lib {
|
||||
getdate_err: Errno
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -38,6 +39,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
|
||||
// NOTE: I don't think OpenBSD implements this API.
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
+2
-110
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -11,19 +12,6 @@ when ODIN_OS == .Darwin {
|
||||
// unistd.h - standard symbolic constants and types
|
||||
|
||||
foreign lib {
|
||||
/*
|
||||
Checks the file named by the pathname pointed to by the path argument for
|
||||
accessibility according to the bit pattern contained in amode.
|
||||
|
||||
Example:
|
||||
if (posix.access("/tmp/myfile", posix.F_OK) != .OK) {
|
||||
fmt.printfln("/tmp/myfile access check failed: %v", posix.strerror(posix.errno()))
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html ]]
|
||||
*/
|
||||
access :: proc(path: cstring, amode: Mode_Flags = F_OK) -> result ---
|
||||
|
||||
/*
|
||||
Equivalent to `access` but relative paths are resolved based on `fd`.
|
||||
|
||||
@@ -42,18 +30,6 @@ foreign lib {
|
||||
*/
|
||||
alarm :: proc(seconds: c.uint) -> c.uint ---
|
||||
|
||||
/*
|
||||
Causes the directory named by path to become the current working directory.
|
||||
|
||||
Example:
|
||||
if (posix.chdir("/tmp") == .OK) {
|
||||
fmt.println("changed current directory to /tmp")
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/chdir.html ]]
|
||||
*/
|
||||
chdir :: proc(path: cstring) -> result ---
|
||||
|
||||
/*
|
||||
Equivalent to chdir but instead of a path the fildes is resolved to a directory.
|
||||
|
||||
@@ -204,15 +180,6 @@ foreign lib {
|
||||
*/
|
||||
dup2 :: proc(fildes, fildes2: FD) -> FD ---
|
||||
|
||||
/*
|
||||
Exits but, shall not call functions registered with atexit() nor any registered signal handlers.
|
||||
Open streams shall not be flushed.
|
||||
Whether open streams are closed (without flushing) is implementation-defined. Finally, the calling process shall be terminated with the consequences described below.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/_exit.html ]]
|
||||
*/
|
||||
_exit :: proc(status: c.int) -> ! ---
|
||||
|
||||
/*
|
||||
The exec family of functions shall replace the current process image with a new process image.
|
||||
The new image shall be constructed from a regular, executable file called the new process image file.
|
||||
@@ -392,44 +359,6 @@ foreign lib {
|
||||
*/
|
||||
ftruncate :: proc(fildes: FD, length: off_t) -> result ---
|
||||
|
||||
/*
|
||||
Places an absolute pathname of the current working directory into buf.
|
||||
|
||||
Returns: buf as a cstring on success, nil (setting errno) on failure
|
||||
|
||||
Example:
|
||||
size: int
|
||||
path_max := posix.pathconf(".", ._PATH_MAX)
|
||||
if path_max == -1 {
|
||||
size = 1024
|
||||
} else if path_max > 10240 {
|
||||
size = 10240
|
||||
} else {
|
||||
size = int(path_max)
|
||||
}
|
||||
|
||||
buf: [dynamic]byte
|
||||
cwd: cstring
|
||||
for ; cwd == nil; size *= 2 {
|
||||
if err := resize(&buf, size); err != nil {
|
||||
fmt.panicf("allocation failure: %v", err)
|
||||
}
|
||||
|
||||
cwd = posix.getcwd(raw_data(buf), len(buf))
|
||||
if cwd == nil {
|
||||
errno := posix.errno()
|
||||
if errno != .ERANGE {
|
||||
fmt.panicf("getcwd failure: %v", posix.strerror(errno))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.println(path_max, cwd)
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html ]]
|
||||
*/
|
||||
getcwd :: proc(buf: [^]c.char, size: c.size_t) -> cstring ---
|
||||
|
||||
/*
|
||||
Returns the effective group ID of the calling process.
|
||||
|
||||
@@ -829,13 +758,6 @@ foreign lib {
|
||||
*/
|
||||
readlinkat :: proc(fd: FD, path: cstring, buf: [^]byte, bufsize: c.size_t) -> c.ssize_t ---
|
||||
|
||||
/*
|
||||
Remove an (empty) directory.
|
||||
|
||||
]] More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html ]]
|
||||
*/
|
||||
rmdir :: proc(path: cstring) -> result ---
|
||||
|
||||
/*
|
||||
Set the effective group ID.
|
||||
|
||||
@@ -912,13 +834,6 @@ foreign lib {
|
||||
*/
|
||||
sleep :: proc(seconds: c.uint) -> c.uint ---
|
||||
|
||||
/*
|
||||
Copy nbyte bytes, from src, to dest, exchanging adjecent bytes.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/swab.html ]]
|
||||
*/
|
||||
swab :: proc(src: [^]byte, dest: [^]byte, nbytes: c.ssize_t) ---
|
||||
|
||||
/*
|
||||
Schedule file system updates.
|
||||
|
||||
@@ -958,13 +873,6 @@ foreign lib {
|
||||
*/
|
||||
ttyname_r :: proc(fildes: FD, name: [^]byte, namesize: c.size_t) -> Errno ---
|
||||
|
||||
/*
|
||||
Remove a directory entry.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html ]]
|
||||
*/
|
||||
unlink :: proc(path: cstring) -> result ---
|
||||
|
||||
/*
|
||||
Equivalent to unlink or rmdir (if flag is .REMOVEDIR) but relative paths are relative to the dir fd.
|
||||
|
||||
@@ -973,20 +881,6 @@ foreign lib {
|
||||
unlinkat :: proc(fd: FD, path: cstring, flag: AT_Flags) -> result ---
|
||||
}
|
||||
|
||||
STDERR_FILENO :: 2
|
||||
STDIN_FILENO :: 0
|
||||
STDOUT_FILENO :: 1
|
||||
|
||||
Mode_Flag_Bits :: enum c.int {
|
||||
X_OK = log2(X_OK),
|
||||
W_OK = log2(W_OK),
|
||||
R_OK = log2(R_OK),
|
||||
}
|
||||
Mode_Flags :: bit_set[Mode_Flag_Bits; c.int]
|
||||
|
||||
#assert(_F_OK == 0)
|
||||
F_OK :: Mode_Flags{}
|
||||
|
||||
CS :: enum c.int {
|
||||
_PATH = _CS_PATH,
|
||||
_POSIX_V6_ILP32_OFF32_CFLAGS = _CS_POSIX_V6_ILP32_OFF32_CFLAGS,
|
||||
@@ -2063,6 +1957,7 @@ when ODIN_OS == .Darwin {
|
||||
_SC_TYPED_MEMORY_OBJECTS :: 165
|
||||
_SC_2_PBS :: 168
|
||||
_SC_2_PBS_ACCOUNTING :: 169
|
||||
_SC_2_PBS_LOCATE :: 170
|
||||
_SC_2_PBS_MESSAGE :: 171
|
||||
_SC_2_PBS_TRACK :: 172
|
||||
_SC_SYMLOOP_MAX :: 173
|
||||
@@ -2097,7 +1992,4 @@ when ODIN_OS == .Darwin {
|
||||
// NOTE: Not implemented.
|
||||
_POSIX_VDISABLE :: 0
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
#+build linux, windows, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
foreign import lib "system:libucrt.lib"
|
||||
} else when ODIN_OS == .Darwin {
|
||||
foreign import lib "system:System.framework"
|
||||
} else {
|
||||
foreign import lib "system:c"
|
||||
}
|
||||
|
||||
// unistd.h - standard symbolic constants and types
|
||||
|
||||
foreign lib {
|
||||
/*
|
||||
Checks the file named by the pathname pointed to by the path argument for
|
||||
accessibility according to the bit pattern contained in amode.
|
||||
|
||||
Example:
|
||||
if (posix.access("/tmp/myfile", posix.F_OK) != .OK) {
|
||||
fmt.printfln("/tmp/myfile access check failed: %v", posix.strerror(posix.errno()))
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html ]]
|
||||
*/
|
||||
@(link_name=LACCESS)
|
||||
access :: proc(path: cstring, amode: Mode_Flags = F_OK) -> result ---
|
||||
|
||||
/*
|
||||
Causes the directory named by path to become the current working directory.
|
||||
|
||||
Example:
|
||||
if (posix.chdir("/tmp") == .OK) {
|
||||
fmt.println("changed current directory to /tmp")
|
||||
}
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/chdir.html ]]
|
||||
*/
|
||||
@(link_name=LCHDIR)
|
||||
chdir :: proc(path: cstring) -> result ---
|
||||
|
||||
/*
|
||||
Exits but, shall not call functions registered with atexit() nor any registered signal handlers.
|
||||
Open streams shall not be flushed.
|
||||
Whether open streams are closed (without flushing) is implementation-defined. Finally, the calling process shall be terminated with the consequences described below.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/_exit.html ]]
|
||||
*/
|
||||
_exit :: proc(status: c.int) -> ! ---
|
||||
|
||||
/*
|
||||
Places an absolute pathname of the current working directory into buf.
|
||||
|
||||
Returns: buf as a cstring on success, nil (setting errno) on failure
|
||||
|
||||
Example:
|
||||
size: int
|
||||
path_max := posix.pathconf(".", ._PATH_MAX)
|
||||
if path_max == -1 {
|
||||
size = 1024
|
||||
} else if path_max > 10240 {
|
||||
size = 10240
|
||||
} else {
|
||||
size = int(path_max)
|
||||
}
|
||||
|
||||
buf: [dynamic]byte
|
||||
cwd: cstring
|
||||
for ; cwd == nil; size *= 2 {
|
||||
if err := resize(&buf, size); err != nil {
|
||||
fmt.panicf("allocation failure: %v", err)
|
||||
}
|
||||
|
||||
cwd = posix.getcwd(raw_data(buf), len(buf))
|
||||
if cwd == nil {
|
||||
errno := posix.errno()
|
||||
if errno != .ERANGE {
|
||||
fmt.panicf("getcwd failure: %v", posix.strerror(errno))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.println(path_max, cwd)
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html ]]
|
||||
*/
|
||||
@(link_name=LGETCWD)
|
||||
getcwd :: proc(buf: [^]c.char, size: c.size_t) -> cstring ---
|
||||
|
||||
/*
|
||||
Remove an (empty) directory.
|
||||
|
||||
]] More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html ]]
|
||||
*/
|
||||
@(link_name=LRMDIR)
|
||||
rmdir :: proc(path: cstring) -> result ---
|
||||
|
||||
/*
|
||||
Copy nbyte bytes, from src, to dest, exchanging adjecent bytes.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/swab.html ]]
|
||||
*/
|
||||
@(link_name=LSWAB)
|
||||
swab :: proc(src: [^]byte, dest: [^]byte, nbytes: c.ssize_t) ---
|
||||
|
||||
/*
|
||||
Remove a directory entry.
|
||||
|
||||
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/unlink.html ]]
|
||||
*/
|
||||
@(link_name=LUNLINK)
|
||||
unlink :: proc(path: cstring) -> result ---
|
||||
}
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
@(private) LACCESS :: "_access"
|
||||
@(private) LCHDIR :: "_chdir"
|
||||
@(private) LGETCWD :: "_getcwd"
|
||||
@(private) LRMDIR :: "_rmdir"
|
||||
@(private) LSWAB :: "_swab"
|
||||
@(private) LUNLINK :: "_unlink"
|
||||
} else {
|
||||
@(private) LACCESS :: "access"
|
||||
@(private) LCHDIR :: "chdir"
|
||||
@(private) LGETCWD :: "getcwd"
|
||||
@(private) LRMDIR :: "rmdir"
|
||||
@(private) LSWAB :: "swab"
|
||||
@(private) LUNLINK :: "unlink"
|
||||
}
|
||||
|
||||
STDERR_FILENO :: 2
|
||||
STDIN_FILENO :: 0
|
||||
STDOUT_FILENO :: 1
|
||||
|
||||
Mode_Flag_Bits :: enum c.int {
|
||||
X_OK = log2(X_OK),
|
||||
W_OK = log2(W_OK),
|
||||
R_OK = log2(R_OK),
|
||||
}
|
||||
Mode_Flags :: bit_set[Mode_Flag_Bits; c.int]
|
||||
|
||||
#assert(_F_OK == 0)
|
||||
F_OK :: Mode_Flags{}
|
||||
|
||||
when ODIN_OS == .Windows {
|
||||
_F_OK :: 0
|
||||
X_OK :: 1
|
||||
W_OK :: 2
|
||||
R_OK :: 4
|
||||
#assert(W_OK|R_OK == 6)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
when ODIN_OS == .Darwin {
|
||||
@@ -31,6 +32,4 @@ when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS
|
||||
modtime: time_t, /* [PSX] modification time (seconds since epoch) */
|
||||
}
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#+build linux, darwin, netbsd, openbsd, freebsd
|
||||
package posix
|
||||
|
||||
import "core:c"
|
||||
@@ -123,6 +124,4 @@ when ODIN_OS == .Darwin {
|
||||
WRDE_CMDSUB :: 4
|
||||
WRDE_SYNTAX :: 5
|
||||
|
||||
} else {
|
||||
#panic("posix is unimplemented for the current target")
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
#+build darwin
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
// NOTE(tetra): No 32-bit Macs.
|
||||
// Source: _pthread_types.h on my Mac.
|
||||
PTHREAD_SIZE :: 8176
|
||||
PTHREAD_ATTR_SIZE :: 56
|
||||
PTHREAD_MUTEXATTR_SIZE :: 8
|
||||
PTHREAD_MUTEX_SIZE :: 56
|
||||
PTHREAD_CONDATTR_SIZE :: 8
|
||||
PTHREAD_COND_SIZE :: 40
|
||||
PTHREAD_ONCE_SIZE :: 8
|
||||
PTHREAD_RWLOCK_SIZE :: 192
|
||||
PTHREAD_RWLOCKATTR_SIZE :: 16
|
||||
|
||||
pthread_t :: distinct u64
|
||||
|
||||
pthread_attr_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_ATTR_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_cond_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_COND_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_condattr_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_CONDATTR_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_mutex_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_MUTEX_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_mutexattr_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_MUTEXATTR_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_once_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_ONCE_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_rwlock_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_RWLOCK_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_rwlockattr_t :: struct {
|
||||
sig: c.long,
|
||||
_: [PTHREAD_RWLOCKATTR_SIZE] c.char,
|
||||
}
|
||||
|
||||
SCHED_OTHER :: 1 // Avoid if you are writing portable software.
|
||||
SCHED_FIFO :: 4
|
||||
SCHED_RR :: 2 // Round robin.
|
||||
|
||||
SCHED_PARAM_SIZE :: 4
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
_: [SCHED_PARAM_SIZE] c.char,
|
||||
}
|
||||
|
||||
// Source: https://github.com/apple/darwin-libpthread/blob/03c4628c8940cca6fd6a82957f683af804f62e7f/pthread/pthread.h#L138
|
||||
PTHREAD_CREATE_JOINABLE :: 1
|
||||
PTHREAD_CREATE_DETACHED :: 2
|
||||
PTHREAD_INHERIT_SCHED :: 1
|
||||
PTHREAD_EXPLICIT_SCHED :: 2
|
||||
PTHREAD_PROCESS_SHARED :: 1
|
||||
PTHREAD_PROCESS_PRIVATE :: 2
|
||||
|
||||
|
||||
PTHREAD_MUTEX_NORMAL :: 0
|
||||
PTHREAD_MUTEX_RECURSIVE :: 1
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 2
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 1
|
||||
|
||||
foreign import pthread "system:System.framework"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
#+build freebsd
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
pthread_t :: distinct u64
|
||||
// pthread_t :: struct #align(16) { x: u64 }
|
||||
|
||||
PTHREAD_COND_T_SIZE :: 8
|
||||
|
||||
PTHREAD_MUTEXATTR_T_SIZE :: 8
|
||||
PTHREAD_CONDATTR_T_SIZE :: 8
|
||||
PTHREAD_RWLOCKATTR_T_SIZE :: 8
|
||||
PTHREAD_BARRIERATTR_T_SIZE :: 8
|
||||
|
||||
// WARNING: The sizes of these things are different yet again
|
||||
// on non-X86!
|
||||
when size_of(int) == 8 {
|
||||
PTHREAD_ATTR_T_SIZE :: 8
|
||||
PTHREAD_MUTEX_T_SIZE :: 8
|
||||
PTHREAD_RWLOCK_T_SIZE :: 8
|
||||
PTHREAD_BARRIER_T_SIZE :: 8
|
||||
} else when size_of(int) == 4 { // TODO
|
||||
PTHREAD_ATTR_T_SIZE :: 32
|
||||
PTHREAD_MUTEX_T_SIZE :: 32
|
||||
PTHREAD_RWLOCK_T_SIZE :: 44
|
||||
PTHREAD_BARRIER_T_SIZE :: 20
|
||||
}
|
||||
|
||||
pthread_cond_t :: struct #align(16) {
|
||||
_: [PTHREAD_COND_T_SIZE] c.char,
|
||||
}
|
||||
pthread_mutex_t :: struct #align(16) {
|
||||
_: [PTHREAD_MUTEX_T_SIZE] c.char,
|
||||
}
|
||||
pthread_rwlock_t :: struct #align(16) {
|
||||
_: [PTHREAD_RWLOCK_T_SIZE] c.char,
|
||||
}
|
||||
pthread_barrier_t :: struct #align(16) {
|
||||
_: [PTHREAD_BARRIER_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_attr_t :: struct #align(16) {
|
||||
_: [PTHREAD_ATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_condattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_CONDATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_mutexattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_MUTEXATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_rwlockattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_RWLOCKATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_barrierattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_BARRIERATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 1
|
||||
PTHREAD_MUTEX_RECURSIVE :: 2
|
||||
PTHREAD_MUTEX_NORMAL :: 3
|
||||
|
||||
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_CREATE_DETACHED :: 1
|
||||
PTHREAD_INHERIT_SCHED :: 4
|
||||
PTHREAD_EXPLICIT_SCHED :: 0
|
||||
PTHREAD_PROCESS_PRIVATE :: 0
|
||||
PTHREAD_PROCESS_SHARED :: 1
|
||||
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_OTHER :: 2
|
||||
SCHED_RR :: 3 // Round robin.
|
||||
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
_usem :: struct {
|
||||
_has_waiters: u32,
|
||||
_count: u32,
|
||||
_flags: u32,
|
||||
}
|
||||
_usem2 :: struct {
|
||||
_count: u32,
|
||||
_flags: u32,
|
||||
}
|
||||
sem_t :: struct {
|
||||
_magic: u32,
|
||||
_kern: _usem2,
|
||||
_padding: u32,
|
||||
}
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 2
|
||||
|
||||
foreign import "system:pthread"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
// create named semaphore.
|
||||
// used in process-shared semaphores.
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
// sem_timedwait :: proc(sem: ^sem_t, timeout: time.TimeSpec) -> c.int ---
|
||||
|
||||
// NOTE: unclear whether pthread_yield is well-supported on Linux systems,
|
||||
// see https://linux.die.net/man/3/pthread_yield
|
||||
pthread_yield :: proc() ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
pthread_t :: distinct rawptr
|
||||
pthread_attr_t :: distinct rawptr
|
||||
pthread_mutex_t :: distinct rawptr
|
||||
pthread_mutexattr_t :: distinct rawptr
|
||||
pthread_cond_t :: distinct rawptr
|
||||
pthread_condattr_t :: distinct rawptr
|
||||
pthread_rwlock_t :: distinct rawptr
|
||||
pthread_rwlockattr_t :: distinct rawptr
|
||||
pthread_barrier_t :: distinct rawptr
|
||||
pthread_barrierattr_t :: distinct rawptr
|
||||
pthread_spinlock_t :: distinct rawptr
|
||||
|
||||
pthread_key_t :: distinct c.int
|
||||
pthread_once_t :: struct {
|
||||
state: c.int,
|
||||
mutex: pthread_mutex_t,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_DEFAULT :: 0
|
||||
PTHREAD_MUTEX_NORMAL :: 1
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 2
|
||||
PTHREAD_MUTEX_RECURSIVE :: 3
|
||||
|
||||
PTHREAD_DETACHED :: 0x1
|
||||
PTHREAD_SCOPE_SYSTEM :: 0x2
|
||||
PTHREAD_INHERIT_SCHED :: 0x4
|
||||
PTHREAD_NOFLOAT :: 0x8
|
||||
|
||||
PTHREAD_CREATE_DETACHED :: PTHREAD_DETACHED
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_SCOPE_PROCESS :: 0
|
||||
PTHREAD_EXPLICIT_SCHED :: 0
|
||||
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_RR :: 2
|
||||
SCHED_SPORADIC :: 3
|
||||
SCHED_OTHER :: 4
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
sem_t :: distinct rawptr
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 2
|
||||
|
||||
foreign import libc "system:c"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign libc {
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
|
||||
pthread_yield :: proc() ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
#+build linux
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
// TODO(tetra): For robustness, I'd like to mark this with align 16.
|
||||
// I cannot currently do this.
|
||||
// And at the time of writing there is a bug with putting it
|
||||
// as the only field in a struct.
|
||||
pthread_t :: distinct u64
|
||||
// pthread_t :: struct #align(16) { x: u64 };
|
||||
|
||||
// NOTE(tetra): Got all the size constants from pthreadtypes-arch.h on my
|
||||
// Linux machine.
|
||||
|
||||
PTHREAD_COND_T_SIZE :: 48
|
||||
|
||||
PTHREAD_MUTEXATTR_T_SIZE :: 4
|
||||
PTHREAD_CONDATTR_T_SIZE :: 4
|
||||
PTHREAD_RWLOCKATTR_T_SIZE :: 8
|
||||
PTHREAD_BARRIERATTR_T_SIZE :: 4
|
||||
|
||||
// WARNING: The sizes of these things are different yet again
|
||||
// on non-X86!
|
||||
when size_of(int) == 8 {
|
||||
PTHREAD_ATTR_T_SIZE :: 56
|
||||
PTHREAD_MUTEX_T_SIZE :: 40
|
||||
PTHREAD_RWLOCK_T_SIZE :: 56
|
||||
PTHREAD_BARRIER_T_SIZE :: 32
|
||||
} else when size_of(int) == 4 {
|
||||
PTHREAD_ATTR_T_SIZE :: 32
|
||||
PTHREAD_MUTEX_T_SIZE :: 32
|
||||
PTHREAD_RWLOCK_T_SIZE :: 44
|
||||
PTHREAD_BARRIER_T_SIZE :: 20
|
||||
}
|
||||
|
||||
pthread_cond_t :: struct #align(16) {
|
||||
_: [PTHREAD_COND_T_SIZE] c.char,
|
||||
}
|
||||
pthread_mutex_t :: struct #align(16) {
|
||||
_: [PTHREAD_MUTEX_T_SIZE] c.char,
|
||||
}
|
||||
pthread_rwlock_t :: struct #align(16) {
|
||||
_: [PTHREAD_RWLOCK_T_SIZE] c.char,
|
||||
}
|
||||
pthread_barrier_t :: struct #align(16) {
|
||||
_: [PTHREAD_BARRIER_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_attr_t :: struct #align(16) {
|
||||
_: [PTHREAD_ATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_condattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_CONDATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_mutexattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_MUTEXATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_rwlockattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_RWLOCKATTR_T_SIZE] c.char,
|
||||
}
|
||||
pthread_barrierattr_t :: struct #align(16) {
|
||||
_: [PTHREAD_BARRIERATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_NORMAL :: 0
|
||||
PTHREAD_MUTEX_RECURSIVE :: 1
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 2
|
||||
|
||||
|
||||
// TODO(tetra, 2019-11-01): Maybe make `enum c.int`s for these?
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_CREATE_DETACHED :: 1
|
||||
PTHREAD_INHERIT_SCHED :: 0
|
||||
PTHREAD_EXPLICIT_SCHED :: 1
|
||||
PTHREAD_PROCESS_PRIVATE :: 0
|
||||
PTHREAD_PROCESS_SHARED :: 1
|
||||
|
||||
SCHED_OTHER :: 0
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_RR :: 2 // Round robin.
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
sem_t :: struct #align(16) {
|
||||
_: [SEM_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
when size_of(int) == 8 {
|
||||
SEM_T_SIZE :: 32
|
||||
} else when size_of(int) == 4 {
|
||||
SEM_T_SIZE :: 16
|
||||
}
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 1
|
||||
|
||||
foreign import "system:pthread"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
// create named semaphore.
|
||||
// used in process-shared semaphores.
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
// sem_timedwait :: proc(sem: ^sem_t, timeout: time.TimeSpec) -> c.int ---;
|
||||
|
||||
// NOTE: unclear whether pthread_yield is well-supported on Linux systems,
|
||||
// see https://linux.die.net/man/3/pthread_yield
|
||||
pthread_yield :: proc() -> c.int ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
pthread_t :: distinct rawptr
|
||||
|
||||
SEM_T_SIZE :: 8
|
||||
|
||||
PTHREAD_CONDATTR_T_SIZE :: 16
|
||||
PTHREAD_MUTEXATTR_T_SIZE :: 16
|
||||
PTHREAD_RWLOCKATTR_T_SIZE :: 16
|
||||
PTHREAD_BARRIERATTR_T_SIZE :: 16
|
||||
|
||||
PTHREAD_COND_T_SIZE :: 40
|
||||
PTHREAD_MUTEX_T_SIZE :: 48
|
||||
PTHREAD_RWLOCK_T_SIZE :: 64
|
||||
PTHREAD_BARRIER_T_SIZE :: 48
|
||||
PTHREAD_ATTR_T_SIZE :: 16
|
||||
|
||||
pthread_cond_t :: struct #align(8) {
|
||||
_: [PTHREAD_COND_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_mutex_t :: struct #align(8) {
|
||||
_: [PTHREAD_MUTEX_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_rwlock_t :: struct #align(8) {
|
||||
_: [PTHREAD_RWLOCK_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_barrier_t :: struct #align(8) {
|
||||
_: [PTHREAD_BARRIER_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_attr_t :: struct #align(8) {
|
||||
_: [PTHREAD_ATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_condattr_t :: struct #align(8) {
|
||||
_: [PTHREAD_CONDATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_mutexattr_t :: struct #align(8) {
|
||||
_: [PTHREAD_MUTEXATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_rwlockattr_t :: struct #align(8) {
|
||||
_: [PTHREAD_RWLOCKATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
pthread_barrierattr_t :: struct #align(8) {
|
||||
_: [PTHREAD_BARRIERATTR_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_NORMAL :: 0
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 1
|
||||
PTHREAD_MUTEX_RECURSIVE :: 2
|
||||
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_CREATE_DETACHED :: 1
|
||||
PTHREAD_INHERIT_SCHED :: 0
|
||||
PTHREAD_EXPLICIT_SCHED :: 1
|
||||
PTHREAD_PROCESS_PRIVATE :: 0
|
||||
PTHREAD_PROCESS_SHARED :: 1
|
||||
|
||||
SCHED_NONE :: -1
|
||||
SCHED_OTHER :: 0
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_RR :: 3
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
sem_t :: struct #align(16) {
|
||||
_: [SEM_T_SIZE] c.char,
|
||||
}
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 1
|
||||
|
||||
foreign import "system:pthread"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
|
||||
pthread_yield :: proc() ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
#+build openbsd
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
pthread_t :: distinct rawptr
|
||||
pthread_attr_t :: distinct rawptr
|
||||
pthread_mutex_t :: distinct rawptr
|
||||
pthread_mutexattr_t :: distinct rawptr
|
||||
pthread_cond_t :: distinct rawptr
|
||||
pthread_condattr_t :: distinct rawptr
|
||||
pthread_rwlock_t :: distinct rawptr
|
||||
pthread_rwlockattr_t :: distinct rawptr
|
||||
pthread_barrier_t :: distinct rawptr
|
||||
pthread_barrierattr_t :: distinct rawptr
|
||||
pthread_spinlock_t :: distinct rawptr
|
||||
|
||||
pthread_key_t :: distinct c.int
|
||||
pthread_once_t :: struct {
|
||||
state: c.int,
|
||||
mutex: pthread_mutex_t,
|
||||
}
|
||||
|
||||
PTHREAD_MUTEX_ERRORCHECK :: 1
|
||||
PTHREAD_MUTEX_RECURSIVE :: 2
|
||||
PTHREAD_MUTEX_NORMAL :: 3
|
||||
PTHREAD_MUTEX_STRICT_NP :: 4
|
||||
|
||||
PTHREAD_DETACHED :: 0x1
|
||||
PTHREAD_SCOPE_SYSTEM :: 0x2
|
||||
PTHREAD_INHERIT_SCHED :: 0x4
|
||||
PTHREAD_NOFLOAT :: 0x8
|
||||
|
||||
PTHREAD_CREATE_DETACHED :: PTHREAD_DETACHED
|
||||
PTHREAD_CREATE_JOINABLE :: 0
|
||||
PTHREAD_SCOPE_PROCESS :: 0
|
||||
PTHREAD_EXPLICIT_SCHED :: 0
|
||||
|
||||
SCHED_FIFO :: 1
|
||||
SCHED_OTHER :: 2
|
||||
SCHED_RR :: 3
|
||||
|
||||
sched_param :: struct {
|
||||
sched_priority: c.int,
|
||||
}
|
||||
|
||||
sem_t :: distinct rawptr
|
||||
|
||||
PTHREAD_CANCEL_ENABLE :: 0
|
||||
PTHREAD_CANCEL_DISABLE :: 1
|
||||
PTHREAD_CANCEL_DEFERRED :: 0
|
||||
PTHREAD_CANCEL_ASYNCHRONOUS :: 2
|
||||
|
||||
foreign import libc "system:c"
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign libc {
|
||||
sem_open :: proc(name: cstring, flags: c.int) -> ^sem_t ---
|
||||
|
||||
sem_init :: proc(sem: ^sem_t, pshared: c.int, initial_value: c.uint) -> c.int ---
|
||||
sem_destroy :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_post :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---
|
||||
sem_trywait :: proc(sem: ^sem_t) -> c.int ---
|
||||
//sem_timedwait :: proc(sem: ^sem_t, timeout: time.TimeSpec) -> c.int ---
|
||||
|
||||
// NOTE: unclear whether pthread_yield is well-supported on Linux systems,
|
||||
// see https://linux.die.net/man/3/pthread_yield
|
||||
pthread_yield :: proc() ---
|
||||
|
||||
pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int ---
|
||||
pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int ---
|
||||
pthread_cancel :: proc (thread: pthread_t) -> c.int ---
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
#+build linux, darwin, freebsd, openbsd, netbsd, haiku
|
||||
package unix
|
||||
|
||||
foreign import "system:pthread"
|
||||
|
||||
import "core:c"
|
||||
|
||||
timespec :: struct {
|
||||
tv_sec: i64,
|
||||
tv_nsec: i64,
|
||||
}
|
||||
|
||||
//
|
||||
// On success, these functions return 0.
|
||||
//
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
pthread_create :: proc(t: ^pthread_t, attrs: ^pthread_attr_t, routine: proc(data: rawptr) -> rawptr, arg: rawptr) -> c.int ---
|
||||
|
||||
// retval is a pointer to a location to put the return value of the thread proc.
|
||||
pthread_join :: proc(t: pthread_t, retval: ^rawptr) -> c.int ---
|
||||
|
||||
pthread_kill :: proc(t: pthread_t, sig: c.int) -> c.int ---
|
||||
|
||||
pthread_self :: proc() -> pthread_t ---
|
||||
|
||||
pthread_equal :: proc(a, b: pthread_t) -> b32 ---
|
||||
|
||||
pthread_detach :: proc(t: pthread_t) -> c.int ---
|
||||
|
||||
sched_get_priority_min :: proc(policy: c.int) -> c.int ---
|
||||
sched_get_priority_max :: proc(policy: c.int) -> c.int ---
|
||||
|
||||
// NOTE: POSIX says this can fail with OOM.
|
||||
pthread_attr_init :: proc(attrs: ^pthread_attr_t) -> c.int ---
|
||||
|
||||
pthread_attr_destroy :: proc(attrs: ^pthread_attr_t) -> c.int ---
|
||||
|
||||
pthread_attr_getschedparam :: proc(attrs: ^pthread_attr_t, param: ^sched_param) -> c.int ---
|
||||
pthread_attr_setschedparam :: proc(attrs: ^pthread_attr_t, param: ^sched_param) -> c.int ---
|
||||
|
||||
// states: PTHREAD_CREATE_DETACHED, PTHREAD_CREATE_JOINABLE
|
||||
pthread_attr_setdetachstate :: proc(attrs: ^pthread_attr_t, detach_state: c.int) -> c.int ---
|
||||
|
||||
// NOTE(tetra, 2019-11-06): WARNING: Different systems have different alignment requirements.
|
||||
// For maximum usefulness, use the OS's page size.
|
||||
// ALSO VERY MAJOR WARNING: `stack_ptr` must be the LAST byte of the stack on systems
|
||||
// where the stack grows downwards, which is the common case, so far as I know.
|
||||
// On systems where it grows upwards, give the FIRST byte instead.
|
||||
// ALSO SLIGHTLY LESS MAJOR WARNING: Using this procedure DISABLES automatically-provided
|
||||
// guard pages. If you are using this procedure, YOU must set them up manually.
|
||||
// If you forget to do this, you WILL get stack corruption bugs if you do not EXTREMELY
|
||||
// know what you are doing!
|
||||
pthread_attr_setstack :: proc(attrs: ^pthread_attr_t, stack_ptr: rawptr, stack_size: u64) -> c.int ---
|
||||
pthread_attr_getstack :: proc(attrs: ^pthread_attr_t, stack_ptr: ^rawptr, stack_size: ^u64) -> c.int ---
|
||||
|
||||
pthread_sigmask :: proc(how: c.int, set: rawptr, oldset: rawptr) -> c.int ---
|
||||
|
||||
sched_yield :: proc() -> c.int ---
|
||||
}
|
||||
|
||||
// NOTE: Unimplemented in Haiku.
|
||||
when ODIN_OS != .Haiku {
|
||||
foreign pthread {
|
||||
// scheds: PTHREAD_INHERIT_SCHED, PTHREAD_EXPLICIT_SCHED
|
||||
pthread_attr_setinheritsched :: proc(attrs: ^pthread_attr_t, sched: c.int) -> c.int ---
|
||||
|
||||
pthread_attr_getschedpolicy :: proc(t: ^pthread_attr_t, policy: ^c.int) -> c.int ---
|
||||
pthread_attr_setschedpolicy :: proc(t: ^pthread_attr_t, policy: c.int) -> c.int ---
|
||||
}
|
||||
}
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
// NOTE: POSIX says this can fail with OOM.
|
||||
pthread_cond_init :: proc(cond: ^pthread_cond_t, attrs: ^pthread_condattr_t) -> c.int ---
|
||||
|
||||
pthread_cond_destroy :: proc(cond: ^pthread_cond_t) -> c.int ---
|
||||
|
||||
pthread_cond_signal :: proc(cond: ^pthread_cond_t) -> c.int ---
|
||||
|
||||
// same as signal, but wakes up _all_ threads that are waiting
|
||||
pthread_cond_broadcast :: proc(cond: ^pthread_cond_t) -> c.int ---
|
||||
|
||||
|
||||
// assumes the mutex is pre-locked
|
||||
pthread_cond_wait :: proc(cond: ^pthread_cond_t, mutex: ^pthread_mutex_t) -> c.int ---
|
||||
pthread_cond_timedwait :: proc(cond: ^pthread_cond_t, mutex: ^pthread_mutex_t, timeout: ^timespec) -> c.int ---
|
||||
|
||||
pthread_condattr_init :: proc(attrs: ^pthread_condattr_t) -> c.int ---
|
||||
pthread_condattr_destroy :: proc(attrs: ^pthread_condattr_t) -> c.int ---
|
||||
|
||||
// p-shared = "process-shared" - i.e: is this condition shared among multiple processes?
|
||||
// values: PTHREAD_PROCESS_PRIVATE, PTHREAD_PROCESS_SHARED
|
||||
pthread_condattr_setpshared :: proc(attrs: ^pthread_condattr_t, value: c.int) -> c.int ---
|
||||
pthread_condattr_getpshared :: proc(attrs: ^pthread_condattr_t, result: ^c.int) -> c.int ---
|
||||
|
||||
}
|
||||
|
||||
@(default_calling_convention="c")
|
||||
foreign pthread {
|
||||
// NOTE: POSIX says this can fail with OOM.
|
||||
pthread_mutex_init :: proc(mutex: ^pthread_mutex_t, attrs: ^pthread_mutexattr_t) -> c.int ---
|
||||
|
||||
pthread_mutex_destroy :: proc(mutex: ^pthread_mutex_t) -> c.int ---
|
||||
|
||||
pthread_mutex_trylock :: proc(mutex: ^pthread_mutex_t) -> c.int ---
|
||||
|
||||
pthread_mutex_lock :: proc(mutex: ^pthread_mutex_t) -> c.int ---
|
||||
|
||||
pthread_mutex_timedlock :: proc(mutex: ^pthread_mutex_t, timeout: ^timespec) -> c.int ---
|
||||
|
||||
pthread_mutex_unlock :: proc(mutex: ^pthread_mutex_t) -> c.int ---
|
||||
|
||||
|
||||
pthread_mutexattr_init :: proc(attrs: ^pthread_mutexattr_t) -> c.int ---
|
||||
pthread_mutexattr_destroy :: proc(attrs: ^pthread_mutexattr_t) -> c.int ---
|
||||
pthread_mutexattr_settype :: proc(attrs: ^pthread_mutexattr_t, type: c.int) -> c.int ---
|
||||
|
||||
// p-shared = "process-shared" - i.e: is this mutex shared among multiple processes?
|
||||
// values: PTHREAD_PROCESS_PRIVATE, PTHREAD_PROCESS_SHARED
|
||||
pthread_mutexattr_setpshared :: proc(attrs: ^pthread_mutexattr_t, value: c.int) -> c.int ---
|
||||
pthread_mutexattr_getpshared :: proc(attrs: ^pthread_mutexattr_t, result: ^c.int) -> c.int ---
|
||||
|
||||
pthread_testcancel :: proc () ---
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package unix
|
||||
|
||||
import "core:c"
|
||||
|
||||
timespec :: struct {
|
||||
secs: i64,
|
||||
nsecs: c.long,
|
||||
}
|
||||
@@ -20,6 +20,8 @@ foreign dom_lib {
|
||||
device_pixel_ratio :: proc() -> f64 ---
|
||||
|
||||
window_set_scroll :: proc(x, y: f64) ---
|
||||
|
||||
set_element_style :: proc(id: string, key: string, value: string) ---
|
||||
}
|
||||
|
||||
get_element_value_string :: proc "contextless" (id: string, buf: []byte) -> string {
|
||||
|
||||
@@ -186,8 +186,8 @@ Key_Location :: enum u8 {
|
||||
Numpad = 3,
|
||||
}
|
||||
|
||||
KEYBOARD_MAX_KEY_SIZE :: 16
|
||||
KEYBOARD_MAX_CODE_SIZE :: 16
|
||||
KEYBOARD_MAX_KEY_SIZE :: 32
|
||||
KEYBOARD_MAX_CODE_SIZE :: 32
|
||||
|
||||
GAMEPAD_MAX_ID_SIZE :: 64
|
||||
GAMEPAD_MAX_MAPPING_SIZE :: 64
|
||||
|
||||
+29
-16
@@ -1259,13 +1259,26 @@ class WebGLInterface {
|
||||
};
|
||||
|
||||
|
||||
function odinSetupDefaultImports(wasmMemoryInterface, consoleElement, memory, eventQueue, event_temp) {
|
||||
function odinSetupDefaultImports(wasmMemoryInterface, consoleElement, memory) {
|
||||
const MAX_INFO_CONSOLE_LINES = 512;
|
||||
let infoConsoleLines = new Array();
|
||||
let currentLine = {};
|
||||
currentLine[false] = "";
|
||||
currentLine[true] = "";
|
||||
let prevIsError = false;
|
||||
|
||||
let event_temp = {};
|
||||
|
||||
const onEventReceived = (event_data, data, callback) => {
|
||||
event_temp.data = event_data;
|
||||
|
||||
const exports = wasmMemoryInterface.exports;
|
||||
const odin_ctx = exports.default_context_ptr();
|
||||
|
||||
exports.odin_dom_do_event_callback(data, callback, odin_ctx);
|
||||
|
||||
event_temp.data = null;
|
||||
};
|
||||
|
||||
const writeToConsole = (line, isError) => {
|
||||
if (!line) {
|
||||
@@ -1535,8 +1548,8 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement, memory, ev
|
||||
|
||||
wmi.storeInt(off(W, W), e.key.length)
|
||||
wmi.storeInt(off(W, W), e.code.length)
|
||||
wmi.storeString(off(16, 1), e.key);
|
||||
wmi.storeString(off(16, 1), e.code);
|
||||
wmi.storeString(off(32, 1), e.key);
|
||||
wmi.storeString(off(32, 1), e.code);
|
||||
} else if (e.type === 'scroll') {
|
||||
wmi.storeF64(off(8, 8), window.scrollX);
|
||||
wmi.storeF64(off(8, 8), window.scrollY);
|
||||
@@ -1594,7 +1607,7 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement, memory, ev
|
||||
event_data.event = e;
|
||||
event_data.name_code = name_code;
|
||||
|
||||
eventQueue.push({event_data: event_data, data: data, callback: callback});
|
||||
onEventReceived(event_data, data, callback);
|
||||
};
|
||||
wasmMemoryInterface.listenerMap[{data: data, callback: callback}] = listener;
|
||||
element.addEventListener(name, listener, !!use_capture);
|
||||
@@ -1611,7 +1624,7 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement, memory, ev
|
||||
event_data.event = e;
|
||||
event_data.name_code = name_code;
|
||||
|
||||
eventQueue.push({event_data: event_data, data: data, callback: callback});
|
||||
onEventReceived(event_data, data, callback);
|
||||
};
|
||||
wasmMemoryInterface.listenerMap[{data: data, callback: callback}] = listener;
|
||||
element.addEventListener(name, listener, !!use_capture);
|
||||
@@ -1802,6 +1815,16 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement, memory, ev
|
||||
}
|
||||
},
|
||||
|
||||
set_element_style: (id_ptr, id_len, key_ptr, key_len, value_ptr, value_len) => {
|
||||
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
||||
let key = wasmMemoryInterface.loadString(key_ptr, key_len);
|
||||
let value = wasmMemoryInterface.loadString(value_ptr, value_len);
|
||||
let element = getElement(id);
|
||||
if (element) {
|
||||
element.style[key] = value;
|
||||
}
|
||||
},
|
||||
|
||||
get_element_key_f64: (id_ptr, id_len, key_ptr, key_len) => {
|
||||
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
||||
let key = wasmMemoryInterface.loadString(key_ptr, key_len);
|
||||
@@ -1905,10 +1928,7 @@ async function runWasm(wasmPath, consoleElement, extraForeignImports, wasmMemory
|
||||
}
|
||||
wasmMemoryInterface.setIntSize(intSize);
|
||||
|
||||
let eventQueue = new Array();
|
||||
let event_temp = {};
|
||||
|
||||
let imports = odinSetupDefaultImports(wasmMemoryInterface, consoleElement, wasmMemoryInterface.memory, eventQueue, event_temp);
|
||||
let imports = odinSetupDefaultImports(wasmMemoryInterface, consoleElement, wasmMemoryInterface.memory);
|
||||
let exports = {};
|
||||
|
||||
if (extraForeignImports !== undefined) {
|
||||
@@ -1948,13 +1968,6 @@ async function runWasm(wasmPath, consoleElement, extraForeignImports, wasmMemory
|
||||
const dt = (currTimeStamp - prevTimeStamp)*0.001;
|
||||
prevTimeStamp = currTimeStamp;
|
||||
|
||||
while (eventQueue.length > 0) {
|
||||
let e = eventQueue.shift()
|
||||
event_temp.data = e.event_data;
|
||||
exports.odin_dom_do_event_callback(e.data, e.callback, odin_ctx);
|
||||
}
|
||||
event_temp.data = null;
|
||||
|
||||
if (!exports.step(dt, odin_ctx)) {
|
||||
exports._end();
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#+build windows
|
||||
package sys_windows
|
||||
|
||||
foreign import "system:icu.lib"
|
||||
|
||||
UError :: enum i32 {
|
||||
U_ZERO_ERROR = 0,
|
||||
}
|
||||
|
||||
@(default_calling_convention="system")
|
||||
foreign icu {
|
||||
ucal_getWindowsTimeZoneID :: proc(id: wstring, len: i32, winid: wstring, winidCapacity: i32, status: ^UError) -> i32 ---
|
||||
ucal_getDefaultTimeZone :: proc(result: wstring, cap: i32, status: ^UError) -> i32 ---
|
||||
}
|
||||
@@ -4545,7 +4545,7 @@ DNS_RECORD :: struct { // aka DNS_RECORDA
|
||||
Flags: DWORD,
|
||||
dwTtl: DWORD,
|
||||
_: DWORD,
|
||||
Data: struct #raw_union {
|
||||
Data: struct #raw_union #align(4) {
|
||||
CNAME: DNS_PTR_DATAA,
|
||||
A: u32be, // Ipv4 Address
|
||||
AAAA: u128be, // Ipv6 Address
|
||||
|
||||
@@ -51,6 +51,7 @@ foreign user32 {
|
||||
IsWindowVisible :: proc(hwnd: HWND) -> BOOL ---
|
||||
IsWindowEnabled :: proc(hwnd: HWND) -> BOOL ---
|
||||
IsIconic :: proc(hwnd: HWND) -> BOOL ---
|
||||
IsZoomed :: proc(hwnd: HWND) -> BOOL ---
|
||||
BringWindowToTop :: proc(hWnd: HWND) -> BOOL ---
|
||||
GetTopWindow :: proc(hWnd: HWND) -> HWND ---
|
||||
SetForegroundWindow :: proc(hWnd: HWND) -> BOOL ---
|
||||
@@ -548,7 +549,7 @@ RI_KEY_TERMSRV_SHADOW :: 0x10
|
||||
MOUSE_MOVE_RELATIVE :: 0x00
|
||||
MOUSE_MOVE_ABSOLUTE :: 0x01
|
||||
MOUSE_VIRTUAL_DESKTOP :: 0x02
|
||||
MOUSE_ATTRIUBTTES_CHANGED :: 0x04
|
||||
MOUSE_ATTRIBUTES_CHANGED :: 0x04
|
||||
MOUSE_MOVE_NOCOALESCE :: 0x08
|
||||
|
||||
RI_MOUSE_BUTTON_1_DOWN :: 0x0001
|
||||
@@ -781,3 +782,64 @@ CF_GDIOBJLAST :: 0x03FF
|
||||
CF_OWNERDISPLAY :: 0x0080
|
||||
CF_PRIVATEFIRST :: 0x0200
|
||||
CF_PRIVATELAST :: 0x02FF
|
||||
|
||||
STICKYKEYS :: struct {
|
||||
cbSize: UINT,
|
||||
dwFlags: DWORD,
|
||||
}
|
||||
LPSTICKYKEYS :: ^STICKYKEYS
|
||||
|
||||
SKF_STICKYKEYSON :: 0x1
|
||||
SKF_AVAILABLE :: 0x2
|
||||
SKF_HOTKEYACTIVE :: 0x4
|
||||
SKF_CONFIRMHOTKEY :: 0x8
|
||||
SKF_HOTKEYSOUND :: 0x10
|
||||
SKF_INDICATOR :: 0x20
|
||||
SKF_AUDIBLEFEEDBACK :: 0x40
|
||||
SKF_TRISTATE :: 0x80
|
||||
SKF_TWOKEYSOFF :: 0x100
|
||||
SKF_LSHIFTLOCKED :: 0x10000
|
||||
SKF_RSHIFTLOCKED :: 0x20000
|
||||
SKF_LCTLLOCKED :: 0x40000
|
||||
SKF_RCTLLOCKED :: 0x80000
|
||||
SKF_LALTLOCKED :: 0x100000
|
||||
SKF_RALTLOCKED :: 0x200000
|
||||
SKF_LWINLOCKED :: 0x400000
|
||||
SKF_RWINLOCKED :: 0x800000
|
||||
SKF_LSHIFTLATCHED :: 0x1000000
|
||||
SKF_RSHIFTLATCHED :: 0x2000000
|
||||
SKF_LCTLLATCHED :: 0x4000000
|
||||
SKF_RCTLLATCHED :: 0x8000000
|
||||
SKF_LALTLATCHED :: 0x10000000
|
||||
SKF_RALTLATCHED :: 0x20000000
|
||||
|
||||
TOGGLEKEYS :: struct {
|
||||
cbSize: UINT,
|
||||
dwFlags: DWORD,
|
||||
}
|
||||
LPTOGGLEKEYS :: ^TOGGLEKEYS
|
||||
|
||||
TKF_TOGGLEKEYSON :: 0x1
|
||||
TKF_AVAILABLE :: 0x2
|
||||
TKF_HOTKEYACTIVE :: 0x4
|
||||
TKF_CONFIRMHOTKEY :: 0x8
|
||||
TKF_HOTKEYSOUND :: 0x10
|
||||
TKF_INDICATOR :: 0x20
|
||||
|
||||
FILTERKEYS :: struct {
|
||||
cbSize: UINT,
|
||||
dwFlags: DWORD,
|
||||
iWaitMSec: DWORD,
|
||||
iDelayMSec: DWORD,
|
||||
iRepeatMSec: DWORD,
|
||||
iBounceMSec: DWORD,
|
||||
}
|
||||
LPFILTERKEYS :: ^FILTERKEYS
|
||||
|
||||
FKF_FILTERKEYSON :: 0x1
|
||||
FKF_AVAILABLE :: 0x2
|
||||
FKF_HOTKEYACTIVE :: 0x4
|
||||
FKF_CONFIRMHOTKEY :: 0x8
|
||||
FKF_HOTKEYSOUND :: 0x10
|
||||
FKF_INDICATOR :: 0x20
|
||||
FKF_CLICKON :: 0x40
|
||||
|
||||
@@ -3,7 +3,7 @@ package sys_windows
|
||||
|
||||
foreign import uxtheme "system:UxTheme.lib"
|
||||
|
||||
MARGINS :: distinct [4]int
|
||||
MARGINS :: distinct [4]i32
|
||||
PMARGINS :: ^MARGINS
|
||||
|
||||
@(default_calling_convention="system")
|
||||
|
||||
@@ -251,26 +251,26 @@ SEVERITY :: enum DWORD {
|
||||
// Generic test for success on any status value (non-negative numbers indicate success).
|
||||
SUCCEEDED :: #force_inline proc "contextless" (#any_int result: int) -> bool { return result >= S_OK }
|
||||
// and the inverse
|
||||
FAILED :: #force_inline proc(#any_int result: int) -> bool { return result < S_OK }
|
||||
FAILED :: #force_inline proc "contextless" (#any_int result: int) -> bool { return result < S_OK }
|
||||
|
||||
// Generic test for error on any status value.
|
||||
IS_ERROR :: #force_inline proc(#any_int status: int) -> bool { return u32(status) >> 31 == u32(SEVERITY.ERROR) }
|
||||
IS_ERROR :: #force_inline proc "contextless" (#any_int status: int) -> bool { return u32(status) >> 31 == u32(SEVERITY.ERROR) }
|
||||
|
||||
// Return the code
|
||||
HRESULT_CODE :: #force_inline proc(#any_int hr: int) -> int { return int(u32(hr) & 0xFFFF) }
|
||||
HRESULT_CODE :: #force_inline proc "contextless" (#any_int hr: int) -> int { return int(u32(hr) & 0xFFFF) }
|
||||
|
||||
// Return the facility
|
||||
HRESULT_FACILITY :: #force_inline proc(#any_int hr: int) -> FACILITY { return FACILITY((u32(hr) >> 16) & 0x1FFF) }
|
||||
HRESULT_FACILITY :: #force_inline proc "contextless" (#any_int hr: int) -> FACILITY { return FACILITY((u32(hr) >> 16) & 0x1FFF) }
|
||||
|
||||
// Return the severity
|
||||
HRESULT_SEVERITY :: #force_inline proc(#any_int hr: int) -> SEVERITY { return SEVERITY((u32(hr) >> 31) & 0x1) }
|
||||
HRESULT_SEVERITY :: #force_inline proc "contextless" (#any_int hr: int) -> SEVERITY { return SEVERITY((u32(hr) >> 31) & 0x1) }
|
||||
|
||||
// Create an HRESULT value from component pieces
|
||||
MAKE_HRESULT :: #force_inline proc(#any_int sev: int, #any_int fac: int, #any_int code: int) -> HRESULT {
|
||||
MAKE_HRESULT :: #force_inline proc "contextless" (#any_int sev: int, #any_int fac: int, #any_int code: int) -> HRESULT {
|
||||
return HRESULT((uint(sev)<<31) | (uint(fac)<<16) | (uint(code)))
|
||||
}
|
||||
|
||||
DECODE_HRESULT :: #force_inline proc(#any_int hr: int) -> (SEVERITY, FACILITY, int) {
|
||||
DECODE_HRESULT :: #force_inline proc "contextless" (#any_int hr: int) -> (SEVERITY, FACILITY, int) {
|
||||
return HRESULT_SEVERITY(hr), HRESULT_FACILITY(hr), HRESULT_CODE(hr)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user