MCPcopy Index your code
hub / github.com/RustPython/RustPython / _getvolumepathname

Function _getvolumepathname

crates/vm/src/stdlib/nt.rs:1376–1392  ·  view source on GitHub ↗
(path: OsPath, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1374
1375 #[pyfunction]
1376 fn _getvolumepathname(path: OsPath, vm: &VirtualMachine) -> PyResult {
1377 let wide = path.to_wide_cstring(vm)?;
1378 let buflen = core::cmp::max(wide.len(), Foundation::MAX_PATH as usize);
1379 if buflen > u32::MAX as usize {
1380 return Err(vm.new_overflow_error("path too long"));
1381 }
1382 let mut buffer = vec![0u16; buflen];
1383 let ret = unsafe {
1384 FileSystem::GetVolumePathNameW(wide.as_ptr(), buffer.as_mut_ptr(), buflen as _)
1385 };
1386 if ret == 0 {
1387 let err = io::Error::last_os_error();
1388 return Err(OSErrorBuilder::with_filename(&err, path, vm));
1389 }
1390 let buffer = widestring::WideCString::from_vec_truncate(buffer);
1391 Ok(path.mode().process_path(buffer.to_os_string(), vm))
1392 }
1393
1394 /// Implements _Py_skiproot logic for Windows paths
1395 /// Returns (drive_size, root_size) where:

Callers 1

ismountFunction · 0.90

Calls 8

maxFunction · 0.85
as_mut_ptrMethod · 0.80
process_pathMethod · 0.80
ErrClass · 0.50
to_wide_cstringMethod · 0.45
lenMethod · 0.45
as_ptrMethod · 0.45
modeMethod · 0.45

Tested by

no test coverage detected