This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RE: Patch/Ada: Implement __gnat_set_filetime_name for w32 targets
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: "jvandyk at attglobal dot net" <jvandyk at attglobal dot net>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 21 Dec 2002 10:27:12 +1100 (EST)
- Subject: RE: Patch/Ada: Implement __gnat_set_filetime_name for w32 targets
--- Jerry van Dijk <jvandyk@attglobal.net> wrote: > > Tested on gcc version
3.3 20021219 (prerelease) with mingw32.
>
> hmmm, today:
>
> C:\home\src\gcc\gcc\ada>patch -p0 < ..\..\..\diffs\adapatch-20021220.diff
> patching file adaint.c
> Hunk #1 FAILED at 766.
> 1 out of 3 hunks FAILED -- saving rejects to file adaint.c.rej
>
Jerry is right. In order to get adaint.c to even compile without warning using
current mingw runtime and w32api distros, other changes are necessary. These
were submitted a long time ago (in March) and forgotten about by everyone
including myself.
The following revised patch applies cleanly against current CVS.
Tested on gcc version 3.3 20021219 (prerelease) with mingw32.
ChangeLog
2002-12-20 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.
(__gnat_file_time_name): Test for invalid file handle.
(__gnat_set_filetime_name): Support win32 targets using
w32api SetFileTime.
*** adaint.c.orig Fri Dec 20 08:48:32 2002
--- adaint.c Fri Dec 20 09:49:56 2002
*************** __gnat_readdir_is_thread_safe ()
*** 766,794 ****
use fstat for this purpose as the DST modify the st_mtime field of the
stat structure. */
static time_t
win32_filetime (h)
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;
}
--- 766,791 ----
use fstat for this purpose as the DST modify the st_mtime field of the
stat structure. */
+ /* Number of seconds between <Jan 1st 1601> and <Jan 1st 1970>. */
+ static const unsigned long long w32_epoch_offset = 11644473600ULL;
+
static time_t
win32_filetime (h)
HANDLE h;
{
FILETIME t_write;
unsigned long long timestamp;
/* 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>. */
! GetFileTime (h, NULL, NULL, &t_write);
timestamp = (((long long) t_write.dwHighDateTime << 32)
+ t_write.dwLowDateTime);
! timestamp = timestamp / 10000000 - w32_epoch_offset;
return (time_t) timestamp;
}
*************** __gnat_file_time_name (name)
*** 809,818 ****
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
--- 806,819 ----
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
*************** __gnat_set_file_time_name (name, time_st
*** 925,934 ****
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;
--- 926,955 ----
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;
+ } time_u;
+
+ 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> */
+ time_u.ull_time = ((unsigned long long)time_stamp + w32_epoch_offset);
+ /* Convert to 100 nanosecond units */
+ time_u.ull_time *= 10000000ULL;
+
+ SetFileTime(h, NULL, NULL, &time_u.ft_time);
+ CloseHandle (h);
+ return;
#elif defined (VMS)
struct FAB fab;
http://greetings.yahoo.com.au - Yahoo! Greetings
- Send your seasons greetings online this year!