annotate src/nt.c @ 853:2b6fa2618f76

[xemacs-hg @ 2002-05-28 08:44:22 by ben] merge my stderr-proc ws make-docfile.c: Fix places where we forget to check for EOF. code-init.el: Don't use CRLF conversion by default on process output. CMD.EXE and friends work both ways but Cygwin programs don't like the CRs. code-process.el, multicast.el, process.el: Removed. Improvements to call-process-internal: -- allows a buffer to be specified for input and stderr output -- use it on all systems -- implement C-g as documented -- clean up and comment call-process-region uses new call-process facilities; no temp file. remove duplicate funs in process.el. comment exactly how coding systems work and fix various problems. open-multicast-group now does similar coding-system frobbing to open-network-stream. dumped-lisp.el, faces.el, msw-faces.el: Fix some hidden errors due to code not being defined at the right time. xemacs.mak: Add -DSTRICT. ================================================================ ALLOW SEPARATION OF STDOUT AND STDERR IN PROCESSES ================================================================ Standard output and standard error can be processed separately in a process. Each can have its own buffer, its own mark in that buffer, and its filter function. You can specify a separate buffer for stderr in `start-process' to get things started, or use the new primitives: set-process-stderr-buffer process-stderr-buffer process-stderr-mark set-process-stderr-filter process-stderr-filter Also, process-send-region takes a 4th optional arg, a buffer. Currently always uses a pipe() under Unix to read the error output. (#### Would a PTY be better?) sysdep.h, sysproc.h, unexfreebsd.c, unexsunos4.c, nt.c, emacs.c, callproc.c, symsinit.h, sysdep.c, Makefile.in.in, process-unix.c: Delete callproc.c. Move child_setup() to process-unix.c. wait_for_termination() now only needed on a few really old systems. console-msw.h, event-Xt.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.h, process-nt.c, process-unix.c, process.c, process.h, procimpl.h: Rewrite the process methods to handle a separate channel for error input. Create Lstreams for reading in the error channel. Many process methods need change. In general the changes are fairly clear as they involve duplicating what's used for reading the normal stdout and changing for stderr -- although tedious, as such changes are required throughout the entire process code. Rewrote the code that reads process output to do two loops, one for stdout and one for stderr. gpmevent.c, tooltalk.c: set_process_filter takes an argument for stderr. ================================================================ NEW ERROR-TRAPPING MECHANISM ================================================================ Totally rewrite error trapping code to be unified and support more features. Basic function is call_trapping_problems(), which lets you specify, by means of flags, what sorts of problems you want trapped. these can include -- quit -- errors -- throws past the function -- creation of "display objects" (e.g. buffers) -- deletion of already-existing "display objects" (e.g. buffers) -- modification of already-existing buffers -- entering the debugger -- gc -- errors->warnings (ala suspended errors) etc. All other error funs rewritten in terms of this one. Various older mechanisms removed or rewritten. window.c, insdel.c, console.c, buffer.c, device.c, frame.c: When creating a display object, added call to note_object_created(), for use with trapping_problems mechanism. When deleting, call check_allowed_operation() and note_object deleted(). The trapping-problems code records the objects created since the call-trapping-problems began. Those objects can be deleted, but none others (i.e. previously existing ones). bytecode.c, cmdloop.c: internal_catch takes another arg. eval.c: Add long comments describing the "five lists" used to maintain state (backtrace, gcpro, specbind, etc.) in the Lisp engine. backtrace.h, eval.c: Implement trapping-problems mechanism, eliminate old mechanisms or redo in terms of new one. frame.c, gutter.c: Flush out the concept of "critical display section", defined by the in_display() var. Use an internal_bind() to get it reset, rather than just doing it at end, because there may be a non-local exit. event-msw.c, event-stream.c, console-msw.h, device.c, dialog-msw.c, frame.c, frame.h, intl.c, toolbar.c, menubar-msw.c, redisplay.c, alloc.c, menubar-x.c: Make use of new trapping-errors stuff and rewrite code based on old mechanisms. glyphs-widget.c, redisplay.h: Protect calling Lisp in redisplay. insdel.c: Protect hooks against deleting existing buffers. frame-msw.c: Use EQ, not EQUAL in hash tables whose keys are just numbers. Otherwise we run into stickiness in redisplay because internal_equal() can QUIT. ================================================================ SIGNAL, C-G CHANGES ================================================================ Here we change the way that C-g interacts with event reading. The idea is that a C-g occurring while we're reading a user event should be read as C-g, but elsewhere should be a QUIT. The former code did all sorts of bizarreness -- requiring that no QUIT occurs anywhere in event-reading code (impossible to enforce given the stuff called or Lisp code invoked), and having some weird system involving enqueue/dequeue of a C-g and interaction with Vquit_flag -- and it didn't work. Now, we simply enclose all code where we want C-g read as an event with {begin/end}_dont_check_for_quit(). This completely turns off the mechanism that checks (and may remove or alter) C-g in the read-ahead queues, so we just get the C-g normal. Signal.c documents this very carefully. cmdloop.c: Correct use of dont_check_for_quit to new scheme, remove old out-of-date comments. event-stream.c: Fix C-g handling to actually work. device-x.c: Disable quit checking when err out. signal.c: Cleanup. Add large descriptive comment. process-unix.c, process-nt.c, sysdep.c: Use QUIT instead of REALLY_QUIT. It's not necessary to use REALLY_QUIT and just confuses the issue. lisp.h: Comment quit handlers. ================================================================ CONS CHANGES ================================================================ free_cons() now takes a Lisp_Object not the result of XCONS(). car and cdr have been renamed so that they don't get used directly; go through XCAR(), XCDR() instead. alloc.c, dired.c, editfns.c, emodules.c, fns.c, glyphs-msw.c, glyphs-x.c, glyphs.c, keymap.c, minibuf.c, search.c, eval.c, lread.c, lisp.h: Correct free_cons calling convention: now takes Lisp_Object, not Lisp_Cons chartab.c: Eliminate direct use of ->car, ->cdr, should be black box. callint.c: Rewrote using EXTERNAL_LIST_LOOP to avoid use of Lisp_Cons. ================================================================ USE INTERNAL-BIND-* ================================================================ eval.c: Cleanups of these funs. alloc.c, fileio.c, undo.c, specifier.c, text.c, profile.c, lread.c, redisplay.c, menubar-x.c, macros.c: Rewrote to use internal_bind_int() and internal_bind_lisp_object() in place of whatever varied and cumbersome mechanisms were formerly there. ================================================================ SPECBIND SANITY ================================================================ backtrace.h: - Improved comments backtrace.h, bytecode.c, eval.c: Add new mechanism check_specbind_stack_sanity() for sanity checking code each time the catchlist or specbind stack change. Removed older prototype of same mechanism. ================================================================ MISC ================================================================ lisp.h, insdel.c, window.c, device.c, console.c, buffer.c: Fleshed out authorship. device-msw.c: Correct bad Unicode-ization. print.c: Be more careful when not initialized or in fatal error handling. search.c: Eliminate running_asynch_code, an FSF holdover. alloc.c: Added comments about gc-cons-threshold. dialog-x.c: Use begin_gc_forbidden() around code to build up a widget value tree, like in menubar-x.c. gui.c: Use Qunbound not Qnil as the default for gethash. lisp-disunion.h, lisp-union.h: Added warnings on use of VOID_TO_LISP(). lisp.h: Use ERROR_CHECK_STRUCTURES to turn on ERROR_CHECK_TRAPPING_PROBLEMS and ERROR_CHECK_TYPECHECK lisp.h: Add assert_with_message. lisp.h: Add macros for gcproing entire arrays. (You could do this before but it required manual twiddling the gcpro structure.) lisp.h: Add prototypes for new functions defined elsewhere.
author ben
date Tue, 28 May 2002 08:45:36 +0000
parents e7ee5f8bde58
children 1d8fb2eee1bb
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.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
3 Copyright (C) 2000, 2001, 2002 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.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
33 Synched (completely!) with Emacs 21.1.103 by Ben Wing, 6-13-01.
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"
4f6ba8f1fb3d [xemacs-hg @ 2001-05-31 12:03:37 by adrian]
adrian
parents: 578
diff changeset
42
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #include "sysproc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #include "sysfile.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
47 #include "syspwd.h"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
48 #include "sysdir.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
50 #include "syswindows.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
52 /* 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
53 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
54 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
55 Lisp_Object Vmswindows_get_true_file_attributes;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
57 /* Vmswindows_generate_fake_inodes; deleted */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
58
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
59 Fixnum mswindows_fake_unix_uid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 /* Emulate getpwuid, getpwnam and others. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
63 static struct passwd the_passwd =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
65 "",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
66 "",
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 0,
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,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
70 "",
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 "",
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 uid_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
76 getuid (void)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
77 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
78 return mswindows_fake_unix_uid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 }
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 uid_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
82 geteuid (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
84 /* 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
85 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
86 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
87 in the long run.]] */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
88 return mswindows_fake_unix_uid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 }
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 gid_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
92 getgid (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 return the_passwd.pw_gid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 gid_t
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
98 getegid (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 return getgid ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 struct passwd *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 getpwuid (uid_t uid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
106 if (uid == mswindows_fake_unix_uid)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
107 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
108 the_passwd.pw_gid = the_passwd.pw_uid = uid;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
109 return &the_passwd;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
110 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
111 else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
112 return NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 struct passwd *
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
116 getpwnam (const Intbyte *name)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 struct passwd *pw;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 pw = getpwuid (getuid ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 if (!pw)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 return pw;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
124 if (qxestrcasecmp_i18n (name, pw->pw_name))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 return pw;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
130 static void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
131 init_user_info (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
133 /* 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
134 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
135 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
136 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
137 choice. --kkm, 02/03/2000 */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
138 #if 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 /* Find the user's real name by opening the process token and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 looking up the name associated with the user-sid in that token.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 Use the relative portion of the identifier authority value from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 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
144 primary group sid from the process token). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
146 TOKEN_USER sidinfo;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
147 Extbyte name[256], domain[256];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
148 Charcount length = sizeof (name) / XETCHAR_SIZE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
149 Charcount dlength = sizeof (domain) / XETCHAR_SIZE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
150 DWORD trash;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
151 HANDLE token = NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
152 SID_NAME_USE user_type;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &token)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
155 && GetTokenInformation (token, TokenUser, &sidinfo, sizeof (sidinfo),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
156 &trash)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
157 && qxeLookupAccountSid (NULL, sidinfo.User.Sid, name, &length,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
158 domain, &dlength, &user_type))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
160 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 /* Determine a reasonable uid value. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
162 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 the_passwd.pw_uid = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 the_passwd.pw_gid = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 SID_IDENTIFIER_AUTHORITY * pSIA;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
170 TOKEN_PRIMARY_GROUP group;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
172 pSIA = GetSidIdentifierAuthority (sidinfo.User.Sid);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 /* I believe the relative portion is the last 4 bytes (of 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 with msb first. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 the_passwd.pw_uid = ((pSIA->Value[2] << 24) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (pSIA->Value[3] << 16) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (pSIA->Value[4] << 8) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (pSIA->Value[5] << 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 /* restrict to conventional uid range for normal users */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 the_passwd.pw_uid = the_passwd.pw_uid % 60001;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 /* Get group id */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 if (GetTokenInformation (token, TokenPrimaryGroup,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
184 &group, sizeof (group), &trash))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 SID_IDENTIFIER_AUTHORITY * pSIA;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
188 pSIA = GetSidIdentifierAuthority (group.PrimaryGroup);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 the_passwd.pw_gid = ((pSIA->Value[2] << 24) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (pSIA->Value[3] << 16) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (pSIA->Value[4] << 8) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 (pSIA->Value[5] << 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 /* I don't know if this is necessary, but for safety... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 the_passwd.pw_gid = the_passwd.pw_gid % 60001;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 the_passwd.pw_gid = the_passwd.pw_uid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 /* If security calls are not supported (presumably because we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 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
202 else if (qxeGetUserName (name, &length))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
204 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
205 if (qxestrcasecmp ("administrator", the_passwd.pw_name) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 the_passwd.pw_uid = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 the_passwd.pw_uid = 123;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 the_passwd.pw_gid = the_passwd.pw_uid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
213 the_passwd.pw_name = "unknown";
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 the_passwd.pw_uid = 123;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 the_passwd.pw_gid = 123;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
218 if (token)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
219 CloseHandle (token);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
220 #else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
221 /* 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
222 DWORD length = UNLEN + 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
223 Extbyte name[MAX_XETCHAR_SIZE * (UNLEN + 1)];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
224 if (qxeGetUserName (name, &length))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
225 TSTR_TO_C_STRING_MALLOC (name, the_passwd.pw_name);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
226 else
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
227 the_passwd.pw_name = "unknown";
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
228 #endif
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
229
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
230 #if 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 /* Ensure HOME and SHELL are defined. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 * With XEmacs, setting $HOME is deprecated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
235 if (egetenv ("HOME") == NULL)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
236 eputenv ("HOME=c:/");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 605
diff changeset
239 /* Set dir from environment variables. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
240 the_passwd.pw_dir = (char *) qxestrdup (get_home_directory ());
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 605
diff changeset
241 /* 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
242 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
243 is not used anywhere. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
246 /* Parse the root part of file name, if present. Return length and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
247 optionally store pointer to Intbyte after root. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
248 static Bytecount
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
249 parse_root (Intbyte *name, Intbyte **pPath)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
251 Intbyte *start = name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 if (name == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 /* find the root name of the volume if given */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 if (isalpha (name[0]) && name[1] == ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 /* skip past drive specifier */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 name += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 if (IS_DIRECTORY_SEP (name[0]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
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 int slashes = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 name += 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
274 while (*name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 if (IS_DIRECTORY_SEP (name[0]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 if (pPath)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 *pPath = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 return name - start;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 /* Get long base name for name; name is assumed to be absolute. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
286 static Intbyte *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
287 get_long_basename (Intbyte *name)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
289 WIN32_FIND_DATAW find_data;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 HANDLE dir_handle;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
291 Extbyte *nameext;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
293 /* 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
294 if (qxestrpbrk (name, "*?|<>\""))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
295 return 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
297 C_STRING_TO_TSTR (name, nameext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
298 dir_handle = qxeFindFirstFile (nameext, &find_data);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 if (dir_handle != INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
301 Intbyte *fileint;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
302
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
303 TSTR_TO_C_STRING_MALLOC (find_data.cFileName, fileint);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 FindClose (dir_handle);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
305 return fileint;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
307 return 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 /* Get long name for file, if possible (assumed to be absolute). */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
311 Intbyte *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
312 mswindows_get_long_filename (Intbyte *name)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
314 Intbyte *full = mswindows_canonicalize_filename (name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
315 Intbyte *p;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
316 Intbyte *q;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
317 DECLARE_EISTRING (o);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
318 Bytecount len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 /* Copy root part verbatim. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 len = parse_root (full, &p);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
322 eicpy_raw (o, full, len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
324 while (p != NULL && *p)
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 Intbyte *component;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
327
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 q = p;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
329 p = qxestrchr (q, '\\');
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 if (p) *p = '\0';
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
331 component = get_long_basename (full);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
332 if (component)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
334 eicat_rawz (o, component);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 if (p != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 *p++ = '\\';
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
338 eicat_ch (o, '\\');
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
340 xfree (component);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 else
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
343 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
344 xfree (full);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
345 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
346 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
349 xfree (full);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
350 return eicpyout_malloc (o, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
353 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
354 is_unc_volume (const Intbyte *filename)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
355 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
356 const Intbyte *ptr = filename;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
358 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
359 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
360
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
361 if (qxestrpbrk (ptr + 2, "*?|<>\"\\/"))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
362 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
363
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
364 return 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
367 /* 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
368 convert. */
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 613
diff changeset
369 #define REG_ROOT "SOFTWARE\\XEmacs\\XEmacs"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
371 static LPBYTE
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
372 nt_get_resource (Intbyte *key, LPDWORD lpdwtype)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 LPBYTE lpvalue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 HKEY hrootkey = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 DWORD cbData;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
377 Extbyte *keyext;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
378
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
379 C_STRING_TO_TSTR (key, keyext);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 /* Check both the current user and the local machine to see if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 we have any resources. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
384 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
385 &hrootkey) == ERROR_SUCCESS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 lpvalue = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
389 if (qxeRegQueryValueEx (hrootkey, keyext, NULL, NULL, NULL,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
390 &cbData) == ERROR_SUCCESS
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
392 && qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
393 &cbData) == ERROR_SUCCESS)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
394 return (lpvalue);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 if (lpvalue) xfree (lpvalue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 RegCloseKey (hrootkey);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
401 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
402 &hrootkey) == ERROR_SUCCESS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 lpvalue = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
406 if (qxeRegQueryValueEx (hrootkey, keyext, NULL, NULL, NULL,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
407 &cbData) == ERROR_SUCCESS &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL &&
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
409 qxeRegQueryValueEx (hrootkey, keyext, NULL, lpdwtype, lpvalue,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
410 &cbData) == ERROR_SUCCESS)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
411 return (lpvalue);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 if (lpvalue) xfree (lpvalue);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 RegCloseKey (hrootkey);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 return (NULL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 }
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 void
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
422 init_mswindows_environment (void)
428
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 /* 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
425 /* 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
426 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
427 Emacs 20.6 messes with TMPDIR; not necessary here. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 LPBYTE lpval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 DWORD dwType;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
433 static Char_ASCII *env_vars[] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 "HOME",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 "EMACSLOADPATH",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 "EMACSDEBUGPATHS",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 "SHELL",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 "CMDPROXY",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 "EMACSDATA",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 "EMACSPATH",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 "EMACSPACKAGEPATH",
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
443 "EMACSLOCKMETHOD",
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 "INFOPATH"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 };
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
446 #if defined (HEAP_IN_DATA) && !defined (PDUMP)
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
447 cache_system_info ();
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
448 #endif
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
449
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
450 #if 0 /* FSF 21.1 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
451 /* !!#### i think i already do the equivalent elsewhere.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
452 delete when i'm sure i do.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
453 (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
454 the locale, so that subprocesses get it right.) */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
455 /* 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
456 if (GetLocaleInfo (LOCALE_USER_DEFAULT,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
457 LOCALE_SABBREVLANGNAME | LOCALE_USE_CP_ACP,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
458 locale_name, sizeof (locale_name)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
459 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
460 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
461 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
462 if (strcmp (env_vars[i].name, "LANG") == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
463 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
464 env_vars[i].def_value = locale_name;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
465 break;
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 }
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 #endif /* 0 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
470
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 for (i = 0; i < countof (env_vars); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
473 if (!egetenv (env_vars[i]) &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (lpval = nt_get_resource (env_vars[i], &dwType)) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 if (dwType == REG_EXPAND_SZ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
478 Extbyte *buf = NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
479 Intbyte *envval;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
480 Charcount cch;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
482 cch = qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, 0);
851
e7ee5f8bde58 [xemacs-hg @ 2002-05-23 11:46:08 by ben]
ben
parents: 819
diff changeset
483 buf = (Extbyte *) ALLOCA (cch * XETCHAR_SIZE);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
484 qxeExpandEnvironmentStrings ((Extbyte *) lpval, buf, cch);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
485 TSTR_TO_C_STRING (buf, envval);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
486 eputenv (env_vars[i], envval);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 else if (dwType == REG_SZ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
490 Intbyte *envval;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
491
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
492 TSTR_TO_C_STRING (lpval, envval);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
493 eputenv (env_vars[i], 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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 xfree (lpval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 /* Another special case: on NT, the PATH variable is actually named
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 "Path" although cmd.exe (perhaps NT itself) arranges for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 environment variable lookup and setting to be case insensitive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 However, Emacs assumes a fully case sensitive environment, so we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 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
506 various elisp packages.
428
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 The same applies to COMSPEC. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
510 Lisp_Object tail;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
512 EXTERNAL_LIST_LOOP (tail, Vprocess_environment)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
513 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
514 Lisp_Object str = XCAR (tail);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
515 if (STRINGP (str))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
516 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
517 Intbyte *dat = XSTRING_DATA (str);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
518 if (qxestrncasecmp (dat, "PATH=", 5) == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
519 memcpy (dat, "PATH=", 5);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
520 else if (qxestrncasecmp (dat, "COMSPEC=", 8) == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
521 memcpy (dat, "COMSPEC=", 8);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
522 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
523 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 init_user_info ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
529 /* 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
530 EMACS_CONFIGURATION. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 #ifndef HAVE_X_WINDOWS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 /* X11R6 on NT provides the single parameter version of this command. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 #include <sys/timeb.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 gettimeofday (struct timeval *tv, struct timezone *tz)
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 struct _timeb tb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 _ftime (&tb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 tv->tv_sec = tb.time;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 tv->tv_usec = tb.millitm * 1000L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 if (tz)
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 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 tz->tz_dsttime = tb.dstflag; /* type of dst correction */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 #endif /* HAVE_X_WINDOWS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
554
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 /* ------------------------------------------------------------------------- */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
556 /* IO support and wrapper functions for Win32 API. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 /* ------------------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
559 typedef struct volume_info_data
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
561 struct volume_info_data *next;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 /* time when info was obtained */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
564 DWORD timestamp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 /* actual volume info */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
567 Intbyte *root_dir;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
568 DWORD serialnum;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
569 DWORD maxcomp;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
570 DWORD flags;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
571 Intbyte *name;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
572 Intbyte *type;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 } volume_info_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 /* Global referenced by various functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 static volume_info_data volume_info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 /* Vector to indicate which drives are local and fixed (for which cached
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 data never expires). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 static BOOL fixed_drives[26];
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 /* Consider cached volume information to be stale if older than 10s,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 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
584 #define DRIVE_INDEX( c ) ( (c) <= 'Z' ? (c) - 'A' : (c) - 'a' )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 #define VOLINFO_STILL_VALID( root_dir, info ) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 ( ( isalpha (root_dir[0]) && \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 fixed_drives[ DRIVE_INDEX (root_dir[0]) ] ) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 || GetTickCount () - info->timestamp < 10000 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 /* Cache support functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 /* Simple linked list with linear search is sufficient. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 static volume_info_data *volume_cache = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 static volume_info_data *
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
596 lookup_volume_info (Intbyte *root_dir)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
598 volume_info_data *info;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 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
601 if (qxestrcasecmp_i18n (info->root_dir, root_dir) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 return info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 static void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
607 add_volume_info (Intbyte *root_dir, volume_info_data *info)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
609 info->root_dir = qxestrdup (root_dir);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 info->next = volume_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 volume_cache = info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 /* Wrapper for GetVolumeInformation, which uses caching to avoid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 performance penalty (~2ms on 486 for local drives, 7.5ms for local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 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
618 static volume_info_data *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
619 get_cached_volume_information (Intbyte *root_dir)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
621 volume_info_data *info;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
622 Intbyte *default_root;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 /* NULL for root_dir means use root from current directory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 if (root_dir == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
627 Charcount nchars = qxeGetCurrentDirectory (0, NULL);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
628 Extbyte *rootext;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
629
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
630 if (!nchars)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 return NULL;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
632 rootext = alloca_extbytes (nchars * XETCHAR_SIZE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
633 if (!qxeGetCurrentDirectory (nchars, rootext))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
634 return NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
635 TSTR_TO_C_STRING (rootext, default_root);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 parse_root (default_root, &root_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 *root_dir = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 root_dir = default_root;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 /* Local fixed drives can be cached permanently. Removable drives
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 cannot be cached permanently, since the volume name and serial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 number (if nothing else) can change. Remote drives should be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 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
645 tell whether they are or not. Also, the UNC association of drive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 letters mapped to remote volumes can be changed at any time (even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 by other processes) without notice.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 As a compromise, so we can benefit from caching info for remote
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 volumes, we use a simple expiry mechanism to invalidate cache
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 entries that are more than ten seconds old. */
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 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 /* No point doing this, because WNetGetConnection is even slower than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 GetVolumeInformation, consistently taking ~50ms on a 486 (FWIW,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 GetDriveType is about the only call of this type which does not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 involve network access, and so is extremely quick). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 /* Map drive letter to UNC if remote. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
660 if (isalpha (root_dir[0]) && !fixed [DRIVE_INDEX (root_dir[0])])
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
662 Extbyte remote_name[256 * XETCHAR_SIZE];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
663 Intbyte drive[3] = { root_dir[0], ':' };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
664 Extbyte *driveext;
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 C_STRING_TO_TSTR (drive, driveext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
667 if (qxeWNetGetConnection (driveext, remote_name,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
668 sizeof (remote_name) / XETCHAR_SIZE)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 == NO_ERROR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 /* do something */ ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 info = lookup_volume_info (root_dir);
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 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
677 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
678 Extbyte name[256 * MAX_XETCHAR_SIZE];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
679 DWORD serialnum;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
680 DWORD maxcomp;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
681 DWORD flags;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
682 Extbyte type[256 * MAX_XETCHAR_SIZE];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
684 /* Info is not cached, or is stale. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
685 if (!qxeGetVolumeInformation (root_dir,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
686 name, sizeof (name) / XETCHAR_SIZE,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
687 &serialnum,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
688 &maxcomp,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
689 &flags,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
690 type, sizeof (type) / XETCHAR_SIZE))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
691 return NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
693 /* 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
694 entry if present. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
695 if (info == NULL)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
696 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
697 info = (volume_info_data *) xmalloc (sizeof (volume_info_data));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
698 add_volume_info (root_dir, info);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
699 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
700 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
701 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
702 xfree (info->name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
703 xfree (info->type);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
704 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
706 TSTR_TO_C_STRING_MALLOC (name, info->name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
707 info->serialnum = serialnum;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
708 info->maxcomp = maxcomp;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
709 info->flags = flags;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
710 TSTR_TO_C_STRING_MALLOC (type, info->type);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
711 info->timestamp = GetTickCount ();
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
712 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 return info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 /* 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
718 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
719 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
720 get_volume_info (const Intbyte *name, const Intbyte **pPath)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
722 /* 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
723 case this function gets changed */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
724 Intbyte *temp = alloca_array (Intbyte, qxestrlen (name) + 10);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
725 Intbyte *rootname = NULL; /* default to current volume */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
726 volume_info_data *info;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 if (name == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 /* find the root name of the volume if given */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 if (isalpha (name[0]) && name[1] == ':')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 rootname = temp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 temp[0] = *name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 temp[1] = *name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 temp[2] = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 temp[3] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
742 Intbyte *str = temp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 int slashes = 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 rootname = temp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 do
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 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 *str++ = *name++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
751 while (*name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 *str++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 *str = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 if (pPath)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 *pPath = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
760 info = get_cached_volume_information (rootname);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 if (info != NULL)
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 /* Set global referenced by other functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 volume_info = *info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
770 /* 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
771 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
772 predates Windows 95!) */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
774 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
775 is_exec (const Intbyte *name)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
776 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
777 Intbyte *p = qxestrrchr (name, '.');
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
778 return (p != NULL && (qxestrcasecmp (p, ".exe") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
779 qxestrcasecmp (p, ".com") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
780 qxestrcasecmp (p, ".bat") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
781 qxestrcasecmp (p, ".cmd") == 0));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 /* Emulate the Unix directory procedures opendir, closedir,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 and readdir. We can't use the procedures supplied in sysdep.c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 so we provide them here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 struct direct dir_static; /* simulated directory contents */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 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
790 /* dir_is_fat deleted */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
791 static Intbyte *dir_pathname;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
792 static WIN32_FIND_DATAW dir_find_data;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
793
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
794 /* 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
795 root directory. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
796 static HANDLE wnet_enum_handle = INVALID_HANDLE_VALUE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
797 static HANDLE open_unc_volume (const Intbyte *);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
798 static Intbyte *read_unc_volume (HANDLE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
799 static int close_unc_volume (HANDLE);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 DIR *
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
802 mswindows_opendir (const Intbyte *filename)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 DIR *dirp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 /* Opening is done by FindFirstFile. However, a read is inherent to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 this operation, so we defer the open until read time. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
809 if (dir_find_handle != INVALID_HANDLE_VALUE)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 return NULL;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
811 if (wnet_enum_handle != INVALID_HANDLE_VALUE)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
814 if (is_unc_volume (filename))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
815 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
816 wnet_enum_handle = open_unc_volume (filename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
817 if (wnet_enum_handle == INVALID_HANDLE_VALUE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
818 return NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
819 }
428
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 (!(dirp = xnew_and_zero (DIR)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
822 return NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
823
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
824 if (dir_pathname)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
825 xfree (dir_pathname);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
826 dir_pathname = qxestrdup (filename);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 return dirp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
831 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
832 mswindows_closedir (DIR *dirp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
834 int retval;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
835
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 /* If we have a find-handle open, close it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 if (dir_find_handle != INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
839 retval = FindClose (dir_find_handle) ? 0 : -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 dir_find_handle = INVALID_HANDLE_VALUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
842 else if (wnet_enum_handle != INVALID_HANDLE_VALUE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
843 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
844 retval = close_unc_volume (wnet_enum_handle);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
845 wnet_enum_handle = INVALID_HANDLE_VALUE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
846 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 xfree (dirp);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
848
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
849 return retval;
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
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
852 struct direct *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
853 mswindows_readdir (DIR *dirp)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
854 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
855 Intbyte *val;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
856 int need_to_free = 0;
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 if (wnet_enum_handle != INVALID_HANDLE_VALUE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
859 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
860 if (!(val = read_unc_volume (wnet_enum_handle)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
861 return NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
862 need_to_free = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
863 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
864 /* 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
865 else if (dir_find_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 DECLARE_EISTRING (filename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
868 Emchar lastch;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
869
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
870 eicpy_rawz (filename, dir_pathname);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
871 lastch = eigetch_char (filename, eicharlen (filename) - 1);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
872 if (!IS_DIRECTORY_SEP (lastch))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
873 eicat_ch (filename, '\\');
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
874 eicat_ch (filename, '*');
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
875 eito_external (filename, Qmswindows_tstr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
876
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
877 dir_find_handle = qxeFindFirstFile (eiextdata (filename),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
878 &dir_find_data);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
879
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
880 if (dir_find_handle == INVALID_HANDLE_VALUE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
881 return NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
882 TSTR_TO_C_STRING (dir_find_data.cFileName, val);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
883 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
884 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
885 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
886 if (!qxeFindNextFile (dir_find_handle, &dir_find_data))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
887 return NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
888 TSTR_TO_C_STRING (dir_find_data.cFileName, val);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
889 }
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 /* 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
892 value returned by qxe_stat(). */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
893 dir_static.d_ino = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
894
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
895 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
896 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
897
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
898 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
899 DECLARE_EISTRING (found);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
900 Bytecount namlen;
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 eicpy_rawz (found, val);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
903 if (need_to_free)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
904 xfree (val);
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 if (!NILP (Vmswindows_downcase_file_names))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
907 eilwr (found);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
908
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
909 namlen = min (eilen (found), sizeof (dir_static.d_name) - 1);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
910 strncpy (dir_static.d_name, (char *) eidata (found), namlen);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
911 dir_static.d_name[namlen] = '\0';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
912 dir_static.d_namlen = (unsigned short) namlen;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
913 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
914
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
915 return &dir_static;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
916 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
917
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
918 static HANDLE
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
919 open_unc_volume (const Intbyte *path)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
920 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
921 NETRESOURCEW nr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
922 HANDLE henum;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
923 int result;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
924
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
925 nr.dwScope = RESOURCE_GLOBALNET;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
926 nr.dwType = RESOURCETYPE_DISK;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
927 nr.dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
928 nr.dwUsage = RESOURCEUSAGE_CONTAINER;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
929 nr.lpLocalName = NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
930 C_STRING_TO_TSTR (path, nr.lpRemoteName);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
931 nr.lpComment = NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
932 nr.lpProvider = NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
933
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
934 result = qxeWNetOpenEnum (RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
935 RESOURCEUSAGE_CONNECTABLE, &nr, &henum);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
936
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
937 if (result == NO_ERROR)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
938 return henum;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
939 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
940 return INVALID_HANDLE_VALUE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
941 }
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 static Intbyte *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
944 read_unc_volume (HANDLE henum)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
945 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
946 int count;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
947 int result;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
948 Extbyte buf[16384];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
949 Intbyte *ptr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
950 Bytecount bufsize = sizeof (buf);
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 count = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
953 /* #### 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
954 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
955
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
956 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
957 retrieve the required buffer size from the lpBufferSize
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
958 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
959 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
960 of lpBufferSize for error detection.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
961 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
962
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
963 result = qxeWNetEnumResource (wnet_enum_handle, &count, buf, &bufsize);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
964 if (result != NO_ERROR)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
965 return NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
966
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
967 /* WNetEnumResource returns \\resource\share...skip forward to "share". */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
968 TSTR_TO_C_STRING (((LPNETRESOURCEW) buf)->lpRemoteName, ptr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
969 INC_CHARPTR (ptr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
970 INC_CHARPTR (ptr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
971 while (*ptr && !IS_DIRECTORY_SEP (charptr_emchar (ptr)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
972 INC_CHARPTR (ptr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
973 INC_CHARPTR (ptr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
974
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
975 return qxestrdup (ptr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
976 }
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 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
979 close_unc_volume (HANDLE henum)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
980 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
981 if (henum != INVALID_HANDLE_VALUE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
982 return WNetCloseEnum (henum) == NO_ERROR ? 0 : -1;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
983 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
984 return -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
987 static DWORD
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
988 unc_volume_file_attributes (const Intbyte *path)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
990 HANDLE henum;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
991 DWORD attrs;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
992
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
993 henum = open_unc_volume (path);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
994 if (henum == INVALID_HANDLE_VALUE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
995 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
996
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
997 attrs = FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_DIRECTORY;
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 close_unc_volume (henum);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1001 return attrs;
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
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1004 int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1005 mswindows_access (const Intbyte *path, int mode)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1006 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1007 DWORD attributes;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1009 /* MSVC implementation doesn't recognize D_OK. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1010 if (is_unc_volume (path))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1011 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1012 attributes = unc_volume_file_attributes (path);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1013 if (attributes == -1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1014 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1015 errno = EACCES;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1016 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1017 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1021 Extbyte *pathext;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1022
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1023 C_STRING_TO_TSTR (path, pathext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1024 if ((attributes = qxeGetFileAttributes (pathext)) == -1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1025 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1026 /* 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
1027 that path doesn't exist. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1028 errno = EACCES;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1029 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1030 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1032 if ((mode & X_OK) != 0 && !is_exec (path))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1033 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1034 errno = EACCES;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1035 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1036 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1037 if ((mode & W_OK) != 0 && (attributes & FILE_ATTRIBUTE_READONLY) != 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1039 errno = EACCES;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1040 return -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1042 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
1043 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1044 errno = EACCES;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1045 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1046 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1047 return 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1050 /* 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
1051 /* #### 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
1052 and it may do more things. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1054 mswindows_link (const Intbyte *old, const Intbyte *new)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1056 HANDLE fileh;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1057 int result = -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1058
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1059 if (old == NULL || new == NULL)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1060 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1061 errno = ENOENT;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1062 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1063 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1064
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1065 C_STRING_TO_TSTR (old, old);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1066 fileh = qxeCreateFile (old, 0, 0, NULL, OPEN_EXISTING,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1067 FILE_FLAG_BACKUP_SEMANTICS, NULL);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1068 if (fileh != INVALID_HANDLE_VALUE)
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 int wlen;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1071 WCHAR *newuni;
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 /* 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
1074 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
1075 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
1076 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
1077 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
1078 stream data. */
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 struct
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1081 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1082 WIN32_STREAM_ID wid;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1083 WCHAR wbuffer[MAX_PATH]; /* extra space for link name */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1084 } data;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1085
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1086 TO_EXTERNAL_FORMAT (C_STRING, new,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1087 ALLOCA, (newuni, wlen), Qmswindows_unicode);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1088 if (wlen / sizeof (WCHAR) < MAX_PATH)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1089 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1090 LPVOID context = NULL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1091 DWORD wbytes = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1093 wcscpy (data.wid.cStreamName, newuni);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1094 data.wid.dwStreamId = BACKUP_LINK;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1095 data.wid.dwStreamAttributes = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1096 data.wid.Size.LowPart = wlen; /* in bytes, not chars! */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1097 data.wid.Size.HighPart = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1098 data.wid.dwStreamNameSize = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1099
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1100 if (BackupWrite (fileh, (LPBYTE)&data,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1101 offsetof (WIN32_STREAM_ID, cStreamName)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1102 + data.wid.Size.LowPart,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1103 &wbytes, FALSE, FALSE, &context)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1104 && BackupWrite (fileh, NULL, 0, &wbytes, TRUE, FALSE, &context))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1105 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1106 /* succeeded */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1107 result = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1108 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1109 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1110 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1111 /* 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
1112 indicate a general error (eg. links not supported). */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1113 errno = EINVAL; // perhaps EMLINK?
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1114 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1115 }
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 CloseHandle (fileh);
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 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1120 errno = ENOENT;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1121
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1122 return result;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1123 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1124
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1125 /* sys_open() merged into sysdep.c sys_open() */
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 int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1128 mswindows_rename (const Intbyte *oldname, const Intbyte *newname)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1129 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1130 int result;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1131 Intbyte *temp;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1132
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1133 /* 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
1134 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
1135 just by looking at oldname and newname, unfortunately). In these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 cases, renaming through a temporary name avoids the problem.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1138 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
1139 newname is uppercase fails (the final long name ends up in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 lowercase, although the short alias might be uppercase) UNLESS the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 long temp name is not 8.3.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1143 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
1144 the temp name has a long extension to ensure correct renaming. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1146 /* 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
1147 so the following calculation should certainly be enough. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1149 temp = qxestrcpy (alloca_intbytes (2 * qxestrlen (oldname) + 100), oldname);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1150
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1151 if (mswindows_windows9x_p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1153 Intbyte *o;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1154 Intbyte *p;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1155 int i = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1157 if (o = qxestrrchr (oldname, '\\'))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1158 o++;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1159 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1160 o = (Intbyte *) oldname;
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 if (p = qxestrrchr (temp, '\\'))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 p = temp;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1166
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1167 do
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1168 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1169 Extbyte *oldext, *tempext;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1170 /* 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
1171 seems to make the second rename work properly. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1172 qxesprintf (p, "_.%s.%u", o, i);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1173 i++;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1174 C_STRING_TO_EXTERNAL (oldname, oldext, Qfile_name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1175 C_STRING_TO_EXTERNAL (temp, tempext, Qfile_name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1176 result = rename (oldext, tempext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1177 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1178 /* This loop must surely terminate! */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1179 while (result < 0 && errno == EEXIST);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1180 if (result < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 }
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 /* Emulate Unix behaviour - newname is deleted if it already exists
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 (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
1186
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1187 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
1188 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
1189 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
1190 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
1191 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
1192 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
1193 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
1194 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1195 Extbyte *newext, *tempext;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1196
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1197 C_STRING_TO_EXTERNAL (newname, newext, Qfile_name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1198 C_STRING_TO_EXTERNAL (temp, tempext, Qfile_name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1199 result = rename (tempext, newext);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1201 if (result < 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1202 && errno == EEXIST
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1203 && _chmod (newext, 0666) == 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1204 && _unlink (newext) == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1205 result = rename (tempext, newext);
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
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1208 return result;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1209 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1211 int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1212 mswindows_unlink (const Intbyte *path)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1213 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1214 Extbyte *pathout;
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 C_STRING_TO_EXTERNAL (path, pathout, Qfile_name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1217 /* On Unix, unlink works without write permission. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1218 _chmod (pathout, 0666);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1219 return _unlink (pathout);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 static FILETIME utc_base_ft;
592
4f6ba8f1fb3d [xemacs-hg @ 2001-05-31 12:03:37 by adrian]
adrian
parents: 578
diff changeset
1223 static long double utc_base;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1224 static int init = 0;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1225 static LARGE_INTEGER utc_base_li;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1226
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1227 /* 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
1228 mswindows_convert_time(), although I'm not sure why. --ben */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 time_t
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1231 mswindows_convert_time (FILETIME uft)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1232 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1233 time_t ret;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1234 #ifndef MAXLONGLONG
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1235 SYSTEMTIME st;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1236 struct tm t;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1237 FILETIME ft;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1238 TIME_ZONE_INFORMATION tzi;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1239 DWORD tzid;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1240 #else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1241 LARGE_INTEGER lft;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1242 #endif
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1243
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1244 if (!init)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1245 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1246 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1247 SYSTEMTIME st;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1248
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1249 st.wYear = 1970;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1250 st.wMonth = 1;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1251 st.wDay = 1;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1252 st.wHour = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1253 st.wMinute = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1254 st.wSecond = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1255 st.wMilliseconds = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1256
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1257 SystemTimeToFileTime (&st, &utc_base_ft);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1258
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1259 utc_base_li.LowPart = utc_base_ft.dwLowDateTime;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1260 utc_base_li.HighPart = utc_base_ft.dwHighDateTime;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1261
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1262 init = 1;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1263 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1264
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1265 #ifdef MAXLONGLONG
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1266
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1267 /* 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
1268 lft.LowPart = uft.dwLowDateTime;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1269 lft.HighPart = uft.dwHighDateTime;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1270 ret = (time_t) ((lft.QuadPart - utc_base_li.QuadPart) / 10000000);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1271
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1272 #else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1273
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1274 /* Do it the hard way using mktime. */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1275 FileTimeToLocalFileTime(&uft, &ft);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1276 FileTimeToSystemTime (&ft, &st);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1277 tzid = GetTimeZoneInformation (&tzi);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1278 t.tm_year = st.wYear - 1900;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1279 t.tm_mon = st.wMonth - 1;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1280 t.tm_mday = st.wDay;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1281 t.tm_hour = st.wHour;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1282 t.tm_min = st.wMinute;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1283 t.tm_sec = st.wSecond;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1284 t.tm_isdst = (tzid == TIME_ZONE_ID_DAYLIGHT);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1285 /* st.wMilliseconds not applicable */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1286 ret = mktime(&t);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1287 if (ret == -1)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1288 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1289 ret = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1290 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1291
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1292 #endif
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1293
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1294 return ret;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1295 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1297 static void
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 convert_from_time_t (time_t time, FILETIME * pft)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 long double tmp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 if (!init)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 SYSTEMTIME st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 st.wYear = 1970;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 st.wMonth = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 st.wDay = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 st.wHour = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 st.wMinute = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 st.wSecond = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 st.wMilliseconds = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 SystemTimeToFileTime (&st, &utc_base_ft);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 utc_base = (long double) utc_base_ft.dwHighDateTime
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 init = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 /* time in 100ns units since 1-Jan-1601 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 tmp = (long double) time * 1e7 + utc_base;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 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
1324 pft->dwLowDateTime = (DWORD) (tmp - (4096.0 * 1024 * 1024) *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1325 pft->dwHighDateTime);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 #if 0
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1329 /* A comment from Emacs 20.6:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1330
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1331 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
1332 using the file index from GetInformationByHandle, is not perfect and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 so by default Emacs doesn't use the inode values on Windows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 Instead, we now determine file-truename correctly (except for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 possible drive aliasing etc). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1337 /* 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
1338 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
1339 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1341 /* #### aichner@ecf.teradyne.com reported that with the library
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1342 provided stat/fstat, (file-exist "d:\\tmp\\") =>> nil,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1343 (file-exist "d:\\tmp") =>> t, when d:\tmp exists. Whenever
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1344 we opt to use non-encapsulated stat(), this should serve as
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1345 a compatibility test. --kkm */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
1346
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1347 /* 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
1348 file timestamps. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1349 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1350 mswindows_fstat (int desc, struct stat *buf)
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1351 {
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1352 HANDLE fh = (HANDLE) _get_osfhandle (desc);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1353 BY_HANDLE_FILE_INFORMATION info;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1354 DWORD fake_inode;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1355 int permission;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1356
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1357 switch (GetFileType (fh) & ~FILE_TYPE_REMOTE)
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1358 {
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1359 case FILE_TYPE_DISK:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1360 buf->st_mode = _S_IFREG;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1361 if (!GetFileInformationByHandle (fh, &info))
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1362 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1363 errno = EACCES;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1364 return -1;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1365 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1366 break;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1367 case FILE_TYPE_PIPE:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1368 buf->st_mode = _S_IFIFO;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1369 goto non_disk;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1370 case FILE_TYPE_CHAR:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1371 case FILE_TYPE_UNKNOWN:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1372 default:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1373 buf->st_mode = _S_IFCHR;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1374 non_disk:
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1375 memset (&info, 0, sizeof (info));
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1376 info.dwFileAttributes = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1377 info.ftCreationTime = utc_base_ft;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1378 info.ftLastAccessTime = utc_base_ft;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1379 info.ftLastWriteTime = utc_base_ft;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1380 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1381
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1382 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1383 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1384 buf->st_mode = _S_IFDIR;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1385 buf->st_nlink = 2; /* doesn't really matter */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1386 fake_inode = 0; /* this doesn't either I think */
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1387 }
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1388 else
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1389 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
1390 buf->st_nlink = (short) info.nNumberOfLinks;
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1391 /* 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
1392 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
1393 all the time (even then there are situations where it is
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1394 not unique). Reputedly, there are at most 48 bits of info
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1395 (on NTFS, presumably less on FAT). */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1396 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1397 }
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1398
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1399 /* 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
1400 if (sizeof (buf->st_ino) == 2)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
1401 buf->st_ino = (unsigned short) (fake_inode ^ (fake_inode >> 16));
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1402 else
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
1403 buf->st_ino = (unsigned short) fake_inode;
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1404
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1405 /* consider files to belong to current user */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1406 buf->st_uid = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1407 buf->st_gid = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1408
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1409 buf->st_dev = info.dwVolumeSerialNumber;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1410 buf->st_rdev = info.dwVolumeSerialNumber;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1411
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1412 buf->st_size = info.nFileSizeLow;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1413
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1414 /* Convert timestamps to Unix format. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1415 buf->st_mtime = mswindows_convert_time (info.ftLastWriteTime);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1416 buf->st_atime = mswindows_convert_time (info.ftLastAccessTime);
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1417 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
1418 buf->st_ctime = mswindows_convert_time (info.ftCreationTime);
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1419 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1420
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1421 /* determine rwx permissions */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1422 if (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1423 permission = _S_IREAD;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1424 else
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1425 permission = _S_IREAD | _S_IWRITE;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1426
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1427 if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1428 permission |= _S_IEXEC;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1429 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1430 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1431 #if 0 /* no way of knowing the filename */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1432 Intbyte *p = qxestrrchr (name, '.');
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1433 if (p != NULL &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1434 (qxestrcasecmp (p, ".exe") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1435 qxestrcasecmp (p, ".com") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1436 qxestrcasecmp (p, ".bat") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1437 qxestrcasecmp (p, ".cmd") == 0))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1438 permission |= _S_IEXEC;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1439 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1440 }
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1441
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1442 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1443
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 442
diff changeset
1444 return 0;
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1445 }
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
1446
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 /* 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
1448 replace it with our own. This also allows us to calculate consistent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 inode values without hacks in the main Emacs code. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1451 mswindows_stat (const Intbyte *path, struct stat *buf)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1453 Intbyte *name, *r;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1454 WIN32_FIND_DATAW wfd;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 HANDLE fh;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 DWORD fake_inode;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 int permission;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1458 Bytecount len;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 int rootdir = FALSE;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1460 Extbyte *nameext;
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 814
diff changeset
1461 int errm;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 if (path == NULL || buf == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 errno = EFAULT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1469 name = qxestrcpy (alloca_intbytes (qxestrlen (path) + 10), path);
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 814
diff changeset
1470 errm = SetErrorMode (SEM_FAILCRITICALERRORS
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 814
diff changeset
1471 | SEM_NOOPENFILEERRORBOX);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1472
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1473 get_volume_info (name, &path);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1474 /* 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
1475 if (qxestrpbrk (name, "*?|<>\""))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 errno = ENOENT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1481 /* 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
1482 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
1483 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
1484 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1485 r[1] = r[2] = '\0';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1486 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1487
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 /* Remove trailing directory separator, unless name is the root
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 directory of a drive or UNC volume in which case ensure there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 is a trailing separator. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1491 len = qxestrlen (name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 rootdir = (path >= name + len - 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 && (IS_DIRECTORY_SEP (*path) || *path == 0));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1494
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1495 if (is_unc_volume (name))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1496 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1497 DWORD attrs = unc_volume_file_attributes (name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1498
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1499 if (attrs == -1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1500 return -1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1502 memset (&wfd, 0, sizeof (wfd));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1503 wfd.dwFileAttributes = attrs;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1504 wfd.ftCreationTime = utc_base_ft;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1505 wfd.ftLastAccessTime = utc_base_ft;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1506 wfd.ftLastWriteTime = utc_base_ft;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1507 /* XEmacs deleted: strcpy (wfd.cFileName, name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1508 Not used later on. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1509 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1510 else if (rootdir)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 if (!IS_DIRECTORY_SEP (name[len-1]))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1513 qxestrcat (name, (Intbyte *) "\\");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1514 C_STRING_TO_TSTR (name, nameext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1515 if (qxeGetDriveType (nameext) < 2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 {
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 814
diff changeset
1517 SetErrorMode (errm);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 errno = ENOENT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 memset (&wfd, 0, sizeof (wfd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 wfd.ftCreationTime = utc_base_ft;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 wfd.ftLastAccessTime = utc_base_ft;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 wfd.ftLastWriteTime = utc_base_ft;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1526 /* XEmacs deleted: strcpy (wfd.cFileName, name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1527 Not used later on. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 else
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 if (IS_DIRECTORY_SEP (name[len-1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 name[len - 1] = 0;
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 /* (This is hacky, but helps when doing file completions on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 network drives.) Optimize by using information available from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 active readdir if possible. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1537 if (dir_pathname)
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 len = qxestrlen (dir_pathname);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1540 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
1541 len--;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1542 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1543 if (dir_find_handle != INVALID_HANDLE_VALUE
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1544 && dir_pathname
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 771
diff changeset
1545 && qxestrncasecmp_i18n (dir_pathname, name, len) == 0
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1546 && IS_DIRECTORY_SEP (name[len])
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1547 && qxestrcasecmp_i18n (name + len + 1,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1548 (Intbyte *) dir_static.d_name) == 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 /* This was the last entry returned by readdir. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 wfd = dir_find_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1555 C_STRING_TO_TSTR (name, nameext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1556 fh = qxeFindFirstFile (nameext, &wfd);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1557 if (fh == INVALID_HANDLE_VALUE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1558 {
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 814
diff changeset
1559 SetErrorMode (errm);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1560 errno = ENOENT;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1561 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1562 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1563 FindClose (fh);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1564 /* 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
1565 not used later on. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 buf->st_mode = _S_IFDIR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 buf->st_nlink = 2; /* doesn't really matter */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 fake_inode = 0; /* this doesn't either I think */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1575 else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1577 if (!NILP (Vmswindows_get_true_file_attributes))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1578 C_STRING_TO_TSTR (name, nameext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1579 if (!NILP (Vmswindows_get_true_file_attributes)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1580 /* No access rights required to get info. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1581 && (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
1582 != INVALID_HANDLE_VALUE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1583 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1584 /* This is more accurate in terms of gettting the correct number
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1585 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
1586 making a list of file name completions). */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1587 BY_HANDLE_FILE_INFORMATION info;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1589 if (GetFileInformationByHandle (fh, &info))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1590 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1591 buf->st_nlink = (short) info.nNumberOfLinks;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1592 /* 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
1593 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
1594 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
1595 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
1596 (on NTFS, presumably less on FAT). */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1597 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh;
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 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1600 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1601 buf->st_nlink = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1602 fake_inode = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1603 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 switch (GetFileType (fh))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 case FILE_TYPE_DISK:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 buf->st_mode = _S_IFREG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 case FILE_TYPE_PIPE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 buf->st_mode = _S_IFIFO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 case FILE_TYPE_CHAR:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 case FILE_TYPE_UNKNOWN:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 buf->st_mode = _S_IFCHR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 CloseHandle (fh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1622 /* 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
1623 buf->st_mode = _S_IFREG;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1624 buf->st_nlink = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1625 fake_inode = 0;
428
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628
819
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 814
diff changeset
1629 SetErrorMode (errm);
6504113e7c2d [xemacs-hg @ 2002-04-25 18:03:23 by andyp]
andyp
parents: 814
diff changeset
1630
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 #if 0
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1632 /* 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
1633 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
1634 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1636 /* 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
1637 if (sizeof (buf->st_ino) == 2)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1638 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
1639 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1640 buf->st_ino = (unsigned short) fake_inode;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 /* consider files to belong to current user */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1643 buf->st_uid = the_passwd.pw_uid;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1644 buf->st_gid = the_passwd.pw_gid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1646 /* volume_info is set by get_volume_info */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 buf->st_dev = volume_info.serialnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 buf->st_rdev = volume_info.serialnum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1650
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 buf->st_size = wfd.nFileSizeLow;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 /* Convert timestamps to Unix format. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1654 buf->st_mtime = mswindows_convert_time (wfd.ftLastWriteTime);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1655 buf->st_atime = mswindows_convert_time (wfd.ftLastAccessTime);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 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
1657 buf->st_ctime = mswindows_convert_time (wfd.ftCreationTime);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 /* determine rwx permissions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 permission = _S_IREAD;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 permission = _S_IREAD | _S_IWRITE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 permission |= _S_IEXEC;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1668 else if (is_exec (name))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1669 permission |= _S_IEXEC;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1677 mswindows_utime (Lisp_Object path, struct utimbuf *times)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1679 /* #### Supposedly we're providing this because standard utime()
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1680 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
1681 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
1682 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
1683 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
1684 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
1685 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
1686 and so far no problems seen. --ben */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1688 struct utimbuf deftime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1689 #if 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1690 HANDLE fh;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1691 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1692 static FILETIME mtime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1693 static FILETIME atime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1694 Extbyte *filename;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1696 if (times == NULL)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1698 deftime.modtime = deftime.actime = time (NULL);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1699 times = &deftime;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1702 LISP_STRING_TO_TSTR (path, filename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1703 /* 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
1704 #if 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1705 /* Need write access to set times. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1706 fh = qxeCreateFile (filename, GENERIC_WRITE,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1707 FILE_SHARE_READ | FILE_SHARE_WRITE,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1708 0, OPEN_EXISTING, 0, NULL);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1709 if (fh)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1710 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1711 convert_from_time_t (times->actime, &atime);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1712 convert_from_time_t (times->modtime, &mtime);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1713 if (!SetFileTime (fh, NULL, &atime, &mtime))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1714 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1715 CloseHandle (fh);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1716 errno = EACCES;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1717 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1718 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1719 CloseHandle (fh);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1720 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1721 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1722 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1723 errno = EINVAL;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1724 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1725 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1726 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1727 #else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1728 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1729 struct _utimbuf newtimes;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1730
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1731 newtimes.actime = times->actime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1732 newtimes.modtime = times->modtime;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1733
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1734 if (XEUNICODE_P)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1735 return _wutime ((const wchar_t *) filename, &newtimes);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1736 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1737 return _utime (filename, &newtimes);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1738 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1739 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1740 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1741
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1742 Intbyte *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1743 mswindows_getdcwd (int drivelet)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1744 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1745 Extbyte *cwdext;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1746 Intbyte *cwd;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1747
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1748 if (XEUNICODE_P)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1749 cwdext = (Extbyte *) _wgetdcwd (drivelet, NULL, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1750 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1751 cwdext = _getdcwd (drivelet, NULL, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1752 TSTR_TO_C_STRING_MALLOC (cwdext, cwd);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1753 xfree (cwdext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1754 return cwd;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1757
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1758 /*--------------------------------------------------------------------*/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1759 /* Memory-mapped files */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1760 /*--------------------------------------------------------------------*/
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1761
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1763 open_input_file (file_data *p_file, const Intbyte *filename)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1765 /* Synched with FSF 20.6. We fixed some warnings. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 HANDLE file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 HANDLE file_mapping;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1768 void *file_base;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 DWORD size, upper_size;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1770 Extbyte *fileext;
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 C_STRING_TO_TSTR (filename, fileext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1773
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1774 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
1775 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 if (file == INVALID_HANDLE_VALUE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 size = GetFileSize (file, &upper_size);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1780 file_mapping = qxeCreateFileMapping (file, NULL, PAGE_READONLY,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1781 0, size, NULL);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 if (!file_mapping)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 if (file_base == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 return FALSE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1789 p_file->name = filename;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1790 p_file->size = size;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1791 p_file->file = file;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1792 p_file->file_mapping = file_mapping;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1793 p_file->file_base = file_base;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1794
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1795 return TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1796 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1797
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1798 int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1799 open_output_file (file_data *p_file, const Intbyte *filename,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1800 unsigned long size)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1801 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1802 /* Synched with FSF 20.6. We fixed some warnings. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1803 HANDLE file;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1804 HANDLE file_mapping;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1805 void *file_base;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1806 Extbyte *fileext;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1807
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1808 C_STRING_TO_TSTR (filename, fileext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1809
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1810 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
1811 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1812 if (file == INVALID_HANDLE_VALUE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1813 return FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1814
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1815 file_mapping = qxeCreateFileMapping (file, NULL, PAGE_READWRITE,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1816 0, size, NULL);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1817 if (!file_mapping)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1818 return FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1819
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1820 file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1821 if (file_base == NULL)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1822 return FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1823
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1824 p_file->name = filename;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 p_file->size = size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 p_file->file = file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 p_file->file_mapping = file_mapping;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1828 p_file->file_base = file_base;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 return TRUE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1833 #if 1 /* !defined(MINGW) */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1834 /* Return pointer to section header for section containing the given
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1835 relative virtual address. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1836 static IMAGE_SECTION_HEADER *
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1837 rva_to_section (DWORD rva, IMAGE_NT_HEADERS *nt_header)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1838 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1839 /* Synched with FSF 20.6. We added MINGW stuff. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1840 PIMAGE_SECTION_HEADER section;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1841 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1842
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1843 section = IMAGE_FIRST_SECTION (nt_header);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1844
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1845 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1846 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1847 /* Some linkers (eg. the NT SDK linker I believe) swapped the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1848 meaning of these two values - or rather, they ignored
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1849 VirtualSize entirely and always set it to zero. This affects
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1850 some very old exes (eg. gzip dated Dec 1993). Since
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1851 mswindows_executable_type relies on this function to work reliably,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1852 we need to cope with this. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1853 DWORD real_size = max (section->SizeOfRawData,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1854 section->Misc.VirtualSize);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1855 if (rva >= section->VirtualAddress
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1856 && rva < section->VirtualAddress + real_size)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1857 return section;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1858 section++;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1859 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1860 return NULL;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1861 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1862 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1863
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1864 void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1865 mswindows_executable_type (const Intbyte *filename, int *is_dos_app,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1866 int *is_cygnus_app)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1867 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1868 /* Synched with FSF 20.6. We added MINGW stuff and casts. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1869 file_data executable;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1870 Intbyte *p;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1871
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1872 /* Default values in case we can't tell for sure. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1873 *is_dos_app = FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1874 *is_cygnus_app = FALSE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1875
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1876 if (!open_input_file (&executable, filename))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1877 return;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1878
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1879 p = qxestrrchr (filename, '.');
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1880
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1881 /* We can only identify DOS .com programs from the extension. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1882 if (p && qxestrcasecmp (p, ".com") == 0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1883 *is_dos_app = TRUE;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1884 else if (p && (qxestrcasecmp (p, ".bat") == 0 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1885 qxestrcasecmp (p, ".cmd") == 0))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1886 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1887 /* A DOS shell script - it appears that CreateProcess is happy to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1888 accept this (somewhat surprisingly); presumably it looks at
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1889 COMSPEC to determine what executable to actually invoke.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1890 Therefore, we have to do the same here as well. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1891 /* Actually, I think it uses the program association for that
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1892 extension, which is defined in the registry. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1893 p = egetenv ("COMSPEC");
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1894 if (p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1895 mswindows_executable_type (p, is_dos_app, is_cygnus_app);
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 else
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1898 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1899 /* 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
1900 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
1901 start with a DOS program stub. Note that 16-bit Windows
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1902 executables use the OS/2 1.x format. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1903
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1904 #if 0 /* defined( MINGW ) */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1905 /* mingw doesn't have enough headers to detect cygwin
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1906 apps, just do what we can. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1907 FILHDR *exe_header;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1908
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1909 exe_header = (FILHDR *) executable.file_base;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1910 if (exe_header->e_magic != DOSMAGIC)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1911 goto unwind;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1912
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1913 if ((char *) exe_header->e_lfanew > (char *) executable.size)
442
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 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1916 *is_dos_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1917 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1918 else if (exe_header->nt_signature != NT_SIGNATURE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1919 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1920 *is_dos_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1921 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1922 #else
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1923 IMAGE_DOS_HEADER *dos_header;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1924 IMAGE_NT_HEADERS *nt_header;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1925
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1926 dos_header = (PIMAGE_DOS_HEADER) executable.file_base;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1927 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1928 goto unwind;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1929
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1930 nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header +
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1931 dos_header->e_lfanew);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1932
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1933 if ((char *) nt_header > (char *) dos_header + executable.size)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1934 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1935 /* Some dos headers (pkunzip) have bogus e_lfanew fields. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1936 *is_dos_app = TRUE;
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 else if (nt_header->Signature != IMAGE_NT_SIGNATURE &&
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1939 LOWORD (nt_header->Signature) != IMAGE_OS2_SIGNATURE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1940 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1941 *is_dos_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1942 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1943 else if (nt_header->Signature == IMAGE_NT_SIGNATURE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1944 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1945 /* Look for cygwin.dll in DLL import list. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1946 IMAGE_DATA_DIRECTORY import_dir =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1947 nt_header->OptionalHeader.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1948 DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1949 IMAGE_IMPORT_DESCRIPTOR *imports;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1950 IMAGE_SECTION_HEADER *section;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1951
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1952 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
1953 imports =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1954 (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
1955 section, executable);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1956
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1957 for ( ; imports->Name; imports++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1958 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1959 Extbyte *dllname_ext =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1960 (Extbyte *) RVA_TO_PTR (imports->Name, section, executable);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1961 Intbyte *dllname;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1962
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1963 EXTERNAL_TO_C_STRING (dllname_ext, dllname, Qbinary);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1964
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1965 /* The exact name of the cygwin dll has changed with
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1966 various releases, but hopefully this will be reasonably
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1967 future proof. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1968 if (qxestrncasecmp (dllname, (Intbyte *) "cygwin", 6) == 0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1969 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1970 *is_cygnus_app = TRUE;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1971 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1972 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1973 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1974 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1975 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1976 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1977
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1978 unwind:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1979 close_file_data (&executable);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1980 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1981
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 /* Close the system structures associated with the given file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 close_file_data (file_data *p_file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 {
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 605
diff changeset
1986 UnmapViewOfFile (p_file->file_base);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 605
diff changeset
1987 CloseHandle (p_file->file_mapping);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 605
diff changeset
1988 CloseHandle (p_file->file);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1991
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1992 /* 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
1993 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
1994
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1995 DEFUN ("mswindows-short-file-name", Fmswindows_short_file_name, 1, 1, "", /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1996 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
1997 If FILENAME does not exist, return nil.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
1998 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
1999 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2000 (filename))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2001 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2002 Extbyte shortname[MAX_PATH * MAX_XETCHAR_SIZE];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2003 Extbyte *fileext;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2004 Intbyte *shortint;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2005
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2006 CHECK_STRING (filename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2007
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2008 /* first expand it. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2009 filename = Fexpand_file_name (filename, Qnil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2010
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2011 LISP_STRING_TO_TSTR (filename, fileext);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2012 /* 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
2013 if (qxeGetShortPathName (fileext, shortname,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2014 sizeof (shortname) / XETCHAR_SIZE) == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2015 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2016
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2017 TSTR_TO_C_STRING (shortname, shortint);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2018 MSWINDOWS_NORMALIZE_FILENAME (shortint);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2019
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2020 return build_string (shortint);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2021 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2022
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2023
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2024 DEFUN ("mswindows-long-file-name", Fmswindows_long_file_name, 1, 1, "", /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2025 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
2026 If FILENAME does not exist, return nil.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2027 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
2028 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2029 (filename))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2030 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2031 Intbyte *longname, *canon;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2032 Lisp_Object ret;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2033
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2034 CHECK_STRING (filename);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2035
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2036 /* first expand it. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2037 filename = Fexpand_file_name (filename, Qnil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2038
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2039 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
2040 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2041
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2042 canon = mswindows_canonicalize_filename (longname);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2043 ret = build_string (canon);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2044 xfree (canon);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2045 xfree (longname);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2046 return ret;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2047 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2048
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2049
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2050 void
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2051 init_nt (void)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2052 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2053 /* Initial preparation for subprocess support: replace our standard
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2054 handles with non-inheritable versions.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2055
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2056 #### 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
2057 support. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2058 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2059 HANDLE parent;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2060 HANDLE stdin_save = INVALID_HANDLE_VALUE;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2061 HANDLE stdout_save = INVALID_HANDLE_VALUE;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2062 HANDLE stderr_save = INVALID_HANDLE_VALUE;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2063
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2064 parent = GetCurrentProcess ();
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2065
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2066 /* ignore errors when duplicating and closing; typically the
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2067 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
2068 DuplicateHandle (parent,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2069 GetStdHandle (STD_INPUT_HANDLE),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2070 parent,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2071 &stdin_save,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2072 0,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2073 FALSE,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2074 DUPLICATE_SAME_ACCESS);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2075
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2076 DuplicateHandle (parent,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2077 GetStdHandle (STD_OUTPUT_HANDLE),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2078 parent,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2079 &stdout_save,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2080 0,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2081 FALSE,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2082 DUPLICATE_SAME_ACCESS);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2083
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2084 DuplicateHandle (parent,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2085 GetStdHandle (STD_ERROR_HANDLE),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2086 parent,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2087 &stderr_save,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2088 0,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2089 FALSE,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2090 DUPLICATE_SAME_ACCESS);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2091
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2092 retry_fclose (stdin);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2093 retry_fclose (stdout);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2094 retry_fclose (stderr);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2095
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2096 if (stdin_save != INVALID_HANDLE_VALUE)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2097 _open_osfhandle ((long) stdin_save, O_TEXT);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2098 else
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2099 _open ("nul", O_TEXT | O_NOINHERIT | O_RDONLY);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2100 _fdopen (0, "r");
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2101
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2102 if (stdout_save != INVALID_HANDLE_VALUE)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2103 _open_osfhandle ((long) stdout_save, O_TEXT);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2104 else
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2105 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2106 _fdopen (1, "w");
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2107
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2108 if (stderr_save != INVALID_HANDLE_VALUE)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2109 _open_osfhandle ((long) stderr_save, O_TEXT);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2110 else
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2111 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2112 _fdopen (2, "w");
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2113 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2114
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2115 /* 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
2116 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2117 /* GetDriveType must have trailing backslash. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2118 Intbyte drive[] = "A:\\";
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2119
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2120 /* Loop over all possible drive letters */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2121 while (*drive <= 'Z')
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2122 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2123 Extbyte *driveext;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2124
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2125 C_STRING_TO_TSTR (drive, driveext);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2126
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2127 /* 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
2128 fixed_drives[DRIVE_INDEX (*drive)] =
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2129 (qxeGetDriveType (driveext) == DRIVE_FIXED);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2130
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2131 (*drive)++;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2132 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2133
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2134 /* Reset the volume info cache. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2135 volume_cache = NULL;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2136 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2137 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2138
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2139 void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2140 syms_of_nt (void)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2141 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2142 DEFSUBR (Fmswindows_short_file_name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2143 DEFSUBR (Fmswindows_long_file_name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2144 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2145
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2146 void
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2147 vars_of_nt (void)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2148 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2149 DEFVAR_INT ("mswindows-fake-unix-uid", &mswindows_fake_unix_uid /*
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2150 *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
2151 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
2152 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
2153 Changes to this variable take effect immediately.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2154 */ );
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2155 mswindows_fake_unix_uid = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2156
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2157 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
2158 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
2159 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
2160 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
2161 where hard links are supported.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2162 */ );
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 707
diff changeset
2163 Vmswindows_get_true_file_attributes = Qnil;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2164 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 436
diff changeset
2165
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 /* end of nt.c */