source: box/trunk/lib/common/FileModificationTime.cpp @ 3063

Revision 3063, 2.1 KB checked in by chris, 4 months ago (diff)

File modification time helper functions don't need to modify their arguments, so make them const.

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