Skip to content

Commit

Permalink
Support AIX operating system
Browse files Browse the repository at this point in the history
  • Loading branch information
ecnelises committed Feb 22, 2023
1 parent e418b72 commit 5b7bcc4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -52,6 +52,7 @@ mod ffi_utils;
any(target_os = "illumos", target_os = "solaris"),
path = "tz_illumos.rs"
)]
#[cfg_attr(target_os = "aix", path = "tz_aix.rs")]
#[cfg_attr(target_os = "android", path = "tz_android.rs")]
#[cfg_attr(target_os = "haiku", path = "tz_haiku.rs")]
mod platform;
Expand Down
2 changes: 1 addition & 1 deletion src/platform.rs
Expand Up @@ -5,5 +5,5 @@ pub fn get_timezone_inner() -> std::result::Result<String, crate::GetTimezoneErr
#[cfg(not(feature = "fallback"))]
compile_error!(
"iana-time-zone is currently implemented for Linux, Window, MacOS, FreeBSD, NetBSD, \
OpenBSD, Dragonfly, WebAssembly (browser), iOS, Illumos, Android, Solaris and Haiku.",
OpenBSD, Dragonfly, WebAssembly (browser), iOS, Illumos, Android, AIX, Solaris and Haiku.",
);
26 changes: 26 additions & 0 deletions src/tz_aix.rs
@@ -0,0 +1,26 @@
use std::fs::OpenOptions;
use std::io::{BufRead, BufReader};
use std::env;

pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
env::var("TZ").map_err(|_| crate::GetTimezoneError::OsError)
}

fn read_environment() -> Result<String, crate::GetTimezoneError> {
// https://www.ibm.com/docs/en/aix/7.2?topic=files-environment-file

let file = OpenOptions::new().read(true).open("/etc/environment")?;
let mut reader = BufReader::new(file);
let mut line = String::with_capacity(80);
loop {
line.clear();
let count = reader.read_line(&mut line)?;
if count == 0 {
return Err(crate::GetTimezoneError::FailedParsingString);
} else if line.starts_with("TZ=") {
line.truncate(line.trim_end().len());
line.replace_range(..3, "");
return Ok(line);
}
}
}

0 comments on commit 5b7bcc4

Please sign in to comment.