@@ -14,3 +14,139 @@ fn t2() -> libcc2rs::Timeval {
1414fn t3 ( ) -> libcc2rs:: Timespec {
1515 Default :: default ( )
1616}
17+
18+ fn f1 ( a0 : Ptr < :: libc:: time_t > ) -> :: libc:: time_t {
19+ let __out = a0;
20+ match nix:: time:: clock_gettime ( nix:: time:: ClockId :: CLOCK_REALTIME ) {
21+ Ok ( __ts) => {
22+ let __s = __ts. tv_sec ( ) ;
23+ if !__out. is_null ( ) {
24+ __out. write ( __s) ;
25+ }
26+ __s
27+ }
28+ Err ( __e) => {
29+ libcc2rs:: cpp2rust_errno ( ) . write ( __e as i32 ) ;
30+ -1
31+ }
32+ }
33+ }
34+
35+ fn f2 ( a0 : nix:: time:: ClockId , a1 : Ptr < Timespec > ) -> i32 {
36+ match nix:: time:: clock_gettime ( a0) {
37+ Ok ( __ts) => {
38+ a1. with_mut ( |__t| {
39+ * __t. tv_sec . borrow_mut ( ) = __ts. tv_sec ( ) as i64 ;
40+ * __t. tv_nsec . borrow_mut ( ) = __ts. tv_nsec ( ) as i64 ;
41+ } ) ;
42+ 0
43+ }
44+ Err ( __e) => {
45+ libcc2rs:: cpp2rust_errno ( ) . write ( __e as i32 ) ;
46+ -1
47+ }
48+ }
49+ }
50+
51+ fn f4 ( a0 : Ptr < :: libc:: time_t > , a1 : Ptr < Tm > ) -> Ptr < Tm > {
52+ let __res = a1. clone ( ) ;
53+ match jiff:: Timestamp :: from_second ( a0. read ( ) ) {
54+ Ok ( __ts) => {
55+ let __dt = __ts. to_zoned ( jiff:: tz:: TimeZone :: UTC ) ;
56+ __res. with_mut ( |__tm| * __tm = Tm :: from_zoned ( & __dt) ) ;
57+ __res
58+ }
59+ Err ( _) => {
60+ libcc2rs:: cpp2rust_errno ( ) . write ( :: libc:: EOVERFLOW ) ;
61+ Ptr :: null ( )
62+ }
63+ }
64+ }
65+
66+ fn f6 ( a0 : Ptr < u8 > , a1 : usize , a2 : Ptr < u8 > , a3 : Ptr < Tm > ) -> usize {
67+ let __dt = a3. with ( |__tm| __tm. to_civil ( ) ) ;
68+ let __text = match __dt {
69+ Ok ( __d) => {
70+ jiff:: fmt:: strtime:: format ( a2. to_rust_string ( ) . as_str ( ) , __d) . unwrap_or_default ( )
71+ }
72+ Err ( _) => String :: new ( ) ,
73+ } ;
74+ if __text. is_empty ( ) || __text. len ( ) + 1 > a1 {
75+ 0
76+ } else {
77+ let mut __dst = a0. clone ( ) ;
78+ for __b in __text. as_bytes ( ) {
79+ __dst. write ( * __b) ;
80+ __dst += 1 ;
81+ }
82+ __dst. write ( 0 ) ;
83+ __text. len ( )
84+ }
85+ }
86+
87+ fn f7 ( a0 : Ptr < u8 > , a1 : Ptr < Timeval > ) -> i32 {
88+ let __times = a1;
89+ let __at = __times. with ( |__tv| {
90+ nix:: sys:: time:: TimeVal :: new (
91+ * __tv. tv_sec . borrow ( ) as :: libc:: time_t ,
92+ * __tv. tv_usec . borrow ( ) as :: libc:: suseconds_t ,
93+ )
94+ } ) ;
95+ let __mt = __times. offset ( 1 ) . with ( |__tv| {
96+ nix:: sys:: time:: TimeVal :: new (
97+ * __tv. tv_sec . borrow ( ) as :: libc:: time_t ,
98+ * __tv. tv_usec . borrow ( ) as :: libc:: suseconds_t ,
99+ )
100+ } ) ;
101+ match nix:: sys:: stat:: utimes ( a0. to_rust_string ( ) . as_str ( ) , & __at, & __mt) {
102+ Ok ( ( ) ) => 0 ,
103+ Err ( __e) => {
104+ libcc2rs:: cpp2rust_errno ( ) . write ( __e as i32 ) ;
105+ -1
106+ }
107+ }
108+ }
109+
110+ // a1 is ignored intentionally, see: https://man7.org/linux/man-pages/man2/gettimeofday.2.html
111+ //
112+ // "The use of the timezone structure is obsolete; the tz argument should normally be specified as NULL."
113+ #[ cfg( target_os = "linux" ) ]
114+ fn f8 ( a0 : Ptr < Timeval > , a1 : Ptr < :: libc:: timezone > ) -> i32 {
115+ match nix:: time:: clock_gettime ( nix:: time:: ClockId :: CLOCK_REALTIME ) {
116+ Ok ( __ts) => {
117+ a0. with_mut ( |__tv| {
118+ * __tv. tv_sec . borrow_mut ( ) = __ts. tv_sec ( ) as i64 ;
119+ * __tv. tv_usec . borrow_mut ( ) = ( __ts. tv_nsec ( ) / 1000 ) as i64 ;
120+ } ) ;
121+ 0
122+ }
123+ Err ( __e) => {
124+ libcc2rs:: cpp2rust_errno ( ) . write ( __e as i32 ) ;
125+ -1
126+ }
127+ }
128+ }
129+
130+ // a1 is ignored intentionally, see: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/gettimeofday.2.html
131+ //
132+ // "Note: timezone is no longer used; this information is kept outside the kernel."
133+ #[ cfg( target_os = "macos" ) ]
134+ fn f8 ( a0 : Ptr < Timeval > , a1 : AnyPtr ) -> i32 {
135+ match nix:: time:: clock_gettime ( nix:: time:: ClockId :: CLOCK_REALTIME ) {
136+ Ok ( __ts) => {
137+ a0. with_mut ( |__tv| {
138+ * __tv. tv_sec . borrow_mut ( ) = __ts. tv_sec ( ) as i64 ;
139+ * __tv. tv_usec . borrow_mut ( ) = ( __ts. tv_nsec ( ) / 1000 ) as i64 ;
140+ } ) ;
141+ 0
142+ }
143+ Err ( __e) => {
144+ libcc2rs:: cpp2rust_errno ( ) . write ( __e as i32 ) ;
145+ -1
146+ }
147+ }
148+ }
149+
150+ unsafe fn f9 ( ) -> nix:: time:: ClockId {
151+ nix:: time:: ClockId :: CLOCK_REALTIME
152+ }
0 commit comments