-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.zig
More file actions
28 lines (21 loc) · 658 Bytes
/
add.zig
File metadata and controls
28 lines (21 loc) · 658 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const std = @import("std");
pub fn add(a: u32, b: u32) !u32 {
return a + b + try getExtraVal();
}
const envVarName = "EXTRA_VAL";
fn getExtraVal() !u32 {
// Just a little hack, linking libc wasn't working.
const old = std.os.environ;
defer std.os.environ = old;
std.os.environ = makeSlice();
if (!std.process.hasEnvVarConstant(envVarName)) {
return error.MissingEnvVar;
}
return std.process.parseEnvVarInt(envVarName, u32, 10);
}
extern var environ: [*][*:0]u8;
fn makeSlice() [][*:0]u8 {
var count: usize = 0;
while (@as(?[*:0]u8, environ[count])) |_| : (count += 1) {}
return environ[0..count];
}