comparison src/nt.c @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents a4f53d9b3154
children 8626e4521993
comparison
equal deleted inserted replaced
370:bd866891f083 371:cc15677e0335
1167 sys_mktemp (temp); 1167 sys_mktemp (temp);
1168 if (rename (map_win32_filename (oldname, NULL), temp) < 0) 1168 if (rename (map_win32_filename (oldname, NULL), temp) < 0)
1169 return -1; 1169 return -1;
1170 } 1170 }
1171 1171
1172 /* Emulate Unix behavior - newname is deleted if it already exists 1172 /* Emulate Unix behaviour - newname is deleted if it already exists
1173 (at least if it is a file; don't do this for directories). 1173 (at least if it is a file; don't do this for directories).
1174 However, don't do this if we are just changing the case of the file 1174 However, don't do this if we are just changing the case of the file
1175 name - we will end up deleting the file we are trying to rename! */ 1175 name - we will end up deleting the file we are trying to rename! */
1176 newname = map_win32_filename (newname, NULL); 1176 newname = map_win32_filename (newname, NULL);
1177 1177
1286 char fullname[ MAX_PATH ]; 1286 char fullname[ MAX_PATH ];
1287 char * p; 1287 char * p;
1288 unsigned hash; 1288 unsigned hash;
1289 1289
1290 /* Get the truly canonical filename, if it exists. (Note: this 1290 /* Get the truly canonical filename, if it exists. (Note: this
1291 doesn't resolve aliasing due to subst commands, or recognize hard 1291 doesn't resolve aliasing due to subst commands, or recognise hard
1292 links. */ 1292 links. */
1293 if (!win32_get_long_filename ((char *)name, fullname, MAX_PATH)) 1293 if (!win32_get_long_filename ((char *)name, fullname, MAX_PATH))
1294 abort (); 1294 abort ();
1295 1295
1296 parse_root (fullname, &p); 1296 parse_root (fullname, &p);
1298 _strlwr (p); 1298 _strlwr (p);
1299 return hashval (p); 1299 return hashval (p);
1300 } 1300 }
1301 1301
1302 #endif 1302 #endif
1303
1304 /* Since stat is encapsulated on Windows NT, we need to encapsulate
1305 the equally broken fstat as well. */
1306 int
1307 fstat (int handle, struct stat *buffer)
1308 {
1309 int ret;
1310 BY_HANDLE_FILE_INFORMATION lpFileInfo;
1311 /* Initialize values */
1312 buffer->st_mode = 0;
1313 buffer->st_size = 0;
1314 buffer->st_dev = 0;
1315 buffer->st_rdev = 0;
1316 buffer->st_atime = 0;
1317 buffer->st_ctime = 0;
1318 buffer->st_mtime = 0;
1319 buffer->st_nlink = 0;
1320 ret = GetFileInformationByHandle((HANDLE) handle, &lpFileInfo);
1321 if (!ret)
1322 {
1323 return -1;
1324 }
1325 else
1326 {
1327 buffer->st_mtime = convert_time (lpFileInfo.ftLastWriteTime);
1328 buffer->st_atime = convert_time (lpFileInfo.ftLastAccessTime);
1329 if (buffer->st_atime == 0) buffer->st_atime = buffer->st_mtime;
1330 buffer->st_ctime = convert_time (lpFileInfo.ftCreationTime);
1331 if (buffer->st_ctime == 0) buffer->st_ctime = buffer->st_mtime;
1332 buffer->st_size = lpFileInfo.nFileSizeLow;
1333 buffer->st_nlink = (short) lpFileInfo.nNumberOfLinks;
1334 return 0;
1335 }
1336 }
1337 1303
1338 /* MSVC stat function can't cope with UNC names and has other bugs, so 1304 /* MSVC stat function can't cope with UNC names and has other bugs, so
1339 replace it with our own. This also allows us to calculate consistent 1305 replace it with our own. This also allows us to calculate consistent
1340 inode values without hacks in the main Emacs code. */ 1306 inode values without hacks in the main Emacs code. */
1341 int 1307 int
1422 buf->st_nlink = 2; /* doesn't really matter */ 1388 buf->st_nlink = 2; /* doesn't really matter */
1423 fake_inode = 0; /* this doesn't either I think */ 1389 fake_inode = 0; /* this doesn't either I think */
1424 } 1390 }
1425 else if (!NILP (Vmswindows_get_true_file_attributes)) 1391 else if (!NILP (Vmswindows_get_true_file_attributes))
1426 { 1392 {
1427 /* This is more accurate in terms of getting the correct number 1393 /* This is more accurate in terms of gettting the correct number
1428 of links, but is quite slow (it is noticeable when Emacs is 1394 of links, but is quite slow (it is noticable when Emacs is
1429 making a list of file name completions). */ 1395 making a list of file name completions). */
1430 BY_HANDLE_FILE_INFORMATION info; 1396 BY_HANDLE_FILE_INFORMATION info;
1431 1397
1432 /* No access rights required to get info. */ 1398 /* No access rights required to get info. */
1433 fh = CreateFile (name, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, 1399 fh = CreateFile (name, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
1895 1861
1896 /* Zero means stop timer */ 1862 /* Zero means stop timer */
1897 if (tv->tv_sec == 0 && tv->tv_usec == 0) 1863 if (tv->tv_sec == 0 && tv->tv_usec == 0)
1898 return 0; 1864 return 0;
1899 1865
1900 /* Convert to ms and divide by denom */ 1866 /* Conver to ms and divide by denom */
1901 res = (tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000) / denom; 1867 res = (tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000) / denom;
1902 1868
1903 /* Converge to minimum timer resolution */ 1869 /* Converge to minimum timer resolution */
1904 if (time_caps.wPeriodMin == 0) 1870 if (time_caps.wPeriodMin == 0)
1905 timeGetDevCaps (&time_caps, sizeof(time_caps)); 1871 timeGetDevCaps (&time_caps, sizeof(time_caps));