xref: /aosp_15_r20/external/ltp/android/include/sys/timeb.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker #ifndef __SYS_TIMEB_H
2*49cdfc7eSAndroid Build Coastguard Worker #define __SYS_TIMEB_H
3*49cdfc7eSAndroid Build Coastguard Worker 
4*49cdfc7eSAndroid Build Coastguard Worker #include <time.h>
5*49cdfc7eSAndroid Build Coastguard Worker 
6*49cdfc7eSAndroid Build Coastguard Worker struct timeb {
7*49cdfc7eSAndroid Build Coastguard Worker     time_t time;
8*49cdfc7eSAndroid Build Coastguard Worker     unsigned short millitm;
9*49cdfc7eSAndroid Build Coastguard Worker     short timezone;
10*49cdfc7eSAndroid Build Coastguard Worker     short dstflag;
11*49cdfc7eSAndroid Build Coastguard Worker };
12*49cdfc7eSAndroid Build Coastguard Worker 
ftime(struct timeb * tp)13*49cdfc7eSAndroid Build Coastguard Worker static inline int ftime(struct timeb *tp) {
14*49cdfc7eSAndroid Build Coastguard Worker     const unsigned int ONE_MS_IN_NS = 100000;
15*49cdfc7eSAndroid Build Coastguard Worker     struct timespec ts;
16*49cdfc7eSAndroid Build Coastguard Worker 
17*49cdfc7eSAndroid Build Coastguard Worker     int err = clock_gettime(CLOCK_REALTIME, &ts);
18*49cdfc7eSAndroid Build Coastguard Worker     if (err)
19*49cdfc7eSAndroid Build Coastguard Worker         return -1;
20*49cdfc7eSAndroid Build Coastguard Worker 
21*49cdfc7eSAndroid Build Coastguard Worker     tp->time = ts.tv_sec;
22*49cdfc7eSAndroid Build Coastguard Worker     tp->millitm = ts.tv_nsec / ONE_MS_IN_NS;
23*49cdfc7eSAndroid Build Coastguard Worker     return 0;
24*49cdfc7eSAndroid Build Coastguard Worker }
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker #endif /* __SYS_TIMEB_H */
27