diff options
author | Danny Smith <dannysmith@users.sourceforge.net> | 2003-10-23 09:58:59 +0000 |
---|---|---|
committer | Danny Smith <dannysmith@gcc.gnu.org> | 2003-10-23 09:58:59 +0000 |
commit | 8f4eb34be674c9a0f3f8fe9ed22516a5c622aabc (patch) | |
tree | 8e3a6c1b0c4341cf207bd4235717ef741a10680a /gcc/ada/adaint.c | |
parent | 448ec26cf73c72bc4293f99d56ac465b0d48f11d (diff) | |
download | gcc-8f4eb34be674c9a0f3f8fe9ed22516a5c622aabc.tar.gz |
adaint.c (w32_epoch_offset): Define static const at file level.
* ada/adaint.c (w32_epoch_offset): Define static const at file
level.
(win32_filetime): Replace offset with w32_epoch_offset. Use NULL
rather than t_create, t_access in call to GetFileTime. Use union
to convert between FILETIME and unsigned long long.
(__gnat_file_time_name): Test for invalid file handle.
(__gnat_set_filetime_name): Support win32 targets using
w32api SetFileTime.
From-SVN: r72840
Diffstat (limited to 'gcc/ada/adaint.c')
-rw-r--r-- | gcc/ada/adaint.c | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c index 6ad07530b8d..75020576425 100644 --- a/gcc/ada/adaint.c +++ b/gcc/ada/adaint.c @@ -792,6 +792,8 @@ __gnat_readdir_is_thread_safe () } #ifdef _WIN32 +/* Number of seconds between <Jan 1st 1601> and <Jan 1st 1970>. */ +static const unsigned long long w32_epoch_offset = 11644473600ULL; /* Returns the file modification timestamp using Win32 routines which are immune against daylight saving time change. It is in fact not possible to @@ -801,27 +803,20 @@ __gnat_readdir_is_thread_safe () static time_t win32_filetime (HANDLE h) { - BOOL res; - FILETIME t_create; - FILETIME t_access; - FILETIME t_write; - unsigned long long timestamp; - - /* Number of seconds between <Jan 1st 1601> and <Jan 1st 1970>. */ - unsigned long long offset = 11644473600; + union + { + FILETIME ft_time; + unsigned long long ull_time; + } t_write; /* GetFileTime returns FILETIME data which are the number of 100 nanosecs since <Jan 1st 1601>. This function must return the number of seconds since <Jan 1st 1970>. */ - res = GetFileTime (h, &t_create, &t_access, &t_write); - - timestamp = (((long long) t_write.dwHighDateTime << 32) - + t_write.dwLowDateTime); - - timestamp = timestamp / 10000000 - offset; - - return (time_t) timestamp; + if (GetFileTime (h, NULL, NULL, &t_write.ft_time)) + return (time_t) (t_write.ull_time / 10000000ULL + - w32_epoch_offset); + return (time_t) 0; } #endif @@ -838,10 +833,15 @@ __gnat_file_time_name (char *name) return ret; #elif defined (_WIN32) + time_t ret = 0; HANDLE h = CreateFile (name, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); - time_t ret = win32_filetime (h); - CloseHandle (h); + + if (h != INVALID_HANDLE_VALUE) + { + ret = win32_filetime (h); + CloseHandle (h); + } return ret; #else struct stat statbuf; @@ -951,11 +951,31 @@ __gnat_file_time_fd (int fd) void __gnat_set_file_time_name (char *name, time_t time_stamp) { -#if defined (__EMX__) || defined (MSDOS) || defined (_WIN32) \ - || defined (__vxworks) +#if defined (__EMX__) || defined (MSDOS) || defined (__vxworks) /* Code to implement __gnat_set_file_time_name for these systems. */ +#elif defined (_WIN32) + union + { + FILETIME ft_time; + unsigned long long ull_time; + } t_write; + + HANDLE h = CreateFile (name, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, + NULL); + if (h == INVALID_HANDLE_VALUE) + return; + /* Add number of seconds between <Jan 1st 1601> and <Jan 1st 1970> */ + t_write.ull_time = ((unsigned long long)time_stamp + w32_epoch_offset); + /* Convert to 100 nanosecond units */ + t_write.ull_time *= 10000000ULL; + + SetFileTime(h, NULL, NULL, &t_write.ft_time); + CloseHandle (h); + return; + #elif defined (VMS) struct FAB fab; struct NAM nam; |