annotate src/nt.c @ 5167:e374ea766cc1

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