From 35a3672c3146a82d4e75cf26f7060695c5cb00b8 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 30 May 2008 03:54:37 +0000 Subject: [PATCH] move FileTimeToTime from sigar_os.h to win32_sigar.c --- src/os/win32/sigar_os.h | 13 ++----------- src/os/win32/win32_sigar.c | 18 +++++++++++++++--- src/sigar_fileinfo.c | 11 +++++++---- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h index c5555a5a..479dd160 100644 --- a/src/os/win32/sigar_os.h +++ b/src/os/win32/sigar_os.h @@ -45,17 +45,6 @@ #define SIGAR_CMDLINE_MAX 4096 -static __inline sigar_uint64_t FileTimeToTime(FILETIME *ft) -{ - sigar_uint64_t time; - time = ft->dwHighDateTime; - time = time << 32; - time |= ft->dwLowDateTime; - time /= 10; - time -= EPOCH_DELTA; - return time; -} - /* XXX: support CP_UTF8 ? */ #define SIGAR_A2W(lpa, lpw, bytes) \ @@ -569,6 +558,8 @@ struct sigar_t { extern "C" { #endif +sigar_uint64_t sigar_FileTimeToTime(FILETIME *ft); + int sigar_wsa_init(sigar_t *sigar); int sigar_proc_exe_peb_get(sigar_t *sigar, HANDLE proc, diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index 34ac3c20..47949e5c 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -122,6 +122,17 @@ typedef enum { #define MS_LOOPBACK_ADAPTER "Microsoft Loopback Adapter" #define NETIF_LA "la" +sigar_uint64_t sigar_FileTimeToTime(FILETIME *ft) +{ + sigar_uint64_t time; + time = ft->dwHighDateTime; + time = time << 32; + time |= ft->dwLowDateTime; + time /= 10; + time -= EPOCH_DELTA; + return time; +} + static DWORD perfbuf_init(sigar_t *sigar) { if (!sigar->perfbuf) { @@ -1244,7 +1255,8 @@ SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid, } if (start_time.dwHighDateTime) { - proctime->start_time = FileTimeToTime(&start_time) / 1000; + proctime->start_time = + sigar_FileTimeToTime(&start_time) / 1000; } else { proctime->start_time = 0; @@ -3126,7 +3138,7 @@ static int get_logon_info(HKEY users, if (status == ERROR_SUCCESS) { FileTimeToLocalFileTime(&wtime, &wtime); - who->time = FileTimeToTime(&wtime) / 1000000; + who->time = sigar_FileTimeToTime(&wtime) / 1000000; } size = sizeof(value); @@ -3334,7 +3346,7 @@ static int sigar_who_wts(sigar_t *sigar, &bytes)) { who->time = - FileTimeToTime(&station_info.ConnectTime) / 1000000; + sigar_FileTimeToTime(&station_info.ConnectTime) / 1000000; } else { who->time = 0; diff --git a/src/sigar_fileinfo.c b/src/sigar_fileinfo.c index aedb718d..e48f8ceb 100644 --- a/src/sigar_fileinfo.c +++ b/src/sigar_fileinfo.c @@ -67,7 +67,10 @@ memset(s, '\0', sizeof(*(s))) #endif -#ifndef WIN32 +#ifdef WIN32 +#include +sigar_uint64_t sigar_FileTimeToTime(FILETIME *ft); +#else #include #endif @@ -192,9 +195,9 @@ static void fillin_fileattrs(sigar_file_attrs_t *finfo, { DWORD *sizes = &wininfo->nFileSizeHigh; - finfo->atime = FileTimeToTime(&wininfo->ftLastAccessTime) / 1000; - finfo->ctime = FileTimeToTime(&wininfo->ftCreationTime) / 1000; - finfo->mtime = FileTimeToTime(&wininfo->ftLastWriteTime) / 1000; + finfo->atime = sigar_FileTimeToTime(&wininfo->ftLastAccessTime) / 1000; + finfo->ctime = sigar_FileTimeToTime(&wininfo->ftCreationTime) / 1000; + finfo->mtime = sigar_FileTimeToTime(&wininfo->ftLastWriteTime) / 1000; finfo->size = (sigar_uint64_t)sizes[1]; if (finfo->size < 0 || sizes[0]) {