comparison src/nt.c @ 592:4f6ba8f1fb3d

[xemacs-hg @ 2001-05-31 12:03:37 by adrian] [PATCH] Fix time preservation in (copy-file ...) on native Windows <1yp8gt63.fsf@rapier.ecf.teradyne.com>
author adrian
date Thu, 31 May 2001 12:03:39 +0000
parents 190b164ddcac
children 47823c2cf014
comparison
equal deleted inserted replaced
591:ec73ae6e772b 592:4f6ba8f1fb3d
26 26
27 #include <config.h> 27 #include <config.h>
28 #define getwd _getwd 28 #define getwd _getwd
29 #include "lisp.h" 29 #include "lisp.h"
30 #undef getwd 30 #undef getwd
31
32 #include "buffer.h"
31 33
32 #include "systime.h" 34 #include "systime.h"
33 #include "syssignal.h" 35 #include "syssignal.h"
34 #include "sysproc.h" 36 #include "sysproc.h"
35 #include "sysfile.h" 37 #include "sysfile.h"
1175 return rename (temp, newname); 1177 return rename (temp, newname);
1176 } 1178 }
1177 #endif /* 0 */ 1179 #endif /* 0 */
1178 1180
1179 static FILETIME utc_base_ft; 1181 static FILETIME utc_base_ft;
1182 static long double utc_base;
1180 static int init = 0; 1183 static int init = 0;
1181 1184
1182 #if 0 1185 #if 0
1183 1186
1184 static long double utc_base; 1187 static long double utc_base;
2235 2238
2236 unwind: 2239 unwind:
2237 close_file_data (&executable); 2240 close_file_data (&executable);
2238 } 2241 }
2239 2242
2243 static void
2244 convert_from_time_t (time_t time, FILETIME * pft)
2245 {
2246 long double tmp;
2247
2248 if (!init)
2249 {
2250 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
2251 SYSTEMTIME st;
2252
2253 st.wYear = 1970;
2254 st.wMonth = 1;
2255 st.wDay = 1;
2256 st.wHour = 0;
2257 st.wMinute = 0;
2258 st.wSecond = 0;
2259 st.wMilliseconds = 0;
2260
2261 SystemTimeToFileTime (&st, &utc_base_ft);
2262 utc_base = (long double) utc_base_ft.dwHighDateTime
2263 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
2264 init = 1;
2265 }
2266
2267 /* time in 100ns units since 1-Jan-1601 */
2268 tmp = (long double) time * 1e7 + utc_base;
2269 pft->dwHighDateTime = (DWORD) (tmp / (4096.0 * 1024 * 1024));
2270 pft->dwLowDateTime = (DWORD) (tmp - (4096.0 * 1024 * 1024) *
2271 pft->dwHighDateTime);
2272 }
2273
2274 int
2275 mswindows_utime (Lisp_Object path, struct utimbuf *times)
2276 {
2277 struct utimbuf deftime;
2278 HANDLE fh;
2279 static FILETIME mtime;
2280 static FILETIME atime;
2281 Extbyte *filename;
2282
2283 if (times == NULL)
2284 {
2285 deftime.modtime = deftime.actime = time (NULL);
2286 times = &deftime;
2287 }
2288
2289 LISP_STRING_TO_EXTERNAL (path, filename, Qmswindows_tstr);
2290 /* APA: SetFileTime fails to set mtime correctly (always 1-Jan-1970) */
2291 #if 0
2292 /* Need write access to set times. */
2293 fh = CreateFile (filename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
2294 0, OPEN_EXISTING, 0, NULL);
2295 if (fh)
2296 {
2297 convert_from_time_t (times->actime, &atime);
2298 convert_from_time_t (times->modtime, &mtime);
2299 if (!SetFileTime (fh, NULL, &atime, &mtime))
2300 {
2301 CloseHandle (fh);
2302 errno = EACCES;
2303 return -1;
2304 }
2305 CloseHandle (fh);
2306 }
2307 else
2308 {
2309 errno = EINVAL;
2310 return -1;
2311 }
2312 return 0;
2313 #else
2314 return utime (filename, &times);
2315 #endif
2316 }
2317
2240 /* Close the system structures associated with the given file. */ 2318 /* Close the system structures associated with the given file. */
2241 void 2319 void
2242 close_file_data (file_data *p_file) 2320 close_file_data (file_data *p_file)
2243 { 2321 {
2244 UnmapViewOfFile (p_file->file_base); 2322 UnmapViewOfFile (p_file->file_base);