{"name":"std/sysinfo.nu","source":"// stdlib/std/sysinfo.nu — what machine is this, and how big?\n//\n// The three questions a program asks about its host that are not files\n// and not the environment: the kernel and machine identity (`uname`),\n// the host's name, and how many processors are online.\n//\n// Each of them is unportable in a different way — utsname is a struct\n// whose field width is a kernel constant, the host name is a syscall on\n// POSIX and a Win32 API elsewhere, and the processor count is a sysconf\n// key — so the runtime answers and this module presents.\n//\n//   ( sys_uname_field SYS_SYSNAME )  → ?String   `Linux`\n//   ( sys_hostname )                 → ?String   the node name\n//   ( sys_cpu_count )                → i         online processors, >= 1\n//\n// A `None` means the platform genuinely cannot say (Windows has no\n// utsname; a unikernel has no name to give), never a placeholder.\n// Callers print what they got or fall back visibly — `uname -s` on a\n// machine that will not say prints `unknown`, it does not print `Linux`.\n\n$ `stdlib/core/string.nu`\n\n& `c` @ nurl_uname_field i which → sink s\n\n& `c` @ nurl_cpu_count → i\n\n& `c` @ nurl_available_parallelism → i\n\n: i SYS_SYSNAME 0\n: i SYS_NODENAME 1\n: i SYS_RELEASE 2\n: i SYS_VERSION 3\n: i SYS_MACHINE 4\n\n// One utsname field as an owned String, or None where there is no\n// utsname. `which` is one of the SYS_* constants above.\n@ sys_uname_field i which → ?String {\n    : s raw ( nurl_uname_field which )\n    ? == # i raw 0 { ^ @ ?String { F # String 0 } } {}\n    ^ @ ?String { T ( string_adopt raw ) }\n}\n\n// The host's name — utsname's nodename, which is what `hostname` prints\n// and what `uname -n` reports.\n@ sys_hostname → ?String {\n    ^ ( sys_uname_field SYS_NODENAME )\n}\n\n// Processors online. At least 1 on every target, including a machine\n// that cannot count them, because a caller sizing a thread pool needs a\n// number it can divide by.\n@ sys_cpu_count → i {\n    : i n ( nurl_cpu_count )\n    ^ ? < n 1 1 n\n}\n\n// How many threads THIS PROCESS can run at once: the affinity mask\n// (taskset / cpuset) capped by a container's cgroup CPU quota — what\n// the fiber scheduler sizes its worker pool by when NURL_WORKERS is\n// unset, and what Rust's available_parallelism() reports. sys_cpu_count\n// is the machine's hardware count regardless of such limits.\n@ sys_available_parallelism → i {\n    : i n ( nurl_available_parallelism )\n    ^ ? > n 0 n 1\n}\n","bytes":2442}