getenvW
Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name.
This function performs a Unicode-aware case-insensitive lookup using RtlEqualUnicodeString.
See also:
std.posix.getenvgetEnvMapgetEnvVarOwnedhasEnvVarConstanthasEnvVar
Function parameters
Parameters
- key:[*:0]const u16
Type definitions in this namespace
Types
- ArgIteratorWindows
- Iterator that implements the Windows command-line parsing algorithm.
- ArgIteratorGeneralOptions
- Optional parameters for `ArgIteratorGeneral`
- ArgIterator
- Cross-platform command line argument iterator.
Functions in this namespace
Functions
- getCwd
- The result is a slice of `out_buffer`, from index `0`.
- getCwdAlloc
- Caller must free the returned memory.
- getEnvMap
- Returns a snapshot of the environment variables of the current process.
- getEnvVarOwned
- Caller must free returned memory.
- hasEnvVarConstant
- On Windows, `key` must be valid WTF-8.
- hasNonEmptyEnvVarConstant
- On Windows, `key` must be valid WTF-8.
- parseEnvVarInt
- Parses an environment variable as an integer.
- hasEnvVar
- On Windows, if `key` is not valid [WTF-8](https://simonsapin.github.io/wtf-8/),
- hasNonEmptyEnvVar
- On Windows, if `key` is not valid [WTF-8](https://simonsapin.github.io/wtf-8/),
- getenvW
- Windows-only.
- ArgIteratorGeneral
- A general Iterator to parse a string into a set of arguments
- args
- Holds the command-line arguments, with the program name as the first entry.
- argsWithAllocator
- You must deinitialize iterator's internal buffers by calling `deinit` when done.
- argsAlloc
- Caller must call argsFree on result.
- getUserInfo
- POSIX function which gets a uid from username.
- posixGetUserInfo
- TODO this reads /etc/passwd.
- execv
- Replaces the current process image with the executed process.
- execve
- Replaces the current process image with the executed process.
- totalSystemMemory
- Returns the total system memory, in bytes as a u64.
- cleanExit
- Indicate that we are now terminating with a successful exit code.
- raiseFileDescriptorLimit
- Raise the open file descriptor limit.
- createEnvironFromMap
- Creates a null-delimited environment variable block in the format
- createEnvironFromExisting
- Creates a null-delimited environment variable block in the format
- createWindowsEnvBlock
- Caller must free result.
- fatal
- Logs an error and then terminates the process with exit code 1.
Error sets in this namespace
Error Sets
Tells whether calling the `execv` or `execve` functions will be a compile error.
Values
Source
Implementation
pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
if (native_os != .windows) {
@compileError("Windows-only");
}
const key_slice = mem.sliceTo(key, 0);
// '=' anywhere but the start makes this an invalid environment variable name
if (key_slice.len > 0 and std.mem.indexOfScalar(u16, key_slice[1..], '=') != null) {
return null;
}
const ptr = windows.peb().ProcessParameters.Environment;
var i: usize = 0;
while (ptr[i] != 0) {
const key_value = mem.sliceTo(ptr[i..], 0);
// There are some special environment variables that start with =,
// so we need a special case to not treat = as a key/value separator
// if it's the first character.
// https://devblogs.microsoft.com/oldnewthing/20100506-00/?p=14133
const equal_search_start: usize = if (key_value[0] == '=') 1 else 0;
const equal_index = std.mem.indexOfScalarPos(u16, key_value, equal_search_start, '=') orelse {
// This is enforced by CreateProcess.
// If violated, CreateProcess will fail with INVALID_PARAMETER.
unreachable; // must contain a =
};
const this_key = key_value[0..equal_index];
if (windows.eqlIgnoreCaseWTF16(key_slice, this_key)) {
return key_value[equal_index + 1 ..];
}
// skip past the NUL terminator
i += key_value.len + 1;
}
return null;
}