OXYGENHUB
◆ v0.11.0 oxygen / vendor / iana-time-zone / src / tz_android.rs
936 B · Rust · last changed Strata: the cloud stores send through ureq, so every release target links 1 month ago source blame history raw
1
use std::sync::Once;
2
3
use android_system_properties::AndroidSystemProperties;
4
5
use crate::ffi_utils::android_timezone_property_name;
6
7
pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
8
    let key = android_timezone_property_name();
9
10
    get_properties()
11
        .and_then(|properties| properties.get_from_cstr(key))
12
        .ok_or(crate::GetTimezoneError::OsError)
13
}
14
15
fn get_properties() -> Option<&'static AndroidSystemProperties> {
16
    static INITIALIZED: Once = Once::new();
17
    static mut PROPERTIES: Option<AndroidSystemProperties> = None;
18
19
    INITIALIZED.call_once(|| {
20
        let properties = AndroidSystemProperties::new();
21
        // SAFETY: `INITIALIZED` is synchronizing. The variable is only assigned to once.
22
        unsafe { PROPERTIES = Some(properties) };
23
    });
24
25
    // SAFETY: `INITIALIZED` is synchronizing. The variable is only assigned to once.
26
    unsafe { PROPERTIES.as_ref() }
27
}