feat: add dependency

This commit is contained in:
2023-01-20 22:36:19 +08:00
parent 68e8d103b4
commit cf8e579f27
644 changed files with 150099 additions and 14 deletions

View File

@@ -0,0 +1,25 @@
use std::fs::read_link;
pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
// see https://www.cyberciti.biz/faq/openbsd-time-zone-howto/
// This is a backport of the Linux implementation.
// NetBSDs is less than thorough how the softlink should be set up.
const PREFIXES: &[&str] = &[
"/usr/share/zoneinfo/", // absolute path
"../usr/share/zoneinfo/", // relative path
];
let mut s = read_link("/etc/localtime")?
.into_os_string()
.into_string()
.map_err(|_| crate::GetTimezoneError::FailedParsingString)?;
for &prefix in PREFIXES {
if s.starts_with(prefix) {
// Trim to the correct length without allocating.
s.replace_range(..prefix.len(), "");
return Ok(s);
}
}
Err(crate::GetTimezoneError::FailedParsingString)
}