aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Smith <dannysmith@users.sourceforge.net>2003-10-23 09:58:59 +0000
committerDanny Smith <dannysmith@users.sourceforge.net>2003-10-23 09:58:59 +0000
commit6700664fb8b4fb6855e0fc1fce05f10509624c04 (patch)
tree8e3a6c1b0c4341cf207bd4235717ef741a10680a
parente0f55604fa960f4929eab84a644b24461f5e8f84 (diff)
* 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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@72840 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ada/ChangeLog11
-rw-r--r--gcc/ada/adaint.c60
2 files changed, 51 insertions, 20 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 1eb48bf41d4..8373bfc36c3 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,14 @@
+2003-10-23 Danny Smith <dannysmith@users.sourceforge.net>
+
+ * 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.
+
2003-10-22 Danny Smith <dannysmith@users.sourceforge.net>
* sysdep.c: Include conio.h if __MINGW32__ and !OLD_MINGW.
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;