Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

getAlloc

Public Function
std.process.Environ.getAlloc
pub fn getAlloc(environ: Environ, gpa: Allocator, key: []const u8) GetAllocError![]u8

Caller owns returned memory.

On Windows:

  • If key is not valid WTF-8, then error.InvalidWtf8 is returned.
  • The returned value is encoded as WTF-8.

On other platforms, the value is an opaque sequence of bytes with no particular encoding.

See also:

Params

Errors

OutOfMemory
EnvironmentVariableMissing
InvalidWtf8

On Windows, environment variable keys provided by the user must be valid WTF-8. This error is unreachable if the key is statically known to be valid.

File

process/Environ.zig:713
713
714
715
716
717
718
719
pub fn getAlloc(environ: Environ, gpa: Allocator, key: []const u8) GetAllocError![]u8 {
    if (native_os == .windows and !unicode.wtf8ValidateSlice(key)) return error.InvalidWtf8;
    var map = createMap(environ, gpa) catch return error.OutOfMemory;
    defer map.deinit();
    const val = map.get(key) orelse return error.EnvironmentVariableMissing;
    return gpa.dupe(u8, val);
}