annotate src/nt.c @ 592:4f6ba8f1fb3d

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