-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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::path::absolute
#91673
std::path::absolute
#91673
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,3 +260,19 @@ pub(crate) fn maybe_verbatim(path: &Path) -> io::Result<Vec<u16>> { | |
)?; | ||
Ok(path) | ||
} | ||
|
||
/// Make a Windows path absolute. | ||
pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> { | ||
if path.as_os_str().bytes().starts_with(br"\\?\") { | ||
return Ok(path.into()); | ||
} | ||
let path = to_u16s(path)?; | ||
let lpfilename = path.as_ptr(); | ||
fill_utf16_buf( | ||
// SAFETY: `fill_utf16_buf` ensures the `buffer` and `size` are valid. | ||
// `lpfilename` is a pointer to a null terminated string that is not | ||
// invalidated until after `GetFullPathNameW` returns successfully. | ||
|buffer, size| unsafe { c::GetFullPathNameW(lpfilename, size, buffer, ptr::null_mut()) }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work for non There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed it does! The std already does exactly that. Unfortunately the current docs for |
||
super::os2path, | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unix test without dot prefix.
I have tried in darwin. it is wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reporting this. I'll add more tests and fix the dot prefix case.