00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef STAT_TIME_H
00022 #define STAT_TIME_H 1
00023
00024 #include <sys/stat.h>
00025 #include <time.h>
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #if defined HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
00036 # ifdef TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC
00037 # define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim)
00038 # else
00039 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.tv_nsec)
00040 # endif
00041 #elif defined HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC
00042 # define STAT_TIMESPEC(st, st_xtim) ((st)->st_xtim##espec)
00043 #elif defined HAVE_STRUCT_STAT_ST_ATIMENSEC
00044 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim##ensec)
00045 #elif defined HAVE_STRUCT_STAT_ST_ATIM_ST__TIM_TV_NSEC
00046 # define STAT_TIMESPEC_NS(st, st_xtim) ((st)->st_xtim.st__tim.tv_nsec)
00047 #endif
00048
00049
00050 static inline long int
00051 get_stat_atime_ns (struct stat const *st)
00052 {
00053 # if defined STAT_TIMESPEC
00054 return STAT_TIMESPEC (st, st_atim).tv_nsec;
00055 # elif defined STAT_TIMESPEC_NS
00056 return STAT_TIMESPEC_NS (st, st_atim);
00057 # else
00058 return 0;
00059 # endif
00060 }
00061
00062
00063 static inline long int
00064 get_stat_ctime_ns (struct stat const *st)
00065 {
00066 # if defined STAT_TIMESPEC
00067 return STAT_TIMESPEC (st, st_ctim).tv_nsec;
00068 # elif defined STAT_TIMESPEC_NS
00069 return STAT_TIMESPEC_NS (st, st_ctim);
00070 # else
00071 return 0;
00072 # endif
00073 }
00074
00075
00076 static inline long int
00077 get_stat_mtime_ns (struct stat const *st)
00078 {
00079 # if defined STAT_TIMESPEC
00080 return STAT_TIMESPEC (st, st_mtim).tv_nsec;
00081 # elif defined STAT_TIMESPEC_NS
00082 return STAT_TIMESPEC_NS (st, st_mtim);
00083 # else
00084 return 0;
00085 # endif
00086 }
00087
00088
00089 static inline long int
00090 get_stat_birthtime_ns (struct stat const *st)
00091 {
00092 # if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
00093 return STAT_TIMESPEC (st, st_birthtim).tv_nsec;
00094 # elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
00095 return STAT_TIMESPEC_NS (st, st_birthtim);
00096 # else
00097 return 0;
00098 # endif
00099 }
00100
00101
00102 static inline struct timespec
00103 get_stat_atime (struct stat const *st)
00104 {
00105 #ifdef STAT_TIMESPEC
00106 return STAT_TIMESPEC (st, st_atim);
00107 #else
00108 struct timespec t;
00109 t.tv_sec = st->st_atime;
00110 t.tv_nsec = get_stat_atime_ns (st);
00111 return t;
00112 #endif
00113 }
00114
00115
00116 static inline struct timespec
00117 get_stat_ctime (struct stat const *st)
00118 {
00119 #ifdef STAT_TIMESPEC
00120 return STAT_TIMESPEC (st, st_ctim);
00121 #else
00122 struct timespec t;
00123 t.tv_sec = st->st_ctime;
00124 t.tv_nsec = get_stat_ctime_ns (st);
00125 return t;
00126 #endif
00127 }
00128
00129
00130 static inline struct timespec
00131 get_stat_mtime (struct stat const *st)
00132 {
00133 #ifdef STAT_TIMESPEC
00134 return STAT_TIMESPEC (st, st_mtim);
00135 #else
00136 struct timespec t;
00137 t.tv_sec = st->st_mtime;
00138 t.tv_nsec = get_stat_mtime_ns (st);
00139 return t;
00140 #endif
00141 }
00142
00143
00144
00145 static inline struct timespec
00146 get_stat_birthtime (struct stat const *st)
00147 {
00148 struct timespec t;
00149
00150 #if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
00151 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC)
00152 t = STAT_TIMESPEC (st, st_birthtim);
00153 #elif defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC
00154 t.tv_sec = st->st_birthtime;
00155 t.tv_nsec = st->st_birthtimensec;
00156 #elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
00157
00158
00159
00160 t.tv_sec = st->st_ctime;
00161 t.tv_nsec = 0;
00162 #else
00163
00164 t.tv_sec = -1;
00165 t.tv_nsec = -1;
00166 #endif
00167
00168 #if (defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC \
00169 || defined HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC \
00170 || defined HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
00171
00172
00173
00174
00175
00176
00177 if (t.tv_sec == 0 || 1000000000 <= t.tv_nsec)
00178 t.tv_nsec = -1;
00179 #endif
00180
00181 return t;
00182 }
00183
00184 #endif