Skip to content

update std lib to integrate with libc for environ - #4525

Merged
andrewrk merged 4 commits into
masterfrom
environ
Feb 23, 2020
Merged

andrewrk merged 4 commits into
masterfrom
environ

Conversation

@andrewrk

Copy link
Copy Markdown
Member

closes #3511
fixes #4521

std.os.getenv and std.os.getenvZ have nice compile errors when not linking
libc and using Windows.

std.os.getenvW is provided as a Windows-only API that does not require
an allocator. It uses the Process Environment Block.
std.process.getEnvVarOwned is improved to be a simple wrapper on top of
std.os.getenvW.

std.process.getEnvMap is improved to use the Process Environment Block
rather than calling GetEnvironmentVariableW.

std.zig.system.NativePaths uses process.getEnvVarOwned instead of
std.os.getenvZ, which works on Windows as well as POSIX.
@SeekingMeaning

SeekingMeaning commented Feb 23, 2020 •

Copy link
Copy Markdown

Confirmed working for macOS (yay)

Comment thread lib/std/process.zig Outdated
if (builtin.os == .windows) {
const ptr = try os.windows.GetEnvironmentStringsW();
const ptr = os.windows.peb().ProcessParameters.Environment;
defer os.windows.FreeEnvironmentStringsW(ptr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this defer still correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱 no!

@daurnimator daurnimator added the standard library This issue involves writing Zig code for the standard library. label Feb 23, 2020
@andrewrk
andrewrk merged commit d1243bf into master Feb 23, 2020
@andrewrk
andrewrk deleted the environ branch February 23, 2020 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

standard library This issue involves writing Zig code for the standard library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to find libc installation: system C compiler exited with failure code make std.os.environ utilize libc when it is linked

3 participants