OS
Module os
import os
| Module | os |
| Source | os/module-docs.zirr, os/shim.zirr |
The only module that talks to the machine.
os is the seam between a program and its host. Everything the outside world provides — the standard streams, the environment, the command line, the real filesystem, the real clocks, the host’s randomness — enters here and nowhere else.
That is what makes the rest testable. A function that takes a fs.FileSystem, a clock.SystemClock or a random.Source can be handed fs.memory, clock.fixed or random.seeded in a test; a function that calls os.fs() itself cannot. Take the capability as a parameter and let the entry point reach for os.
Dependencies
Contents
- Functions —
args,cwd,env,exit,fastRandom,fs,monotonicClock,stderr,stdin,stdout,strongRandom,systemClock
Functions
args
`os/shim.zirr:24`
extern fn args() -> [String]
Returns the command line arguments as an array of strings.
cwd
`os/shim.zirr:31`
extern fn cwd() -> String
Returns the directory the process is running in, as an absolute path.
The filesystem os.fs returns is rooted at the host’s own root, so this is what a path written relative to where the program was started has to be joined onto.
env
`os/shim.zirr:21`
extern fn env(key: String) -> String
Returns the value of the environment variable with the given key.
exit
`os/shim.zirr:18`
extern fn exit(code: Int) -> Void
Terminates the process with the given exit code.
fastRandom
`os/shim.zirr:34`
extern fn fastRandom() -> random.Source
A fast generator seeded from the clock. Suitable for simulations and sampling, never for secrets.
fs
`os/shim.zirr:27`
extern fn fs() -> fs.FileSystem
Returns the host’s own filesystem, rooted so that absolute paths resolve as written.
monotonicClock
`os/shim.zirr:48`
fn monotonicClock() -> clock.MonotonicClock
The host’s monotonic clock, which only moves forward and is the one to measure elapsed time with.
stderr
`os/shim.zirr:15`
extern fn stderr() -> @io.Writer
Returns a Writer for the standard error stream.
stdin
`os/shim.zirr:12`
extern fn stdin() -> @io.Reader
Returns a Reader for the standard input stream.
stdout
`os/shim.zirr:9`
extern fn stdout() -> @io.Writer
Returns a Writer for the standard output stream.
strongRandom
`os/shim.zirr:37`
extern fn strongRandom() -> random.Source
The host’s cryptographic generator. Slower, and the only one to use for tokens, keys or anything an adversary should not predict.
systemClock
`os/shim.zirr:43`
fn systemClock() -> clock.SystemClock
The host’s wall clock, which reports civil time and can jump when the machine is corrected.