Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std(os/windows): Add GetTempPathW and GetTempPath #16005

Closed
wants to merge 2 commits into from

Conversation

abhinav
Copy link
Contributor

@abhinav abhinav commented Jun 11, 2023

This change adds a kernel32.GetTempPathW binding to GetTempPathW.
This function returns the system path for temporary directories
(e.g. "C:\Temp").

The accompanying windows.GetTempPath function produces a UTF-8 string,
exposing an API with a similar pattern to GetCurrentDirectory.

This change adds a kernel32.GetTempPathW binding to [GetTempPathW][1].
This function returns the system path for temporary directories
(e.g. 'C:\Temp\').

[1]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppathw

The accompanying windows.GetTempPath function produces a UTF-8 string,
exposing an API with a similar pattern to GetCurrentDirectory.
GetCurrentDirectory and GetTempPath duplicate the same logic
to convert a UTF-16LE encoded string into a UTF-8 encoded string.

Extract this logic into a function and reuse it in both places.
@squeek502
Copy link
Collaborator

Just a heads up: this is unlikely to be merged unless there's a use-case within the standard library or the Zig compiler source code.

Relevant issues:

Note also that this does not have to be part of the standard library for you to be able to use it. This:

pub extern "kernel32" fn GetTempPathW(
    nBufferLength: u32,
    lpBuffer: [*]u16,
) callconv(WINAPI) u32;

can go in your project's source and it'll work just fine.

@abhinav
Copy link
Contributor Author

abhinav commented Jun 11, 2023

Note also that this does not have to be part of the standard library for you to be able to use it.

Ah, thanks for verifying. I suspected this but didn't have an easy way to verify it.

Yeah, it makes sense if the Windows bindings are limited to things std needs.
I can imagine a need for this and a unix analog in the future, but this PR can be closed meanwhile.

@abhinav abhinav closed this Jun 11, 2023
@abhinav abhinav deleted the win-gettemppath branch June 16, 2023 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants