4 use crate::path::{Path, PathBuf, Prefix};
7 pub fn is_sep_byte(b: u8) -> bool {
12 pub fn is_verbatim_sep(b: u8) -> bool {
17 pub fn parse_prefix(_: &OsStr) -> Option<Prefix<'_>> {
21 pub const MAIN_SEP_STR: &str = "/";
22 pub const MAIN_SEP: char = '/';
24 /// Make a POSIX path absolute without changing its semantics.
25 pub(crate) fn absolute(path: &Path) -> io::Result<PathBuf> {
26 // This is mostly a wrapper around collecting `Path::components`, with
27 // exceptions made where this conflicts with the POSIX specification.
28 // See 4.13 Pathname Resolution, IEEE Std 1003.1-2017
29 // https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
31 let mut components = path.components();
32 let path_os = path.as_os_str().bytes();
34 let mut normalized = if path.is_absolute() {
35 // "If a pathname begins with two successive <slash> characters, the
36 // first component following the leading <slash> characters may be
37 // interpreted in an implementation-defined manner, although more than
38 // two leading <slash> characters shall be treated as a single <slash>
40 if path_os.starts_with(b"//") && !path_os.starts_with(b"///") {
49 normalized.extend(components);
51 // "Interfaces using pathname resolution may specify additional constraints
52 // when a pathname that does not name an existing directory contains at
53 // least one non- <slash> character and contains one or more trailing
54 // <slash> characters".
55 // A trailing <slash> is also meaningful if "a symbolic link is
56 // encountered during pathname resolution".
57 if path_os.ends_with(b"/") {