1 /* Utility and Unix shadow routines for XEmacs on Windows NT.
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4 This file is part of XEmacs.
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 Geoff Voelker (voelker@cs.washington.edu) 7-29-94 */
24 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
25 /* Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */
35 #include "syssignal.h"
58 extern Lisp_Object Vmswindows_downcase_file_names;
60 extern Lisp_Object Vwin32_generate_fake_inodes;
62 extern Lisp_Object Vmswindows_get_true_file_attributes;
66 static char startup_dir[ MAXPATHLEN ];
68 /* Get the current working directory. */
73 if (GetCurrentDirectory (MAXPATHLEN, dir) > 0)
77 /* Emacs doesn't actually change directory itself, and we want to
78 force our real wd to be where emacs.exe is to avoid unnecessary
79 conflicts when trying to rename or delete directories. */
80 strcpy (dir, startup_dir);
85 /* Emulate getloadavg. */
87 getloadavg (double loadavg[], int nelem)
91 /* A faithful emulation is going to have to be saved for a rainy day. */
92 for (i = 0; i < nelem; i++)
99 /* Emulate getpwuid, getpwnam and others. */
101 #define PASSWD_FIELD_SIZE 256
103 static char the_passwd_name[PASSWD_FIELD_SIZE];
104 static char the_passwd_passwd[PASSWD_FIELD_SIZE];
105 static char the_passwd_gecos[PASSWD_FIELD_SIZE];
106 static char the_passwd_dir[PASSWD_FIELD_SIZE];
107 static char the_passwd_shell[PASSWD_FIELD_SIZE];
109 static struct passwd the_passwd =
124 return nt_fake_unix_uid;
130 return nt_fake_unix_uid;
136 return the_passwd.pw_gid;
148 if (uid == nt_fake_unix_uid)
150 the_passwd.pw_gid = the_passwd.pw_uid = uid;
158 getpwnam (const char *name)
162 pw = getpwuid (getuid ());
166 if (stricmp (name, pw->pw_name))
173 init_user_info (void)
175 /* This code is pretty much of ad hoc nature. There is no unix-like
176 UIDs under Windows NT. There is no concept of root user, because
177 all security is ACL-based. Instead, let's use a simple variable,
178 nt-fake-unix-uid, which would allow the user to have a uid of
179 choice. --kkm, 02/03/2000 */
181 /* Find the user's real name by opening the process token and
182 looking up the name associated with the user-sid in that token.
184 Use the relative portion of the identifier authority value from
185 the user-sid as the user id value (same for group id using the
186 primary group sid from the process token). */
188 char user_sid[256], name[256], domain[256];
189 DWORD length = sizeof (name), dlength = sizeof (domain), trash;
191 SID_NAME_USE user_type;
193 if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &token)
194 && GetTokenInformation (token, TokenUser,
195 (PVOID) user_sid, sizeof (user_sid), &trash)
196 && LookupAccountSid (NULL, *((PSID *) user_sid), name, &length,
197 domain, &dlength, &user_type))
199 strcpy (the_passwd.pw_name, name);
200 /* Determine a reasonable uid value. */
201 if (stricmp ("administrator", name) == 0)
203 the_passwd.pw_uid = 0;
204 the_passwd.pw_gid = 0;
208 SID_IDENTIFIER_AUTHORITY * pSIA;
210 pSIA = GetSidIdentifierAuthority (*((PSID *) user_sid));
211 /* I believe the relative portion is the last 4 bytes (of 6)
213 the_passwd.pw_uid = ((pSIA->Value[2] << 24) +
214 (pSIA->Value[3] << 16) +
215 (pSIA->Value[4] << 8) +
216 (pSIA->Value[5] << 0));
217 /* restrict to conventional uid range for normal users */
218 the_passwd.pw_uid = the_passwd.pw_uid % 60001;
221 if (GetTokenInformation (token, TokenPrimaryGroup,
222 (PVOID) user_sid, sizeof (user_sid), &trash))
224 SID_IDENTIFIER_AUTHORITY * pSIA;
226 pSIA = GetSidIdentifierAuthority (*((PSID *) user_sid));
227 the_passwd.pw_gid = ((pSIA->Value[2] << 24) +
228 (pSIA->Value[3] << 16) +
229 (pSIA->Value[4] << 8) +
230 (pSIA->Value[5] << 0));
231 /* I don't know if this is necessary, but for safety... */
232 the_passwd.pw_gid = the_passwd.pw_gid % 60001;
235 the_passwd.pw_gid = the_passwd.pw_uid;
238 /* If security calls are not supported (presumably because we
239 are running under Windows 95), fallback to this. */
240 else if (GetUserName (name, &length))
242 strcpy (the_passwd.pw_name, name);
243 if (stricmp ("administrator", name) == 0)
244 the_passwd.pw_uid = 0;
246 the_passwd.pw_uid = 123;
247 the_passwd.pw_gid = the_passwd.pw_uid;
251 strcpy (the_passwd.pw_name, "unknown");
252 the_passwd.pw_uid = 123;
253 the_passwd.pw_gid = 123;
259 /* Obtain only logon id here, uid part is moved to getuid */
261 DWORD length = sizeof (name);
262 if (GetUserName (name, &length))
263 strcpy (the_passwd.pw_name, name);
265 strcpy (the_passwd.pw_name, "unknown");
268 /* Ensure HOME and SHELL are defined. */
271 * With XEmacs, setting $HOME is deprecated.
273 if (getenv ("HOME") == NULL)
276 if (getenv ("SHELL") == NULL)
277 putenv ((GetVersion () & 0x80000000) ? "SHELL=command" : "SHELL=cmd");
279 /* Set dir and shell from environment variables. */
280 strcpy (the_passwd.pw_dir, (char *)get_home_directory());
281 strcpy (the_passwd.pw_shell, getenv ("SHELL"));
284 /* Normalize filename by converting all path separators to
285 the specified separator. Also conditionally convert upper
286 case path name components to lower case. */
289 normalize_filename (char *fp, char path_sep)
294 /* Always lower-case drive letters a-z, even if the filesystem
295 preserves case in filenames.
296 This is so filenames can be compared by string comparison
297 functions that are case-sensitive. Even case-preserving filesystems
298 do not distinguish case in drive letters. */
299 if (fp[1] == ':' && *fp >= 'A' && *fp <= 'Z')
305 if (NILP (Vmswindows_downcase_file_names))
309 if (*fp == '/' || *fp == '\\')
316 sep = path_sep; /* convert to this path separator */
317 elem = fp; /* start of current path element */
320 if (*fp >= 'a' && *fp <= 'z')
321 elem = 0; /* don't convert this element */
323 if (*fp == 0 || *fp == ':')
325 sep = *fp; /* restore current separator (or 0) */
326 *fp = '/'; /* after conversion of this element */
329 if (*fp == '/' || *fp == '\\')
331 if (elem && elem != fp)
333 *fp = 0; /* temporary end of string */
334 _strlwr (elem); /* while we convert to lower case */
336 *fp = sep; /* convert (or restore) path separator */
337 elem = fp + 1; /* next element starts after separator */
343 /* Destructively turn backslashes into slashes. */
345 dostounix_filename (char *p)
347 normalize_filename (p, '/');
350 /* Destructively turn slashes into backslashes. */
352 unixtodos_filename (char *p)
354 normalize_filename (p, '\\');
357 /* Remove all CR's that are followed by a LF.
358 (From msdos.c...probably should figure out a way to share it,
359 although this code isn't going to ever change.) */
361 crlf_to_lf (int n, unsigned char *buf, unsigned *lf_count)
363 unsigned char *np = buf;
364 unsigned char *startp = buf;
365 unsigned char *endp = buf + n;
369 while (buf < endp - 1)
375 if (*(++buf) != 0x0a)
390 /* Parse the root part of file name, if present. Return length and
391 optionally store pointer to char after root. */
393 parse_root (char * name, char ** pPath)
400 /* find the root name of the volume if given */
401 if (isalpha (name[0]) && name[1] == ':')
403 /* skip past drive specifier */
405 if (IS_DIRECTORY_SEP (name[0]))
408 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
414 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
419 if (IS_DIRECTORY_SEP (name[0]))
429 /* Get long base name for name; name is assumed to be absolute. */
431 get_long_basename (char * name, char * buf, int size)
433 WIN32_FIND_DATA find_data;
439 /* If the last component of NAME has a wildcard character,
440 return it as the basename. */
441 p = name + strlen (name);
442 while (*p != '\\' && *p != ':' && p > name) p--;
444 if (strchr (p, '*') || strchr (p, '?'))
446 if ((len = strlen (p)) < size)
447 memcpy (buf, p, len + 1);
454 dir_handle = FindFirstFile (name, &find_data);
455 if (dir_handle != INVALID_HANDLE_VALUE)
457 if ((len = strlen (find_data.cFileName)) < size)
458 memcpy (buf, find_data.cFileName, len + 1);
461 FindClose (dir_handle);
466 /* Get long name for file, if possible (assumed to be absolute). */
468 win32_get_long_filename (char * name, char * buf, int size)
473 char full[ MAX_PATH ];
480 /* Use local copy for destructive modification. */
481 memcpy (full, name, len+1);
482 unixtodos_filename (full);
484 /* Copy root part verbatim. */
485 len = parse_root (full, &p);
486 memcpy (o, full, len);
493 p = strchr (q, '\\');
495 len = get_long_basename (full, o, size);
513 while (p != NULL && *p);
519 /* Routines that are no-ops on NT but are defined to get Emacs to compile. */
521 #if 0 /* #### We do not need those, do we? -kkm */
523 unrequest_sigio (void)
535 #define REG_ROOT "SOFTWARE\\GNU\\XEmacs"
538 nt_get_resource (char *key, LPDWORD lpdwtype)
541 HKEY hrootkey = NULL;
544 /* Check both the current user and the local machine to see if
545 we have any resources. */
547 if (RegOpenKeyEx (HKEY_CURRENT_USER, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
551 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS
552 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
553 && RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
558 if (lpvalue) xfree (lpvalue);
560 RegCloseKey (hrootkey);
563 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
567 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS &&
568 (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL &&
569 RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
574 if (lpvalue) xfree (lpvalue);
576 RegCloseKey (hrootkey);
583 init_environment (void)
585 /* Check for environment variables and use registry if they don't exist */
591 static char * env_vars[] =
605 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
606 cache_system_info ();
608 for (i = 0; i < countof (env_vars); i++)
610 if (!getenv (env_vars[i]) &&
611 (lpval = nt_get_resource (env_vars[i], &dwType)) != NULL)
613 if (dwType == REG_EXPAND_SZ)
615 char buf1[500], buf2[500];
617 ExpandEnvironmentStrings ((LPSTR) lpval, buf1, 500);
618 _snprintf (buf2, 499, "%s=%s", env_vars[i], buf1);
619 putenv (strdup (buf2));
621 else if (dwType == REG_SZ)
625 _snprintf (buf, 499, "%s=%s", env_vars[i], lpval);
626 putenv (strdup (buf));
634 /* Another special case: on NT, the PATH variable is actually named
635 "Path" although cmd.exe (perhaps NT itself) arranges for
636 environment variable lookup and setting to be case insensitive.
637 However, Emacs assumes a fully case sensitive environment, so we
638 need to change "Path" to "PATH" to match the expectations of
639 various elisp packages. We do this by the sneaky method of
640 modifying the string in the C runtime environ entry.
642 The same applies to COMSPEC. */
646 for (envp = environ; *envp; envp++)
647 if (_strnicmp (*envp, "PATH=", 5) == 0)
648 memcpy (*envp, "PATH=", 5);
649 else if (_strnicmp (*envp, "COMSPEC=", 8) == 0)
650 memcpy (*envp, "COMSPEC=", 8);
653 /* Remember the initial working directory for getwd, then make the
654 real wd be the location of emacs.exe to avoid conflicts when
655 renaming or deleting directories. (We also don't call chdir when
656 running subprocesses for the same reason.) */
657 if (!GetCurrentDirectory (MAXPATHLEN, startup_dir))
662 char modname[MAX_PATH];
664 if (!GetModuleFileName (NULL, modname, MAX_PATH))
666 if ((p = strrchr (modname, '\\')) == NULL)
670 SetCurrentDirectory (modname);
676 #ifndef HAVE_X_WINDOWS
677 /* X11R6 on NT provides the single parameter version of this command. */
679 #include <sys/timeb.h>
681 /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */
683 gettimeofday (struct timeval *tv, struct timezone *tz)
688 tv->tv_sec = tb.time;
689 tv->tv_usec = tb.millitm * 1000L;
692 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
693 tz->tz_dsttime = tb.dstflag; /* type of dst correction */
697 #endif /* HAVE_X_WINDOWS */
699 /* ------------------------------------------------------------------------- */
700 /* IO support and wrapper functions for Win32 API. */
701 /* ------------------------------------------------------------------------- */
703 /* Place a wrapper around the MSVC version of ctime. It returns NULL
704 on network directories, so we handle that case here.
705 (Ulrich Leodolter, 1/11/95). */
707 sys_ctime (const time_t *t)
709 char *str = (char *) ctime (t);
710 return (str ? str : "Sun Jan 01 00:00:00 1970");
713 /* Emulate sleep...we could have done this with a define, but that
714 would necessitate including windows.h in the files that used it.
715 This is much easier. */
717 #ifndef HAVE_X_WINDOWS
719 sys_sleep (int seconds)
721 Sleep (seconds * 1000);
725 /* #### This is an evil dirty hack. We must get rid of it.
726 Word "munging" is not in XEmacs lexicon. - kkm */
728 /* Internal MSVC data and functions for low-level descriptor munging */
729 #if (_MSC_VER == 900)
730 extern char _osfile[];
732 extern int __cdecl _set_osfhnd (int fd, long h);
733 extern int __cdecl _free_osfhnd (int fd);
735 /* parallel array of private info on file handles */
736 filedesc fd_info [ MAXDESC ];
738 typedef struct volume_info_data {
739 struct volume_info_data * next;
741 /* time when info was obtained */
744 /* actual volume info */
753 /* Global referenced by various functions. */
754 static volume_info_data volume_info;
756 /* Vector to indicate which drives are local and fixed (for which cached
757 data never expires). */
758 static BOOL fixed_drives[26];
760 /* Consider cached volume information to be stale if older than 10s,
761 at least for non-local drives. Info for fixed drives is never stale. */
762 #define DRIVE_INDEX( c ) ( (c) <= 'Z' ? (c) - 'A' : (c) - 'a' )
763 #define VOLINFO_STILL_VALID( root_dir, info ) \
764 ( ( isalpha (root_dir[0]) && \
765 fixed_drives[ DRIVE_INDEX (root_dir[0]) ] ) \
766 || GetTickCount () - info->timestamp < 10000 )
768 /* Cache support functions. */
770 /* Simple linked list with linear search is sufficient. */
771 static volume_info_data *volume_cache = NULL;
773 static volume_info_data *
774 lookup_volume_info (char * root_dir)
776 volume_info_data * info;
778 for (info = volume_cache; info; info = info->next)
779 if (stricmp (info->root_dir, root_dir) == 0)
785 add_volume_info (char * root_dir, volume_info_data * info)
787 info->root_dir = xstrdup (root_dir);
788 info->next = volume_cache;
793 /* Wrapper for GetVolumeInformation, which uses caching to avoid
794 performance penalty (~2ms on 486 for local drives, 7.5ms for local
795 cdrom drive, ~5-10ms or more for remote drives on LAN). */
797 GetCachedVolumeInformation (char * root_dir)
799 volume_info_data * info;
800 char default_root[ MAX_PATH ];
802 /* NULL for root_dir means use root from current directory. */
803 if (root_dir == NULL)
805 if (GetCurrentDirectory (MAX_PATH, default_root) == 0)
807 parse_root (default_root, &root_dir);
809 root_dir = default_root;
812 /* Local fixed drives can be cached permanently. Removable drives
813 cannot be cached permanently, since the volume name and serial
814 number (if nothing else) can change. Remote drives should be
815 treated as if they are removable, since there is no sure way to
816 tell whether they are or not. Also, the UNC association of drive
817 letters mapped to remote volumes can be changed at any time (even
818 by other processes) without notice.
820 As a compromise, so we can benefit from caching info for remote
821 volumes, we use a simple expiry mechanism to invalidate cache
822 entries that are more than ten seconds old. */
825 /* No point doing this, because WNetGetConnection is even slower than
826 GetVolumeInformation, consistently taking ~50ms on a 486 (FWIW,
827 GetDriveType is about the only call of this type which does not
828 involve network access, and so is extremely quick). */
830 /* Map drive letter to UNC if remote. */
831 if ( isalpha( root_dir[0] ) && !fixed[ DRIVE_INDEX( root_dir[0] ) ] )
833 char remote_name[ 256 ];
834 char drive[3] = { root_dir[0], ':' };
836 if (WNetGetConnection (drive, remote_name, sizeof (remote_name))
842 info = lookup_volume_info (root_dir);
844 if (info == NULL || ! VOLINFO_STILL_VALID (root_dir, info))
852 /* Info is not cached, or is stale. */
853 if (!GetVolumeInformation (root_dir,
858 type, sizeof (type)))
861 /* Cache the volume information for future use, overwriting existing
865 info = (volume_info_data *) xmalloc (sizeof (volume_info_data));
866 add_volume_info (root_dir, info);
874 info->name = xstrdup (name);
875 info->serialnum = serialnum;
876 info->maxcomp = maxcomp;
878 info->type = xstrdup (type);
879 info->timestamp = GetTickCount ();
885 /* Get information on the volume where name is held; set path pointer to
886 start of pathname in name (past UNC header\volume header if present). */
888 get_volume_info (const char * name, const char ** pPath)
891 char *rootname = NULL; /* default to current volume */
892 volume_info_data * info;
897 /* find the root name of the volume if given */
898 if (isalpha (name[0]) && name[1] == ':')
906 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
913 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
926 info = GetCachedVolumeInformation (rootname);
929 /* Set global referenced by other functions. */
936 /* Determine if volume is FAT format (ie. only supports short 8.3
937 names); also set path pointer to start of pathname in name. */
939 is_fat_volume (const char * name, const char ** pPath)
941 if (get_volume_info (name, pPath))
942 return (volume_info.maxcomp == 12);
946 /* Map filename to a legal 8.3 name if necessary. */
948 map_win32_filename (const char * name, const char ** pPath)
950 static char shortname[MAX_PATH];
951 char * str = shortname;
954 const char * save_name = name;
956 if (is_fat_volume (name, &path)) /* truncate to 8.3 */
958 REGISTER int left = 8; /* maximum number of chars in part */
959 REGISTER int extn = 0; /* extension added? */
960 REGISTER int dots = 2; /* maximum number of dots allowed */
963 *str++ = *name++; /* skip past UNC header */
965 while ((c = *name++))
972 extn = 0; /* reset extension flags */
973 dots = 2; /* max 2 dots */
974 left = 8; /* max length 8 for main part */
978 extn = 0; /* reset extension flags */
979 dots = 2; /* max 2 dots */
980 left = 8; /* max length 8 for main part */
985 /* Convert path components of the form .xxx to _xxx,
986 but leave . and .. as they are. This allows .emacs
987 to be read as _emacs, for example. */
991 IS_DIRECTORY_SEP (*name))
1006 extn = 1; /* we've got an extension */
1007 left = 3; /* 3 chars in extension */
1011 /* any embedded dots after the first are converted to _ */
1016 case '#': /* don't lose these, they're important */
1018 str[-1] = c; /* replace last character of part */
1023 *str++ = tolower (c); /* map to lower case (looks nicer) */
1025 dots = 0; /* started a path component */
1034 strcpy (shortname, name);
1035 unixtodos_filename (shortname);
1039 *pPath = shortname + (path - save_name);
1045 /* Emulate the Unix directory procedures opendir, closedir,
1046 and readdir. We can't use the procedures supplied in sysdep.c,
1047 so we provide them here. */
1049 struct direct dir_static; /* simulated directory contents */
1050 static HANDLE dir_find_handle = INVALID_HANDLE_VALUE;
1051 static int dir_is_fat;
1052 static char dir_pathname[MAXPATHLEN+1];
1053 static WIN32_FIND_DATA dir_find_data;
1056 opendir (const char *filename)
1060 /* Opening is done by FindFirstFile. However, a read is inherent to
1061 this operation, so we defer the open until read time. */
1063 if (!(dirp = xnew_and_zero(DIR)))
1065 if (dir_find_handle != INVALID_HANDLE_VALUE)
1072 strncpy (dir_pathname, map_win32_filename (filename, NULL), MAXPATHLEN);
1073 dir_pathname[MAXPATHLEN] = '\0';
1074 dir_is_fat = is_fat_volume (filename, NULL);
1080 closedir (DIR *dirp)
1082 /* If we have a find-handle open, close it. */
1083 if (dir_find_handle != INVALID_HANDLE_VALUE)
1085 FindClose (dir_find_handle);
1086 dir_find_handle = INVALID_HANDLE_VALUE;
1094 /* If we aren't dir_finding, do a find-first, otherwise do a find-next. */
1095 if (dir_find_handle == INVALID_HANDLE_VALUE)
1097 char filename[MAXNAMLEN + 3];
1100 strcpy (filename, dir_pathname);
1101 ln = strlen (filename) - 1;
1102 if (!IS_DIRECTORY_SEP (filename[ln]))
1103 strcat (filename, "\\");
1104 strcat (filename, "*");
1106 dir_find_handle = FindFirstFile (filename, &dir_find_data);
1108 if (dir_find_handle == INVALID_HANDLE_VALUE)
1113 if (!FindNextFile (dir_find_handle, &dir_find_data))
1117 /* Emacs never uses this value, so don't bother making it match
1118 value returned by stat(). */
1119 dir_static.d_ino = 1;
1121 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
1122 dir_static.d_namlen - dir_static.d_namlen % 4;
1124 dir_static.d_namlen = strlen (dir_find_data.cFileName);
1125 strcpy (dir_static.d_name, dir_find_data.cFileName);
1127 _strlwr (dir_static.d_name);
1128 else if (!NILP (Vmswindows_downcase_file_names))
1131 for (p = dir_static.d_name; *p; p++)
1132 if (*p >= 'a' && *p <= 'z')
1135 _strlwr (dir_static.d_name);
1142 /* #### Have to check if all that sad story about '95 is true - kkm */
1144 sys_rename (const char * oldname, const char * newname)
1146 char temp[MAX_PATH];
1149 /* MoveFile on Win95 doesn't correctly change the short file name
1150 alias in a number of circumstances (it is not easy to predict when
1151 just by looking at oldname and newname, unfortunately). In these
1152 cases, renaming through a temporary name avoids the problem.
1154 A second problem on Win95 is that renaming through a temp name when
1155 newname is uppercase fails (the final long name ends up in
1156 lowercase, although the short alias might be uppercase) UNLESS the
1157 long temp name is not 8.3.
1159 So, on Win95 we always rename through a temp name, and we make sure
1160 the temp name has a long extension to ensure correct renaming. */
1162 strcpy (temp, map_win32_filename (oldname, NULL));
1164 if (GetVersion () & 0x80000000)
1168 if (p = strrchr (temp, '\\'))
1172 /* Force temp name to require a manufactured 8.3 alias - this
1173 seems to make the second rename work properly. */
1174 strcpy (p, "_rename_temp.XXXXXX");
1176 if (rename (map_win32_filename (oldname, NULL), temp) < 0)
1180 /* Emulate Unix behavior - newname is deleted if it already exists
1181 (at least if it is a file; don't do this for directories).
1182 However, don't do this if we are just changing the case of the file
1183 name - we will end up deleting the file we are trying to rename! */
1184 newname = map_win32_filename (newname, NULL);
1186 /* TODO: Use GetInformationByHandle (on NT) to ensure newname and temp
1187 do not refer to the same file, eg. through share aliases. */
1188 if (stricmp (newname, temp) != 0
1189 && (attr = GetFileAttributes (newname)) != -1
1190 && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
1192 _chmod (newname, 0666);
1196 return rename (temp, newname);
1200 static FILETIME utc_base_ft;
1201 static int init = 0;
1205 static long double utc_base;
1208 convert_time (FILETIME ft)
1214 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
1223 st.wMilliseconds = 0;
1225 SystemTimeToFileTime (&st, &utc_base_ft);
1226 utc_base = (long double) utc_base_ft.dwHighDateTime
1227 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
1231 if (CompareFileTime (&ft, &utc_base_ft) < 0)
1234 ret = (long double) ft.dwHighDateTime * 4096 * 1024 * 1024 + ft.dwLowDateTime;
1236 return (time_t) (ret * 1e-7);
1240 #if defined(__MINGW32__) && CYGWIN_VERSION_DLL_MAJOR <= 21
1241 #define LowPart u.LowPart
1242 #define HighPart u.HighPart
1245 static LARGE_INTEGER utc_base_li;
1248 convert_time (FILETIME uft)
1255 TIME_ZONE_INFORMATION tzi;
1263 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
1272 st.wMilliseconds = 0;
1274 SystemTimeToFileTime (&st, &utc_base_ft);
1276 utc_base_li.LowPart = utc_base_ft.dwLowDateTime;
1277 utc_base_li.HighPart = utc_base_ft.dwHighDateTime;
1284 /* On a compiler that supports long integers, do it the easy way */
1285 lft.LowPart = uft.dwLowDateTime;
1286 lft.HighPart = uft.dwHighDateTime;
1287 ret = (time_t) ((lft.QuadPart - utc_base_li.QuadPart) / 10000000);
1291 /* Do it the hard way using mktime. */
1292 FileTimeToLocalFileTime(&uft, &ft);
1293 FileTimeToSystemTime (&ft, &st);
1294 tzid = GetTimeZoneInformation (&tzi);
1295 t.tm_year = st.wYear - 1900;
1296 t.tm_mon = st.wMonth - 1;
1297 t.tm_mday = st.wDay;
1298 t.tm_hour = st.wHour;
1299 t.tm_min = st.wMinute;
1300 t.tm_sec = st.wSecond;
1301 t.tm_isdst = (tzid == TIME_ZONE_ID_DAYLIGHT);
1302 /* st.wMilliseconds not applicable */
1314 #if defined(__MINGW32__) && CYGWIN_VERSION_DLL_MAJOR <= 21
1320 /* in case we ever have need of this */
1322 convert_from_time_t (time_t time, FILETIME * pft)
1328 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
1337 st.wMilliseconds = 0;
1339 SystemTimeToFileTime (&st, &utc_base_ft);
1340 utc_base = (long double) utc_base_ft.dwHighDateTime
1341 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
1345 /* time in 100ns units since 1-Jan-1601 */
1346 tmp = (long double) time * 1e7 + utc_base;
1347 pft->dwHighDateTime = (DWORD) (tmp / (4096.0 * 1024 * 1024));
1348 pft->dwLowDateTime = (DWORD) (tmp - pft->dwHighDateTime);
1353 /* No reason to keep this; faking inode values either by hashing or even
1354 using the file index from GetInformationByHandle, is not perfect and
1355 so by default Emacs doesn't use the inode values on Windows.
1356 Instead, we now determine file-truename correctly (except for
1357 possible drive aliasing etc). */
1359 /* Modified version of "PJW" algorithm (see the "Dragon" compiler book). */
1361 hashval (const unsigned char * str)
1366 h = (h << 4) + *str++;
1372 /* Return the hash value of the canonical pathname, excluding the
1373 drive/UNC header, to get a hopefully unique inode number. */
1375 generate_inode_val (const char * name)
1377 char fullname[ MAX_PATH ];
1381 /* Get the truly canonical filename, if it exists. (Note: this
1382 doesn't resolve aliasing due to subst commands, or recognize hard
1384 if (!win32_get_long_filename ((char *)name, fullname, MAX_PATH))
1387 parse_root (fullname, &p);
1388 /* Normal Win32 filesystems are still case insensitive. */
1395 /* stat has been fixed since MSVC 5.0.
1396 Oh, and do not encapsulater stat for non-MS compilers, too */
1397 /* #### popineau@ese-metz.fr says they still might be broken.
1398 Oh well... Let's add that `1 ||' condition.... --kkm */
1399 /* #### aichner@ecf.teradyne.com reported that with the library
1400 provided stat/fstat, (file-exist "d:\\tmp\\") =>> nil,
1401 (file-exist "d:\\tmp") =>> t, when d:\tmp exists. Whenever
1402 we opt to use non-encapsulated stat(), this should serve as
1403 a compatibility test. --kkm */
1405 #if 1 || defined(_MSC_VER) && _MSC_VER < 1100
1407 /* Since stat is encapsulated on Windows NT, we need to encapsulate
1408 the equally broken fstat as well. */
1410 fstat (int handle, struct stat *buffer)
1413 BY_HANDLE_FILE_INFORMATION lpFileInfo;
1414 /* Initialize values */
1415 buffer->st_mode = 0;
1416 buffer->st_size = 0;
1418 buffer->st_rdev = 0;
1419 buffer->st_atime = 0;
1420 buffer->st_ctime = 0;
1421 buffer->st_mtime = 0;
1422 buffer->st_nlink = 0;
1423 ret = GetFileInformationByHandle((HANDLE) _get_osfhandle(handle), &lpFileInfo);
1430 buffer->st_mtime = convert_time (lpFileInfo.ftLastWriteTime);
1431 buffer->st_atime = convert_time (lpFileInfo.ftLastAccessTime);
1432 if (buffer->st_atime == 0) buffer->st_atime = buffer->st_mtime;
1433 buffer->st_ctime = convert_time (lpFileInfo.ftCreationTime);
1434 if (buffer->st_ctime == 0) buffer->st_ctime = buffer->st_mtime;
1435 buffer->st_size = lpFileInfo.nFileSizeLow;
1436 buffer->st_nlink = (short) lpFileInfo.nNumberOfLinks;
1441 /* MSVC stat function can't cope with UNC names and has other bugs, so
1442 replace it with our own. This also allows us to calculate consistent
1443 inode values without hacks in the main Emacs code. */
1445 stat (const char * path, struct stat * buf)
1448 WIN32_FIND_DATA wfd;
1453 int rootdir = FALSE;
1455 if (path == NULL || buf == NULL)
1461 name = (char *) map_win32_filename (path, &path);
1462 /* must be valid filename, no wild cards */
1463 if (strchr (name, '*') || strchr (name, '?'))
1469 /* Remove trailing directory separator, unless name is the root
1470 directory of a drive or UNC volume in which case ensure there
1471 is a trailing separator. */
1472 len = strlen (name);
1473 rootdir = (path >= name + len - 1
1474 && (IS_DIRECTORY_SEP (*path) || *path == 0));
1475 name = strcpy ((char *)alloca (len + 2), name);
1479 if (!IS_DIRECTORY_SEP (name[len-1]))
1480 strcat (name, "\\");
1481 if (GetDriveType (name) < 2)
1486 memset (&wfd, 0, sizeof (wfd));
1487 wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
1488 wfd.ftCreationTime = utc_base_ft;
1489 wfd.ftLastAccessTime = utc_base_ft;
1490 wfd.ftLastWriteTime = utc_base_ft;
1491 strcpy (wfd.cFileName, name);
1495 if (IS_DIRECTORY_SEP (name[len-1]))
1498 /* (This is hacky, but helps when doing file completions on
1499 network drives.) Optimize by using information available from
1500 active readdir if possible. */
1501 if (dir_find_handle != INVALID_HANDLE_VALUE &&
1502 (len = strlen (dir_pathname)),
1503 strnicmp (name, dir_pathname, len) == 0 &&
1504 IS_DIRECTORY_SEP (name[len]) &&
1505 stricmp (name + len + 1, dir_static.d_name) == 0)
1507 /* This was the last entry returned by readdir. */
1508 wfd = dir_find_data;
1512 fh = FindFirstFile (name, &wfd);
1513 if (fh == INVALID_HANDLE_VALUE)
1522 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1524 buf->st_mode = _S_IFDIR;
1525 buf->st_nlink = 2; /* doesn't really matter */
1526 fake_inode = 0; /* this doesn't either I think */
1528 else if (!NILP (Vmswindows_get_true_file_attributes))
1530 /* This is more accurate in terms of getting the correct number
1531 of links, but is quite slow (it is noticeable when Emacs is
1532 making a list of file name completions). */
1533 BY_HANDLE_FILE_INFORMATION info;
1535 /* No access rights required to get info. */
1536 fh = CreateFile (name, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
1537 OPEN_EXISTING, 0, NULL);
1539 if (GetFileInformationByHandle (fh, &info))
1541 switch (GetFileType (fh))
1543 case FILE_TYPE_DISK:
1544 buf->st_mode = _S_IFREG;
1546 case FILE_TYPE_PIPE:
1547 buf->st_mode = _S_IFIFO;
1549 case FILE_TYPE_CHAR:
1550 case FILE_TYPE_UNKNOWN:
1552 buf->st_mode = _S_IFCHR;
1554 buf->st_nlink = (short) info.nNumberOfLinks;
1555 /* Might as well use file index to fake inode values, but this
1556 is not guaranteed to be unique unless we keep a handle open
1557 all the time (even then there are situations where it is
1558 not unique). Reputedly, there are at most 48 bits of info
1559 (on NTFS, presumably less on FAT). */
1560 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
1571 /* Don't bother to make this information more accurate. */
1572 buf->st_mode = _S_IFREG;
1578 /* Not sure if there is any point in this. */
1579 if (!NILP (Vwin32_generate_fake_inodes))
1580 fake_inode = generate_inode_val (name);
1581 else if (fake_inode == 0)
1583 /* For want of something better, try to make everything unique. */
1584 static DWORD gen_num = 0;
1585 fake_inode = ++gen_num;
1589 /* #### MSVC defines _ino_t to be short; other libc's might not. */
1590 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16));
1592 /* consider files to belong to current user */
1593 buf->st_uid = buf->st_gid = nt_fake_unix_uid;
1595 /* volume_info is set indirectly by map_win32_filename */
1596 buf->st_dev = volume_info.serialnum;
1597 buf->st_rdev = volume_info.serialnum;
1599 buf->st_size = wfd.nFileSizeLow;
1601 /* Convert timestamps to Unix format. */
1602 buf->st_mtime = convert_time (wfd.ftLastWriteTime);
1603 buf->st_atime = convert_time (wfd.ftLastAccessTime);
1604 if (buf->st_atime == 0) buf->st_atime = buf->st_mtime;
1605 buf->st_ctime = convert_time (wfd.ftCreationTime);
1606 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
1608 /* determine rwx permissions */
1609 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
1610 permission = _S_IREAD;
1612 permission = _S_IREAD | _S_IWRITE;
1614 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1615 permission |= _S_IEXEC;
1618 char * p = strrchr (name, '.');
1620 (stricmp (p, ".exe") == 0 ||
1621 stricmp (p, ".com") == 0 ||
1622 stricmp (p, ".bat") == 0 ||
1623 stricmp (p, ".cmd") == 0))
1624 permission |= _S_IEXEC;
1627 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
1631 #endif /* defined(_MSC_VER) && _MSC_VER < 1100 */
1633 /* From callproc.c */
1634 extern Lisp_Object Vbinary_process_input;
1635 extern Lisp_Object Vbinary_process_output;
1637 /* Unix pipe() has only one arg */
1639 sys_pipe (int * phandles)
1644 /* make pipe handles non-inheritable; when we spawn a child, we
1645 replace the relevant handle with an inheritable one. Also put
1646 pipes into binary mode; we will do text mode translation ourselves
1648 rc = _pipe (phandles, 0, _O_NOINHERIT | _O_BINARY);
1652 flags = FILE_PIPE | FILE_READ;
1653 if (!NILP (Vbinary_process_output))
1654 flags |= FILE_BINARY;
1655 fd_info[phandles[0]].flags = flags;
1657 flags = FILE_PIPE | FILE_WRITE;
1658 if (!NILP (Vbinary_process_input))
1659 flags |= FILE_BINARY;
1660 fd_info[phandles[1]].flags = flags;
1667 term_ntproc (int unused)
1674 /* Initial preparation for subprocess support: replace our standard
1675 handles with non-inheritable versions. */
1678 HANDLE stdin_save = INVALID_HANDLE_VALUE;
1679 HANDLE stdout_save = INVALID_HANDLE_VALUE;
1680 HANDLE stderr_save = INVALID_HANDLE_VALUE;
1682 parent = GetCurrentProcess ();
1684 /* ignore errors when duplicating and closing; typically the
1685 handles will be invalid when running as a gui program. */
1686 DuplicateHandle (parent,
1687 GetStdHandle (STD_INPUT_HANDLE),
1692 DUPLICATE_SAME_ACCESS);
1694 DuplicateHandle (parent,
1695 GetStdHandle (STD_OUTPUT_HANDLE),
1700 DUPLICATE_SAME_ACCESS);
1702 DuplicateHandle (parent,
1703 GetStdHandle (STD_ERROR_HANDLE),
1708 DUPLICATE_SAME_ACCESS);
1714 if (stdin_save != INVALID_HANDLE_VALUE)
1715 _open_osfhandle ((long) stdin_save, O_TEXT);
1717 _open ("nul", O_TEXT | O_NOINHERIT | O_RDONLY);
1720 if (stdout_save != INVALID_HANDLE_VALUE)
1721 _open_osfhandle ((long) stdout_save, O_TEXT);
1723 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
1726 if (stderr_save != INVALID_HANDLE_VALUE)
1727 _open_osfhandle ((long) stderr_save, O_TEXT);
1729 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
1733 /* unfortunately, atexit depends on implementation of malloc */
1734 /* atexit (term_ntproc); */
1735 signal (SIGABRT, term_ntproc);
1737 /* determine which drives are fixed, for GetCachedVolumeInformation */
1739 /* GetDriveType must have trailing backslash. */
1740 char drive[] = "A:\\";
1742 /* Loop over all possible drive letters */
1743 while ( *drive <= 'Z' )
1745 /* Record if this drive letter refers to a fixed drive. */
1746 fixed_drives[ DRIVE_INDEX (*drive) ] =
1747 (GetDriveType (drive) == DRIVE_FIXED);
1755 tty_semi_canonicalize_console_connection (Lisp_Object connection,
1756 Error_behavior errb)
1762 tty_canonicalize_console_connection (Lisp_Object connection,
1763 Error_behavior errb)
1769 tty_semi_canonicalize_device_connection (Lisp_Object connection,
1770 Error_behavior errb)
1776 tty_canonicalize_device_connection (Lisp_Object connection,
1777 Error_behavior errb)
1783 /*--------------------------------------------------------------------*/
1784 /* Signal support */
1785 /*--------------------------------------------------------------------*/
1787 /* We need MS-defined signal and raise here */
1791 #define sigmask(nsig) (1U << nsig)
1793 /* We can support as many signals as fit into word */
1796 /* Signal handlers. Initial value = 0 = SIG_DFL */
1797 static void (__cdecl *signal_handlers[SIG_MAX])(int) = {0};
1799 /* Signal block mask: bit set to 1 means blocked */
1800 unsigned signal_block_mask = 0;
1802 /* Signal pending mask: bit set to 1 means sig is pending */
1803 unsigned signal_pending_mask = 0;
1805 msw_sighandler msw_sigset (int nsig, msw_sighandler handler)
1807 /* We delegate some signals to the system function */
1808 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
1809 return signal (nsig, handler);
1811 if (nsig < 0 || nsig > SIG_MAX)
1817 /* Store handler ptr */
1819 msw_sighandler old_handler = signal_handlers[nsig];
1820 signal_handlers[nsig] = handler;
1825 int msw_sighold (int nsig)
1827 if (nsig < 0 || nsig > SIG_MAX)
1828 return errno = EINVAL;
1830 signal_block_mask |= sigmask(nsig);
1834 int msw_sigrelse (int nsig)
1836 if (nsig < 0 || nsig > SIG_MAX)
1837 return errno = EINVAL;
1839 signal_block_mask &= ~sigmask(nsig);
1841 if (signal_pending_mask & sigmask(nsig))
1847 int msw_sigpause (int nsig)
1849 /* This is currently not called, because the only
1850 call to sigpause inside XEmacs is with SIGCHLD
1851 parameter. Just in case, we put an assert here,
1852 so anyone who will add a call to sigpause will
1853 be surprised (or surprise someone else...) */
1858 int msw_raise (int nsig)
1860 /* We delegate some raises to the system routine */
1861 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
1862 return raise (nsig);
1864 if (nsig < 0 || nsig > SIG_MAX)
1865 return errno = EINVAL;
1867 /* If the signal is blocked, remember to issue later */
1868 if (signal_block_mask & sigmask(nsig))
1870 signal_pending_mask |= sigmask(nsig);
1874 if (signal_handlers[nsig] == SIG_IGN)
1877 if (signal_handlers[nsig] != SIG_DFL)
1879 (*signal_handlers[nsig])(nsig);
1883 /* Default signal actions */
1884 if (nsig == SIGALRM || nsig == SIGPROF)
1887 /* Other signals are ignored by default */
1891 /*--------------------------------------------------------------------*/
1893 /*--------------------------------------------------------------------*/
1895 /* We emulate two timers, one for SIGALRM, another for SIGPROF.
1897 itimerproc() function has an implementation limitation: it does
1898 not allow to set *both* interval and period. If an attempt is
1899 made to set both, and then they are unequal, the function
1902 Minimum timer resolution on Win32 systems varies, and is greater
1903 than or equal than 1 ms. The resolution is always wrapped not to
1904 attempt to get below the system defined limit.
1907 /* Timer precision, denominator of one fraction: for 100 ms
1908 interval, request 10 ms precision
1910 const int timer_prec = 10;
1912 /* Last itimervals, as set by calls to setitimer */
1913 static struct itimerval it_alarm;
1914 static struct itimerval it_prof;
1916 /* Timer IDs as returned by MM */
1917 MMRESULT tid_alarm = 0;
1918 MMRESULT tid_prof = 0;
1920 static void CALLBACK timer_proc (UINT uID, UINT uMsg, DWORD dwUser,
1921 DWORD dw1, DWORD dw2)
1923 /* Just raise a signal indicated by dwUser parameter */
1927 /* Divide time in ms specified by IT by DENOM. Return 1 ms
1928 if division results in zero */
1929 static UINT period (const struct itimerval* it, UINT denom)
1931 static TIMECAPS time_caps;
1934 const struct timeval* tv =
1935 (it->it_value.tv_sec == 0 && it->it_value.tv_usec == 0)
1936 ? &it->it_interval : &it->it_value;
1938 /* Zero means stop timer */
1939 if (tv->tv_sec == 0 && tv->tv_usec == 0)
1942 /* Convert to ms and divide by denom */
1943 res = (tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000) / denom;
1945 /* Converge to minimum timer resolution */
1946 if (time_caps.wPeriodMin == 0)
1947 timeGetDevCaps (&time_caps, sizeof(time_caps));
1949 if (res < time_caps.wPeriodMin)
1950 res = time_caps.wPeriodMin;
1955 static int setitimer_helper (const struct itimerval* itnew,
1956 struct itimerval* itold, struct itimerval* itcurrent,
1957 MMRESULT* tid, DWORD sigkind)
1959 UINT delay, resolution, event_type;
1961 /* First stop the old timer */
1964 timeKillEvent (*tid);
1965 timeEndPeriod (period (itcurrent, timer_prec));
1969 /* Return old itimerval if requested */
1971 *itold = *itcurrent;
1973 *itcurrent = *itnew;
1975 /* Determine if to start new timer */
1976 delay = period (itnew, 1);
1979 resolution = period (itnew, timer_prec);
1980 event_type = (itnew->it_value.tv_sec == 0 && itnew->it_value.tv_usec == 0)
1981 ? TIME_ONESHOT : TIME_PERIODIC;
1982 timeBeginPeriod (resolution);
1983 *tid = timeSetEvent (delay, resolution, timer_proc, sigkind, event_type);
1986 return !delay || *tid;
1989 int setitimer (int kind, const struct itimerval* itnew,
1990 struct itimerval* itold)
1992 /* In this version, both interval and value are allowed
1993 only if they are equal. */
1994 assert ((itnew->it_value.tv_sec == 0 && itnew->it_value.tv_usec == 0)
1995 || (itnew->it_interval.tv_sec == 0 && itnew->it_interval.tv_usec == 0)
1996 || (itnew->it_value.tv_sec == itnew->it_interval.tv_sec &&
1997 itnew->it_value.tv_usec == itnew->it_interval.tv_usec));
1999 if (kind == ITIMER_REAL)
2000 return setitimer_helper (itnew, itold, &it_alarm, &tid_alarm, SIGALRM);
2001 else if (kind == ITIMER_PROF)
2002 return setitimer_helper (itnew, itold, &it_prof, &tid_prof, SIGPROF);
2004 return errno = EINVAL;
2008 open_input_file (file_data *p_file, const char *filename)
2011 HANDLE file_mapping;
2013 DWORD size, upper_size;
2015 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
2016 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
2017 if (file == INVALID_HANDLE_VALUE)
2020 size = GetFileSize (file, &upper_size);
2021 file_mapping = CreateFileMapping (file, NULL, PAGE_READONLY,
2026 file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size);
2030 p_file->name = (char *)filename;
2031 p_file->size = size;
2032 p_file->file = file;
2033 p_file->file_mapping = file_mapping;
2034 p_file->file_base = (char *)file_base;
2039 /* Close the system structures associated with the given file. */
2041 close_file_data (file_data *p_file)
2043 UnmapViewOfFile (p_file->file_base);
2044 CloseHandle (p_file->file_mapping);
2045 CloseHandle (p_file->file);
2051 DEFVAR_INT ("nt-fake-unix-uid", &nt_fake_unix_uid /*
2052 *Set uid returned by `user-uid' and `user-real-uid'.
2053 Under NT and 9x, there is no uids, and even no almighty user called root.
2054 By setting this variable, you can have any uid of choice. Default is 0.
2055 Changes to this variable take effect immediately.
2057 nt_fake_unix_uid = 0;