OS family the binary was compiled for. "linux", "windows", "macos", "freebsd", "openbsd", "netbsd", or "unknown".
if os_name().eq("linux") { /* linux-only path */ }
defined in C:\Users\bye45\.glide\bin/src/stdlib/os.glide
OS family the binary was compiled for. `"linux"`, `"windows"`, `"macos"`,
OS family the binary was compiled for. "linux", "windows", "macos", "freebsd", "openbsd", "netbsd", or "unknown".
if os_name().eq("linux") { /* linux-only path */ }
CPU architecture: "x86_64", "aarch64", "arm", "x86", "riscv64", or "unknown". Reflects the build target.
println!("running on", os_arch()); // e.g. "running on x86_64"
true on Windows, false everywhere else.
if os_is_windows() { use_crlf(); } else { use_lf(); }
true on POSIX-y systems (Linux, macOS, *BSD), false on Windows.
if os_is_posix() { send_signal(); }
true only on Linux.
if os_is_linux() { read_proc_meminfo(); }
true only on macOS / Darwin. os_is_posix() is also true.
if os_is_macos() { open_url_via("open"); }
Path component separator: \\ on Windows, / elsewhere.
let full: string = format!("{}{}{}", base, os_path_sep(), name);
Line ending convention: "\r\n" on Windows, "\n" elsewhere.
let line: string = format!("hello{}", os_line_sep());
PATH-list separator: ; on Windows, : elsewhere. Use this when parsing $PATH / %PATH%.
let path: string = env_get("PATH");
let dirs: *Vector<string> = path.split(os_path_list_sep());
Current process ID. Always returns a positive value; getpid never fails.
println!("pid:", os_pid());
Parent process ID. POSIX returns getppid(); on Windows, returns Err("ppid not available") because the API doesn't expose it cheaply.
let r: !int = os_ppid();
if r.ok { println!("parent:", r.val); }
POSIX user ID. Err on Windows (no numeric UID concept).
let u: !int = os_uid();
if u.ok && u.val == 0 { println!("running as root"); }
POSIX group ID. Err on Windows.
let g: !int = os_gid();
if g.ok { println!("gid:", g.val); }
Login name of the current user. POSIX checks $USER then getpwuid; Windows uses GetUserNameA.
let r: !string = os_username();
if r.ok { println!("hello,", r.val); }
Host name (machine name). gethostname() on POSIX, GetComputerNameA on Windows.
let r: !string = os_hostname();
if r.ok { println!("on host", r.val); }
Kernel/OS version string. POSIX returns uname -r (e.g. 5.15.0-91); Windows returns <major>.<minor>.<build>.
let r: !string = os_kernel_version();
if r.ok { println!("kernel:", r.val); }
Current working directory of the process, no trailing separator.
let r: !string = os_cwd();
if r.ok { println!("cwd:", r.val); }
Change the process's working directory. Returns Ok on success, Err on failure (path missing, no permission, etc.). The success branch carries no value — callers just check r.ok.
let r: ! = os_chdir("/tmp");
if !r.ok { eprintln(r.err); }
Absolute path of the running executable.
let r: !string = os_exe_path();
if r.ok { println!("running from:", r.val); }
Directory portion of os_exe_path, without trailing separator.
let r: !string = os_exe_dir();
if r.ok { println!("install dir:", r.val); }
Number of logical CPUs available to the process.
let r: !int = os_cpu_count();
if r.ok { println!(r.val, "threads"); }
Number of physical cores. Falls back to os_cpu_count() when the platform doesn't expose a clean count (e.g. some Linux containers).
let r: !int = os_cpu_count_physical();
if r.ok { println!(r.val, "physical cores"); }
Virtual memory page size in bytes. Typically 4096; can be 16384 on Apple Silicon and some ARM Linux.
let r: !int = os_page_size();
if r.ok { println!("page:", r.val, "bytes"); }
Total physical RAM in bytes.
let r: !u64 = os_memory_total();
if r.ok { println!("RAM:", (r.val / 1024 / 1024) as int, "MiB"); }
Available physical RAM in bytes (snapshot at call time). Best-effort on macOS / BSD where the metric needs mach-specific calls.
let r: !u64 = os_memory_free();
if r.ok { println!("free:", (r.val / 1024 / 1024) as int, "MiB"); }
Seconds since system boot.
let r: !u64 = os_uptime_secs();
if r.ok { println!("up", r.val, "seconds"); }
1-minute load average. POSIX-only — Err on Windows.
let r: !f64 = os_loadavg_1m();
if r.ok { println!("load:", r.val); }
Per-user temporary dir. POSIX: $TMPDIR or /tmp. Windows: %TEMP%.
let r: !string = os_temp_dir();
if r.ok { fs_write(format!("{}/scratch.txt", r.val), "..."); }
User home directory. POSIX: $HOME (fallback getpwuid->pw_dir). Windows: %USERPROFILE%.
let r: !string = os_home_dir();
if r.ok { println!("home:", r.val); }
Per-user config dir (base — caller appends app name). Linux: $XDG_CONFIG_HOME or ~/.config. macOS: ~/Library/Application Support. Windows: %APPDATA%.
let r: !string = os_config_dir();
if r.ok { fs_read(format!("{}/myapp/cfg.toml", r.val)); }
Per-user cache dir (base). Linux: $XDG_CACHE_HOME or ~/.cache. macOS: ~/Library/Caches. Windows: %LOCALAPPDATA%.
let r: !string = os_cache_dir();
if r.ok { /* write rebuildable artifacts under r.val/myapp/ */ }
Per-user data dir (base). Linux: $XDG_DATA_HOME or ~/.local/share. macOS: ~/Library/Application Support. Windows: %APPDATA%.
let r: !string = os_data_dir();
if r.ok { /* persistent state under r.val/myapp/ */ }
true if the descriptor is a terminal. fd: 0=stdin, 1=stdout, 2=stderr. Use this before emitting ANSI color escapes — output piped to a file or other process should stay plain.
if os_is_tty(1) { println!("\x1b[32mok\x1b[0m"); }
else { println!("ok"); }
Run cmd through the OS shell (cmd /c on Windows, /bin/sh -c elsewhere). Returns Ok(exit_code) (0 = success) or Err if the shell itself failed to launch. Output streams are inherited; capture requires shell-level redirection in the command string.
**Prefer stdlib::process::Command** for anything beyond a one-liner: it gives argv-level control, captured stdout/stderr, env override, cwd, stdin piping, and avoids shell-injection hazards. os_shell stays as a 1-liner convenience for trivial cases (os_shell("ls -la > out")).
let r: !int = os_shell("ls -la");
if r.ok { println!("exited", r.val); }