annotate src/nt.c @ 100:4be1180a9e89 r20-1b2

Import from CVS: tag r20-1b2
author cvs
date Mon, 13 Aug 2007 09:15:11 +0200
parents
children 850242ba4a81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1 /* Utility and Unix shadow routines for XEmacs on Windows NT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
3
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
4 This file is part of XEmacs.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
5
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
9 later version.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
10
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
14 for more details.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
15
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to the Free
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
19 02111-1307, USA.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
20
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
21
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
22 Geoff Voelker (voelker@cs.washington.edu) 7-29-94 */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
23
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
24 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
25
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
26 #include <stdlib.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
27 #include <stdio.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
28 #include <io.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
29 #include <errno.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
30 #include <fcntl.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
31 #include <ctype.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
32 #include <signal.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
33 #include <sys/time.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
34
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
35 /* must include CRT headers *before* config.h */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
36 #include "config.h"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
37 #undef access
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
38 #undef chdir
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
39 #undef chmod
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
40 #undef creat
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
41 #undef ctime
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
42 #undef fopen
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
43 #undef link
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
44 #undef mkdir
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
45 #undef mktemp
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
46 #undef open
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
47 #undef rename
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
48 #undef rmdir
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
49 #undef unlink
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
50
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
51 #undef close
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
52 #undef dup
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
53 #undef dup2
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
54 #undef pipe
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
55 #undef read
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
56 #undef write
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
57 #undef closedir
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
58
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
59 #define getwd _getwd
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
60 #include "lisp.h"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
61 #undef getwd
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
62
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
63 #include <pwd.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
64
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
65 #include <windows.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
66
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
67 #ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
68 #include <sys/socket.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
69 #undef socket
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
70 #undef bind
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
71 #undef connect
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
72 #undef htons
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
73 #undef ntohs
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
74 #undef inet_addr
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
75 #undef gethostname
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
76 #undef gethostbyname
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
77 #undef getservbyname
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
78 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
79
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
80 #include "nt.h"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
81 #include <sys/dir.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
82 #include "ntheap.h"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
83
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
84 /* Get the current working directory. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
85 char *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
86 getwd (char *dir)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
87 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
88 if (GetCurrentDirectory (MAXPATHLEN, dir) > 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
89 return dir;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
90 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
91 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
92
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
93 #ifndef HAVE_SOCKETS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
94 /* Emulate gethostname. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
95 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
96 gethostname (char *buffer, int size)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
97 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
98 /* NT only allows small host names, so the buffer is
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
99 certainly large enough. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
100 return !GetComputerName (buffer, &size);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
101 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
102 #endif /* HAVE_SOCKETS */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
103
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
104 /* Emulate getloadavg. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
105 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
106 getloadavg (double loadavg[], int nelem)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
107 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
108 int i;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
109
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
110 /* A faithful emulation is going to have to be saved for a rainy day. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
111 for (i = 0; i < nelem; i++)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
112 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
113 loadavg[i] = 0.0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
114 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
115 return i;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
116 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
117
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
118 /* Emulate the Unix directory procedures opendir, closedir,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
119 and readdir. We can't use the procedures supplied in sysdep.c,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
120 so we provide them here. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
121
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
122 struct direct dir_static; /* simulated directory contents */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
123 static HANDLE dir_find_handle = INVALID_HANDLE_VALUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
124 static int dir_is_fat;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
125 static char dir_pathname[MAXPATHLEN+1];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
126
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
127 extern Lisp_Object Vwin32_downcase_file_names;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
128
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
129 DIR *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
130 opendir (char *filename)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
131 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
132 DIR *dirp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
133
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
134 /* Opening is done by FindFirstFile. However, a read is inherent to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
135 this operation, so we defer the open until read time. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
136
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
137 if (!(dirp = (DIR *) xmalloc (sizeof (DIR))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
138 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
139 if (dir_find_handle != INVALID_HANDLE_VALUE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
140 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
141
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
142 dirp->dd_fd = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
143 dirp->dd_loc = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
144 dirp->dd_size = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
145
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
146 strncpy (dir_pathname, filename, MAXPATHLEN);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
147 dir_pathname[MAXPATHLEN] = '\0';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
148 dir_is_fat = is_fat_volume (filename, NULL);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
149
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
150 return dirp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
151 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
152
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
153 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
154 closedir (DIR *dirp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
155 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
156 /* If we have a find-handle open, close it. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
157 if (dir_find_handle != INVALID_HANDLE_VALUE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
158 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
159 FindClose (dir_find_handle);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
160 dir_find_handle = INVALID_HANDLE_VALUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
161 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
162 xfree ((char *) dirp);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
163 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
164
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
165 struct direct *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
166 readdir (DIR *dirp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
167 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
168 WIN32_FIND_DATA find_data;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
169
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
170 /* If we aren't dir_finding, do a find-first, otherwise do a find-next. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
171 if (dir_find_handle == INVALID_HANDLE_VALUE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
172 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
173 char filename[MAXNAMLEN + 3];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
174 int ln;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
175
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
176 strcpy (filename, dir_pathname);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
177 ln = strlen (filename) - 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
178 if (!IS_DIRECTORY_SEP (filename[ln]))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
179 strcat (filename, "\\");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
180 strcat (filename, "*");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
181
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
182 dir_find_handle = FindFirstFile (filename, &find_data);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
183
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
184 if (dir_find_handle == INVALID_HANDLE_VALUE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
185 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
186 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
187 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
188 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
189 if (!FindNextFile (dir_find_handle, &find_data))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
190 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
191 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
192
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
193 /* Emacs never uses this value, so don't bother making it match
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
194 value returned by stat(). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
195 dir_static.d_ino = 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
196
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
197 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 +
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
198 dir_static.d_namlen - dir_static.d_namlen % 4;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
199
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
200 dir_static.d_namlen = strlen (find_data.cFileName);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
201 strcpy (dir_static.d_name, find_data.cFileName);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
202 if (dir_is_fat)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
203 _strlwr (dir_static.d_name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
204 else if (!NILP (Vwin32_downcase_file_names))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
205 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
206 register char *p;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
207 for (p = dir_static.d_name; *p; p++)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
208 if (*p >= 'a' && *p <= 'z')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
209 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
210 if (!*p)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
211 _strlwr (dir_static.d_name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
212 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
213
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
214 return &dir_static;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
215 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
216
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
217 /* Emulate getpwuid, getpwnam and others. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
218
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
219 #define PASSWD_FIELD_SIZE 256
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
220
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
221 static char the_passwd_name[PASSWD_FIELD_SIZE];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
222 static char the_passwd_passwd[PASSWD_FIELD_SIZE];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
223 static char the_passwd_gecos[PASSWD_FIELD_SIZE];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
224 static char the_passwd_dir[PASSWD_FIELD_SIZE];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
225 static char the_passwd_shell[PASSWD_FIELD_SIZE];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
226
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
227 static struct passwd the_passwd =
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
228 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
229 the_passwd_name,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
230 the_passwd_passwd,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
231 0,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
232 0,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
233 0,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
234 the_passwd_gecos,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
235 the_passwd_dir,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
236 the_passwd_shell,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
237 };
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
238
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
239 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
240 getuid ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
241 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
242 return the_passwd.pw_uid;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
243 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
244
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
245 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
246 geteuid ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
247 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
248 /* I could imagine arguing for checking to see whether the user is
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
249 in the Administrators group and returning a UID of 0 for that
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
250 case, but I don't know how wise that would be in the long run. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
251 return getuid ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
252 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
253
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
254 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
255 getgid ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
256 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
257 return the_passwd.pw_gid;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
258 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
259
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
260 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
261 getegid ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
262 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
263 return getgid ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
264 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
265
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
266 struct passwd *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
267 getpwuid (int uid)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
268 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
269 if (uid == the_passwd.pw_uid)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
270 return &the_passwd;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
271 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
272 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
273
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
274 struct passwd *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
275 getpwnam (char *name)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
276 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
277 struct passwd *pw;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
278
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
279 pw = getpwuid (getuid ());
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
280 if (!pw)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
281 return pw;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
282
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
283 if (stricmp (name, pw->pw_name))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
284 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
285
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
286 return pw;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
287 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
288
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
289 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
290 init_user_info ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
291 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
292 /* Find the user's real name by opening the process token and
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
293 looking up the name associated with the user-sid in that token.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
294
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
295 Use the relative portion of the identifier authority value from
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
296 the user-sid as the user id value (same for group id using the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
297 primary group sid from the process token). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
298
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
299 char user_sid[256], name[256], domain[256];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
300 DWORD length = sizeof (name), dlength = sizeof (domain), trash;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
301 HANDLE token = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
302 SID_NAME_USE user_type;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
303
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
304 if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &token)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
305 && GetTokenInformation (token, TokenUser,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
306 (PVOID) user_sid, sizeof (user_sid), &trash)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
307 && LookupAccountSid (NULL, *((PSID *) user_sid), name, &length,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
308 domain, &dlength, &user_type))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
309 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
310 strcpy (the_passwd.pw_name, name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
311 /* Determine a reasonable uid value. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
312 if (stricmp ("administrator", name) == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
313 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
314 the_passwd.pw_uid = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
315 the_passwd.pw_gid = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
316 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
317 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
318 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
319 SID_IDENTIFIER_AUTHORITY * pSIA;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
320
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
321 pSIA = GetSidIdentifierAuthority (*((PSID *) user_sid));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
322 /* I believe the relative portion is the last 4 bytes (of 6)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
323 with msb first. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
324 the_passwd.pw_uid = ((pSIA->Value[2] << 24) +
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
325 (pSIA->Value[3] << 16) +
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
326 (pSIA->Value[4] << 8) +
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
327 (pSIA->Value[5] << 0));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
328 /* restrict to conventional uid range for normal users */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
329 the_passwd.pw_uid = the_passwd.pw_uid % 60001;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
330
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
331 /* Get group id */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
332 if (GetTokenInformation (token, TokenPrimaryGroup,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
333 (PVOID) user_sid, sizeof (user_sid), &trash))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
334 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
335 SID_IDENTIFIER_AUTHORITY * pSIA;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
336
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
337 pSIA = GetSidIdentifierAuthority (*((PSID *) user_sid));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
338 the_passwd.pw_gid = ((pSIA->Value[2] << 24) +
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
339 (pSIA->Value[3] << 16) +
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
340 (pSIA->Value[4] << 8) +
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
341 (pSIA->Value[5] << 0));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
342 /* I don't know if this is necessary, but for safety... */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
343 the_passwd.pw_gid = the_passwd.pw_gid % 60001;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
344 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
345 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
346 the_passwd.pw_gid = the_passwd.pw_uid;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
347 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
348 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
349 /* If security calls are not supported (presumably because we
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
350 are running under Windows 95), fallback to this. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
351 else if (GetUserName (name, &length))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
352 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
353 strcpy (the_passwd.pw_name, name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
354 if (stricmp ("administrator", name) == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
355 the_passwd.pw_uid = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
356 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
357 the_passwd.pw_uid = 123;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
358 the_passwd.pw_gid = the_passwd.pw_uid;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
359 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
360 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
361 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
362 strcpy (the_passwd.pw_name, "unknown");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
363 the_passwd.pw_uid = 123;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
364 the_passwd.pw_gid = 123;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
365 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
366
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
367 /* Ensure HOME and SHELL are defined. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
368 if (getenv ("HOME") == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
369 putenv ("HOME=c:/");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
370 if (getenv ("SHELL") == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
371 putenv ((GetVersion () & 0x80000000) ? "SHELL=command" : "SHELL=cmd");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
372
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
373 /* Set dir and shell from environment variables. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
374 strcpy (the_passwd.pw_dir, getenv ("HOME"));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
375 strcpy (the_passwd.pw_shell, getenv ("SHELL"));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
376
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
377 if (token)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
378 CloseHandle (token);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
379 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
380
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
381 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
382 random ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
383 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
384 /* rand () on NT gives us 15 random bits...hack together 30 bits. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
385 return ((rand () << 15) | rand ());
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
386 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
387
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
388 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
389 srandom (int seed)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
390 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
391 srand (seed);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
392 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
393
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
394 /* Normalize filename by converting all path separators to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
395 the specified separator. Also conditionally convert upper
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
396 case path name components to lower case. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
397
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
398 static void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
399 normalize_filename (fp, path_sep)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
400 register char *fp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
401 char path_sep;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
402 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
403 char sep;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
404 char *elem;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
405
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
406 /* Always lower-case drive letters a-z, even if the filesystem
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
407 preserves case in filenames.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
408 This is so filenames can be compared by string comparison
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
409 functions that are case-sensitive. Even case-preserving filesystems
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
410 do not distinguish case in drive letters. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
411 if (fp[1] == ':' && *fp >= 'A' && *fp <= 'Z')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
412 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
413 *fp += 'a' - 'A';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
414 fp += 2;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
415 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
416
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
417 if (NILP (Vwin32_downcase_file_names))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
418 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
419 while (*fp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
420 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
421 if (*fp == '/' || *fp == '\\')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
422 *fp = path_sep;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
423 fp++;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
424 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
425 return;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
426 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
427
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
428 sep = path_sep; /* convert to this path separator */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
429 elem = fp; /* start of current path element */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
430
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
431 do {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
432 if (*fp >= 'a' && *fp <= 'z')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
433 elem = 0; /* don't convert this element */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
434
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
435 if (*fp == 0 || *fp == ':')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
436 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
437 sep = *fp; /* restore current separator (or 0) */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
438 *fp = '/'; /* after conversion of this element */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
439 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
440
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
441 if (*fp == '/' || *fp == '\\')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
442 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
443 if (elem && elem != fp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
444 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
445 *fp = 0; /* temporary end of string */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
446 _strlwr (elem); /* while we convert to lower case */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
447 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
448 *fp = sep; /* convert (or restore) path separator */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
449 elem = fp + 1; /* next element starts after separator */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
450 sep = path_sep;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
451 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
452 } while (*fp++);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
453 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
454
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
455 /* Destructively turn backslashes into slashes. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
456 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
457 dostounix_filename (p)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
458 register char *p;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
459 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
460 normalize_filename (p, '/');
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
461 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
462
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
463 /* Destructively turn slashes into backslashes. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
464 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
465 unixtodos_filename (p)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
466 register char *p;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
467 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
468 normalize_filename (p, '\\');
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
469 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
470
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
471 /* Remove all CR's that are followed by a LF.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
472 (From msdos.c...probably should figure out a way to share it,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
473 although this code isn't going to ever change.) */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
474 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
475 crlf_to_lf (n, buf)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
476 register int n;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
477 register unsigned char *buf;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
478 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
479 unsigned char *np = buf;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
480 unsigned char *startp = buf;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
481 unsigned char *endp = buf + n;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
482
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
483 if (n == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
484 return n;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
485 while (buf < endp - 1)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
486 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
487 if (*buf == 0x0d)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
488 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
489 if (*(++buf) != 0x0a)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
490 *np++ = 0x0d;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
491 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
492 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
493 *np++ = *buf++;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
494 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
495 if (buf < endp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
496 *np++ = *buf++;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
497 return np - startp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
498 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
499
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
500 /* Routines that are no-ops on NT but are defined to get Emacs to compile. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
501
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
502 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
503 sigsetmask (int signal_mask)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
504 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
505 return 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
506 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
507
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
508 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
509 sigblock (int sig)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
510 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
511 return 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
512 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
513
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
514 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
515 setpgrp (int pid, int gid)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
516 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
517 return 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
518 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
519
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
520 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
521 alarm (int seconds)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
522 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
523 return 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
524 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
525
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
526 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
527 unrequest_sigio (void)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
528 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
529 return 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
530 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
531
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
532 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
533 request_sigio (void)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
534 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
535 return 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
536 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
537
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
538 #define REG_ROOT "SOFTWARE\\GNU\\Emacs"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
539
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
540 LPBYTE
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
541 nt_get_resource (key, lpdwtype)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
542 char *key;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
543 LPDWORD lpdwtype;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
544 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
545 LPBYTE lpvalue;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
546 HKEY hrootkey = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
547 DWORD cbData;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
548 BOOL ok = FALSE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
549
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
550 /* Check both the current user and the local machine to see if
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
551 we have any resources. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
552
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
553 if (RegOpenKeyEx (HKEY_CURRENT_USER, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
554 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
555 lpvalue = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
556
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
557 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
558 && (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
559 && RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
560 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
561 return (lpvalue);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
562 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
563
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
564 if (lpvalue) xfree (lpvalue);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
565
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
566 RegCloseKey (hrootkey);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
567 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
568
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
569 if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
570 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
571 lpvalue = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
572
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
573 if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS &&
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
574 (lpvalue = (LPBYTE) xmalloc (cbData)) != NULL &&
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
575 RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
576 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
577 return (lpvalue);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
578 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
579
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
580 if (lpvalue) xfree (lpvalue);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
581
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
582 RegCloseKey (hrootkey);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
583 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
584
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
585 return (NULL);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
586 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
587
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
588 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
589 init_environment ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
590 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
591 /* Check for environment variables and use registry if they don't exist */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
592 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
593 int i;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
594 LPBYTE lpval;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
595 DWORD dwType;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
596
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
597 static char * env_vars[] =
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
598 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
599 "HOME",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
600 "PRELOAD_WINSOCK",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
601 "emacs_dir",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
602 "EMACSLOADPATH",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
603 "SHELL",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
604 "EMACSDATA",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
605 "EMACSPATH",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
606 "EMACSLOCKDIR",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
607 "INFOPATH",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
608 "EMACSDOC",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
609 "TERM",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
610 };
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
611
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
612 for (i = 0; i < (sizeof (env_vars) / sizeof (env_vars[0])); i++)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
613 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
614 if (!getenv (env_vars[i]) &&
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
615 (lpval = nt_get_resource (env_vars[i], &dwType)) != NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
616 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
617 if (dwType == REG_EXPAND_SZ)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
618 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
619 char buf1[500], buf2[500];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
620
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
621 ExpandEnvironmentStrings ((LPSTR) lpval, buf1, 500);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
622 _snprintf (buf2, 499, "%s=%s", env_vars[i], buf1);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
623 putenv (strdup (buf2));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
624 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
625 else if (dwType == REG_SZ)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
626 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
627 char buf[500];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
628
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
629 _snprintf (buf, 499, "%s=%s", env_vars[i], lpval);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
630 putenv (strdup (buf));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
631 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
632
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
633 xfree (lpval);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
634 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
635 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
636 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
637
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
638 init_user_info ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
639 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
640
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
641 /* We don't have scripts to automatically determine the system configuration
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
642 for Emacs before it's compiled, and we don't want to have to make the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
643 user enter it, so we define EMACS_CONFIGURATION to invoke this runtime
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
644 routine. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
645
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
646 static char configuration_buffer[32];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
647
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
648 char *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
649 get_emacs_configuration (void)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
650 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
651 char *arch, *oem, *os;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
652
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
653 /* Determine the processor type. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
654 switch (get_processor_type ())
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
655 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
656
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
657 #ifdef PROCESSOR_INTEL_386
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
658 case PROCESSOR_INTEL_386:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
659 case PROCESSOR_INTEL_486:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
660 case PROCESSOR_INTEL_PENTIUM:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
661 arch = "i386";
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
662 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
663 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
664
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
665 #ifdef PROCESSOR_INTEL_860
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
666 case PROCESSOR_INTEL_860:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
667 arch = "i860";
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
668 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
669 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
670
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
671 #ifdef PROCESSOR_MIPS_R2000
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
672 case PROCESSOR_MIPS_R2000:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
673 case PROCESSOR_MIPS_R3000:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
674 case PROCESSOR_MIPS_R4000:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
675 arch = "mips";
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
676 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
677 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
678
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
679 #ifdef PROCESSOR_ALPHA_21064
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
680 case PROCESSOR_ALPHA_21064:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
681 arch = "alpha";
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
682 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
683 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
684
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
685 default:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
686 arch = "unknown";
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
687 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
688 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
689
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
690 /* Let oem be "*" until we figure out how to decode the OEM field. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
691 oem = "*";
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
692
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
693 os = (GetVersion () & 0x80000000) ? "win95" : "nt";
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
694
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
695 sprintf (configuration_buffer, "%s-%s-%s%d.%d", arch, oem, os,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
696 get_nt_major_version (), get_nt_minor_version ());
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
697 return configuration_buffer;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
698 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
699
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
700 #ifndef HAVE_X_WINDOWS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
701 /* X11R6 on NT provides the single parameter version of this command. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
702
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
703 #include <sys/timeb.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
704
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
705 /* Emulate gettimeofday (Ulrich Leodolter, 1/11/95). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
706 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
707 gettimeofday (struct timeval *tv, struct timezone *tz)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
708 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
709 struct _timeb tb;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
710 _ftime (&tb);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
711
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
712 tv->tv_sec = tb.time;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
713 tv->tv_usec = tb.millitm * 1000L;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
714 if (tz)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
715 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
716 tz->tz_minuteswest = tb.timezone; /* minutes west of Greenwich */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
717 tz->tz_dsttime = tb.dstflag; /* type of dst correction */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
718 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
719 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
720
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
721 #endif /* HAVE_X_WINDOWS */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
722
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
723 /* ------------------------------------------------------------------------- */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
724 /* IO support and wrapper functions for Win32 API. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
725 /* ------------------------------------------------------------------------- */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
726
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
727 /* Place a wrapper around the MSVC version of ctime. It returns NULL
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
728 on network directories, so we handle that case here.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
729 (Ulrich Leodolter, 1/11/95). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
730 char *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
731 sys_ctime (const time_t *t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
732 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
733 char *str = (char *) ctime (t);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
734 return (str ? str : "Sun Jan 01 00:00:00 1970");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
735 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
736
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
737 /* Emulate sleep...we could have done this with a define, but that
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
738 would necessitate including windows.h in the files that used it.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
739 This is much easier. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
740
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
741 #ifndef HAVE_X_WINDOWS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
742 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
743 sys_sleep (int seconds)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
744 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
745 Sleep (seconds * 1000);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
746 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
747 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
748
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
749 /* Internal MSVC data and functions for low-level descriptor munging */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
750 #if (_MSC_VER == 900)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
751 extern char _osfile[];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
752 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
753 extern int __cdecl _set_osfhnd (int fd, long h);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
754 extern int __cdecl _free_osfhnd (int fd);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
755
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
756 /* parallel array of private info on file handles */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
757 filedesc fd_info [ MAXDESC ];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
758
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
759 static struct {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
760 DWORD serialnum;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
761 DWORD maxcomp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
762 DWORD flags;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
763 char name[32];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
764 char type[32];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
765 } volume_info;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
766
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
767 /* Get information on the volume where name is held; set path pointer to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
768 start of pathname in name (past UNC header\volume header if present). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
769 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
770 get_volume_info (const char * name, const char ** pPath)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
771 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
772 char temp[MAX_PATH];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
773 char *rootname = NULL; /* default to current volume */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
774
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
775 if (name == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
776 return FALSE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
777
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
778 /* find the root name of the volume if given */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
779 if (isalpha (name[0]) && name[1] == ':')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
780 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
781 rootname = temp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
782 temp[0] = *name++;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
783 temp[1] = *name++;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
784 temp[2] = '\\';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
785 temp[3] = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
786 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
787 else if (IS_DIRECTORY_SEP (name[0]) && IS_DIRECTORY_SEP (name[1]))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
788 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
789 char *str = temp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
790 int slashes = 4;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
791 rootname = temp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
792 do
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
793 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
794 if (IS_DIRECTORY_SEP (*name) && --slashes == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
795 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
796 *str++ = *name++;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
797 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
798 while ( *name );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
799
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
800 *str++ = '\\';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
801 *str = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
802 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
803
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
804 if (pPath)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
805 *pPath = name;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
806
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
807 if (GetVolumeInformation (rootname,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
808 volume_info.name, 32,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
809 &volume_info.serialnum,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
810 &volume_info.maxcomp,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
811 &volume_info.flags,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
812 volume_info.type, 32))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
813 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
814 return TRUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
815 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
816 return FALSE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
817 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
818
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
819 /* Determine if volume is FAT format (ie. only supports short 8.3
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
820 names); also set path pointer to start of pathname in name. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
821 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
822 is_fat_volume (const char * name, const char ** pPath)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
823 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
824 if (get_volume_info (name, pPath))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
825 return (volume_info.maxcomp == 12);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
826 return FALSE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
827 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
828
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
829 /* Map filename to a legal 8.3 name if necessary. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
830 const char *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
831 map_win32_filename (const char * name, const char ** pPath)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
832 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
833 static char shortname[MAX_PATH];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
834 char * str = shortname;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
835 char c;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
836 char * path;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
837
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
838 if (is_fat_volume (name, &path)) /* truncate to 8.3 */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
839 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
840 register int left = 8; /* maximum number of chars in part */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
841 register int extn = 0; /* extension added? */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
842 register int dots = 2; /* maximum number of dots allowed */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
843
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
844 while (name < path)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
845 *str++ = *name++; /* skip past UNC header */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
846
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
847 while ((c = *name++))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
848 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
849 switch ( c )
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
850 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
851 case '\\':
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
852 case '/':
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
853 *str++ = '\\';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
854 extn = 0; /* reset extension flags */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
855 dots = 2; /* max 2 dots */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
856 left = 8; /* max length 8 for main part */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
857 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
858 case ':':
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
859 *str++ = ':';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
860 extn = 0; /* reset extension flags */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
861 dots = 2; /* max 2 dots */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
862 left = 8; /* max length 8 for main part */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
863 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
864 case '.':
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
865 if ( dots )
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
866 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
867 /* Convert path components of the form .xxx to _xxx,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
868 but leave . and .. as they are. This allows .emacs
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
869 to be read as _emacs, for example. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
870
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
871 if (! *name ||
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
872 *name == '.' ||
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
873 IS_DIRECTORY_SEP (*name))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
874 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
875 *str++ = '.';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
876 dots--;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
877 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
878 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
879 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
880 *str++ = '_';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
881 left--;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
882 dots = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
883 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
884 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
885 else if ( !extn )
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
886 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
887 *str++ = '.';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
888 extn = 1; /* we've got an extension */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
889 left = 3; /* 3 chars in extension */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
890 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
891 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
892 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
893 /* any embedded dots after the first are converted to _ */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
894 *str++ = '_';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
895 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
896 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
897 case '~':
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
898 case '#': /* don't lose these, they're important */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
899 if ( ! left )
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
900 str[-1] = c; /* replace last character of part */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
901 /* FALLTHRU */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
902 default:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
903 if ( left )
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
904 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
905 *str++ = tolower (c); /* map to lower case (looks nicer) */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
906 left--;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
907 dots = 0; /* started a path component */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
908 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
909 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
910 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
911 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
912 *str = '\0';
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
913 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
914 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
915 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
916 strcpy (shortname, name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
917 unixtodos_filename (shortname);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
918 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
919
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
920 if (pPath)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
921 *pPath = shortname + (path - name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
922
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
923 return shortname;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
924 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
925
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
926
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
927 /* Shadow some MSVC runtime functions to map requests for long filenames
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
928 to reasonable short names if necessary. This was originally added to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
929 permit running Emacs on NT 3.1 on a FAT partition, which doesn't support
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
930 long file names. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
931
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
932 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
933 sys_access (const char * path, int mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
934 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
935 return _access (map_win32_filename (path, NULL), mode);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
936 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
937
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
938 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
939 sys_chdir (const char * path)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
940 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
941 return _chdir (map_win32_filename (path, NULL));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
942 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
943
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
944 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
945 sys_chmod (const char * path, int mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
946 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
947 return _chmod (map_win32_filename (path, NULL), mode);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
948 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
949
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
950 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
951 sys_creat (const char * path, int mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
952 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
953 return _creat (map_win32_filename (path, NULL), mode);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
954 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
955
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
956 FILE *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
957 sys_fopen(const char * path, const char * mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
958 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
959 int fd;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
960 int oflag;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
961 const char * mode_save = mode;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
962
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
963 /* Force all file handles to be non-inheritable. This is necessary to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
964 ensure child processes don't unwittingly inherit handles that might
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
965 prevent future file access. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
966
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
967 if (mode[0] == 'r')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
968 oflag = O_RDONLY;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
969 else if (mode[0] == 'w' || mode[0] == 'a')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
970 oflag = O_WRONLY | O_CREAT | O_TRUNC;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
971 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
972 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
973
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
974 /* Only do simplistic option parsing. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
975 while (*++mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
976 if (mode[0] == '+')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
977 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
978 oflag &= ~(O_RDONLY | O_WRONLY);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
979 oflag |= O_RDWR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
980 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
981 else if (mode[0] == 'b')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
982 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
983 oflag &= ~O_TEXT;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
984 oflag |= O_BINARY;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
985 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
986 else if (mode[0] == 't')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
987 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
988 oflag &= ~O_BINARY;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
989 oflag |= O_TEXT;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
990 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
991 else break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
992
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
993 fd = _open (map_win32_filename (path, NULL), oflag | _O_NOINHERIT, 0644);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
994 if (fd < 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
995 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
996
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
997 return fdopen (fd, mode_save);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
998 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
999
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1000 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1001 sys_link (const char * path1, const char * path2)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1002 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1003 errno = EINVAL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1004 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1005 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1006
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1007 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1008 sys_mkdir (const char * path)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1009 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1010 return _mkdir (map_win32_filename (path, NULL));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1011 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1012
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1013 /* Because of long name mapping issues, we need to implement this
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1014 ourselves. Also, MSVC's _mktemp returns NULL when it can't generate
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1015 a unique name, instead of setting the input template to an empty
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1016 string.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1017
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1018 Standard algorithm seems to be use pid or tid with a letter on the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1019 front (in place of the 6 X's) and cycle through the letters to find a
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1020 unique name. We extend that to allow any reasonable character as the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1021 first of the 6 X's. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1022 char *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1023 sys_mktemp (char * template)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1024 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1025 char * p;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1026 int i;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1027 unsigned uid = GetCurrentThreadId ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1028 static char first_char[] = "abcdefghijklmnopqrstuvwyz0123456789!%-_@#";
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1029
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1030 if (template == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1031 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1032 p = template + strlen (template);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1033 i = 5;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1034 /* replace up to the last 5 X's with uid in decimal */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1035 while (--p >= template && p[0] == 'X' && --i >= 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1036 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1037 p[0] = '0' + uid % 10;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1038 uid /= 10;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1039 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1040
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1041 if (i < 0 && p[0] == 'X')
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1042 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1043 i = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1044 do
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1045 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1046 int save_errno = errno;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1047 p[0] = first_char[i];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1048 if (sys_access (template, 0) < 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1049 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1050 errno = save_errno;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1051 return template;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1052 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1053 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1054 while (++i < sizeof (first_char));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1055 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1056
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1057 /* Template is badly formed or else we can't generate a unique name,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1058 so return empty string */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1059 template[0] = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1060 return template;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1061 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1062
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1063 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1064 sys_open (const char * path, int oflag, int mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1065 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1066 /* Force all file handles to be non-inheritable. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1067 return _open (map_win32_filename (path, NULL), oflag | _O_NOINHERIT, mode);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1068 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1069
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1070 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1071 sys_rename (const char * oldname, const char * newname)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1072 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1073 char temp[MAX_PATH];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1074 DWORD attr;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1075
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1076 /* MoveFile on Win95 doesn't correctly change the short file name
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1077 alias in a number of circumstances (it is not easy to predict when
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1078 just by looking at oldname and newname, unfortunately). In these
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1079 cases, renaming through a temporary name avoids the problem.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1080
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1081 A second problem on Win95 is that renaming through a temp name when
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1082 newname is uppercase fails (the final long name ends up in
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1083 lowercase, although the short alias might be uppercase) UNLESS the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1084 long temp name is not 8.3.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1085
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1086 So, on Win95 we always rename through a temp name, and we make sure
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1087 the temp name has a long extension to ensure correct renaming. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1088
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1089 strcpy (temp, map_win32_filename (oldname, NULL));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1090
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1091 if (GetVersion () & 0x80000000)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1092 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1093 char * p;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1094
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1095 if (p = strrchr (temp, '\\'))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1096 p++;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1097 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1098 p = temp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1099 strcpy (p, "__XXXXXX");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1100 sys_mktemp (temp);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1101 /* Force temp name to require a manufactured 8.3 alias - this
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1102 seems to make the second rename work properly. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1103 strcat (temp, ".long");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1104 if (rename (map_win32_filename (oldname, NULL), temp) < 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1105 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1106 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1107
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1108 /* Emulate Unix behaviour - newname is deleted if it already exists
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1109 (at least if it is a file; don't do this for directories).
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1110 However, don't do this if we are just changing the case of the file
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1111 name - we will end up deleting the file we are trying to rename! */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1112 newname = map_win32_filename (newname, NULL);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1113 if (stricmp (newname, temp) != 0
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1114 && (attr = GetFileAttributes (newname)) != -1
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1115 && (attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1116 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1117 _chmod (newname, 0666);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1118 _unlink (newname);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1119 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1120
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1121 return rename (temp, newname);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1122 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1123
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1124 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1125 sys_rmdir (const char * path)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1126 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1127 return _rmdir (map_win32_filename (path, NULL));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1128 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1129
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1130 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1131 sys_unlink (const char * path)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1132 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1133 return _unlink (map_win32_filename (path, NULL));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1134 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1135
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1136 static FILETIME utc_base_ft;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1137 static long double utc_base;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1138 static int init = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1139
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1140 static time_t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1141 convert_time (FILETIME ft)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1142 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1143 long double ret;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1144
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1145 if (!init)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1146 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1147 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1148 SYSTEMTIME st;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1149
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1150 st.wYear = 1970;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1151 st.wMonth = 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1152 st.wDay = 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1153 st.wHour = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1154 st.wMinute = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1155 st.wSecond = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1156 st.wMilliseconds = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1157
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1158 SystemTimeToFileTime (&st, &utc_base_ft);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1159 utc_base = (long double) utc_base_ft.dwHighDateTime
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1160 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1161 init = 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1162 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1163
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1164 if (CompareFileTime (&ft, &utc_base_ft) < 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1165 return 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1166
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1167 ret = (long double) ft.dwHighDateTime * 4096 * 1024 * 1024 + ft.dwLowDateTime;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1168 ret -= utc_base;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1169 return (time_t) (ret * 1e-7);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1170 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1171
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1172 #if 0
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1173 /* in case we ever have need of this */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1174 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1175 convert_from_time_t (time_t time, FILETIME * pft)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1176 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1177 long double tmp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1178
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1179 if (!init)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1180 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1181 /* Determine the delta between 1-Jan-1601 and 1-Jan-1970. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1182 SYSTEMTIME st;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1183
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1184 st.wYear = 1970;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1185 st.wMonth = 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1186 st.wDay = 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1187 st.wHour = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1188 st.wMinute = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1189 st.wSecond = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1190 st.wMilliseconds = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1191
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1192 SystemTimeToFileTime (&st, &utc_base_ft);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1193 utc_base = (long double) utc_base_ft.dwHighDateTime
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1194 * 4096 * 1024 * 1024 + utc_base_ft.dwLowDateTime;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1195 init = 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1196 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1197
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1198 /* time in 100ns units since 1-Jan-1601 */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1199 tmp = (long double) time * 1e7 + utc_base;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1200 pft->dwHighDateTime = (DWORD) (tmp / (4096.0 * 1024 * 1024));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1201 pft->dwLowDateTime = (DWORD) (tmp - pft->dwHighDateTime);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1202 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1203 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1204
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1205 /* "PJW" algorithm (see the "Dragon" compiler book). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1206 static unsigned
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1207 hashval (const char * str)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1208 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1209 unsigned h = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1210 unsigned g;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1211 while (*str)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1212 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1213 h = (h << 4) + *str++;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1214 if ((g = h & 0xf0000000) != 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1215 h = (h ^ (g >> 24)) & 0x0fffffff;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1216 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1217 return h;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1218 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1219
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1220 /* Return the hash value of the canonical pathname, excluding the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1221 drive/UNC header, to get a hopefully unique inode number. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1222 static _ino_t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1223 generate_inode_val (const char * name)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1224 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1225 char fullname[ MAX_PATH ];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1226 char * p;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1227 unsigned hash;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1228
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1229 GetFullPathName (name, sizeof (fullname), fullname, &p);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1230 get_volume_info (fullname, &p);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1231 /* Normal Win32 filesystems are still case insensitive. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1232 _strlwr (p);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1233 hash = hashval (p);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1234 return (_ino_t) (hash ^ (hash >> 16));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1235 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1236
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1237 /* MSVC stat function can't cope with UNC names and has other bugs, so
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1238 replace it with our own. This also allows us to calculate consistent
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1239 inode values without hacks in the main Emacs code. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1240 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1241 stat (const char * path, struct stat * buf)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1242 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1243 char * name;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1244 WIN32_FIND_DATA wfd;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1245 HANDLE fh;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1246 int permission;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1247 int len;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1248 int rootdir = FALSE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1249
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1250 if (path == NULL || buf == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1251 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1252 errno = EFAULT;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1253 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1254 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1255
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1256 name = (char *) map_win32_filename (path, &path);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1257 /* must be valid filename, no wild cards */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1258 if (strchr (name, '*') || strchr (name, '?'))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1259 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1260 errno = ENOENT;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1261 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1262 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1263
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1264 /* Remove trailing directory separator, unless name is the root
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1265 directory of a drive or UNC volume in which case ensure there
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1266 is a trailing separator. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1267 len = strlen (name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1268 rootdir = (path >= name + len - 1
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1269 && (IS_DIRECTORY_SEP (*path) || *path == 0));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1270 name = strcpy (alloca (len + 2), name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1271
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1272 if (rootdir)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1273 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1274 if (!IS_DIRECTORY_SEP (name[len-1]))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1275 strcat (name, "\\");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1276 if (GetDriveType (name) < 2)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1277 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1278 errno = ENOENT;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1279 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1280 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1281 memset (&wfd, 0, sizeof (wfd));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1282 wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1283 wfd.ftCreationTime = utc_base_ft;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1284 wfd.ftLastAccessTime = utc_base_ft;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1285 wfd.ftLastWriteTime = utc_base_ft;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1286 strcpy (wfd.cFileName, name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1287 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1288 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1289 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1290 if (IS_DIRECTORY_SEP (name[len-1]))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1291 name[len - 1] = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1292 fh = FindFirstFile (name, &wfd);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1293 if (fh == INVALID_HANDLE_VALUE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1294 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1295 errno = ENOENT;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1296 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1297 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1298 FindClose (fh);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1299 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1300
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1301 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1302 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1303 buf->st_mode = _S_IFDIR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1304 buf->st_nlink = 2; /* doesn't really matter */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1305 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1306 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1307 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1308 #if 0
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1309 /* This is more accurate in terms of gettting the correct number
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1310 of links, but is quite slow (it is noticable when Emacs is
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1311 making a list of file name completions). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1312 BY_HANDLE_FILE_INFORMATION info;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1313
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1314 fh = CreateFile (name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1315 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1316
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1317 if (GetFileInformationByHandle (fh, &info))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1318 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1319 switch (GetFileType (fh))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1320 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1321 case FILE_TYPE_DISK:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1322 buf->st_mode = _S_IFREG;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1323 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1324 case FILE_TYPE_PIPE:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1325 buf->st_mode = _S_IFIFO;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1326 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1327 case FILE_TYPE_CHAR:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1328 case FILE_TYPE_UNKNOWN:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1329 default:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1330 buf->st_mode = _S_IFCHR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1331 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1332 buf->st_nlink = info.nNumberOfLinks;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1333 /* Could use file index, but this is not guaranteed to be
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1334 unique unless we keep a handle open all the time. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1335 /* buf->st_ino = info.nFileIndexLow ^ info.nFileIndexHigh; */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1336 CloseHandle (fh);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1337 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1338 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1339 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1340 errno = EACCES;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1341 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1342 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1343 #else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1344 buf->st_mode = _S_IFREG;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1345 buf->st_nlink = 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1346 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1347 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1348
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1349 /* consider files to belong to current user */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1350 buf->st_uid = the_passwd.pw_uid;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1351 buf->st_gid = the_passwd.pw_gid;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1352
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1353 /* volume_info is set indirectly by map_win32_filename */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1354 buf->st_dev = volume_info.serialnum;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1355 buf->st_rdev = volume_info.serialnum;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1356
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1357 buf->st_ino = generate_inode_val (name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1358
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1359 buf->st_size = wfd.nFileSizeLow;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1360
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1361 /* Convert timestamps to Unix format. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1362 buf->st_mtime = convert_time (wfd.ftLastWriteTime);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1363 buf->st_atime = convert_time (wfd.ftLastAccessTime);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1364 if (buf->st_atime == 0) buf->st_atime = buf->st_mtime;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1365 buf->st_ctime = convert_time (wfd.ftCreationTime);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1366 if (buf->st_ctime == 0) buf->st_ctime = buf->st_mtime;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1367
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1368 /* determine rwx permissions */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1369 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1370 permission = _S_IREAD;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1371 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1372 permission = _S_IREAD | _S_IWRITE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1373
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1374 if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1375 permission |= _S_IEXEC;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1376 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1377 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1378 char * p = strrchr (name, '.');
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1379 if (p != NULL &&
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1380 (stricmp (p, ".exe") == 0 ||
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1381 stricmp (p, ".com") == 0 ||
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1382 stricmp (p, ".bat") == 0 ||
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1383 stricmp (p, ".cmd") == 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1384 permission |= _S_IEXEC;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1385 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1386
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1387 buf->st_mode |= permission | (permission >> 3) | (permission >> 6);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1388
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1389 return 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1390 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1391
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1392 #ifdef HAVE_SOCKETS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1393
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1394 /* Wrappers for winsock functions to map between our file descriptors
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1395 and winsock's handles; also set h_errno for convenience.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1396
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1397 To allow Emacs to run on systems which don't have winsock support
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1398 installed, we dynamically link to winsock on startup if present, and
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1399 otherwise provide the minimum necessary functionality
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1400 (eg. gethostname). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1401
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1402 /* function pointers for relevant socket functions */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1403 int (PASCAL *pfn_WSAStartup) (WORD wVersionRequired, LPWSADATA lpWSAData);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1404 void (PASCAL *pfn_WSASetLastError) (int iError);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1405 int (PASCAL *pfn_WSAGetLastError) (void);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1406 int (PASCAL *pfn_socket) (int af, int type, int protocol);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1407 int (PASCAL *pfn_bind) (SOCKET s, const struct sockaddr *addr, int namelen);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1408 int (PASCAL *pfn_connect) (SOCKET s, const struct sockaddr *addr, int namelen);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1409 int (PASCAL *pfn_ioctlsocket) (SOCKET s, long cmd, u_long *argp);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1410 int (PASCAL *pfn_recv) (SOCKET s, char * buf, int len, int flags);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1411 int (PASCAL *pfn_send) (SOCKET s, const char * buf, int len, int flags);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1412 int (PASCAL *pfn_closesocket) (SOCKET s);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1413 int (PASCAL *pfn_shutdown) (SOCKET s, int how);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1414 int (PASCAL *pfn_WSACleanup) (void);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1415
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1416 u_short (PASCAL *pfn_htons) (u_short hostshort);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1417 u_short (PASCAL *pfn_ntohs) (u_short netshort);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1418 unsigned long (PASCAL *pfn_inet_addr) (const char * cp);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1419 int (PASCAL *pfn_gethostname) (char * name, int namelen);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1420 struct hostent * (PASCAL *pfn_gethostbyname) (const char * name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1421 struct servent * (PASCAL *pfn_getservbyname) (const char * name, const char * proto);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1422
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1423 /* SetHandleInformation is only needed to make sockets non-inheritable. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1424 BOOL (WINAPI *pfn_SetHandleInformation) (HANDLE object, DWORD mask, DWORD flags);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1425 #ifndef HANDLE_FLAG_INHERIT
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1426 #define HANDLE_FLAG_INHERIT 1
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1427 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1428
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1429 HANDLE winsock_lib;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1430 static int winsock_inuse;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1431
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1432 BOOL
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1433 term_winsock (void)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1434 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1435 if (winsock_lib != NULL && winsock_inuse == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1436 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1437 /* Not sure what would cause WSAENETDOWN, or even if it can happen
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1438 after WSAStartup returns successfully, but it seems reasonable
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1439 to allow unloading winsock anyway in that case. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1440 if (pfn_WSACleanup () == 0 ||
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1441 pfn_WSAGetLastError () == WSAENETDOWN)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1442 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1443 if (FreeLibrary (winsock_lib))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1444 winsock_lib = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1445 return TRUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1446 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1447 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1448 return FALSE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1449 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1450
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1451 BOOL
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1452 init_winsock (int load_now)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1453 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1454 WSADATA winsockData;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1455
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1456 if (winsock_lib != NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1457 return TRUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1458
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1459 pfn_SetHandleInformation = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1460 pfn_SetHandleInformation
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1461 = (void *) GetProcAddress (GetModuleHandle ("kernel32.dll"),
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1462 "SetHandleInformation");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1463
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1464 winsock_lib = LoadLibrary ("wsock32.dll");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1465
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1466 if (winsock_lib != NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1467 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1468 /* dynamically link to socket functions */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1469
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1470 #define LOAD_PROC(fn) \
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1471 if ((pfn_##fn = (void *) GetProcAddress (winsock_lib, #fn)) == NULL) \
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1472 goto fail;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1473
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1474 LOAD_PROC( WSAStartup );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1475 LOAD_PROC( WSASetLastError );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1476 LOAD_PROC( WSAGetLastError );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1477 LOAD_PROC( socket );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1478 LOAD_PROC( bind );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1479 LOAD_PROC( connect );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1480 LOAD_PROC( ioctlsocket );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1481 LOAD_PROC( recv );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1482 LOAD_PROC( send );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1483 LOAD_PROC( closesocket );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1484 LOAD_PROC( shutdown );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1485 LOAD_PROC( htons );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1486 LOAD_PROC( ntohs );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1487 LOAD_PROC( inet_addr );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1488 LOAD_PROC( gethostname );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1489 LOAD_PROC( gethostbyname );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1490 LOAD_PROC( getservbyname );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1491 LOAD_PROC( WSACleanup );
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1492
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1493 #undef LOAD_PROC
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1494
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1495 /* specify version 1.1 of winsock */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1496 if (pfn_WSAStartup (0x101, &winsockData) == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1497 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1498 if (winsockData.wVersion != 0x101)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1499 goto fail;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1500
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1501 if (!load_now)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1502 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1503 /* Report that winsock exists and is usable, but leave
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1504 socket functions disabled. I am assuming that calling
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1505 WSAStartup does not require any network interaction,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1506 and in particular does not cause or require a dial-up
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1507 connection to be established. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1508
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1509 pfn_WSACleanup ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1510 FreeLibrary (winsock_lib);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1511 winsock_lib = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1512 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1513 winsock_inuse = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1514 return TRUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1515 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1516
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1517 fail:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1518 FreeLibrary (winsock_lib);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1519 winsock_lib = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1520 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1521
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1522 return FALSE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1523 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1524
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1525
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1526 int h_errno = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1527
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1528 /* function to set h_errno for compatability; map winsock error codes to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1529 normal system codes where they overlap (non-overlapping definitions
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1530 are already in <sys/socket.h> */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1531 static void set_errno ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1532 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1533 if (winsock_lib == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1534 h_errno = EINVAL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1535 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1536 h_errno = pfn_WSAGetLastError ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1537
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1538 switch (h_errno)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1539 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1540 case WSAEACCES: h_errno = EACCES; break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1541 case WSAEBADF: h_errno = EBADF; break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1542 case WSAEFAULT: h_errno = EFAULT; break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1543 case WSAEINTR: h_errno = EINTR; break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1544 case WSAEINVAL: h_errno = EINVAL; break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1545 case WSAEMFILE: h_errno = EMFILE; break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1546 case WSAENAMETOOLONG: h_errno = ENAMETOOLONG; break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1547 case WSAENOTEMPTY: h_errno = ENOTEMPTY; break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1548 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1549 errno = h_errno;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1550 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1551
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1552 static void check_errno ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1553 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1554 if (h_errno == 0 && winsock_lib != NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1555 pfn_WSASetLastError (0);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1556 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1557
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1558 /* [andrewi 3-May-96] I've had conflicting results using both methods,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1559 but I believe the method of keeping the socket handle separate (and
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1560 insuring it is not inheritable) is the correct one. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1561
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1562 //#define SOCK_REPLACE_HANDLE
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1563
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1564 #ifdef SOCK_REPLACE_HANDLE
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1565 #define SOCK_HANDLE(fd) ((SOCKET) _get_osfhandle (fd))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1566 #else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1567 #define SOCK_HANDLE(fd) ((SOCKET) fd_info[fd].hnd)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1568 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1569
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1570 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1571 sys_socket(int af, int type, int protocol)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1572 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1573 int fd;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1574 long s;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1575 child_process * cp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1576
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1577 if (winsock_lib == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1578 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1579 h_errno = ENETDOWN;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1580 return INVALID_SOCKET;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1581 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1582
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1583 check_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1584
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1585 /* call the real socket function */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1586 s = (long) pfn_socket (af, type, protocol);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1587
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1588 if (s != INVALID_SOCKET)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1589 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1590 /* Although under NT 3.5 _open_osfhandle will accept a socket
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1591 handle, if opened with SO_OPENTYPE == SO_SYNCHRONOUS_NONALERT,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1592 that does not work under NT 3.1. However, we can get the same
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1593 effect by using a backdoor function to replace an existing
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1594 descriptor handle with the one we want. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1595
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1596 /* allocate a file descriptor (with appropriate flags) */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1597 fd = _open ("NUL:", _O_RDWR);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1598 if (fd >= 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1599 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1600 #ifdef SOCK_REPLACE_HANDLE
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1601 /* now replace handle to NUL with our socket handle */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1602 CloseHandle ((HANDLE) _get_osfhandle (fd));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1603 _free_osfhnd (fd);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1604 _set_osfhnd (fd, s);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1605 /* setmode (fd, _O_BINARY); */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1606 #else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1607 /* Make a non-inheritable copy of the socket handle. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1608 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1609 HANDLE parent;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1610 HANDLE new_s = INVALID_HANDLE_VALUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1611
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1612 parent = GetCurrentProcess ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1613
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1614 /* Apparently there is a bug in NT 3.51 with some service
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1615 packs, which prevents using DuplicateHandle to make a
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1616 socket handle non-inheritable (causes WSACleanup to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1617 hang). The work-around is to use SetHandleInformation
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1618 instead if it is available and implemented. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1619 if (!pfn_SetHandleInformation
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1620 || !pfn_SetHandleInformation ((HANDLE) s,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1621 HANDLE_FLAG_INHERIT,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1622 HANDLE_FLAG_INHERIT))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1623 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1624 DuplicateHandle (parent,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1625 (HANDLE) s,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1626 parent,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1627 &new_s,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1628 0,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1629 FALSE,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1630 DUPLICATE_SAME_ACCESS);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1631 pfn_closesocket (s);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1632 s = (SOCKET) new_s;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1633 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1634 fd_info[fd].hnd = (HANDLE) s;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1635 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1636 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1637
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1638 /* set our own internal flags */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1639 fd_info[fd].flags = FILE_SOCKET | FILE_BINARY | FILE_READ | FILE_WRITE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1640
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1641 cp = new_child ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1642 if (cp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1643 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1644 cp->fd = fd;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1645 cp->status = STATUS_READ_ACKNOWLEDGED;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1646
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1647 /* attach child_process to fd_info */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1648 if (fd_info[ fd ].cp != NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1649 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1650 DebPrint (("sys_socket: fd_info[%d] apparently in use!\n", fd));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1651 abort ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1652 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1653
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1654 fd_info[ fd ].cp = cp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1655
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1656 /* success! */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1657 winsock_inuse++; /* count open sockets */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1658 return fd;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1659 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1660
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1661 /* clean up */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1662 _close (fd);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1663 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1664 pfn_closesocket (s);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1665 h_errno = EMFILE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1666 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1667 set_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1668
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1669 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1670 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1671
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1672
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1673 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1674 sys_bind (int s, const struct sockaddr * addr, int namelen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1675 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1676 if (winsock_lib == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1677 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1678 h_errno = ENOTSOCK;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1679 return SOCKET_ERROR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1680 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1681
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1682 check_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1683 if (fd_info[s].flags & FILE_SOCKET)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1684 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1685 int rc = pfn_bind (SOCK_HANDLE (s), addr, namelen);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1686 if (rc == SOCKET_ERROR)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1687 set_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1688 return rc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1689 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1690 h_errno = ENOTSOCK;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1691 return SOCKET_ERROR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1692 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1693
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1694
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1695 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1696 sys_connect (int s, const struct sockaddr * name, int namelen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1697 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1698 if (winsock_lib == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1699 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1700 h_errno = ENOTSOCK;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1701 return SOCKET_ERROR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1702 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1703
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1704 check_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1705 if (fd_info[s].flags & FILE_SOCKET)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1706 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1707 int rc = pfn_connect (SOCK_HANDLE (s), name, namelen);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1708 if (rc == SOCKET_ERROR)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1709 set_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1710 return rc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1711 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1712 h_errno = ENOTSOCK;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1713 return SOCKET_ERROR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1714 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1715
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1716 u_short
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1717 sys_htons (u_short hostshort)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1718 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1719 return (winsock_lib != NULL) ?
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1720 pfn_htons (hostshort) : hostshort;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1721 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1722
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1723 u_short
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1724 sys_ntohs (u_short netshort)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1725 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1726 return (winsock_lib != NULL) ?
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1727 pfn_ntohs (netshort) : netshort;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1728 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1729
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1730 unsigned long
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1731 sys_inet_addr (const char * cp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1732 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1733 return (winsock_lib != NULL) ?
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1734 pfn_inet_addr (cp) : INADDR_NONE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1735 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1736
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1737 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1738 sys_gethostname (char * name, int namelen)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1739 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1740 if (winsock_lib != NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1741 return pfn_gethostname (name, namelen);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1742
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1743 if (namelen > MAX_COMPUTERNAME_LENGTH)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1744 return !GetComputerName (name, &namelen);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1745
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1746 h_errno = EFAULT;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1747 return SOCKET_ERROR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1748 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1749
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1750 struct hostent *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1751 sys_gethostbyname(const char * name)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1752 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1753 struct hostent * host;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1754
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1755 if (winsock_lib == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1756 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1757 h_errno = ENETDOWN;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1758 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1759 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1760
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1761 check_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1762 host = pfn_gethostbyname (name);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1763 if (!host)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1764 set_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1765 return host;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1766 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1767
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1768 struct servent *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1769 sys_getservbyname(const char * name, const char * proto)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1770 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1771 struct servent * serv;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1772
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1773 if (winsock_lib == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1774 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1775 h_errno = ENETDOWN;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1776 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1777 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1778
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1779 check_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1780 serv = pfn_getservbyname (name, proto);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1781 if (!serv)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1782 set_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1783 return serv;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1784 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1785
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1786 #endif /* HAVE_SOCKETS */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1787
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1788
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1789 /* Shadow main io functions: we need to handle pipes and sockets more
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1790 intelligently, and implement non-blocking mode as well. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1791
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1792 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1793 sys_close (int fd)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1794 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1795 int rc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1796
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1797 if (fd < 0 || fd >= MAXDESC)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1798 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1799 errno = EBADF;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1800 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1801 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1802
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1803 if (fd_info[fd].cp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1804 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1805 child_process * cp = fd_info[fd].cp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1806
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1807 fd_info[fd].cp = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1808
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1809 if (CHILD_ACTIVE (cp))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1810 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1811 /* if last descriptor to active child_process then cleanup */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1812 int i;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1813 for (i = 0; i < MAXDESC; i++)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1814 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1815 if (i == fd)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1816 continue;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1817 if (fd_info[i].cp == cp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1818 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1819 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1820 if (i == MAXDESC)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1821 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1822 #ifdef HAVE_SOCKETS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1823 if (fd_info[fd].flags & FILE_SOCKET)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1824 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1825 #ifndef SOCK_REPLACE_HANDLE
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1826 if (winsock_lib == NULL) abort ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1827
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1828 pfn_shutdown (SOCK_HANDLE (fd), 2);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1829 rc = pfn_closesocket (SOCK_HANDLE (fd));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1830 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1831 winsock_inuse--; /* count open sockets */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1832 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1833 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1834 delete_child (cp);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1835 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1836 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1837 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1838
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1839 /* Note that sockets do not need special treatment here (at least on
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1840 NT and Win95 using the standard tcp/ip stacks) - it appears that
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1841 closesocket is equivalent to CloseHandle, which is to be expected
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1842 because socket handles are fully fledged kernel handles. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1843 rc = _close (fd);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1844
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1845 if (rc == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1846 fd_info[fd].flags = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1847
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1848 return rc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1849 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1850
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1851 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1852 sys_dup (int fd)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1853 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1854 int new_fd;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1855
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1856 new_fd = _dup (fd);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1857 if (new_fd >= 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1858 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1859 /* duplicate our internal info as well */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1860 fd_info[new_fd] = fd_info[fd];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1861 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1862 return new_fd;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1863 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1864
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1865
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1866 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1867 sys_dup2 (int src, int dst)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1868 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1869 int rc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1870
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1871 if (dst < 0 || dst >= MAXDESC)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1872 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1873 errno = EBADF;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1874 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1875 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1876
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1877 /* make sure we close the destination first if it's a pipe or socket */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1878 if (src != dst && fd_info[dst].flags != 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1879 sys_close (dst);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1880
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1881 rc = _dup2 (src, dst);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1882 if (rc == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1883 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1884 /* duplicate our internal info as well */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1885 fd_info[dst] = fd_info[src];
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1886 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1887 return rc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1888 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1889
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1890 /* From callproc.c */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1891 extern Lisp_Object Vbinary_process_input;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1892 extern Lisp_Object Vbinary_process_output;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1893
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1894 /* Unix pipe() has only one arg */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1895 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1896 sys_pipe (int * phandles)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1897 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1898 int rc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1899 unsigned flags;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1900 child_process * cp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1901
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1902 /* make pipe handles non-inheritable; when we spawn a child,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1903 we replace the relevant handle with an inheritable one. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1904 rc = _pipe (phandles, 0, _O_NOINHERIT);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1905
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1906 if (rc == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1907 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1908 /* set internal flags, and put read and write handles into binary
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1909 mode as necessary; if not in binary mode, set the MSVC internal
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1910 FDEV (0x40) flag to prevent _read from treating ^Z as eof (this
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1911 could otherwise allow Emacs to hang because it then waits
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1912 indefinitely for the child process to exit, when it might not be
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1913 finished). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1914 flags = FILE_PIPE | FILE_READ;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1915 if (!NILP (Vbinary_process_output))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1916 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1917 flags |= FILE_BINARY;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1918 setmode (phandles[0], _O_BINARY);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1919 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1920 #if (_MSC_VER == 900)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1921 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1922 _osfile[phandles[0]] |= 0x40;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1923 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1924
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1925 fd_info[phandles[0]].flags = flags;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1926
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1927 flags = FILE_PIPE | FILE_WRITE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1928 if (!NILP (Vbinary_process_input))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1929 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1930 flags |= FILE_BINARY;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1931 setmode (phandles[1], _O_BINARY);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1932 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1933 #if (_MSC_VER == 900)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1934 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1935 _osfile[phandles[1]] |= 0x40;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1936 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1937
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1938 fd_info[phandles[1]].flags = flags;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1939 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1940
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1941 return rc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1942 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1943
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1944 /* From ntproc.c */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1945 extern Lisp_Object Vwin32_pipe_read_delay;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1946
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1947 /* Function to do blocking read of one byte, needed to implement
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1948 select. It is only allowed on sockets and pipes. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1949 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1950 _sys_read_ahead (int fd)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1951 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1952 child_process * cp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1953 int rc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1954
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1955 if (fd < 0 || fd >= MAXDESC)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1956 return STATUS_READ_ERROR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1957
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1958 cp = fd_info[fd].cp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1959
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1960 if (cp == NULL || cp->fd != fd || cp->status != STATUS_READ_READY)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1961 return STATUS_READ_ERROR;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1962
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1963 if ((fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET)) == 0
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1964 || (fd_info[fd].flags & FILE_READ) == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1965 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1966 DebPrint (("_sys_read_ahead: internal error: fd %d is not a pipe or socket!\n", fd));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1967 abort ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1968 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1969
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1970 cp->status = STATUS_READ_IN_PROGRESS;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1971
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1972 if (fd_info[fd].flags & FILE_PIPE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1973 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1974 /* Use read to get CRLF translation */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1975 rc = _read (fd, &cp->chr, sizeof (char));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1976
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1977 /* Give subprocess time to buffer some more output for us before
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1978 reporting that input is available; we need this because Win95
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1979 connects DOS programs to pipes by making the pipe appear to be
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1980 the normal console stdout - as a result most DOS programs will
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1981 write to stdout without buffering, ie. one character at a
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1982 time. Even some Win32 programs do this - "dir" in a command
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1983 shell on NT is very slow if we don't do this. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1984 if (rc > 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1985 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1986 int wait = XINT (Vwin32_pipe_read_delay);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1987
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1988 if (wait > 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1989 Sleep (wait);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1990 else if (wait < 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1991 while (++wait <= 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1992 /* Yield remainder of our time slice, effectively giving a
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1993 temporary priority boost to the child process. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1994 Sleep (0);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1995 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1996 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1997 #ifdef HAVE_SOCKETS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1998 else if (fd_info[fd].flags & FILE_SOCKET)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1999 rc = pfn_recv (SOCK_HANDLE (fd), &cp->chr, sizeof (char), 0);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2000 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2001
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2002 if (rc == sizeof (char))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2003 cp->status = STATUS_READ_SUCCEEDED;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2004 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2005 cp->status = STATUS_READ_FAILED;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2006
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2007 return cp->status;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2008 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2009
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2010 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2011 sys_read (int fd, char * buffer, unsigned int count)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2012 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2013 int nchars;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2014 int extra = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2015 int to_read;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2016 DWORD waiting;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2017
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2018 if (fd < 0 || fd >= MAXDESC)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2019 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2020 errno = EBADF;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2021 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2022 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2023
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2024 if (fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2025 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2026 child_process *cp = fd_info[fd].cp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2027
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2028 if ((fd_info[fd].flags & FILE_READ) == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2029 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2030 errno = EBADF;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2031 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2032 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2033
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2034 /* presence of a child_process structure means we are operating in
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2035 non-blocking mode - otherwise we just call _read directly.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2036 Note that the child_process structure might be missing because
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2037 reap_subprocess has been called; in this case the pipe is
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2038 already broken, so calling _read on it is okay. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2039 if (cp)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2040 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2041 int current_status = cp->status;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2042
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2043 switch (current_status)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2044 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2045 case STATUS_READ_FAILED:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2046 case STATUS_READ_ERROR:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2047 /* report normal EOF */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2048 return 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2049
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2050 case STATUS_READ_READY:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2051 case STATUS_READ_IN_PROGRESS:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2052 DebPrint (("sys_read called when read is in progress\n"));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2053 errno = EWOULDBLOCK;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2054 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2055
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2056 case STATUS_READ_SUCCEEDED:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2057 /* consume read-ahead char */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2058 *buffer++ = cp->chr;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2059 count--;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2060 extra = 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2061 cp->status = STATUS_READ_ACKNOWLEDGED;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2062 ResetEvent (cp->char_avail);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2063
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2064 case STATUS_READ_ACKNOWLEDGED:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2065 break;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2066
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2067 default:
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2068 DebPrint (("sys_read: bad status %d\n", current_status));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2069 errno = EBADF;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2070 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2071 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2072
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2073 if (fd_info[fd].flags & FILE_PIPE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2074 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2075 PeekNamedPipe ((HANDLE) _get_osfhandle (fd), NULL, 0, NULL, &waiting, NULL);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2076 to_read = min (waiting, (DWORD) count);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2077
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2078 /* Use read to get CRLF translation */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2079 nchars = _read (fd, buffer, to_read);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2080 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2081 #ifdef HAVE_SOCKETS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2082 else /* FILE_SOCKET */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2083 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2084 if (winsock_lib == NULL) abort ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2085
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2086 /* do the equivalent of a non-blocking read */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2087 pfn_ioctlsocket (SOCK_HANDLE (fd), FIONREAD, &waiting);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2088 if (waiting == 0 && extra == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2089 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2090 h_errno = errno = EWOULDBLOCK;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2091 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2092 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2093
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2094 nchars = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2095 if (waiting)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2096 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2097 /* always use binary mode for sockets */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2098 nchars = pfn_recv (SOCK_HANDLE (fd), buffer, count, 0);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2099 if (nchars == SOCKET_ERROR)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2100 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2101 DebPrint(("sys_read.recv failed with error %d on socket %ld\n",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2102 pfn_WSAGetLastError (), SOCK_HANDLE (fd)));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2103 if (extra == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2104 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2105 set_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2106 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2107 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2108 nchars = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2109 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2110 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2111 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2112 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2113 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2114 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2115 nchars = _read (fd, buffer, count);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2116 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2117 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2118 nchars = _read (fd, buffer, count);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2119
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2120 return nchars + extra;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2121 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2122
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2123 /* For now, don't bother with a non-blocking mode */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2124 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2125 sys_write (int fd, const void * buffer, unsigned int count)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2126 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2127 int nchars;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2128
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2129 if (fd < 0 || fd >= MAXDESC)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2130 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2131 errno = EBADF;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2132 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2133 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2134
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2135 if (fd_info[fd].flags & (FILE_PIPE | FILE_SOCKET))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2136 if ((fd_info[fd].flags & FILE_WRITE) == 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2137 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2138 errno = EBADF;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2139 return -1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2140 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2141 #ifdef HAVE_SOCKETS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2142 if (fd_info[fd].flags & FILE_SOCKET)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2143 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2144 if (winsock_lib == NULL) abort ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2145 nchars = pfn_send (SOCK_HANDLE (fd), buffer, count, 0);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2146 if (nchars == SOCKET_ERROR)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2147 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2148 DebPrint(("sys_read.send failed with error %d on socket %ld\n",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2149 pfn_WSAGetLastError (), SOCK_HANDLE (fd)));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2150 set_errno ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2151 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2152 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2153 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2154 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2155 nchars = _write (fd, buffer, count);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2156
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2157 return nchars;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2158 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2159
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2160
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2161 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2162 term_ntproc ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2163 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2164 #ifdef HAVE_SOCKETS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2165 /* shutdown the socket interface if necessary */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2166 term_winsock ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2167 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2168 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2169
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2170 extern BOOL dos_process_running;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2171
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2172 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2173 init_ntproc ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2174 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2175 #ifdef HAVE_SOCKETS
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2176 /* Initialise the socket interface now if available and requested by
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2177 the user by defining PRELOAD_WINSOCK; otherwise loading will be
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2178 delayed until open-network-stream is called (win32-has-winsock can
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2179 also be used to dynamically load or reload winsock).
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2180
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2181 Conveniently, init_environment is called before us, so
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2182 PRELOAD_WINSOCK can be set in the registry. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2183
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2184 /* Always initialize this correctly. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2185 winsock_lib = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2186
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2187 if (getenv ("PRELOAD_WINSOCK") != NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2188 init_winsock (TRUE);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2189 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2190
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2191 /* Initial preparation for subprocess support: replace our standard
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2192 handles with non-inheritable versions. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2193 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2194 HANDLE parent;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2195 HANDLE stdin_save = INVALID_HANDLE_VALUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2196 HANDLE stdout_save = INVALID_HANDLE_VALUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2197 HANDLE stderr_save = INVALID_HANDLE_VALUE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2198
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2199 parent = GetCurrentProcess ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2200
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2201 /* ignore errors when duplicating and closing; typically the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2202 handles will be invalid when running as a gui program. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2203 DuplicateHandle (parent,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2204 GetStdHandle (STD_INPUT_HANDLE),
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2205 parent,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2206 &stdin_save,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2207 0,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2208 FALSE,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2209 DUPLICATE_SAME_ACCESS);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2210
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2211 DuplicateHandle (parent,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2212 GetStdHandle (STD_OUTPUT_HANDLE),
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2213 parent,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2214 &stdout_save,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2215 0,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2216 FALSE,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2217 DUPLICATE_SAME_ACCESS);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2218
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2219 DuplicateHandle (parent,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2220 GetStdHandle (STD_ERROR_HANDLE),
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2221 parent,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2222 &stderr_save,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2223 0,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2224 FALSE,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2225 DUPLICATE_SAME_ACCESS);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2226
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2227 fclose (stdin);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2228 fclose (stdout);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2229 fclose (stderr);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2230
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2231 if (stdin_save != INVALID_HANDLE_VALUE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2232 _open_osfhandle ((long) stdin_save, O_TEXT);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2233 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2234 _open ("nul", O_TEXT | O_NOINHERIT | O_RDONLY);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2235 fdopen (0, "r");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2236
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2237 if (stdout_save != INVALID_HANDLE_VALUE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2238 _open_osfhandle ((long) stdout_save, O_TEXT);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2239 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2240 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2241 fdopen (1, "w");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2242
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2243 if (stderr_save != INVALID_HANDLE_VALUE)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2244 _open_osfhandle ((long) stderr_save, O_TEXT);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2245 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2246 _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2247 fdopen (2, "w");
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2248 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2249
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2250 /* Restrict Emacs to running only one DOS program at a time (with any
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2251 number of Win32 programs). This is to prevent the user from
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2252 running into problems with DOS programs being run in the same VDM
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2253 under both Windows 95 and Windows NT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2254
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2255 Note that it is possible for Emacs to run DOS programs in separate
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2256 VDMs, but unfortunately the pipe implementation on Windows 95 then
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2257 fails to report when the DOS process exits (which is supposed to
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2258 break the pipe). Until this bug is fixed, or we can devise a
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2259 work-around, we must try to avoid letting the user start more than
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2260 one DOS program if possible. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2261
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2262 dos_process_running = FALSE;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2263
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2264 /* unfortunately, atexit depends on implementation of malloc */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2265 /* atexit (term_ntproc); */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2266 signal (SIGABRT, term_ntproc);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2267 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2268
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2269 #ifndef HAVE_TTY
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2270 Lisp_Object Vstdio_str;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2271
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2272 Lisp_Object
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2273 tty_semi_canonicalize_console_connection (Lisp_Object connection,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2274 Error_behavior errb)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2275 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2276 return Vstdio_str;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2277 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2278
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2279 Lisp_Object
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2280 tty_canonicalize_console_connection (Lisp_Object connection,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2281 Error_behavior errb)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2282 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2283 return Vstdio_str;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2284 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2285
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2286 Lisp_Object
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2287 tty_semi_canonicalize_device_connection (Lisp_Object connection,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2288 Error_behavior errb)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2289 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2290 return Vstdio_str;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2291 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2292
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2293 Lisp_Object
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2294 tty_canonicalize_device_connection (Lisp_Object connection,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2295 Error_behavior errb)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2296 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2297 return Vstdio_str;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2298 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2299 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2300
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2301 /* end of nt.c */