2 Unix SMB/CIFS implementation.
3 time handling functions
5 Copyright (C) Andrew Tridgell 1992-2004
6 Copyright (C) Stefan (metze) Metzmacher 2002
7 Copyright (C) Jeremy Allison 2007
8 Copyright (C) Andrew Bartlett 2011
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "system/time.h"
29 * @brief time handling functions
32 #if (SIZEOF_LONG == 8)
33 #define TIME_FIXUP_CONSTANT_INT 11644473600L
34 #elif (SIZEOF_LONG_LONG == 8)
35 #define TIME_FIXUP_CONSTANT_INT 11644473600LL
41 External access to time_t_min and time_t_max.
43 _PUBLIC_
time_t get_time_t_max(void)
49 a gettimeofday wrapper
51 _PUBLIC_
void GetTimeOfDay(struct timeval
*tval
)
53 #ifdef HAVE_GETTIMEOFDAY_TZ
54 gettimeofday(tval
,NULL
);
61 a wrapper to preferably get the monotonic time
63 _PUBLIC_
void clock_gettime_mono(struct timespec
*tp
)
65 /* prefer a suspend aware monotonic CLOCK_BOOTTIME: */
67 if (clock_gettime(CLOCK_BOOTTIME
,tp
) == 0) {
71 /* then try the monotonic clock: */
72 #if CUSTOM_CLOCK_MONOTONIC != CLOCK_REALTIME
73 if (clock_gettime(CUSTOM_CLOCK_MONOTONIC
,tp
) == 0) {
77 clock_gettime(CLOCK_REALTIME
,tp
);
81 a wrapper to preferably get the monotonic time in seconds
83 _PUBLIC_
time_t time_mono(time_t *t
)
87 clock_gettime_mono(&tp
);
95 #define TIME_FIXUP_CONSTANT 11644473600LL
97 time_t convert_timespec_to_time_t(struct timespec ts
)
99 /* Ensure tv_nsec is less than 1sec. */
100 while (ts
.tv_nsec
> 1000000000) {
102 ts
.tv_nsec
-= 1000000000;
105 /* 1 ns == 1,000,000,000 - one thousand millionths of a second.
106 increment if it's greater than 500 millionth of a second. */
108 if (ts
.tv_nsec
> 500000000) {
109 return ts
.tv_sec
+ 1;
114 struct timespec
convert_time_t_to_timespec(time_t t
)
125 Interpret an 8 byte "filetime" structure to a time_t
126 It's originally in "100ns units since jan 1st 1601"
128 An 8 byte value of 0xffffffffffffffff will be returned as a timespec of
135 time_t nt_time_to_unix(NTTIME nt
)
137 return convert_timespec_to_time_t(nt_time_to_unix_timespec(&nt
));
142 put a 8 byte filetime from a time_t
143 This takes GMT as input
145 _PUBLIC_
void unix_to_nt_time(NTTIME
*nt
, time_t t
)
149 if (t
== (time_t)-1) {
154 if (t
== TIME_T_MAX
|| t
== INT64_MAX
) {
155 *nt
= 0x7fffffffffffffffLL
;
165 t2
+= TIME_FIXUP_CONSTANT_INT
;
173 check if it's a null unix time
175 _PUBLIC_
bool null_time(time_t t
)
178 t
== (time_t)0xFFFFFFFF ||
184 check if it's a null NTTIME
186 _PUBLIC_
bool null_nttime(NTTIME t
)
188 return t
== 0 || t
== (NTTIME
)-1;
191 /*******************************************************************
192 create a 16 bit dos packed date
193 ********************************************************************/
194 static uint16_t make_dos_date1(struct tm
*t
)
197 ret
= (((unsigned int)(t
->tm_mon
+1)) >> 3) | ((t
->tm_year
-80) << 1);
198 ret
= ((ret
&0xFF)<<8) | (t
->tm_mday
| (((t
->tm_mon
+1) & 0x7) << 5));
202 /*******************************************************************
203 create a 16 bit dos packed time
204 ********************************************************************/
205 static uint16_t make_dos_time1(struct tm
*t
)
208 ret
= ((((unsigned int)t
->tm_min
>> 3)&0x7) | (((unsigned int)t
->tm_hour
) << 3));
209 ret
= ((ret
&0xFF)<<8) | ((t
->tm_sec
/2) | ((t
->tm_min
& 0x7) << 5));
213 /*******************************************************************
214 create a 32 bit dos packed date/time from some parameters
215 This takes a GMT time and returns a packed localtime structure
216 ********************************************************************/
217 static uint32_t make_dos_date(time_t unixdate
, int zone_offset
)
226 unixdate
-= zone_offset
;
228 t
= gmtime(&unixdate
);
233 ret
= make_dos_date1(t
);
234 ret
= ((ret
&0xFFFF)<<16) | make_dos_time1(t
);
240 put a dos date into a buffer (time/date format)
241 This takes GMT time and puts local time in the buffer
243 _PUBLIC_
void push_dos_date(uint8_t *buf
, int offset
, time_t unixdate
, int zone_offset
)
245 uint32_t x
= make_dos_date(unixdate
, zone_offset
);
250 put a dos date into a buffer (date/time format)
251 This takes GMT time and puts local time in the buffer
253 _PUBLIC_
void push_dos_date2(uint8_t *buf
,int offset
,time_t unixdate
, int zone_offset
)
256 x
= make_dos_date(unixdate
, zone_offset
);
257 x
= ((x
&0xFFFF)<<16) | ((x
&0xFFFF0000)>>16);
262 put a dos 32 bit "unix like" date into a buffer. This routine takes
263 GMT and converts it to LOCAL time before putting it (most SMBs assume
264 localtime for this sort of date)
266 _PUBLIC_
void push_dos_date3(uint8_t *buf
,int offset
,time_t unixdate
, int zone_offset
)
268 if (!null_time(unixdate
)) {
269 unixdate
-= zone_offset
;
271 SIVAL(buf
,offset
,unixdate
);
274 /*******************************************************************
275 interpret a 32 bit dos packed date/time to some parameters
276 ********************************************************************/
277 void interpret_dos_date(uint32_t date
,int *year
,int *month
,int *day
,int *hour
,int *minute
,int *second
)
279 uint32_t p0
,p1
,p2
,p3
;
281 p0
=date
&0xFF; p1
=((date
&0xFF00)>>8)&0xFF;
282 p2
=((date
&0xFF0000)>>16)&0xFF; p3
=((date
&0xFF000000)>>24)&0xFF;
284 *second
= 2*(p0
& 0x1F);
285 *minute
= ((p0
>>5)&0xFF) + ((p1
&0x7)<<3);
286 *hour
= (p1
>>3)&0xFF;
288 *month
= ((p2
>>5)&0xFF) + ((p3
&0x1)<<3) - 1;
289 *year
= ((p3
>>1)&0xFF) + 80;
293 create a unix date (int GMT) from a dos date (which is actually in
296 _PUBLIC_
time_t pull_dos_date(const uint8_t *date_ptr
, int zone_offset
)
302 dos_date
= IVAL(date_ptr
,0);
304 if (dos_date
== 0) return (time_t)0;
306 interpret_dos_date(dos_date
,&t
.tm_year
,&t
.tm_mon
,
307 &t
.tm_mday
,&t
.tm_hour
,&t
.tm_min
,&t
.tm_sec
);
318 like make_unix_date() but the words are reversed
320 _PUBLIC_
time_t pull_dos_date2(const uint8_t *date_ptr
, int zone_offset
)
324 x
= IVAL(date_ptr
,0);
325 x2
= ((x
&0xFFFF)<<16) | ((x
&0xFFFF0000)>>16);
328 return pull_dos_date((const uint8_t *)&x
, zone_offset
);
332 create a unix GMT date from a dos date in 32 bit "unix like" format
333 these generally arrive as localtimes, with corresponding DST
335 _PUBLIC_
time_t pull_dos_date3(const uint8_t *date_ptr
, int zone_offset
)
337 time_t t
= (time_t)IVAL(date_ptr
,0);
345 /****************************************************************************
346 Return the date and time as a string
347 ****************************************************************************/
349 char *timeval_string(TALLOC_CTX
*ctx
, const struct timeval
*tp
, bool hires
)
354 t
= (time_t)tp
->tv_sec
;
358 return talloc_asprintf(ctx
,
359 "%ld.%06ld seconds since the Epoch",
363 return talloc_asprintf(ctx
,
364 "%ld seconds since the Epoch",
371 strftime(TimeBuf
,sizeof(TimeBuf
)-1,"%Y/%m/%d %H:%M:%S",tm
);
372 return talloc_asprintf(ctx
,
376 strftime(TimeBuf
,sizeof(TimeBuf
)-1,"%Y/%m/%d %H:%M:%S",tm
);
377 return talloc_strdup(ctx
, TimeBuf
);
381 const char *asct
= asctime(tm
);
382 return talloc_asprintf(ctx
, "%s.%06ld",
383 asct
? asct
: "unknown",
386 const char *asct
= asctime(tm
);
387 return talloc_asprintf(ctx
, asct
? asct
: "unknown");
393 char *current_timestring(TALLOC_CTX
*ctx
, bool hires
)
398 return timeval_string(ctx
, &tv
, hires
);
403 return a HTTP/1.0 time string
405 _PUBLIC_
char *http_timestring(TALLOC_CTX
*mem_ctx
, time_t t
)
409 struct tm
*tm
= localtime(&t
);
411 if (t
== TIME_T_MAX
) {
412 return talloc_strdup(mem_ctx
, "never");
416 return talloc_asprintf(mem_ctx
,"%ld seconds since the Epoch",(long)t
);
419 #ifndef HAVE_STRFTIME
420 buf
= talloc_strdup(mem_ctx
, asctime(tm
));
421 if (buf
[strlen(buf
)-1] == '\n') {
422 buf
[strlen(buf
)-1] = 0;
425 strftime(tempTime
, sizeof(tempTime
)-1, "%a, %d %b %Y %H:%M:%S %Z", tm
);
426 buf
= talloc_strdup(mem_ctx
, tempTime
);
427 #endif /* !HAVE_STRFTIME */
433 Return the date and time as a string
435 _PUBLIC_
char *timestring(TALLOC_CTX
*mem_ctx
, time_t t
)
443 return talloc_asprintf(mem_ctx
,
444 "%ld seconds since the Epoch",
449 /* Some versions of gcc complain about using some special format
450 * specifiers. This is a bug in gcc, not a bug in this code. See a
451 * recent strftime() manual page for details. */
452 strftime(tempTime
,sizeof(tempTime
)-1,"%a %b %e %X %Y %Z",tm
);
453 TimeBuf
= talloc_strdup(mem_ctx
, tempTime
);
455 TimeBuf
= talloc_strdup(mem_ctx
, asctime(tm
));
456 if (TimeBuf
== NULL
) {
459 if (TimeBuf
[0] != '\0') {
460 size_t len
= strlen(TimeBuf
);
461 if (TimeBuf
[len
- 1] == '\n') {
462 TimeBuf
[len
- 1] = '\0';
471 return a talloced string representing a NTTIME for human consumption
473 _PUBLIC_
const char *nt_time_string(TALLOC_CTX
*mem_ctx
, NTTIME nt
)
479 t
= nt_time_to_unix(nt
);
480 return timestring(mem_ctx
, t
);
485 put a NTTIME into a packet
487 _PUBLIC_
void push_nttime(uint8_t *base
, uint16_t offset
, NTTIME t
)
489 SBVAL(base
, offset
, t
);
493 pull a NTTIME from a packet
495 _PUBLIC_ NTTIME
pull_nttime(uint8_t *base
, uint16_t offset
)
497 NTTIME ret
= BVAL(base
, offset
);
502 return (tv1 - tv2) in microseconds
504 _PUBLIC_
int64_t usec_time_diff(const struct timeval
*tv1
, const struct timeval
*tv2
)
506 int64_t sec_diff
= tv1
->tv_sec
- tv2
->tv_sec
;
507 return (sec_diff
* 1000000) + (int64_t)(tv1
->tv_usec
- tv2
->tv_usec
);
511 return (tp1 - tp2) in microseconds
513 _PUBLIC_
int64_t nsec_time_diff(const struct timespec
*tp1
, const struct timespec
*tp2
)
515 int64_t sec_diff
= tp1
->tv_sec
- tp2
->tv_sec
;
516 return (sec_diff
* 1000000000) + (int64_t)(tp1
->tv_nsec
- tp2
->tv_nsec
);
521 return a zero timeval
523 _PUBLIC_
struct timeval
timeval_zero(void)
532 return true if a timeval is zero
534 _PUBLIC_
bool timeval_is_zero(const struct timeval
*tv
)
536 return tv
->tv_sec
== 0 && tv
->tv_usec
== 0;
540 return a timeval for the current time
542 _PUBLIC_
struct timeval
timeval_current(void)
550 return a timeval struct with the given elements
552 _PUBLIC_
struct timeval
timeval_set(uint32_t secs
, uint32_t usecs
)
562 return a timeval ofs microseconds after tv
564 _PUBLIC_
struct timeval
timeval_add(const struct timeval
*tv
,
565 uint32_t secs
, uint32_t usecs
)
567 struct timeval tv2
= *tv
;
568 const unsigned int million
= 1000000;
570 tv2
.tv_usec
+= usecs
;
571 tv2
.tv_sec
+= tv2
.tv_usec
/ million
;
572 tv2
.tv_usec
= tv2
.tv_usec
% million
;
577 return the sum of two timeval structures
579 struct timeval
timeval_sum(const struct timeval
*tv1
,
580 const struct timeval
*tv2
)
582 return timeval_add(tv1
, tv2
->tv_sec
, tv2
->tv_usec
);
586 return a timeval secs/usecs into the future
588 _PUBLIC_
struct timeval
timeval_current_ofs(uint32_t secs
, uint32_t usecs
)
590 struct timeval tv
= timeval_current();
591 return timeval_add(&tv
, secs
, usecs
);
595 return a timeval milliseconds into the future
597 _PUBLIC_
struct timeval
timeval_current_ofs_msec(uint32_t msecs
)
599 struct timeval tv
= timeval_current();
600 return timeval_add(&tv
, msecs
/ 1000, (msecs
% 1000) * 1000);
604 return a timeval microseconds into the future
606 _PUBLIC_
struct timeval
timeval_current_ofs_usec(uint32_t usecs
)
608 struct timeval tv
= timeval_current();
609 return timeval_add(&tv
, usecs
/ 1000000, usecs
% 1000000);
613 compare two timeval structures.
614 Return -1 if tv1 < tv2
615 Return 0 if tv1 == tv2
616 Return 1 if tv1 > tv2
618 _PUBLIC_
int timeval_compare(const struct timeval
*tv1
, const struct timeval
*tv2
)
620 if (tv1
->tv_sec
> tv2
->tv_sec
) return 1;
621 if (tv1
->tv_sec
< tv2
->tv_sec
) return -1;
622 if (tv1
->tv_usec
> tv2
->tv_usec
) return 1;
623 if (tv1
->tv_usec
< tv2
->tv_usec
) return -1;
628 return true if a timer is in the past
630 _PUBLIC_
bool timeval_expired(const struct timeval
*tv
)
632 struct timeval tv2
= timeval_current();
633 if (tv2
.tv_sec
> tv
->tv_sec
) return true;
634 if (tv2
.tv_sec
< tv
->tv_sec
) return false;
635 return (tv2
.tv_usec
>= tv
->tv_usec
);
639 return the number of seconds elapsed between two times
641 _PUBLIC_
double timeval_elapsed2(const struct timeval
*tv1
, const struct timeval
*tv2
)
643 return (tv2
->tv_sec
- tv1
->tv_sec
) +
644 (tv2
->tv_usec
- tv1
->tv_usec
)*1.0e-6;
648 return the number of seconds elapsed since a given time
650 _PUBLIC_
double timeval_elapsed(const struct timeval
*tv
)
652 struct timeval tv2
= timeval_current();
653 return timeval_elapsed2(tv
, &tv2
);
656 * return the number of seconds elapsed between two times
658 _PUBLIC_
double timespec_elapsed2(const struct timespec
*ts1
,
659 const struct timespec
*ts2
)
661 return (ts2
->tv_sec
- ts1
->tv_sec
) +
662 (ts2
->tv_nsec
- ts1
->tv_nsec
)*1.0e-9;
666 * return the number of seconds elapsed since a given time
668 _PUBLIC_
double timespec_elapsed(const struct timespec
*ts
)
670 struct timespec ts2
= timespec_current();
671 return timespec_elapsed2(ts
, &ts2
);
675 return the lesser of two timevals
677 _PUBLIC_
struct timeval
timeval_min(const struct timeval
*tv1
,
678 const struct timeval
*tv2
)
680 if (tv1
->tv_sec
< tv2
->tv_sec
) return *tv1
;
681 if (tv1
->tv_sec
> tv2
->tv_sec
) return *tv2
;
682 if (tv1
->tv_usec
< tv2
->tv_usec
) return *tv1
;
687 return the greater of two timevals
689 _PUBLIC_
struct timeval
timeval_max(const struct timeval
*tv1
,
690 const struct timeval
*tv2
)
692 if (tv1
->tv_sec
> tv2
->tv_sec
) return *tv1
;
693 if (tv1
->tv_sec
< tv2
->tv_sec
) return *tv2
;
694 if (tv1
->tv_usec
> tv2
->tv_usec
) return *tv1
;
699 return the difference between two timevals as a timeval
700 if tv1 comes after tv2, then return a zero timeval
701 (this is *tv2 - *tv1)
703 _PUBLIC_
struct timeval
timeval_until(const struct timeval
*tv1
,
704 const struct timeval
*tv2
)
707 if (timeval_compare(tv1
, tv2
) >= 0) {
708 return timeval_zero();
710 t
.tv_sec
= tv2
->tv_sec
- tv1
->tv_sec
;
711 if (tv1
->tv_usec
> tv2
->tv_usec
) {
713 t
.tv_usec
= 1000000 - (tv1
->tv_usec
- tv2
->tv_usec
);
715 t
.tv_usec
= tv2
->tv_usec
- tv1
->tv_usec
;
722 convert a timeval to a NTTIME
724 _PUBLIC_ NTTIME
timeval_to_nttime(const struct timeval
*tv
)
726 return 10*(tv
->tv_usec
+
727 ((TIME_FIXUP_CONSTANT
+ (uint64_t)tv
->tv_sec
) * 1000000));
731 convert a NTTIME to a timeval
733 _PUBLIC_
void nttime_to_timeval(struct timeval
*tv
, NTTIME t
)
735 if (tv
== NULL
) return;
739 t
-= TIME_FIXUP_CONSTANT
*1000*1000;
741 tv
->tv_sec
= t
/ 1000000;
743 if (TIME_T_MIN
> tv
->tv_sec
|| tv
->tv_sec
> TIME_T_MAX
) {
749 tv
->tv_usec
= t
- tv
->tv_sec
*1000000;
752 /*******************************************************************
753 yield the difference between *A and *B, in seconds, ignoring leap seconds
754 ********************************************************************/
755 static int tm_diff(struct tm
*a
, struct tm
*b
)
757 int ay
= a
->tm_year
+ (1900 - 1);
758 int by
= b
->tm_year
+ (1900 - 1);
759 int intervening_leap_days
=
760 (ay
/4 - by
/4) - (ay
/100 - by
/100) + (ay
/400 - by
/400);
762 int days
= 365*years
+ intervening_leap_days
+ (a
->tm_yday
- b
->tm_yday
);
763 int hours
= 24*days
+ (a
->tm_hour
- b
->tm_hour
);
764 int minutes
= 60*hours
+ (a
->tm_min
- b
->tm_min
);
765 int seconds
= 60*minutes
+ (a
->tm_sec
- b
->tm_sec
);
772 return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
774 _PUBLIC_
int get_time_zone(time_t t
)
776 struct tm
*tm
= gmtime(&t
);
784 return tm_diff(&tm_utc
,tm
);
787 struct timespec
nt_time_to_unix_timespec(NTTIME
*nt
)
792 if (*nt
== 0 || *nt
== (int64_t)-1) {
799 /* d is now in 100ns units, since jan 1st 1601".
800 Save off the ns fraction. */
803 * Take the last seven decimal digits and multiply by 100.
804 * to convert from 100ns units to 1ns units.
806 ret
.tv_nsec
= (long) ((d
% (1000 * 1000 * 10)) * 100);
808 /* Convert to seconds */
811 /* Now adjust by 369 years to make the secs since 1970 */
812 d
-= TIME_FIXUP_CONSTANT_INT
;
814 if (d
<= (int64_t)TIME_T_MIN
) {
815 ret
.tv_sec
= TIME_T_MIN
;
820 if (d
>= (int64_t)TIME_T_MAX
) {
821 ret
.tv_sec
= TIME_T_MAX
;
826 ret
.tv_sec
= (time_t)d
;
832 check if 2 NTTIMEs are equal.
834 bool nt_time_equal(NTTIME
*t1
, NTTIME
*t2
)
840 Check if it's a null timespec.
843 bool null_timespec(struct timespec ts
)
845 return ts
.tv_sec
== 0 ||
846 ts
.tv_sec
== (time_t)0xFFFFFFFF ||
847 ts
.tv_sec
== (time_t)-1;
850 /****************************************************************************
851 Convert a normalized timeval to a timespec.
852 ****************************************************************************/
854 struct timespec
convert_timeval_to_timespec(const struct timeval tv
)
857 ts
.tv_sec
= tv
.tv_sec
;
858 ts
.tv_nsec
= tv
.tv_usec
* 1000;
862 /****************************************************************************
863 Convert a normalized timespec to a timeval.
864 ****************************************************************************/
866 struct timeval
convert_timespec_to_timeval(const struct timespec ts
)
869 tv
.tv_sec
= ts
.tv_sec
;
870 tv
.tv_usec
= ts
.tv_nsec
/ 1000;
874 /****************************************************************************
875 Return a timespec for the current time
876 ****************************************************************************/
878 _PUBLIC_
struct timespec
timespec_current(void)
881 clock_gettime(CLOCK_REALTIME
, &ts
);
885 /****************************************************************************
886 Return the lesser of two timespecs.
887 ****************************************************************************/
889 struct timespec
timespec_min(const struct timespec
*ts1
,
890 const struct timespec
*ts2
)
892 if (ts1
->tv_sec
< ts2
->tv_sec
) return *ts1
;
893 if (ts1
->tv_sec
> ts2
->tv_sec
) return *ts2
;
894 if (ts1
->tv_nsec
< ts2
->tv_nsec
) return *ts1
;
898 /****************************************************************************
899 compare two timespec structures.
900 Return -1 if ts1 < ts2
901 Return 0 if ts1 == ts2
902 Return 1 if ts1 > ts2
903 ****************************************************************************/
905 _PUBLIC_
int timespec_compare(const struct timespec
*ts1
, const struct timespec
*ts2
)
907 if (ts1
->tv_sec
> ts2
->tv_sec
) return 1;
908 if (ts1
->tv_sec
< ts2
->tv_sec
) return -1;
909 if (ts1
->tv_nsec
> ts2
->tv_nsec
) return 1;
910 if (ts1
->tv_nsec
< ts2
->tv_nsec
) return -1;
914 /****************************************************************************
915 Round up a timespec if nsec > 500000000, round down if lower,
917 ****************************************************************************/
919 void round_timespec_to_sec(struct timespec
*ts
)
921 ts
->tv_sec
= convert_timespec_to_time_t(*ts
);
925 /****************************************************************************
926 Round a timespec to usec value.
927 ****************************************************************************/
929 void round_timespec_to_usec(struct timespec
*ts
)
931 struct timeval tv
= convert_timespec_to_timeval(*ts
);
932 *ts
= convert_timeval_to_timespec(tv
);
933 while (ts
->tv_nsec
> 1000000000) {
935 ts
->tv_nsec
-= 1000000000;
939 /****************************************************************************
940 Put a 8 byte filetime from a struct timespec. Uses GMT.
941 ****************************************************************************/
943 _PUBLIC_
void unix_timespec_to_nt_time(NTTIME
*nt
, struct timespec ts
)
947 if (ts
.tv_sec
==0 && ts
.tv_nsec
== 0) {
951 if (ts
.tv_sec
== TIME_T_MAX
) {
952 *nt
= 0x7fffffffffffffffLL
;
955 if (ts
.tv_sec
== (time_t)-1) {
961 d
+= TIME_FIXUP_CONSTANT_INT
;
963 /* d is now in 100ns units. */
964 d
+= (ts
.tv_nsec
/ 100);