diff options
author | Simo Sorce <idra@samba.org> | 2008-09-03 11:52:54 -0400 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2008-09-03 11:52:54 -0400 |
commit | c5894e14771562bccd153a98610722632ca3956a (patch) | |
tree | 5ea00141df4ffa12bad3475fdafc525ffa4d92af /source3/lib/time.c | |
parent | a1de4e988d7780f687bb7ed2288faf3dfbb9da71 (diff) | |
parent | 84fca380f2040c53d20fff41972d2f4102183766 (diff) | |
download | samba-c5894e14771562bccd153a98610722632ca3956a.tar.gz samba-c5894e14771562bccd153a98610722632ca3956a.tar.bz2 samba-c5894e14771562bccd153a98610722632ca3956a.zip |
Merge branch 'v3-devel' of ssh://git.samba.org/data/git/samba into v3-devel
(This used to be commit 8e4dca3b9416d9b5e535bda5e4befc073bfc1641)
Diffstat (limited to 'source3/lib/time.c')
-rw-r--r-- | source3/lib/time.c | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/source3/lib/time.c b/source3/lib/time.c index 9db88b3fc8..8cefef6e23 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -826,14 +826,10 @@ void put_long_date(char *p, time_t t) structure. ****************************************************************************/ -time_t get_create_time(const SMB_STRUCT_STAT *st,bool fake_dirs) +static time_t calc_create_time(const SMB_STRUCT_STAT *st) { time_t ret, ret1; - if(S_ISDIR(st->st_mode) && fake_dirs) { - return (time_t)315493200L; /* 1/1/1980 */ - } - ret = MIN(st->st_ctime, st->st_mtime); ret1 = MIN(ret, st->st_atime); @@ -848,12 +844,42 @@ time_t get_create_time(const SMB_STRUCT_STAT *st,bool fake_dirs) return ret; } -struct timespec get_create_timespec(const SMB_STRUCT_STAT *st,bool fake_dirs) +/**************************************************************************** + Return the 'create time' from a stat struct if it exists (birthtime) or else + use the best approximation. +****************************************************************************/ + +struct timespec get_create_timespec(const SMB_STRUCT_STAT *pst,bool fake_dirs) { - struct timespec ts; - ts.tv_sec = get_create_time(st, fake_dirs); - ts.tv_nsec = 0; - return ts; + struct timespec ret; + + if(S_ISDIR(pst->st_mode) && fake_dirs) { + ret.tv_sec = 315493200L; /* 1/1/1980 */ + ret.tv_nsec = 0; + return ret; + } + +#if defined(HAVE_STAT_ST_BIRTHTIMESPEC) + ret = pst->st_birthtimespec; +#elif defined(HAVE_STAT_ST_BIRTHTIMENSEC) + ret.tv_sec = pst->st_birthtime; + ret.tv_nsec = pst->st_birthtimenspec; +#elif defined(HAVE_STAT_ST_BIRTHTIME) + ret.tv_sec = pst->st_birthtime; + ret.tv_nsec = 0; +#else + ret.tv_sec = calc_create_time(pst); + ret.tv_nsec = 0; +#endif + + /* Deal with systems that don't initialize birthtime correctly. + * Pointed out by SATOH Fumiyasu <fumiyas@osstech.jp>. + */ + if (null_timespec(ret)) { + ret.tv_sec = calc_create_time(pst); + ret.tv_nsec = 0; + } + return ret; } /**************************************************************************** |