(fmt: &str, tm: &libc::tm, vm: &VirtualMachine)
| 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> { |
no test coverage detected