annotate src/nt.c @ 458:c33ae14dd6d0 r21-2-44

Import from CVS: tag r21-2-44
author cvs
date Mon, 13 Aug 2007 11:42:25 +0200
parents 3078fd1074e8
children 0784d089fdc9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Utility and Unix shadow routines for XEmacs on Windows NT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Geoff Voelker (voelker@cs.washington.edu) 7-29-94 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* Sync'ed with Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #define getwd _getwd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #undef getwd
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include "sysproc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include "sysfile.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
36 #include "syspwd.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
37 #include "sysdir.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
39 #include "syswindows.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #include "nt.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #include "ntheap.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 extern Lisp_Object Vmswindows_downcase_file_names;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 extern Lisp_Object Vwin32_generate_fake_inodes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 extern Lisp_Object Vmswindows_get_true_file_attributes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 448
diff changeset
51 Fixnum nt_fake_unix_uid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 static char startup_dir[ MAXPATHLEN ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 /* Get the current working directory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 getwd (char *dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 if (GetCurrentDirectory (MAXPATHLEN, dir) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 return dir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 /* Emacs doesn't actually change directory itself, and we want to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 force our real wd to be where emacs.exe is to avoid unnecessary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 conflicts when trying to rename or delete directories. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 strcpy (dir, startup_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 return dir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 /* Emulate getpwuid, getpwnam and others. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 #define PASSWD_FIELD_SIZE 256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 static char the_passwd_name[PASSWD_FIELD_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 static char the_passwd_passwd[PASSWD_FIELD_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 static char the_passwd_gecos[PASSWD_FIELD_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 static char the_passwd_dir[PASSWD_FIELD_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 static char the_passwd_shell[PASSWD_FIELD_SIZE];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 static struct passwd the_passwd =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 the_passwd_name,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 the_passwd_passwd,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 the_passwd_gecos,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 the_passwd_dir,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 the_passwd_shell,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 uid_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
95 getuid (void)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
96 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
97 return nt_fake_unix_uid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 uid_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
101 geteuid (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
103 return nt_fake_unix_uid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 gid_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
107 getgid (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 return the_passwd.pw_gid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 gid_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
113 getegid (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 return getgid ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 struct passwd *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 getpwuid (uid_t uid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
121 if (uid == nt_fake_unix_uid)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
122 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
123 the_passwd.pw_gid = the_passwd.pw_uid = uid;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
124 return &the_passwd;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
125 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
126 else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
127 return NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 struct passwd *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 getpwnam (const char *name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 struct passwd *pw;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 pw = getpwuid (getuid ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 if (!pw)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 return pw;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 if (stricmp (name, pw->pw_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 return pw;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
146 init_user_info (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
148 /* This code is pretty much of ad hoc nature. There is no unix-like
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
149 UIDs under Windows NT. There is no concept of root user, because
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
150 all security is ACL-based. Instead, let's use a simple variable,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
151 nt-fake-unix-uid, which would allow the user to have a uid of
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
152 choice. --kkm, 02/03/2000 */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
153 #if 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 /* Find the user's real name by opening the process token and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 looking up the name associated with the user-sid in that token.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 Use the relative portion of the identifier authority value from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 the user-sid as the user id value (same for group id using the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 primary group sid from the process token). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 char user_sid[256], name[256], domain[256];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 DWORD length = sizeof (name), dlength = sizeof (domain), trash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 HANDLE token = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 SID_NAME_USE user_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &token)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 && GetTokenInformation (token, TokenUser,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (PVOID) user_sid, sizeof (user_sid), &trash)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 && LookupAccountSid (NULL, *((PSID *) user_sid), name, &length,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 domain, &dlength, &user_type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 strcpy (the_passwd.pw_name, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 /* Determine a reasonable uid value. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 if (stricmp ("administrator", name) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 the_passwd.pw_uid = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 the_passwd.pw_gid = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 SID_IDENTIFIER_AUTHORITY * pSIA;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 pSIA = GetSidIdentifierAuthority (*((PSID *) user_sid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 /* I believe the relative portion is the last 4 bytes (of 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 with msb first. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 the_passwd.pw_uid = ((pSIA->Value[2] << 24) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (pSIA->Value[3] << 16) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (pSIA->Value[4] << 8) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 (pSIA->Value[5] << 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 /* restrict to conventional uid range for normal users */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 the_passwd.pw_uid = the_passwd.pw_uid % 60001;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 /* Get group id */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 if (GetTokenInformation (token, TokenPrimaryGroup,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (PVOID) user_sid, sizeof (user_sid), &trash))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 SID_IDENTIFIER_AUTHORITY * pSIA;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 pSIA = GetSidIdentifierAuthority (*((PSID *) user_sid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 the_passwd.pw_gid = ((pSIA->Value[2] << 24) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (pSIA->Value[3] << 16) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (pSIA->Value[4] << 8) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (pSIA->Value[5] << 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 /* I don't know if this is necessary, but for safety... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 the_passwd.pw_gid = the_passwd.pw_gid % 60001;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 the_passwd.pw_gid = the_passwd.pw_uid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 /* If security calls are not supported (presumably because we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 are running under Windows 95), fallback to this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 else if (GetUserName (name, &length))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 strcpy (the_passwd.pw_name, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 if (stricmp ("administrator", name) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 the_passwd.pw_uid = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 the_passwd.pw_uid = 123;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 the_passwd.pw_gid = the_passwd.pw_uid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 strcpy (the_passwd.pw_name, "unknown");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 the_passwd.pw_uid = 123;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 the_passwd.pw_gid = 123;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
229 if (token)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
230 CloseHandle (token);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
231 #else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
232 /* Obtain only logon id here, uid part is moved to getuid */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
233 char name[256];
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
234 DWORD length = sizeof (name);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
235 if (GetUserName (name, &length))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
236 strcpy (the_passwd.pw_name, name);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
237 else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
238 strcpy (the_passwd.pw_name, "unknown");
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
239 #endif
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
240
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 /* Ensure HOME and SHELL are defined. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 * With XEmacs, setting $HOME is deprecated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 if (getenv ("HOME") == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 putenv ("HOME=c:/");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 if (getenv ("SHELL") == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 putenv ((GetVersion () & 0x80000000) ? "SHELL=command" : "SHELL=cmd");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 /* Set dir and shell from environment variables. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
253 strcpy (the_passwd.pw_dir, (char *)get_home_directory());
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 strcpy (the_passwd.pw_shell, getenv ("SHELL"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 /* Normalize filename by converting all path separators to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 the specified separator. Also conditionally convert upper
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 case path name components to lower case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
262 normalize_filename (char *fp, char path_sep)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 char sep;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 char *elem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 /* Always lower-case drive letters a-z, even if the filesystem
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 preserves case in filenames.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 This is so filenames can be compared by string comparison
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 functions that are case-sensitive. Even case-preserving filesystems
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 do not distinguish case in drive letters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 if (fp[1] == ':' && *fp >= 'A' && *fp <= 'Z')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 *fp += 'a' - 'A';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 fp += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 if (NILP (Vmswindows_downcase_file_names))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 while (*fp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 if (*fp == '/' || *fp == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 *fp = path_sep;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 fp++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 sep = path_sep; /* convert to this path separator */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 elem = fp; /* start of current path element */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 do {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 if (*fp >= 'a' && *fp <= 'z')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 elem = 0; /* don't convert this element */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 if (*fp == 0 || *fp == ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 sep = *fp; /* restore current separator (or 0) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 *fp = '/'; /* after conversion of this element */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 if (*fp == '/' || *fp == '\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 if (elem && elem != fp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 *fp = 0; /* temporary end of string */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 _strlwr (elem); /* while we convert to lower case */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 *fp = sep; /* convert (or restore) path separator */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 elem = fp + 1; /* next element starts after separator */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 sep = path_sep;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 } while (*fp++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 /* Destructively turn backslashes into slashes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
318 dostounix_filename (char *p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 normalize_filename (p, '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 /* Destructively turn slashes into backslashes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
325 unixtodos_filename (char *p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 normalize_filename (p, '\\');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 /* Remove all CR's that are followed by a LF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (From msdos.c...probably should figure out a way to share it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 although this code isn't going to ever change.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
334 crlf_to_lf (int n, unsigned char *buf, unsigned *lf_count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 unsigned char *np = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 unsigned char *startp = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 unsigned char *endp = buf + n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 if (n == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 return n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 while (buf < endp - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 if (*buf == 0x0a)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (*lf_count)++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 if (*buf == 0x0d)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 if (*(++buf) != 0x0a)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 *np++ = 0x0d;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 *np++ = *buf++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 if (buf < endp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 if (*buf == 0x0a)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (*lf_count)++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 *np++ = *buf++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 return np - startp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 /* Parse the root part of file name, if present. Return length and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 optionally store pointer to char after root. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 parse_root (char * name, char ** pPath)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 char * start = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 if (name == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 /* find the root name of the volume if given */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 if (isalpha (name[0]) && name[1] == ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 /* skip past drive specifier */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 name += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 if (IS_DIRECTORY_SEP (name[0]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 int slashes = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 name += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 while ( *name );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 if (IS_DIRECTORY_SEP (name[0]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 if (pPath)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 *pPath = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 return name - start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 /* Get long base name for name; name is assumed to be absolute. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 get_long_basename (char * name, char * buf, int size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 WIN32_FIND_DATA find_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 HANDLE dir_handle;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 int len = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 #ifdef PIGSFLY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 char *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 /* If the last component of NAME has a wildcard character,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 return it as the basename. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 p = name + strlen (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 while (*p != '\\' && *p != ':' && p > name) p--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 if (p > name) p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 if (strchr (p, '*') || strchr (p, '?'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 if ((len = strlen (p)) < size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 memcpy (buf, p, len + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 len = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 return len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 dir_handle = FindFirstFile (name, &find_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 if (dir_handle != INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 if ((len = strlen (find_data.cFileName)) < size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 memcpy (buf, find_data.cFileName, len + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 len = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 FindClose (dir_handle);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 return len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 /* Get long name for file, if possible (assumed to be absolute). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 BOOL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 win32_get_long_filename (char * name, char * buf, int size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 char * o = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 char * p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 char * q;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 char full[ MAX_PATH ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 len = strlen (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 if (len >= MAX_PATH)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 /* Use local copy for destructive modification. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 memcpy (full, name, len+1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 unixtodos_filename (full);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 /* Copy root part verbatim. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 len = parse_root (full, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 memcpy (o, full, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 o += len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 size -= len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 q = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 p = strchr (q, '\\');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 if (p) *p = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 len = get_long_basename (full, o, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 if (len > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 o += len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 size -= len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 if (p != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 *p++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 if (size < 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 *o++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 size--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 *o = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 while (p != NULL && *p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 /* Routines that are no-ops on NT but are defined to get Emacs to compile. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 #if 0 /* #### We do not need those, do we? -kkm */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 unrequest_sigio (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 request_sigio (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 #define REG_ROOT "SOFTWARE\\GNU\\XEmacs"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 LPBYTE
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
511 nt_get_resource (char *key, LPDWORD lpdwtype)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 LPBYTE lpvalue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 HKEY hrootkey = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 DWORD cbData;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 /* Check both the current user and the local machine to see if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 we have any resources. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 if (RegOpenKeyEx (HKEY_CURRENT_USER, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 lpvalue = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 && RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 return (lpvalue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 if (lpvalue) xfree (lpvalue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 RegCloseKey (hrootkey);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 lpvalue = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 return (lpvalue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 if (lpvalue) xfree (lpvalue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 RegCloseKey (hrootkey);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 return (NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
556 init_environment (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 /* Check for environment variables and use registry if they don't exist */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 LPBYTE lpval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 DWORD dwType;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 static char * env_vars[] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 "HOME",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 "emacs_dir",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 "EMACSLOADPATH",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 "EMACSDEBUGPATHS",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 "SHELL",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 "CMDPROXY",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 "EMACSDATA",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 "EMACSPATH",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 "EMACSPACKAGEPATH",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 "EMACSLOCKDIR",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 "INFOPATH"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 };
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
578 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
579 cache_system_info ();
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
580 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 for (i = 0; i < countof (env_vars); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 if (!getenv (env_vars[i]) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 (lpval = nt_get_resource (env_vars[i], &dwType)) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 if (dwType == REG_EXPAND_SZ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 char buf1[500], buf2[500];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 ExpandEnvironmentStrings ((LPSTR) lpval, buf1, 500);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 _snprintf (buf2, 499, "%s=%s", env_vars[i], buf1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 putenv (strdup (buf2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 else if (dwType == REG_SZ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 char buf[500];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 _snprintf (buf, 499, "%s=%s", env_vars[i], lpval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 putenv (strdup (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 xfree (lpval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 /* Another special case: on NT, the PATH variable is actually named
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 "Path" although cmd.exe (perhaps NT itself) arranges for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 environment variable lookup and setting to be case insensitive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 However, Emacs assumes a fully case sensitive environment, so we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 need to change "Path" to "PATH" to match the expectations of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 various elisp packages. We do this by the sneaky method of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 modifying the string in the C runtime environ entry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 The same applies to COMSPEC. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 char ** envp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 for (envp = environ; *envp; envp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 if (_strnicmp (*envp, "PATH=", 5) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 memcpy (*envp, "PATH=", 5);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 else if (_strnicmp (*envp, "COMSPEC=", 8) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 memcpy (*envp, "COMSPEC=", 8);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 /* Remember the initial working directory for getwd, then make the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 real wd be the location of emacs.exe to avoid conflicts when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 renaming or deleting directories. (We also don't call chdir when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 running subprocesses for the same reason.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 if (!GetCurrentDirectory (MAXPATHLEN, startup_dir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 char *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 char modname[MAX_PATH];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 if (!GetModuleFileName (NULL, modname, MAX_PATH))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 if ((p = strrchr (modname, '\\')) == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 *p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 SetCurrentDirectory (modname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 init_user_info ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 #ifndef HAVE_X_WINDOWS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 /* X11R6 on NT provides the single parameter version of this command. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 #include <sys/timeb.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 gettimeofday (struct timeval *tv, struct timezone *tz)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 struct _timeb tb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 _ftime (&tb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 tv->tv_sec = tb.time;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 tv->tv_usec = tb.millitm * 1000L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 if (tz)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 tz->tz_dsttime = tb.dstflag; /* type of dst correction */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 #endif /* HAVE_X_WINDOWS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 /* ------------------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 /* IO support and wrapper functions for Win32 API. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 /* ------------------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 /* Place a wrapper around the MSVC version of ctime. It returns NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 on network directories, so we handle that case here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 (Ulrich Leodolter, 1/11/95). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 sys_ctime (const time_t *t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 char *str = (char *) ctime (t);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 return (str ? str : "Sun Jan 01 00:00:00 1970");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 /* Emulate sleep...we could have done this with a define, but that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 would necessitate including windows.h in the files that used it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 This is much easier. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 #ifndef HAVE_X_WINDOWS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 sys_sleep (int seconds)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 Sleep (seconds * 1000);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 /* #### This is an evil dirty hack. We must get rid of it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 Word "munging" is not in XEmacs lexicon. - kkm */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 /* Internal MSVC data and functions for low-level descriptor munging */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 #if (_MSC_VER == 900)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 extern char _osfile[];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 extern int __cdecl _set_osfhnd (int fd, long h);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 extern int __cdecl _free_osfhnd (int fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 /* parallel array of private info on file handles */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 filedesc fd_info [ MAXDESC ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 typedef struct volume_info_data {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 struct volume_info_data * next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 /* time when info was obtained */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 DWORD timestamp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 /* actual volume info */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 char * root_dir;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 DWORD serialnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 DWORD maxcomp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 DWORD flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 char * name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 char * type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 } volume_info_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 /* Global referenced by various functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 static volume_info_data volume_info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 /* Vector to indicate which drives are local and fixed (for which cached
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 data never expires). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 static BOOL fixed_drives[26];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 /* Consider cached volume information to be stale if older than 10s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 at least for non-local drives. Info for fixed drives is never stale. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 #define DRIVE_INDEX( c ) ( (c) <= 'Z' ? (c) - 'A' : (c) - 'a' )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 #define VOLINFO_STILL_VALID( root_dir, info ) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 ( ( isalpha (root_dir[0]) && \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 fixed_drives[ DRIVE_INDEX (root_dir[0]) ] ) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 || GetTickCount () - info->timestamp < 10000 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 /* Cache support functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 /* Simple linked list with linear search is sufficient. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 static volume_info_data *volume_cache = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 static volume_info_data *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 lookup_volume_info (char * root_dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 volume_info_data * info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 for (info = volume_cache; info; info = info->next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 if (stricmp (info->root_dir, root_dir) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 return info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 add_volume_info (char * root_dir, volume_info_data * info)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 info->root_dir = xstrdup (root_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 info->next = volume_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 volume_cache = info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 /* Wrapper for GetVolumeInformation, which uses caching to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 performance penalty (~2ms on 486 for local drives, 7.5ms for local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 cdrom drive, ~5-10ms or more for remote drives on LAN). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 volume_info_data *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 GetCachedVolumeInformation (char * root_dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 volume_info_data * info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 char default_root[ MAX_PATH ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 /* NULL for root_dir means use root from current directory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 if (root_dir == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 if (GetCurrentDirectory (MAX_PATH, default_root) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 parse_root (default_root, &root_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 *root_dir = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 root_dir = default_root;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 /* Local fixed drives can be cached permanently. Removable drives
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 cannot be cached permanently, since the volume name and serial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 number (if nothing else) can change. Remote drives should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 treated as if they are removable, since there is no sure way to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 tell whether they are or not. Also, the UNC association of drive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 letters mapped to remote volumes can be changed at any time (even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 by other processes) without notice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 As a compromise, so we can benefit from caching info for remote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 volumes, we use a simple expiry mechanism to invalidate cache
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 entries that are more than ten seconds old. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 /* No point doing this, because WNetGetConnection is even slower than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 GetVolumeInformation, consistently taking ~50ms on a 486 (FWIW,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 GetDriveType is about the only call of this type which does not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 involve network access, and so is extremely quick). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 /* Map drive letter to UNC if remote. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 if ( isalpha( root_dir[0] ) && !fixed[ DRIVE_INDEX( root_dir[0] ) ] )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 char remote_name[ 256 ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 char drive[3] = { root_dir[0], ':' };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 if (WNetGetConnection (drive, remote_name, sizeof (remote_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 == NO_ERROR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 /* do something */ ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 info = lookup_volume_info (root_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 if (info == NULL || ! VOLINFO_STILL_VALID (root_dir, info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 char name[ 256 ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 DWORD serialnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 DWORD maxcomp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 DWORD flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 char type[ 256 ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 /* Info is not cached, or is stale. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 if (!GetVolumeInformation (root_dir,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 name, sizeof (name),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 &serialnum,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 &maxcomp,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 &flags,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 type, sizeof (type)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 /* Cache the volume information for future use, overwriting existing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 entry if present. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 if (info == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 info = (volume_info_data *) xmalloc (sizeof (volume_info_data));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 add_volume_info (root_dir, info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 free (info->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 free (info->type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 info->name = xstrdup (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 info->serialnum = serialnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 info->maxcomp = maxcomp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 info->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 info->type = xstrdup (type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 info->timestamp = GetTickCount ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 return info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 /* Get information on the volume where name is held; set path pointer to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 start of pathname in name (past UNC header\volume header if present). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 get_volume_info (const char * name, const char ** pPath)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 char temp[MAX_PATH];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 char *rootname = NULL; /* default to current volume */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 volume_info_data * info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 if (name == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 /* find the root name of the volume if given */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 if (isalpha (name[0]) && name[1] == ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 rootname = temp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 temp[0] = *name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 temp[1] = *name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 temp[2] = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 temp[3] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 char *str = temp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 int slashes = 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 rootname = temp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 *str++ = *name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 while ( *name );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 *str++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 *str = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 if (pPath)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 *pPath = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 info = GetCachedVolumeInformation (rootname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 if (info != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 /* Set global referenced by other functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 volume_info = *info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 /* Determine if volume is FAT format (ie. only supports short 8.3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 names); also set path pointer to start of pathname in name. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 is_fat_volume (const char * name, const char ** pPath)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 if (get_volume_info (name, pPath))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 return (volume_info.maxcomp == 12);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 /* Map filename to a legal 8.3 name if necessary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 const char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 map_win32_filename (const char * name, const char ** pPath)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 static char shortname[MAX_PATH];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 char * str = shortname;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 const char * path;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 const char * save_name = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 if (is_fat_volume (name, &path)) /* truncate to 8.3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 REGISTER int left = 8; /* maximum number of chars in part */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 REGISTER int extn = 0; /* extension added? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 REGISTER int dots = 2; /* maximum number of dots allowed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 while (name < path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 *str++ = *name++; /* skip past UNC header */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 while ((c = *name++))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 switch ( c )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 case '\\':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 case '/':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 *str++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 extn = 0; /* reset extension flags */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 dots = 2; /* max 2 dots */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 left = 8; /* max length 8 for main part */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 case ':':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 *str++ = ':';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 extn = 0; /* reset extension flags */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 dots = 2; /* max 2 dots */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 left = 8; /* max length 8 for main part */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 case '.':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 if ( dots )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 /* Convert path components of the form .xxx to _xxx,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 but leave . and .. as they are. This allows .emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 to be read as _emacs, for example. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 if (! *name ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 *name == '.' ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 IS_DIRECTORY_SEP (*name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 *str++ = '.';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 dots--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 *str++ = '_';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 left--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 dots = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 else if ( !extn )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 *str++ = '.';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 extn = 1; /* we've got an extension */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 left = 3; /* 3 chars in extension */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 /* any embedded dots after the first are converted to _ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 *str++ = '_';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 case '~':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 case '#': /* don't lose these, they're important */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 if ( ! left )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 str[-1] = c; /* replace last character of part */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 /* FALLTHRU */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 if ( left )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 *str++ = tolower (c); /* map to lower case (looks nicer) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 left--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 dots = 0; /* started a path component */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 *str = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 strcpy (shortname, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 unixtodos_filename (shortname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 if (pPath)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 *pPath = shortname + (path - save_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 return shortname;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 /* Emulate the Unix directory procedures opendir, closedir,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 and readdir. We can't use the procedures supplied in sysdep.c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 so we provide them here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 struct direct dir_static; /* simulated directory contents */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 static HANDLE dir_find_handle = INVALID_HANDLE_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 static int dir_is_fat;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 static char dir_pathname[MAXPATHLEN+1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 static WIN32_FIND_DATA dir_find_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 DIR *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 opendir (const char *filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 DIR *dirp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 /* Opening is done by FindFirstFile. However, a read is inherent to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 this operation, so we defer the open until read time. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 if (!(dirp = xnew_and_zero(DIR)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 if (dir_find_handle != INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 dirp->dd_fd = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 dirp->dd_loc = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 dirp->dd_size = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 strncpy (dir_pathname, map_win32_filename (filename, NULL), MAXPATHLEN);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 dir_pathname[MAXPATHLEN] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 dir_is_fat = is_fat_volume (filename, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 return dirp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1052 int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 closedir (DIR *dirp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1055 BOOL retval;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1056
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 /* If we have a find-handle open, close it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 if (dir_find_handle != INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1060 retval = FindClose (dir_find_handle);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 dir_find_handle = INVALID_HANDLE_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 xfree (dirp);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1064 if (retval)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1065 return 0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1066 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1067 return -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 struct direct *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 readdir (DIR *dirp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 /* If we aren't dir_finding, do a find-first, otherwise do a find-next. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 if (dir_find_handle == INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 char filename[MAXNAMLEN + 3];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 int ln;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 strcpy (filename, dir_pathname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 ln = strlen (filename) - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 if (!IS_DIRECTORY_SEP (filename[ln]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 strcat (filename, "\\");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 strcat (filename, "*");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 dir_find_handle = FindFirstFile (filename, &dir_find_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 if (dir_find_handle == INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 if (!FindNextFile (dir_find_handle, &dir_find_data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 /* Emacs never uses this value, so don't bother making it match
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1097 value returned by xemacs_stat(). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 dir_static.d_ino = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 dir_static.d_namlen - dir_static.d_namlen % 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 dir_static.d_namlen = strlen (dir_find_data.cFileName);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 strcpy (dir_static.d_name, dir_find_data.cFileName);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 if (dir_is_fat)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 _strlwr (dir_static.d_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 else if (!NILP (Vmswindows_downcase_file_names))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 REGISTER char *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 for (p = dir_static.d_name; *p; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 if (*p >= 'a' && *p <= 'z')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 if (!*p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 _strlwr (dir_static.d_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 return &dir_static;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 /* #### Have to check if all that sad story about '95 is true - kkm */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 sys_rename (const char * oldname, const char * newname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 char temp[MAX_PATH];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 DWORD attr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 /* MoveFile on Win95 doesn't correctly change the short file name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 alias in a number of circumstances (it is not easy to predict when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 just by looking at oldname and newname, unfortunately). In these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 cases, renaming through a temporary name avoids the problem.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 A second problem on Win95 is that renaming through a temp name when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 newname is uppercase fails (the final long name ends up in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 lowercase, although the short alias might be uppercase) UNLESS the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 long temp name is not 8.3.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 So, on Win95 we always rename through a temp name, and we make sure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 the temp name has a long extension to ensure correct renaming. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 strcpy (temp, map_win32_filename (oldname, NULL));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 if (GetVersion () & 0x80000000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 char * p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 if (p = strrchr (temp, '\\'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 p = temp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 /* Force temp name to require a manufactured 8.3 alias - this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 seems to make the second rename work properly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 strcpy (p, "_rename_temp.XXXXXX");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 sys_mktemp (temp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 if (rename (map_win32_filename (oldname, NULL), temp) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 /* Emulate Unix behavior - newname is deleted if it already exists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 (at least if it is a file; don't do this for directories).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 However, don't do this if we are just changing the case of the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 name - we will end up deleting the file we are trying to rename! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 newname = map_win32_filename (newname, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 /* TODO: Use GetInformationByHandle (on NT) to ensure newname and temp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 do not refer to the same file, eg. through share aliases. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 if (stricmp (newname, temp) != 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 && (attr = GetFileAttributes (newname)) != -1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 _chmod (newname, 0666);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 _unlink (newname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 return rename (temp, newname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 static FILETIME utc_base_ft;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1180 static int init = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1181
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1182 #if 0
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1183
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 static long double utc_base;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 time_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 convert_time (FILETIME ft)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 long double ret;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 if (!init)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 SYSTEMTIME st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 st.wYear = 1970;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 st.wMonth = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 st.wDay = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 st.wHour = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 st.wMinute = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 st.wSecond = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 st.wMilliseconds = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 SystemTimeToFileTime (&st, &utc_base_ft);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 utc_base = (long double) utc_base_ft.dwHighDateTime
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 init = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 if (CompareFileTime (&ft, &utc_base_ft) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 ret = (long double) ft.dwHighDateTime * 4096 * 1024 * 1024 + ft.dwLowDateTime;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 ret -= utc_base;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 return (time_t) (ret * 1e-7);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 }
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1217 #else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1218
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1219 #if defined(MINGW) && CYGWIN_VERSION_DLL_MAJOR <= 21
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1220 #define LowPart u.LowPart
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1221 #define HighPart u.HighPart
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1222 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1223
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1224 static LARGE_INTEGER utc_base_li;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1225
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1226 time_t
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1227 convert_time (FILETIME uft)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1228 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1229 time_t ret;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1230 #ifndef MAXLONGLONG
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1231 SYSTEMTIME st;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1232 struct tm t;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1233 FILETIME ft;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1234 TIME_ZONE_INFORMATION tzi;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1235 DWORD tzid;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1236 #else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1237 LARGE_INTEGER lft;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1238 #endif
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1239
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1240 if (!init)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1241 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1242 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1243 SYSTEMTIME st;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1244
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1245 st.wYear = 1970;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1246 st.wMonth = 1;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1247 st.wDay = 1;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1248 st.wHour = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1249 st.wMinute = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1250 st.wSecond = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1251 st.wMilliseconds = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1252
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1253 SystemTimeToFileTime (&st, &utc_base_ft);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1254
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1255 utc_base_li.LowPart = utc_base_ft.dwLowDateTime;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1256 utc_base_li.HighPart = utc_base_ft.dwHighDateTime;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1257
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1258 init = 1;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1259 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1260
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1261 #ifdef MAXLONGLONG
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1262
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1263 /* On a compiler that supports long integers, do it the easy way */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1264 lft.LowPart = uft.dwLowDateTime;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1265 lft.HighPart = uft.dwHighDateTime;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1266 ret = (time_t) ((lft.QuadPart - utc_base_li.QuadPart) / 10000000);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1267
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1268 #else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1269
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1270 /* Do it the hard way using mktime. */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1271 FileTimeToLocalFileTime(&uft, &ft);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1272 FileTimeToSystemTime (&ft, &st);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1273 tzid = GetTimeZoneInformation (&tzi);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1274 t.tm_year = st.wYear - 1900;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1275 t.tm_mon = st.wMonth - 1;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1276 t.tm_mday = st.wDay;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1277 t.tm_hour = st.wHour;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1278 t.tm_min = st.wMinute;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1279 t.tm_sec = st.wSecond;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1280 t.tm_isdst = (tzid == TIME_ZONE_ID_DAYLIGHT);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1281 /* st.wMilliseconds not applicable */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1282 ret = mktime(&t);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1283 if (ret == -1)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1284 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1285 ret = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1286 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1287
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1288 #endif
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1289
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1290 return ret;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1291 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1292 #endif
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1293 #if defined(MINGW) && CYGWIN_VERSION_DLL_MAJOR <= 21
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1294 #undef LowPart
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1295 #undef HighPart
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1296 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 /* in case we ever have need of this */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 convert_from_time_t (time_t time, FILETIME * pft)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 long double tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 if (!init)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 SYSTEMTIME st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 st.wYear = 1970;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 st.wMonth = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 st.wDay = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 st.wHour = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 st.wMinute = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 st.wSecond = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 st.wMilliseconds = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 SystemTimeToFileTime (&st, &utc_base_ft);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 utc_base = (long double) utc_base_ft.dwHighDateTime
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 init = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 /* time in 100ns units since 1-Jan-1601 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 tmp = (long double) time * 1e7 + utc_base;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 pft->dwHighDateTime = (DWORD) (tmp / (4096.0 * 1024 * 1024));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 pft->dwLowDateTime = (DWORD) (tmp - pft->dwHighDateTime);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 /* No reason to keep this; faking inode values either by hashing or even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 using the file index from GetInformationByHandle, is not perfect and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 so by default Emacs doesn't use the inode values on Windows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 Instead, we now determine file-truename correctly (except for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 possible drive aliasing etc). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 /* Modified version of "PJW" algorithm (see the "Dragon" compiler book). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 static unsigned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 hashval (const unsigned char * str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 unsigned h = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 while (*str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 h = (h << 4) + *str++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 h ^= (h >> 28);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 return h;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 /* Return the hash value of the canonical pathname, excluding the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 drive/UNC header, to get a hopefully unique inode number. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 static DWORD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 generate_inode_val (const char * name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 char fullname[ MAX_PATH ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 char * p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 unsigned hash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 /* Get the truly canonical filename, if it exists. (Note: this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 doesn't resolve aliasing due to subst commands, or recognize hard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 links. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 if (!win32_get_long_filename ((char *)name, fullname, MAX_PATH))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 parse_root (fullname, &p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 /* Normal Win32 filesystems are still case insensitive. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 _strlwr (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 return hashval (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1374 /* #### aichner@ecf.teradyne.com reported that with the library
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1375 provided stat/fstat, (file-exist "d:\\tmp\\") =>> nil,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1376 (file-exist "d:\\tmp") =>> t, when d:\tmp exists. Whenever
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1377 we opt to use non-encapsulated stat(), this should serve as
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1378 a compatibility test. --kkm */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1379
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1380 /* Since stat is encapsulated on Windows NT, we need to encapsulate
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1381 the equally broken fstat as well. FSFmacs also provides its own
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1382 utime. Is that necessary here too? */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1383 int
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1384 mswindows_fstat (int desc, struct stat * buf)
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1385 {
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1386 HANDLE fh = (HANDLE) _get_osfhandle (desc);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1387 BY_HANDLE_FILE_INFORMATION info;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1388 DWORD fake_inode;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1389 int permission;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1390
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1391 switch (GetFileType (fh) & ~FILE_TYPE_REMOTE)
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1392 {
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1393 case FILE_TYPE_DISK:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1394 buf->st_mode = _S_IFREG;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1395 if (!GetFileInformationByHandle (fh, &info))
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1396 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1397 errno = EACCES;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1398 return -1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1399 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1400 break;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1401 case FILE_TYPE_PIPE:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1402 buf->st_mode = _S_IFIFO;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1403 goto non_disk;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1404 case FILE_TYPE_CHAR:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1405 case FILE_TYPE_UNKNOWN:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1406 default:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1407 buf->st_mode = _S_IFCHR;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1408 non_disk:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1409 memset (&info, 0, sizeof (info));
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1410 info.dwFileAttributes = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1411 info.ftCreationTime = utc_base_ft;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1412 info.ftLastAccessTime = utc_base_ft;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1413 info.ftLastWriteTime = utc_base_ft;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1414 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1415
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1416 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1417 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1418 buf->st_mode = _S_IFDIR;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1419 buf->st_nlink = 2; /* doesn't really matter */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1420 fake_inode = 0; /* this doesn't either I think */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1421 }
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1422 else
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1423 {
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1424 buf->st_nlink = info.nNumberOfLinks;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1425 /* Might as well use file index to fake inode values, but this
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1426 is not guaranteed to be unique unless we keep a handle open
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1427 all the time (even then there are situations where it is
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1428 not unique). Reputedly, there are at most 48 bits of info
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1429 (on NTFS, presumably less on FAT). */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1430 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1431 }
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1432
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1433 /* MSVC defines _ino_t to be short; other libc's might not. */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1434 if (sizeof (buf->st_ino) == 2)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1435 buf->st_ino = fake_inode ^ (fake_inode >> 16);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1436 else
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1437 buf->st_ino = fake_inode;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1438
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1439 /* consider files to belong to current user */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1440 buf->st_uid = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1441 buf->st_gid = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1442
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1443 buf->st_dev = info.dwVolumeSerialNumber;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1444 buf->st_rdev = info.dwVolumeSerialNumber;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1445
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1446 buf->st_size = info.nFileSizeLow;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1447
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1448 /* Convert timestamps to Unix format. */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1449 buf->st_mtime = convert_time (info.ftLastWriteTime);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1450 buf->st_atime = convert_time (info.ftLastAccessTime);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1451 if (buf->st_atime == 0) buf->st_atime = buf->st_mtime;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1452 buf->st_ctime = convert_time (info.ftCreationTime);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1453 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1454
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1455 /* determine rwx permissions */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1456 if (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1457 permission = _S_IREAD;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1458 else
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1459 permission = _S_IREAD | _S_IWRITE;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1460
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1461 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1462 permission |= _S_IEXEC;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1463
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1464 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1465
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1466 return 0;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1467 }
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1468
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 /* MSVC stat function can't cope with UNC names and has other bugs, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 replace it with our own. This also allows us to calculate consistent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 inode values without hacks in the main Emacs code. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1473 mswindows_stat (const char * path, struct stat * buf)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 char * name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 WIN32_FIND_DATA wfd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 HANDLE fh;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 DWORD fake_inode;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 int permission;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 int rootdir = FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 if (path == NULL || buf == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 errno = EFAULT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 name = (char *) map_win32_filename (path, &path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 /* must be valid filename, no wild cards */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 if (strchr (name, '*') || strchr (name, '?'))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 errno = ENOENT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 /* Remove trailing directory separator, unless name is the root
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 directory of a drive or UNC volume in which case ensure there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 is a trailing separator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 len = strlen (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 rootdir = (path >= name + len - 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 && (IS_DIRECTORY_SEP (*path) || *path == 0));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1503 name = strcpy ((char *)alloca (len + 2), name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 if (rootdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 if (!IS_DIRECTORY_SEP (name[len-1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 strcat (name, "\\");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 if (GetDriveType (name) < 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 errno = ENOENT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 memset (&wfd, 0, sizeof (wfd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 wfd.ftCreationTime = utc_base_ft;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 wfd.ftLastAccessTime = utc_base_ft;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 wfd.ftLastWriteTime = utc_base_ft;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 strcpy (wfd.cFileName, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 if (IS_DIRECTORY_SEP (name[len-1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 name[len - 1] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 /* (This is hacky, but helps when doing file completions on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 network drives.) Optimize by using information available from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 active readdir if possible. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 if (dir_find_handle != INVALID_HANDLE_VALUE &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 (len = strlen (dir_pathname)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 strnicmp (name, dir_pathname, len) == 0 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 IS_DIRECTORY_SEP (name[len]) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 stricmp (name + len + 1, dir_static.d_name) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 /* This was the last entry returned by readdir. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 wfd = dir_find_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 fh = FindFirstFile (name, &wfd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 if (fh == INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 errno = ENOENT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 FindClose (fh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 buf->st_mode = _S_IFDIR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 buf->st_nlink = 2; /* doesn't really matter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 fake_inode = 0; /* this doesn't either I think */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 else if (!NILP (Vmswindows_get_true_file_attributes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 /* This is more accurate in terms of getting the correct number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 of links, but is quite slow (it is noticeable when Emacs is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 making a list of file name completions). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 BY_HANDLE_FILE_INFORMATION info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 /* No access rights required to get info. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 fh = CreateFile (name, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 OPEN_EXISTING, 0, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 if (GetFileInformationByHandle (fh, &info))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 switch (GetFileType (fh))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 case FILE_TYPE_DISK:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 buf->st_mode = _S_IFREG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 case FILE_TYPE_PIPE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 buf->st_mode = _S_IFIFO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 case FILE_TYPE_CHAR:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 case FILE_TYPE_UNKNOWN:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 buf->st_mode = _S_IFCHR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 buf->st_nlink = (short) info.nNumberOfLinks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 /* Might as well use file index to fake inode values, but this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 is not guaranteed to be unique unless we keep a handle open
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 all the time (even then there are situations where it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 not unique). Reputedly, there are at most 48 bits of info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 (on NTFS, presumably less on FAT). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 CloseHandle (fh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 errno = EACCES;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 /* Don't bother to make this information more accurate. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 buf->st_mode = _S_IFREG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 buf->st_nlink = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 fake_inode = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 /* Not sure if there is any point in this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 if (!NILP (Vwin32_generate_fake_inodes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 fake_inode = generate_inode_val (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 else if (fake_inode == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 /* For want of something better, try to make everything unique. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 static DWORD gen_num = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 fake_inode = ++gen_num;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 /* #### MSVC defines _ino_t to be short; other libc's might not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 /* consider files to belong to current user */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1621 buf->st_uid = buf->st_gid = nt_fake_unix_uid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 /* volume_info is set indirectly by map_win32_filename */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 buf->st_dev = volume_info.serialnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 buf->st_rdev = volume_info.serialnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 buf->st_size = wfd.nFileSizeLow;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 /* Convert timestamps to Unix format. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 buf->st_mtime = convert_time (wfd.ftLastWriteTime);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 buf->st_atime = convert_time (wfd.ftLastAccessTime);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 if (buf->st_atime == 0) buf->st_atime = buf->st_mtime;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 buf->st_ctime = convert_time (wfd.ftCreationTime);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 /* determine rwx permissions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 permission = _S_IREAD;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 permission = _S_IREAD | _S_IWRITE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 permission |= _S_IEXEC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 char * p = strrchr (name, '.');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 if (p != NULL &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 (stricmp (p, ".exe") == 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 stricmp (p, ".com") == 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 stricmp (p, ".bat") == 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 stricmp (p, ".cmd") == 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 permission |= _S_IEXEC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 /* From callproc.c */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 extern Lisp_Object Vbinary_process_input;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 extern Lisp_Object Vbinary_process_output;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 /* Unix pipe() has only one arg */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 sys_pipe (int * phandles)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 int rc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 unsigned flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 /* make pipe handles non-inheritable; when we spawn a child, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 replace the relevant handle with an inheritable one. Also put
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 pipes into binary mode; we will do text mode translation ourselves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 if required. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 rc = _pipe (phandles, 0, _O_NOINHERIT | _O_BINARY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 if (rc == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 flags = FILE_PIPE | FILE_READ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 if (!NILP (Vbinary_process_output))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 flags |= FILE_BINARY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 fd_info[phandles[0]].flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 flags = FILE_PIPE | FILE_WRITE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 if (!NILP (Vbinary_process_input))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 flags |= FILE_BINARY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 fd_info[phandles[1]].flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 return rc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 term_ntproc (int unused)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1699 init_ntproc (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 /* Initial preparation for subprocess support: replace our standard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 handles with non-inheritable versions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 HANDLE parent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 HANDLE stdin_save = INVALID_HANDLE_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 HANDLE stdout_save = INVALID_HANDLE_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 HANDLE stderr_save = INVALID_HANDLE_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 parent = GetCurrentProcess ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 /* ignore errors when duplicating and closing; typically the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 handles will be invalid when running as a gui program. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 DuplicateHandle (parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 GetStdHandle (STD_INPUT_HANDLE),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 &stdin_save,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 FALSE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 DUPLICATE_SAME_ACCESS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 DuplicateHandle (parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 GetStdHandle (STD_OUTPUT_HANDLE),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 &stdout_save,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 FALSE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 DUPLICATE_SAME_ACCESS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 DuplicateHandle (parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 GetStdHandle (STD_ERROR_HANDLE),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 parent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 &stderr_save,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 FALSE,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 DUPLICATE_SAME_ACCESS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 fclose (stdin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 fclose (stdout);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 fclose (stderr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 if (stdin_save != INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 _open_osfhandle ((long) stdin_save, O_TEXT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 _open ("nul", O_TEXT | O_NOINHERIT | O_RDONLY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 _fdopen (0, "r");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 if (stdout_save != INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 _open_osfhandle ((long) stdout_save, O_TEXT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 _fdopen (1, "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 if (stderr_save != INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 _open_osfhandle ((long) stderr_save, O_TEXT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 _fdopen (2, "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 /* unfortunately, atexit depends on implementation of malloc */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 /* atexit (term_ntproc); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 signal (SIGABRT, term_ntproc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 /* determine which drives are fixed, for GetCachedVolumeInformation */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 /* GetDriveType must have trailing backslash. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 char drive[] = "A:\\";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 /* Loop over all possible drive letters */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 while ( *drive <= 'Z' )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 /* Record if this drive letter refers to a fixed drive. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 fixed_drives[ DRIVE_INDEX (*drive) ] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 (GetDriveType (drive) == DRIVE_FIXED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 (*drive)++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 #ifndef HAVE_TTY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 tty_semi_canonicalize_console_connection (Lisp_Object connection,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 Error_behavior errb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 return Vstdio_str;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 tty_canonicalize_console_connection (Lisp_Object connection,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 Error_behavior errb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 return Vstdio_str;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 tty_semi_canonicalize_device_connection (Lisp_Object connection,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 Error_behavior errb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 return Vstdio_str;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 tty_canonicalize_device_connection (Lisp_Object connection,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 Error_behavior errb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 return Vstdio_str;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 /*--------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 /* Signal support */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 /*--------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 /* We need MS-defined signal and raise here */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 #undef signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 #undef raise
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 #define sigmask(nsig) (1U << nsig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 /* We can support as many signals as fit into word */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 #define SIG_MAX 32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 /* Signal handlers. Initial value = 0 = SIG_DFL */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 static void (__cdecl *signal_handlers[SIG_MAX])(int) = {0};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 /* Signal block mask: bit set to 1 means blocked */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 unsigned signal_block_mask = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 /* Signal pending mask: bit set to 1 means sig is pending */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 unsigned signal_pending_mask = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1832 mswindows_sighandler mswindows_sigset (int nsig, mswindows_sighandler handler)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 /* We delegate some signals to the system function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 return signal (nsig, handler);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 if (nsig < 0 || nsig > SIG_MAX)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 /* Store handler ptr */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1846 mswindows_sighandler old_handler = signal_handlers[nsig];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 signal_handlers[nsig] = handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 return old_handler;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1852 int mswindows_sighold (int nsig)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 if (nsig < 0 || nsig > SIG_MAX)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 return errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 signal_block_mask |= sigmask(nsig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1861 int mswindows_sigrelse (int nsig)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 if (nsig < 0 || nsig > SIG_MAX)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 return errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 signal_block_mask &= ~sigmask(nsig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 if (signal_pending_mask & sigmask(nsig))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1869 mswindows_raise (nsig);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1874 int mswindows_sigpause (int nsig)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 /* This is currently not called, because the only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 call to sigpause inside XEmacs is with SIGCHLD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 parameter. Just in case, we put an assert here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 so anyone who will add a call to sigpause will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 be surprised (or surprise someone else...) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 assert (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1885 int mswindows_raise (int nsig)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 /* We delegate some raises to the system routine */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 if (nsig == SIGFPE || nsig == SIGABRT || nsig == SIGINT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 return raise (nsig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 if (nsig < 0 || nsig > SIG_MAX)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 return errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 /* If the signal is blocked, remember to issue later */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 if (signal_block_mask & sigmask(nsig))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 signal_pending_mask |= sigmask(nsig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 if (signal_handlers[nsig] == SIG_IGN)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 if (signal_handlers[nsig] != SIG_DFL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 (*signal_handlers[nsig])(nsig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 /* Default signal actions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 if (nsig == SIGALRM || nsig == SIGPROF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 exit (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 /* Other signals are ignored by default */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 /*--------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 /* Async timers */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 /*--------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 /* We emulate two timers, one for SIGALRM, another for SIGPROF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 itimerproc() function has an implementation limitation: it does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 not allow to set *both* interval and period. If an attempt is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 made to set both, and then they are unequal, the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 asserts.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 Minimum timer resolution on Win32 systems varies, and is greater
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 than or equal than 1 ms. The resolution is always wrapped not to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 attempt to get below the system defined limit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 /* Timer precision, denominator of one fraction: for 100 ms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 interval, request 10 ms precision
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 const int timer_prec = 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 /* Last itimervals, as set by calls to setitimer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 static struct itimerval it_alarm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 static struct itimerval it_prof;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 /* Timer IDs as returned by MM */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 MMRESULT tid_alarm = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 MMRESULT tid_prof = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 static void CALLBACK timer_proc (UINT uID, UINT uMsg, DWORD dwUser,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 DWORD dw1, DWORD dw2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 /* Just raise a signal indicated by dwUser parameter */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1951 mswindows_raise (dwUser);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 /* Divide time in ms specified by IT by DENOM. Return 1 ms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 if division results in zero */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 static UINT period (const struct itimerval* it, UINT denom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 static TIMECAPS time_caps;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 UINT res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 const struct timeval* tv =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 (it->it_value.tv_sec == 0 && it->it_value.tv_usec == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 ? &it->it_interval : &it->it_value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 /* Zero means stop timer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 if (tv->tv_sec == 0 && tv->tv_usec == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 /* Convert to ms and divide by denom */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 res = (tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000) / denom;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 /* Converge to minimum timer resolution */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 if (time_caps.wPeriodMin == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 timeGetDevCaps (&time_caps, sizeof(time_caps));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 if (res < time_caps.wPeriodMin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 res = time_caps.wPeriodMin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 return res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 static int setitimer_helper (const struct itimerval* itnew,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 struct itimerval* itold, struct itimerval* itcurrent,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 MMRESULT* tid, DWORD sigkind)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 UINT delay, resolution, event_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 /* First stop the old timer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 if (*tid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 timeKillEvent (*tid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 timeEndPeriod (period (itcurrent, timer_prec));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 *tid = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 /* Return old itimerval if requested */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 if (itold)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 *itold = *itcurrent;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 *itcurrent = *itnew;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 /* Determine if to start new timer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 delay = period (itnew, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 if (delay)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 resolution = period (itnew, timer_prec);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 event_type = (itnew->it_value.tv_sec == 0 && itnew->it_value.tv_usec == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 ? TIME_ONESHOT : TIME_PERIODIC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 timeBeginPeriod (resolution);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 *tid = timeSetEvent (delay, resolution, timer_proc, sigkind, event_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 return !delay || *tid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 int setitimer (int kind, const struct itimerval* itnew,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 struct itimerval* itold)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 /* In this version, both interval and value are allowed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 only if they are equal. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 assert ((itnew->it_value.tv_sec == 0 && itnew->it_value.tv_usec == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 || (itnew->it_interval.tv_sec == 0 && itnew->it_interval.tv_usec == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 || (itnew->it_value.tv_sec == itnew->it_interval.tv_sec &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 itnew->it_value.tv_usec == itnew->it_interval.tv_usec));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 if (kind == ITIMER_REAL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 return setitimer_helper (itnew, itold, &it_alarm, &tid_alarm, SIGALRM);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 else if (kind == ITIMER_PROF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 return setitimer_helper (itnew, itold, &it_prof, &tid_prof, SIGPROF);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 return errno = EINVAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2034
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2035 /*--------------------------------------------------------------------*/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2036 /* Memory-mapped files */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2037 /*--------------------------------------------------------------------*/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2038
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2040 open_input_file (file_data *p_file, const char *filename)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2042 /* Synched with FSF 20.6. We fixed some warnings. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 HANDLE file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 HANDLE file_mapping;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 void *file_base;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 DWORD size, upper_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 if (file == INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 size = GetFileSize (file, &upper_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 file_mapping = CreateFileMapping (file, NULL, PAGE_READONLY,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 0, size, NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 if (!file_mapping)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 if (file_base == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2063 p_file->name = (char *)filename;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2064 p_file->size = size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2065 p_file->file = file;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2066 p_file->file_mapping = file_mapping;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2067 p_file->file_base = (char *)file_base;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2068
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2069 return TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2070 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2071
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2072 int
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2073 open_output_file (file_data *p_file, const char *filename, unsigned long size)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2074 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2075 /* Synched with FSF 20.6. We fixed some warnings. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2076 HANDLE file;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2077 HANDLE file_mapping;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2078 void *file_base;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2079
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2080 file = CreateFile (filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2081 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2082 if (file == INVALID_HANDLE_VALUE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2083 return FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2084
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2085 file_mapping = CreateFileMapping (file, NULL, PAGE_READWRITE,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2086 0, size, NULL);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2087 if (!file_mapping)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2088 return FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2089
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2090 file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2091 if (file_base == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2092 return FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2093
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2094 p_file->name = filename;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 p_file->size = size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 p_file->file = file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 p_file->file_mapping = file_mapping;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2098 p_file->file_base = (char*) file_base;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2103 #if 1 /* !defined(MINGW) */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2104 /* Return pointer to section header for section containing the given
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2105 relative virtual address. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2106 static IMAGE_SECTION_HEADER *
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2107 rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2108 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2109 /* Synched with FSF 20.6. We added MINGW stuff. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2110 PIMAGE_SECTION_HEADER section;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2111 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2112
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2113 section = IMAGE_FIRST_SECTION (nt_header);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2114
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2115 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2116 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2117 /* Some linkers (eg. the NT SDK linker I believe) swapped the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2118 meaning of these two values - or rather, they ignored
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2119 VirtualSize entirely and always set it to zero. This affects
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2120 some very old exes (eg. gzip dated Dec 1993). Since
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2121 mswindows_executable_type relies on this function to work reliably,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2122 we need to cope with this. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2123 DWORD real_size = max (section->SizeOfRawData,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2124 section->Misc.VirtualSize);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2125 if (rva >= section->VirtualAddress
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2126 && rva < section->VirtualAddress + real_size)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2127 return section;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2128 section++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2129 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2130 return NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2131 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2132 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2133
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2134 void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2135 mswindows_executable_type (const char * filename, int * is_dos_app,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2136 int * is_cygnus_app)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2137 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2138 /* Synched with FSF 20.6. We added MINGW stuff and casts. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2139 file_data executable;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2140 char * p;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2141
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2142 /* Default values in case we can't tell for sure. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2143 *is_dos_app = FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2144 *is_cygnus_app = FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2145
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2146 if (!open_input_file (&executable, filename))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2147 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2148
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2149 p = strrchr (filename, '.');
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2150
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2151 /* We can only identify DOS .com programs from the extension. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2152 if (p && stricmp (p, ".com") == 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2153 *is_dos_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2154 else if (p && (stricmp (p, ".bat") == 0 ||
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2155 stricmp (p, ".cmd") == 0))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2156 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2157 /* A DOS shell script - it appears that CreateProcess is happy to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2158 accept this (somewhat surprisingly); presumably it looks at
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2159 COMSPEC to determine what executable to actually invoke.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2160 Therefore, we have to do the same here as well. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2161 /* Actually, I think it uses the program association for that
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2162 extension, which is defined in the registry. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2163 p = egetenv ("COMSPEC");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2164 if (p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2165 mswindows_executable_type (p, is_dos_app, is_cygnus_app);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2166 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2167 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2168 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2169 /* Look for DOS .exe signature - if found, we must also check that
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2170 it isn't really a 16- or 32-bit Windows exe, since both formats
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2171 start with a DOS program stub. Note that 16-bit Windows
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2172 executables use the OS/2 1.x format. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2173
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2174 #if 0 /* defined( MINGW ) */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2175 /* mingw32 doesn't have enough headers to detect cygwin
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2176 apps, just do what we can. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2177 FILHDR * exe_header;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2178
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2179 exe_header = (FILHDR*) executable.file_base;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2180 if (exe_header->e_magic != DOSMAGIC)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2181 goto unwind;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2182
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2183 if ((char*) exe_header->e_lfanew > (char*) executable.size)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2184 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2185 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2186 *is_dos_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2187 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2188 else if (exe_header->nt_signature != NT_SIGNATURE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2189 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2190 *is_dos_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2191 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2192 #else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2193 IMAGE_DOS_HEADER * dos_header;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2194 IMAGE_NT_HEADERS * nt_header;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2195
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2196 dos_header = (PIMAGE_DOS_HEADER) executable.file_base;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2197 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2198 goto unwind;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2199
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2200 nt_header = (PIMAGE_NT_HEADERS) ((char*) dos_header + dos_header->e_lfanew);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2201
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2202 if ((char*) nt_header > (char*) dos_header + executable.size)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2203 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2204 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2205 *is_dos_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2206 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2207 else if (nt_header->Signature != IMAGE_NT_SIGNATURE &&
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2208 LOWORD (nt_header->Signature) != IMAGE_OS2_SIGNATURE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2209 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2210 *is_dos_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2211 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2212 else if (nt_header->Signature == IMAGE_NT_SIGNATURE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2213 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2214 /* Look for cygwin.dll in DLL import list. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2215 IMAGE_DATA_DIRECTORY import_dir =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2216 nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2217 IMAGE_IMPORT_DESCRIPTOR * imports;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2218 IMAGE_SECTION_HEADER * section;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2219
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2220 section = rva_to_section (import_dir.VirtualAddress, nt_header);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2221 imports = (IMAGE_IMPORT_DESCRIPTOR *) RVA_TO_PTR (import_dir.VirtualAddress,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2222 section, executable);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2223
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2224 for ( ; imports->Name; imports++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2225 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2226 char *dllname = (char*) RVA_TO_PTR (imports->Name, section, executable);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2227
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2228 /* The exact name of the cygwin dll has changed with
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2229 various releases, but hopefully this will be reasonably
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2230 future proof. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2231 if (strncmp (dllname, "cygwin", 6) == 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2232 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2233 *is_cygnus_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2234 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2235 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2236 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2237 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2238 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2239 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2240
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2241 unwind:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2242 close_file_data (&executable);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2243 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2244
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 /* Close the system structures associated with the given file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 close_file_data (file_data *p_file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 UnmapViewOfFile (p_file->file_base);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 CloseHandle (p_file->file_mapping);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 CloseHandle (p_file->file);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2254 void
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2255 vars_of_nt (void)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2256 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2257 DEFVAR_INT ("nt-fake-unix-uid", &nt_fake_unix_uid /*
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2258 *Set uid returned by `user-uid' and `user-real-uid'.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2259 Under NT and 9x, there is no uids, and even no almighty user called root.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2260 By setting this variable, you can have any uid of choice. Default is 0.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2261 Changes to this variable take effect immediately.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2262 */ );
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2263 nt_fake_unix_uid = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2264 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2265
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 /* end of nt.c */