1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
// --------------------------------------------------------------------------
//
// File
// Name: FileModificationTime.cpp
// Purpose: Function for getting file modification time.
// Created: 2010/02/15
//
// --------------------------------------------------------------------------
#include "Box.h"
#include <sys/stat.h>
#include "BoxTime.h"
#include "FileModificationTime.h"
#include "MemLeakFindOn.h"
box_time_t FileModificationTime(const EMU_STRUCT_STAT &st)
{
#if defined HAVE_STRUCT_STAT_ST_ATIM
box_time_t datamodified = (((int64_t)st.st_mtim.tv_nsec) / NANO_SEC_IN_USEC_LL)
+ (((int64_t)st.st_mtim.tv_sec) * (MICRO_SEC_IN_SEC_LL));
#elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC
box_time_t datamodified = (((int64_t)st.st_mtimespec.tv_nsec) / NANO_SEC_IN_USEC_LL)
+ (((int64_t)st.st_mtimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL));
#else
box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL);
#endif
return datamodified;
}
box_time_t FileAttrModificationTime(const EMU_STRUCT_STAT &st)
{
box_time_t statusmodified =
#if defined HAVE_STRUCT_STAT_ST_ATIM
(((int64_t)st.st_ctim.tv_nsec) / (NANO_SEC_IN_USEC_LL)) +
(((int64_t)st.st_ctim.tv_sec) * (MICRO_SEC_IN_SEC_LL));
#elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC
(((int64_t)st.st_ctimespec.tv_nsec) / (NANO_SEC_IN_USEC_LL)) +
(((int64_t)st.st_ctimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL));
#elif defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
(((int64_t)st.st_ctim.tv_nsec) / (NANO_SEC_IN_USEC_LL)) +
(((int64_t)st.st_ctim.tv_sec) * (MICRO_SEC_IN_SEC_LL));
#elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC
(((int64_t)st.st_ctimensec) / (NANO_SEC_IN_USEC_LL)) +
(((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL));
#else // no nanoseconds anywhere
(((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL));
#endif
return statusmodified;
}
box_time_t FileModificationTimeMaxModAndAttr(const EMU_STRUCT_STAT &st)
{
#ifndef HAVE_STRUCT_STAT_ST_MTIMESPEC
box_time_t datamodified = ((int64_t)st.st_mtime) * (MICRO_SEC_IN_SEC_LL);
box_time_t statusmodified = ((int64_t)st.st_ctime) * (MICRO_SEC_IN_SEC_LL);
#else
box_time_t datamodified = (((int64_t)st.st_mtimespec.tv_nsec) / NANO_SEC_IN_USEC_LL)
+ (((int64_t)st.st_mtimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL));
box_time_t statusmodified = (((int64_t)st.st_ctimespec.tv_nsec) / NANO_SEC_IN_USEC_LL)
+ (((int64_t)st.st_ctimespec.tv_sec) * (MICRO_SEC_IN_SEC_LL));
#endif
return (datamodified > statusmodified)?datamodified:statusmodified;
}
|