From c4e6ff484c1e6a57304d14ba46852054e98e9158 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 6 Jun 2002 15:35:09 +0000 Subject: * fhandler.cc (fhandler_base::fstat): Initialise tv_nsec member of st_atim, st_mtim, and st_ctim fields. * fhandler_disk_file.cc (fhandler_disk_file::fstat_helper): Ditto. * fhandler_process.cc (fhandler_process::fstat): Ditto. * glob.c (stat32_to_STAT): Copy across the whole st_atim, st_mtime, and st_ctim fields. * syscalls.cc (stat64_to_stat32): Ditto. * times.cc (to_timestruc_t): New function. (time_as_timestruc_t): New function. * winsup.h: Add to_timestruc_t and time_as_timestruc_t functions. * include/cygwin/stat.h: Replace time_t with timestruc_t throughout for all file times, removing the st_spare1, st_spare2, and st_spare3 fields in the process. Add macros to access tv_sec fields by old names. * include/cygwin/types.h: Typedef timespec_t and timestruc_t as struct timespec. --- winsup/cygwin/times.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'winsup/cygwin/times.cc') diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc index e8a886b71..a81201e7b 100644 --- a/winsup/cygwin/times.cc +++ b/winsup/cygwin/times.cc @@ -227,6 +227,47 @@ to_time_t (FILETIME *ptr) return x; } +/* Cygwin internal */ +/* Convert a Win32 time to "UNIX" timestruc_t format. */ +void __stdcall +to_timestruc_t (FILETIME *ptr, timestruc_t *out) +{ + /* A file time is the number of 100ns since jan 1 1601 + stuffed into two long words. + A timestruc_t is the number of seconds and microseconds since jan 1 1970 + stuffed into a time_t and a long. */ + + long rem; + long long x = ((long long) ptr->dwHighDateTime << 32) + ((unsigned)ptr->dwLowDateTime); + + /* pass "no time" as epoch */ + if (x == 0) + { + out->tv_sec = 0; + out->tv_nsec = 0; + return; + } + + x -= FACTOR; /* number of 100ns between 1601 and 1970 */ + rem = x % ((long long)NSPERSEC); + x /= (long long) NSPERSEC; /* number of 100ns in a second */ + out->tv_nsec = rem * 100; /* as tv_nsec is in nanoseconds */ + out->tv_sec = x; +} + +/* Cygwin internal */ +/* Get the current time as a "UNIX" timestruc_t format. */ +void __stdcall +time_as_timestruc_t (timestruc_t * out) +{ + SYSTEMTIME systemtime; + FILETIME filetime; + + GetSystemTime (&systemtime); + SystemTimeToFileTime (&systemtime, &filetime); + to_timestruc_t (&filetime, out); +} + /* time: POSIX 4.5.1.1, C 4.12.2.4 */ /* Return number of seconds since 00:00 UTC on jan 1, 1970 */ extern "C" -- cgit v1.2.3