Skip to content

Add safe rules for time#260

Merged
nunoplopes merged 11 commits into
Cpp2Rust:masterfrom
lucic71:sys_time
Jul 18, 2026
Merged

Add safe rules for time#260
nunoplopes merged 11 commits into
Cpp2Rust:masterfrom
lucic71:sys_time

Conversation

@lucic71

@lucic71 lucic71 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

This also adds a new dependency called jiff. jiff is used to avoid manually implementing strftime and localtime_r

In general, nix only contains safe wrappers over syscalls. Everything which is a pure library implementation is not included

@lucic71
lucic71 marked this pull request as draft July 16, 2026 19:34
@lucic71
lucic71 marked this pull request as ready for review July 16, 2026 20:59
}
}

#[cfg(target_os = "linux")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the implementation seems to be the same in linux and mac; why do we need both?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the signature is different between linux and macos. Linux receives a struct timezone pointer, macos receives a void pointer:

https://man7.org/linux/man-pages/man2/gettimeofday.2.html
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/gettimeofday.2.html

}

#[cfg(target_os = "linux")]
fn f8(a0: Ptr<Timeval>, a1: Ptr<::libc::timezone>) -> i32 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this 2nd parameter?

}

#[cfg(target_os = "macos")]
fn f8(a0: Ptr<Timeval>, a1: AnyPtr) -> i32 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is ignoring the 2nd parameter. At least it should have a TODO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both man pages (linux and macos) say that the second param is obsolete. I will add a comment about that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment about that

Comment thread rules/time/tgt_refcount.rs Outdated
*__tm.tm_yday.borrow_mut() = __dt.day_of_year() as i32 - 1;
*__tm.tm_isdst.borrow_mut() = 0;
*__tm.tm_gmtoff.borrow_mut() = 0;
*__tm.tm_zone.borrow_mut() = Ptr::from_string_literal(b"GMT");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be UTC

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's GMT on linux and UTC on macos

@nunoplopes
nunoplopes merged commit 3eaeae0 into Cpp2Rust:master Jul 18, 2026
9 checks passed
@lucic71
lucic71 deleted the sys_time branch July 18, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants