Closed kegesch closed 4 years ago
That would function well on other platforms? Like BSDs and Solaris
BSD yes. Solaris i don't know. But i think this is a basic unix function so it should work.
I was looking at the libc crate to see what platforms expose that function, looks like it's missing on Solaris, OpenBSD and Haiku
Note that libc not exposing it doesn't mean that it doesn't exist on the platform, as example, I filled 2 issues on libc crate to expose utmpx on NetBSD and Solaris, cause they have that structc and methods, but they are not present on libc crate
Alright. OpenBSD at least has a man page for that. I couldn't find anything about Solaris.
I found for illumos: https://illumos.org/man/3c/settimeofday Most of the time their API are the same, so I'm guessing Solaris has it too
I have opened 2 issues on libc crate
Update: I made pull request to add that function on libc, hopefully they will be merged easilly
Update: OpenBSD now expose that function: https://github.com/rust-lang/libc/pull/1548
Update: Solaris/Illumos now expose that function, next libc crate release they will have it
I started working on this since they released a new version. You can have look here
libc
exposes a new type timezone
for each distro. So I don't really know how to use this type which is needed for settimeofday
apart from branching the code for each distro. Maybe you have an idea?timezone
struct usually (e.g. here) has a member that indicates the daylight saving time (which is not trivial to get). Somehow libc
just implements it as an empty struct. Do you have an idea why?Timezone in libc is specifies as a empty enum, probably cause they don't want anyone creating it
Aha, found it, timezone struct is historical and should be just a NULL pointer when calling the functions
As for problem 2, time crate implements a Tm
struct, the represents in a higher level the tm
struct in c, inside it has the thing you wanted. ref: https://docs.rs/time/0.1.42/time/struct.Tm.html
My recommendation is, implement safe abstraction on coreutils_core
and have it as dependency on the crate (note that coreutils_core
re-export time crate)
Okay, thanks a lot. I give it a shot.
Currently
date
is lacking of the ability to set the datetime of the OS. This could be implemented by utilising the Linux functionsettimeofday
.