Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/uu/date/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
libc = { workspace = true }
rustix = { workspace = true, features = ["time"] }

[target.'cfg(target_env = "ohos")'.dependencies]

Check warning on line 47 in src/uu/date/Cargo.toml

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'ohos' (file:'src/uu/date/Cargo.toml', line:47)
# OHOS has no /usr/share/zoneinfo or /etc/localtime: embed IANA tzdata so

Check warning on line 48 in src/uu/date/Cargo.toml

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'tzdata' (file:'src/uu/date/Cargo.toml', line:48)

Check warning on line 48 in src/uu/date/Cargo.toml

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'OHOS' (file:'src/uu/date/Cargo.toml', line:48)
# ohos_system_zone() can resolve the TimeService timezone ID directly (pass-through,

Check warning on line 49 in src/uu/date/Cargo.toml

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'ohos' (file:'src/uu/date/Cargo.toml', line:49)
# no environment injection).
jiff-tzdb = "0.1"

[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = [
"Win32_Foundation",
Expand Down
45 changes: 44 additions & 1 deletion src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,36 @@

use uucore::parser::shortcut_value_parser::ShortcutValueParser;

/// OHOS helper: pass through the system time zone ID returned by

Check warning on line 35 in src/uu/date/src/date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'OHOS' (file:'src/uu/date/src/date.rs', line:35)
/// TimeService (OH_TimeService_GetTimeZone, e.g. "Asia/Shanghai") and
/// resolve it against the embedded IANA tzdata (jiff-tzdb) so that

Check warning on line 37 in src/uu/date/src/date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'tzdb' (file:'src/uu/date/src/date.rs', line:37)

Check warning on line 37 in src/uu/date/src/date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'tzdata' (file:'src/uu/date/src/date.rs', line:37)
/// historial DST rules and transitions are preserved. jiff's

Check warning on line 38 in src/uu/date/src/date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'historial' (file:'src/uu/date/src/date.rs', line:38)
/// `try_system()` is useless on OHOS because both `/etc/localtime` and

Check warning on line 39 in src/uu/date/src/date.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'OHOS' (file:'src/uu/date/src/date.rs', line:39)
/// the zoneinfo dirs are absent.
#[cfg(target_env = "ohos")]
fn ohos_system_zone() -> jiff::tz::TimeZone {
use core::ffi::{CStr, c_char};

#[link(name = "time_service_ndk")]
unsafe extern "C" {
fn OH_TimeService_GetTimeZone(tz: *mut c_char, len: u32) -> i32;
}
let mut buf = [0u8; 64];
let rc = unsafe { OH_TimeService_GetTimeZone(buf.as_mut_ptr() as *mut c_char, 64) };
if rc != 0 {
return jiff::tz::TimeZone::UTC;
}
let id = unsafe { CStr::from_ptr(buf.as_ptr() as *const c_char) }
.to_string_lossy()
.into_owned();
if let Some((name, tzif)) = jiff_tzdb::get(&id) {
if let Ok(tz) = jiff::tz::TimeZone::tzif(name, tzif) {
return tz;
}
}
jiff::tz::TimeZone::UTC
}

// Options
const DATE: &str = "date";
const HOURS: &str = "hours";
Expand Down Expand Up @@ -371,7 +401,14 @@
let now = if utc {
Timestamp::now().to_zoned(TimeZone::UTC)
} else {
Zoned::now()
#[cfg(target_env = "ohos")]
{
Timestamp::now().to_zoned(ohos_system_zone())
}
#[cfg(not(target_env = "ohos"))]
{
Zoned::now()
}
};

let set_to = match matches.get_one::<String>(OPT_SET) {
Expand Down Expand Up @@ -557,12 +594,18 @@
translate!("date-error-cannot-set-date", "path" => path.quote(), "error" => e),
)
})?;
#[cfg(target_env = "ohos")]
let date = ts.to_zoned(ohos_system_zone());
#[cfg(not(target_env = "ohos"))]
let date = ts.to_zoned(TimeZone::try_system().unwrap_or(TimeZone::UTC));
let iter = std::iter::once(Ok(ParsedDateTime::InRange(date)));
Box::new(iter)
}
DateSource::Resolution => {
let resolution = get_clock_resolution();
#[cfg(target_env = "ohos")]
let date = resolution.to_zoned(ohos_system_zone());
#[cfg(not(target_env = "ohos"))]
let date = resolution.to_zoned(TimeZone::system());
let iter = std::iter::once(Ok(ParsedDateTime::InRange(date)));
Box::new(iter)
Expand Down
25 changes: 25 additions & 0 deletions src/uu/hostid/src/hostid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,37 @@

use clap::Command;
use core::ffi::c_long;
#[cfg(not(target_env = "ohos"))]
use libc::gethostid;
use std::io::{Write, stdout};
use uucore::{error::UResult, format_usage};

use uucore::translate;

// OHOS SDK libc no longer exports gethostid; replicate the glibc semantics:
// read /etc/hostid when present, otherwise hash the hostname.
#[cfg(target_env = "ohos")]
fn gethostid() -> c_long {
use std::fs::read;
if let Ok(data) = read("/etc/hostid") {
if data.len() >= 4 {
let n: u32 = u32::from_ne_bytes([data[0], data[1], data[2], data[3]]);
return n as c_long;
}
}
let mut name = [0u8; 256];
if unsafe { libc::gethostname(name.as_mut_ptr() as *mut _, name.len()) } == 0 {
let end = name.iter().position(|&b| b == 0).unwrap_or(name.len());
let mut h: u32 = 0x811c9dc5;
for &b in &name[..end] {
h ^= b as u32;
h = h.wrapping_mul(0x01000193);
}
return h as c_long;
}
0
}

#[uucore::main(no_signals)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
uucore::clap_localization::handle_clap_result(uu_app(), args)?;
Expand Down
5 changes: 3 additions & 2 deletions src/uucore/src/lib/features/fsext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ impl FsMeta for StatFs {
))]
fn fs_type(&self) -> i64 {
#[cfg(all(
not(target_env = "musl"),
not(any(target_env = "musl", target_env = "ohos")),
not(target_vendor = "apple"),
not(target_os = "android"),
not(target_os = "freebsd"),
Expand All @@ -808,7 +808,7 @@ impl FsMeta for StatFs {
))]
return self.f_type;
#[cfg(all(
not(target_env = "musl"),
not(any(target_env = "musl", target_env = "ohos")),
any(
target_vendor = "apple",
all(target_os = "android", target_pointer_width = "32"),
Expand All @@ -820,6 +820,7 @@ impl FsMeta for StatFs {
return self.f_type.into();
#[cfg(any(
target_env = "musl",
target_env = "ohos",
all(target_os = "android", target_pointer_width = "64"),
))]
return self.f_type.try_into().unwrap();
Expand Down
Loading