Function realpath_ext::normpath_raw [−][src]
pub fn normpath_raw(path: &[u8], buf: &mut [u8]) -> Result<usize, i32>
“Normalize” the given path.
Other than the differences described below, the path
and buf
arguments to this function,
and the return values, have the same meaning as for realpath_raw()
.
This function was designed after Python’s os.path.normpath()
. It will remove .
elements,
condense extra slashes, and collapse ..
entries. Think of it as a version of
realpath_raw()
that doesn’t actually touch the filesystem. (As a consequence of this, if
the given path
is relative, the returned path will also be relative.)
Note that because this function doesn’t actually touch the filesystem, the returned path may
not refer to the correct file! Certain combinations of ..
and/or symbolic links can cause
this; the only way to get the definitive canonicalized path is to use realpath_raw()
.
Example usage:
let mut buf = [0; libc::PATH_MAX as usize]; let n = normpath_raw(b"/a/b/./c/../", &mut buf).unwrap(); assert_eq!(&buf[..n], b"/a/b");
Errors
This function may fail with the following errors:
ENAMETOOLONG
: The givenbuf
is not long enough to store the normalized path.ENOENT
: The givenpath
is empty.EINVAL
: The givenpath
contains a NUL byte (not allowed in *nix paths).