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.
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.
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.
24
This stuff was largely rewritten by Paul Eggert <eggert@twinsun.com>
28
int extra_time_offset = 0;
35
#define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \
36
: ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1))
39
#define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN)
42
/*******************************************************************
43
External access to time_t_min and time_t_max.
44
********************************************************************/
46
time_t get_time_t_max(void)
51
/*******************************************************************
52
A gettimeofday wrapper.
53
********************************************************************/
55
void GetTimeOfDay(struct timeval *tval)
57
#ifdef HAVE_GETTIMEOFDAY_TZ
58
gettimeofday(tval,NULL);
64
#define TM_YEAR_BASE 1900
66
/*******************************************************************
67
Yield the difference between *A and *B, in seconds, ignoring leap seconds.
68
********************************************************************/
70
static int tm_diff(struct tm *a, struct tm *b)
72
int ay = a->tm_year + (TM_YEAR_BASE - 1);
73
int by = b->tm_year + (TM_YEAR_BASE - 1);
74
int intervening_leap_days = (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
76
int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday);
77
int hours = 24*days + (a->tm_hour - b->tm_hour);
78
int minutes = 60*hours + (a->tm_min - b->tm_min);
79
int seconds = 60*minutes + (a->tm_sec - b->tm_sec);
84
/*******************************************************************
85
Return the UTC offset in seconds west of UTC, or 0 if it cannot be determined.
86
******************************************************************/
88
int get_time_zone(time_t t)
90
struct tm *tm = gmtime(&t);
101
return tm_diff(&tm_utc,tm) + 60*extra_time_offset;
104
/*******************************************************************
105
Accessor function for the server time zone offset.
106
set_server_zone_offset() must have been called first.
107
******************************************************************/
109
static int server_zone_offset;
111
int get_server_zone_offset(void)
113
return server_zone_offset;
116
/*******************************************************************
117
Initialize the server time zone offset. Called when a client connects.
118
******************************************************************/
120
int set_server_zone_offset(time_t t)
122
server_zone_offset = get_time_zone(t);
123
return server_zone_offset;
126
/*******************************************************************
127
Re-read the smb serverzone value.
128
******************************************************************/
130
static struct timeval start_time_hires;
134
set_server_zone_offset(time(NULL));
136
DEBUG(4,("TimeInit: Serverzone is %d\n", server_zone_offset));
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);
144
/**********************************************************************
145
Return a timeval struct of the uptime of this process. As TimeInit is
146
done before a daemon fork then this is the start time from the parent
148
***********************************************************************/
150
void get_process_uptime(struct timeval *ret_time)
152
struct timeval time_now_hires;
154
GetTimeOfDay(&time_now_hires);
155
ret_time->tv_sec = time_now_hires.tv_sec - start_time_hires.tv_sec;
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);
160
ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec;
165
/****************************************************************************
166
Return the UTC offset in seconds west of UTC, adjusted for extra time offset.
167
**************************************************************************/
169
int TimeDiff(time_t t)
171
return get_time_zone(t);
175
#define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
177
/****************************************************************************
178
Interpret an 8 byte "filetime" structure to a time_t
179
It's originally in "100ns units since jan 1st 1601"
181
An 8 byte value of 0xffffffffffffffff will be returned as (time_t)0.
184
****************************************************************************/
186
time_t nt_time_to_unix(NTTIME *nt)
190
/* The next two lines are a fix needed for the
191
broken SCO compiler. JRA. */
192
time_t l_time_min = TIME_T_MIN;
193
time_t l_time_max = TIME_T_MAX;
195
if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) {
199
d = ((double)nt->high)*4.0*(double)(1<<30);
200
d += (nt->low&0xFFF00000);
203
/* now adjust by 369 years to make the secs since 1970 */
204
d -= TIME_FIXUP_CONSTANT;
206
if (d <= l_time_min) {
210
if (d >= l_time_max) {
214
ret = (time_t)(d+0.5);
218
/****************************************************************************
219
Convert a NTTIME structure to a time_t.
220
It's originally in "100ns units".
222
This is an absolute version of the one above.
223
By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970
224
if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM
225
****************************************************************************/
227
time_t nt_time_to_unix_abs(const NTTIME *nt)
231
/* The next two lines are a fix needed for the
232
broken SCO compiler. JRA. */
233
time_t l_time_min = TIME_T_MIN;
234
time_t l_time_max = TIME_T_MAX;
241
if (nt->high==0x80000000 && nt->low==0) {
245
/* reverse the time */
246
/* it's a negative value, turn it to positive */
247
neg_nt.high=~nt->high;
250
d = ((double)neg_nt.high)*4.0*(double)(1<<30);
251
d += (neg_nt.low&0xFFF00000);
254
if (!(l_time_min <= d && d <= l_time_max)) {
258
ret = (time_t)(d+0.5);
263
/****************************************************************************
264
Interprets an nt time into a unix time_t.
265
Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff
266
will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case.
267
****************************************************************************/
269
time_t interpret_long_date(char *p)
274
if (nt.low == 0xFFFFFFFF && nt.high == 0xFFFFFFFF) {
277
return nt_time_to_unix(&nt);
280
/****************************************************************************
281
Put a 8 byte filetime from a time_t. Uses GMT.
282
****************************************************************************/
284
void unix_to_nt_time(NTTIME *nt, time_t t)
293
if (t == TIME_T_MAX) {
294
nt->low = 0xffffffff;
295
nt->high = 0x7fffffff;
298
if (t == (time_t)-1) {
299
nt->low = 0xffffffff;
300
nt->high = 0xffffffff;
305
d += TIME_FIXUP_CONSTANT;
308
nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
309
nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
312
/****************************************************************************
313
Convert a time_t to a NTTIME structure
315
This is an absolute version of the one above.
316
By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601
317
If the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM
318
****************************************************************************/
320
void unix_to_nt_time_abs(NTTIME *nt, time_t t)
330
if (t == TIME_T_MAX) {
331
nt->low = 0xffffffff;
332
nt->high = 0x7fffffff;
336
if (t == (time_t)-1) {
337
/* that's what NT uses for infinite */
339
nt->high = 0x80000000;
346
nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
347
nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
349
/* convert to a negative value */
354
/****************************************************************************
355
Take a Unix time and convert to an NTTIME structure and place in buffer
357
****************************************************************************/
359
void put_long_date(char *p, time_t t)
362
unix_to_nt_time(&nt, t);
364
SIVAL(p, 4, nt.high);
367
/****************************************************************************
368
Check if it's a null mtime.
369
****************************************************************************/
371
BOOL null_mtime(time_t mtime)
373
if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1)
378
/*******************************************************************
379
Create a 16 bit dos packed date.
380
********************************************************************/
382
static uint16 make_dos_date1(struct tm *t)
385
ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1);
386
ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5));
390
/*******************************************************************
391
Create a 16 bit dos packed time.
392
********************************************************************/
394
static uint16 make_dos_time1(struct tm *t)
397
ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3));
398
ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5));
402
/*******************************************************************
403
Create a 32 bit dos packed date/time from some parameters.
404
This takes a GMT time and returns a packed localtime structure.
405
********************************************************************/
407
static uint32 make_dos_date(time_t unixdate, int zone_offset)
416
unixdate -= zone_offset;
417
t = gmtime(&unixdate);
422
ret = make_dos_date1(t);
423
ret = ((ret&0xFFFF)<<16) | make_dos_time1(t);
428
/*******************************************************************
429
Put a dos date into a buffer (time/date format).
430
This takes GMT time and puts local time in the buffer.
431
********************************************************************/
433
static void put_dos_date(char *buf,int offset,time_t unixdate, int zone_offset)
435
uint32 x = make_dos_date(unixdate, zone_offset);
439
/*******************************************************************
440
Put a dos date into a buffer (date/time format).
441
This takes GMT time and puts local time in the buffer.
442
********************************************************************/
444
static void put_dos_date2(char *buf,int offset,time_t unixdate, int zone_offset)
446
uint32 x = make_dos_date(unixdate, zone_offset);
447
x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
451
/*******************************************************************
452
Put a dos 32 bit "unix like" date into a buffer. This routine takes
453
GMT and converts it to LOCAL time before putting it (most SMBs assume
454
localtime for this sort of date)
455
********************************************************************/
457
static void put_dos_date3(char *buf,int offset,time_t unixdate, int zone_offset)
459
if (!null_mtime(unixdate)) {
460
unixdate -= zone_offset;
462
SIVAL(buf,offset,unixdate);
465
/*******************************************************************
466
Interpret a 32 bit dos packed date/time to some parameters.
467
********************************************************************/
469
static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second)
473
p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF;
474
p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF;
476
*second = 2*(p0 & 0x1F);
477
*minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3);
478
*hour = (p1>>3)&0xFF;
480
*month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1;
481
*year = ((p3>>1)&0xFF) + 80;
484
/*******************************************************************
485
Create a unix date (int GMT) from a dos date (which is actually in
487
********************************************************************/
489
static time_t make_unix_date(void *date_ptr, int zone_offset)
495
dos_date = IVAL(date_ptr,0);
501
interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon,
502
&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec);
512
/*******************************************************************
513
Like make_unix_date() but the words are reversed.
514
********************************************************************/
516
static time_t make_unix_date2(void *date_ptr, int zone_offset)
520
x = IVAL(date_ptr,0);
521
x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
524
return(make_unix_date((void *)&x, zone_offset));
527
/*******************************************************************
528
Create a unix GMT date from a dos date in 32 bit "unix like" format
529
these generally arrive as localtimes, with corresponding DST.
530
******************************************************************/
532
static time_t make_unix_date3(void *date_ptr, int zone_offset)
534
time_t t = (time_t)IVAL(date_ptr,0);
535
if (!null_mtime(t)) {
541
/***************************************************************************
542
Server versions of the above functions.
543
***************************************************************************/
545
void srv_put_dos_date(char *buf,int offset,time_t unixdate)
547
put_dos_date(buf, offset, unixdate, server_zone_offset);
550
void srv_put_dos_date2(char *buf,int offset, time_t unixdate)
552
put_dos_date2(buf, offset, unixdate, server_zone_offset);
555
void srv_put_dos_date3(char *buf,int offset,time_t unixdate)
557
put_dos_date3(buf, offset, unixdate, server_zone_offset);
560
time_t srv_make_unix_date(void *date_ptr)
562
return make_unix_date(date_ptr, server_zone_offset);
565
time_t srv_make_unix_date2(void *date_ptr)
567
return make_unix_date2(date_ptr, server_zone_offset);
570
time_t srv_make_unix_date3(void *date_ptr)
572
return make_unix_date3(date_ptr, server_zone_offset);
575
/***************************************************************************
576
Client versions of the above functions.
577
***************************************************************************/
579
void cli_put_dos_date(struct cli_state *cli, char *buf, int offset, time_t unixdate)
581
put_dos_date(buf, offset, unixdate, cli->serverzone);
584
void cli_put_dos_date2(struct cli_state *cli, char *buf, int offset, time_t unixdate)
586
put_dos_date2(buf, offset, unixdate, cli->serverzone);
589
void cli_put_dos_date3(struct cli_state *cli, char *buf, int offset, time_t unixdate)
591
put_dos_date3(buf, offset, unixdate, cli->serverzone);
594
time_t cli_make_unix_date(struct cli_state *cli, void *date_ptr)
596
return make_unix_date(date_ptr, cli->serverzone);
599
time_t cli_make_unix_date2(struct cli_state *cli, void *date_ptr)
601
return make_unix_date2(date_ptr, cli->serverzone);
604
time_t cli_make_unix_date3(struct cli_state *cli, void *date_ptr)
606
return make_unix_date3(date_ptr, cli->serverzone);
609
/***************************************************************************
610
Return a HTTP/1.0 time string.
611
***************************************************************************/
613
char *http_timestring(time_t t)
616
struct tm *tm = localtime(&t);
619
slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t);
621
#ifndef HAVE_STRFTIME
622
const char *asct = asctime(tm);
623
fstrcpy(buf, asct ? asct : "unknown");
625
if(buf[strlen(buf)-1] == '\n') {
626
buf[strlen(buf)-1] = 0;
627
#else /* !HAVE_STRFTIME */
628
strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm);
629
#endif /* !HAVE_STRFTIME */
634
/****************************************************************************
635
Return the date and time as a string
636
****************************************************************************/
638
char *current_timestring(BOOL hires)
640
static fstring TimeBuf;
647
t = (time_t)tp.tv_sec;
656
"%ld.%06ld seconds since the Epoch",
662
"%ld seconds since the Epoch",
668
strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
669
slprintf(TimeBuf+strlen(TimeBuf),
670
sizeof(TimeBuf)-1 - strlen(TimeBuf),
674
strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm);
678
const char *asct = asctime(tm);
682
asct ? asct : "unknown",
685
const char *asct = asctime(tm);
686
fstrcpy(TimeBuf, asct ? asct : "unknown");
693
/****************************************************************************
694
Return the best approximation to a 'create time' under UNIX from a stat
696
****************************************************************************/
698
time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs)
702
if(S_ISDIR(st->st_mode) && fake_dirs) {
703
return (time_t)315493200L; /* 1/1/1980 */
706
ret = MIN(st->st_ctime, st->st_mtime);
707
ret1 = MIN(ret, st->st_atime);
709
if(ret1 != (time_t)0) {
714
* One of ctime, mtime or atime was zero (probably atime).
715
* Just return MIN(ctime, mtime).
720
/****************************************************************************
721
Initialise an NTTIME to -1, which means "unknown" or "don't expire".
722
****************************************************************************/
724
void init_nt_time(NTTIME *nt)
726
nt->high = 0x7FFFFFFF;
727
nt->low = 0xFFFFFFFF;
730
BOOL nt_time_is_set(const NTTIME *nt)
732
if ((nt->high == 0x7FFFFFFF) && (nt->low == 0xFFFFFFFF)) {
736
if ((nt->high == 0x80000000) && (nt->low == 0)) {
743
/****************************************************************************
744
Check if NTTIME is 0.
745
****************************************************************************/
747
BOOL nt_time_is_zero(const NTTIME *nt)
755
/****************************************************************************
756
Check if two NTTIMEs are the same.
757
****************************************************************************/
759
BOOL nt_time_equals(const NTTIME *nt1, const NTTIME *nt2)
761
return (nt1->high == nt2->high && nt1->low == nt2->low);
764
/****************************************************************************
765
Return a timeval difference in usec.
766
****************************************************************************/
768
SMB_BIG_INT usec_time_diff(const struct timeval *larget, const struct timeval *smallt)
770
SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec;
771
return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec);
774
/****************************************************************************
775
Return a timeval struct with the given elements.
776
****************************************************************************/
778
struct timeval timeval_set(uint32_t secs, uint32_t usecs)
786
/****************************************************************************
787
Return a zero timeval.
788
****************************************************************************/
790
struct timeval timeval_zero(void)
792
return timeval_set(0,0);
795
/****************************************************************************
796
Return True if a timeval is zero.
797
****************************************************************************/
799
BOOL timeval_is_zero(const struct timeval *tv)
801
return tv->tv_sec == 0 && tv->tv_usec == 0;
804
/****************************************************************************
805
Return a timeval for the current time.
806
****************************************************************************/
808
struct timeval timeval_current(void)
815
/****************************************************************************
816
Return a timeval ofs microseconds after tv.
817
****************************************************************************/
819
struct timeval timeval_add(const struct timeval *tv,
820
uint32_t secs, uint32_t usecs)
822
struct timeval tv2 = *tv;
824
tv2.tv_usec += usecs;
825
tv2.tv_sec += tv2.tv_usec / 1000000;
826
tv2.tv_usec = tv2.tv_usec % 1000000;
830
/****************************************************************************
831
Return the sum of two timeval structures.
832
****************************************************************************/
834
struct timeval timeval_sum(const struct timeval *tv1,
835
const struct timeval *tv2)
837
return timeval_add(tv1, tv2->tv_sec, tv2->tv_usec);
840
/****************************************************************************
841
Return a timeval secs/usecs into the future.
842
****************************************************************************/
844
struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs)
846
struct timeval tv = timeval_current();
847
return timeval_add(&tv, secs, usecs);
850
/****************************************************************************
851
Compare two timeval structures.
852
Return -1 if tv1 < tv2
853
Return 0 if tv1 == tv2
854
Return 1 if tv1 > tv2
855
****************************************************************************/
857
int timeval_compare(const struct timeval *tv1, const struct timeval *tv2)
859
if (tv1->tv_sec > tv2->tv_sec) {
862
if (tv1->tv_sec < tv2->tv_sec) {
865
if (tv1->tv_usec > tv2->tv_usec) {
868
if (tv1->tv_usec < tv2->tv_usec) {
874
/****************************************************************************
875
Return the difference between two timevals as a timeval.
876
If tv1 comes after tv2, then return a zero timeval
877
(this is *tv2 - *tv1).
878
****************************************************************************/
880
struct timeval timeval_until(const struct timeval *tv1,
881
const struct timeval *tv2)
884
if (timeval_compare(tv1, tv2) >= 0) {
885
return timeval_zero();
887
t.tv_sec = tv2->tv_sec - tv1->tv_sec;
888
if (tv1->tv_usec > tv2->tv_usec) {
890
t.tv_usec = 1000000 - (tv1->tv_usec - tv2->tv_usec);
892
t.tv_usec = tv2->tv_usec - tv1->tv_usec;
897
/****************************************************************************
898
Return the lesser of two timevals.
899
****************************************************************************/
901
struct timeval timeval_min(const struct timeval *tv1,
902
const struct timeval *tv2)
904
if (tv1->tv_sec < tv2->tv_sec) {
907
if (tv1->tv_sec > tv2->tv_sec) {
910
if (tv1->tv_usec < tv2->tv_usec) {
916
/****************************************************************************
917
Return the greater of two timevals.
918
****************************************************************************/
920
struct timeval timeval_max(const struct timeval *tv1,
921
const struct timeval *tv2)
923
if (tv1->tv_sec > tv2->tv_sec) {
926
if (tv1->tv_sec < tv2->tv_sec) {
929
if (tv1->tv_usec > tv2->tv_usec) {
935
/****************************************************************************
936
Convert ASN.1 GeneralizedTime string to unix-time.
937
Returns 0 on failure; Currently ignores timezone.
938
****************************************************************************/
940
time_t generalized_to_unix_time(const char *str)
946
if (sscanf(str, "%4d%2d%2d%2d%2d%2d",
947
&tm.tm_year, &tm.tm_mon, &tm.tm_mday,
948
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
957
/****************************************************************************
958
Return all the possible time fields from a stat struct as a timespec.
959
****************************************************************************/
961
struct timespec get_atimespec(SMB_STRUCT_STAT *pst)
963
#if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
966
/* Old system - no ns timestamp. */
967
ret.tv_sec = pst->st_atime;
971
#if defined(HAVE_STAT_ST_ATIM)
973
#elif defined(HAVE_STAT_ST_ATIMENSEC)
975
ret.tv_sec = pst->st_atime;
976
ret.tv_nsec = pst->st_atimensec;
979
#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
984
struct timespec get_mtimespec(SMB_STRUCT_STAT *pst)
986
#if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
989
/* Old system - no ns timestamp. */
990
ret.tv_sec = pst->st_mtime;
994
#if defined(HAVE_STAT_ST_MTIM)
996
#elif defined(HAVE_STAT_ST_MTIMENSEC)
998
ret.tv_sec = pst->st_mtime;
999
ret.tv_nsec = pst->st_mtimensec;
1002
#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
1007
struct timespec get_ctimespec(SMB_STRUCT_STAT *pst)
1009
#if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
1010
struct timespec ret;
1012
/* Old system - no ns timestamp. */
1013
ret.tv_sec = pst->st_ctime;
1017
#if defined(HAVE_STAT_ST_CTIM)
1018
return pst->st_ctim;
1019
#elif defined(HAVE_STAT_ST_CTIMENSEC)
1020
struct timespec ret;
1021
ret.tv_sec = pst->st_ctime;
1022
ret.tv_nsec = pst->st_ctimensec;
1025
#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
1031
/****************************************************************************
1032
Return the best approximation to a 'create time' under UNIX from a stat
1034
****************************************************************************/
1036
struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs)
1040
if(S_ISDIR(st->st_mode) && fake_dirs) {
1041
return (time_t)315493200L; /* 1/1/1980 */
1044
ret = MIN(st->st_ctime, st->st_mtime);
1045
ret1 = MIN(ret, st->st_atime);
1047
if(ret1 != (time_t)0) {
1052
* One of ctime, mtime or atime was zero (probably atime).
1053
* Just return MIN(ctime, mtime).
1061
Return the date and time as a string
1063
char *timestring(TALLOC_CTX *mem_ctx, time_t t)
1071
return talloc_asprintf(mem_ctx,
1072
"%ld seconds since the Epoch",
1076
#ifdef HAVE_STRFTIME
1077
/* some versions of gcc complain about using %c. This is a bug
1078
in the gcc warning, not a bug in this code. See a recent
1079
strftime() manual page for details.
1081
strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm);
1082
TimeBuf = talloc_strdup(mem_ctx, tempTime);
1084
TimeBuf = talloc_strdup(mem_ctx, asctime(tm));
1092
return a talloced string representing a NTTIME for human consumption
1094
const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt)
1097
if (nt.low == 0 && nt.high == 0) {
1100
t = nt_time_to_unix(&nt);
1101
return timestring(mem_ctx, t);
1104
/****************************************************************************
1105
Utility function that always returns a const string even if localtime
1107
****************************************************************************/
1109
const char *time_to_asc(const time_t *t)
1112
struct tm *lt = localtime(t);
1115
return "unknown time";
1120
return "unknown time";