sync with HEAD
[ira/wip.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 = (struct dst_table *)Realloc(dst_table,
194                                               sizeof(dst_table[0])*(i+1));
195     if (!tdt) {
196       DEBUG(0,("TimeZoneFaster: out of memory!\n"));
197       SAFE_FREE(dst_table);
198       table_size = 0;
199     } else {
200       dst_table = tdt;
201       table_size++;
202
203       dst_table[i].zone = zone; 
204       dst_table[i].start = dst_table[i].end = t;
205     
206       /* no entry will cover more than 6 months */
207       low = t - MAX_DST_WIDTH/2;
208       if (t < low)
209         low = TIME_T_MIN;
210       
211       high = t + MAX_DST_WIDTH/2;
212       if (high < t)
213         high = TIME_T_MAX;
214       
215       /* widen the new entry using two bisection searches */
216       while (low+60*60 < dst_table[i].start) {
217         if (dst_table[i].start - low > MAX_DST_SKIP*2)
218           t = dst_table[i].start - MAX_DST_SKIP;
219         else
220           t = low + (dst_table[i].start-low)/2;
221         if (TimeZone(t) == zone)
222           dst_table[i].start = t;
223         else
224           low = t;
225       }
226
227       while (high-60*60 > dst_table[i].end) {
228         if (high - dst_table[i].end > MAX_DST_SKIP*2)
229           t = dst_table[i].end + MAX_DST_SKIP;
230         else
231           t = high - (high-dst_table[i].end)/2;
232         if (TimeZone(t) == zone)
233           dst_table[i].end = t;
234         else
235           high = t;
236       }
237 #if 0
238       DEBUG(1,("Added DST entry from %s ",
239                asctime(localtime(&dst_table[i].start))));
240       DEBUG(1,("to %s (%d)\n",asctime(localtime(&dst_table[i].end)),
241                dst_table[i].zone));
242 #endif
243     }
244   }
245   return zone;
246 }
247
248 /****************************************************************************
249   return the UTC offset in seconds west of UTC, adjusted for extra time offset
250   **************************************************************************/
251 int TimeDiff(time_t t)
252 {
253   return TimeZoneFaster(t) + 60*extra_time_offset;
254 }
255
256
257 /****************************************************************************
258   return the UTC offset in seconds west of UTC, adjusted for extra time
259   offset, for a local time value.  If ut = lt + LocTimeDiff(lt), then
260   lt = ut - TimeDiff(ut), but the converse does not necessarily hold near
261   daylight savings transitions because some local times are ambiguous.
262   LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions.
263   +**************************************************************************/
264 static int LocTimeDiff(time_t lte)
265 {
266   time_t lt = lte - 60*extra_time_offset;
267   int d = TimeZoneFaster(lt);
268   time_t t = lt + d;
269
270   /* if overflow occurred, ignore all the adjustments so far */
271   if (((lte < lt) ^ (extra_time_offset < 0))  |  ((t < lt) ^ (d < 0)))
272     t = lte;
273
274   /* now t should be close enough to the true UTC to yield the right answer */
275   return TimeDiff(t);
276 }
277
278
279 /****************************************************************************
280 try to optimise the localtime call, it can be quite expensive on some machines
281 ****************************************************************************/
282 struct tm *LocalTime(time_t *t)
283 {
284   time_t t2 = *t;
285
286   t2 -= TimeDiff(t2);
287
288   return(gmtime(&t2));
289 }
290
291 #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
292
293 /****************************************************************************
294 interpret an 8 byte "filetime" structure to a time_t
295 It's originally in "100ns units since jan 1st 1601"
296
297 It appears to be kludge-GMT (at least for file listings). This means
298 its the GMT you get by taking a localtime and adding the
299 serverzone. This is NOT the same as GMT in some cases. This routine
300 converts this to real GMT.
301 ****************************************************************************/
302 time_t nt_time_to_unix(NTTIME *nt)
303 {
304   double d;
305   time_t ret;
306   /* The next two lines are a fix needed for the 
307      broken SCO compiler. JRA. */
308   time_t l_time_min = TIME_T_MIN;
309   time_t l_time_max = TIME_T_MAX;
310
311   if (nt->high == 0) 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 (!(l_time_min <= d && d <= l_time_max))
321     return(0);
322
323   ret = (time_t)(d+0.5);
324
325   /* this takes us from kludge-GMT to real GMT */
326   ret -= get_serverzone();
327   ret += LocTimeDiff(ret);
328
329   return(ret);
330 }
331
332 /****************************************************************************
333 convert a NTTIME structure to a time_t
334 It's originally in "100ns units"
335
336 this is an absolute version of the one above.
337 By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970
338 if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM
339 ****************************************************************************/
340 time_t nt_time_to_unix_abs(NTTIME *nt)
341 {
342         double d;
343         time_t ret;
344         /* The next two lines are a fix needed for the 
345            broken SCO compiler. JRA. */
346         time_t l_time_min = TIME_T_MIN;
347         time_t l_time_max = TIME_T_MAX;
348
349         if (nt->high == 0)
350                 return(0);
351
352         if (nt->high==0x80000000 && nt->low==0)
353                 return -1;
354
355         /* reverse the time */
356         /* it's a negative value, turn it to positive */
357         nt->high=~nt->high;
358         nt->low=~nt->low;
359
360         d = ((double)nt->high)*4.0*(double)(1<<30);
361         d += (nt->low&0xFFF00000);
362         d *= 1.0e-7;
363   
364         if (!(l_time_min <= d && d <= l_time_max))
365                 return(0);
366
367         ret = (time_t)(d+0.5);
368
369         /* this takes us from kludge-GMT to real GMT */
370         ret -= get_serverzone();
371         ret += LocTimeDiff(ret);
372
373         return(ret);
374 }
375
376
377
378 /****************************************************************************
379 interprets an nt time into a unix time_t
380 ****************************************************************************/
381 time_t interpret_long_date(char *p)
382 {
383         NTTIME nt;
384         nt.low = IVAL(p,0);
385         nt.high = IVAL(p,4);
386         return nt_time_to_unix(&nt);
387 }
388
389 /****************************************************************************
390 put a 8 byte filetime from a time_t
391 This takes real GMT as input and converts to kludge-GMT
392 ****************************************************************************/
393 void unix_to_nt_time(NTTIME *nt, time_t t)
394 {
395         double d;
396
397         if (t==0)
398         {
399                 nt->low = 0;
400                 nt->high = 0;
401                 return;
402         }
403         if (t == TIME_T_MAX)
404         {
405                 nt->low = 0xffffffff;
406                 nt->high = 0x7fffffff;
407                 return;
408         }               
409         if (t == -1)
410         {
411                 nt->low = 0xffffffff;
412                 nt->high = 0xffffffff;
413                 return;
414         }               
415
416         /* this converts GMT to kludge-GMT */
417         t -= TimeDiff(t) - get_serverzone(); 
418
419         d = (double)(t);
420         d += TIME_FIXUP_CONSTANT;
421         d *= 1.0e7;
422
423         nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
424         nt->low  = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
425 }
426
427 /****************************************************************************
428 convert a time_t to a NTTIME structure
429
430 this is an absolute version of the one above.
431 By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601
432 if the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM
433 ****************************************************************************/
434 void unix_to_nt_time_abs(NTTIME *nt, time_t t)
435 {
436         double d;
437
438         if (t==0) {
439                 nt->low = 0;
440                 nt->high = 0;
441                 return;
442         }
443
444         if (t == TIME_T_MAX) {
445                 nt->low = 0xffffffff;
446                 nt->high = 0x7fffffff;
447                 return;
448         }
449                 
450         if (t == -1) {
451                 /* that's what NT uses for infinite */
452                 nt->low = 0x0;
453                 nt->high = 0x80000000;
454                 return;
455         }               
456
457         /* this converts GMT to kludge-GMT */
458         t -= LocTimeDiff(t) - get_serverzone(); 
459
460         d = (double)(t);
461         d *= 1.0e7;
462
463         nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
464         nt->low  = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
465
466         /* convert to a negative value */
467         nt->high=~nt->high;
468         nt->low=~nt->low;
469 }
470
471
472 /****************************************************************************
473 take an NTTIME structure, containing high / low time.  convert to unix time.
474 lkclXXXX this may need 2 SIVALs not a memcpy.  we'll see...
475 ****************************************************************************/
476 void put_long_date(char *p,time_t t)
477 {
478         NTTIME nt;
479         unix_to_nt_time(&nt, t);
480         SIVAL(p, 0, nt.low);
481         SIVAL(p, 4, nt.high);
482 }
483
484 /****************************************************************************
485 check if it's a null mtime
486 ****************************************************************************/
487 BOOL null_mtime(time_t mtime)
488 {
489   if (mtime == 0 || mtime == 0xFFFFFFFF || mtime == (time_t)-1)
490     return(True);
491   return(False);
492 }
493
494 /*******************************************************************
495   create a 16 bit dos packed date
496 ********************************************************************/
497 static uint16 make_dos_date1(struct tm *t)
498 {
499   uint16 ret=0;
500   ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1);
501   ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5));
502   return(ret);
503 }
504
505 /*******************************************************************
506   create a 16 bit dos packed time
507 ********************************************************************/
508 static uint16 make_dos_time1(struct tm *t)
509 {
510   uint16 ret=0;
511   ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3));
512   ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5));
513   return(ret);
514 }
515
516 /*******************************************************************
517   create a 32 bit dos packed date/time from some parameters
518   This takes a GMT time and returns a packed localtime structure
519 ********************************************************************/
520 static uint32 make_dos_date(time_t unixdate)
521 {
522   struct tm *t;
523   uint32 ret=0;
524
525   t = LocalTime(&unixdate);
526   if (!t)
527     return 0xFFFFFFFF;
528
529   ret = make_dos_date1(t);
530   ret = ((ret&0xFFFF)<<16) | make_dos_time1(t);
531
532   return(ret);
533 }
534
535 /*******************************************************************
536 put a dos date into a buffer (time/date format)
537 This takes GMT time and puts local time in the buffer
538 ********************************************************************/
539 void put_dos_date(char *buf,int offset,time_t unixdate)
540 {
541   uint32 x = make_dos_date(unixdate);
542   SIVAL(buf,offset,x);
543 }
544
545 /*******************************************************************
546 put a dos date into a buffer (date/time format)
547 This takes GMT time and puts local time in the buffer
548 ********************************************************************/
549 void put_dos_date2(char *buf,int offset,time_t unixdate)
550 {
551   uint32 x = make_dos_date(unixdate);
552   x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
553   SIVAL(buf,offset,x);
554 }
555
556 /*******************************************************************
557 put a dos 32 bit "unix like" date into a buffer. This routine takes
558 GMT and converts it to LOCAL time before putting it (most SMBs assume
559 localtime for this sort of date)
560 ********************************************************************/
561 void put_dos_date3(char *buf,int offset,time_t unixdate)
562 {
563   if (!null_mtime(unixdate))
564     unixdate -= TimeDiff(unixdate);
565   SIVAL(buf,offset,unixdate);
566 }
567
568 /*******************************************************************
569   interpret a 32 bit dos packed date/time to some parameters
570 ********************************************************************/
571 static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second)
572 {
573   uint32 p0,p1,p2,p3;
574
575   p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; 
576   p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF;
577
578   *second = 2*(p0 & 0x1F);
579   *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3);
580   *hour = (p1>>3)&0xFF;
581   *day = (p2&0x1F);
582   *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1;
583   *year = ((p3>>1)&0xFF) + 80;
584 }
585
586 /*******************************************************************
587   create a unix date (int GMT) from a dos date (which is actually in
588   localtime)
589 ********************************************************************/
590 time_t make_unix_date(void *date_ptr)
591 {
592   uint32 dos_date=0;
593   struct tm t;
594   time_t ret;
595
596   dos_date = IVAL(date_ptr,0);
597
598   if (dos_date == 0) return(0);
599   
600   interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon,
601                      &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec);
602   t.tm_isdst = -1;
603   
604   /* mktime() also does the local to GMT time conversion for us */
605   ret = mktime(&t);
606
607   return(ret);
608 }
609
610 /*******************************************************************
611 like make_unix_date() but the words are reversed
612 ********************************************************************/
613 time_t make_unix_date2(void *date_ptr)
614 {
615   uint32 x,x2;
616
617   x = IVAL(date_ptr,0);
618   x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
619   SIVAL(&x,0,x2);
620
621   return(make_unix_date((void *)&x));
622 }
623
624 /*******************************************************************
625   create a unix GMT date from a dos date in 32 bit "unix like" format
626   these generally arrive as localtimes, with corresponding DST
627   ******************************************************************/
628 time_t make_unix_date3(void *date_ptr)
629 {
630   time_t t = (time_t)IVAL(date_ptr,0);
631   if (!null_mtime(t))
632     t += LocTimeDiff(t);
633   return(t);
634 }
635
636
637 /***************************************************************************
638 return a HTTP/1.0 time string
639   ***************************************************************************/
640 char *http_timestring(time_t t)
641 {
642   static fstring buf;
643   struct tm *tm = LocalTime(&t);
644
645   if (!tm)
646     slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t);
647   else
648 #ifndef HAVE_STRFTIME
649   fstrcpy(buf, asctime(tm));
650   if(buf[strlen(buf)-1] == '\n')
651     buf[strlen(buf)-1] = 0;
652 #else /* !HAVE_STRFTIME */
653   strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
654 #endif /* !HAVE_STRFTIME */
655   return buf;
656 }
657
658
659
660 /****************************************************************************
661  Return the date and time as a string
662 ****************************************************************************/
663
664 char *timestring(BOOL hires)
665 {
666         static fstring TimeBuf;
667         struct timeval tp;
668         time_t t;
669         struct tm *tm;
670
671         if (hires) {
672                 GetTimeOfDay(&tp);
673                 t = (time_t)tp.tv_sec;
674         } else {
675                 t = time(NULL);
676         }
677         tm = LocalTime(&t);
678         if (!tm) {
679                 if (hires) {
680                         slprintf(TimeBuf,
681                                  sizeof(TimeBuf)-1,
682                                  "%ld.%06ld seconds since the Epoch",
683                                  (long)tp.tv_sec, 
684                                  (long)tp.tv_usec);
685                 } else {
686                         slprintf(TimeBuf,
687                                  sizeof(TimeBuf)-1,
688                                  "%ld seconds since the Epoch",
689                                  (long)t);
690                 }
691         } else {
692 #ifdef HAVE_STRFTIME
693                 if (hires) {
694                         strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
695                         slprintf(TimeBuf+strlen(TimeBuf),
696                                  sizeof(TimeBuf)-1 - strlen(TimeBuf), 
697                                  ".%06ld", 
698                                  (long)tp.tv_usec);
699                 } else {
700                         strftime(TimeBuf,100,"%Y/%m/%d %H:%M:%S",tm);
701                 }
702 #else
703                 if (hires) {
704                         slprintf(TimeBuf, 
705                                  sizeof(TimeBuf)-1, 
706                                  "%s.%06ld", 
707                                  asctime(tm), 
708                                  (long)tp.tv_usec);
709                 } else {
710                         fstrcpy(TimeBuf, asctime(tm));
711                 }
712 #endif
713         }
714         return(TimeBuf);
715 }
716
717 /****************************************************************************
718   return the best approximation to a 'create time' under UNIX from a stat
719   structure.
720 ****************************************************************************/
721
722 time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs)
723 {
724   time_t ret, ret1;
725
726   if(S_ISDIR(st->st_mode) && fake_dirs)
727     return (time_t)315493200L;          /* 1/1/1980 */
728     
729   ret = MIN(st->st_ctime, st->st_mtime);
730   ret1 = MIN(ret, st->st_atime);
731
732   if(ret1 != (time_t)0)
733     return ret1;
734
735   /*
736    * One of ctime, mtime or atime was zero (probably atime).
737    * Just return MIN(ctime, mtime).
738    */
739   return ret;
740 }
741
742 /****************************************************************************
743 initialise an NTTIME to -1, which means "unknown" or "don't expire"
744 ****************************************************************************/
745
746 void init_nt_time(NTTIME *nt)
747 {
748         nt->high = 0x7FFFFFFF;
749         nt->low = 0xFFFFFFFF;
750 }
751
752 /****************************************************************************
753 check if NTTIME is 0
754 ****************************************************************************/
755 BOOL nt_time_is_zero(NTTIME *nt)
756 {
757         if(nt->high==0) 
758                 return True;
759         return False;
760 }