Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AIX operating system #57

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
}
}
}