define nsec of file stat in Linux and FreeBSD

pull/6/head
yuqing 2016-02-01 15:05:35 +08:00
parent 08d3932845
commit a8b9d024e3
2 changed files with 21 additions and 0 deletions

View File

@ -116,6 +116,18 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind);
#define IS_UPPER_HEX(ch) ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F'))
#define STRERROR(no) (strerror(no) != NULL ? strerror(no) : "Unkown error")
#if defined(OS_LINUX)
#if defined __USE_MISC || defined __USE_XOPEN2K8
#define st_atimensec st_atim.tv_nsec
#define st_mtimensec st_mtim.tv_nsec
#define st_ctimensec st_ctim.tv_nsec
#endif
#elif defined(OS_FREEBSD)
#define st_atimensec st_atimespec.tv_nsec
#define st_mtimensec st_mtimespec.tv_nsec
#define st_ctimensec st_ctimespec.tv_nsec
#endif
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -4,7 +4,9 @@
#include <math.h>
#include <time.h>
#include <inttypes.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include "logger.h"
#include "shared_func.h"
#include "sched_thread.h"
@ -87,6 +89,7 @@ int main(int argc, char *argv[])
{
FastProcessInfo *processes;
struct fast_sysinfo info;
struct stat st;
get_processes(&processes, &count);
printf("process count: %d\n", count);
@ -117,7 +120,13 @@ int main(int argc, char *argv[])
printf("freeswap: %ld\n", info.freeswap);
printf("procs: %d\n", info.procs);
}
stat("/dev/null", &st);
printf("file access time: %d.%ld\n", (int)st.st_atime, st.st_atimensec);
printf("file modify time: %d.%ld\n", (int)st.st_mtime, st.st_mtimensec);
printf("file change time: %d.%ld\n", (int)st.st_ctime, st.st_ctimensec);
}
#endif
if ((result=iniLoadFromFile(filename, &iniContext)) != 0) {