771
|
1 /* Utility and Unix shadow routines under MS Windows (WIN32_NATIVE defined).
|
428
|
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
771
|
3 Copyright (C) 2000, 2001, 2002 Ben Wing.
|
428
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to the Free
|
|
19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
20 02111-1307, USA.
|
|
21
|
771
|
22 */
|
428
|
23
|
771
|
24 /* Authorship:
|
428
|
25
|
771
|
26 Geoff Voelker (voelker@cs.washington.edu) 7-29-94
|
|
27 Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au>
|
|
28 Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org>
|
|
29 (Note: Sync messages from Marc Paquette may indicate
|
|
30 incomplete synching, so beware.)
|
|
31 Synched (completely!) with Emacs 20.6 by Ben Wing, 6-23-00.
|
|
32 Largely rewritten by Ben Wing for XEmacs Mule support.
|
|
33 Synched (completely!) with Emacs 21.1.103 by Ben Wing, 6-13-01.
|
|
34 */
|
|
35
|
|
36 /* This file Mule-ized by Ben Wing, 6-23-00. */
|
428
|
37
|
|
38 #include <config.h>
|
|
39 #include "lisp.h"
|
|
40
|
592
|
41 #include "buffer.h"
|
|
42
|
428
|
43 #include "systime.h"
|
|
44 #include "syssignal.h"
|
|
45 #include "sysproc.h"
|
|
46 #include "sysfile.h"
|
442
|
47 #include "syspwd.h"
|
|
48 #include "sysdir.h"
|
428
|
49
|
442
|
50 #include "syswindows.h"
|
428
|
51
|
771
|
52 /* Control whether stat() attempts to determine file type and link count
|
|
53 exactly, at the expense of slower operation. Since true hard links
|
|
54 are supported on NTFS volumes, this is only relevant on NT. */
|
|
55 Lisp_Object Vmswindows_get_true_file_attributes;
|
428
|
56
|
771
|
57 /* Vmswindows_generate_fake_inodes; deleted */
|
|
58
|
|
59 Fixnum mswindows_fake_unix_uid;
|
428
|
60
|
|
61 /* Emulate getpwuid, getpwnam and others. */
|
|
62
|
771
|
63 static struct passwd the_passwd =
|
428
|
64 {
|
771
|
65 "",
|
|
66 "",
|
428
|
67 0,
|
|
68 0,
|
|
69 0,
|
771
|
70 "",
|
|
71 "",
|
|
72 "",
|
428
|
73 };
|
|
74
|
|
75 uid_t
|
442
|
76 getuid (void)
|
440
|
77 {
|
771
|
78 return mswindows_fake_unix_uid;
|
428
|
79 }
|
|
80
|
|
81 uid_t
|
442
|
82 geteuid (void)
|
428
|
83 {
|
771
|
84 /* Emacs 20.6 says: [[I could imagine arguing for checking to see
|
|
85 whether the user is in the Administrators group and returning a
|
|
86 UID of 0 for that case, but I don't know how wise that would be
|
|
87 in the long run.]] */
|
|
88 return mswindows_fake_unix_uid;
|
428
|
89 }
|
|
90
|
|
91 gid_t
|
442
|
92 getgid (void)
|
428
|
93 {
|
|
94 return the_passwd.pw_gid;
|
|
95 }
|
|
96
|
|
97 gid_t
|
442
|
98 getegid (void)
|
428
|
99 {
|
|
100 return getgid ();
|
|
101 }
|
|
102
|
|
103 struct passwd *
|
|
104 getpwuid (uid_t uid)
|
|
105 {
|
771
|
106 if (uid == mswindows_fake_unix_uid)
|
440
|
107 {
|
|
108 the_passwd.pw_gid = the_passwd.pw_uid = uid;
|
|
109 return &the_passwd;
|
|
110 }
|
|
111 else
|
|
112 return NULL;
|
428
|
113 }
|
|
114
|
|
115 struct passwd *
|
771
|
116 getpwnam (const Intbyte *name)
|
428
|
117 {
|
|
118 struct passwd *pw;
|
|
119
|
|
120 pw = getpwuid (getuid ());
|
|
121 if (!pw)
|
|
122 return pw;
|
|
123
|
771
|
124 if (qxestrcasecmp_i18n (name, pw->pw_name))
|
428
|
125 return NULL;
|
|
126
|
|
127 return pw;
|
|
128 }
|
|
129
|
771
|
130 static void
|
442
|
131 init_user_info (void)
|
428
|
132 {
|
440
|
133 /* This code is pretty much of ad hoc nature. There is no unix-like
|
|
134 UIDs under Windows NT. There is no concept of root user, because
|
|
135 all security is ACL-based. Instead, let's use a simple variable,
|
|
136 nt-fake-unix-uid, which would allow the user to have a uid of
|
|
137 choice. --kkm, 02/03/2000 */
|
|
138 #if 0
|
428
|
139 /* Find the user's real name by opening the process token and
|
|
140 looking up the name associated with the user-sid in that token.
|
|
141
|
|
142 Use the relative portion of the identifier authority value from
|
|
143 the user-sid as the user id value (same for group id using the
|
|
144 primary group sid from the process token). */
|
|
145
|
771
|
146 TOKEN_USER sidinfo;
|
|
147 Extbyte name[256], domain[256];
|
|
148 Charcount length = sizeof (name) / XETCHAR_SIZE;
|
|
149 Charcount dlength = sizeof (domain) / XETCHAR_SIZE;
|
|
150 DWORD trash;
|
|
151 HANDLE token = NULL;
|
|
152 SID_NAME_USE user_type;
|
428
|
153
|
|
154 if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &token)
|
771
|
155 && GetTokenInformation (token, TokenUser, &sidinfo, sizeof (sidinfo),
|
|
156 &trash)
|
|
157 && qxeLookupAccountSid (NULL, sidinfo.User.Sid, name, &length,
|
|
158 domain, &dlength, &user_type))
|
428
|
159 {
|
771
|
160 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name);
|
428
|
161 /* Determine a reasonable uid value. */
|
771
|
162 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0)
|
428
|
163 {
|
|
164 the_passwd.pw_uid = 0;
|
|
165 the_passwd.pw_gid = 0;
|
|
166 }
|
|
167 else
|
|
168 {
|
|
169 SID_IDENTIFIER_AUTHORITY * pSIA;
|
771
|
170 TOKEN_PRIMARY_GROUP group;
|
428
|
171
|
771
|
172 pSIA = GetSidIdentifierAuthority (sidinfo.User.Sid);
|
428
|
173 /* I believe the relative portion is the last 4 bytes (of 6)
|
|
174 with msb first. */
|
|
175 the_passwd.pw_uid = ((pSIA->Value[2] << 24) +
|
|
176 (pSIA->Value[3] << 16) +
|
|
177 (pSIA->Value[4] << 8) +
|
|
178 (pSIA->Value[5] << 0));
|
|
179 /* restrict to conventional uid range for normal users */
|
|
180 the_passwd.pw_uid = the_passwd.pw_uid % 60001;
|
|
181
|
|
182 /* Get group id */
|
|
183 if (GetTokenInformation (token, TokenPrimaryGroup,
|
771
|
184 &group, sizeof (group), &trash))
|
428
|
185 {
|
|
186 SID_IDENTIFIER_AUTHORITY * pSIA;
|
|
187
|
771
|
188 pSIA = GetSidIdentifierAuthority (group.PrimaryGroup);
|
428
|
189 the_passwd.pw_gid = ((pSIA->Value[2] << 24) +
|
|
190 (pSIA->Value[3] << 16) +
|
|
191 (pSIA->Value[4] << 8) +
|
|
192 (pSIA->Value[5] << 0));
|
|
193 /* I don't know if this is necessary, but for safety... */
|
|
194 the_passwd.pw_gid = the_passwd.pw_gid % 60001;
|
|
195 }
|
|
196 else
|
|
197 the_passwd.pw_gid = the_passwd.pw_uid;
|
|
198 }
|
|
199 }
|
|
200 /* If security calls are not supported (presumably because we
|
|
201 are running under Windows 95), fallback to this. */
|
771
|
202 else if (qxeGetUserName (name, &length))
|
428
|
203 {
|
771
|
204 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name);
|
|
205 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0)
|
428
|
206 the_passwd.pw_uid = 0;
|
|
207 else
|
|
208 the_passwd.pw_uid = 123;
|
|
209 the_passwd.pw_gid = the_passwd.pw_uid;
|
|
210 }
|
|
211 else
|
|
212 {
|
771
|
213 the_passwd.pw_name = "unknown";
|
428
|
214 the_passwd.pw_uid = 123;
|
|
215 the_passwd.pw_gid = 123;
|
|
216 }
|
|
217
|
440
|
218 if (token)
|
|
219 CloseHandle (token);
|
|
220 #else
|
|
221 /* Obtain only logon id here, uid part is moved to getuid */
|
771
|
222 DWORD length = UNLEN + 1;
|
|
223 Extbyte name[MAX_XETCHAR_SIZE * (UNLEN + 1)];
|
|
224 if (qxeGetUserName (name, &length))
|
|
225 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name);
|
440
|
226 else
|
771
|
227 the_passwd.pw_name = "unknown";
|
440
|
228 #endif
|
|
229
|
771
|
230 #if 0
|
428
|
231 /* Ensure HOME and SHELL are defined. */
|
|
232 /*
|
|
233 * With XEmacs, setting $HOME is deprecated.
|
|
234 */
|
771
|
235 if (egetenv ("HOME") == NULL)
|
|
236 eputenv ("HOME=c:/");
|
428
|
237 #endif
|
|
238
|
611
|
239 /* Set dir from environment variables. */
|
771
|
240 the_passwd.pw_dir = (char *) qxestrdup (get_home_directory ());
|
611
|
241 /* We used to set pw_shell here, but the order is wrong (SHELL gets
|
771
|
242 initted in callproc.c, called later in the init process) and pw_shell
|
611
|
243 is not used anywhere. */
|
428
|
244 }
|
|
245
|
771
|
246 /* Parse the root part of file name, if present. Return length and
|
|
247 optionally store pointer to Intbyte after root. */
|
|
248 static Bytecount
|
|
249 parse_root (Intbyte *name, Intbyte **pPath)
|
428
|
250 {
|
771
|
251 Intbyte *start = name;
|
428
|
252
|
|
253 if (name == NULL)
|
|
254 return 0;
|
|
255
|
|
256 /* find the root name of the volume if given */
|
|
257 if (isalpha (name[0]) && name[1] == ':')
|
|
258 {
|
|
259 /* skip past drive specifier */
|
|
260 name += 2;
|
|
261 if (IS_DIRECTORY_SEP (name[0]))
|
|
262 name++;
|
|
263 }
|
|
264 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
|
|
265 {
|
|
266 int slashes = 2;
|
|
267 name += 2;
|
|
268 do
|
|
269 {
|
|
270 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
|
|
271 break;
|
|
272 name++;
|
|
273 }
|
771
|
274 while (*name);
|
428
|
275 if (IS_DIRECTORY_SEP (name[0]))
|
|
276 name++;
|
|
277 }
|
|
278
|
|
279 if (pPath)
|
|
280 *pPath = name;
|
|
281
|
|
282 return name - start;
|
|
283 }
|
|
284
|
|
285 /* Get long base name for name; name is assumed to be absolute. */
|
771
|
286 static Intbyte *
|
|
287 get_long_basename (Intbyte *name)
|
428
|
288 {
|
771
|
289 WIN32_FIND_DATAW find_data;
|
428
|
290 HANDLE dir_handle;
|
771
|
291 Extbyte *nameext;
|
428
|
292
|
771
|
293 /* must be valid filename, no wild cards or other invalid characters */
|
|
294 if (qxestrpbrk (name, "*?|<>\""))
|
|
295 return 0;
|
428
|
296
|
771
|
297 C_STRING_TO_TSTR (name, nameext);
|
|
298 dir_handle = qxeFindFirstFile (nameext, &find_data);
|
428
|
299 if (dir_handle != INVALID_HANDLE_VALUE)
|
|
300 {
|
771
|
301 Intbyte *fileint;
|
|
302
|
|
303 TSTR_TO_C_STRING_MALLOC (find_data.cFileName, fileint);
|
428
|
304 FindClose (dir_handle);
|
771
|
305 return fileint;
|
428
|
306 }
|
771
|
307 return 0;
|
428
|
308 }
|
|
309
|
|
310 /* Get long name for file, if possible (assumed to be absolute). */
|
771
|
311 Intbyte *
|
|
312 mswindows_get_long_filename (Intbyte *name)
|
428
|
313 {
|
771
|
314 Intbyte *full = mswindows_canonicalize_filename (name);
|
|
315 Intbyte *p;
|
|
316 Intbyte *q;
|
|
317 DECLARE_EISTRING (o);
|
|
318 Bytecount len;
|
428
|
319
|
|
320 /* Copy root part verbatim. */
|
|
321 len = parse_root (full, &p);
|
771
|
322 eicpy_raw (o, full, len);
|
428
|
323
|
771
|
324 while (p != NULL && *p)
|
428
|
325 {
|
771
|
326 Intbyte *component;
|
|
327
|
428
|
328 q = p;
|
771
|
329 p = qxestrchr (q, '\\');
|
428
|
330 if (p) *p = '\0';
|
771
|
331 component = get_long_basename (full);
|
|
332 if (component)
|
428
|
333 {
|
771
|
334 eicat_rawz (o, component);
|
428
|
335 if (p != NULL)
|
|
336 {
|
|
337 *p++ = '\\';
|
771
|
338 eicat_ch (o, '\\');
|
428
|
339 }
|
771
|
340 xfree (component);
|
428
|
341 }
|
|
342 else
|
771
|
343 {
|
|
344 xfree (full);
|
|
345 return 0;
|
|
346 }
|
428
|
347 }
|
|
348
|
771
|
349 xfree (full);
|
|
350 return eicpyout_malloc (o, 0);
|
428
|
351 }
|
|
352
|
771
|
353 static int
|
|
354 is_unc_volume (const Intbyte *filename)
|
|
355 {
|
|
356 const Intbyte *ptr = filename;
|
428
|
357
|
771
|
358 if (!IS_DIRECTORY_SEP (ptr[0]) || !IS_DIRECTORY_SEP (ptr[1]) || !ptr[2])
|
|
359 return 0;
|
|
360
|
|
361 if (qxestrpbrk (ptr + 2, "*?|<>\"\\/"))
|
|
362 return 0;
|
|
363
|
|
364 return 1;
|
428
|
365 }
|
|
366
|
771
|
367 /* NOTE: Value returned is still in external format. Callers need to
|
|
368 convert. */
|
707
|
369 #define REG_ROOT "SOFTWARE\\XEmacs\\XEmacs"
|
428
|
370
|
771
|
371 static LPBYTE
|
|
372 nt_get_resource (Intbyte *key, LPDWORD lpdwtype)
|
428
|
373 {
|
|
374 LPBYTE lpvalue;
|
|
375 HKEY hrootkey = NULL;
|
|
376 DWORD cbData;
|
771
|
377 Extbyte *keyext;
|
|
378
|
|
379 C_STRING_TO_TSTR (key, keyext);
|
428
|
380
|
|
381 /* Check both the current user and the local machine to see if
|
|
382 we have any resources. */
|
|
383
|
771
|
384 if (qxeRegOpenKeyEx (HKEY_CURRENT_USER, XETEXT (REG_ROOT), 0, KEY_READ,
|
|
385 &hrootkey) == ERROR_SUCCESS)
|
428
|
386 {
|
|
387 lpvalue = NULL;
|
|
388
|
771
|
389 if (qxeRegQueryValueEx (hrootkey, keyext, NULL, NULL, NULL,
|
|
390 &cbData) == ERROR_SUCCESS
|
428
|
391 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
|
771
|
392 && qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue,
|
|
393 &cbData) == ERROR_SUCCESS)
|
|
394 return (lpvalue);
|
428
|
395
|
|
396 if (lpvalue) xfree (lpvalue);
|
|
397
|
|
398 RegCloseKey (hrootkey);
|
|
399 }
|
|
400
|
771
|
401 if (qxeRegOpenKeyEx (HKEY_LOCAL_MACHINE, XETEXT (REG_ROOT), 0, KEY_READ,
|
|
402 &hrootkey) == ERROR_SUCCESS)
|
428
|
403 {
|
|
404 lpvalue = NULL;
|
|
405
|
771
|
406 if (qxeRegQueryValueEx (hrootkey, keyext, NULL, NULL, NULL,
|
|
407 &cbData) == ERROR_SUCCESS &&
|
428
|
408 (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL &&
|
771
|
409 qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue,
|
|
410 &cbData) == ERROR_SUCCESS)
|
|
411 return (lpvalue);
|
428
|
412
|
|
413 if (lpvalue) xfree (lpvalue);
|
|
414
|
|
415 RegCloseKey (hrootkey);
|
|
416 }
|
|
417
|
|
418 return (NULL);
|
|
419 }
|
|
420
|
|
421 void
|
442
|
422 init_environment (void)
|
428
|
423 {
|
|
424 /* Check for environment variables and use registry if they don't exist */
|
771
|
425 /* Emacs 20.6 sets default values for these; not necessary here because
|
|
426 we already supply them. (except SHELL, which is set in init_user_info().)
|
|
427 Emacs 20.6 messes with TMPDIR; not necessary here. */
|
428
|
428 {
|
|
429 int i;
|
|
430 LPBYTE lpval;
|
|
431 DWORD dwType;
|
|
432
|
771
|
433 static Char_ASCII *env_vars[] =
|
428
|
434 {
|
|
435 "HOME",
|
|
436 "EMACSLOADPATH",
|
|
437 "EMACSDEBUGPATHS",
|
|
438 "SHELL",
|
|
439 "CMDPROXY",
|
|
440 "EMACSDATA",
|
|
441 "EMACSPATH",
|
|
442 "EMACSPACKAGEPATH",
|
771
|
443 "EMACSLOCKMETHOD",
|
428
|
444 "INFOPATH"
|
|
445 };
|
771
|
446 #if defined (HEAP_IN_DATA) && !defined (PDUMP)
|
430
|
447 cache_system_info ();
|
|
448 #endif
|
771
|
449
|
|
450 #if 0 /* FSF 21.1 */
|
|
451 /* !!#### i think i already do the equivalent elsewhere.
|
|
452 delete when i'm sure i do.
|
|
453 (but maybe i should be playing with LANG when the user changes
|
|
454 the locale, so that subprocesses get it right.) */
|
|
455 /* Get default locale info and use it for LANG. */
|
|
456 if (GetLocaleInfo (LOCALE_USER_DEFAULT,
|
|
457 LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP,
|
|
458 locale_name, sizeof (locale_name)))
|
|
459 {
|
|
460 for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++)
|
|
461 {
|
|
462 if (strcmp (env_vars[i].name, "LANG") == 0)
|
|
463 {
|
|
464 env_vars[i].def_value = locale_name;
|
|
465 break;
|
|
466 }
|
|
467 }
|
|
468 }
|
|
469 #endif /* 0 */
|
|
470
|
428
|
471 for (i = 0; i < countof (env_vars); i++)
|
|
472 {
|
771
|
473 if (!egetenv (env_vars[i]) &&
|
428
|
474 (lpval = nt_get_resource (env_vars[i], &dwType)) != NULL)
|
|
475 {
|
|
476 if (dwType == REG_EXPAND_SZ)
|
|
477 {
|
771
|
478 Extbyte *buf = NULL;
|
|
479 Intbyte *envval;
|
|
480 Charcount cch;
|
428
|
481
|
771
|
482 cch = qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, 0);
|
|
483 buf = (Extbyte *) alloca (cch * XETCHAR_SIZE);
|
|
484 qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, cch);
|
|
485 TSTR_TO_C_STRING (buf, envval);
|
|
486 eputenv (env_vars[i], envval);
|
428
|
487 }
|
|
488 else if (dwType == REG_SZ)
|
|
489 {
|
771
|
490 Intbyte *envval;
|
|
491
|
|
492 TSTR_TO_C_STRING (lpval, envval);
|
|
493 eputenv (env_vars[i], envval);
|
428
|
494 }
|
|
495
|
|
496 xfree (lpval);
|
|
497 }
|
|
498 }
|
|
499 }
|
|
500
|
|
501 /* Another special case: on NT, the PATH variable is actually named
|
|
502 "Path" although cmd.exe (perhaps NT itself) arranges for
|
|
503 environment variable lookup and setting to be case insensitive.
|
|
504 However, Emacs assumes a fully case sensitive environment, so we
|
|
505 need to change "Path" to "PATH" to match the expectations of
|
771
|
506 various elisp packages.
|
428
|
507
|
|
508 The same applies to COMSPEC. */
|
|
509 {
|
771
|
510 Lisp_Object tail;
|
428
|
511
|
771
|
512 EXTERNAL_LIST_LOOP (tail, Vprocess_environment)
|
|
513 {
|
|
514 Lisp_Object str = XCAR (tail);
|
|
515 if (STRINGP (str))
|
|
516 {
|
|
517 Intbyte *dat = XSTRING_DATA (str);
|
|
518 if (qxestrncasecmp (dat, "PATH=", 5) == 0)
|
|
519 memcpy (dat, "PATH=", 5);
|
|
520 else if (qxestrncasecmp (dat, "COMSPEC=", 8) == 0)
|
|
521 memcpy (dat, "COMSPEC=", 8);
|
|
522 }
|
|
523 }
|
428
|
524 }
|
|
525
|
|
526 init_user_info ();
|
|
527 }
|
|
528
|
771
|
529 /* Emacs 20.6 contains a routine get_emacs_configuration() here to set
|
|
530 EMACS_CONFIGURATION. */
|
428
|
531 #ifndef HAVE_X_WINDOWS
|
|
532 /* X11R6 on NT provides the single parameter version of this command. */
|
|
533
|
|
534 #include <sys/timeb.h>
|
|
535
|
|
536 /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */
|
|
537 void
|
|
538 gettimeofday (struct timeval *tv, struct timezone *tz)
|
|
539 {
|
|
540 struct _timeb tb;
|
|
541 _ftime (&tb);
|
|
542
|
|
543 tv->tv_sec = tb.time;
|
|
544 tv->tv_usec = tb.millitm * 1000L;
|
|
545 if (tz)
|
|
546 {
|
|
547 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
|
|
548 tz->tz_dsttime = tb.dstflag; /* type of dst correction */
|
|
549 }
|
|
550 }
|
|
551
|
|
552 #endif /* HAVE_X_WINDOWS */
|
|
553
|
771
|
554
|
428
|
555 /* ------------------------------------------------------------------------- */
|
771
|
556 /* IO support and wrapper functions for Win32 API. */
|
428
|
557 /* ------------------------------------------------------------------------- */
|
|
558
|
771
|
559 typedef struct volume_info_data
|
428
|
560 {
|
771
|
561 struct volume_info_data *next;
|
428
|
562
|
|
563 /* time when info was obtained */
|
771
|
564 DWORD timestamp;
|
428
|
565
|
|
566 /* actual volume info */
|
771
|
567 Intbyte *root_dir;
|
|
568 DWORD serialnum;
|
|
569 DWORD maxcomp;
|
|
570 DWORD flags;
|
|
571 Intbyte *name;
|
|
572 Intbyte *type;
|
428
|
573 } volume_info_data;
|
|
574
|
|
575 /* Global referenced by various functions. */
|
|
576 static volume_info_data volume_info;
|
|
577
|
|
578 /* Vector to indicate which drives are local and fixed (for which cached
|
|
579 data never expires). */
|
|
580 static BOOL fixed_drives[26];
|
|
581
|
|
582 /* Consider cached volume information to be stale if older than 10s,
|
|
583 at least for non-local drives. Info for fixed drives is never stale. */
|
|
584 #define DRIVE_INDEX( c ) ( (c) <= 'Z' ? (c) - 'A' : (c) - 'a' )
|
|
585 #define VOLINFO_STILL_VALID( root_dir, info ) \
|
|
586 ( ( isalpha (root_dir[0]) && \
|
|
587 fixed_drives[ DRIVE_INDEX (root_dir[0]) ] ) \
|
|
588 || GetTickCount () - info->timestamp < 10000 )
|
|
589
|
|
590 /* Cache support functions. */
|
|
591
|
|
592 /* Simple linked list with linear search is sufficient. */
|
|
593 static volume_info_data *volume_cache = NULL;
|
|
594
|
|
595 static volume_info_data *
|
771
|
596 lookup_volume_info (Intbyte *root_dir)
|
428
|
597 {
|
771
|
598 volume_info_data *info;
|
428
|
599
|
|
600 for (info = volume_cache; info; info = info->next)
|
771
|
601 if (qxestrcasecmp_i18n (info->root_dir, root_dir) == 0)
|
428
|
602 break;
|
|
603 return info;
|
|
604 }
|
|
605
|
|
606 static void
|
771
|
607 add_volume_info (Intbyte *root_dir, volume_info_data *info)
|
428
|
608 {
|
771
|
609 info->root_dir = qxestrdup (root_dir);
|
428
|
610 info->next = volume_cache;
|
|
611 volume_cache = info;
|
|
612 }
|
|
613
|
|
614
|
|
615 /* Wrapper for GetVolumeInformation, which uses caching to avoid
|
|
616 performance penalty (~2ms on 486 for local drives, 7.5ms for local
|
|
617 cdrom drive, ~5-10ms or more for remote drives on LAN). */
|
771
|
618 static volume_info_data *
|
|
619 get_cached_volume_information (Intbyte *root_dir)
|
428
|
620 {
|
771
|
621 volume_info_data *info;
|
|
622 Intbyte *default_root;
|
428
|
623
|
|
624 /* NULL for root_dir means use root from current directory. */
|
|
625 if (root_dir == NULL)
|
|
626 {
|
771
|
627 Charcount nchars = qxeGetCurrentDirectory (0, NULL);
|
|
628 Extbyte *rootext;
|
|
629
|
|
630 if (!nchars)
|
428
|
631 return NULL;
|
771
|
632 rootext = alloca_extbytes (nchars * XETCHAR_SIZE);
|
|
633 if (!qxeGetCurrentDirectory (nchars, rootext))
|
|
634 return NULL;
|
|
635 TSTR_TO_C_STRING (rootext, default_root);
|
428
|
636 parse_root (default_root, &root_dir);
|
|
637 *root_dir = 0;
|
|
638 root_dir = default_root;
|
|
639 }
|
|
640
|
|
641 /* Local fixed drives can be cached permanently. Removable drives
|
|
642 cannot be cached permanently, since the volume name and serial
|
|
643 number (if nothing else) can change. Remote drives should be
|
|
644 treated as if they are removable, since there is no sure way to
|
|
645 tell whether they are or not. Also, the UNC association of drive
|
|
646 letters mapped to remote volumes can be changed at any time (even
|
|
647 by other processes) without notice.
|
|
648
|
|
649 As a compromise, so we can benefit from caching info for remote
|
|
650 volumes, we use a simple expiry mechanism to invalidate cache
|
|
651 entries that are more than ten seconds old. */
|
|
652
|
|
653 #if 0
|
|
654 /* No point doing this, because WNetGetConnection is even slower than
|
|
655 GetVolumeInformation, consistently taking ~50ms on a 486 (FWIW,
|
|
656 GetDriveType is about the only call of this type which does not
|
|
657 involve network access, and so is extremely quick). */
|
|
658
|
|
659 /* Map drive letter to UNC if remote. */
|
771
|
660 if (isalpha (root_dir[0]) && !fixed [DRIVE_INDEX (root_dir[0])])
|
428
|
661 {
|
771
|
662 Extbyte remote_name[256 * XETCHAR_SIZE];
|
|
663 Intbyte drive[3] = { root_dir[0], ':' };
|
|
664 Extbyte *driveext;
|
428
|
665
|
771
|
666 C_STRING_TO_TSTR (drive, driveext);
|
|
667 if (qxeWNetGetConnection (driveext, remote_name,
|
|
668 sizeof (remote_name) / XETCHAR_SIZE)
|
428
|
669 == NO_ERROR)
|
|
670 /* do something */ ;
|
|
671 }
|
|
672 #endif
|
|
673
|
|
674 info = lookup_volume_info (root_dir);
|
|
675
|
|
676 if (info == NULL || ! VOLINFO_STILL_VALID (root_dir, info))
|
771
|
677 {
|
|
678 Extbyte name[256 * MAX_XETCHAR_SIZE];
|
|
679 DWORD serialnum;
|
|
680 DWORD maxcomp;
|
|
681 DWORD flags;
|
|
682 Extbyte type[256 * MAX_XETCHAR_SIZE];
|
428
|
683
|
771
|
684 /* Info is not cached, or is stale. */
|
|
685 if (!qxeGetVolumeInformation (root_dir,
|
|
686 name, sizeof (name) / XETCHAR_SIZE,
|
|
687 &serialnum,
|
|
688 &maxcomp,
|
|
689 &flags,
|
|
690 type, sizeof (type) / XETCHAR_SIZE))
|
|
691 return NULL;
|
428
|
692
|
771
|
693 /* Cache the volume information for future use, overwriting existing
|
|
694 entry if present. */
|
|
695 if (info == NULL)
|
|
696 {
|
|
697 info = (volume_info_data *) xmalloc (sizeof (volume_info_data));
|
|
698 add_volume_info (root_dir, info);
|
|
699 }
|
|
700 else
|
|
701 {
|
|
702 xfree (info->name);
|
|
703 xfree (info->type);
|
|
704 }
|
428
|
705
|
771
|
706 TSTR_TO_C_STRING_MALLOC (name, info->name);
|
|
707 info->serialnum = serialnum;
|
|
708 info->maxcomp = maxcomp;
|
|
709 info->flags = flags;
|
|
710 TSTR_TO_C_STRING_MALLOC (type, info->type);
|
|
711 info->timestamp = GetTickCount ();
|
|
712 }
|
428
|
713
|
|
714 return info;
|
|
715 }
|
|
716
|
|
717 /* Get information on the volume where name is held; set path pointer to
|
|
718 start of pathname in name (past UNC header\volume header if present). */
|
771
|
719 static int
|
|
720 get_volume_info (const Intbyte *name, const Intbyte **pPath)
|
428
|
721 {
|
771
|
722 /* We probably only need a couple of bytes, but let's be generous in
|
|
723 case this function gets changed */
|
|
724 Intbyte *temp = alloca_array (Intbyte, qxestrlen (name) + 10);
|
|
725 Intbyte *rootname = NULL; /* default to current volume */
|
|
726 volume_info_data *info;
|
428
|
727
|
|
728 if (name == NULL)
|
|
729 return FALSE;
|
|
730
|
|
731 /* find the root name of the volume if given */
|
|
732 if (isalpha (name[0]) && name[1] == ':')
|
|
733 {
|
|
734 rootname = temp;
|
|
735 temp[0] = *name++;
|
|
736 temp[1] = *name++;
|
|
737 temp[2] = '\\';
|
|
738 temp[3] = 0;
|
|
739 }
|
|
740 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
|
|
741 {
|
771
|
742 Intbyte *str = temp;
|
428
|
743 int slashes = 4;
|
|
744 rootname = temp;
|
|
745 do
|
|
746 {
|
|
747 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
|
|
748 break;
|
|
749 *str++ = *name++;
|
|
750 }
|
771
|
751 while (*name);
|
428
|
752
|
|
753 *str++ = '\\';
|
|
754 *str = 0;
|
|
755 }
|
|
756
|
|
757 if (pPath)
|
|
758 *pPath = name;
|
|
759
|
771
|
760 info = get_cached_volume_information (rootname);
|
428
|
761 if (info != NULL)
|
|
762 {
|
|
763 /* Set global referenced by other functions. */
|
|
764 volume_info = *info;
|
|
765 return TRUE;
|
|
766 }
|
|
767 return FALSE;
|
|
768 }
|
|
769
|
771
|
770 /* XEmacs: Everything referring to map_win32_filename() aka map_w32_filename()
|
|
771 removed; it was only for NT 3.1, which we hereby do not support. (NT 3.5
|
|
772 predates Windows 95!) */
|
428
|
773
|
771
|
774 static int
|
|
775 is_exec (const Intbyte *name)
|
|
776 {
|
|
777 Intbyte *p = qxestrrchr (name, '.');
|
|
778 return (p != NULL && (qxestrcasecmp (p, ".exe") == 0 ||
|
|
779 qxestrcasecmp (p, ".com") == 0 ||
|
|
780 qxestrcasecmp (p, ".bat") == 0 ||
|
|
781 qxestrcasecmp (p, ".cmd") == 0));
|
428
|
782 }
|
|
783
|
|
784 /* Emulate the Unix directory procedures opendir, closedir,
|
|
785 and readdir. We can't use the procedures supplied in sysdep.c,
|
|
786 so we provide them here. */
|
|
787
|
|
788 struct direct dir_static; /* simulated directory contents */
|
|
789 static HANDLE dir_find_handle = INVALID_HANDLE_VALUE;
|
771
|
790 /* dir_is_fat deleted */
|
|
791 static Intbyte *dir_pathname;
|
|
792 static WIN32_FIND_DATAW dir_find_data;
|
|
793
|
|
794 /* Support shares on a network resource as subdirectories of a read-only
|
|
795 root directory. */
|
|
796 static HANDLE wnet_enum_handle = INVALID_HANDLE_VALUE;
|
|
797 static HANDLE open_unc_volume (const Intbyte *);
|
|
798 static Intbyte *read_unc_volume (HANDLE);
|
|
799 static int close_unc_volume (HANDLE);
|
428
|
800
|
|
801 DIR *
|
771
|
802 mswindows_opendir (const Intbyte *filename)
|
428
|
803 {
|
|
804 DIR *dirp;
|
|
805
|
|
806 /* Opening is done by FindFirstFile. However, a read is inherent to
|
|
807 this operation, so we defer the open until read time. */
|
|
808
|
771
|
809 if (dir_find_handle != INVALID_HANDLE_VALUE)
|
428
|
810 return NULL;
|
771
|
811 if (wnet_enum_handle != INVALID_HANDLE_VALUE)
|
428
|
812 return NULL;
|
|
813
|
771
|
814 if (is_unc_volume (filename))
|
|
815 {
|
|
816 wnet_enum_handle = open_unc_volume (filename);
|
|
817 if (wnet_enum_handle == INVALID_HANDLE_VALUE)
|
|
818 return NULL;
|
|
819 }
|
428
|
820
|
771
|
821 if (!(dirp = xnew_and_zero (DIR)))
|
|
822 return NULL;
|
|
823
|
|
824 if (dir_pathname)
|
|
825 xfree (dir_pathname);
|
|
826 dir_pathname = qxestrdup (filename);
|
428
|
827
|
|
828 return dirp;
|
|
829 }
|
|
830
|
442
|
831 int
|
771
|
832 mswindows_closedir (DIR *dirp)
|
428
|
833 {
|
771
|
834 int retval;
|
442
|
835
|
428
|
836 /* If we have a find-handle open, close it. */
|
|
837 if (dir_find_handle != INVALID_HANDLE_VALUE)
|
|
838 {
|
771
|
839 retval = FindClose (dir_find_handle) ? 0 : -1;
|
428
|
840 dir_find_handle = INVALID_HANDLE_VALUE;
|
|
841 }
|
771
|
842 else if (wnet_enum_handle != INVALID_HANDLE_VALUE)
|
|
843 {
|
|
844 retval = close_unc_volume (wnet_enum_handle);
|
|
845 wnet_enum_handle = INVALID_HANDLE_VALUE;
|
|
846 }
|
428
|
847 xfree (dirp);
|
771
|
848
|
|
849 return retval;
|
|
850 }
|
|
851
|
|
852 struct direct *
|
|
853 mswindows_readdir (DIR *dirp)
|
|
854 {
|
|
855 Intbyte *val;
|
|
856 int need_to_free = 0;
|
|
857
|
|
858 if (wnet_enum_handle != INVALID_HANDLE_VALUE)
|
|
859 {
|
|
860 if (!(val = read_unc_volume (wnet_enum_handle)))
|
|
861 return NULL;
|
|
862 need_to_free = 1;
|
|
863 }
|
|
864 /* If we aren't dir_finding, do a find-first, otherwise do a find-next. */
|
|
865 else if (dir_find_handle == INVALID_HANDLE_VALUE)
|
|
866 {
|
|
867 DECLARE_EISTRING (filename);
|
|
868 Emchar lastch;
|
|
869
|
|
870 eicpy_rawz (filename, dir_pathname);
|
|
871 lastch = eigetch_char (filename, eicharlen (filename) - 1);
|
|
872 if (!IS_DIRECTORY_SEP (lastch))
|
|
873 eicat_ch (filename, '\\');
|
|
874 eicat_ch (filename, '*');
|
|
875 eito_external (filename, Qmswindows_tstr);
|
|
876
|
|
877 dir_find_handle = qxeFindFirstFile (eiextdata (filename),
|
|
878 &dir_find_data);
|
|
879
|
|
880 if (dir_find_handle == INVALID_HANDLE_VALUE)
|
|
881 return NULL;
|
|
882 TSTR_TO_C_STRING (dir_find_data.cFileName, val);
|
|
883 }
|
|
884 else
|
|
885 {
|
|
886 if (!qxeFindNextFile (dir_find_handle, &dir_find_data))
|
|
887 return NULL;
|
|
888 TSTR_TO_C_STRING (dir_find_data.cFileName, val);
|
|
889 }
|
|
890
|
|
891 /* XEmacs never uses this value, so don't bother making it match
|
|
892 value returned by qxe_stat(). */
|
|
893 dir_static.d_ino = 1;
|
|
894
|
|
895 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
|
|
896 dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
897
|
|
898 {
|
|
899 DECLARE_EISTRING (found);
|
|
900 Bytecount namlen;
|
|
901
|
|
902 eicpy_rawz (found, val);
|
|
903 if (need_to_free)
|
|
904 xfree (val);
|
|
905
|
|
906 if (!NILP (Vmswindows_downcase_file_names))
|
|
907 eilwr (found);
|
|
908
|
|
909 namlen = min (eilen (found), sizeof (dir_static.d_name) - 1);
|
|
910 strncpy (dir_static.d_name, (char *) eidata (found), namlen);
|
|
911 dir_static.d_name[namlen] = '\0';
|
|
912 dir_static.d_namlen = (unsigned short) namlen;
|
|
913 }
|
|
914
|
|
915 return &dir_static;
|
|
916 }
|
|
917
|
|
918 static HANDLE
|
|
919 open_unc_volume (const Intbyte *path)
|
|
920 {
|
|
921 NETRESOURCEW nr;
|
|
922 HANDLE henum;
|
|
923 int result;
|
|
924
|
|
925 nr.dwScope = RESOURCE_GLOBALNET;
|
|
926 nr.dwType = RESOURCETYPE_DISK;
|
|
927 nr.dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;
|
|
928 nr.dwUsage = RESOURCEUSAGE_CONTAINER;
|
|
929 nr.lpLocalName = NULL;
|
|
930 C_STRING_TO_TSTR (path, nr.lpRemoteName);
|
|
931 nr.lpComment = NULL;
|
|
932 nr.lpProvider = NULL;
|
|
933
|
|
934 result = qxeWNetOpenEnum (RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
|
|
935 RESOURCEUSAGE_CONNECTABLE, &nr, &henum);
|
|
936
|
|
937 if (result == NO_ERROR)
|
|
938 return henum;
|
|
939 else
|
|
940 return INVALID_HANDLE_VALUE;
|
|
941 }
|
|
942
|
|
943 static Intbyte *
|
|
944 read_unc_volume (HANDLE henum)
|
|
945 {
|
|
946 int count;
|
|
947 int result;
|
|
948 Extbyte buf[16384];
|
|
949 Intbyte *ptr;
|
|
950 Bytecount bufsize = sizeof (buf);
|
|
951
|
|
952 count = 1;
|
|
953 /* #### we should just be querying the size and then allocating the
|
|
954 right amount, like for all similar API's. but the docs say this ?!
|
|
955
|
|
956 An application cannot set the lpBuffer parameter to NULL and
|
|
957 retrieve the required buffer size from the lpBufferSize
|
|
958 parameter. Instead, the application should allocate a buffer of a
|
|
959 reasonable size -- 16 kilobytes (K) is typical -- and use the value
|
|
960 of lpBufferSize for error detection.
|
|
961 */
|
|
962
|
|
963 result = qxeWNetEnumResource (wnet_enum_handle, &count, buf, &bufsize);
|
|
964 if (result != NO_ERROR)
|
|
965 return NULL;
|
|
966
|
|
967 /* WNetEnumResource returns \\resource\share...skip forward to "share". */
|
|
968 TSTR_TO_C_STRING (((LPNETRESOURCEW) buf)->lpRemoteName, ptr);
|
|
969 INC_CHARPTR (ptr);
|
|
970 INC_CHARPTR (ptr);
|
|
971 while (*ptr && !IS_DIRECTORY_SEP (charptr_emchar (ptr)))
|
|
972 INC_CHARPTR (ptr);
|
|
973 INC_CHARPTR (ptr);
|
|
974
|
|
975 return qxestrdup (ptr);
|
|
976 }
|
|
977
|
|
978 static int
|
|
979 close_unc_volume (HANDLE henum)
|
|
980 {
|
|
981 if (henum != INVALID_HANDLE_VALUE)
|
|
982 return WNetCloseEnum (henum) == NO_ERROR ? 0 : -1;
|
442
|
983 else
|
|
984 return -1;
|
428
|
985 }
|
|
986
|
771
|
987 static DWORD
|
|
988 unc_volume_file_attributes (const Intbyte *path)
|
428
|
989 {
|
771
|
990 HANDLE henum;
|
|
991 DWORD attrs;
|
|
992
|
|
993 henum = open_unc_volume (path);
|
|
994 if (henum == INVALID_HANDLE_VALUE)
|
|
995 return -1;
|
|
996
|
|
997 attrs = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY;
|
|
998
|
|
999 close_unc_volume (henum);
|
428
|
1000
|
771
|
1001 return attrs;
|
|
1002 }
|
|
1003
|
|
1004 int
|
|
1005 mswindows_access (const Intbyte *path, int mode)
|
|
1006 {
|
|
1007 DWORD attributes;
|
428
|
1008
|
771
|
1009 /* MSVC implementation doesn't recognize D_OK. */
|
|
1010 if (is_unc_volume (path))
|
|
1011 {
|
|
1012 attributes = unc_volume_file_attributes (path);
|
|
1013 if (attributes == -1)
|
|
1014 {
|
|
1015 errno = EACCES;
|
|
1016 return -1;
|
|
1017 }
|
428
|
1018 }
|
|
1019 else
|
|
1020 {
|
771
|
1021 Extbyte *pathext;
|
|
1022
|
|
1023 C_STRING_TO_TSTR (path, pathext);
|
|
1024 if ((attributes = qxeGetFileAttributes (pathext)) == -1)
|
|
1025 {
|
|
1026 /* Should try mapping GetLastError to errno; for now just indicate
|
|
1027 that path doesn't exist. */
|
|
1028 errno = EACCES;
|
|
1029 return -1;
|
|
1030 }
|
428
|
1031 }
|
771
|
1032 if ((mode & X_OK) != 0 && !is_exec (path))
|
|
1033 {
|
|
1034 errno = EACCES;
|
|
1035 return -1;
|
|
1036 }
|
|
1037 if ((mode & W_OK) != 0 && (attributes & FILE_ATTRIBUTE_READONLY) != 0)
|
428
|
1038 {
|
771
|
1039 errno = EACCES;
|
|
1040 return -1;
|
428
|
1041 }
|
771
|
1042 if ((mode & D_OK) != 0 && (attributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
|
|
1043 {
|
|
1044 errno = EACCES;
|
|
1045 return -1;
|
|
1046 }
|
|
1047 return 0;
|
428
|
1048 }
|
|
1049
|
771
|
1050 /* This only works on NTFS volumes, but is useful to have. */
|
|
1051 /* #### NT 5.0 has a function CreateHardLink to do this directly,
|
|
1052 and it may do more things. */
|
428
|
1053 int
|
771
|
1054 mswindows_link (const Intbyte *old, const Intbyte *new)
|
428
|
1055 {
|
771
|
1056 HANDLE fileh;
|
|
1057 int result = -1;
|
|
1058
|
|
1059 if (old == NULL || new == NULL)
|
|
1060 {
|
|
1061 errno = ENOENT;
|
|
1062 return -1;
|
|
1063 }
|
|
1064
|
|
1065 C_STRING_TO_TSTR (old, old);
|
|
1066 fileh = qxeCreateFile (old, 0, 0, NULL, OPEN_EXISTING,
|
|
1067 FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
|
1068 if (fileh != INVALID_HANDLE_VALUE)
|
|
1069 {
|
|
1070 int wlen;
|
|
1071 WCHAR *newuni;
|
|
1072
|
|
1073 /* Confusingly, the "alternate" stream name field does not apply
|
|
1074 when restoring a hard link, and instead contains the actual
|
|
1075 stream data for the link (ie. the name of the link to create).
|
|
1076 The WIN32_STREAM_ID structure before the cStreamName field is
|
|
1077 the stream header, which is then immediately followed by the
|
|
1078 stream data. */
|
|
1079
|
|
1080 struct
|
|
1081 {
|
|
1082 WIN32_STREAM_ID wid;
|
|
1083 WCHAR wbuffer[MAX_PATH]; /* extra space for link name */
|
|
1084 } data;
|
|
1085
|
|
1086 TO_EXTERNAL_FORMAT (C_STRING, new,
|
|
1087 ALLOCA, (newuni, wlen), Qmswindows_unicode);
|
|
1088 if (wlen / sizeof (WCHAR) < MAX_PATH)
|
|
1089 {
|
|
1090 LPVOID context = NULL;
|
|
1091 DWORD wbytes = 0;
|
428
|
1092
|
771
|
1093 wcscpy (data.wid.cStreamName, newuni);
|
|
1094 data.wid.dwStreamId = BACKUP_LINK;
|
|
1095 data.wid.dwStreamAttributes = 0;
|
|
1096 data.wid.Size.LowPart = wlen; /* in bytes, not chars! */
|
|
1097 data.wid.Size.HighPart = 0;
|
|
1098 data.wid.dwStreamNameSize = 0;
|
|
1099
|
|
1100 if (BackupWrite (fileh, (LPBYTE)&data,
|
|
1101 offsetof (WIN32_STREAM_ID, cStreamName)
|
|
1102 + data.wid.Size.LowPart,
|
|
1103 &wbytes, FALSE, FALSE, &context)
|
|
1104 && BackupWrite (fileh, NULL, 0, &wbytes, TRUE, FALSE, &context))
|
|
1105 {
|
|
1106 /* succeeded */
|
|
1107 result = 0;
|
|
1108 }
|
|
1109 else
|
|
1110 {
|
|
1111 /* Should try mapping GetLastError to errno; for now just
|
|
1112 indicate a general error (eg. links not supported). */
|
|
1113 errno = EINVAL; // perhaps EMLINK?
|
|
1114 }
|
|
1115 }
|
|
1116
|
|
1117 CloseHandle (fileh);
|
|
1118 }
|
|
1119 else
|
|
1120 errno = ENOENT;
|
|
1121
|
|
1122 return result;
|
|
1123 }
|
|
1124
|
|
1125 /* sys_open() merged into sysdep.c sys_open() */
|
|
1126
|
|
1127 int
|
|
1128 mswindows_rename (const Intbyte *oldname, const Intbyte *newname)
|
|
1129 {
|
|
1130 int result;
|
|
1131 Intbyte *temp;
|
|
1132
|
|
1133 /* MoveFile on Windows 95 doesn't correctly change the short file name
|
428
|
1134 alias in a number of circumstances (it is not easy to predict when
|
|
1135 just by looking at oldname and newname, unfortunately). In these
|
|
1136 cases, renaming through a temporary name avoids the problem.
|
|
1137
|
771
|
1138 A second problem on Windows 95 is that renaming through a temp name when
|
428
|
1139 newname is uppercase fails (the final long name ends up in
|
|
1140 lowercase, although the short alias might be uppercase) UNLESS the
|
|
1141 long temp name is not 8.3.
|
|
1142
|
771
|
1143 So, on Windows 95 we always rename through a temp name, and we make sure
|
428
|
1144 the temp name has a long extension to ensure correct renaming. */
|
|
1145
|
771
|
1146 /* XEmacs: We sprintf() part of OLDNAME into part of OLDNAME + a number,
|
|
1147 so the following calculation should certainly be enough. */
|
428
|
1148
|
771
|
1149 temp = qxestrcpy (alloca_intbytes (2 * qxestrlen (oldname) + 100), oldname);
|
|
1150
|
|
1151 if (mswindows_windows9x_p)
|
428
|
1152 {
|
771
|
1153 Intbyte *o;
|
|
1154 Intbyte *p;
|
|
1155 int i = 0;
|
428
|
1156
|
771
|
1157 if (o = qxestrrchr (oldname, '\\'))
|
|
1158 o++;
|
|
1159 else
|
|
1160 o = (Intbyte *) oldname;
|
|
1161
|
|
1162 if (p = qxestrrchr (temp, '\\'))
|
428
|
1163 p++;
|
|
1164 else
|
|
1165 p = temp;
|
771
|
1166
|
|
1167 do
|
|
1168 {
|
|
1169 Extbyte *oldext, *tempext;
|
|
1170 /* Force temp name to require a manufactured 8.3 alias - this
|
|
1171 seems to make the second rename work properly. */
|
|
1172 qxesprintf (p, "_.%s.%u", o, i);
|
|
1173 i++;
|
|
1174 C_STRING_TO_EXTERNAL (oldname, oldext, Qfile_name);
|
|
1175 C_STRING_TO_EXTERNAL (temp, tempext, Qfile_name);
|
|
1176 result = rename (oldext, tempext);
|
|
1177 }
|
|
1178 /* This loop must surely terminate! */
|
|
1179 while (result < 0 && errno == EEXIST);
|
|
1180 if (result < 0)
|
428
|
1181 return -1;
|
|
1182 }
|
|
1183
|
771
|
1184 /* Emulate Unix behaviour - newname is deleted if it already exists
|
428
|
1185 (at least if it is a file; don't do this for directories).
|
771
|
1186
|
|
1187 Since we mustn't do this if we are just changing the case of the
|
|
1188 file name (we would end up deleting the file we are trying to
|
|
1189 rename!), we let rename detect if the destination file already
|
|
1190 exists - that way we avoid the possible pitfalls of trying to
|
|
1191 determine ourselves whether two names really refer to the same
|
|
1192 file, which is not always possible in the general case. (Consider
|
|
1193 all the permutations of shared or subst'd drives, etc.) */
|
|
1194 {
|
|
1195 Extbyte *newext, *tempext;
|
|
1196
|
|
1197 C_STRING_TO_EXTERNAL (newname, newext, Qfile_name);
|
|
1198 C_STRING_TO_EXTERNAL (temp, tempext, Qfile_name);
|
|
1199 result = rename (tempext, newext);
|
428
|
1200
|
771
|
1201 if (result < 0
|
|
1202 && errno == EEXIST
|
|
1203 && _chmod (newext, 0666) == 0
|
|
1204 && _unlink (newext) == 0)
|
|
1205 result = rename (tempext, newext);
|
|
1206 }
|
|
1207
|
|
1208 return result;
|
|
1209 }
|
428
|
1210
|
771
|
1211 int
|
|
1212 mswindows_unlink (const Intbyte *path)
|
|
1213 {
|
|
1214 Extbyte *pathout;
|
|
1215
|
|
1216 C_STRING_TO_EXTERNAL (path, pathout, Qfile_name);
|
|
1217 /* On Unix, unlink works without write permission. */
|
|
1218 _chmod (pathout, 0666);
|
|
1219 return _unlink (pathout);
|
428
|
1220 }
|
|
1221
|
|
1222 static FILETIME utc_base_ft;
|
592
|
1223 static long double utc_base;
|
440
|
1224 static int init = 0;
|
771
|
1225 static LARGE_INTEGER utc_base_li;
|
440
|
1226
|
771
|
1227 /* XEmacs: We seem to have a new definition of
|
|
1228 mswindows_convert_time(), although I'm not sure why. --ben */
|
428
|
1229
|
|
1230 time_t
|
771
|
1231 mswindows_convert_time (FILETIME uft)
|
440
|
1232 {
|
|
1233 time_t ret;
|
|
1234 #ifndef MAXLONGLONG
|
|
1235 SYSTEMTIME st;
|
|
1236 struct tm t;
|
|
1237 FILETIME ft;
|
|
1238 TIME_ZONE_INFORMATION tzi;
|
|
1239 DWORD tzid;
|
|
1240 #else
|
|
1241 LARGE_INTEGER lft;
|
|
1242 #endif
|
|
1243
|
|
1244 if (!init)
|
|
1245 {
|
|
1246 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
|
|
1247 SYSTEMTIME st;
|
|
1248
|
|
1249 st.wYear = 1970;
|
|
1250 st.wMonth = 1;
|
|
1251 st.wDay = 1;
|
|
1252 st.wHour = 0;
|
|
1253 st.wMinute = 0;
|
|
1254 st.wSecond = 0;
|
|
1255 st.wMilliseconds = 0;
|
|
1256
|
|
1257 SystemTimeToFileTime (&st, &utc_base_ft);
|
|
1258
|
|
1259 utc_base_li.LowPart = utc_base_ft.dwLowDateTime;
|
|
1260 utc_base_li.HighPart = utc_base_ft.dwHighDateTime;
|
|
1261
|
|
1262 init = 1;
|
|
1263 }
|
|
1264
|
|
1265 #ifdef MAXLONGLONG
|
|
1266
|
|
1267 /* On a compiler that supports long integers, do it the easy way */
|
|
1268 lft.LowPart = uft.dwLowDateTime;
|
|
1269 lft.HighPart = uft.dwHighDateTime;
|
|
1270 ret = (time_t) ((lft.QuadPart - utc_base_li.QuadPart) / 10000000);
|
|
1271
|
|
1272 #else
|
|
1273
|
|
1274 /* Do it the hard way using mktime. */
|
|
1275 FileTimeToLocalFileTime(&uft, &ft);
|
|
1276 FileTimeToSystemTime (&ft, &st);
|
|
1277 tzid = GetTimeZoneInformation (&tzi);
|
|
1278 t.tm_year = st.wYear - 1900;
|
|
1279 t.tm_mon = st.wMonth - 1;
|
|
1280 t.tm_mday = st.wDay;
|
|
1281 t.tm_hour = st.wHour;
|
|
1282 t.tm_min = st.wMinute;
|
|
1283 t.tm_sec = st.wSecond;
|
|
1284 t.tm_isdst = (tzid == TIME_ZONE_ID_DAYLIGHT);
|
|
1285 /* st.wMilliseconds not applicable */
|
|
1286 ret = mktime(&t);
|
|
1287 if (ret == -1)
|
|
1288 {
|
|
1289 ret = 0;
|
|
1290 }
|
|
1291
|
|
1292 #endif
|
|
1293
|
|
1294 return ret;
|
|
1295 }
|
428
|
1296
|
771
|
1297 static void
|
428
|
1298 convert_from_time_t (time_t time, FILETIME * pft)
|
|
1299 {
|
|
1300 long double tmp;
|
|
1301
|
|
1302 if (!init)
|
|
1303 {
|
|
1304 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
|
|
1305 SYSTEMTIME st;
|
|
1306
|
|
1307 st.wYear = 1970;
|
|
1308 st.wMonth = 1;
|
|
1309 st.wDay = 1;
|
|
1310 st.wHour = 0;
|
|
1311 st.wMinute = 0;
|
|
1312 st.wSecond = 0;
|
|
1313 st.wMilliseconds = 0;
|
|
1314
|
|
1315 SystemTimeToFileTime (&st, &utc_base_ft);
|
|
1316 utc_base = (long double) utc_base_ft.dwHighDateTime
|
|
1317 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
|
|
1318 init = 1;
|
|
1319 }
|
|
1320
|
|
1321 /* time in 100ns units since 1-Jan-1601 */
|
|
1322 tmp = (long double) time * 1e7 + utc_base;
|
|
1323 pft->dwHighDateTime = (DWORD) (tmp / (4096.0 * 1024 * 1024));
|
771
|
1324 pft->dwLowDateTime = (DWORD) (tmp - (4096.0 * 1024 * 1024) *
|
|
1325 pft->dwHighDateTime);
|
428
|
1326 }
|
|
1327
|
|
1328 #if 0
|
771
|
1329 /* A comment from Emacs 20.6:
|
|
1330
|
|
1331 No reason to keep this; faking inode values either by hashing or even
|
428
|
1332 using the file index from GetInformationByHandle, is not perfect and
|
|
1333 so by default Emacs doesn't use the inode values on Windows.
|
|
1334 Instead, we now determine file-truename correctly (except for
|
|
1335 possible drive aliasing etc). */
|
|
1336
|
771
|
1337 /* XEmacs: Removed the fake-inodes code here, which was if 0'd out.
|
|
1338 If you want it, look in w32.c in Emacs 20.6. */
|
428
|
1339 #endif
|
|
1340
|
442
|
1341 /* #### aichner@ecf.teradyne.com reported that with the library
|
|
1342 provided stat/fstat, (file-exist "d:\\tmp\\") =>> nil,
|
|
1343 (file-exist "d:\\tmp") =>> t, when d:\tmp exists. Whenever
|
|
1344 we opt to use non-encapsulated stat(), this should serve as
|
|
1345 a compatibility test. --kkm */
|
440
|
1346
|
771
|
1347 /* Provide fstat and utime as well as stat for consistent handling of
|
|
1348 file timestamps. */
|
442
|
1349 int
|
771
|
1350 mswindows_fstat (int desc, struct stat *buf)
|
432
|
1351 {
|
448
|
1352 HANDLE fh = (HANDLE) _get_osfhandle (desc);
|
|
1353 BY_HANDLE_FILE_INFORMATION info;
|
|
1354 DWORD fake_inode;
|
|
1355 int permission;
|
|
1356
|
|
1357 switch (GetFileType (fh) & ~FILE_TYPE_REMOTE)
|
432
|
1358 {
|
448
|
1359 case FILE_TYPE_DISK:
|
|
1360 buf->st_mode = _S_IFREG;
|
|
1361 if (!GetFileInformationByHandle (fh, &info))
|
|
1362 {
|
|
1363 errno = EACCES;
|
|
1364 return -1;
|
|
1365 }
|
|
1366 break;
|
|
1367 case FILE_TYPE_PIPE:
|
|
1368 buf->st_mode = _S_IFIFO;
|
|
1369 goto non_disk;
|
|
1370 case FILE_TYPE_CHAR:
|
|
1371 case FILE_TYPE_UNKNOWN:
|
|
1372 default:
|
|
1373 buf->st_mode = _S_IFCHR;
|
|
1374 non_disk:
|
|
1375 memset (&info, 0, sizeof (info));
|
|
1376 info.dwFileAttributes = 0;
|
|
1377 info.ftCreationTime = utc_base_ft;
|
|
1378 info.ftLastAccessTime = utc_base_ft;
|
|
1379 info.ftLastWriteTime = utc_base_ft;
|
|
1380 }
|
|
1381
|
|
1382 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
1383 {
|
|
1384 buf->st_mode = _S_IFDIR;
|
|
1385 buf->st_nlink = 2; /* doesn't really matter */
|
|
1386 fake_inode = 0; /* this doesn't either I think */
|
432
|
1387 }
|
|
1388 else
|
|
1389 {
|
462
|
1390 buf->st_nlink = (short) info.nNumberOfLinks;
|
448
|
1391 /* Might as well use file index to fake inode values, but this
|
|
1392 is not guaranteed to be unique unless we keep a handle open
|
|
1393 all the time (even then there are situations where it is
|
|
1394 not unique). Reputedly, there are at most 48 bits of info
|
|
1395 (on NTFS, presumably less on FAT). */
|
|
1396 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
|
432
|
1397 }
|
448
|
1398
|
|
1399 /* MSVC defines _ino_t to be short; other libc's might not. */
|
|
1400 if (sizeof (buf->st_ino) == 2)
|
462
|
1401 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16));
|
448
|
1402 else
|
462
|
1403 buf->st_ino = (unsigned short) fake_inode;
|
448
|
1404
|
|
1405 /* consider files to belong to current user */
|
|
1406 buf->st_uid = 0;
|
|
1407 buf->st_gid = 0;
|
|
1408
|
|
1409 buf->st_dev = info.dwVolumeSerialNumber;
|
|
1410 buf->st_rdev = info.dwVolumeSerialNumber;
|
|
1411
|
|
1412 buf->st_size = info.nFileSizeLow;
|
|
1413
|
|
1414 /* Convert timestamps to Unix format. */
|
771
|
1415 buf->st_mtime = mswindows_convert_time (info.ftLastWriteTime);
|
|
1416 buf->st_atime = mswindows_convert_time (info.ftLastAccessTime);
|
448
|
1417 if (buf->st_atime == 0) buf->st_atime = buf->st_mtime;
|
771
|
1418 buf->st_ctime = mswindows_convert_time (info.ftCreationTime);
|
448
|
1419 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
|
|
1420
|
|
1421 /* determine rwx permissions */
|
|
1422 if (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
|
|
1423 permission = _S_IREAD;
|
|
1424 else
|
|
1425 permission = _S_IREAD | _S_IWRITE;
|
|
1426
|
|
1427 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
1428 permission |= _S_IEXEC;
|
771
|
1429 else
|
|
1430 {
|
|
1431 #if 0 /* no way of knowing the filename */
|
|
1432 Intbyte *p = qxestrrchr (name, '.');
|
|
1433 if (p != NULL &&
|
|
1434 (qxestrcasecmp (p, ".exe") == 0 ||
|
|
1435 qxestrcasecmp (p, ".com") == 0 ||
|
|
1436 qxestrcasecmp (p, ".bat") == 0 ||
|
|
1437 qxestrcasecmp (p, ".cmd") == 0))
|
|
1438 permission |= _S_IEXEC;
|
|
1439 #endif
|
|
1440 }
|
448
|
1441
|
|
1442 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
|
|
1443
|
|
1444 return 0;
|
432
|
1445 }
|
|
1446
|
428
|
1447 /* MSVC stat function can't cope with UNC names and has other bugs, so
|
|
1448 replace it with our own. This also allows us to calculate consistent
|
|
1449 inode values without hacks in the main Emacs code. */
|
|
1450 int
|
771
|
1451 mswindows_stat (const Intbyte *path, struct stat *buf)
|
428
|
1452 {
|
771
|
1453 Intbyte *name, *r;
|
|
1454 WIN32_FIND_DATAW wfd;
|
428
|
1455 HANDLE fh;
|
|
1456 DWORD fake_inode;
|
|
1457 int permission;
|
771
|
1458 Bytecount len;
|
428
|
1459 int rootdir = FALSE;
|
771
|
1460 Extbyte *nameext;
|
428
|
1461
|
|
1462 if (path == NULL || buf == NULL)
|
|
1463 {
|
|
1464 errno = EFAULT;
|
|
1465 return -1;
|
|
1466 }
|
|
1467
|
771
|
1468 name = qxestrcpy (alloca_intbytes (qxestrlen (path) + 10), path);
|
|
1469
|
|
1470 get_volume_info (name, &path);
|
|
1471 /* must be valid filename, no wild cards or other invalid characters */
|
|
1472 if (qxestrpbrk (name, "*?|<>\""))
|
428
|
1473 {
|
|
1474 errno = ENOENT;
|
|
1475 return -1;
|
|
1476 }
|
|
1477
|
771
|
1478 /* If name is "c:/.." or "/.." then stat "c:/" or "/". */
|
|
1479 r = IS_DEVICE_SEP (name[1]) ? &name[2] : name;
|
|
1480 if (IS_DIRECTORY_SEP (r[0]) && r[1] == '.' && r[2] == '.' && r[3] == '\0')
|
|
1481 {
|
|
1482 r[1] = r[2] = '\0';
|
|
1483 }
|
|
1484
|
428
|
1485 /* Remove trailing directory separator, unless name is the root
|
|
1486 directory of a drive or UNC volume in which case ensure there
|
|
1487 is a trailing separator. */
|
771
|
1488 len = qxestrlen (name);
|
428
|
1489 rootdir = (path >= name + len - 1
|
|
1490 && (IS_DIRECTORY_SEP (*path) || *path == 0));
|
771
|
1491
|
|
1492 if (is_unc_volume (name))
|
|
1493 {
|
|
1494 DWORD attrs = unc_volume_file_attributes (name);
|
|
1495
|
|
1496 if (attrs == -1)
|
|
1497 return -1;
|
428
|
1498
|
771
|
1499 memset (&wfd, 0, sizeof (wfd));
|
|
1500 wfd.dwFileAttributes = attrs;
|
|
1501 wfd.ftCreationTime = utc_base_ft;
|
|
1502 wfd.ftLastAccessTime = utc_base_ft;
|
|
1503 wfd.ftLastWriteTime = utc_base_ft;
|
|
1504 /* XEmacs deleted: strcpy (wfd.cFileName, name);
|
|
1505 Not used later on. */
|
|
1506 }
|
|
1507 else if (rootdir)
|
428
|
1508 {
|
|
1509 if (!IS_DIRECTORY_SEP (name[len-1]))
|
771
|
1510 qxestrcat (name, (Intbyte *) "\\");
|
|
1511 C_STRING_TO_TSTR (name, nameext);
|
|
1512 if (qxeGetDriveType (nameext) < 2)
|
428
|
1513 {
|
|
1514 errno = ENOENT;
|
|
1515 return -1;
|
|
1516 }
|
|
1517 memset (&wfd, 0, sizeof (wfd));
|
|
1518 wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
|
|
1519 wfd.ftCreationTime = utc_base_ft;
|
|
1520 wfd.ftLastAccessTime = utc_base_ft;
|
|
1521 wfd.ftLastWriteTime = utc_base_ft;
|
771
|
1522 /* XEmacs deleted: strcpy (wfd.cFileName, name);
|
|
1523 Not used later on. */
|
428
|
1524 }
|
|
1525 else
|
|
1526 {
|
|
1527 if (IS_DIRECTORY_SEP (name[len-1]))
|
|
1528 name[len - 1] = 0;
|
|
1529
|
|
1530 /* (This is hacky, but helps when doing file completions on
|
|
1531 network drives.) Optimize by using information available from
|
|
1532 active readdir if possible. */
|
771
|
1533 if (dir_pathname)
|
|
1534 {
|
|
1535 len = qxestrlen (dir_pathname);
|
|
1536 if (len && IS_DIRECTORY_SEP (dir_pathname[len-1]))
|
|
1537 len--;
|
|
1538 }
|
|
1539 if (dir_find_handle != INVALID_HANDLE_VALUE
|
|
1540 && dir_pathname
|
|
1541 && qxestrncasecmp_i18n (name, dir_pathname, len) == 0
|
|
1542 && IS_DIRECTORY_SEP (name[len])
|
|
1543 && qxestrcasecmp_i18n (name + len + 1,
|
|
1544 (Intbyte *) dir_static.d_name) == 0)
|
428
|
1545 {
|
|
1546 /* This was the last entry returned by readdir. */
|
|
1547 wfd = dir_find_data;
|
|
1548 }
|
|
1549 else
|
|
1550 {
|
771
|
1551 C_STRING_TO_TSTR (name, nameext);
|
|
1552 fh = qxeFindFirstFile (nameext, &wfd);
|
|
1553 if (fh == INVALID_HANDLE_VALUE)
|
|
1554 {
|
|
1555 errno = ENOENT;
|
|
1556 return -1;
|
|
1557 }
|
|
1558 FindClose (fh);
|
|
1559 /* XEmacs: Don't need to convert wfd.cFileName because
|
|
1560 not used later on. */
|
428
|
1561 }
|
|
1562 }
|
|
1563
|
|
1564 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
1565 {
|
|
1566 buf->st_mode = _S_IFDIR;
|
|
1567 buf->st_nlink = 2; /* doesn't really matter */
|
|
1568 fake_inode = 0; /* this doesn't either I think */
|
|
1569 }
|
771
|
1570 else
|
428
|
1571 {
|
771
|
1572 if (!NILP (Vmswindows_get_true_file_attributes))
|
|
1573 C_STRING_TO_TSTR (name, nameext);
|
|
1574 if (!NILP (Vmswindows_get_true_file_attributes)
|
|
1575 /* No access rights required to get info. */
|
|
1576 && (fh = qxeCreateFile (nameext, 0, 0, NULL, OPEN_EXISTING, 0, NULL))
|
|
1577 != INVALID_HANDLE_VALUE)
|
|
1578 {
|
|
1579 /* This is more accurate in terms of gettting the correct number
|
|
1580 of links, but is quite slow (it is noticable when Emacs is
|
|
1581 making a list of file name completions). */
|
|
1582 BY_HANDLE_FILE_INFORMATION info;
|
428
|
1583
|
771
|
1584 if (GetFileInformationByHandle (fh, &info))
|
|
1585 {
|
|
1586 buf->st_nlink = (short) info.nNumberOfLinks;
|
|
1587 /* Might as well use file index to fake inode values, but this
|
|
1588 is not guaranteed to be unique unless we keep a handle open
|
|
1589 all the time (even then there are situations where it is
|
|
1590 not unique). Reputedly, there are at most 48 bits of info
|
|
1591 (on NTFS, presumably less on FAT). */
|
|
1592 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
|
|
1593 }
|
|
1594 else
|
|
1595 {
|
|
1596 buf->st_nlink = 1;
|
|
1597 fake_inode = 0;
|
|
1598 }
|
428
|
1599
|
|
1600 switch (GetFileType (fh))
|
|
1601 {
|
|
1602 case FILE_TYPE_DISK:
|
|
1603 buf->st_mode = _S_IFREG;
|
|
1604 break;
|
|
1605 case FILE_TYPE_PIPE:
|
|
1606 buf->st_mode = _S_IFIFO;
|
|
1607 break;
|
|
1608 case FILE_TYPE_CHAR:
|
|
1609 case FILE_TYPE_UNKNOWN:
|
|
1610 default:
|
|
1611 buf->st_mode = _S_IFCHR;
|
|
1612 }
|
|
1613 CloseHandle (fh);
|
|
1614 }
|
|
1615 else
|
|
1616 {
|
771
|
1617 /* Don't bother to make this information more accurate. */
|
|
1618 buf->st_mode = _S_IFREG;
|
|
1619 buf->st_nlink = 1;
|
|
1620 fake_inode = 0;
|
428
|
1621 }
|
|
1622 }
|
|
1623
|
|
1624 #if 0
|
771
|
1625 /* XEmacs: Removed the fake-inodes code here, which was if 0'd out.
|
|
1626 If you want it, look in w32.c in Emacs 20.6. */
|
428
|
1627 #endif
|
|
1628
|
771
|
1629 /* MSVC defines _ino_t to be short; other libc's might not. */
|
|
1630 if (sizeof (buf->st_ino) == 2)
|
|
1631 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16));
|
|
1632 else
|
|
1633 buf->st_ino = (unsigned short) fake_inode;
|
428
|
1634
|
|
1635 /* consider files to belong to current user */
|
771
|
1636 buf->st_uid = the_passwd.pw_uid;
|
|
1637 buf->st_gid = the_passwd.pw_gid;
|
428
|
1638
|
771
|
1639 /* volume_info is set by get_volume_info */
|
428
|
1640 buf->st_dev = volume_info.serialnum;
|
|
1641 buf->st_rdev = volume_info.serialnum;
|
|
1642
|
771
|
1643
|
428
|
1644 buf->st_size = wfd.nFileSizeLow;
|
|
1645
|
|
1646 /* Convert timestamps to Unix format. */
|
771
|
1647 buf->st_mtime = mswindows_convert_time (wfd.ftLastWriteTime);
|
|
1648 buf->st_atime = mswindows_convert_time (wfd.ftLastAccessTime);
|
428
|
1649 if (buf->st_atime == 0) buf->st_atime = buf->st_mtime;
|
771
|
1650 buf->st_ctime = mswindows_convert_time (wfd.ftCreationTime);
|
428
|
1651 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
|
|
1652
|
|
1653 /* determine rwx permissions */
|
|
1654 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
|
|
1655 permission = _S_IREAD;
|
|
1656 else
|
|
1657 permission = _S_IREAD | _S_IWRITE;
|
|
1658
|
|
1659 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
1660 permission |= _S_IEXEC;
|
771
|
1661 else if (is_exec (name))
|
|
1662 permission |= _S_IEXEC;
|
428
|
1663
|
|
1664 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
|
|
1665
|
|
1666 return 0;
|
|
1667 }
|
|
1668
|
|
1669 int
|
771
|
1670 mswindows_utime (Lisp_Object path, struct utimbuf *times)
|
428
|
1671 {
|
771
|
1672 /* #### Supposedly we're providing this because standard utime()
|
|
1673 might not work; or at the very least to get consistent results
|
|
1674 since we replace other time-handling routines in stat. But out
|
|
1675 replacement doesn't seem to work, probably due to some subtle bug
|
|
1676 in this routine, which should be investigated eventually. So for
|
|
1677 the moment, we just use utime(), which conceivably might be
|
|
1678 slightly off in comparison with our own routines? Seems strange,
|
|
1679 and so far no problems seen. --ben */
|
428
|
1680
|
771
|
1681 struct utimbuf deftime;
|
|
1682 #if 0
|
|
1683 HANDLE fh;
|
|
1684 #endif
|
|
1685 static FILETIME mtime;
|
|
1686 static FILETIME atime;
|
|
1687 Extbyte *filename;
|
428
|
1688
|
771
|
1689 if (times == NULL)
|
428
|
1690 {
|
771
|
1691 deftime.modtime = deftime.actime = time (NULL);
|
|
1692 times = &deftime;
|
428
|
1693 }
|
|
1694
|
771
|
1695 LISP_STRING_TO_TSTR (path, filename);
|
|
1696 /* APA: SetFileTime fails to set mtime correctly (always 1-Jan-1970) */
|
|
1697 #if 0
|
|
1698 /* Need write access to set times. */
|
|
1699 fh = qxeCreateFile (filename, GENERIC_WRITE,
|
|
1700 FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
1701 0, OPEN_EXISTING, 0, NULL);
|
|
1702 if (fh)
|
|
1703 {
|
|
1704 convert_from_time_t (times->actime, &atime);
|
|
1705 convert_from_time_t (times->modtime, &mtime);
|
|
1706 if (!SetFileTime (fh, NULL, &atime, &mtime))
|
|
1707 {
|
|
1708 CloseHandle (fh);
|
|
1709 errno = EACCES;
|
|
1710 return -1;
|
|
1711 }
|
|
1712 CloseHandle (fh);
|
|
1713 }
|
|
1714 else
|
|
1715 {
|
|
1716 errno = EINVAL;
|
|
1717 return -1;
|
|
1718 }
|
|
1719 return 0;
|
|
1720 #else
|
|
1721 {
|
|
1722 struct _utimbuf newtimes;
|
|
1723
|
|
1724 newtimes.actime = times->actime;
|
|
1725 newtimes.modtime = times->modtime;
|
|
1726
|
|
1727 if (XEUNICODE_P)
|
|
1728 return _wutime ((const wchar_t *) filename, &newtimes);
|
|
1729 else
|
|
1730 return _utime (filename, &newtimes);
|
|
1731 }
|
|
1732 #endif
|
|
1733 }
|
|
1734
|
|
1735 Intbyte *
|
|
1736 mswindows_getdcwd (int drivelet)
|
|
1737 {
|
|
1738 Extbyte *cwdext;
|
|
1739 Intbyte *cwd;
|
|
1740
|
|
1741 if (XEUNICODE_P)
|
|
1742 cwdext = (Extbyte *) _wgetdcwd (drivelet, NULL, 0);
|
|
1743 else
|
|
1744 cwdext = _getdcwd (drivelet, NULL, 0);
|
|
1745 TSTR_TO_C_STRING_MALLOC (cwdext, cwd);
|
|
1746 xfree (cwdext);
|
|
1747 return cwd;
|
428
|
1748 }
|
|
1749
|
|
1750 void
|
442
|
1751 init_ntproc (void)
|
428
|
1752 {
|
|
1753 /* Initial preparation for subprocess support: replace our standard
|
|
1754 handles with non-inheritable versions. */
|
|
1755 {
|
|
1756 HANDLE parent;
|
|
1757 HANDLE stdin_save = INVALID_HANDLE_VALUE;
|
|
1758 HANDLE stdout_save = INVALID_HANDLE_VALUE;
|
|
1759 HANDLE stderr_save = INVALID_HANDLE_VALUE;
|
|
1760
|
|
1761 parent = GetCurrentProcess ();
|
|
1762
|
|
1763 /* ignore errors when duplicating and closing; typically the
|
|
1764 handles will be invalid when running as a gui program. */
|
|
1765 DuplicateHandle (parent,
|
|
1766 GetStdHandle (STD_INPUT_HANDLE),
|
|
1767 parent,
|
|
1768 &stdin_save,
|
|
1769 0,
|
|
1770 FALSE,
|
|
1771 DUPLICATE_SAME_ACCESS);
|
|
1772
|
|
1773 DuplicateHandle (parent,
|
|
1774 GetStdHandle (STD_OUTPUT_HANDLE),
|
|
1775 parent,
|
|
1776 &stdout_save,
|
|
1777 0,
|
|
1778 FALSE,
|
|
1779 DUPLICATE_SAME_ACCESS);
|
|
1780
|
|
1781 DuplicateHandle (parent,
|
|
1782 GetStdHandle (STD_ERROR_HANDLE),
|
|
1783 parent,
|
|
1784 &stderr_save,
|
|
1785 0,
|
|
1786 FALSE,
|
|
1787 DUPLICATE_SAME_ACCESS);
|
|
1788
|
771
|
1789 retry_fclose (stdin);
|
|
1790 retry_fclose (stdout);
|
|
1791 retry_fclose (stderr);
|
428
|
1792
|
|
1793 if (stdin_save != INVALID_HANDLE_VALUE)
|
|
1794 _open_osfhandle ((long) stdin_save, O_TEXT);
|
|
1795 else
|
|
1796 _open ("nul", O_TEXT | O_NOINHERIT | O_RDONLY);
|
|
1797 _fdopen (0, "r");
|
|
1798
|
|
1799 if (stdout_save != INVALID_HANDLE_VALUE)
|
|
1800 _open_osfhandle ((long) stdout_save, O_TEXT);
|
|
1801 else
|
|
1802 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
|
|
1803 _fdopen (1, "w");
|
|
1804
|
|
1805 if (stderr_save != INVALID_HANDLE_VALUE)
|
|
1806 _open_osfhandle ((long) stderr_save, O_TEXT);
|
|
1807 else
|
|
1808 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
|
|
1809 _fdopen (2, "w");
|
|
1810 }
|
|
1811
|
771
|
1812 /* determine which drives are fixed, for get_cached_volume_information */
|
428
|
1813 {
|
|
1814 /* GetDriveType must have trailing backslash. */
|
771
|
1815 Intbyte drive[] = "A:\\";
|
428
|
1816
|
|
1817 /* Loop over all possible drive letters */
|
771
|
1818 while (*drive <= 'Z')
|
428
|
1819 {
|
771
|
1820 Extbyte *driveext;
|
|
1821
|
|
1822 C_STRING_TO_TSTR (drive, driveext);
|
|
1823
|
428
|
1824 /* Record if this drive letter refers to a fixed drive. */
|
771
|
1825 fixed_drives[DRIVE_INDEX (*drive)] =
|
|
1826 (qxeGetDriveType (driveext) == DRIVE_FIXED);
|
428
|
1827
|
|
1828 (*drive)++;
|
|
1829 }
|
771
|
1830
|
|
1831 /* Reset the volume info cache. */
|
|
1832 volume_cache = NULL;
|
428
|
1833 }
|
|
1834 }
|
|
1835
|
442
|
1836
|
|
1837 /*--------------------------------------------------------------------*/
|
|
1838 /* Memory-mapped files */
|
|
1839 /*--------------------------------------------------------------------*/
|
|
1840
|
428
|
1841 int
|
771
|
1842 open_input_file (file_data *p_file, const Intbyte *filename)
|
428
|
1843 {
|
442
|
1844 /* Synched with FSF 20.6. We fixed some warnings. */
|
428
|
1845 HANDLE file;
|
|
1846 HANDLE file_mapping;
|
771
|
1847 void *file_base;
|
428
|
1848 DWORD size, upper_size;
|
771
|
1849 Extbyte *fileext;
|
428
|
1850
|
771
|
1851 C_STRING_TO_TSTR (filename, fileext);
|
|
1852
|
|
1853 file = qxeCreateFile (fileext, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
1854 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
428
|
1855 if (file == INVALID_HANDLE_VALUE)
|
|
1856 return FALSE;
|
|
1857
|
|
1858 size = GetFileSize (file, &upper_size);
|
771
|
1859 file_mapping = qxeCreateFileMapping (file, NULL, PAGE_READONLY,
|
|
1860 0, size, NULL);
|
428
|
1861 if (!file_mapping)
|
|
1862 return FALSE;
|
|
1863
|
|
1864 file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size);
|
|
1865 if (file_base == 0)
|
|
1866 return FALSE;
|
|
1867
|
771
|
1868 p_file->name = filename;
|
442
|
1869 p_file->size = size;
|
|
1870 p_file->file = file;
|
|
1871 p_file->file_mapping = file_mapping;
|
771
|
1872 p_file->file_base = file_base;
|
442
|
1873
|
|
1874 return TRUE;
|
|
1875 }
|
|
1876
|
|
1877 int
|
771
|
1878 open_output_file (file_data *p_file, const Intbyte *filename,
|
|
1879 unsigned long size)
|
442
|
1880 {
|
|
1881 /* Synched with FSF 20.6. We fixed some warnings. */
|
|
1882 HANDLE file;
|
|
1883 HANDLE file_mapping;
|
771
|
1884 void *file_base;
|
|
1885 Extbyte *fileext;
|
442
|
1886
|
771
|
1887 C_STRING_TO_TSTR (filename, fileext);
|
|
1888
|
|
1889 file = qxeCreateFile (fileext, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
|
1890 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
442
|
1891 if (file == INVALID_HANDLE_VALUE)
|
|
1892 return FALSE;
|
|
1893
|
771
|
1894 file_mapping = qxeCreateFileMapping (file, NULL, PAGE_READWRITE,
|
|
1895 0, size, NULL);
|
442
|
1896 if (!file_mapping)
|
|
1897 return FALSE;
|
|
1898
|
|
1899 file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size);
|
|
1900 if (file_base == NULL)
|
|
1901 return FALSE;
|
|
1902
|
|
1903 p_file->name = filename;
|
428
|
1904 p_file->size = size;
|
|
1905 p_file->file = file;
|
|
1906 p_file->file_mapping = file_mapping;
|
771
|
1907 p_file->file_base = file_base;
|
428
|
1908
|
|
1909 return TRUE;
|
|
1910 }
|
|
1911
|
442
|
1912 #if 1 /* !defined(MINGW) */
|
|
1913 /* Return pointer to section header for section containing the given
|
|
1914 relative virtual address. */
|
|
1915 static IMAGE_SECTION_HEADER *
|
771
|
1916 rva_to_section (DWORD rva, IMAGE_NT_HEADERS *nt_header)
|
442
|
1917 {
|
|
1918 /* Synched with FSF 20.6. We added MINGW stuff. */
|
|
1919 PIMAGE_SECTION_HEADER section;
|
|
1920 int i;
|
|
1921
|
|
1922 section = IMAGE_FIRST_SECTION (nt_header);
|
|
1923
|
|
1924 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
|
|
1925 {
|
|
1926 /* Some linkers (eg. the NT SDK linker I believe) swapped the
|
|
1927 meaning of these two values - or rather, they ignored
|
|
1928 VirtualSize entirely and always set it to zero. This affects
|
|
1929 some very old exes (eg. gzip dated Dec 1993). Since
|
|
1930 mswindows_executable_type relies on this function to work reliably,
|
|
1931 we need to cope with this. */
|
|
1932 DWORD real_size = max (section->SizeOfRawData,
|
|
1933 section->Misc.VirtualSize);
|
|
1934 if (rva >= section->VirtualAddress
|
|
1935 && rva < section->VirtualAddress + real_size)
|
|
1936 return section;
|
|
1937 section++;
|
|
1938 }
|
|
1939 return NULL;
|
|
1940 }
|
|
1941 #endif
|
|
1942
|
|
1943 void
|
771
|
1944 mswindows_executable_type (const Intbyte *filename, int *is_dos_app,
|
|
1945 int *is_cygnus_app)
|
442
|
1946 {
|
|
1947 /* Synched with FSF 20.6. We added MINGW stuff and casts. */
|
|
1948 file_data executable;
|
771
|
1949 Intbyte *p;
|
442
|
1950
|
|
1951 /* Default values in case we can't tell for sure. */
|
|
1952 *is_dos_app = FALSE;
|
|
1953 *is_cygnus_app = FALSE;
|
|
1954
|
|
1955 if (!open_input_file (&executable, filename))
|
|
1956 return;
|
|
1957
|
771
|
1958 p = qxestrrchr (filename, '.');
|
442
|
1959
|
|
1960 /* We can only identify DOS .com programs from the extension. */
|
771
|
1961 if (p && qxestrcasecmp (p, ".com") == 0)
|
442
|
1962 *is_dos_app = TRUE;
|
771
|
1963 else if (p && (qxestrcasecmp (p, ".bat") == 0 ||
|
|
1964 qxestrcasecmp (p, ".cmd") == 0))
|
442
|
1965 {
|
|
1966 /* A DOS shell script - it appears that CreateProcess is happy to
|
|
1967 accept this (somewhat surprisingly); presumably it looks at
|
|
1968 COMSPEC to determine what executable to actually invoke.
|
|
1969 Therefore, we have to do the same here as well. */
|
|
1970 /* Actually, I think it uses the program association for that
|
|
1971 extension, which is defined in the registry. */
|
|
1972 p = egetenv ("COMSPEC");
|
|
1973 if (p)
|
|
1974 mswindows_executable_type (p, is_dos_app, is_cygnus_app);
|
|
1975 }
|
|
1976 else
|
|
1977 {
|
|
1978 /* Look for DOS .exe signature - if found, we must also check that
|
|
1979 it isn't really a 16- or 32-bit Windows exe, since both formats
|
|
1980 start with a DOS program stub. Note that 16-bit Windows
|
|
1981 executables use the OS/2 1.x format. */
|
|
1982
|
|
1983 #if 0 /* defined( MINGW ) */
|
771
|
1984 /* mingw doesn't have enough headers to detect cygwin
|
442
|
1985 apps, just do what we can. */
|
771
|
1986 FILHDR *exe_header;
|
442
|
1987
|
771
|
1988 exe_header = (FILHDR *) executable.file_base;
|
442
|
1989 if (exe_header->e_magic != DOSMAGIC)
|
|
1990 goto unwind;
|
|
1991
|
771
|
1992 if ((char *) exe_header->e_lfanew > (char *) executable.size)
|
442
|
1993 {
|
|
1994 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
|
|
1995 *is_dos_app = TRUE;
|
|
1996 }
|
|
1997 else if (exe_header->nt_signature != NT_SIGNATURE)
|
|
1998 {
|
|
1999 *is_dos_app = TRUE;
|
|
2000 }
|
|
2001 #else
|
771
|
2002 IMAGE_DOS_HEADER *dos_header;
|
|
2003 IMAGE_NT_HEADERS *nt_header;
|
442
|
2004
|
|
2005 dos_header = (PIMAGE_DOS_HEADER) executable.file_base;
|
|
2006 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
|
|
2007 goto unwind;
|
|
2008
|
771
|
2009 nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header +
|
|
2010 dos_header->e_lfanew);
|
442
|
2011
|
771
|
2012 if ((char *) nt_header > (char *) dos_header + executable.size)
|
442
|
2013 {
|
|
2014 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
|
|
2015 *is_dos_app = TRUE;
|
|
2016 }
|
|
2017 else if (nt_header->Signature != IMAGE_NT_SIGNATURE &&
|
|
2018 LOWORD (nt_header->Signature) != IMAGE_OS2_SIGNATURE)
|
|
2019 {
|
|
2020 *is_dos_app = TRUE;
|
|
2021 }
|
|
2022 else if (nt_header->Signature == IMAGE_NT_SIGNATURE)
|
|
2023 {
|
|
2024 /* Look for cygwin.dll in DLL import list. */
|
|
2025 IMAGE_DATA_DIRECTORY import_dir =
|
771
|
2026 nt_header->OptionalHeader.
|
|
2027 DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
|
|
2028 IMAGE_IMPORT_DESCRIPTOR *imports;
|
|
2029 IMAGE_SECTION_HEADER *section;
|
442
|
2030
|
|
2031 section = rva_to_section (import_dir.VirtualAddress, nt_header);
|
771
|
2032 imports =
|
|
2033 (IMAGE_IMPORT_DESCRIPTOR *) RVA_TO_PTR (import_dir.VirtualAddress,
|
|
2034 section, executable);
|
|
2035
|
442
|
2036 for ( ; imports->Name; imports++)
|
|
2037 {
|
771
|
2038 Extbyte *dllname_ext =
|
|
2039 (Extbyte *) RVA_TO_PTR (imports->Name, section, executable);
|
|
2040 Intbyte *dllname;
|
|
2041
|
|
2042 EXTERNAL_TO_C_STRING (dllname_ext, dllname, Qbinary);
|
442
|
2043
|
|
2044 /* The exact name of the cygwin dll has changed with
|
|
2045 various releases, but hopefully this will be reasonably
|
|
2046 future proof. */
|
771
|
2047 if (qxestrncasecmp (dllname, (Intbyte *) "cygwin", 6) == 0)
|
442
|
2048 {
|
|
2049 *is_cygnus_app = TRUE;
|
|
2050 break;
|
|
2051 }
|
|
2052 }
|
|
2053 }
|
|
2054 #endif
|
|
2055 }
|
|
2056
|
|
2057 unwind:
|
|
2058 close_file_data (&executable);
|
|
2059 }
|
|
2060
|
428
|
2061 /* Close the system structures associated with the given file. */
|
|
2062 void
|
|
2063 close_file_data (file_data *p_file)
|
|
2064 {
|
611
|
2065 UnmapViewOfFile (p_file->file_base);
|
|
2066 CloseHandle (p_file->file_mapping);
|
|
2067 CloseHandle (p_file->file);
|
428
|
2068 }
|
|
2069
|
771
|
2070
|
|
2071 /* Some miscellaneous functions that are Windows specific, but not GUI
|
|
2072 specific (ie. are applicable in terminal or batch mode as well). */
|
|
2073
|
|
2074 DEFUN ("mswindows-short-file-name", Fmswindows_short_file_name, 1, 1, "", /*
|
|
2075 Return the short file name version (8.3) of the full path of FILENAME.
|
|
2076 If FILENAME does not exist, return nil.
|
|
2077 All path elements in FILENAME are converted to their short names.
|
|
2078 */
|
|
2079 (filename))
|
|
2080 {
|
|
2081 Extbyte shortname[MAX_PATH * MAX_XETCHAR_SIZE];
|
|
2082 Extbyte *fileext;
|
|
2083 Intbyte *shortint;
|
|
2084
|
|
2085 CHECK_STRING (filename);
|
|
2086
|
|
2087 /* first expand it. */
|
|
2088 filename = Fexpand_file_name (filename, Qnil);
|
|
2089
|
|
2090 LISP_STRING_TO_TSTR (filename, fileext);
|
|
2091 /* luckily, this returns the short version of each element in the path. */
|
|
2092 if (qxeGetShortPathName (fileext, shortname,
|
|
2093 sizeof (shortname) / XETCHAR_SIZE) == 0)
|
|
2094 return Qnil;
|
|
2095
|
|
2096 TSTR_TO_C_STRING (shortname, shortint);
|
|
2097 MSWINDOWS_NORMALIZE_FILENAME (shortint);
|
|
2098
|
|
2099 return build_string (shortint);
|
|
2100 }
|
|
2101
|
|
2102
|
|
2103 DEFUN ("mswindows-long-file-name", Fmswindows_long_file_name, 1, 1, "", /*
|
|
2104 Return the long file name version of the full path of FILENAME.
|
|
2105 If FILENAME does not exist, return nil.
|
|
2106 All path elements in FILENAME are converted to their long names.
|
|
2107 */
|
|
2108 (filename))
|
|
2109 {
|
|
2110 Intbyte *longname, *canon;
|
|
2111 Lisp_Object ret;
|
|
2112
|
|
2113 CHECK_STRING (filename);
|
|
2114
|
|
2115 /* first expand it. */
|
|
2116 filename = Fexpand_file_name (filename, Qnil);
|
|
2117
|
|
2118 if (!(longname = mswindows_get_long_filename (XSTRING_DATA (filename))))
|
|
2119 return Qnil;
|
|
2120
|
|
2121 canon = mswindows_canonicalize_filename (longname);
|
|
2122 ret = build_string (canon);
|
|
2123 xfree (canon);
|
|
2124 xfree (longname);
|
|
2125 return ret;
|
|
2126 }
|
|
2127
|
|
2128 void
|
|
2129 syms_of_nt (void)
|
|
2130 {
|
|
2131 DEFSUBR (Fmswindows_short_file_name);
|
|
2132 DEFSUBR (Fmswindows_long_file_name);
|
|
2133 }
|
|
2134
|
440
|
2135 void
|
|
2136 vars_of_nt (void)
|
|
2137 {
|
771
|
2138 DEFVAR_INT ("mswindows-fake-unix-uid", &mswindows_fake_unix_uid /*
|
440
|
2139 *Set uid returned by `user-uid' and `user-real-uid'.
|
771
|
2140 Under NT and 9x, there are no uids, and even no almighty user called root.
|
|
2141 By setting this variable, you can have any uid of choice. Default is 0.
|
440
|
2142 Changes to this variable take effect immediately.
|
|
2143 */ );
|
771
|
2144 mswindows_fake_unix_uid = 0;
|
|
2145
|
|
2146 DEFVAR_LISP ("mswindows-get-true-file-attributes", &Vmswindows_get_true_file_attributes /*
|
|
2147 Non-nil means determine accurate link count in file-attributes.
|
|
2148 This option slows down file-attributes noticeably, so is disabled by
|
|
2149 default. Note that it is only useful for files on NTFS volumes,
|
|
2150 where hard links are supported.
|
|
2151 */ );
|
|
2152 Vmswindows_get_true_file_attributes = Qnil;
|
440
|
2153 }
|
|
2154
|
428
|
2155 /* end of nt.c */
|