Commit 8f4eb34b by Danny Smith Committed by Danny Smith

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
parent 448ec26c
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> 2003-10-22 Danny Smith <dannysmith@users.sourceforge.net>
* sysdep.c: Include conio.h if __MINGW32__ and !OLD_MINGW. * sysdep.c: Include conio.h if __MINGW32__ and !OLD_MINGW.
......
...@@ -792,6 +792,8 @@ __gnat_readdir_is_thread_safe () ...@@ -792,6 +792,8 @@ __gnat_readdir_is_thread_safe ()
} }
#ifdef _WIN32 #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 /* Returns the file modification timestamp using Win32 routines which are
immune against daylight saving time change. It is in fact not possible to immune against daylight saving time change. It is in fact not possible to
...@@ -801,27 +803,20 @@ __gnat_readdir_is_thread_safe () ...@@ -801,27 +803,20 @@ __gnat_readdir_is_thread_safe ()
static time_t static time_t
win32_filetime (HANDLE h) win32_filetime (HANDLE h)
{ {
BOOL res; union
FILETIME t_create; {
FILETIME t_access; FILETIME ft_time;
FILETIME t_write; unsigned long long ull_time;
unsigned long long timestamp; } t_write;
/* Number of seconds between <Jan 1st 1601> and <Jan 1st 1970>. */
unsigned long long offset = 11644473600;
/* GetFileTime returns FILETIME data which are the number of 100 nanosecs /* 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 1601>. This function must return the number of seconds
since <Jan 1st 1970>. */ since <Jan 1st 1970>. */
res = GetFileTime (h, &t_create, &t_access, &t_write); if (GetFileTime (h, NULL, NULL, &t_write.ft_time))
return (time_t) (t_write.ull_time / 10000000ULL
timestamp = (((long long) t_write.dwHighDateTime << 32) - w32_epoch_offset);
+ t_write.dwLowDateTime); return (time_t) 0;
timestamp = timestamp / 10000000 - offset;
return (time_t) timestamp;
} }
#endif #endif
...@@ -838,10 +833,15 @@ __gnat_file_time_name (char *name) ...@@ -838,10 +833,15 @@ __gnat_file_time_name (char *name)
return ret; return ret;
#elif defined (_WIN32) #elif defined (_WIN32)
time_t ret = 0;
HANDLE h = CreateFile (name, GENERIC_READ, FILE_SHARE_READ, 0, HANDLE h = CreateFile (name, GENERIC_READ, FILE_SHARE_READ, 0,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
time_t ret = win32_filetime (h);
if (h != INVALID_HANDLE_VALUE)
{
ret = win32_filetime (h);
CloseHandle (h); CloseHandle (h);
}
return ret; return ret;
#else #else
struct stat statbuf; struct stat statbuf;
...@@ -951,11 +951,31 @@ __gnat_file_time_fd (int fd) ...@@ -951,11 +951,31 @@ __gnat_file_time_fd (int fd)
void void
__gnat_set_file_time_name (char *name, time_t time_stamp) __gnat_set_file_time_name (char *name, time_t time_stamp)
{ {
#if defined (__EMX__) || defined (MSDOS) || defined (_WIN32) \ #if defined (__EMX__) || defined (MSDOS) || defined (__vxworks)
|| defined (__vxworks)
/* Code to implement __gnat_set_file_time_name for these systems. */ /* 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) #elif defined (VMS)
struct FAB fab; struct FAB fab;
struct NAM nam; struct NAM nam;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment