annotate src/nt.c @ 290:c9fe270a4101 r21-0b43

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