MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / _readlink

Function _readlink

src/fs/abs.rs:119–139  ·  view source on GitHub ↗
(path: &CStr, mut buffer: Vec<u8>)

Source from the content-addressed store, hash-verified

117
118#[cfg(feature = "alloc")]
119fn _readlink(path: &CStr, mut buffer: Vec<u8>) -> io::Result<CString> {
120 // This code would benefit from having a better way to read into
121 // uninitialized memory, but that requires `unsafe`.
122 buffer.clear();
123 buffer.reserve(SMALL_PATH_BUFFER_SIZE);
124 buffer.resize(buffer.capacity(), 0_u8);
125
126 loop {
127 let nread = backend::fs::syscalls::readlink(path, &mut buffer)?;
128
129 let nread = nread as usize;
130 assert!(nread <= buffer.len());
131 if nread < buffer.len() {
132 buffer.resize(nread, 0_u8);
133 return Ok(CString::new(buffer).unwrap());
134 }
135 // Use `Vec` reallocation strategy to grow capacity exponentially.
136 buffer.reserve(1);
137 buffer.resize(buffer.capacity(), 0_u8);
138 }
139}
140
141/// `rename(old_path, new_path)`—Renames a file or directory.
142///

Callers 1

readlinkFunction · 0.85

Calls 3

readlinkFunction · 0.70
clearMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected