This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch: Ada. Fix file timestamps (gnatchop -p) for mingw32
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: charlet at act-europe dot fr
- Date: Thu, 23 Oct 2003 19:41:51 +1000 (EST)
- Subject: Patch: Ada. Fix file timestamps (gnatchop -p) for mingw32
This patch to ada/adaint.c cleans up some unneeded variables in
win32_filetime. In the call to GetFileTime we are only after the write
timestamp, so we don't need to allocate the create and access
structures, and GetFile Time has less work to do as well. I've also
change the "bitshift and add" FILETIME -> long long conversion to
the use of a union.
It also adds a w32 implementation of __gnat_set_filetime_name. The
latter allows gnatchop -p (and other apps) to correctly preserve
timestamp on output files. Currently, on mingw32, gnatchop -p creates
files with a nonsense modification timestamp (eg 12/03/1925 11:36)
that causes grief to ls.
Tested on gcc version 3.4 20031022 (experimental) with mingw32.
Danny
ChangeLog
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.
Index: adaint.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/adaint.c,v
retrieving revision 1.17
diff -c -3 -p -r1.17 adaint.c
*** adaint.c 22 Oct 2003 21:34:51 -0000 1.17
--- adaint.c 23 Oct 2003 09:20:11 -0000
*************** __gnat_readdir_is_thread_safe ()
*** 792,797 ****
--- 792,799 ----
}
#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
*************** __gnat_readdir_is_thread_safe ()
*** 801,827 ****
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;
/* 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;
}
#endif
--- 803,822 ----
static time_t
win32_filetime (HANDLE h)
{
! 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>. */
! 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
*************** __gnat_file_time_name (char *name)
*** 838,847 ****
return ret;
#elif defined (_WIN32)
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);
return ret;
#else
struct stat statbuf;
--- 833,847 ----
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);
!
! if (h != INVALID_HANDLE_VALUE)
! {
! ret = win32_filetime (h);
! CloseHandle (h);
! }
return ret;
#else
struct stat statbuf;
*************** __gnat_file_time_fd (int fd)
*** 951,960 ****
void
__gnat_set_file_time_name (char *name, time_t time_stamp)
{
! #if defined (__EMX__) || defined (MSDOS) || defined (_WIN32) \
! || defined (__vxworks)
/* Code to implement __gnat_set_file_time_name for these systems. */
#elif defined (VMS)
struct FAB fab;
--- 951,980 ----
void
__gnat_set_file_time_name (char *name, time_t time_stamp)
{
! #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;
http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.