+/* stat has been fixed since MSVC 5.0.
+ Oh, and do not encapsulater stat for non-MS compilers, too */
+/* #### popineau@ese-metz.fr says they still might be broken.
+ Oh well... Let's add that `1 ||' condition.... --kkm */
+/* #### aichner@ecf.teradyne.com reported that with the library
+ provided stat/fstat, (file-exist "d:\\tmp\\") =>> nil,
+ (file-exist "d:\\tmp") =>> t, when d:\tmp exists. Whenever
+ we opt to use non-encapsulated stat(), this should serve as
+ a compatibility test. --kkm */
+
+#if 1 || defined(_MSC_VER) && _MSC_VER < 1100
+
+/* Since stat is encapsulated on Windows NT, we need to encapsulate
+ the equally broken fstat as well. */
+int _cdecl
+fstat (int handle, struct stat *buffer)
+{
+ int ret;
+ BY_HANDLE_FILE_INFORMATION lpFileInfo;
+ /* Initialize values */
+ buffer->st_mode = 0;
+ buffer->st_size = 0;
+ buffer->st_dev = 0;
+ buffer->st_rdev = 0;
+ buffer->st_atime = 0;
+ buffer->st_ctime = 0;
+ buffer->st_mtime = 0;
+ buffer->st_nlink = 0;
+ ret = GetFileInformationByHandle((HANDLE) _get_osfhandle(handle), &lpFileInfo);
+ if (!ret)
+ {
+ return -1;
+ }
+ else
+ {
+ buffer->st_mtime = convert_time (lpFileInfo.ftLastWriteTime);
+ buffer->st_atime = convert_time (lpFileInfo.ftLastAccessTime);
+ if (buffer->st_atime == 0) buffer->st_atime = buffer->st_mtime;
+ buffer->st_ctime = convert_time (lpFileInfo.ftCreationTime);
+ if (buffer->st_ctime == 0) buffer->st_ctime = buffer->st_mtime;
+ buffer->st_size = lpFileInfo.nFileSizeLow;
+ buffer->st_nlink = (short) lpFileInfo.nNumberOfLinks;
+ return 0;
+ }
+}
+