Mercurial > emacs
annotate src/w32.c @ 14474:799da4d5aeb7
(with-electric-help):
Bind inhibit-read-only around the erase-buffer.
(electric-help-form-to-execute): Renamed from to-be-executed.
Add defvar for it.
(electric-help-mode): Turn off view-mode.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 03 Feb 1996 03:18:00 +0000 |
parents | ebdd1b50daba |
children | 8d25697cc14b |
rev | line source |
---|---|
9803 | 1 /* Utility and Unix shadow routines for GNU Emacs on Windows NT. |
11384 | 2 Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
9803 | 3 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
4 This file is part of GNU Emacs. |
9803 | 5 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
6 GNU Emacs is free software; you can redistribute it and/or modify |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
7 it under the terms of the GNU General Public License as published by |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
9 any later version. |
9803 | 10 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
11 GNU Emacs is distributed in the hope that it will be useful, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
14 GNU General Public License for more details. |
9803 | 15 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
17 along with GNU Emacs; see the file COPYING. If not, write to |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
13932
diff
changeset
|
19 Boston, MA 02111-1307, USA. |
9803 | 20 |
21 Geoff Voelker (voelker@cs.washington.edu) 7-29-94 | |
22 */ | |
23 | |
14246
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
24 |
11384 | 25 /* Define stat before including config.h. */ |
26 #include <string.h> | |
27 #include <sys/stat.h> | |
14246
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
28 #include <malloc.h> |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
29 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
30 static int is_toplevel_share_name (char *); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
31 static int stat_toplevel_share (char *, void *); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
32 |
11384 | 33 int |
34 nt_stat (char *filename, struct stat *statbuf) | |
35 { | |
14246
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
36 int l = strlen (filename); |
11384 | 37 char *str = NULL; |
38 | |
39 /* stat has a bug when passed a name of a directory with a trailing | |
40 backslash (but a trailing forward slash works fine). */ | |
41 if (filename[l - 1] == '\\') | |
42 { | |
14246
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
43 str = (char *) alloca (l + 1); |
11384 | 44 strcpy (str, filename); |
45 str[l - 1] = '/'; | |
14246
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
46 return stat (str, statbuf); |
11384 | 47 } |
14246
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
48 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
49 if (stat (filename, statbuf) == 0) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
50 return 0; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
51 else if (is_toplevel_share_name (filename)) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
52 return stat_toplevel_share (filename, statbuf); |
11384 | 53 else |
14246
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
54 return -1; |
11384 | 55 } |
56 | |
57 /* Place a wrapper around the NT version of ctime. It returns NULL | |
58 on network directories, so we handle that case here. | |
59 Define it before including config.h. (Ulrich Leodolter, 1/11/95). */ | |
60 char * | |
61 nt_ctime (const time_t *t) | |
62 { | |
63 char *str = (char *) ctime (t); | |
64 return (str ? str : "Sun Jan 01 00:00:00 1970"); | |
65 } | |
66 | |
12183
47685fb0fbd1
Include config.h before stdio.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12025
diff
changeset
|
67 #include <config.h> |
9803 | 68 #include <windows.h> |
69 #include <stdlib.h> | |
70 #include <stdio.h> | |
71 #include <io.h> | |
72 #include <fcntl.h> | |
73 #include <ctype.h> | |
74 | |
75 #define getwd _getwd | |
76 #include "lisp.h" | |
77 #undef getwd | |
78 | |
79 #include <pwd.h> | |
80 | |
81 #include "ndir.h" | |
82 #include "ntheap.h" | |
83 | |
84 extern int report_file_error (char *, Lisp_Object); | |
85 | |
14246
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
86 /* Routines for extending stat above. */ |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
87 static int |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
88 get_unassigned_drive_letter () |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
89 { |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
90 int i; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
91 unsigned int mask; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
92 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
93 mask = GetLogicalDrives (); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
94 for (i = 0; i < 26; i++) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
95 { |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
96 if (mask & (1 << i)) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
97 continue; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
98 break; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
99 } |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
100 return (i == 26 ? -1 : 'A' + i); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
101 } |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
102 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
103 void dostounix_filename (char *); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
104 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
105 /* Return nonzero if NAME is of the form \\host\share (forward slashes |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
106 also valid), otherwise return 0. */ |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
107 static int |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
108 is_toplevel_share_name (char *filename) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
109 { |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
110 int len; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
111 char *name; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
112 char *host; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
113 char *share; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
114 char *suffix; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
115 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
116 len = strlen (filename); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
117 name = alloca (len + 1); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
118 strcpy (name, filename); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
119 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
120 dostounix_filename (name); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
121 if (name[0] != '/' || name[1] != '/') |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
122 return 0; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
123 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
124 host = strtok (&name[2], "/"); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
125 share = strtok (NULL, "/"); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
126 suffix = strtok (NULL, "/"); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
127 if (!host || !share || suffix) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
128 return 0; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
129 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
130 return 1; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
131 } |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
132 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
133 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
134 /* FILENAME is of the form \\host\share, and stat can't handle names |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
135 of this form. But stat can handle \\host\share if it's been |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
136 assigned a drive letter. So we create a network connection to this |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
137 share, assign it a drive letter, stat the drive letter, and |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
138 disconnect from the share. Hassle... */ |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
139 static int |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
140 stat_toplevel_share (char *filename, void *statbuf) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
141 { |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
142 NETRESOURCE net; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
143 int drive_letter; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
144 char drive[4]; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
145 int result; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
146 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
147 drive_letter = get_unassigned_drive_letter (); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
148 if (drive_letter < 0) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
149 return -1; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
150 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
151 drive[0] = drive_letter; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
152 drive[1] = ':'; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
153 drive[2] = '\0'; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
154 net.dwType = RESOURCETYPE_DISK; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
155 net.lpLocalName = drive; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
156 net.lpRemoteName = filename; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
157 net.lpProvider = NULL; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
158 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
159 switch (WNetAddConnection2 (&net, NULL, NULL, 0)) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
160 { |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
161 case NO_ERROR: |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
162 break; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
163 case ERROR_ALREADY_ASSIGNED: |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
164 default: |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
165 return -1; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
166 } |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
167 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
168 /* Name the toplevel directory on the drive letter. */ |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
169 drive[2] = '/'; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
170 drive[3] = '\0'; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
171 result = stat (drive, (void *) statbuf); |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
172 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
173 /* Strip the slash so we can disconnect. */ |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
174 drive[2] = '\0'; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
175 if (WNetCancelConnection2 (drive, 0, TRUE) != NO_ERROR) |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
176 result = -1; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
177 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
178 return result; |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
179 } |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
180 |
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
181 |
9803 | 182 /* Get the current working directory. */ |
183 int | |
184 getwd (char *dir) | |
185 { | |
186 return GetCurrentDirectory (MAXPATHLEN, dir); | |
187 } | |
188 | |
189 /* Emulate gethostname. */ | |
190 int | |
191 gethostname (char *buffer, int size) | |
192 { | |
193 /* NT only allows small host names, so the buffer is | |
194 certainly large enough. */ | |
195 return !GetComputerName (buffer, &size); | |
196 } | |
197 | |
198 /* Emulate getloadavg. */ | |
199 int | |
200 getloadavg (double loadavg[], int nelem) | |
201 { | |
202 int i; | |
203 | |
204 /* A faithful emulation is going to have to be saved for a rainy day. */ | |
205 for (i = 0; i < nelem; i++) | |
206 { | |
207 loadavg[i] = 0.0; | |
208 } | |
209 return i; | |
210 } | |
211 | |
212 /* Emulate sleep...we could have done this with a define, but that | |
213 would necessitate including windows.h in the files that used it. | |
214 This is much easier. */ | |
215 void | |
216 nt_sleep (int seconds) | |
217 { | |
218 Sleep (seconds * 1000); | |
219 } | |
220 | |
221 /* Emulate the Unix directory procedures opendir, closedir, | |
222 and readdir. We can't use the procedures supplied in sysdep.c, | |
223 so we provide them here. */ | |
224 | |
225 struct direct dir_static; /* simulated directory contents */ | |
226 static int dir_finding; | |
227 static HANDLE dir_find_handle; | |
228 | |
229 DIR * | |
230 opendir (char *filename) | |
231 { | |
232 DIR *dirp; | |
233 | |
234 /* Opening is done by FindFirstFile. However, a read is inherent to | |
235 this operation, so we have a flag to handle the open at read | |
236 time. This flag essentially means "there is a find-handle open and | |
237 it needs to be closed." */ | |
238 | |
239 if (!(dirp = (DIR *) malloc (sizeof (DIR)))) | |
240 { | |
241 return 0; | |
242 } | |
243 | |
244 dirp->dd_fd = 0; | |
245 dirp->dd_loc = 0; | |
246 dirp->dd_size = 0; | |
247 | |
248 /* This is tacky, but we need the directory name for our | |
249 implementation of readdir. */ | |
250 strncpy (dirp->dd_buf, filename, DIRBLKSIZ); | |
251 return dirp; | |
252 } | |
253 | |
254 void | |
255 closedir (DIR *dirp) | |
256 { | |
257 /* If we have a find-handle open, close it. */ | |
258 if (dir_finding) | |
259 { | |
260 FindClose (dir_find_handle); | |
261 dir_finding = 0; | |
262 } | |
263 xfree ((char *) dirp); | |
264 } | |
265 | |
266 struct direct * | |
267 readdir (DIR *dirp) | |
268 { | |
269 WIN32_FIND_DATA find_data; | |
270 | |
271 /* If we aren't dir_finding, do a find-first, otherwise do a find-next. */ | |
272 if (!dir_finding) | |
273 { | |
274 char filename[MAXNAMLEN + 3]; | |
275 int ln; | |
276 | |
277 strncpy (filename, dirp->dd_buf, MAXNAMLEN); | |
278 ln = strlen (filename)-1; | |
14246
ebdd1b50daba
(nt_stat): Use alloca instead of xmalloc.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
279 if (!IS_ANY_SEP (filename[ln])) |
9803 | 280 strcat (filename, "\\"); |
281 strcat (filename, "*.*"); | |
282 | |
283 dir_find_handle = FindFirstFile (filename, &find_data); | |
284 | |
285 if (dir_find_handle == INVALID_HANDLE_VALUE) | |
286 return NULL; | |
287 | |
288 dir_finding = 1; | |
289 } | |
290 else | |
291 { | |
292 if (!FindNextFile (dir_find_handle, &find_data)) | |
293 return NULL; | |
294 } | |
295 | |
296 /* NT's unique ID for a file is 64 bits, so we have to fake it here. | |
297 This should work as long as we never use 0. */ | |
298 dir_static.d_ino = 1; | |
299 | |
300 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 + | |
301 dir_static.d_namlen - dir_static.d_namlen % 4; | |
302 | |
303 dir_static.d_namlen = strlen (find_data.cFileName); | |
304 strncpy (dir_static.d_name, find_data.cFileName, MAXNAMLEN); | |
305 | |
306 return &dir_static; | |
307 } | |
308 | |
309 /* Emulate getpwuid and getpwnam. */ | |
310 | |
311 int getuid (); /* forward declaration */ | |
312 | |
12451
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
313 #define PASSWD_FIELD_SIZE 256 |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
314 |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
315 static char the_passwd_name[PASSWD_FIELD_SIZE]; |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
316 static char the_passwd_passwd[PASSWD_FIELD_SIZE]; |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
317 static char the_passwd_gecos[PASSWD_FIELD_SIZE]; |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
318 static char the_passwd_dir[PASSWD_FIELD_SIZE]; |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
319 static char the_passwd_shell[PASSWD_FIELD_SIZE]; |
9803 | 320 |
321 static struct passwd the_passwd = | |
322 { | |
323 the_passwd_name, | |
324 the_passwd_passwd, | |
325 0, | |
326 0, | |
327 0, | |
328 the_passwd_gecos, | |
329 the_passwd_dir, | |
330 the_passwd_shell, | |
331 }; | |
332 | |
333 struct passwd * | |
334 getpwuid (int uid) | |
335 { | |
12451
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
336 int size = PASSWD_FIELD_SIZE; |
9803 | 337 |
338 if (!GetUserName (the_passwd.pw_name, &size)) | |
339 return NULL; | |
340 | |
341 the_passwd.pw_passwd[0] = '\0'; | |
342 the_passwd.pw_uid = 0; | |
343 the_passwd.pw_gid = 0; | |
344 strcpy (the_passwd.pw_gecos, the_passwd.pw_name); | |
345 the_passwd.pw_dir[0] = '\0'; | |
346 the_passwd.pw_shell[0] = '\0'; | |
347 | |
348 return &the_passwd; | |
349 } | |
350 | |
351 struct passwd * | |
352 getpwnam (char *name) | |
353 { | |
354 struct passwd *pw; | |
355 | |
356 pw = getpwuid (getuid ()); | |
357 if (!pw) | |
358 return pw; | |
359 | |
360 if (strcmp (name, pw->pw_name)) | |
361 return NULL; | |
362 | |
363 return pw; | |
364 } | |
365 | |
366 | |
367 /* We don't have scripts to automatically determine the system configuration | |
368 for Emacs before it's compiled, and we don't want to have to make the | |
369 user enter it, so we define EMACS_CONFIGURATION to invoke this runtime | |
370 routine. */ | |
371 | |
11941
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
372 static char configuration_buffer[32]; |
9803 | 373 |
374 char * | |
375 get_emacs_configuration (void) | |
376 { | |
13156 | 377 char *arch, *oem, *os; |
9803 | 378 |
13156 | 379 /* Determine the processor type. */ |
380 switch (get_processor_type ()) | |
381 { | |
12451
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
382 |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
383 #ifdef PROCESSOR_INTEL_386 |
13156 | 384 case PROCESSOR_INTEL_386: |
385 case PROCESSOR_INTEL_486: | |
386 case PROCESSOR_INTEL_PENTIUM: | |
387 arch = "i386"; | |
388 break; | |
12451
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
389 #endif |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
390 |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
391 #ifdef PROCESSOR_INTEL_860 |
13156 | 392 case PROCESSOR_INTEL_860: |
393 arch = "i860"; | |
394 break; | |
12451
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
395 #endif |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
396 |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
397 #ifdef PROCESSOR_MIPS_R2000 |
13156 | 398 case PROCESSOR_MIPS_R2000: |
399 case PROCESSOR_MIPS_R3000: | |
400 case PROCESSOR_MIPS_R4000: | |
401 arch = "mips"; | |
402 break; | |
12451
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
403 #endif |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
404 |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
405 #ifdef PROCESSOR_ALPHA_21064 |
13156 | 406 case PROCESSOR_ALPHA_21064: |
407 arch = "alpha"; | |
408 break; | |
12451
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
409 #endif |
4439dcb1496a
(PASSWD_FIELD_SIZE): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
12183
diff
changeset
|
410 |
13156 | 411 default: |
412 arch = "unknown"; | |
413 break; | |
414 } | |
9803 | 415 |
13156 | 416 /* Let oem be "*" until we figure out how to decode the OEM field. */ |
417 oem = "*"; | |
9803 | 418 |
11941
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
419 #ifdef WINDOWS95 |
13156 | 420 os = "win"; |
11941
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
421 #else |
13156 | 422 os = "nt"; |
11941
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
423 #endif |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
424 |
13156 | 425 sprintf (configuration_buffer, "%s-%s-%s%d.%d", arch, oem, os, |
426 get_nt_major_version (), get_nt_minor_version ()); | |
427 return configuration_buffer; | |
9803 | 428 } |
429 | |
430 /* Conjure up inode and device numbers that will serve the purpose | |
431 of Emacs. Return 1 upon success, 0 upon failure. */ | |
432 int | |
433 get_inode_and_device_vals (Lisp_Object filename, Lisp_Object *p_inode, | |
434 Lisp_Object *p_device) | |
435 { | |
436 /* File uids on NT are found using a handle to a file, which | |
437 implies that it has been opened. Since we want to be able | |
438 to stat an arbitrary file, we must open it, get the info, | |
439 and then close it. | |
440 | |
441 Also, NT file uids are 64-bits. This is a problem. */ | |
442 | |
443 HANDLE handle; | |
444 BOOL result; | |
11384 | 445 DWORD attrs; |
9803 | 446 BY_HANDLE_FILE_INFORMATION info; |
447 | |
11384 | 448 /* We have to stat files and directories differently, so check |
449 to see what filename references. */ | |
450 attrs = GetFileAttributes (XSTRING (filename)->data); | |
451 if (attrs == 0xFFFFFFFF) { | |
452 return 0; | |
453 } | |
454 if (attrs & FILE_ATTRIBUTE_DIRECTORY) { | |
455 /* Conjure up bogus, but unique, values. */ | |
456 attrs = GetTickCount (); | |
457 *p_inode = make_number (attrs); | |
458 *p_device = make_number (attrs); | |
459 return 1; | |
460 } | |
461 | |
9803 | 462 /* FIXME: It shouldn't be opened without READ access, but NT on x86 |
463 doesn't allow GetFileInfo in that case (NT on mips does). */ | |
464 | |
465 handle = CreateFile (XSTRING (filename)->data, | |
466 GENERIC_READ, | |
467 FILE_SHARE_READ | FILE_SHARE_WRITE, | |
468 NULL, | |
469 OPEN_EXISTING, | |
470 FILE_ATTRIBUTE_NORMAL, | |
471 NULL); | |
472 if (handle == INVALID_HANDLE_VALUE) | |
473 return 0; | |
474 | |
475 result = GetFileInformationByHandle (handle, &info); | |
476 CloseHandle (handle); | |
477 if (!result) | |
478 return 0; | |
479 | |
480 *p_inode = make_number (info.nFileIndexLow); /* use the low value */ | |
481 *p_device = make_number (info.dwVolumeSerialNumber); | |
482 | |
483 return 1; | |
484 } | |
485 | |
486 /* The following pipe routines are used to support our fork emulation. | |
487 Since NT's crt dup always creates inherited handles, we | |
488 must be careful in setting up pipes. First create | |
489 non-inherited pipe handles, then create an inherited handle | |
490 to the write end by dup-ing it, and then close the non-inherited | |
491 end that was just duped. This gives us one non-inherited handle | |
492 on the read end and one inherited handle to the write end. As | |
493 the parent, we close the inherited handle to the write end after | |
494 spawning the child. */ | |
495 | |
496 /* From callproc.c */ | |
497 extern Lisp_Object Vbinary_process_input; | |
498 extern Lisp_Object Vbinary_process_output; | |
499 | |
500 void | |
501 pipe_with_inherited_out (int fds[2]) | |
502 { | |
503 int inherit_out; | |
504 unsigned int flags = _O_NOINHERIT; | |
505 | |
506 if (!NILP (Vbinary_process_output)) | |
507 flags |= _O_BINARY; | |
508 | |
509 _pipe (fds, 0, flags); | |
510 inherit_out = dup (fds[1]); | |
511 close (fds[1]); | |
512 fds[1] = inherit_out; | |
513 } | |
514 | |
515 void | |
516 pipe_with_inherited_in (int fds[2]) | |
517 { | |
518 int inherit_in; | |
519 unsigned int flags = _O_NOINHERIT; | |
520 | |
521 if (!NILP (Vbinary_process_input)) | |
522 flags |= _O_BINARY; | |
523 | |
524 _pipe (fds, 0, flags); | |
525 inherit_in = dup (fds[0]); | |
526 close (fds[0]); | |
527 fds[0] = inherit_in; | |
528 } | |
529 | |
530 /* The following two routines are used to manipulate stdin, stdout, and | |
531 stderr of our child processes. | |
532 | |
533 Assuming that in, out, and err are inherited, we make them stdin, | |
534 stdout, and stderr of the child as follows: | |
535 | |
536 - Save the parent's current standard handles. | |
537 - Set the parent's standard handles to the handles being passed in. | |
538 (Note that _get_osfhandle is an io.h procedure that | |
539 maps crt file descriptors to NT file handles.) | |
540 - Spawn the child, which inherits in, out, and err as stdin, | |
541 stdout, and stderr. (see Spawnve) | |
542 - Reset the parent's standard handles to the saved handles. | |
543 (see reset_standard_handles) | |
544 We assume that the caller closes in, out, and err after calling us. */ | |
545 | |
546 void | |
547 prepare_standard_handles (int in, int out, int err, HANDLE handles[4]) | |
548 { | |
549 HANDLE parent, stdin_save, stdout_save, stderr_save, err_handle; | |
11941
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
550 |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
551 #ifdef WINDOWS95 |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
552 /* The Win95 beta doesn't set the standard handles correctly. |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
553 Handicap subprocesses until we get a version that works correctly. |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
554 Undefining the subprocesses macro reveals other incompatibilities, |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
555 so, since we're expecting subprocs to work in the near future, |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
556 disable them here. */ |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
557 report_file_error ("Subprocesses currently disabled on Win95", Qnil); |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
558 #endif |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
559 |
9803 | 560 parent = GetCurrentProcess (); |
11941
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
561 stdin_save = GetStdHandle (STD_INPUT_HANDLE); |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
562 stdout_save = GetStdHandle (STD_OUTPUT_HANDLE); |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
563 stderr_save = GetStdHandle (STD_ERROR_HANDLE); |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
564 |
13427
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
565 #ifndef HAVE_NTGUI |
9803 | 566 if (!DuplicateHandle (parent, |
567 GetStdHandle (STD_INPUT_HANDLE), | |
568 parent, | |
569 &stdin_save, | |
570 0, | |
571 FALSE, | |
572 DUPLICATE_SAME_ACCESS)) | |
573 report_file_error ("Duplicating parent's input handle", Qnil); | |
574 | |
575 if (!DuplicateHandle (parent, | |
576 GetStdHandle (STD_OUTPUT_HANDLE), | |
577 parent, | |
578 &stdout_save, | |
579 0, | |
580 FALSE, | |
581 DUPLICATE_SAME_ACCESS)) | |
582 report_file_error ("Duplicating parent's output handle", Qnil); | |
583 | |
584 if (!DuplicateHandle (parent, | |
585 GetStdHandle (STD_ERROR_HANDLE), | |
586 parent, | |
587 &stderr_save, | |
588 0, | |
589 FALSE, | |
590 DUPLICATE_SAME_ACCESS)) | |
591 report_file_error ("Duplicating parent's error handle", Qnil); | |
13427
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
592 #endif /* !HAVE_NTGUI */ |
9803 | 593 |
594 if (!SetStdHandle (STD_INPUT_HANDLE, (HANDLE) _get_osfhandle (in))) | |
595 report_file_error ("Changing stdin handle", Qnil); | |
596 | |
597 if (!SetStdHandle (STD_OUTPUT_HANDLE, (HANDLE) _get_osfhandle (out))) | |
598 report_file_error ("Changing stdout handle", Qnil); | |
599 | |
600 /* We lose data if we use the same handle to the pipe for stdout and | |
601 stderr, so make a duplicate. This took a while to find. */ | |
602 if (out == err) | |
603 { | |
604 if (!DuplicateHandle (parent, | |
605 (HANDLE) _get_osfhandle (err), | |
606 parent, | |
607 &err_handle, | |
608 0, | |
609 TRUE, | |
610 DUPLICATE_SAME_ACCESS)) | |
611 report_file_error ("Duplicating out handle to make err handle.", | |
612 Qnil); | |
613 } | |
614 else | |
615 { | |
616 err_handle = (HANDLE) _get_osfhandle (err); | |
617 } | |
618 | |
619 if (!SetStdHandle (STD_ERROR_HANDLE, err_handle)) | |
620 report_file_error ("Changing stderr handle", Qnil); | |
621 | |
622 handles[0] = stdin_save; | |
623 handles[1] = stdout_save; | |
624 handles[2] = stderr_save; | |
625 handles[3] = err_handle; | |
626 } | |
627 | |
628 void | |
629 reset_standard_handles (int in, int out, int err, HANDLE handles[4]) | |
630 { | |
631 HANDLE stdin_save = handles[0]; | |
632 HANDLE stdout_save = handles[1]; | |
633 HANDLE stderr_save = handles[2]; | |
634 HANDLE err_handle = handles[3]; | |
11941
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
635 int i; |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
636 |
13427
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
637 #ifndef HAVE_NTGUI |
9803 | 638 if (!SetStdHandle (STD_INPUT_HANDLE, stdin_save)) |
639 report_file_error ("Resetting input handle", Qnil); | |
640 | |
641 if (!SetStdHandle (STD_OUTPUT_HANDLE, stdout_save)) | |
11941
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
642 { |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
643 i = GetLastError (); |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
644 report_file_error ("Resetting output handle", Qnil); |
cb26a4ca0e10
(configuration_buffer): Increase size.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11384
diff
changeset
|
645 } |
9803 | 646 |
647 if (!SetStdHandle (STD_ERROR_HANDLE, stderr_save)) | |
648 report_file_error ("Resetting error handle", Qnil); | |
13427
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
649 #endif /* !HAVE_NTGUI */ |
9803 | 650 |
651 if (out == err) | |
652 { | |
653 /* If out and err are the same handle, then we duplicated out | |
654 and stuck it in err_handle. Close the duplicate to clean up. */ | |
655 if (!CloseHandle (err_handle)) | |
656 report_file_error ("Closing error handle duplicated from out.", | |
657 Qnil); | |
658 } | |
659 } | |
660 | |
11384 | 661 int |
662 random () | |
663 { | |
664 /* rand () on NT gives us 15 random bits...hack together 30 bits. */ | |
665 return ((rand () << 15) | rand ()); | |
666 } | |
667 | |
668 void | |
669 srandom (int seed) | |
670 { | |
671 srand (seed); | |
672 } | |
673 | |
9803 | 674 /* Destructively turn backslashes into slashes. */ |
675 void | |
676 dostounix_filename (p) | |
677 register char *p; | |
678 { | |
679 while (*p) | |
680 { | |
681 if (*p == '\\') | |
682 *p = '/'; | |
683 p++; | |
684 } | |
685 } | |
686 | |
687 /* Routines that are no-ops on NT but are defined to get Emacs to compile. */ | |
688 | |
689 | |
690 int | |
691 sigsetmask (int signal_mask) | |
692 { | |
693 return 0; | |
694 } | |
695 | |
696 int | |
697 sigblock (int sig) | |
698 { | |
699 return 0; | |
700 } | |
701 | |
702 int | |
703 kill (int pid, int signal) | |
704 { | |
705 return 0; | |
706 } | |
707 | |
708 int | |
709 setpgrp (int pid, int gid) | |
710 { | |
711 return 0; | |
712 } | |
713 | |
714 int | |
715 alarm (int seconds) | |
716 { | |
717 return 0; | |
718 } | |
719 | |
720 int | |
721 unrequest_sigio (void) | |
722 { | |
723 return 0; | |
724 } | |
725 | |
726 int | |
727 request_sigio (void) | |
728 { | |
729 return 0; | |
730 } | |
731 | |
732 int | |
733 getuid () | |
734 { | |
13932
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
735 char buffer[256]; |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
736 int size = 256; |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
737 |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
738 if (!GetUserName (buffer, &size)) |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
739 /* Assume all powers upon failure. */ |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
740 return 0; |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
741 |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
742 if (!stricmp ("administrator", buffer)) |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
743 return 0; |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
744 else |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
745 /* A complete fabrication...is there anything to base it on? */ |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
746 return 123; |
9803 | 747 } |
748 | |
749 int | |
750 geteuid () | |
751 { | |
13932
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
752 /* I could imagine arguing for checking to see whether the user is |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
753 in the Administrators group and returning a UID of 0 for that |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
754 case, but I don't know how wise that would be in the long run. */ |
de7851688890
(getuid): Only return root uid if Administrator.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13427
diff
changeset
|
755 return getuid (); |
9803 | 756 } |
757 | |
758 /* Remove all CR's that are followed by a LF. | |
759 (From msdos.c...probably should figure out a way to share it, | |
760 although this code isn't going to ever change.) */ | |
761 int | |
762 crlf_to_lf (n, buf) | |
763 register int n; | |
764 register unsigned char *buf; | |
765 { | |
766 unsigned char *np = buf; | |
767 unsigned char *startp = buf; | |
768 unsigned char *endp = buf + n; | |
769 | |
770 if (n == 0) | |
771 return n; | |
772 while (buf < endp - 1) | |
773 { | |
774 if (*buf == 0x0d) | |
775 { | |
776 if (*(++buf) != 0x0a) | |
777 *np++ = 0x0d; | |
778 } | |
779 else | |
780 *np++ = *buf++; | |
781 } | |
782 if (buf < endp) | |
783 *np++ = *buf++; | |
784 return np - startp; | |
785 } | |
786 | |
13427
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
787 #define REG_ROOT "SOFTWARE\\GNU\\Emacs\\" |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
788 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
789 LPBYTE |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
790 nt_get_resource (key, lpdwtype) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
791 char *key; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
792 LPDWORD lpdwtype; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
793 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
794 LPBYTE lpvalue; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
795 HKEY hrootkey = NULL; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
796 DWORD cbData; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
797 BOOL ok = FALSE; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
798 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
799 /* Check both the current user and the local machine to see if |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
800 we have any resources. */ |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
801 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
802 if (RegOpenKeyEx (HKEY_CURRENT_USER, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
803 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
804 lpvalue = NULL; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
805 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
806 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
807 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
808 && RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
809 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
810 return (lpvalue); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
811 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
812 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
813 if (lpvalue) xfree (lpvalue); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
814 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
815 RegCloseKey (hrootkey); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
816 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
817 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
818 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
819 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
820 lpvalue = NULL; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
821 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
822 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS && |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
823 (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL && |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
824 RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
825 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
826 return (lpvalue); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
827 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
828 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
829 if (lpvalue) xfree (lpvalue); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
830 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
831 RegCloseKey (hrootkey); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
832 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
833 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
834 return (NULL); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
835 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
836 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
837 void |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
838 init_environment () |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
839 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
840 /* Open a console window to display messages during dumping. */ |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
841 if (!initialized) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
842 AllocConsole (); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
843 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
844 /* Check for environment variables and use registry if they don't exist */ |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
845 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
846 int i; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
847 LPBYTE lpval; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
848 DWORD dwType; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
849 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
850 static char * env_vars[] = |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
851 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
852 "emacs_path", |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
853 "EMACSLOADPATH", |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
854 "SHELL", |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
855 "EMACSDATA", |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
856 "EMACSPATH", |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
857 "EMACSLOCKDIR", |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
858 "INFOPATH", |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
859 "EMACSDOC", |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
860 "TERM", |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
861 }; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
862 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
863 for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
864 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
865 if (!getenv (env_vars[i]) && |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
866 (lpval = nt_get_resource (env_vars[i], &dwType)) != NULL) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
867 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
868 if (dwType == REG_EXPAND_SZ) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
869 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
870 char buf1[500], buf2[500]; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
871 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
872 ExpandEnvironmentStrings ((LPSTR) lpval, buf1, 500); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
873 _snprintf (buf2, 499, "%s=%s", env_vars[i], buf1); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
874 putenv (strdup (buf2)); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
875 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
876 else if (dwType == REG_SZ) |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
877 { |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
878 char buf[500]; |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
879 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
880 _snprintf (buf, 499, "%s=%s", env_vars[i], lpval); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
881 putenv (strdup (buf)); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
882 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
883 |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
884 xfree (lpval); |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
885 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
886 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
887 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
888 } |
71d734525d2c
(nt_get_resource, init_environment): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
13156
diff
changeset
|
889 |
11384 | 890 #ifdef HAVE_TIMEVAL |
891 #include <sys/timeb.h> | |
892 | |
893 /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */ | |
894 void | |
895 gettimeofday (struct timeval *tv, struct timezone *tz) | |
896 { | |
897 struct _timeb tb; | |
898 _ftime (&tb); | |
899 | |
900 tv->tv_sec = tb.time; | |
901 tv->tv_usec = tb.millitm * 1000L; | |
902 if (tz) | |
903 { | |
904 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */ | |
905 tz->tz_dsttime = tb.dstflag; /* type of dst correction */ | |
906 } | |
907 } | |
908 #endif /* HAVE_TIMEVAL */ | |
909 | |
9803 | 910 |
911 #ifdef PIGSFLY | |
912 Keep this around...we might need it later. | |
913 #ifdef WINDOWSNT | |
914 { | |
915 /* | |
916 * Find the user's real name by opening the process token and looking | |
917 * up the name associated with the user-sid in that token. | |
918 */ | |
919 | |
920 char b[256], Name[256], RefD[256]; | |
921 DWORD length = 256, rlength = 256, trash; | |
922 HANDLE Token; | |
923 SID_NAME_USE User; | |
924 | |
925 if (1) | |
12025
e804b43418f6
Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents:
11941
diff
changeset
|
926 Vuser_real_login_name = build_string ("foo"); |
9803 | 927 else if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &Token)) |
928 { | |
12025
e804b43418f6
Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents:
11941
diff
changeset
|
929 Vuser_real_login_name = build_string ("unknown"); |
9803 | 930 } |
931 else if (!GetTokenInformation (Token, TokenUser, (PVOID)b, 256, | |
932 &trash)) | |
933 { | |
934 CloseHandle (Token); | |
12025
e804b43418f6
Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents:
11941
diff
changeset
|
935 Vuser_real_login_name = build_string ("unknown"); |
9803 | 936 } |
937 else if (!LookupAccountSid ((void *)0, (PSID)b, Name, &length, RefD, | |
938 &rlength, &User)) | |
939 { | |
940 CloseHandle (Token); | |
12025
e804b43418f6
Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents:
11941
diff
changeset
|
941 Vuser_real_login_name = build_string ("unknown"); |
9803 | 942 } |
943 else | |
12025
e804b43418f6
Change Vuser_real_name to Vuser_real_login_name.
Karl Heuer <kwzh@gnu.org>
parents:
11941
diff
changeset
|
944 Vuser_real_login_name = build_string (Name); |
9803 | 945 } |
946 #else /* not WINDOWSNT */ | |
947 #endif /* not WINDOWSNT */ | |
948 #endif /* PIGSFLY */ |