aboutsummaryrefslogtreecommitdiff
path: root/core/os/errors.odin
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2025-06-15 16:31:54 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2025-06-16 20:12:26 +0200
commit1a2f83f1235039b6bad43d9e697cc4b2f0fb2b60 (patch)
tree3f2acb923ea254a632170dfe30a75f2f31db5d2a /core/os/errors.odin
parent1bd48df41febbcf0f903fdfc697f59527b03bbe9 (diff)
Add bring-your-own-buffer versions of `os.lookup_env` and `os.get_env`
And make `core:terminal` use it so that `core:log` can be imported with `-default-to-nil-allocator`, in which the actual allocator is set up in `main()`. Windows was tricky because of the utf-8 <> utf-16 conversion, so we use some temporary stack buffers for that purpose, limiting the non-allocating version there to 512 utf-16 characters each for the key and environment value. In general the value is (obviously) limited to the size of the supplied buffer, and a `.Buffer_Full` error is returned if that buffer is insufficient. If the key is not found, the procedure returns `.Env_Var_Not_Found`. TODO: - Factor out buffer-backed utf8 + utf16 conversion to `core:sys/util` to more easily apply this pattern. - Add similar `lookup_env` and `get_env` procedures to `core:os/os2`. Fixes #5336
Diffstat (limited to 'core/os/errors.odin')
-rw-r--r--core/os/errors.odin4
1 files changed, 4 insertions, 0 deletions
diff --git a/core/os/errors.odin b/core/os/errors.odin
index 691397f4b..bf4cf27ff 100644
--- a/core/os/errors.odin
+++ b/core/os/errors.odin
@@ -35,6 +35,9 @@ General_Error :: enum u32 {
File_Is_Pipe,
Not_Dir,
+
+ // Environment variable not found.
+ Env_Var_Not_Found,
}
@@ -82,6 +85,7 @@ error_string :: proc "contextless" (ferr: Error) -> string {
case .Pattern_Has_Separator: return "pattern has separator"
case .File_Is_Pipe: return "file is pipe"
case .Not_Dir: return "file is not directory"
+ case .Env_Var_Not_Found: return "environment variable not found"
}
case io.Error:
switch e {