r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
[abartlet/samba.git/.git] / source3 / lib / time.c
1 /* 
2    Unix SMB/CIFS implementation.
3    time handling functions
4    Copyright (C) Andrew Tridgell                1992-1998
5    Copyright (C) Stefan (metze) Metzmacher      2002   
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 /*
24   This stuff was largely rewritten by Paul Eggert <eggert@twinsun.com>
25   in May 1996 
26   */
27
28
29 int extra_time_offset = 0;
30
31 #ifndef CHAR_BIT
32 #define CHAR_BIT 8
33 #endif
34
35 #ifndef TIME_T_MIN
36 #define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \
37                     : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1))
38 #endif
39 #ifndef TIME_T_MAX
40 #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN)
41 #endif
42
43 void get_nttime_max(NTTIME *t)
44 {
45         /* FIXME: This is incorrect */
46         unix_to_nt_time(t, get_time_t_max());
47 }
48
49 /*******************************************************************
50  External access to time_t_min and time_t_max.
51 ********************************************************************/
52
53 time_t get_time_t_max(void)
54 {
55         return TIME_T_MAX;
56 }
57
58 /*******************************************************************
59 a gettimeofday wrapper
60 ********************************************************************/
61 void GetTimeOfDay(struct timeval *tval)
62 {
63 #ifdef HAVE_GETTIMEOFDAY_TZ
64         gettimeofday(tval,NULL);
65 #else
66         gettimeofday(tval);
67 #endif
68 }
69
70 #define TM_YEAR_BASE 1900
71
72 /*******************************************************************
73 yield the difference between *A and *B, in seconds, ignoring leap seconds
74 ********************************************************************/
75 static int tm_diff(struct tm *a, struct tm *b)
76 {
77   int ay = a->tm_year + (TM_YEAR_BASE - 1);
78   int by = b->tm_year + (TM_YEAR_BASE - 1);
79   int intervening_leap_days =
80     (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
81   int years = ay - by;
82   int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday);
83   int hours = 24*days + (a->tm_hour - b->tm_hour);
84   int minutes = 60*hours + (a->tm_min - b->tm_min);
85   int seconds = 60*minutes + (a->tm_sec - b->tm_sec);
86
87   return seconds;
88 }
89
90 /*******************************************************************
91   return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
92   ******************************************************************/
93 static int TimeZone(time_t t)
94 {
95   struct tm *tm = gmtime(&t);
96   struct tm tm_utc;
97   if (!tm)
98     return 0;
99   tm_utc = *tm;
100   tm = localtime(&t);
101   if (!tm)
102     return 0;
103   return tm_diff(&tm_utc,tm);
104
105 }
106
107 static BOOL done_serverzone_init;
108
109 /* Return the smb serverzone value */
110
111 static int get_serverzone(void)
112 {
113         static int serverzone;
114
115         if (!done_serverzone_init) {
116                 serverzone = TimeZone(time(NULL));
117
118                 if ((serverzone % 60) != 0) {
119                         DEBUG(1,("WARNING: Your timezone is not a multiple of 1 minute.\n"));
120                 }
121
122                 DEBUG(4,("Serverzone is %d\n",serverzone));
123
124                 done_serverzone_init = True;
125         }
126
127         return serverzone;
128 }
129
130 /* Re-read the smb serverzone value */
131
132 static struct timeval start_time_hires;
133
134 void TimeInit(void)
135 {
136         done_serverzone_init = False;
137         get_serverzone();
138         /* Save the start time of this process. */
139         if (start_time_hires.tv_sec == 0 && start_time_hires.tv_usec == 0)
140                 GetTimeOfDay(&start_time_hires);
141 }
142
143 /**********************************************************************
144  Return a timeval struct of the uptime of this process. As TimeInit is
145  done before a daemon fork then this is the start time from the parent
146  daemon start. JRA.
147 ***********************************************************************/
148
149 void get_process_uptime(struct timeval *ret_time)
150 {
151         struct timeval time_now_hires;
152
153         GetTimeOfDay(&time_now_hires);
154         ret_time->tv_sec = time_now_hires.tv_sec - start_time_hires.tv_sec;
155         ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec;
156         if (time_now_hires.tv_usec < start_time_hires.tv_usec) {
157                 ret_time->tv_sec -= 1;
158                 ret_time->tv_usec = 1000000 + (time_now_hires.tv_usec - start_time_hires.tv_usec);
159         } else
160                 ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec;
161 }
162
163 /*******************************************************************
164 return the same value as TimeZone, but it should be more efficient.
165
166 We keep a table of DST offsets to prevent calling localtime() on each 
167 call of this function. This saves a LOT of time on many unixes.
168
169 Updated by Paul Eggert <eggert@twinsun.com>
170 ********************************************************************/
171 static int TimeZoneFaster(time_t t)
172 {
173   static struct dst_table {time_t start,end; int zone;} *tdt, *dst_table = NULL;
174   static int table_size = 0;
175   int i;
176   int zone = 0;
177
178   if (t == 0) t = time(NULL);
179
180   /* Tunis has a 8 day DST region, we need to be careful ... */
181 #define MAX_DST_WIDTH (365*24*60*60)
182 #define MAX_DST_SKIP (7*24*60*60)
183
184   for (i=0;i<table_size;i++)
185     if (t >= dst_table[i].start && t <= dst_table[i].end) break;
186
187   if (i<table_size) {
188     zone = dst_table[i].zone;
189   } else {
190     time_t low,high;
191
192     zone = TimeZone(t);
193     tdt = SMB_REALLOC_ARRAY(dst_table, struct dst_table, i+1);
194     if (!tdt) {
195       DEBUG(0,("TimeZoneFaster: out of memory!\n"));
196       SAFE_FREE(dst_table);
197       table_size = 0;
198     } else {
199       dst_table = tdt;
200       table_size++;
201
202       dst_table[i].zone = zone; 
203       dst_table[i].start = dst_table[i].end = t;
204     
205       /* no entry will cover more than 6 months */
206       low = t - MAX_DST_WIDTH/2;
207       if (t < low)
208         low = TIME_T_MIN;
209       
210       high = t + MAX_DST_WIDTH/2;
211       if (high < t)
212         high = TIME_T_MAX;
213       
214       /* widen the new entry using two bisection searches */
215       while (low+60*60 < dst_table[i].start) {
216         if (dst_table[i].start - low > MAX_DST_SKIP*2)
217           t = dst_table[i].start - MAX_DST_SKIP;
218         else
219           t = low + (dst_table[i].start-low)/2;
220         if (TimeZone(t) == zone)
221           dst_table[i].start = t;
222         else
223           low = t;
224       }
225
226       while (high-60*60 > dst_table[i].end) {
227         if (high - dst_table[i].end > MAX_DST_SKIP*2)
228           t = dst_table[i].end + MAX_DST_SKIP;
229         else
230           t = high - (high-dst_table[i].end)/2;
231         if (TimeZone(t) == zone)
232           dst_table[i].end = t;
233         else
234           high = t;
235       }
236 #if 0
237       DEBUG(1,("Added DST entry from %s ",
238                asctime(localtime(&dst_table[i].start))));
239       DEBUG(1,("to %s (%d)\n",asctime(localtime(&dst_table[i].end)),
240                dst_table[i].zone));
241 #endif
242     }
243   }
244   return zone;
245 }
246
247 /****************************************************************************
248   return the UTC offset in seconds west of UTC, adjusted for extra time offset
249   **************************************************************************/
250 int TimeDiff(time_t t)
251 {
252   return TimeZoneFaster(t) + 60*extra_time_offset;
253 }
254
255
256 /****************************************************************************
257   return the UTC offset in seconds west of UTC, adjusted for extra time
258   offset, for a local time value.  If ut = lt + LocTimeDiff(lt), then
259   lt = ut - TimeDiff(ut), but the converse does not necessarily hold near
260   daylight savings transitions because some local times are ambiguous.
261   LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions.
262   +**************************************************************************/
263 static int LocTimeDiff(time_t lte)
264 {
265   time_t lt = lte - 60*extra_time_offset;
266   int d = TimeZoneFaster(lt);
267   time_t t = lt + d;
268
269   /* if overflow occurred, ignore all the adjustments so far */
270   if (((lte < lt) ^ (extra_time_offset < 0))  |  ((t < lt) ^ (d < 0)))
271     t = lte;
272
273   /* now t should be close enough to the true UTC to yield the right answer */
274   return TimeDiff(t);
275 }
276
277
278 /****************************************************************************
279 try to optimise the localtime call, it can be quite expensive on some machines
280 ****************************************************************************/
281 struct tm *LocalTime(time_t *t)
282 {
283   time_t t2 = *t;
284
285   t2 -= TimeDiff(t2);
286
287   return(gmtime(&t2));
288 }
289
290 #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
291
292 /****************************************************************************
293 interpret an 8 byte "filetime" structure to a time_t
294 It's originally in "100ns units since jan 1st 1601"
295
296 It appears to be kludge-GMT (at least for file listings). This means
297 its the GMT you get by taking a localtime and adding the
298 serverzone. This is NOT the same as GMT in some cases. This routine
299 converts this to real GMT.
300 ****************************************************************************/
301 time_t nt_time_to_unix(NTTIME *nt)
302 {
303   double d;
304   time_t ret;
305   /* The next two lines are a fix needed for the 
306      broken SCO compiler. JRA. */
307   time_t l_time_min = TIME_T_MIN;
308   time_t l_time_max = TIME_T_MAX;
309
310   if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff))
311           return(0);
312
313   d = ((double)nt->high)*4.0*(double)(1<<30);
314   d += (nt->low&0xFFF00000);
315   d *= 1.0e-7;
316  
317   /* now adjust by 369 years to make the secs since 1970 */
318   d -= TIME_FIXUP_CONSTANT;
319
320   if (d <= l_time_min)
321           return (l_time_min);
322
323   if (d >= l_time_max)
324           return (l_time_max);
325
326   ret = (time_t)(d+0.5);
327
328   /* this takes us from kludge-GMT to real GMT */
329   ret -= get_serverzone();
330   ret += LocTimeDiff(ret);
331
332   return(ret);
333 }
334
335 /****************************************************************************
336  Convert a NTTIME structure to a time_t.
337  It's originally in "100ns units".
338
339  This is an absolute version of the one above.
340  By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970
341  if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM
342 ****************************************************************************/
343
344 time_t nt_time_to_unix_abs(NTTIME *nt)
345 {
346         double d;
347         time_t ret;
348         /* The next two lines are a fix needed for the 
349            broken SCO compiler. JRA. */
350         time_t l_time_min = TIME_T_MIN;
351         time_t l_time_max = TIME_T_MAX;
352
353         if (nt->high == 0)
354                 return(0);
355
356         if (nt->high==0x80000000 && nt->low==0)
357                 return -1;
358
359         /* reverse the time */
360         /* it's a negative value, turn it to positive */
361         nt->high=~nt->high;
362         nt->low=~nt->low;
363
364         d = ((double)nt->high)*4.0*(double)(1<<30);
365         d += (nt->low&0xFFF00000);
366         d *= 1.0e-7;
367   
368         if (!(l_time_min <= d && d <= l_time_max))
369                 return(0);
370
371         ret = (time_t)(d+0.5);
372
373         return(ret);
374 }
375
376 /****************************************************************************
377 interprets an nt time into a unix time_t
378 ****************************************************************************/
379 time_t interpret_long_date(char *p)
380 {
381         NTTIME nt;
382         nt.low = IVAL(p,0);
383         nt.high = IVAL(p,4);
384         return nt_time_to_unix(&nt);
385 }
386
387 /****************************************************************************
388 put a 8 byte filetime from a time_t
389 This takes real GMT as input and converts to kludge-GMT
390 ****************************************************************************/
391 void unix_to_nt_time(NTTIME *nt, time_t t)
392 {
393         double d;
394
395         if (t==0)
396         {
397                 nt->low = 0;
398                 nt->high = 0;
399                 return;
400         }
401         if (t == TIME_T_MAX)
402         {
403                 nt->low = 0xffffffff;
404                 nt->high = 0x7fffffff;
405                 return;
406         }               
407         if (t == -1)
408         {
409                 nt->low = 0xffffffff;
410                 nt->high = 0xffffffff;
411                 return;
412         }               
413
414         /* this converts GMT to kludge-GMT */
415         t -= TimeDiff(t) - get_serverzone(); 
416
417         d = (double)(t);
418         d += TIME_FIXUP_CONSTANT;
419         d *= 1.0e7;
420
421         nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
422         nt->low  = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
423 }
424
425 /****************************************************************************
426  Convert a time_t to a NTTIME structure
427
428  This is an absolute version of the one above.
429  By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601
430  If the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM
431 ****************************************************************************/
432
433 void unix_to_nt_time_abs(NTTIME *nt, time_t t)
434 {
435         double d;
436
437         if (t==0) {
438                 nt->low = 0;
439                 nt->high = 0;
440                 return;
441         }
442
443         if (t == TIME_T_MAX) {
444                 nt->low = 0xffffffff;
445                 nt->high = 0x7fffffff;
446                 return;
447         }
448                 
449         if (t == -1) {
450                 /* that's what NT uses for infinite */
451                 nt->low = 0x0;
452                 nt->high = 0x80000000;
453                 return;
454         }               
455
456         d = (double)(t);
457         d *= 1.0e7;
458
459         nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
460         nt->low  = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
461
462         /* convert to a negative value */
463         nt->high=~nt->high;
464         nt->low=~nt->low;
465 }
466
467 /****************************************************************************
468 take a Unix time and convert to an NTTIME structure and place in buffer 
469 pointed to by p.
470 ****************************************************************************/
471 void put_long_date(char *p,time_t t)
472 {
473         NTTIME nt;
474         unix_to_nt_time(&nt, t);
475         SIVAL(p, 0, nt.low);
476         SIVAL(p, 4, nt.high);
477 }
478
479 /****************************************************************************
480 check if it's a null mtime
481 ****************************************************************************/
482 BOOL null_mtime(time_t mtime)
483 {
484   if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1)
485     return(True);
486   return(False);
487 }
488
489 /*******************************************************************
490   create a 16 bit dos packed date
491 ********************************************************************/
492 static uint16 make_dos_date1(struct tm *t)
493 {
494   uint16 ret=0;
495   ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1);
496   ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5));
497   return(ret);
498 }
499
500 /*******************************************************************
501   create a 16 bit dos packed time
502 ********************************************************************/
503 static uint16 make_dos_time1(struct tm *t)
504 {
505   uint16 ret=0;
506   ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3));
507   ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5));
508   return(ret);
509 }
510
511 /*******************************************************************
512   create a 32 bit dos packed date/time from some parameters
513   This takes a GMT time and returns a packed localtime structure
514 ********************************************************************/
515 static uint32 make_dos_date(time_t unixdate)
516 {
517   struct tm *t;
518   uint32 ret=0;
519
520   t = LocalTime(&unixdate);
521   if (!t)
522     return 0xFFFFFFFF;
523
524   ret = make_dos_date1(t);
525   ret = ((ret&0xFFFF)<<16) | make_dos_time1(t);
526
527   return(ret);
528 }
529
530 /*******************************************************************
531 put a dos date into a buffer (time/date format)
532 This takes GMT time and puts local time in the buffer
533 ********************************************************************/
534 void put_dos_date(char *buf,int offset,time_t unixdate)
535 {
536   uint32 x = make_dos_date(unixdate);
537   SIVAL(buf,offset,x);
538 }
539
540 /*******************************************************************
541 put a dos date into a buffer (date/time format)
542 This takes GMT time and puts local time in the buffer
543 ********************************************************************/
544 void put_dos_date2(char *buf,int offset,time_t unixdate)
545 {
546   uint32 x = make_dos_date(unixdate);
547   x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
548   SIVAL(buf,offset,x);
549 }
550
551 /*******************************************************************
552 put a dos 32 bit "unix like" date into a buffer. This routine takes
553 GMT and converts it to LOCAL time before putting it (most SMBs assume
554 localtime for this sort of date)
555 ********************************************************************/
556 void put_dos_date3(char *buf,int offset,time_t unixdate)
557 {
558   if (!null_mtime(unixdate))
559     unixdate -= TimeDiff(unixdate);
560   SIVAL(buf,offset,unixdate);
561 }
562
563 /*******************************************************************
564   interpret a 32 bit dos packed date/time to some parameters
565 ********************************************************************/
566 static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second)
567 {
568   uint32 p0,p1,p2,p3;
569
570   p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; 
571   p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF;
572
573   *second = 2*(p0 & 0x1F);
574   *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3);
575   *hour = (p1>>3)&0xFF;
576   *day = (p2&0x1F);
577   *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1;
578   *year = ((p3>>1)&0xFF) + 80;
579 }
580
581 /*******************************************************************
582   create a unix date (int GMT) from a dos date (which is actually in
583   localtime)
584 ********************************************************************/
585 time_t make_unix_date(void *date_ptr)
586 {
587   uint32 dos_date=0;
588   struct tm t;
589   time_t ret;
590
591   dos_date = IVAL(date_ptr,0);
592
593   if (dos_date == 0) return(0);
594   
595   interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon,
596                      &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec);
597   t.tm_isdst = -1;
598   
599   /* mktime() also does the local to GMT time conversion for us */
600   ret = mktime(&t);
601
602   return(ret);
603 }
604
605 /*******************************************************************
606 like make_unix_date() but the words are reversed
607 ********************************************************************/
608 time_t make_unix_date2(void *date_ptr)
609 {
610   uint32 x,x2;
611
612   x = IVAL(date_ptr,0);
613   x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
614   SIVAL(&x,0,x2);
615
616   return(make_unix_date((void *)&x));
617 }
618
619 /*******************************************************************
620   create a unix GMT date from a dos date in 32 bit "unix like" format
621   these generally arrive as localtimes, with corresponding DST
622   ******************************************************************/
623 time_t make_unix_date3(void *date_ptr)
624 {
625   time_t t = (time_t)IVAL(date_ptr,0);
626   if (!null_mtime(t))
627     t += LocTimeDiff(t);
628   return(t);
629 }
630
631
632 /***************************************************************************
633 return a HTTP/1.0 time string
634   ***************************************************************************/
635 char *http_timestring(time_t t)
636 {
637   static fstring buf;
638   struct tm *tm = LocalTime(&t);
639
640   if (!tm)
641     slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t);
642   else
643 #ifndef HAVE_STRFTIME
644   fstrcpy(buf, asctime(tm));
645   if(buf[strlen(buf)-1] == '\n')
646     buf[strlen(buf)-1] = 0;
647 #else /* !HAVE_STRFTIME */
648   strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
649 #endif /* !HAVE_STRFTIME */
650   return buf;
651 }
652
653
654
655 /****************************************************************************
656  Return the date and time as a string
657 ****************************************************************************/
658
659 char *timestring(BOOL hires)
660 {
661         static fstring TimeBuf;
662         struct timeval tp;
663         time_t t;
664         struct tm *tm;
665
666         if (hires) {
667                 GetTimeOfDay(&tp);
668                 t = (time_t)tp.tv_sec;
669         } else {
670                 t = time(NULL);
671         }
672         tm = LocalTime(&t);
673         if (!tm) {
674                 if (hires) {
675                         slprintf(TimeBuf,
676                                  sizeof(TimeBuf)-1,
677                                  "%ld.%06ld seconds since the Epoch",
678                                  (long)tp.tv_sec, 
679                                  (long)tp.tv_usec);
680                 } else {
681                         slprintf(TimeBuf,
682                                  sizeof(TimeBuf)-1,
683                                  "%ld seconds since the Epoch",
684                                  (long)t);
685                 }
686         } else {
687 #ifdef HAVE_STRFTIME
688                 if (hires) {
689                         strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
690                         slprintf(TimeBuf+strlen(TimeBuf),
691                                  sizeof(TimeBuf)-1 - strlen(TimeBuf), 
692                                  ".%06ld", 
693                                  (long)tp.tv_usec);
694                 } else {
695                         strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
696                 }
697 #else
698                 if (hires) {
699                         slprintf(TimeBuf, 
700                                  sizeof(TimeBuf)-1, 
701                                  "%s.%06ld", 
702                                  asctime(tm), 
703                                  (long)tp.tv_usec);
704                 } else {
705                         fstrcpy(TimeBuf, asctime(tm));
706                 }
707 #endif
708         }
709         return(TimeBuf);
710 }
711
712 /****************************************************************************
713   return the best approximation to a 'create time' under UNIX from a stat
714   structure.
715 ****************************************************************************/
716
717 time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs)
718 {
719   time_t ret, ret1;
720
721   if(S_ISDIR(st->st_mode) && fake_dirs)
722     return (time_t)315493200L;          /* 1/1/1980 */
723     
724   ret = MIN(st->st_ctime, st->st_mtime);
725   ret1 = MIN(ret, st->st_atime);
726
727   if(ret1 != (time_t)0)
728     return ret1;
729
730   /*
731    * One of ctime, mtime or atime was zero (probably atime).
732    * Just return MIN(ctime, mtime).
733    */
734   return ret;
735 }
736
737 /****************************************************************************
738 initialise an NTTIME to -1, which means "unknown" or "don't expire"
739 ****************************************************************************/
740
741 void init_nt_time(NTTIME *nt)
742 {
743         nt->high = 0x7FFFFFFF;
744         nt->low = 0xFFFFFFFF;
745 }
746
747 /****************************************************************************
748 check if NTTIME is 0
749 ****************************************************************************/
750 BOOL nt_time_is_zero(NTTIME *nt)
751 {
752         if(nt->high==0) 
753                 return True;
754         return False;
755 }
756
757 SMB_BIG_INT usec_time_diff(struct timeval *larget, struct timeval *smallt)
758 {
759         SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec;
760         return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec);
761 }