This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[PATCH] GetFileAttributesEx not present on Win95
- From: Ranjit Mathew <rmathew at hotmail dot com>
- To: java-patches at gcc dot gnu dot org
- Cc: "Fernando Lozano" <fernando at lozano dot eti dot br>
- Date: Fri, 18 Oct 2002 19:49:34 +0530
- Subject: [PATCH] GetFileAttributesEx not present on Win95
Hi,
The file "libjava/java/io/natFileWin32.cc" refers
to the Win32 API GetFileAttributesEx for determining
the size of a file as well as the last time it was
modified. The issue is that this function is not
available on Windows 95 - this problem was pointed
out by Fernando Lozano to me.
This seems to make gij, rmic, rmiregistry and generated
Java programs die with an error like "GetFileAttributesEx
not present in KERNEL32.DLL".
I propose the following patch to this file to resolve
this issue if we want to also support Windows 95 as
a target:
---------------------------- 8< --------------------------
--- natFileWin32.cc Fri Oct 18 19:06:08 2002
+++ natFileWin32.cc Fri Oct 18 19:14:49 2002
@@ -84,14 +84,22 @@
JvAssert (query == MODIFIED || query == LENGTH);
- WIN32_FILE_ATTRIBUTE_DATA info;
- if (! GetFileAttributesEx(buf, GetFileExInfoStandard, &info))
+ HANDLE hFile;
+ if ( ( hFile = CreateFile( buf, GENERIC_READ, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
return 0;
- if (query == LENGTH)
- return ((long long)info.nFileSizeHigh) << 32 | (unsigned long
long)info.nFileSizeLow;
- else {
+ if (query == LENGTH) {
+ DWORD nFileSizeHigh, nFileSizeLow;
+ nFileSizeLow = GetFileSize( hFile, &nFileSizeHigh);
+ CloseHandle( hFile);
+
+ return ((long long)nFileSizeHigh) << 32 | (unsigned long
long)nFileSizeLow;
+ } else {
+ FILETIME ftLastWriteTime;
+ GetFileTime( hFile, NULL, NULL, &ftLastWriteTime);
+ CloseHandle( hFile);
+
// FIXME? This is somewhat compiler dependant (the LL constant suffix)
// The file time as return by windows is the number of
100-nanosecond intervals since January 1, 1601
- return (((((long long)info.ftLastWriteTime.dwHighDateTime) << 32) |
((unsigned long long)info.ftLastWriteTime.dwLowDateTime)) -
116444736000000000LL) / 10000LL;
+ return (((((long long)ftLastWriteTime.dwHighDateTime) << 32) |
((unsigned long long)ftLastWriteTime.dwLowDateTime)) -
116444736000000000LL) / 10000LL;
}
}
---------------------------- 8< --------------------------
A simpler alternative was to use the _stat( ) family of
functions as provided by <sys/stat.h>, but I wanted to
preserve the "flavour" of the implementation. ;-)
Can someone (Adam?) with Win32 experience please properly
review this patch and recommend it for inclusion?
Sincerely Yours,
Ranjit.
--
Ranjit Mathew Email: rmathew AT hotmail DOT com
Bangalore, INDIA. Web: http://ranjitmathew.tripod.com/