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

Function strftime_ascii

crates/vm/src/stdlib/time.rs:656–676  ·  view source on GitHub ↗
(fmt: &str, tm: &libc::tm, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

654
655 #[cfg(unix)]
656 fn strftime_ascii(fmt: &str, tm: &libc::tm, vm: &VirtualMachine) -> PyResult<String> {
657 let fmt_c =
658 CString::new(fmt).map_err(|_| vm.new_value_error("embedded null character"))?;
659 let mut size = 1024usize;
660 let max_scale = 256usize.saturating_mul(fmt.len().max(1));
661 loop {
662 let mut out = vec![0u8; size];
663 let written = unsafe {
664 libc::strftime(
665 out.as_mut_ptr().cast(),
666 out.len(),
667 fmt_c.as_ptr(),
668 tm as *const libc::tm,
669 )
670 };
671 if written > 0 || size >= max_scale {
672 return Ok(String::from_utf8_lossy(&out[..written]).into_owned());
673 }
674 size = size.saturating_mul(2);
675 }
676 }
677
678 #[cfg(windows)]
679 fn strftime_ascii(fmt: &str, tm: &libc::tm, vm: &VirtualMachine) -> PyResult<String> {

Callers 1

strftime_crtFunction · 0.85

Calls 13

newFunction · 0.85
strftimeFunction · 0.85
onceFunction · 0.85
as_mut_ptrMethod · 0.80
into_ownedMethod · 0.80
collectMethod · 0.80
chainMethod · 0.80
ErrClass · 0.50
maxMethod · 0.45
lenMethod · 0.45
castMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected