Skip to content

Commit

Permalink
FIXUP: <#54 (review)>
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski committed Aug 15, 2022
1 parent 9454971 commit 8b38556
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/tz_macos.rs
Expand Up @@ -11,19 +11,22 @@ unsafe fn get_timezone() -> Option<String> {
// The longest name in the IANA time zone database is 25 ASCII characters long.
const MAX_LEN: usize = 32;

// Get system time zone, and its name.
// Get system time zone, and borrow its name.
let tz = Dropping::new(CFTimeZoneCopySystem())?;
let name = Dropping::new(CFTimeZoneGetName(tz.0))?;
let name = match CFTimeZoneGetName(tz.0) {
name if !name.is_null() => name,
_ => return None,
};

// Copy the name into the buffer.
let mut buf = [0; MAX_LEN];
let mut buf_bytes = 0;
let range = CFRange {
location: 0,
length: CFStringGetLength(name.0),
length: CFStringGetLength(name),
};
if CFStringGetBytes(
name.0,
name,
range,
kCFStringEncodingUTF8,
b'\0',
Expand Down

0 comments on commit 8b38556

Please sign in to comment.