chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

View File

@@ -0,0 +1,67 @@
#include <cstddef>
#ifdef __HAIKU__
#include <cstring>
#include <Errors.h>
#include <LocaleRoster.h>
#include <String.h>
#include <TimeZone.h>
extern "C" {
size_t iana_time_zone_haiku_get_tz(char *buf, size_t buf_size) {
try {
static_assert(sizeof(char) == sizeof(uint8_t), "Illegal char size");
if (buf_size == 0) {
return 0;
}
// `BLocaleRoster::Default()` returns a reference to a statically allocated object.
// https://github.com/haiku/haiku/blob/8f16317/src/kits/locale/LocaleRoster.cpp#L143-L147
BLocaleRoster *locale_roster(BLocaleRoster::Default());
if (!locale_roster) {
return 0;
}
BTimeZone tz(NULL, NULL);
if (locale_roster->GetDefaultTimeZone(&tz) != B_OK) {
return 0;
}
BString bname(tz.ID());
int32_t ilength(bname.Length());
if (ilength <= 0) {
return 0;
}
size_t length(ilength);
if (length > buf_size) {
return 0;
}
// BString::String() returns a borrowed string.
// https://www.haiku-os.org/docs/api/classBString.html#ae4fe78b06c8e3310093b80305e14ba87
const char *sname(bname.String());
if (!sname) {
return 0;
}
std::memcpy(buf, sname, length);
return length;
} catch (...) {
return 0;
}
}
} // extern "C"
#else
extern "C" {
size_t iana_time_zone_haiku_get_tz(char *buf, size_t buf_size) { return 0; }
} // extern "C"
#endif

71
vendor/iana-time-zone-haiku/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,71 @@
#![warn(clippy::all)]
#![warn(clippy::cargo)]
#![warn(clippy::undocumented_unsafe_blocks)]
#![allow(unknown_lints)]
#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]
#![warn(rust_2018_idioms)]
#![warn(trivial_casts, trivial_numeric_casts)]
#![warn(unsafe_op_in_unsafe_fn)]
#![warn(unused_qualifications)]
#![warn(variant_size_differences)]
//! # iana-time-zone-haiku
//!
//! [![Crates.io](https://img.shields.io/crates/v/iana-time-zone-haiku.svg)](https://crates.io/crates/iana-time-zone-haiku)
//! [![Documentation](https://docs.rs/iana-time-zone/badge.svg)](https://docs.rs/iana-time-zone/)
//! [![Crate License](https://img.shields.io/crates/l/iana-time-zone-haiku-haiku.svg)](https://crates.io/crates/iana-time-zone-haiku)
//! [![build](https://github.com/strawlab/iana-time-zone/workflows/build/badge.svg?branch=main)](https://github.com/strawlab/iana-time-zone/actions?query=branch%3Amain)
//!
//! [iana-time-zone](https://github.com/strawlab/iana-time-zone) support crate for Haiku OS.
use std::os::raw::c_char;
extern "C" {
fn iana_time_zone_haiku_get_tz(buf: *mut c_char, buf_size: usize) -> usize;
}
/// Get the current IANA time zone as a string.
///
/// On Haiku platforms this function will return [`Some`] with the timezone string
/// or [`None`] if an error occurs. On all other platforms, [`None`] is returned.
///
/// # Examples
///
/// ```
/// let timezone = iana_time_zone_haiku::get_timezone();
/// ```
#[must_use]
pub fn get_timezone() -> Option<String> {
// The longest name in the IANA time zone database is 25 ASCII characters long.
let mut buf = [0u8; 32];
// SAFETY: a valid, aligned, non-NULL pointer and length are given which
// point to a single allocation.
let len = unsafe {
let buf_size = buf.len();
let buf_ptr = buf.as_mut_ptr().cast::<c_char>();
iana_time_zone_haiku_get_tz(buf_ptr, buf_size)
};
// The name should not be empty, or excessively long.
match buf.get(..len)? {
b"" => None,
s => Some(std::str::from_utf8(s).ok()?.to_owned()),
}
}
#[cfg(test)]
mod tests {
#[test]
#[cfg(not(target_os = "haiku"))]
fn test_fallback_on_non_haiku_platforms() {
assert!(super::get_timezone().is_none());
}
#[test]
#[cfg(target_os = "haiku")]
fn test_retrieve_time_zone_on_haiku_platforms() {
let timezone = super::get_timezone().unwrap();
assert!(!timezone.is_empty());
}
}