annotate src/sysdep.c @ 185:3d6bfa290dbd r20-3b19

Import from CVS: tag r20-3b19
author cvs
date Mon, 13 Aug 2007 09:55:28 +0200
parents 9ad43877534d
children b405438285a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Interfaces to system-dependent kernel and library entries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Tinker Systems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: FSF 19.30 except for some Windows-NT crap. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* Substantially cleaned up by Ben Wing, Dec. 1994 / Jan. 1995. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 /* In this file, open, read and write refer to the system calls,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 not our sugared interfaces sys_open, sys_read and sys_write.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #define DONT_ENCAPSULATE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 /* ------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 /* basic includes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 /* ------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include "console-tty.h"
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
41 #else
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
42 #include "syssignal.h"
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
43 #include "systty.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #endif /* HAVE_TTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include "console-stream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #include "redisplay.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #include "process.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #include "sysdep.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include "window.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #include <setjmp.h>
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
57 #ifdef HAVE_LIBGEN_H /* Must come before sysfile.h */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58 #include <libgen.h>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
59 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #include "sysfile.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #include "syswait.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 #include "sysdir.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #include "systime.h"
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
64 #if defined(WINDOWSNT)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
65 #include "syssignal.h"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
66 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 #include <sys/times.h>
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
68 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
70 #ifdef WINDOWSNT
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
71 #include <direct.h>
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
72 /* In process.h which conflicts with the local copy. */
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
73 #define _P_WAIT 0
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
74 int _CRTAPI1 _spawnlp (int, const char *, const char *, ...);
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
75 int _CRTAPI1 _getpid (void);
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
76 #endif
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
77
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 /* ------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 /* VMS includes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 /* ------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 #include <ttdef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 #include <tt2def.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 #include <iodef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 #include <ssdef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 #include <descrip.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 #include <fibdef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 #include <atrdef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 #undef F_SETFL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 #ifndef RAB/*$C_BID -- suppress compiler warnings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 #include <rab.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 /* ------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 /* TTY definitions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 /* ------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 #ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 #include <sys/utsname.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 #if defined (TIOCGWINSZ) || defined (ISC4_0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 #ifdef NEED_SIOCTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 #include <sys/sioctl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #ifdef NEED_PTEM_H
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 #include <sys/stream.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #include <sys/ptem.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 #endif /* TIOCGWINSZ or ISC4_0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 #endif /* USG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 #ifdef HAVE_SYS_STROPTS_H
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
115 #include <sys/stropts.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 #endif /* HAVE_SYS_STROPTS_H */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 #ifndef LPASS8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 #define LPASS8 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 #ifndef HAVE_H_ERRNO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 int h_errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 static int baud_convert[] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 #ifdef BAUD_CONVERT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 BAUD_CONVERT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 1800, 2400, 4800, 9600, 19200, 38400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 #ifdef AIXHFT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 static void hft_init (struct console *c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 static void hft_reset (struct console *c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 /* ------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 /* miscellaneous */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 /* ------------------------------- */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 #ifndef HAVE_UTIMES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 #ifndef HAVE_STRUCT_UTIMBUF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 /* We want to use utime rather than utimes, but we couldn't find the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 structure declaration. We'll use the traditional one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 struct utimbuf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 long actime;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 long modtime;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 /* subprocess control */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 #ifdef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 /* Arrange for character C to be read as the next input from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 the terminal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 stuff_char (struct console *con, int c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 int input_fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 assert (CONSOLE_TTY_P (con));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 input_fd = CONSOLE_TTY_DATA (con)->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 /* Should perhaps error if in batch mode */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 #ifdef TIOCSTI
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ioctl (input_fd, TIOCSTI, &c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 #else /* no TIOCSTI */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 error ("Cannot stuff terminal input characters in this version of Unix.");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 #endif /* no TIOCSTI */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 #endif /* SIGTSTP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 #endif /* HAVE_TTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 set_exclusive_use (int fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 #ifdef FIOCLEX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ioctl (fd, FIOCLEX, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 /* Ok to do nothing if this feature does not exist */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 set_descriptor_non_blocking (int fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 /* Stride people say it's a mystery why this is needed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 as well as the O_NDELAY, but that it fails without this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 /* For AIX: Apparently need this for non-blocking reads on sockets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 It seems that O_NONBLOCK applies only to FIFOs? From
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 lowry@watson.ibm.com (Andy Lowry). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 /* #### Should this be conditionalized on FIONBIO? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 #if defined (STRIDE) || (defined (pfa) && defined (HAVE_PTYS)) || defined (AIX)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 int one = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ioctl (fd, FIONBIO, &one);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 #ifdef O_NONBLOCK /* The POSIX way */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 fcntl (fd, F_SETFL, O_NONBLOCK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 #elif defined (O_NDELAY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 fcntl (fd, F_SETFL, O_NDELAY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 #endif /* O_NONBLOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 #if defined (NO_SUBPROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 #ifdef BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 wait_without_blocking (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 wait3 (0, WNOHANG | WUNTRACED, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 synch_process_alive = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 #endif /* BSD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 #endif /* NO_SUBPROCESSES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 wait_for_termination (int pid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 /* #### With the new improved SIGCHLD handling stuff, there is much
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 less danger of race conditions and some of the comments below
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 don't apply. This should be updated. */
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
244
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
245 #if defined (NO_SUBPROCESSES)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 {
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
248 /* No need to be tricky like below; we can just call wait(). */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
249 /* #### should figure out how to write a wait_allowing_quit().
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
250 Since hardly any systems don't have subprocess support,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
251 however, there doesn't seem to be much point. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
252 if (wait (0) == pid)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
253 return;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
254 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
255 #elif defined (VMS)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
256 int status = SYS$FORCEX (&pid, 0, 0);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
257 return;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
258
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
259 #elif defined (HAVE_WAITPID)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
260 /* Note that, whenever any subprocess terminates (asynch. or synch.),
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
261 the SIGCHLD handler will be called and it will call wait(). Thus
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
262 we cannot just call wait() ourselves, and we can't block SIGCHLD
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
263 and then call wait(), because then if an asynch. process dies
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
264 while we're waiting for our synch. process, Emacs will never
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
265 notice that the asynch. process died.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
266
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
267 So, the general approach we take is to repeatedly block until a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
268 signal arrives, and then check if our process died using kill
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
269 (pid, 0). (We could also check the value of `synch_process_alive',
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
270 since the SIGCHLD handler will reset that and we know that we're
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
271 only being called on synchronous processes, but this approach is
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
272 safer. I don't trust the proper delivery of SIGCHLD.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
273
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
274 Note also that we cannot use any form of waitpid(). A loop with
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
275 WNOHANG will chew up CPU time; better to use sleep(). A loop
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
276 without WNOWAIT will screw up the SIGCHLD handler (actually this
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
277 is not true, if you duplicate the exit-status-reaping code; see
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
278 below). A loop with WNOWAIT will result in a race condition if
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
279 the process terminates between the process-status check and the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
280 call to waitpid(). */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
281
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
282 /* Formerly, immediate_quit was set around this function call, but
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
283 that could lead to problems if the QUIT happened when SIGCHLD was
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
284 blocked -- it would remain blocked. Yet another reason why
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
285 immediate_quit is a bad idea. In any case, there is no reason to
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
286 resort to this because either the SIGIO or the SIGALRM will stop
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
287 the block in EMACS_WAIT_FOR_SIGNAL(). */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
288
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
289 /* Apparently there are bugs on some systems with the second method
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
290 used below (the EMACS_BLOCK_SIGNAL method), whereby zombie
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
291 processes get left around. It appears in those cases that the
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
292 SIGCHLD handler is never getting invoked. It's not clear whether
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
293 this is an Emacs bug or a kernel bug or both: on HPUX this
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
294 problem is observed only with XEmacs, but under Solaris 2.4 all
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
295 sorts of different programs have problems with zombies. The
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
296 method we use here does not require a working SIGCHLD (but will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
297 not break if it is working), and should be safe. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
298 /*
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
299 We use waitpid(), contrary to the remarks above. There is no
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
300 race condition, because the three situations when sigchld_handler
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
301 is invoked should be handled OK:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
302
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
303 - handler invoked before waitpid(): In this case, subprocess
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
304 status will be set by sigchld_handler. waitpid() here will
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
305 return -1 with errno set to ECHILD, which is a valid exit
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
306 condition.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
307
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
308 - handler invoked during waitpid(): as above, except that errno
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
309 here will be set to EINTR. This will cause waitpid() to be
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
310 called again, and this time it will exit with ECHILD.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
311
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
312 - handler invoked after waitpid(): The following code will reap
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
313 the subprocess. In the handler, wait() will return -1 because
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
314 there is no child to reap, and the handler will exit without
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
315 modifying child subprocess status. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
316 int ret, status;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
317
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
318 /* Because the SIGCHLD handler can potentially reap the synchronous
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
319 subprocess, we should take care of that. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
320
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
321 /* Will stay in the do loop as long as:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
322 1. Process is alive
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
323 2. Ctrl-G is not pressed */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
324 do
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
325 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 QUIT;
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
327 ret = waitpid (pid, &status, 0);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
328 /* waitpid returns 0 if the process is still alive. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
329 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
330 while (ret == 0 || (ret == -1 && errno == EINTR));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
331
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
332 if (ret == pid) /* Success */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
333 /* Set synch process globals. This is can also happen
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
334 in sigchld_handler, and that code is duplicated. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
335 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
336 synch_process_alive = 0;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
337 if (WIFEXITED (status))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
338 synch_process_retcode = WEXITSTATUS (status);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
339 else if (WIFSIGNALED (status))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
340 synch_process_death = signal_name (WTERMSIG (status));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
341 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
342 /* On exiting the loop, ret will be -1, with errno set to ECHILD if
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
343 the child has already been reaped, e.g. in the signal handler. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
344
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
345 /* Otherwise, we've had some error condition here.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
346 Per POSIX, the only other possibilities are:
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
347 - EFAULT (bus error accessing arg 2) or
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
348 - EINVAL (incorrect arguments),
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
349 which are both program bugs.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
350
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
351 Since implementations may add their own error indicators on top,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
352 we ignore it by default. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
353 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
354 while (1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
355 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
356 static int wait_debugging = 0; /* Set nonzero to make following
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
357 function work under dbx (at least for bsd). */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
358 QUIT;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
359 if (wait_debugging)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
360 return;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
361
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
362 EMACS_BLOCK_SIGNAL (SIGCHLD);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
363 /* Block SIGCHLD from happening during this check,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
364 to avoid race conditions. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
365 if (kill (pid, 0) < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 {
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
367 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
368 return;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 }
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
370 else
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
371 /* WARNING: Whatever this macro does *must* not allow SIGCHLD
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
372 to happen between the time that it's reenabled and when we
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
373 begin to block. Otherwise we may end up blocking for a
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
374 signal that has already arrived and isn't coming again.
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
375 Can you say "race condition"?
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
376
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
377 I assume that the system calls sigpause() or sigsuspend()
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
378 to provide this atomicness. If you're getting hangs in
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
379 sigpause()/sigsuspend(), then your OS doesn't implement
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
380 this properly (this applies under hpux9, for example).
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
381 Try defining BROKEN_WAIT_FOR_SIGNAL. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
382 EMACS_WAIT_FOR_SIGNAL (SIGCHLD);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
383 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
384 #else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
385 /* This approach is kind of cheesy but is guaranteed(?!) to work
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
386 for all systems. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
387 while (1)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
388 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
389 QUIT;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 if (kill (pid, 0) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 emacs_sleep (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 }
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
394 #endif /* OS features */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 #if !defined (NO_SUBPROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 * flush any pending output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 * (may flush input as well; it does not matter the way we use it)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
404
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 flush_pending_output (int channel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 #ifdef HAVE_TERMIOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 /* If we try this, we get hit with SIGTTIN, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 the child's tty belongs to the child's pgrp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 #elif defined (TCFLSH)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ioctl (channel, TCFLSH, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 #elif defined (TIOCFLUSH)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 int zero = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 /* 3rd arg should be ignored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 but some 4.2 kernels actually want the address of an int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 and nonzero means something different. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 ioctl (channel, TIOCFLUSH, &zero);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 #ifndef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 #ifndef MSDOS
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
424 #ifndef WINDOWSNT
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 /* Set up the terminal at the other end of a pseudo-terminal that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 we will be controlling an inferior through.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 It should not echo or do line-editing, since that is done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 in Emacs. No padding needed for insertion into an Emacs buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 child_setup_tty (int out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 struct emacs_tty s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 EMACS_GET_TTY (out, &s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 assert (isatty(out));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 s.main.c_oflag |= OPOST; /* Enable output postprocessing */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 #ifdef NLDLY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 s.main.c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 /* No output delays */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 s.main.c_lflag &= ~ECHO; /* Disable echo */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 s.main.c_lflag |= ISIG; /* Enable signals */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 #ifdef IUCLC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 s.main.c_iflag &= ~IUCLC; /* Disable downcasing on input. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 #ifdef OLCUC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 s.main.c_oflag &= ~OLCUC; /* Disable upcasing on output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 #endif
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
452 s.main.c_oflag &= ~TAB3; /* Disable tab expansion */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 #if defined (CSIZE) && defined (CS8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 s.main.c_cflag = (s.main.c_cflag & ~CSIZE) | CS8; /* Don't strip 8th bit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 #ifdef ISTRIP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 s.main.c_iflag &= ~ISTRIP; /* Don't strip 8th bit on input */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 /* Unnecessary as long as ICANON is set */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 s.main.c_cc[VMIN] = 1; /* minimum number of characters to accept */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 163
diff changeset
466 s.main.c_cc[VEOF] = 04; /* ensure that EOF is Control-D */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 s.main.c_cc[VERASE] = CDISABLE; /* disable erase processing */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 s.main.c_cc[VKILL] = CDISABLE; /* disable kill processing */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 #ifdef HPUX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 #endif /* HPUX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 #ifdef AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 #ifndef IBMR2AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 /* AIX enhanced edit loses NULs, so disable it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 s.main.c_line = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 s.main.c_iflag &= ~ASCEDIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 #endif /* IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 /* Also, PTY overloads NUL and BREAK.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 don't ignore break, but don't signal either, so it looks like NUL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 This really serves a purpose only if running in an XTERM window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 or via TELNET or the like, but does no harm elsewhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 s.main.c_iflag &= ~IGNBRK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 s.main.c_iflag &= ~BRKINT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 #endif /* AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 #ifdef SIGNALS_VIA_CHARACTERS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 /* the QUIT and INTR character are used in process_send_signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 so set them here to something useful. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 s.main.c_cc[VQUIT] = '\\'&037; /* Control-\ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 s.main.c_cc[VINTR] = 'C' &037; /* Control-C */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 /* QUIT and INTR work better as signals, so disable character forms */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 s.main.c_cc[VQUIT] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 s.main.c_cc[VINTR] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 s.main.c_lflag &= ~ISIG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 s.main.c_cc[VEOL] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 #if defined (CBAUD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 /* <mdiers> ### This is not portable. ###
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 POSIX does not specify CBAUD, and 4.4BSD does not have it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 Instead, POSIX suggests to use cfset{i,o}speed().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 I/O, O'Reilly 1991] */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 /* <mdiers> What to do upon failure? Just ignoring rc is probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 not acceptable, is it? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 if (cfsetispeed (&s.main, B9600) == -1) /* ignore */;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 if (cfsetospeed (&s.main, B9600) == -1) /* ignore */;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 #endif /* defined (CBAUD) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 #else /* not HAVE_TERMIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 s.main.sg_flags &= ~(ECHO | CRMOD | ANYP | ALLDELAY | RAW | LCASE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 | CBREAK | TANDEM);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 s.main.sg_flags |= LPASS8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 s.main.sg_erase = 0377;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 s.main.sg_kill = 0377;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 s.lmode = LLITOUT | s.lmode; /* Don't strip 8th bit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 #endif /* not HAVE_TERMIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 EMACS_SET_TTY (out, &s, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 #ifdef RTU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 int zero = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ioctl (out, FIOASYNC, &zero);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 #endif /* RTU */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 }
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
532 #endif /* WINDOWSNT */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 #endif /* not NO_SUBPROCESSES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 #if !defined (VMS) && !defined (SIGTSTP) && !defined (USG_JOBCTRL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 /* Record a signal code and the handler for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 struct save_signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 int code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 SIGTYPE (*handler) ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 save_signal_handlers (struct save_signal *saved_handlers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 while (saved_handlers->code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 saved_handlers->handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 = (SIGTYPE (*) ()) signal (saved_handlers->code, SIG_IGN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 saved_handlers++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 restore_signal_handlers (struct save_signal *saved_handlers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 while (saved_handlers->code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 signal (saved_handlers->code, saved_handlers->handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 saved_handlers++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 /* Fork a subshell. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 sys_subshell (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 int st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 char oldwd[MAXPATHLEN+1]; /* Fixed length is safe on MSDOS. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 int pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 struct save_signal saved_handlers[5];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 Lisp_Object dir;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 unsigned char *str = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 int len;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
582 struct gcpro gcpro1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 saved_handlers[0].code = SIGINT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 saved_handlers[1].code = SIGQUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 saved_handlers[2].code = SIGTERM;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 #ifdef SIGIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 saved_handlers[3].code = SIGIO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 saved_handlers[4].code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 saved_handlers[3].code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 /* Mentioning current_buffer->buffer would mean including buffer.h,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 which somehow wedges the hp compiler. So instead... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 if (NILP (Fboundp (Qdefault_directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 goto xyzzy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 dir = Fsymbol_value (Qdefault_directory);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 if (!STRINGP (dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 goto xyzzy;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
602
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
603 GCPRO1 (dir);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
604 dir = Funhandled_file_name_directory (dir);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
605 dir = expand_and_dir_to_file (dir, Qnil);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 108
diff changeset
606 UNGCPRO;
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
607 str = (unsigned char *) alloca (XSTRING_LENGTH (dir) + 2);
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
608 len = XSTRING_LENGTH (dir);
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
609 memcpy (str, XSTRING_DATA (dir), len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 /* #### Unix specific */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 if (str[len - 1] != '/') str[len++] = '/';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 str[len] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 xyzzy:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
615 #ifdef WINDOWSNT
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
616 pid = -1;
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
617 #else /* not WINDOWSNT */
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
618
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 pid = vfork ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 if (pid == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 error ("Can't spawn subshell");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 if (pid == 0)
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
624
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
625 #endif /* not WINDOWSNT */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 char *sh = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 #ifdef MSDOS /* MW, Aug 1993 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 getwd (oldwd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 if (sh == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 sh = (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 if (sh == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 sh = (char *) egetenv ("SHELL");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 if (sh == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 sh = "sh";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 /* Use our buffer's default directory for the subshell. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 if (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 sys_chdir (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 #if !defined (NO_SUBPROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 close_process_descs (); /* Close Emacs's pipes/ptys */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 #ifdef SET_EMACS_PRIORITY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 if (emacs_priority != 0)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
649 nice (-emacs_priority); /* Give the new shell the default priority */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 st = system (sh);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 sys_chdir (oldwd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 if (st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 report_file_error ("Can't execute subshell",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 Fcons (build_string (sh), Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 #else /* not MSDOS */
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
661 #ifdef WINDOWSNT
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
662 /* Waits for process completion */
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
663 pid = _spawnlp (_P_WAIT, sh, sh, NULL);
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
664 if (pid == -1)
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
665 write (1, "Can't execute subshell", 22);
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
666
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
667 #if 0
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
668 /* This relates to the GNU Emacs console port, not required under X ? */
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
669 take_console ();
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
670 #endif
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
671 #else /* not WINDOWSNT */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 execlp (sh, sh, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 write (1, "Can't execute subshell", 22);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 _exit (1);
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
675 #endif /* not WINDOWSNT */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 save_signal_handlers (saved_handlers);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 synch_process_alive = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 #ifndef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 wait_for_termination (pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 restore_signal_handlers (saved_handlers);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 #endif /* !defined (VMS) && !defined (SIGTSTP) && !defined (USG_JOBCTRL) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 /* Suspend the Emacs process; give terminal to its superior. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 sys_suspend (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 /* "Foster" parentage allows emacs to return to a subprocess that attached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 to the current emacs as a cheaper than starting a whole new process. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 is set up by KEPTEDITOR.COM. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 unsigned long parent_id, foster_parent_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 char *fpid_string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 fpid_string = getenv ("EMACS_PARENT_PID");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 if (fpid_string != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 sscanf (fpid_string, "%x", &foster_parent_id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 if (foster_parent_id != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 parent_id = foster_parent_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 parent_id = getppid ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 parent_id = getppid ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 xfree (fpid_string); /* On VMS, this was malloc'd */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 if (parent_id && parent_id != 0xffffffff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 SIGTYPE (*oldsig)() = (int) signal (SIGINT, SIG_IGN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 int status = LIB$ATTACH (&parent_id) & 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 signal (SIGINT, oldsig);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 return status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 struct {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 int l;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 char *a;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 } d_prompt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 d_prompt.l = sizeof ("Emacs: "); /* Our special prompt */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 d_prompt.a = "Emacs: "; /* Just a reminder */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 LIB$SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 #elif defined (SIGTSTP) && !defined (MSDOS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 int pgrp = EMACS_GET_PROCESS_GROUP ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 EMACS_KILLPG (pgrp, SIGTSTP);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 #elif defined (USG_JOBCTRL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 /* If you don't know what this is don't mess with it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 kill (getpid (), SIGQUIT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 #else /* No SIGTSTP or USG_JOBCTRL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 /* On a system where suspending is not implemented,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 instead fork a subshell and let it talk directly to the terminal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 while we wait. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 sys_subshell ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
756 /* Suspend a process if possible; give terminal to its superior. */
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
757 void
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
758 sys_suspend_process (int process)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
759 {
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
760 /* I don't doubt that it is possible to suspend processes on
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
761 * VMS machines or thost that use USG_JOBCTRL,
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
762 * but I don't know how to do it, so...
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
763 */
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
764 #if defined (SIGTSTP) && !defined (MSDOS)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
765 kill(process, SIGTSTP);
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
766 #endif
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
767 }
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 100
diff changeset
768
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 /* Set the logical window size associated with descriptor FD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 to HEIGHT and WIDTH. This is used mainly with ptys. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 set_window_size (int fd, int height, int width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 #ifdef TIOCSWINSZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 /* BSD-style. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 struct winsize size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 size.ws_row = height;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 size.ws_col = width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 if (ioctl (fd, TIOCSWINSZ, &size) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 return 0; /* error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 #elif defined (TIOCSSIZE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 /* SunOS - style. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
790 struct ttysize size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 size.ts_lines = height;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 size.ts_cols = width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 if (ioctl (fd, TIOCGSIZE, &size) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 /* Set up the proper status flags for use of a pty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 setup_pty (int fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 /* I'm told that TOICREMOTE does not mean control chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 "can't be sent" but rather that they don't have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 input-editing or signaling effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 That should be good, because we have other ways
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 to do those things in Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 However, telnet mode seems not to work on 4.2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 So TIOCREMOTE is turned off now. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 will hang. In particular, the "timeout" feature (which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 causes a read to return if there is no data available)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 does this. Also it is known that telnet mode will hang
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 in such a way that Emacs must be stopped (perhaps this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 is the same problem).
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
824
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 If TIOCREMOTE is turned off, then there is a bug in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 hp-ux which sometimes loses data. Apparently the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 code which blocks the master process when the internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 buffer fills up does not work. Other than this,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 though, everything else seems to work fine.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
830
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 Since the latter lossage is more benign, we may as well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 lose that way. -- cph */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 #if defined (FIONBIO) && defined (SYSV_PTYS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 int on = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 ioctl (fd, FIONBIO, &on);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 #ifdef IBMRTAIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 /* cause EMACS not to die when it should, i.e., when its own controlling */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 /* tty goes away. I've complained to the AIX developers, and they may */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 /* change this behavior, but I'm not going to hold my breath. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 signal (SIGHUP, SIG_IGN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 #ifdef TIOCPKT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 /* In some systems (Linux through 2.0.0, at least), packet mode doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 get cleared when a pty is closed, so we need to clear it here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 Linux pre2.0.13 contained an attempted fix for this (from Ted Ts'o,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 tytso@mit.edu), but apparently it messed up rlogind and telnetd, so he
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 removed the fix in pre2.0.14. - dkindred@cs.cmu.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 int off = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ioctl (fd, TIOCPKT, (char *)&off);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 #endif /* HAVE_PTYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 /* TTY control */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 /* get baud rate */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 /* It really makes more sense for the baud-rate to be console-specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 and not device-specific, but it's (at least potentially) used for output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 decisions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 init_baud_rate (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 if (DEVICE_WIN_P (d) || DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 DEVICE_BAUD_RATE (d) = 38400;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 assert (DEVICE_TTY_P (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 int input_fd = CONSOLE_TTY_DATA (con)->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 DEVICE_TTY_DATA (d)->ospeed = 15;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 #elif defined (VMS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 struct vms_sensemode sg;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
893
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 &sg.class, 12, 0, 0, 0, 0 );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 DEVICE_TTY_DATA (d)->ospeed = sg.xmit_baud;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 #elif defined (HAVE_TERMIOS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 struct termios sg;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
899
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 sg.c_cflag = B9600;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 tcgetattr (input_fd, &sg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 DEVICE_TTY_DATA (d)->ospeed = cfgetospeed (&sg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 # if defined (USE_GETOBAUD) && defined (getobaud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 if (DEVICE_TTY_DATA (d)->ospeed == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 DEVICE_TTY_DATA (d)->ospeed = getobaud (sg.c_cflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 #elif defined (HAVE_TERMIO)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 struct termio sg;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
910
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 sg.c_cflag = B9600;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 # ifdef HAVE_TCATTR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 tcgetattr (input_fd, &sg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 ioctl (input_fd, TCGETA, &sg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 DEVICE_TTY_DATA (d)->ospeed = sg.c_cflag & CBAUD;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 #else /* neither VMS nor TERMIOS nor TERMIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 struct sgttyb sg;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
920
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 sg.sg_ospeed = B9600;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 if (ioctl (input_fd, TIOCGETP, &sg) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 DEVICE_TTY_DATA (d)->ospeed = sg.sg_ospeed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
927
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 DEVICE_BAUD_RATE (d) =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (DEVICE_TTY_DATA (d)->ospeed < sizeof baud_convert / sizeof baud_convert[0]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 ? baud_convert[DEVICE_TTY_DATA (d)->ospeed]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 : 9600);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 if (DEVICE_BAUD_RATE (d) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 DEVICE_BAUD_RATE (d) = 1200;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 #endif /* HAVE_TTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 /* SIGIO control */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 #ifdef SIGIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 init_sigio_on_device (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 int filedesc = DEVICE_INFD (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
950 #if defined (I_SETSIG) && !defined(HPUX10)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 ioctl (filedesc, I_GETSIG, &DEVICE_OLD_SIGIO_FLAG (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 DEVICE_OLD_SIGIO_FLAG (d) &= ~S_INPUT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 #elif defined (FASYNC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 DEVICE_OLD_SIGIO_FLAG (d) =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 fcntl (filedesc, F_GETFL, 0) & ~FASYNC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 #if defined (FIOSSAIOOWN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 { /* HPUX stuff */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 int owner = getpid ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 int ioctl_status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 if (DEVICE_TTY_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ioctl_status = ioctl (filedesc, FIOGSAIOOWN,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 &DEVICE_OLD_FCNTL_OWNER (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 ioctl_status = ioctl (filedesc, FIOSSAIOOWN, &owner);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 #ifdef HAVE_WINDOW_SYSTEM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 else if (!DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 ioctl_status = ioctl (filedesc, SIOCGPGRP,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 &DEVICE_OLD_FCNTL_OWNER (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ioctl_status = ioctl (filedesc, SIOCSPGRP, &owner);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 DEVICE_OLD_FCNTL_OWNER (d) = fcntl (filedesc, F_GETOWN, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 # ifdef F_SETOWN_SOCK_NEG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 /* stdin is a socket here */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 fcntl (filedesc, F_SETOWN, -getpid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 fcntl (filedesc, F_SETOWN, getpid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 reset_sigio_on_device (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 int filedesc = DEVICE_INFD (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 #if defined (FIOSSAIOOWN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 { /* HPUX stuff */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 int owner = getpid ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 int ioctl_status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 if (DEVICE_TTY_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 ioctl_status = ioctl (filedesc, FIOSSAIOOWN,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 &DEVICE_OLD_FCNTL_OWNER (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 #ifdef HAVE_WINDOW_SYSTEM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 else if (!DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 ioctl_status = ioctl (filedesc, SIOCSPGRP,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 &DEVICE_OLD_FCNTL_OWNER (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 fcntl (filedesc, F_SETOWN, DEVICE_OLD_FCNTL_OWNER (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 request_sigio_on_device (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 int filedesc = DEVICE_INFD (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 /* prevent redundant ioctl()s, which may cause syslog messages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (e.g. on Solaris) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 if (d->sigio_enabled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1025 #if defined (I_SETSIG) && !defined(HPUX10)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ioctl (filedesc, I_SETSIG, DEVICE_OLD_SIGIO_FLAG (d) | S_INPUT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 #elif defined (FASYNC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 fcntl (filedesc, F_SETFL, DEVICE_OLD_SIGIO_FLAG (d) | FASYNC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 #elif defined (FIOSSAIOSTAT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 sockets and other devices for some bizarre reason. We guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 that an X device is a socket, and tty devices aren't. We then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 use the following crud to do the appropriate thing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 int on = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 int ioctl_status; /* ####DG: check if IOCTL succeeds here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 if (DEVICE_TTY_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &on);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 #ifdef HAVE_WINDOW_SYSTEM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 else if (!DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ioctl_status = ioctl (filedesc, FIOASYNC, &on);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 #elif defined (FIOASYNC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 int on = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ioctl (filedesc, FIOASYNC, &on);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 #if defined (_CX_UX) /* #### Is this crap necessary? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 EMACS_UNBLOCK_SIGNAL (SIGIO);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 d->sigio_enabled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 unrequest_sigio_on_device (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 int filedesc = DEVICE_INFD (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 /* prevent redundant ioctl()s, which may cause syslog messages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (e.g. on Solaris) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 if (!d->sigio_enabled)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1073 #if defined (I_SETSIG) && !defined(HPUX10)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 ioctl (filedesc, I_SETSIG, DEVICE_OLD_SIGIO_FLAG (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 #elif defined (FASYNC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 fcntl (filedesc, F_SETFL, DEVICE_OLD_SIGIO_FLAG (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 #elif defined (FIOSSAIOSTAT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 sockets and other devices for some bizarre reason. We guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 that an X device is a socket, and tty devices aren't. We then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 use the following crud to do the appropriate thing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 int off = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 int ioctl_status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 /* See comment for request_sigio_on_device */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 if (DEVICE_TTY_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &off);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1093 else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 ioctl_status = ioctl (filedesc, FIOASYNC, &off);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 #elif defined (FIOASYNC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 int off = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 ioctl (filedesc, FIOASYNC, &off);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 d->sigio_enabled = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 request_sigio (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 Lisp_Object devcons, concons;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 DEVICE_LOOP_NO_BREAK (devcons, concons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 struct device *d;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 d = XDEVICE (XCAR (devcons));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 if (!DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 request_sigio_on_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 unrequest_sigio (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 Lisp_Object devcons, concons;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 DEVICE_LOOP_NO_BREAK (devcons, concons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 struct device *d;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 d = XDEVICE (XCAR (devcons));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 if (!DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 unrequest_sigio_on_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 #endif /* SIGIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 /* Changing Emacs's process group */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 /* Saving and restoring the process group of Emacs's terminal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 /* On some systems, apparently (?!) Emacs must be in its own process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 group in order to receive SIGIO correctly. On other systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (e.g. Solaris), it's not required and doing it makes things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 get fucked up. So, we only do it when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP is defined. Basically,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 this is only required for BSD 4.2 systems. (Actually, I bet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 we don't have to do this at all -- those systems also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 required interrupt input, which we don't support.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 If Emacs was in its own process group (i.e. inherited_pgroup ==
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 getpid ()), then we know we're running under a shell with job
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 control (Emacs would never be run as part of a pipeline).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 Everything is fine.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 If Emacs was not in its own process group, then we know we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 running under a shell (or a caller) that doesn't know how to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 separate itself from Emacs (like sh). Emacs must be in its own
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 process group in order to receive SIGIO correctly. In this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 situation, we put ourselves in our own pgroup, forcibly set the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 tty's pgroup to our pgroup, and make sure to restore and reinstate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 the tty's pgroup just like any other terminal setting. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 inherited_group was not the tty's pgroup, then we'll get a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 it goes foreground in the future, which is what should happen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 static int inherited_pgroup;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 static int inherited_tty_pgroup;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 munge_tty_process_group (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 if (noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 /* Only do this munging if we have a device on the controlling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 terminal. See the large comment below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 if (CONSOLEP (Vcontrolling_terminal) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 int fd = open ("/dev/tty", O_RDWR, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 int me = getpid ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 EMACS_BLOCK_SIGNAL (SIGTTOU);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 EMACS_SET_TTY_PROCESS_GROUP (fd, &me);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 /* Split off the foreground process group to Emacs alone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 When we are in the foreground, but not started in our own process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 group, redirect the TTY to point to our own process group. We need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 to be in our own process group to receive SIGIO properly. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 munge_process_groups (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 if (noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 EMACS_SEPARATE_PROCESS_GROUP ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 munge_tty_process_group ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 unmunge_tty_process_group (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 int fd = open ("/dev/tty", O_RDWR, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 EMACS_BLOCK_SIGNAL (SIGTTOU);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 EMACS_SET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 /* Set the tty to our original foreground group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 Also restore the original process group (put us back into sh's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 process group), so that ^Z will suspend both us and sh. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 unmunge_process_groups (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 if (noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 unmunge_tty_process_group ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 EMACS_SET_PROCESS_GROUP (inherited_pgroup);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 /* According to some old wisdom, we need to be in a separate process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 group for SIGIO to work correctly (at least on some systems ...).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 So go ahead and put ourselves into our own process group. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 will fail if we're already in our own process group, but who cares.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 Also record whether we were in our own process group. (In general,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 we will already be in our own process group if we were started from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 a job-control shell like csh, but not if we were started from sh).
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1257
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 If we succeeded in changing our process group, then we will no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 longer be in the foreground process group of our controlling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 terminal. Therefore, if we have a console open onto this terminal,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 we have to change the controlling terminal's foreground process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 group (otherwise we will get stopped with a SIGTTIN signal when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 attempting to read from the terminal). It's important,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 however, that we do this *only* when we have a console open onto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 the terminal. It's a decidedly bad idea to do so otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 especially if XEmacs was started from the background. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 init_process_group (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 if (! noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 int fd = open ("/dev/tty", O_RDWR, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 inherited_pgroup = EMACS_GET_PROCESS_GROUP ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 EMACS_GET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 EMACS_SEPARATE_PROCESS_GROUP ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 disconnect_controlling_terminal (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 # ifdef HAVE_SETSID
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 /* Controlling terminals are attached to a session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 Create a new session for us; it will have no controlling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 terminal. This also, of course, puts us in our own
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 process group. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 setsid ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 /* Put us in our own process group. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 EMACS_SEPARATE_PROCESS_GROUP ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 # if defined (TIOCNOTTY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 /* This is the older way of disconnecting the controlling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 terminal, on 4.3 BSD. We must open /dev/tty; using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 filedesc 0 is not sufficient because it could be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 something else (e.g. our stdin was redirected to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 another terminal).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 int j = open ("/dev/tty", O_RDWR, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 ioctl (j, TIOCNOTTY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 close (j);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 # endif /* TIOCNOTTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 On systems without TIOCNOTTY and without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 setsid(), we don't need to do anything more to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 disconnect our controlling terminal. Here is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 what the man page for termio(7) from a SYSV 3.2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 system says:
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1314
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 "The first terminal file opened by the process group leader
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 of a terminal file not already associated with a process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 group becomes the control terminal for that process group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 The control terminal plays a special role in handling quit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 and interrupt signals, as discussed below. The control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 terminal is inherited by a child process during a fork(2).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 A process can break this association by changing its process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 group using setpgrp(2)."
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1323
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 # endif /* not HAVE_SETSID */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 /* Getting and setting emacs_tty structures */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
1333 /* It's wrong to encase these into #ifdef HAVE_TTY because we need
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
1334 them for child TTY processes. */
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
1335 /* However, this does break NT support while we don't do child TTY processes */
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
1336 #ifndef WINDOWSNT
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
1337
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 /* Set *TC to the parameters associated with the terminal FD.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 Return zero if all's well, or -1 if we ran into an error we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 couldn't deal with. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 emacs_get_tty (int fd, struct emacs_tty *settings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 #ifdef HAVE_TCATTR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 /* We have those nifty POSIX tcmumbleattr functions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 if (tcgetattr (fd, &settings->main) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 #ifdef HAVE_TERMIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 /* The SYSV-style interface? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 if (ioctl (fd, TCGETA, &settings->main) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 /* Vehemently Monstrous System? :-) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 if (! (SYS$QIOW (0, fd, IO$_SENSEMODE, settings, 0, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 &settings->main.class, 12, 0, 0, 0, 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 & 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 #ifndef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 /* I give up - I hope you have the BSD ioctls. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 if (ioctl (fd, TIOCGETP, &settings->main) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 #endif /* HAVE_TERMIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 #endif /* HAVE_TCATTR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 /* Suivant - Do we have to get struct ltchars data? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 #ifdef HAVE_LTCHARS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 if (ioctl (fd, TIOCGLTC, &settings->ltchars) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 /* How about a struct tchars and a wordful of lmode bits? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 #ifdef HAVE_TCHARS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 if (ioctl (fd, TIOCGETC, &settings->tchars) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 || ioctl (fd, TIOCLGET, &settings->lmode) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 /* We have survived the tempest. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 /* Set the parameters of the tty on FD according to the contents of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 *SETTINGS. If FLUSHP is non-zero, we discard input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 Return 0 if all went well, and -1 if anything failed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 emacs_set_tty (int fd, struct emacs_tty *settings, int flushp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 /* Set the primary parameters - baud rate, character size, etcetera. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 #ifdef HAVE_TCATTR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 /* We have those nifty POSIX tcmumbleattr functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 William J. Smith <wjs@wiis.wang.com> writes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 "POSIX 1003.1 defines tcsetattr() to return success if it was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 able to perform any of the requested actions, even if some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 of the requested actions could not be performed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 We must read settings back to ensure tty setup properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 AIX requires this to keep tty from hanging occasionally." */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 /* This makes sure that we don't loop indefinitely in here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 for (i = 0 ; i < 10 ; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 if (tcsetattr (fd, flushp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 if (errno == EINTR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 struct termios new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 /* Get the current settings, and see if they're what we asked for. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 tcgetattr (fd, &new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 /* We cannot use memcmp on the whole structure here because under
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 * aix386 the termios structure has some reserved field that may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 * not be filled in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 if ( new.c_iflag == settings->main.c_iflag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 && new.c_oflag == settings->main.c_oflag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 && new.c_cflag == settings->main.c_cflag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 && new.c_lflag == settings->main.c_lflag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 && memcmp(new.c_cc, settings->main.c_cc, NCCS) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 #ifdef HAVE_TERMIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 /* The SYSV-style interface? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 /* Vehemently Monstrous System? :-) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 if (! (SYS$QIOW (0, fd, IO$_SETMODE, &input_iosb, 0, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 &settings->main.class, 12, 0, 0, 0, 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 & 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 #ifndef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 /* I give up - I hope you have the BSD ioctls. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 #endif /* HAVE_TERMIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 #endif /* HAVE_TCATTR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 /* Suivant - Do we have to get struct ltchars data? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 #ifdef HAVE_LTCHARS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 if (ioctl (fd, TIOCSLTC, &settings->ltchars) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 /* How about a struct tchars and a wordful of lmode bits? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 #ifdef HAVE_TCHARS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 if (ioctl (fd, TIOCSETC, &settings->tchars) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1472
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 /* We have survived the tempest. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
1477 #endif /* WINDOWSNT */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 /* Initializing a device */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 /* This may also be defined in stdio,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 but if so, this does no harm,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 and using the same name avoids wasting the other one's space. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 #if ((defined(USG) || defined(DGUX)) && !defined(__STDC__))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 char _sobuf[BUFSIZ+8];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 #elif (defined(USG) && !defined(LINUX) && !defined(_SCO_DS)) || defined(IRIX5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 extern unsigned char _sobuf[BUFSIZ+8];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 char _sobuf[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1496
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 #if defined (TIOCGLTC) && defined (HAVE_LTCHARS) /* HAVE_LTCHARS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 #ifdef TIOCGETC /* HAVE_TCHARS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 #ifdef HAVE_TCHARS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1504 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 tty_init_sys_modes_on_device (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 struct emacs_tty tty;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 int input_fd, output_fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 input_fd = CONSOLE_TTY_DATA (con)->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 output_fd = CONSOLE_TTY_DATA (con)->outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 EMACS_GET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 tty = CONSOLE_TTY_DATA (con)->old_tty;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1519 con->tty_erase_char = Qnil;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1520
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1522 /* after all those years... */
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1523 con->tty_erase_char = make_char (tty.main.c_cc[VERASE]);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 #ifdef DGUX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 /* This allows meta to be sent on 8th bit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 tty.main.c_iflag &= ~INPCK; /* don't check input for parity */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 #ifdef ISTRIP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 tty.main.c_lflag &= ~ECHO; /* Disable echo */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 #ifdef IEXTEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 tty.main.c_lflag &= ~IEXTEN; /* Disable other editing characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 tty.main.c_lflag |= ISIG; /* Enable signals */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 if (TTY_FLAGS (con).flow_control)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 tty.main.c_iflag |= IXON; /* Enable start/stop output control */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 #ifdef IXANY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 tty.main.c_iflag &= ~IXANY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 #endif /* IXANY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1548 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 on output */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 #ifdef CS8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 if (TTY_FLAGS (con).meta_key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 tty.main.c_cflag |= CS8; /* allow 8th bit on input */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 tty.main.c_cflag &= ~PARENB;/* Don't check parity */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 if (CONSOLE_TTY_DATA (con)->controlling_terminal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 tty.main.c_cc[VINTR] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 CONSOLE_QUIT_CHAR (con); /* C-g (usually) gives SIGINT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 /* Set up C-g for both SIGQUIT and SIGINT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 We don't know which we will get, but we handle both alike
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 so which one it really gives us does not matter. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 tty.main.c_cc[VQUIT] = CONSOLE_QUIT_CHAR (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 tty.main.c_cc[VINTR] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 tty.main.c_cc[VQUIT] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 tty.main.c_cc[VMIN] = 1; /* Input should wait for at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 least 1 char */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 #ifdef VSWTCH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 of C-z */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 #endif /* VSWTCH */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 /* There was some conditionalizing here on (mips or TCATTR), but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 I think that's wrong. There was one report of C-y (DSUSP) not being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 disabled on HP9000s700 systems, and this might fix it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 #ifdef VSUSP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 tty.main.c_cc[VSUSP] = CDISABLE;/* Turn off mips handling of C-z. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 #endif /* VSUSP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 #ifdef V_DSUSP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 #endif /* V_DSUSP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 tty.main.c_cc[VDSUSP] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 #endif /* VDSUSP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 #ifdef VLNEXT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 tty.main.c_cc[VLNEXT] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 #endif /* VLNEXT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 #ifdef VREPRINT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 tty.main.c_cc[VREPRINT] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 #endif /* VREPRINT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 #ifdef VWERASE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 tty.main.c_cc[VWERASE] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 #endif /* VWERASE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 #ifdef VDISCARD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 tty.main.c_cc[VDISCARD] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 #endif /* VDISCARD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 #ifdef VSTART
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 tty.main.c_cc[VSTART] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 #endif /* VSTART */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 #ifdef VSTRT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 tty.main.c_cc[VSTRT] = CDISABLE; /* called VSTRT on some systems */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 #endif /* VSTART */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 #ifdef VSTOP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 tty.main.c_cc[VSTOP] = CDISABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 #endif /* VSTOP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 #ifdef SET_LINE_DISCIPLINE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 /* Need to explicitely request TERMIODISC line discipline or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 Ultrix's termios does not work correctly. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 tty.main.c_line = SET_LINE_DISCIPLINE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1617
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 #ifdef AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 #ifndef IBMR2AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 /* AIX enhanced edit loses NULs, so disable it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 tty.main.c_line = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 tty.main.c_iflag &= ~ASCEDIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 tty.main.c_cc[VSTRT] = 255;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 tty.main.c_cc[VSTOP] = 255;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 tty.main.c_cc[VSUSP] = 255;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 tty.main.c_cc[VDSUSP] = 255;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 #endif /* IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 /* Also, PTY overloads NUL and BREAK.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 don't ignore break, but don't signal either, so it looks like NUL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 This really serves a purpose only if running in an XTERM window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 or via TELNET or the like, but does no harm elsewhere. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 tty.main.c_iflag &= ~IGNBRK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 tty.main.c_iflag &= ~BRKINT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 #endif /* AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 #else /* if not HAVE_TERMIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 #ifndef MSDOS
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1638 con->tty_erase_char = make_char (tty.main.sg_erase);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 if (TTY_FLAGS (con).meta_key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 tty.main.sg_flags |= ANYP;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 /* #### should we be using RAW mode here? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 tty.main.sg_flags |= /* interrupt_input ? RAW : */ CBREAK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 #endif /* not HAVE_TERMIO */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1646
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 /* If going to use CBREAK mode, we must request C-g to interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 and turn off start and stop chars, etc. If not going to use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 CBREAK mode, do this anyway so as to turn off local flow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 control for user coming over network on 4.2; in this case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 only t_stopc and t_startc really matter. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 #ifndef HAVE_TERMIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 #ifdef HAVE_TCHARS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 /* Note: if not using CBREAK mode, it makes no difference how we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 set this */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 tty.tchars = new_tchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 tty.tchars.t_intrc = CONSOLE_QUIT_CHAR (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 if (TTY_FLAGS (con).flow_control)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 tty.tchars.t_startc = '\021';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 tty.tchars.t_stopc = '\023';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1663
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 CONSOLE_TTY_DATA (con)->old_tty.lmode;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1666
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 #if defined (ultrix) || defined (__bsdi__)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 anything, and leaving it in breaks the meta key. Go figure. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 /* Turning off ONLCR is enough under BSD/386. Leave the general
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 output post-processing flag alone since for some reason it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 doesn't get reset after XEmacs goes away. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 tty.lmode &= ~LLITOUT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1675
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 #endif /* HAVE_TCHARS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 #endif /* not HAVE_TERMIO */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1678
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 #ifdef HAVE_LTCHARS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 tty.ltchars = new_ltchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 #endif /* HAVE_LTCHARS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 internal_terminal_init ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 dos_ttraw ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1686
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 EMACS_SET_TTY (input_fd, &tty, 0);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1688
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 /* This code added to insure that, if flow-control is not to be used,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 we have an unlocked terminal at the start. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1691
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 #ifdef TCXONC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 #ifndef APOLLO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 #ifdef TIOCSTART
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1700
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 #if defined (HAVE_TERMIOS) || defined (HPUX9)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 #ifdef TCOON
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 #ifdef AIXHFT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 hft_init (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 #ifdef IBMR2AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 /* IBM's HFT device usually thinks a ^J should be LF/CR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 We need it to be only LF. This is the way that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 done. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 struct termio tty;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1714
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 if (ioctl (output_fd, HFTGETID, &tty) != -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 write (output_fd, "\033[20l", 5);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 /* Appears to do nothing when in PASTHRU mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 interrupt_signal, oob_chars, 0, 0, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 queue_kbd_input (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 #if 0 /* We do our own buffering with lstreams. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 #ifdef _IOFBF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 /* This symbol is defined on recent USG systems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 Someone says without this call USG won't really buffer the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 even with a call to setbuf. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 setvbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf, _IOFBF, sizeof _sobuf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 setbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 set_tty_modes (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 #endif /* HAVE_TTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 init_one_device (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 if (DEVICE_TTY_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 tty_init_sys_modes_on_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 #ifdef SIGIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 if (!DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 init_sigio_on_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 request_sigio_on_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 init_one_console (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 Lisp_Object devcons;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 CONSOLE_DEVICE_LOOP (devcons, con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 struct device *d = XDEVICE (XCAR (devcons));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1768
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 init_one_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 reinit_initial_console (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 munge_process_groups ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 if (CONSOLEP (Vcontrolling_terminal) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 init_one_console (XCONSOLE (Vcontrolling_terminal));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 /* Other TTY functions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 #if 0 /* not currently used */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 /* Return nonzero if safe to use tabs in output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 At the time this is called, init_sys_modes has not been done yet. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1793
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 tabs_safe_p (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 if (DEVICE_TTY_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 struct emacs_tty tty;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1801
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 EMACS_GET_TTY (DEVICE_INFD (d), &tty);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 return EMACS_TTY_TABS_OK (&tty);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 /* Get terminal size from system.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 Store number of lines into *heightp and width into *widthp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 If zero or a negative number is stored, the value is not valid. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 get_tty_device_size (struct device *d, int *widthp, int *heightp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 int input_fd = DEVICE_INFD (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 assert (DEVICE_TTY_P (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 #ifdef TIOCGWINSZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 /* BSD-style. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 struct winsize size;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1826
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 *widthp = *heightp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 *widthp = size.ws_col;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 *heightp = size.ws_row;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 #ifdef TIOCGSIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 /* SunOS - style. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1839 struct ttysize size;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1840
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 *widthp = *heightp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 *widthp = size.ts_cols;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 *heightp = size.ts_lines;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 struct vms_sensemode tty;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1853
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 &tty.class, 12, 0, 0, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 *widthp = tty.scr_wid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 *heightp = tty.scr_len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 *widthp = FrameCols ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 *heightp = FrameRows ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 #else /* system doesn't know size */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 *widthp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 *heightp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 #endif /* not SunOS-style */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 #endif /* not BSD-style */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 #endif /* HAVE_TTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 /* Is device 8 bit ? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 eight_bit_tty (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 struct emacs_tty s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 int input_fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 int eight_bit = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 assert (DEVICE_TTY_P (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 input_fd = DEVICE_INFD (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 EMACS_GET_TTY (input_fd, &s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 eight_bit = (s.main.c_cflag & CSIZE) == CS8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 eight_bit = 0; /* I don't know how to do it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 return eight_bit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 #endif /* HAVE_TTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 /* Resetting a device */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 /* Prepare the terminal for exiting Emacs; move the cursor to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 bottom of the frame, turn off interrupt-driven I/O, etc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 tty_reset_sys_modes_on_device (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 int input_fd, output_fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 input_fd = CONSOLE_TTY_DATA (con)->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 output_fd = CONSOLE_TTY_DATA (con)->outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 #if defined (IBMR2AIX) && defined (AIXHFT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1927 /* HFT consoles normally use ^J as a LF/CR. We forced it to
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 do the LF only. Now, we need to reset it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 struct termio tty;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1930
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 if (ioctl (output_fd, HFTGETID, &tty) != -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 write (output_fd, "\033[20h", 5);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 tty_redisplay_shutdown (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 /* reset_tty_modes() flushes the connection at its end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 reset_tty_modes (con);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1939
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 #if defined (BSD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 /* Avoid possible loss of output when changing terminal modes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 fsync (output_fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 while (EMACS_SET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 < 0 && errno == EINTR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 ;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1948
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 dos_ttcooked ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1952
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 #ifdef SET_LINE_DISCIPLINE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 A different old line discipline is therefore not restored, yet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 Restore the old line discipline by hand. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 ioctl (input_fd, TIOCSETD, &old_tty.main.c_line);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 #ifdef AIXHFT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 hft_reset (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 stop_vms_input (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 #endif /* HAVE_TTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 reset_one_device (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 #ifdef HAVE_TTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 if (DEVICE_TTY_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 tty_reset_sys_modes_on_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 if (DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 fflush (CONSOLE_STREAM_DATA (XCONSOLE (DEVICE_CONSOLE (d)))->outfd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 #ifdef SIGIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 if (!DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 unrequest_sigio_on_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 reset_sigio_on_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 reset_one_console (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 /* Note: this can be called during GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 Lisp_Object devcons;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 CONSOLE_DEVICE_LOOP (devcons, con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 struct device *d = XDEVICE (XCAR (devcons));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
1999
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 reset_one_device (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 reset_all_consoles (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 /* Note: this can be called during GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 Lisp_Object concons;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 CONSOLE_LOOP (concons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 struct console *con = XCONSOLE (XCAR (concons));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2013
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 reset_one_console (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 unmunge_process_groups ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 reset_initial_console (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 if (CONSOLEP (Vcontrolling_terminal) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 reset_one_console (XCONSOLE (Vcontrolling_terminal));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 unmunge_process_groups ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 /* extra TTY stuff under AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 #ifdef AIXHFT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 /* Called from init_sys_modes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 hft_init (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 int junk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 int input_fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 assert (CONSOLE_TTY_P (con));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 input_fd = CONSOLE_TTY_DATA (con)->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 /* If we're not on an HFT we shouldn't do any of this. We determine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 if we are on an HFT by trying to get an HFT error code. If this
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2048 call fails, we're not on an HFT. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 #ifdef IBMR2AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 if (ioctl (input_fd, HFQERROR, &junk) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 #else /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 if (ioctl (input_fd, HFQEIO, 0) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 #endif /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 /* On AIX the default hft keyboard mapping uses backspace rather than delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 as the rubout key's ASCII code. Here this is changed. The bug is that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 there's no way to determine the old mapping, so in reset_one_console
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 we need to assume that the normal map had been present. Of course, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 code also doesn't help if on a terminal emulator which doesn't understand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 HFT VTD's. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 struct hfbuf buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 struct hfkeymap keymap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 buf.hf_bufp = (char *)&keymap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 buf.hf_buflen = sizeof (keymap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 keymap.hf_nkeys = 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 keymap.hfkey[0].hf_kpos = 15;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 #ifdef IBMR2AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 keymap.hfkey[0].hf_keyidh = '<';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 #else /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 keymap.hfkey[0].hf_page = '<';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 #endif /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 keymap.hfkey[0].hf_char = 127;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 keymap.hfkey[1].hf_kpos = 15;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 #ifdef IBMR2AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 keymap.hfkey[1].hf_keyidh = '<';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 #else /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 keymap.hfkey[1].hf_page = '<';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 #endif /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 keymap.hfkey[1].hf_char = 127;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 hftctl (input_fd, HFSKBD, &buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 /* #### Should probably set a console TTY flag here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 at times. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 line_ins_del_ok = char_ins_del_ok = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 /* Reset the rubout key to backspace. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 hft_reset (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 struct hfbuf buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 struct hfkeymap keymap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 int junk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 int input_fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 assert (CONSOLE_TTY_P (con));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 input_fd = CONSOLE_TTY_DATA (con)->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 #ifdef IBMR2AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 if (ioctl (input_fd, HFQERROR, &junk) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 #else /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 if (ioctl (input_fd, HFQEIO, 0) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 #endif /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 buf.hf_bufp = (char *)&keymap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 buf.hf_buflen = sizeof (keymap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 keymap.hf_nkeys = 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 keymap.hfkey[0].hf_kpos = 15;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 #ifdef IBMR2AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 keymap.hfkey[0].hf_keyidh = '<';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 #else /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 keymap.hfkey[0].hf_page = '<';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 #endif /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 keymap.hfkey[0].hf_char = 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 keymap.hfkey[1].hf_kpos = 15;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 #ifdef IBMR2AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 keymap.hfkey[1].hf_keyidh = '<';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 #else /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 keymap.hfkey[1].hf_page = '<';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 #endif /* not IBMR2AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 keymap.hfkey[1].hf_char = 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 hftctl (input_fd, HFSKBD, &buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 #endif /* AIXHFT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 /* TTY stuff under VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 /* ------------------------------------------------------ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 /***** #### this is all broken ****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 /* Assigning an input channel is done at the start of Emacs execution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 This is called each time Emacs is resumed, also, but does nothing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 because input_chain is no longer zero. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 init_vms_input (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 /* #### broken. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 int status;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2159
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 if (input_fd == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 status = SYS$ASSIGN (&vms_input_dsc, &input_fd, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 if (! (status & 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 LIB$STOP (status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 /* Deassigning the input channel is done before exiting. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 stop_vms_input (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 int input_fd = CONSOLE_TTY_DATA (con)->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 return SYS$DASSGN (input_fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 static short vms_input_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 /* Request reading one character into the keyboard buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 This is done as soon as the buffer becomes empty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 queue_vms_kbd_input (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 int input_fd = CONSOLE_TTY_DATA (con)->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 int status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 vms_waiting_for_ast = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 vms_stop_input = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 status = SYS$QIO (0, input_fd, IO$_READVBLK,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 &vms_input_iosb, vms_kbd_input_ast, 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 &vms_input_buffer, 1, 0, vms_terminator_mask, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 static int vms_input_count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 /* Ast routine that is called when keyboard input comes in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 in accord with the SYS$QIO above. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 vms_kbd_input_ast (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 int c = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 int old_errno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 extern EMACS_TIME *input_available_clear_time;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 if (vms_waiting_for_ast)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 SYS$SETEF (vms_input_ef);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 vms_waiting_for_ast = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 vms_input_count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 #ifdef ASTDEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 if (vms_input_count == 25)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 printf ("Ast # %d,", vms_input_count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 printf (" iosb = %x, %x, %x, %x",
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2215 vms_input_iosb.offset, vms_input_iosb.status,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 vms_input_iosb.termlen, vms_input_iosb.term);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 if (vms_input_iosb.offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 c = vms_input_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 #ifdef ASTDEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 printf (", char = 0%o", c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 #ifdef ASTDEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 printf ("\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 emacs_sleep (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 if (! vms_stop_input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 queue_vms_kbd_input (con);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 if (c >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 kbd_buffer_store_char (c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 if (input_available_clear_time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 errno = old_errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 #if 0 /* Unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 /* Wait until there is something in kbd_buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 vms_wait_for_kbd_input (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 extern int have_process_input, process_exited;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 /* If already something, avoid doing system calls. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 if (detect_input_pending (0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 /* Clear a flag, and tell ast routine above to set it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 SYS$CLREF (vms_input_ef);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 vms_waiting_for_ast = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 /* Check for timing error: ast happened while we were doing that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 if (!detect_input_pending (0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 /* No timing error: wait for flag to be set. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 set_waiting_for_input (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 SYS$WFLOR (vms_input_ef, vms_input_eflist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 clear_waiting_for_input (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 if (!detect_input_pending (0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 /* Check for subprocess input availability */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 int dsp = have_process_input || process_exited;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 SYS$CLREF (vms_process_ef);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 if (have_process_input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 process_command_input ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 if (process_exited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 process_exit ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 if (dsp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 MARK_MODELINE_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 redisplay ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 vms_waiting_for_ast = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 /* Get rid of any pending QIO, when we are about to suspend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 or when we want to throw away pending input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 We wait for a positive sign that the AST routine has run
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 and therefore there is no I/O request queued when we return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 SYS$SETAST is used to avoid a timing error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 vms_end_kbd_input (struct console *con)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 int input_fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 assert (CONSOLE_TTY_P (con));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 input_fd = CONSOLE_TTY_DATA (con)->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 #ifdef ASTDEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 printf ("At end_kbd_input.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 emacs_sleep (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_char! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 SYS$CANCEL (input_fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 SYS$SETAST (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 /* Clear a flag, and tell ast routine above to set it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 SYS$CLREF (vms_input_ef);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 vms_waiting_for_ast = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 vms_stop_input = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 SYS$CANCEL (input_fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 SYS$SETAST (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 SYS$WAITFR (vms_input_ef);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 vms_waiting_for_ast = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 #if 0 /* Unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 /* Wait for either input available or time interval expiry. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 vms_input_wait_timeout (int timeval) /* Time to wait, in seconds */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 int time [2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 static int zero = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 static int large = -10000000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 /* If already something, avoid doing system calls. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 if (detect_input_pending (0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 /* Clear a flag, and tell ast routine above to set it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 SYS$CLREF (vms_input_ef);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 vms_waiting_for_ast = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 /* Check for timing error: ast happened while we were doing that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 if (!detect_input_pending (0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 /* No timing error: wait for flag to be set. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 SYS$CANTIM (1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 if (SYS$SETIMR (vms_timer_ef, time, 0, 1) & 1) /* Set timer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 SYS$WFLOR (vms_timer_ef, vms_timer_eflist); /* Wait for timer expiry or input */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 vms_waiting_for_ast = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 /* limits of text/data segments */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 #ifndef CANNOT_DUMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 #define NEED_STARTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 #ifndef SYSTEM_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 #ifndef NEED_STARTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 #define NEED_STARTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 #ifdef NEED_STARTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 /* Some systems that cannot dump also cannot implement these. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 * Return the address of the start of the text segment prior to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 * doing an unexec. After unexec the return value is undefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 * See crt0.c for further explanation and _start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2380 #ifdef __cplusplus
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2381 extern "C" int _start ();
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2382 #else
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2383 extern int _start ();
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2384 #endif
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2385
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 #ifndef HAVE_TEXT_START
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 start_of_text (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 #ifdef TEXT_START
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 return ((char *) TEXT_START);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 #ifdef GOULD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 extern csrt ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 return ((char *) csrt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 #else /* not GOULD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 return ((char *) _start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 #endif /* GOULD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 #endif /* TEXT_START */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 #endif /* not HAVE_TEXT_START */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 * Return the address of the start of the data segment prior to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 * doing an unexec. After unexec the return value is undefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 * See crt0.c for further information and definition of data_start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 * Apparently, on BSD systems this is etext at startup. On
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 * USG systems (swapping) this is highly mmu dependent and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 * is also dependent on whether or not the program is running
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 * with shared text. Generally there is a (possibly large)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 * gap between end of text and start of data with shared text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 * On Uniplus+ systems with shared text, data starts at a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 * fixed address. Each port (from a given oem) is generally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 * different, and the specific value of the start of data can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 * be obtained via the UniPlus+ specific "uvar" system call,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 * however the method outlined in crt0.c seems to be more portable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 * Probably what will have to happen when a USG unexec is available,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 * at least on UniPlus, is temacs will have to be made unshared so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 * that text and data are contiguous. Then once loadup is complete,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 * unexec will produce a shared executable where the data can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 * at the normal shared text boundry and the startofdata variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 * will be patched by unexec to the correct value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2428
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 start_of_data (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 #ifdef DATA_START
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 return ((char *) DATA_START);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 #ifdef ORDINARY_LINK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 * data_start isn't defined. We take the address of environ, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 * is known to live at or near the start of the system crt0.c, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 * we don't sweat the handful of bytes that might lose.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 extern char **environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 return((char *) &environ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 extern int data_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 return ((char *) &data_start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 #endif /* ORDINARY_LINK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 #endif /* DATA_START */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 #ifndef CANNOT_DUMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 /* Some systems that cannot dump also cannot implement these. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 * Return the address of the end of the text segment prior to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 * doing an unexec. After unexec the return value is undefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2460
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 end_of_text (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 #ifdef TEXT_END
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 return ((char *) TEXT_END);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 extern int etext;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 return ((char *) &etext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2471
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 * Return the address of the end of the data segment prior to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 * doing an unexec. After unexec the return value is undefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 end_of_data (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 #ifdef DATA_END
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 return ((char *) DATA_END);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 extern int edata;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 return ((char *) &edata);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 #endif /* not CANNOT_DUMP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 /* get the system name */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 /* init_system_name sets up the string for the Lisp function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 system-name to return. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 extern Lisp_Object Vsystem_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 #if defined (HAVE_SOCKETS) && !defined (VMS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 # include <sys/socket.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 # include <netdb.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 #endif /* HAVE_SOCKETS and not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 init_system_name (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 #if defined (VMS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 char *sp, *end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 if ((sp = egetenv ("SYS$NODE")) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 Vsystem_name = build_string ("vax-vms");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 else if ((end = strchr (sp, ':')) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 Vsystem_name = build_string (sp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 Vsystem_name = make_string ((Bufbyte *) sp, end - sp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 #elif !defined (HAVE_GETHOSTNAME)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 struct utsname uts;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 uname (&uts);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 Vsystem_name = build_string (uts.nodename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 #else /* HAVE_GETHOSTNAME */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 unsigned int hostname_size = 256;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 char *hostname = (char *) alloca (hostname_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 /* Try to get the host name; if the buffer is too short, try
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 again. Apparently, the only indication gethostname gives of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 whether the buffer was large enough is the presence or absence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 of a '\0' in the string. Eech. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 for (;;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 gethostname (hostname, hostname_size - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 hostname[hostname_size - 1] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 /* Was the buffer large enough for the '\0'? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 if (strlen (hostname) < (size_t) (hostname_size - 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 hostname_size <<= 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 hostname = (char *) alloca (hostname_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 # ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 /* Turn the hostname into the official, fully-qualified hostname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 Don't do this if we're going to dump; this can confuse system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 libraries on some machines and make the dumped emacs core dump. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 # ifndef CANNOT_DUMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 if (initialized)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 # endif /* not CANNOT_DUMP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 struct hostent *hp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 int count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 # ifdef TRY_AGAIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 for (count = 0; count < 10; count++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 h_errno = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 stop_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 hp = gethostbyname (hostname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 # ifdef TRY_AGAIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 if (! (hp == 0 && h_errno == TRY_AGAIN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 Fsleep_for (make_int (1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 if (hp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 CONST char *fqdn = (CONST char *) hp->h_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 if (!strchr (fqdn, '.'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 /* We still don't have a fully qualified domain name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 Try to find one in the list of alternate names */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 char **alias = hp->h_aliases;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 while (*alias && !strchr (*alias, '.'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 alias++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 if (*alias)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 fqdn = *alias;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 hostname = (char *) alloca (strlen (fqdn) + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 strcpy (hostname, fqdn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 # endif /* HAVE_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 Vsystem_name = build_string (hostname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 #endif /* HAVE_GETHOSTNAME and not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 Bufbyte *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 Bytecount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
2590 for (i = 0, p = XSTRING_DATA (Vsystem_name);
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
2591 i < XSTRING_LENGTH (Vsystem_name);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 i++, p++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 if (*p == ' ' || *p == '\t')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 *p = '-';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 /* Emulation of select() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 #ifndef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 #ifndef HAVE_SELECT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 ERROR: XEmacs requires a working select().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 #endif /* not HAVE_SELECT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 /* Emulation of signal stuff */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 /* BSD 4.1 crap deleted. 4.2 was released in 1983, for God's sake! I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 can't imagine that anyone is actually running that OS any more.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 You can't use X under it (I think) because there's no select().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 Anyway, the signal stuff has all been changed. If someone wants to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 get this stuff working again, look in the FSF Emacs sources. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2623
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 /* POSIX signals support - DJB */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 #ifdef HAVE_SIGPROCMASK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 /* #### Is there any reason this is static global rather than local? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 static struct sigaction new_action, old_action;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 signal_handler_t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 sys_do_signal (int signal_number, signal_handler_t action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 /* XEmacs works better if system calls are *not* restarted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 This allows C-g to interrupt reads and writes, on most systems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 #### Another possibility is to just longjmp() out of the signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 handler. According to W.R. Stevens, this should be OK on all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 systems. However, I don't want to deal with the potential
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 evil ramifications of this at this point. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 #ifdef DGUX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 /* This gets us restartable system calls for efficiency.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 The "else" code will work as well. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 return (berk_signal (signal_number, action));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 sigemptyset (&new_action.sa_mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 new_action.sa_handler = action;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 #if defined (SA_RESTART)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 /* Emacs mostly works better with restartable system services. If this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 * flag exists, we probably want to turn it on here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 new_action.sa_flags = SA_RESTART;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 new_action.sa_flags = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 sigaction (signal_number, &new_action, &old_action);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 return (old_action.sa_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 #endif /* DGUX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 #else /* not 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 sigemptyset (&new_action.sa_mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 new_action.sa_handler = action;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 #if defined (SA_INTERRUPT) /* don't restart system calls, under SunOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 new_action.sa_flags = SA_INTERRUPT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 new_action.sa_flags = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 sigaction (signal_number, &new_action, &old_action);
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 175
diff changeset
2673 return (signal_handler_t) (old_action.sa_handler);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 #endif /* not 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 #elif defined (HAVE_SIGBLOCK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 /* We use sigvec() rather than signal() if we have it, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 it lets us specify interruptible system calls. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 signal_handler_t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 sys_do_signal (int signal_number, signal_handler_t action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 struct sigvec vec, ovec;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 vec.sv_handler = action;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 vec.sv_mask = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 #ifdef SV_INTERRUPT /* don't restart system calls */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 vec.sv_flags = SV_INTERRUPT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 vec.sv_flags = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 sigvec (signal_number, &vec, &ovec);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 return (ovec.sv_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 #endif /* HAVE_SIGBLOCK (HAVE_SIGPROCMASK) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 /* Emulation of strerror() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 #ifndef HAVE_STRERROR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 #if defined (VMS) && defined (LINK_CRTL_SHARE) && defined (SHAREABLE_LIB_BUG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 /* Variables declared noshare and initialized in sharable libraries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 cannot be shared. The VMS linker incorrectly forces you to use a private
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 version which is uninitialized... If not for this "feature", we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 could use the C library definition of sys_nerr and sys_errlist. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 CONST char *sys_errlist[] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 "error 0",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 "not owner",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 "no such file or directory",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 "no such process",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 "interrupted system call",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 "I/O error",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 "no such device or address",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 "argument list too long",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 "exec format error",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 "bad file number",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 "no child process",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 "no more processes",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 "not enough memory",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 "permission denied",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 "bad address",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 "block device required",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 "mount devices busy",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 "file exists",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 "cross-device link",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 "no such device",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 "not a directory",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 "is a directory",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 "invalid argument",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 "file table overflow",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 "too many open files",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 "not a typewriter",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 "text file busy",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 "file too big",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 "no space left on device",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 "illegal seek",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 "read-only file system",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 "too many links",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 "broken pipe",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 "math argument",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 "result too large",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 "I/O stream empty",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 "vax/vms specific error code nontranslatable error"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 int sys_nerr = countof (sys_errlist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 #endif /* VMS & LINK_CRTL_SHARE & SHAREABLE_LIB_BUG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 /* Irix added here by gparker@sni-usa.com for XEmacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 extern CONST char *sys_errlist[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 extern int sys_nerr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 #ifdef __NetBSD__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 extern char *sys_errlist[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 extern int sys_nerr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 CONST char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 strerror (int errnum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 if (errnum >= 0 && errnum < sys_nerr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 return sys_errlist[errnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 return ((CONST char *) GETTEXT ("Unknown error"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 #endif /* ! HAVE_STRERROR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 /* Encapsulations of system calls */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 #define PATHNAME_CONVERT_OUT(path) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (path, path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 /***** VMS versions are at the bottom of this file *****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 /***** MSDOS versions are in msdos.c *****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 /***************** low-level calls ****************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 * On USG systems the system calls are INTERRUPTIBLE by signals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 * that the user program has elected to catch. Thus the system call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 * must be retried in these cases. To handle this without massive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 * changes in the source code, we remap the standard system call names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 * to names for our own functions in sysdep.c that do the system call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 * with retries. Actually, for portability reasons, it is good
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 * programming practice, as this example shows, to limit all actual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 * system calls to a single occurrence in the source. Sure, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 * adds an extra level of function call overhead but it is almost
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 * always negligible. Fred Fish, Unisoft Systems Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 approach to programming and its connection to the silly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 interruptible-system-call business. To find it, look at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 Jamie's home page (http://www.netscape.com/people/jwz). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 #ifdef ENCAPSULATE_OPEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 sys_open (CONST char *path, int oflag, ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 int mode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 va_list ap;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2822
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 va_start (ap, oflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 mode = va_arg (ap, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 va_end (ap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 #ifdef INTERRUPTIBLE_OPEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 int rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 while ((rtnval = open (path, oflag, mode)) == -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 && (errno == EINTR));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 return rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 return open (path, oflag, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 #endif /* ENCAPSULATE_OPEN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
2841
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 #ifdef ENCAPSULATE_CLOSE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 sys_close (int fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 #ifdef INTERRUPTIBLE_CLOSE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 int did_retry = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 register int rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 while ((rtnval = close (fd)) == -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 && (errno == EINTR))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 did_retry = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 /* If close is interrupted SunOS 4.1 may or may not have closed the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 file descriptor. If it did the second close will fail with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 errno = EBADF. That means we have succeeded. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 if (rtnval == -1 && did_retry && errno == EBADF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 return rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 return close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 #endif /* ENCAPSULATE_CLOSE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 sys_read_1 (int fildes, void *buf, unsigned int nbyte, int allow_quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 return vms_read (fildes, buf, nbyte);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 int rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 while ((rtnval = read (fildes, buf, nbyte)) == -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 && (errno == EINTR))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 if (allow_quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 REALLY_QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 return rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 #ifdef ENCAPSULATE_READ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 sys_read (int fildes, void *buf, unsigned int nbyte)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 return sys_read_1 (fildes, buf, nbyte, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 #endif /* ENCAPSULATE_READ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 sys_write_1 (int fildes, CONST void *buf, unsigned int nbyte, int allow_quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 return vms_write (fildes, buf, nbyte);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 int rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 int bytes_written = 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
2902 CONST char *b = (CONST char *) buf;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 while (nbyte > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 rtnval = write (fildes, b, nbyte);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 if (allow_quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 REALLY_QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 if (rtnval == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 if (errno == EINTR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 return (bytes_written ? bytes_written : -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 b += rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 nbyte -= rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 bytes_written += rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 return (bytes_written);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 #ifdef ENCAPSULATE_WRITE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 sys_write (int fildes, CONST void *buf, unsigned int nbyte)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 return sys_write_1 (fildes, buf, nbyte, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 #endif /* ENCAPSULATE_WRITE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 /**************** stdio calls ****************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 /* There is at least some evidence that the stdio calls are interruptible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 just like the normal system calls, at least on some systems. In any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 case, it doesn't hurt to encapsulate them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 /* #### Should also encapsulate fflush().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 #### Should conceivably encapsulate getchar() etc. What a pain! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 #ifdef ENCAPSULATE_FOPEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 FILE *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 sys_fopen (CONST char *path, CONST char *type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 #ifdef INTERRUPTIBLE_OPEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 FILE *rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 while (!(rtnval = fopen (path, type)) && (errno == EINTR));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 return rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 return fopen (path, type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 #endif /* ENCAPSULATE_FOPEN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
2962
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 #ifdef ENCAPSULATE_FCLOSE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 sys_fclose (FILE *stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 #ifdef INTERRUPTIBLE_CLOSE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 int rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 while ((rtnval = fclose (stream)) == EOF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 && (errno == EINTR))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 return rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 return fclose (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 #endif /* ENCAPSULATE_FCLOSE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
2980
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 #ifdef ENCAPSULATE_FREAD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 size_t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 sys_fread (void *ptr, size_t size, size_t nitem, FILE *stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 #ifdef INTERRUPTIBLE_IO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 size_t rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 size_t items_read = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 char *b = (char *) ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 while (nitem > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 rtnval = fread (b, size, nitem, stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 if (rtnval == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 if (ferror (stream) && errno == EINTR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 return items_read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 b += size*rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 nitem -= rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 items_read += rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 return (items_read);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 return fread (ptr, size, nitem, stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 #endif /* ENCAPSULATE_FREAD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3011
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 #ifdef ENCAPSULATE_FWRITE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 size_t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 sys_fwrite (CONST void *ptr, size_t size, size_t nitem, FILE *stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 #ifdef INTERRUPTIBLE_IO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 size_t rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 size_t items_written = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 CONST char *b = (CONST char *) ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 while (nitem > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 rtnval = fwrite (b, size, nitem, stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 if (rtnval == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 if (ferror (stream) && errno == EINTR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 return items_written;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 b += size*rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 nitem -= rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 items_written += rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 return (items_written);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 #elif defined (VMS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 return vms_fwrite (ptr, size, nitem, stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 return fwrite (ptr, size, nitem, stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 #endif /* ENCAPSULATE_FWRITE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 /********************* directory calls *******************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 #ifdef ENCAPSULATE_CHDIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 sys_chdir (CONST char *path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 return dos_chdir (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 return chdir (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 #endif /* ENCAPSULATE_CHDIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3060
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 #ifdef ENCAPSULATE_MKDIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 sys_mkdir (CONST char *path, int mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 return mkdir (path, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 #endif /* ENCAPSULATE_MKDIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3070
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 #ifdef ENCAPSULATE_OPENDIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 DIR *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 sys_opendir (CONST char *filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 DIR *rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 PATHNAME_CONVERT_OUT (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 while (!(rtnval = opendir (filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 && (errno == EINTR))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 return rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 #endif /* ENCAPSULATE_OPENDIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3085
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 #ifdef ENCAPSULATE_READDIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 DIRENTRY *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 sys_readdir (DIR *dirp)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3089 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 DIRENTRY *rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 /* Apparently setting errno is necessary on some systems?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 Maybe readdir() doesn't always set errno ?! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 while (!(errno = 0, rtnval = readdir (dirp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 && (errno == EINTR))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 ;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3097 #ifndef MULE
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 return rtnval;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3099 #else /* MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3100 if (rtnval == NULL) /* End of directory */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3101 return NULL;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3102 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3103 Extcount external_len;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3104 int ascii_filename_p = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3105 CONST Extbyte * CONST external_name = (CONST Extbyte *) rtnval->d_name;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3106
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3107 /* Optimize for the common all-ASCII case, computing len en passant */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3108 for (external_len = 0; external_name[external_len] ; external_len++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3109 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3110 if (!BYTE_ASCII_P (external_name[external_len]))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3111 ascii_filename_p = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3112 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3113 if (ascii_filename_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3114 return rtnval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3115
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3116 { /* Non-ASCII filename */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3117 static Bufbyte_dynarr *internal_DIRENTRY;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3118 CONST Bufbyte *internal_name;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3119 Bytecount internal_len;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3120 if (!internal_DIRENTRY)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3121 internal_DIRENTRY = Dynarr_new (Bufbyte);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3122 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3123 Dynarr_reset (internal_DIRENTRY);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3124
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3125 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3126 offsetof (DIRENTRY, d_name));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3127
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3128 internal_name =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3129 convert_from_external_format (external_name, external_len,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3130 &internal_len, FORMAT_FILENAME);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3131
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3132 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3133 Dynarr_add (internal_DIRENTRY, 0); /* zero-terminate */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3134 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3135 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3136 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 46
diff changeset
3137 #endif /* MULE */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 #endif /* ENCAPSULATE_READDIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3141
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 #ifdef ENCAPSULATE_CLOSEDIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 sys_closedir (DIR *dirp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 int rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 while ((rtnval = closedir (dirp)) == -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 && (errno == EINTR))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 return rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 #endif /* ENCAPSULATE_CLOSEDIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3155
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 #ifdef ENCAPSULATE_RMDIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 sys_rmdir (CONST char *path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 return rmdir (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 #endif /* ENCAPSULATE_RMDIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 /***************** file-information calls ******************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 #ifdef ENCAPSULATE_ACCESS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 sys_access (CONST char *path, int mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 return vms_access (path, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 return access (path, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 #endif /* ENCAPSULATE_ACCESS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3181
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3182 #ifdef HAVE_EACCESS
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3183 #ifdef ENCAPSULATE_EACCESS
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3184 int
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3185 sys_eaccess (CONST char *path, int mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3186 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3187 PATHNAME_CONVERT_OUT (path);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3188 return eaccess (path, mode);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3189 }
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3190 #endif /* ENCAPSULATE_EACCESS */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3191 #endif /* HAVE_EACCESS */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3192
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3193
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 #ifdef ENCAPSULATE_LSTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 sys_lstat (CONST char *path, struct stat *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 return lstat (path, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 #endif /* ENCAPSULATE_LSTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3203
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 #ifdef ENCAPSULATE_READLINK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 sys_readlink (CONST char *path, char *buf, int bufsiz)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 /* #### currently we don't do conversions on the incoming data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 return readlink (path, buf, bufsiz);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 #endif /* ENCAPSULATE_READLINK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3214
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 #ifdef ENCAPSULATE_STAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 sys_stat (CONST char *path, struct stat *buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 return stat (path, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 #endif /* ENCAPSULATE_STAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 /****************** file-manipulation calls *****************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 #ifdef ENCAPSULATE_CHMOD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 sys_chmod (CONST char *path, int mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 return chmod (path, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 #endif /* ENCAPSULATE_CHMOD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3236
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 #ifdef ENCAPSULATE_CREAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 sys_creat (CONST char *path, int mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 return creat (path, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 #endif /* ENCAPSULATE_CREAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3246
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 #ifdef ENCAPSULATE_LINK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 sys_link (CONST char *existing, CONST char *new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 PATHNAME_CONVERT_OUT (existing);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 PATHNAME_CONVERT_OUT (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 return link (existing, new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 #endif /* ENCAPSULATE_LINK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3257
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 #ifdef ENCAPSULATE_RENAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 sys_rename (CONST char *old, CONST char *new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 PATHNAME_CONVERT_OUT (old);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 PATHNAME_CONVERT_OUT (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 return rename (old, new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 #endif /* ENCAPSULATE_RENAME */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3268
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 #ifdef ENCAPSULATE_SYMLINK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 sys_symlink (CONST char *name1, CONST char *name2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 PATHNAME_CONVERT_OUT (name1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 PATHNAME_CONVERT_OUT (name2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 return symlink (name1, name2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 #endif /* ENCAPSULATE_SYMLINK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3279
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 #ifdef ENCAPSULATE_UNLINK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 sys_unlink (CONST char *path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 PATHNAME_CONVERT_OUT (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 return unlink (path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 #endif /* ENCAPSULATE_UNLINK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3289
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3290 #ifdef ENCAPSULATE_EXECVP
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3291 int
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 78
diff changeset
3292 sys_execvp (CONST char *path, char * CONST * argv)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3293 {
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 78
diff changeset
3294 int i, argc;
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 78
diff changeset
3295 CONST char ** new_argv;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3296
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3297 PATHNAME_CONVERT_OUT (path);
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 78
diff changeset
3298 for (argc = 0; argv[argc]; argc++)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 78
diff changeset
3299 ;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3300 new_argv = alloca_array (CONST char *, argc + 1);
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 78
diff changeset
3301 for (i = 0; i < argc; i++)
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 78
diff changeset
3302 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (argv[i], new_argv[i]);
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 78
diff changeset
3303 new_argv[argc] = NULL;
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 78
diff changeset
3304 return execvp (path, (char **) new_argv);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3305 }
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3306 #endif /* ENCAPSULATE_EXECVP */
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3307
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 /* Emulations of missing system calls */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 /***** (these are primarily required for USG, it seems) *****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3315 #ifndef HAVE_GETCWD
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3316 char *
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3317 getcwd (char *pathname, int size)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3318 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3319 return getwd (pathname);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3320 }
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3321 #endif /* emulate getcwd */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3322
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3323
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3324 #if 0 /* mrb */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 /*
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3326 * Warning, this function may not duplicate BSD 4.2 action properly
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 * under error conditions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 #ifndef HAVE_GETWD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 getwd (char *pathname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 char *npath, *spath;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 #if !__STDC__ && !defined(STDC_HEADERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 extern char *getcwd ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 spath = npath = getcwd ((char *) 0, MAXPATHLEN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 if (spath == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 return spath;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 /* On Altos 3068, getcwd can return @hostname/dir, so discard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 up to first slash. Should be harmless on other systems. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 while (*npath && *npath != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 npath++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 strcpy (pathname, npath);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 xfree (spath); /* getcwd uses malloc */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 return pathname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 #endif /* HAVE_GETWD */
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 157
diff changeset
3351 #endif /* 0 - mrb */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 * Emulate rename using unlink/link. Note that this is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 * only partially correct. Also, doesn't enforce restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 * that files be of same type (regular->regular, dir->dir, etc).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 #ifndef HAVE_RENAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361 rename (CONST char *from, CONST char *to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 if (access (from, 0) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 unlink (to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 if (link (from, to) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367 if (unlink (from) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 return (-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 }
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 12
diff changeset
3372 #endif /* HAVE_RENAME */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374 #ifdef HPUX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375 #ifndef HAVE_PERROR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377 /* HPUX curses library references perror, but as far as we know
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 it won't be called. Anyway this definition will do for now. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 perror (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 #endif /* not HAVE_PERROR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 #endif /* HPUX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 #ifndef HAVE_DUP2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 * Emulate BSD dup2. First close newd if it already exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 * Then, attempt to dup oldd. If not successful, call dup2 recursively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 * until we are, then close the unsuccessful ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 dup2 (int oldd, int newd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398 int fd, ret;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3399
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 sys_close (newd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 #ifdef F_DUPFD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 fd = fcntl (oldd, F_DUPFD, newd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 if (fd != newd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 error ("can't dup2 (%i,%i) : %s", oldd, newd, strerror (errno));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 fd = dup (old);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 if (fd == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 if (fd == new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 return new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 ret = dup2 (old, new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 sys_close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414 return ret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415 #endif /* F_DUPFD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 #endif /* not HAVE_DUP2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 * Gettimeofday. Simulate as much as possible. Only accurate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 * to nearest second. Emacs doesn't use tzp so ignore it for now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 #if !defined (HAVE_GETTIMEOFDAY)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3426
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 gettimeofday (struct timeval *tp, struct timezone *tzp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 extern long time ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3432 tp->tv_sec = time ((long *)0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433 tp->tv_usec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 if (tzp != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 tzp->tz_minuteswest = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3438
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 #endif /* !HAVE_GETTIMEOFDAY */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
3440
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 /* No need to encapsulate utime and utimes explicitly because all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 access to those functions goes through the following. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 #ifdef HAVE_UTIMES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 struct timeval tv[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 tv[0] = atime;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450 tv[1] = mtime;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 return utimes (filename, tv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 #else /* not HAVE_UTIMES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 struct utimbuf utb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 utb.actime = EMACS_SECS (atime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 utb.modtime = EMACS_SECS (mtime);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 return utime (filename, &utb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 #endif /* not HAVE_UTIMES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 static long ticks_per_second;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 static long orig_user_ticks, orig_system_ticks;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 EMACS_TIME orig_real_time;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 static int process_times_available;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 /* Return the relative user and system tick count. We try to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 maintain calculations in terms of integers as long as possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 for increased accuracy. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 get_process_times_1 (long *user_ticks, long *system_ticks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 {
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3475 #if defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 /* We have the POSIX times() function available. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 struct tms tttt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 times (&tttt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 *user_ticks = (long) tttt.tms_utime;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 *system_ticks = (long) tttt.tms_stime;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482 #elif defined (CLOCKS_PER_SEC)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3483 *user_ticks = (long) clock ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3484 *system_ticks = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 init_process_times_very_early (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 #if defined (_SC_CLK_TCK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 ticks_per_second = sysconf (_SC_CLK_TCK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 #elif defined (CLK_TCK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 ticks_per_second = CLK_TCK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 #elif defined (CLOCKS_PER_SEC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 ticks_per_second = CLOCKS_PER_SEC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 process_times_available = get_process_times_1 (&orig_user_ticks,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 &orig_system_ticks);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 EMACS_GET_TIME (orig_real_time);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 /* Return the user and system times used up by this process so far. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 get_process_times (double *user_time, double *system_time, double *real_time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511 EMACS_TIME curr_real_time;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 EMACS_TIME elapsed_time;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 long curr_user_ticks, curr_system_ticks;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 EMACS_GET_TIME (curr_real_time);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 EMACS_SUB_TIME (elapsed_time, curr_real_time, orig_real_time);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517 *real_time = (EMACS_SECS (elapsed_time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518 + ((double) EMACS_USECS (elapsed_time)) / 1000000);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 if (get_process_times_1 (&curr_user_ticks, &curr_system_ticks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 *user_time = (((double) (curr_user_ticks - orig_user_ticks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 / ticks_per_second);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 *system_time = (((double) (curr_system_ticks - orig_system_ticks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 / ticks_per_second);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 /* MS-DOS or equally lame OS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 *user_time = *real_time;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 *system_time = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534 #ifndef HAVE_RANDOM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 #ifdef random
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 #define HAVE_RANDOM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 /* Figure out how many bits the system's random number generator uses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 `random' and `lrand48' are assumed to return 31 usable bits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 BSD `rand' returns a 31 bit value but the low order bits are unusable;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 so we'll shift it and treat it like the 15-bit USG `rand'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 #ifndef RAND_BITS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 # ifdef HAVE_RANDOM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 # define RAND_BITS 31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 # else /* !HAVE_RANDOM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 # ifdef HAVE_LRAND48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 # define RAND_BITS 31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 # define random lrand48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 # else /* !HAVE_LRAND48 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 # define RAND_BITS 15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 # if RAND_MAX == 32767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 # define random rand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 # else /* RAND_MAX != 32767 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 # if RAND_MAX == 2147483647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 # define random() (rand () >> 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 # else /* RAND_MAX != 2147483647 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 # ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 # define random rand
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 # define random() (rand () >> 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 # endif /* !BSD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 # endif /* RAND_MAX != 2147483647 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 # endif /* RAND_MAX != 32767 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 # endif /* !HAVE_LRAND48 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 # endif /* !HAVE_RANDOM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 #endif /* !RAND_BITS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 void seed_random (long arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 seed_random (long arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 #ifdef HAVE_RANDOM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 srandom ((unsigned int)arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 # ifdef HAVE_LRAND48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 srand48 (arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 srand ((unsigned int)arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 * Build a full Emacs-sized word out of whatever we've got.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 * This suffices even for a 64-bit architecture with a 15-bit rand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 long get_random (void);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591 long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 get_random (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 long val = random ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 #if VALBITS > RAND_BITS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 val = (val << RAND_BITS) ^ random ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 #if VALBITS > 2*RAND_BITS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 val = (val << RAND_BITS) ^ random ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 #if VALBITS > 3*RAND_BITS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 val = (val << RAND_BITS) ^ random ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 #if VALBITS > 4*RAND_BITS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602 val = (val << RAND_BITS) ^ random ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 #endif /* need at least 5 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604 #endif /* need at least 4 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3605 #endif /* need at least 3 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 #endif /* need at least 2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 return val & ((1L << VALBITS) - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 #ifdef WRONG_NAME_INSQUE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 insque (caddr_t q, caddr_t p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615 _insque (q,p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 /* Strings corresponding to defined signals */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3627 #ifdef WINDOWSNT
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3628 char *sys_siglist[] =
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3629 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3630 "bum signal!!",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3631 "hangup",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3632 "interrupt",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3633 "quit",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3634 "illegal instruction",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3635 "trace trap",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3636 "iot instruction",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3637 "emt instruction",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3638 "floating point exception",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3639 "kill",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3640 "bus error",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3641 "segmentation violation",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3642 "bad argument to system call",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3643 "write on a pipe with no one to read it",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3644 "alarm clock",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3645 "software termination signal from kill",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3646 "status signal",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3647 "sendable stop signal not from tty",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3648 "stop signal from tty",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3649 "continue a stopped process",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3650 "child status has changed",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3651 "background read attempted from control tty",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3652 "background write attempted from control tty",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3653 "input record available at control tty",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3654 "exceeded CPU time limit",
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3655 "exceeded file size limit"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3656 };
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3657 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 82
diff changeset
3658
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 #ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 #ifdef AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 CONST char *sys_siglist[NSIG + 1] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663 /* AIX has changed the signals a bit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 DEFER_GETTEXT ("bogus signal"), /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 DEFER_GETTEXT ("crash likely"), /* 7 SIGDANGER */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 DEFER_GETTEXT ("software termination signum"), /* 15 SIGTERM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 DEFER_GETTEXT ("bogus signal"), /* 20 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 DEFER_GETTEXT ("bogus signal"), /* 21 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 DEFER_GETTEXT ("bogus signal"), /* 22 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 DEFER_GETTEXT ("bogus signal"), /* 23 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 DEFER_GETTEXT ("bogus signal"), /* 24 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689 DEFER_GETTEXT ("LAN I/O interrupt"), /* 25 SIGAIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 DEFER_GETTEXT ("PTY I/O interrupt"), /* 26 SIGPTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691 DEFER_GETTEXT ("I/O intervention required"), /* 27 SIGIOINT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 #ifdef AIXHFT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 DEFER_GETTEXT ("HFT grant"), /* 28 SIGGRANT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 DEFER_GETTEXT ("HFT retract"), /* 29 SIGRETRACT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 DEFER_GETTEXT ("HFT sound done"), /* 30 SIGSOUND */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 DEFER_GETTEXT ("HFT input ready"), /* 31 SIGMSG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 #else /* USG, not AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 CONST char *sys_siglist[NSIG + 1] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 DEFER_GETTEXT ("bogus signal"), /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 DEFER_GETTEXT ("EMT instruction"), /* 7 SIGEMT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 DEFER_GETTEXT ("software termination signum"), /* 15 SIGTERM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 #ifdef sun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 DEFER_GETTEXT ("window size changed"), /* 20 SIGWINCH */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 DEFER_GETTEXT ("urgent socket condition"), /* 21 SIGURG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 DEFER_GETTEXT ("pollable event occurred"), /* 22 SIGPOLL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 DEFER_GETTEXT ("stop (cannot be caught or ignored)"), /* 23 SIGSTOP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 DEFER_GETTEXT ("user stop requested from tty"), /* 24 SIGTSTP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 DEFER_GETTEXT ("stopped process has been continued"), /* 25 SIGCONT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 DEFER_GETTEXT ("background tty read attempted"), /* 26 SIGTTIN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 DEFER_GETTEXT ("background tty write attempted"), /* 27 SIGTTOU */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 DEFER_GETTEXT ("virtual timer expired"), /* 28 SIGVTALRM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 DEFER_GETTEXT ("profiling timer expired"), /* 29 SIGPROF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 DEFER_GETTEXT ("exceeded cpu limit"), /* 30 SIGXCPU */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 DEFER_GETTEXT ("exceeded file size limit"), /* 31 SIGXFSZ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 DEFER_GETTEXT ("process's lwps are blocked"), /* 32 SIGWAITING */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 DEFER_GETTEXT ("special signal used by thread library"), /* 33 SIGLWP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 #ifdef SIGFREEZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 DEFER_GETTEXT ("special signal used by CPR"), /* 34 SIGFREEZE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 #ifdef SIGTHAW
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 DEFER_GETTEXT ("special signal used by CPR"), /* 35 SIGTHAW */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744 #endif /* sun */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 #endif /* not AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 #endif /* USG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 #ifdef DGUX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 CONST char *sys_siglist[NSIG + 1] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 DEFER_GETTEXT ("null signal"), /* 0 SIGNULL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 DEFER_GETTEXT ("abort termination"), /* 6 SIGABRT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 DEFER_GETTEXT ("SIGEMT"), /* 7 SIGEMT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 DEFER_GETTEXT ("write on a pipe with no reader"), /* 13 SIGPIPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 DEFER_GETTEXT ("software termination signal"), /* 15 SIGTERM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770 DEFER_GETTEXT ("child stopped or terminated"), /* 18 SIGCLD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 DEFER_GETTEXT ("window size changed"), /* 20 SIGWINCH */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 DEFER_GETTEXT ("undefined"), /* 21 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 DEFER_GETTEXT ("pollable event occurred"), /* 22 SIGPOLL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 DEFER_GETTEXT ("sendable stop signal not from tty"), /* 23 SIGSTOP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 DEFER_GETTEXT ("stop signal from tty"), /* 24 SIGSTP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 DEFER_GETTEXT ("continue a stopped process"), /* 25 SIGCONT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778 DEFER_GETTEXT ("attempted background tty read"), /* 26 SIGTTIN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 DEFER_GETTEXT ("attempted background tty write"), /* 27 SIGTTOU */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 DEFER_GETTEXT ("undefined"), /* 28 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 DEFER_GETTEXT ("undefined"), /* 29 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782 DEFER_GETTEXT ("undefined"), /* 30 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 DEFER_GETTEXT ("undefined"), /* 31 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 DEFER_GETTEXT ("undefined"), /* 32 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 DEFER_GETTEXT ("socket (TCP/IP) urgent data arrival"), /* 33 SIGURG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786 DEFER_GETTEXT ("I/O is possible"), /* 34 SIGIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 DEFER_GETTEXT ("exceeded cpu time limit"), /* 35 SIGXCPU */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 DEFER_GETTEXT ("exceeded file size limit"), /* 36 SIGXFSZ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789 DEFER_GETTEXT ("virtual time alarm"), /* 37 SIGVTALRM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790 DEFER_GETTEXT ("profiling time alarm"), /* 38 SIGPROF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791 DEFER_GETTEXT ("undefined"), /* 39 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792 DEFER_GETTEXT ("file record locks revoked"), /* 40 SIGLOST */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 DEFER_GETTEXT ("undefined"), /* 41 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794 DEFER_GETTEXT ("undefined"), /* 42 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 DEFER_GETTEXT ("undefined"), /* 43 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796 DEFER_GETTEXT ("undefined"), /* 44 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 DEFER_GETTEXT ("undefined"), /* 45 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3798 DEFER_GETTEXT ("undefined"), /* 46 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3799 DEFER_GETTEXT ("undefined"), /* 47 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3800 DEFER_GETTEXT ("undefined"), /* 48 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801 DEFER_GETTEXT ("undefined"), /* 49 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802 DEFER_GETTEXT ("undefined"), /* 50 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3803 DEFER_GETTEXT ("undefined"), /* 51 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3804 DEFER_GETTEXT ("undefined"), /* 52 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3805 DEFER_GETTEXT ("undefined"), /* 53 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3806 DEFER_GETTEXT ("undefined"), /* 54 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3807 DEFER_GETTEXT ("undefined"), /* 55 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3808 DEFER_GETTEXT ("undefined"), /* 56 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3809 DEFER_GETTEXT ("undefined"), /* 57 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 DEFER_GETTEXT ("undefined"), /* 58 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811 DEFER_GETTEXT ("undefined"), /* 59 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812 DEFER_GETTEXT ("undefined"), /* 60 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 DEFER_GETTEXT ("undefined"), /* 61 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814 DEFER_GETTEXT ("undefined"), /* 62 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 DEFER_GETTEXT ("undefined"), /* 63 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3816 DEFER_GETTEXT ("notification message in mess. queue"), /* 64 SIGDGNOTIFY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3819 #endif /* DGUX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821 #endif /* ! SYS_SIGLIST_DECLARED && ! HAVE_SYS_SIGLIST */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825 /* Directory routines for systems that don't have them */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3826 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3828 #ifdef SYSV_SYSTEM_DIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830 #include <dirent.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834 closedir (DIR *dirp) /* stream from opendir */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836 int rtnval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 rtnval = sys_close (dirp->dd_fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840 /* Some systems (like Solaris) allocate the buffer and the DIR all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 in one block. Why in the world are we freeing this ourselves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 anyway? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 #if ! (defined (sun) && defined (USG5_4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844 xfree ((char *) dirp->dd_buf); /* directory block defined in <dirent.h> */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3846 xfree ((char *) dirp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3847 return (rtnval);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3849 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3850 #endif /* SYSV_SYSTEM_DIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 #ifdef NONSYSTEM_DIR_LIBRARY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854 DIR *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855 opendir (CONST char *filename) /* name of directory */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3856 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857 DIR *dirp; /* -> malloc'ed storage */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858 int fd; /* file descriptor for read */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 struct stat sbuf; /* result of fstat */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861 fd = sys_open (filename, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 if (fd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 if (fstat (fd, &sbuf) < 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 || (sbuf.st_mode & S_IFMT) != S_IFDIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3869 sys_close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870 return 0; /* bad luck today */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3873 dirp->dd_fd = fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3876 return dirp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3878
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880 closedir (DIR *dirp) /* stream from opendir */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882 sys_close (dirp->dd_fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883 xfree (dirp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887 #ifndef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888 #define DIRSIZ 14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889 struct olddir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891 ino_t od_ino; /* inode */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892 char od_name[DIRSIZ]; /* filename */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3896 static struct direct dir_static; /* simulated directory contents */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898 /* ARGUSED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899 struct direct *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3900 readdir (DIR *dirp) /* stream from opendir */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3901 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3902 #ifndef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3903 struct olddir *dp; /* -> directory data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3904 #else /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3905 struct dir$_name *dp; /* -> directory data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3906 struct dir$_version *dv; /* -> version data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3907 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3909 for (; ;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3910 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3911 if (dirp->dd_loc >= dirp->dd_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3912 dirp->dd_loc = dirp->dd_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3914 if (dirp->dd_size == 0 /* refill buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3916 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3918 #ifndef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3919 dp = (struct olddir *) &dirp->dd_buf[dirp->dd_loc];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3920 dirp->dd_loc += sizeof (struct olddir);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3922 if (dp->od_ino != 0) /* not deleted entry */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3923 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3924 dir_static.d_ino = dp->od_ino;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925 strncpy (dir_static.d_name, dp->od_name, DIRSIZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 dir_static.d_name[DIRSIZ] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3927 dir_static.d_namlen = strlen (dir_static.d_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3928 dir_static.d_reclen = sizeof (struct direct)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3929 - MAXNAMLEN + 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3930 + dir_static.d_namlen - dir_static.d_namlen % 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3931 return &dir_static; /* -> simulated structure */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3932 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3933 #else /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3934 dp = (struct dir$_name *) dirp->dd_buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3935 if (dirp->dd_loc == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3936 dirp->dd_loc = (dp->dir$b_namecount&1) ? dp->dir$b_namecount + 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937 : dp->dir$b_namecount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938 dv = (struct dir$_version *)&dp->dir$t_name[dirp->dd_loc];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939 dir_static.d_ino = dv->dir$w_fid_num;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940 dir_static.d_namlen = dp->dir$b_namecount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3941 dir_static.d_reclen = sizeof (struct direct)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3942 - MAXNAMLEN + 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943 + dir_static.d_namlen - dir_static.d_namlen % 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 dir_static.d_name[dir_static.d_namlen] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946 dirp->dd_loc = dirp->dd_size; /* only one record at a time */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 return &dir_static;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3948 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3949 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3952 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3953 /* readdirver is just like readdir except it returns all versions of a file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3954 as separate entries. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 /* ARGUSED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3957 struct direct *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3958 readdirver (DIR *dirp) /* stream from opendir */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3959 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3960 struct dir$_name *dp; /* -> directory data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3961 struct dir$_version *dv; /* -> version data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3963 if (dirp->dd_loc >= dirp->dd_size - sizeof (struct dir$_name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3964 dirp->dd_loc = dirp->dd_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3965
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3966 if (dirp->dd_size == 0 /* refill buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3967 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3968 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3970 dp = (struct dir$_name *) dirp->dd_buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3971 if (dirp->dd_loc == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3972 dirp->dd_loc = (dp->dir$b_namecount & 1) ? dp->dir$b_namecount + 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3973 : dp->dir$b_namecount;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3974 dv = (struct dir$_version *) &dp->dir$t_name[dirp->dd_loc];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3975 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3976 sprintf (&dir_static.d_name[dp->dir$b_namecount], ";%d", dv->dir$w_version);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3977 dir_static.d_namlen = strlen (dir_static.d_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3978 dir_static.d_ino = dv->dir$w_fid_num;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3979 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3980 + dir_static.d_namlen - dir_static.d_namlen % 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3981 dirp->dd_loc = ((char *) (++dv) - dp->dir$t_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3982 return &dir_static;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3983 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3985 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3987 #endif /* NONSYSTEM_DIR_LIBRARY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3990 /* mkdir and rmdir functions, for systems which don't have them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3992 #ifndef HAVE_MKDIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3993 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3994 * Written by Robert Rother, Mariah Corporation, August 1985.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3995 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3996 * If you want it, it's yours. All I ask in return is that if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3997 * figure out how to do this in a Bourne Shell script you send me
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3998 * a copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3999 * sdcsvax!rmr or rmr@uscd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4000 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4001 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4002 * subroutine. 11Mar86; hoptoad!gnu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4003 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4004 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4005 * subroutine didn't return EEXIST. It does now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4006 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4008 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4009 * Make a directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4010 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4011 #ifdef MKDIR_PROTOTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4012 MKDIR_PROTOTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4013 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4014 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4015 mkdir (CONST char *dpath, int dmode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4016 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4017 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4018 int cpid, status, fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4019 struct stat statbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4021 if (stat (dpath, &statbuf) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4022 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4023 errno = EEXIST; /* Stat worked, so it already exists */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4024 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4025 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4027 /* If stat fails for a reason other than non-existence, return error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4028 if (errno != ENOENT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4029 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4031 synch_process_alive = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4032 switch (cpid = fork ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4033 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4035 case -1: /* Error in fork() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4036 return (-1); /* Errno is set already */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4038 case 0: /* Child process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4039 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4040 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4041 * Cheap hack to set mode of new directory. Since this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4042 * child process is going away anyway, we zap its umask.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4043 * ####, this won't suffice to set SUID, SGID, etc. on this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4044 * directory. Does anybody care?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4045 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4046 status = umask (0); /* Get current umask */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4047 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4048 fd = sys_open ("/dev/null", 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4049 if (fd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4050 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4051 dup2 (fd, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4052 dup2 (fd, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4053 dup2 (fd, 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4054 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4055 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4056 _exit (-1); /* Can't exec /bin/mkdir */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4057 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4058
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4059 default: /* Parent process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4060 wait_for_termination (cpid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4061 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4062
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4063 if (synch_process_death != 0 || synch_process_retcode != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4064 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4065 errno = EIO; /* We don't know why, but */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4066 return -1; /* /bin/mkdir failed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4067 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4069 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4070 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4071 #endif /* not HAVE_MKDIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4073 #ifndef HAVE_RMDIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4074 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4075 rmdir (CONST char *dpath)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4076 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4077 int cpid, status, fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4078 struct stat statbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4079
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4080 if (stat (dpath, &statbuf) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4081 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4082 /* Stat just set errno. We don't have to */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4083 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4084 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4085
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4086 synch_process_alive = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4087 switch (cpid = fork ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4088 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4090 case -1: /* Error in fork() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4091 return (-1); /* Errno is set already */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4092
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4093 case 0: /* Child process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4094 fd = sys_open("/dev/null", 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4095 if (fd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4096 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4097 dup2 (fd, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4098 dup2 (fd, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4099 dup2 (fd, 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4100 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4101 execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4102 _exit (-1); /* Can't exec /bin/mkdir */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4104 default: /* Parent process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4105 wait_for_termination (cpid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4106 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4108 if (synch_process_death != 0 || synch_process_retcode != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4109 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4110 errno = EIO; /* We don't know why, but */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4111 return -1; /* /bin/rmdir failed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4112 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4114 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4115 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4116 #endif /* !HAVE_RMDIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4119 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4120 /* Misc. SunOS crap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4121 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4123 #ifdef USE_DL_STUBS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4125 /* These are included on Sunos 4.1 when we do not use shared libraries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4126 X11 libraries may refer to these functions but (we hope) do not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4127 actually call them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4129 void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4130 dlopen (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4131 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4132 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4133 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4135 void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4136 dlsym (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4137 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4138 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4139 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4141 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4142 dlclose (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4143 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4144 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4145 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4147 #endif /* USE_DL_STUBS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4150 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4151 /* VMS emulation of system calls */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4152 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4154 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4155 #include "vms-pwd.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4156 #include <acldef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4157 #include <chpdef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4158 #include <jpidef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4160 /* Return as a string the VMS error string pertaining to STATUS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4161 Reuses the same static buffer each time it is called. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4163 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4164 vmserrstr (int status) /* VMS status code */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4165 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4166 int bufadr[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4167 short len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4168 static char buf[257];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4170 bufadr[0] = sizeof buf - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4171 bufadr[1] = (int) buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4172 if (! (SYS$GETMSG (status, &len, bufadr, 0x1, 0) & 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4173 return "untranslatable VMS error status";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4174 buf[len] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4175 return buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4176 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4178 #ifdef access
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4179 #undef access
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4180
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4181 /* The following is necessary because 'access' emulation by VMS C (2.0) does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4182 * not work correctly. (It also doesn't work well in version 2.3.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4183 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4185 #ifdef VMS4_4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4187 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4188 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4190 typedef union {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4191 struct {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4192 unsigned short s_buflen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4193 unsigned short s_code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4194 char *s_bufadr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4195 unsigned short *s_retlenadr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4196 } s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4197 int end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4198 } item;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4199 #define buflen s.s_buflen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4200 #define code s.s_code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4201 #define bufadr s.s_bufadr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4202 #define retlenadr s.s_retlenadr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4204 #define R_OK 4 /* test for read permission */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4205 #define W_OK 2 /* test for write permission */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4206 #define X_OK 1 /* test for execute (search) permission */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4207 #define F_OK 0 /* test for presence of file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4209 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4210 vms_access (CONST char *path, int mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4211 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4212 static char *user = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4213 char dir_fn[512];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4215 /* translate possible directory spec into .DIR file name, so brain-dead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4216 * access can treat the directory like a file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4217 if (directory_file_name (path, dir_fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4218 path = dir_fn;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4219
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4220 if (mode == F_OK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4221 return access (path, mode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4222 if (user == NULL && (user = (char *) getenv ("USER")) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4223 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4225 int stat;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4226 int flags;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4227 int acces;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4228 unsigned short int dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4229 item itemlst[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4230 static int constant = ACL$C_FILE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4231 DESCRIPTOR (path_desc, path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4232 DESCRIPTOR (user_desc, user);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4233
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4234 flags = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4235 acces = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4236 if ((mode & X_OK) && ((stat = access (path, mode)) < 0 || mode == X_OK))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4237 return stat;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4238 if (mode & R_OK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4239 acces |= CHP$M_READ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4240 if (mode & W_OK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4241 acces |= CHP$M_WRITE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4242 itemlst[0].buflen = sizeof (int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4243 itemlst[0].code = CHP$_FLAGS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4244 itemlst[0].bufadr = (char *) &flags;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4245 itemlst[0].retlenadr = &dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4246 itemlst[1].buflen = sizeof (int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4247 itemlst[1].code = CHP$_ACCESS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4248 itemlst[1].bufadr = (char *) &acces;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4249 itemlst[1].retlenadr = &dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4250 itemlst[2].end = CHP$_END;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4251 stat = SYS$CHECK_ACCESS (&constant, &path_desc, &user_desc, itemlst);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4252 return stat == SS$_NORMAL ? 0 : -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4253 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4254 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4256 #else /* not VMS4_4 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4258 #include <prvdef.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4259 #define ACE$M_WRITE 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4260 #define ACE$C_KEYID 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4262 static unsigned short vms_memid, vms_grpid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4263 static unsigned int vms_uic;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4265 /* Called from init_sys_modes, so it happens not very often
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4266 but at least each time Emacs is loaded. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4267 sys_access_reinit (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4268 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4269 vms_uic = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4270 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4272 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4273 vms_access (CONST char *filename, int type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4274 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4275 struct FAB fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4276 struct XABPRO xab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4277 int status, size, i, typecode, acl_controlled;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4278 unsigned int *aclptr, *aclend, aclbuf[60];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4279 union prvdef prvmask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4281 /* Get UIC and GRP values for protection checking. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4282 if (vms_uic == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4283 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4284 status = LIB$GETJPI (&JPI$_UIC, 0, 0, &vms_uic, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4285 if (! (status & 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4286 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4287 vms_memid = vms_uic & 0xFFFF;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4288 vms_grpid = vms_uic >> 16;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4289 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4291 if (type != 2) /* not checking write access */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4292 return access (filename, type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4294 /* Check write protection. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4295
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4296 #define CHECKPRIV(bit) (prvmask.bit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4297 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4299 /* Find privilege bits */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4300 status = SYS$SETPRV (0, 0, 0, prvmask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4301 if (! (status & 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4302 error ("Unable to find privileges: %s", vmserrstr (status));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4303 if (CHECKPRIV (PRV$V_BYPASS))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4304 return 0; /* BYPASS enabled */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4305 fab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4306 fab.fab$b_fac = FAB$M_GET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4307 fab.fab$l_fna = filename;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4308 fab.fab$b_fns = strlen (filename);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4309 fab.fab$l_xab = &xab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4310 xab = cc$rms_xabpro;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4311 xab.xab$l_aclbuf = aclbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4312 xab.xab$w_aclsiz = sizeof (aclbuf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4313 status = SYS$OPEN (&fab, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4314 if (! (status & 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4315 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4316 SYS$CLOSE (&fab, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4317 /* Check system access */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4318 if (CHECKPRIV (PRV$V_SYSPRV) && WRITEABLE (XAB$V_SYS))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4319 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4320 /* Check ACL entries, if any */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4321 acl_controlled = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4322 if (xab.xab$w_acllen > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4323 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4324 aclptr = aclbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4325 aclend = &aclbuf[xab.xab$w_acllen / 4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4326 while (*aclptr && aclptr < aclend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4327 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4328 size = (*aclptr & 0xff) / 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4329 typecode = (*aclptr >> 8) & 0xff;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4330 if (typecode == ACE$C_KEYID)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4331 for (i = size - 1; i > 1; i--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4332 if (aclptr[i] == vms_uic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4333 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4334 acl_controlled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4335 if (aclptr[1] & ACE$M_WRITE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4336 return 0; /* Write access through ACL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4337 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4338 aclptr = &aclptr[size];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4339 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4340 if (acl_controlled) /* ACL specified, prohibits write access */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4341 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4342 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4343 /* No ACL entries specified, check normal protection */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4344 if (WRITEABLE (XAB$V_WLD)) /* World writeable */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4345 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4346 if (WRITEABLE (XAB$V_GRP) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4347 (unsigned short) (xab.xab$l_uic >> 16) == vms_grpid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4348 return 0; /* Group writeable */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4349 if (WRITEABLE (XAB$V_OWN) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4350 (xab.xab$l_uic & 0xFFFF) == vms_memid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4351 return 0; /* Owner writeable */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4353 return -1; /* Not writeable */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4354 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4355 #endif /* not VMS4_4 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4356 #endif /* access */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4357
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4358 static char vtbuf[NAM$C_MAXRSS+1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4360 /* translate a vms file spec to a unix path */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4361 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4362 sys_translate_vms (char *vfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4363 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4364 char * p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4365 char * targ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4367 if (!vfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4368 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4370 targ = vtbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4372 /* leading device or logical name is a root directory */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4373 if (p = strchr (vfile, ':'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4374 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4375 *targ++ = '/';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4376 while (vfile < p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4377 *targ++ = *vfile++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4378 vfile++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4379 *targ++ = '/';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4380 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4381 p = vfile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4382 if (*p == '[' || *p == '<')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4383 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4384 while (*++vfile != *p + 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4385 switch (*vfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4386 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4387 case '.':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4388 if (vfile[-1] == *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4389 *targ++ = '.';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4390 *targ++ = '/';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4391 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4393 case '-':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4394 *targ++ = '.';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4395 *targ++ = '.';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4396 break;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4397
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4398 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4399 *targ++ = *vfile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4400 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4401 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4402 vfile++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4403 *targ++ = '/';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4404 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4405 while (*vfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4406 *targ++ = *vfile++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4408 return vtbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4409 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4411 static char utbuf[NAM$C_MAXRSS+1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4413 /* translate a unix path to a VMS file spec */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4414 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4415 sys_translate_unix (char *ufile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4416 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4417 int slash_seen = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4418 char *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4419 char * targ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4421 if (!ufile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4422 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4424 targ = utbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4426 if (*ufile == '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4427 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4428 ufile++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4431 while (*ufile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4432 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4433 switch (*ufile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4434 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4435 case '/':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4436 if (slash_seen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4437 if (strchr (&ufile[1], '/'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4438 *targ++ = '.';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4439 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4440 *targ++ = ']';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4441 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4442 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4443 *targ++ = ':';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4444 if (strchr (&ufile[1], '/'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4445 *targ++ = '[';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4446 slash_seen = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4448 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4450 case '.':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4451 if (strncmp (ufile, "./", 2) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4452 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4453 if (!slash_seen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4454 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4455 *targ++ = '[';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4456 slash_seen = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4457 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4458 ufile++; /* skip the dot */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4459 if (strchr (&ufile[1], '/'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4460 *targ++ = '.';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4461 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4462 *targ++ = ']';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4463 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4464 else if (strncmp (ufile, "../", 3) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4465 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4466 if (!slash_seen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4467 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4468 *targ++ = '[';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4469 slash_seen = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4470 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4471 *targ++ = '-';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4472 ufile += 2; /* skip the dots */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4473 if (strchr (&ufile[1], '/'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4474 *targ++ = '.';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4475 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4476 *targ++ = ']';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4477 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4478 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4479 *targ++ = *ufile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4480 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4482 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4483 *targ++ = *ufile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4484 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4485 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4486 ufile++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4487 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4488 *targ = '\0';
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4489
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4490 return utbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4491 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4493 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4494 getwd (char *pathname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4495 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4496 char *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4497 strcpy (pathname, egetenv ("PATH"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4499 ptr = pathname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4500 while (*ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4501 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4502 /* #### This is evil. Smashes (shared) result of egetenv */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4503 *ptr = toupper (* (unsigned char *) ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4504 ptr++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4505 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4506 return pathname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4507 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4509 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4510 getppid (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4511 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4512 long item_code = JPI$_OWNER;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4513 unsigned long parent_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4514 int status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4516 if (((status = LIB$GETJPI (&item_code, 0, 0, &parent_id)) & 1) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4517 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4518 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4519 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4520 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4521 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4522 return parent_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4523 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4525 #undef getuid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4526 unsigned int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4527 sys_getuid (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4528 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4529 return (getgid () << 16) | getuid ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4530 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4532 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4533 vms_read (int fildes, CONST void *buf, unsigned int nbyte)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4534 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4535 return read (fildes, buf, (nbyte < MAXIOSIZE ? nbyte : MAXIOSIZE));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4536 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4538 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4539 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4540 vms_write (int fildes, CONST void *buf, unsigned int nbyte)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4541 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4542 int nwrote, rtnval = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4544 while (nbyte > MAXIOSIZE && (nwrote = write (fildes, buf, MAXIOSIZE)) > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4545 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4546 nbyte -= nwrote;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4547 buf += nwrote;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4548 rtnval += nwrote;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4549 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4550 if (nwrote < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4551 return rtnval ? rtnval : -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4552 if ((nwrote = write (fildes, buf, nbyte)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4553 return rtnval ? rtnval : -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4554 return (rtnval + nwrote);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4555 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4556 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4558 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4559 * VAX/VMS VAX C RTL really loses. It insists that records
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4560 * end with a newline (carriage return) character, and if they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4561 * don't it adds one (nice of it isn't it!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4562 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4563 * Thus we do this stupidity below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4564 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4566 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4567 vms_write (int fildes, CONST void *buf, unsigned int nbytes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4568 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4569 char *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4570 char *e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4571 int sum = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4572 struct stat st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4574 fstat (fildes, &st);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4575 p = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4576 while (nbytes > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4577 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4578 int len, retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4580 /* Handle fixed-length files with carriage control. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4581 if (st.st_fab_rfm == FAB$C_FIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4582 && ((st.st_fab_rat & (FAB$M_FTN | FAB$M_CR)) != 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4583 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4584 len = st.st_fab_mrs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4585 retval = write (fildes, p, min (len, nbytes));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4586 if (retval != len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4587 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4588 retval++; /* This skips the implied carriage control */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4589 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4590 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4591 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4592 e = p + min (MAXIOSIZE, nbytes) - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4593 while (*e != '\n' && e > p) e--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4594 if (p == e) /* Ok.. so here we add a newline... sigh. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4595 e = p + min (MAXIOSIZE, nbytes) - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4596 len = e + 1 - p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4597 retval = write (fildes, p, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4598 if (retval != len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4599 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4600 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4601 p += retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4602 sum += retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4603 nbytes -= retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4604 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4605 return sum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4606 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4608 /* Create file NEW copying its attributes from file OLD. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4609 OLD is 0 or does not exist, create based on the value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4610 vms_stmlf_recfm. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4612 /* Protection value the file should ultimately have.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4613 Set by create_copy_attrs, and use by rename_sansversions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4614 static unsigned short int vms_fab_final_pro;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4616 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4617 creat_copy_attrs (char *old, char *new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4618 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4619 struct FAB fab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4620 struct XABPRO xabpro;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4621 char aclbuf[256]; /* Choice of size is arbitrary. See below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4622 extern int vms_stmlf_recfm;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4624 if (old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4625 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4626 fab.fab$b_fac = FAB$M_GET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4627 fab.fab$l_fna = old;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4628 fab.fab$b_fns = strlen (old);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4629 fab.fab$l_xab = (char *) &xabpro;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4630 xabpro = cc$rms_xabpro;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4631 xabpro.xab$l_aclbuf = aclbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4632 xabpro.xab$w_aclsiz = sizeof aclbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4633 /* Call $OPEN to fill in the fab & xabpro fields. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4634 if (SYS$OPEN (&fab, 0, 0) & 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4635 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4636 SYS$CLOSE (&fab, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4637 fab.fab$l_alq = 0; /* zero the allocation quantity */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4638 if (xabpro.xab$w_acllen > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4639 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4640 if (xabpro.xab$w_acllen > sizeof aclbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4641 /* If the acl buffer was too short, redo open with longer one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4642 Wouldn't need to do this if there were some system imposed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4643 limit on the size of an ACL, but I can't find any such. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4644 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4645 xabpro.xab$l_aclbuf = (char *) alloca (xabpro.xab$w_acllen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4646 xabpro.xab$w_aclsiz = xabpro.xab$w_acllen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4647 if (SYS$OPEN (&fab, 0, 0) & 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4648 SYS$CLOSE (&fab, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4649 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4650 old = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4651 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4652 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4653 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4654 xabpro.xab$l_aclbuf = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4655 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4656 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4657 old = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4658 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4659 fab.fab$l_fna = new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4660 fab.fab$b_fns = strlen (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4661 if (!old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4662 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4663 fab.fab$l_xab = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4664 fab.fab$b_rfm = vms_stmlf_recfm ? FAB$C_STMLF : FAB$C_VAR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4665 fab.fab$b_rat = FAB$M_CR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4666 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4668 /* Set the file protections such that we will be able to manipulate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4669 this file. Once we are done writing and renaming it, we will set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4670 the protections back. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4671 if (old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4672 vms_fab_final_pro = xabpro.xab$w_pro;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4673 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4674 SYS$SETDFPROT (0, &vms_fab_final_pro);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4675 xabpro.xab$w_pro &= 0xff0f; /* set O:rewd for now. This is set back later. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4677 /* Create the new file with either default attrs or attrs copied
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4678 from old file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4679 if (!(SYS$CREATE (&fab, 0, 0) & 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4680 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4681 SYS$CLOSE (&fab, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4682 /* As this is a "replacement" for creat, return a file descriptor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4683 opened for writing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4684 return open (new, O_WRONLY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4685 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4687 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4688 vms_creat (CONST char *path, int mode, ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4689 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4690 int rfd; /* related file descriptor */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4691 int fd; /* Our new file descriptor */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4692 int count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4693 struct stat st_buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4694 char rfm[12];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4695 char rat[15];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4696 char mrs[13];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4697 char fsz[13];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4698 extern int vms_stmlf_recfm;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4700 /* #### there was some weird machine-dependent code to determine how many
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4701 arguments were passed to this function. This certainly won't work
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4702 under ANSI C. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4703 if (count > 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4704 rfd = fix this;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4705 if (count > 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4706 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4707 /* Use information from the related file descriptor to set record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4708 format of the newly created file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4709 fstat (rfd, &st_buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4710 switch (st_buf.st_fab_rfm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4711 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4712 case FAB$C_FIX:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4713 strcpy (rfm, "rfm = fix");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4714 sprintf (mrs, "mrs = %d", st_buf.st_fab_mrs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4715 strcpy (rat, "rat = ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4716 if (st_buf.st_fab_rat & FAB$M_CR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4717 strcat (rat, "cr");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4718 else if (st_buf.st_fab_rat & FAB$M_FTN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4719 strcat (rat, "ftn");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4720 else if (st_buf.st_fab_rat & FAB$M_PRN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4721 strcat (rat, "prn");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4722 if (st_buf.st_fab_rat & FAB$M_BLK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4723 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4724 strcat (rat, ", blk");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4725 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4726 strcat (rat, "blk");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4727 return creat (name, 0, rfm, rat, mrs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4729 case FAB$C_VFC:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4730 strcpy (rfm, "rfm = vfc");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4731 sprintf (fsz, "fsz = %d", st_buf.st_fab_fsz);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4732 strcpy (rat, "rat = ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4733 if (st_buf.st_fab_rat & FAB$M_CR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4734 strcat (rat, "cr");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4735 else if (st_buf.st_fab_rat & FAB$M_FTN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4736 strcat (rat, "ftn");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4737 else if (st_buf.st_fab_rat & FAB$M_PRN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4738 strcat (rat, "prn");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4739 if (st_buf.st_fab_rat & FAB$M_BLK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4740 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4741 strcat (rat, ", blk");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4742 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4743 strcat (rat, "blk");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4744 return creat (name, 0, rfm, rat, fsz);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4746 case FAB$C_STM:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4747 strcpy (rfm, "rfm = stm");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4748 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4750 case FAB$C_STMCR:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4751 strcpy (rfm, "rfm = stmcr");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4752 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4754 case FAB$C_STMLF:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4755 strcpy (rfm, "rfm = stmlf");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4756 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4758 case FAB$C_UDF:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4759 strcpy (rfm, "rfm = udf");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4760 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4762 case FAB$C_VAR:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4763 strcpy (rfm, "rfm = var");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4764 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4765 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4766 strcpy (rat, "rat = ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4767 if (st_buf.st_fab_rat & FAB$M_CR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4768 strcat (rat, "cr");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4769 else if (st_buf.st_fab_rat & FAB$M_FTN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4770 strcat (rat, "ftn");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4771 else if (st_buf.st_fab_rat & FAB$M_PRN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4772 strcat (rat, "prn");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4773 if (st_buf.st_fab_rat & FAB$M_BLK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4774 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4775 strcat (rat, ", blk");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4776 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4777 strcat (rat, "blk");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4778 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4779 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4780 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4781 strcpy (rfm, vms_stmlf_recfm ? "rfm = stmlf" : "rfm=var");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4782 strcpy (rat, "rat=cr");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4783 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4784 /* Until the VAX C RTL fixes the many bugs with modes, always use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4785 mode 0 to get the user's default protection. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4786 fd = creat (name, 0, rfm, rat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4787 if (fd < 0 && errno == EEXIST)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4788 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4789 if (unlink (name) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4790 report_file_error ("delete", build_string (name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4791 fd = creat (name, 0, rfm, rat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4792 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4793 return fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4794 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4796 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4797 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4798 vms_fwrite (CONST void *ptr, int size, int num, FILE *fp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4799 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4800 int tot = num * size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4802 while (tot--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4803 fputc (* (CONST char *) ptr++, fp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4804 return (num);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4805 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4807 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4808 * The VMS C library routine creat actually creates a new version of an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4809 * existing file rather than truncating the old version. There are times
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4810 * when this is not the desired behavior, for instance, when writing an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4811 * auto save file (you only want one version), or when you don't have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4812 * write permission in the directory containing the file (but the file
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4813 * itself is writable). Hence this routine, which is equivalent to
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4814 * "close (creat (fn, 0));" on Unix if fn already exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4815 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4816 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4817 vms_truncate (char *fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4818 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4819 struct FAB xfab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4820 struct RAB xrab = cc$rms_rab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4821 int status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4823 xfab.fab$l_fop = FAB$M_TEF; /* free allocated but unused blocks on close */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4824 xfab.fab$b_fac = FAB$M_TRN | FAB$M_GET; /* allow truncate and get access */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4825 xfab.fab$b_shr = FAB$M_NIL; /* allow no sharing - file must be locked */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4826 xfab.fab$l_fna = fn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4827 xfab.fab$b_fns = strlen (fn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4828 xfab.fab$l_dna = ";0"; /* default to latest version of the file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4829 xfab.fab$b_dns = 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4830 xrab.rab$l_fab = &xfab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4832 /* This gibberish opens the file, positions to the first record, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4833 deletes all records from there until the end of file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4834 if ((SYS$OPEN (&xfab) & 01) == 01)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4835 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4836 if ((SYS$CONNECT (&xrab) & 01) == 01 &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4837 (SYS$FIND (&xrab) & 01) == 01 &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4838 (SYS$TRUNCATE (&xrab) & 01) == 01)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4839 status = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4840 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4841 status = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4842 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4843 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4844 status = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4845 SYS$CLOSE (&xfab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4846 return status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4847 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4849 /* Define this symbol to actually read SYSUAF.DAT. This requires either
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4850 SYSPRV or a readable SYSUAF.DAT. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4852 #ifdef READ_SYSUAF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4853 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4854 * getuaf.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4855 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4856 * Routine to read the VMS User Authorization File and return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4857 * a specific user's record.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4858 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4860 static struct UAF vms_retuaf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4862 static struct UAF *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4863 get_uaf_name (char *uname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4864 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4865 status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4866 struct FAB uaf_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4867 struct RAB uaf_rab;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4868
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4869 uaf_fab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4870 uaf_rab = cc$rms_rab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4871 /* initialize fab fields */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4872 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4873 uaf_fab.fab$b_fns = 21;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4874 uaf_fab.fab$b_fac = FAB$M_GET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4875 uaf_fab.fab$b_org = FAB$C_IDX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4876 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4877 /* initialize rab fields */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4878 uaf_rab.rab$l_fab = &uaf_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4879 /* open the User Authorization File */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4880 status = SYS$OPEN (&uaf_fab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4881 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4882 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4883 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4884 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4885 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4886 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4887 status = SYS$CONNECT (&uaf_rab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4888 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4889 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4890 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4891 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4892 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4893 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4894 /* read the requested record - index is in uname */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4895 uaf_rab.rab$l_kbf = uname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4896 uaf_rab.rab$b_ksz = strlen (uname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4897 uaf_rab.rab$b_rac = RAB$C_KEY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4898 uaf_rab.rab$l_ubf = (char *)&vms_retuaf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4899 uaf_rab.rab$w_usz = sizeof vms_retuaf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4900 status = SYS$GET (&uaf_rab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4901 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4902 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4903 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4904 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4905 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4906 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4907 /* close the User Authorization File */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4908 status = SYS$DISCONNECT (&uaf_rab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4909 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4910 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4911 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4912 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4913 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4914 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4915 status = SYS$CLOSE (&uaf_fab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4916 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4917 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4918 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4919 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4920 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4921 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4922 return &vms_retuaf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4923 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4925 static struct UAF *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4926 get_uaf_uic (unsigned long uic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4927 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4928 status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4929 struct FAB uaf_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4930 struct RAB uaf_rab;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
4931
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4932 uaf_fab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4933 uaf_rab = cc$rms_rab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4934 /* initialize fab fields */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4935 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4936 uaf_fab.fab$b_fns = 21;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4937 uaf_fab.fab$b_fac = FAB$M_GET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4938 uaf_fab.fab$b_org = FAB$C_IDX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4939 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4940 /* initialize rab fields */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4941 uaf_rab.rab$l_fab = &uaf_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4942 /* open the User Authorization File */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4943 status = SYS$OPEN (&uaf_fab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4944 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4945 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4946 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4947 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4948 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4949 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4950 status = SYS$CONNECT (&uaf_rab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4951 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4952 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4953 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4954 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4955 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4956 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4957 /* read the requested record - index is in uic */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4958 uaf_rab.rab$b_krf = 1; /* 1st alternate key */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4959 uaf_rab.rab$l_kbf = (char *) &uic;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4960 uaf_rab.rab$b_ksz = sizeof uic;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4961 uaf_rab.rab$b_rac = RAB$C_KEY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4962 uaf_rab.rab$l_ubf = (char *)&vms_retuaf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4963 uaf_rab.rab$w_usz = sizeof vms_retuaf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4964 status = SYS$GET (&uaf_rab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4965 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4966 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4967 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4968 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4969 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4970 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4971 /* close the User Authorization File */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4972 status = SYS$DISCONNECT (&uaf_rab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4973 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4974 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4975 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4976 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4977 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4978 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4979 status = SYS$CLOSE (&uaf_fab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4980 if (!(status&1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4981 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4982 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4983 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4984 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4985 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4986 return &vms_retuaf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4987 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4989 static struct passwd vms_retpw;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4991 static struct passwd *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4992 cnv_uaf_pw (struct UAF *up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4994 char * ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4996 /* copy these out first because if the username is 32 chars, the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4997 section will overwrite the first byte of the UIC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4998 vms_retpw.pw_uid = up->uaf$w_mem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4999 vms_retpw.pw_gid = up->uaf$w_grp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5001 /* I suppose this is not the best sytle, to possibly overwrite one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5002 byte beyond the end of the field, but what the heck... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5003 ptr = &up->uaf$t_username[UAF$S_USERNAME];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5004 while (ptr[-1] == ' ')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5005 ptr--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5006 *ptr = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5007 strcpy (vms_retpw.pw_name, up->uaf$t_username);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5008
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5009 /* the rest of these are counted ascii strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5010 strncpy (vms_retpw.pw_gecos, &up->uaf$t_owner[1], up->uaf$t_owner[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5011 vms_retpw.pw_gecos[up->uaf$t_owner[0]] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5012 strncpy (vms_retpw.pw_dir, &up->uaf$t_defdev[1], up->uaf$t_defdev[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5013 vms_retpw.pw_dir[up->uaf$t_defdev[0]] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5014 strncat (vms_retpw.pw_dir, &up->uaf$t_defdir[1], up->uaf$t_defdir[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5015 vms_retpw.pw_dir[up->uaf$t_defdev[0] + up->uaf$t_defdir[0]] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5016 strncpy (vms_retpw.pw_shell, &up->uaf$t_defcli[1], up->uaf$t_defcli[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5017 vms_retpw.pw_shell[up->uaf$t_defcli[0]] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5018
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5019 return &vms_retpw;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5020 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5021 #else /* not READ_SYSUAF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5022 static struct passwd vms_retpw;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5023 #endif /* not READ_SYSUAF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5025 struct passwd *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5026 getpwnam (char *name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5027 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5028 #ifdef READ_SYSUAF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5029 struct UAF *up;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5030 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5031 char * user;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5032 char * dir;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5033 unsigned char * full;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5034 #endif /* READ_SYSUAF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5035 char *ptr = name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5036
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5037 while (*ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5038 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5039 *ptr = toupper (* (unsigned char *) ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5040 ptr++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5041 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5042 #ifdef READ_SYSUAF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5043 if (!(up = get_uaf_name (name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5044 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5045 return cnv_uaf_pw (up);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5046 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5047 if (strcmp (name, getenv ("USER")) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5048 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5049 vms_retpw.pw_uid = getuid ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5050 vms_retpw.pw_gid = getgid ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5051 strcpy (vms_retpw.pw_name, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5052 if (full = egetenv ("FULLNAME"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5053 strcpy (vms_retpw.pw_gecos, full);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5054 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5055 *vms_retpw.pw_gecos = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5056 strcpy (vms_retpw.pw_dir, egetenv ("HOME"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5057 *vms_retpw.pw_shell = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5058 return &vms_retpw;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5059 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5060 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5061 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5062 #endif /* not READ_SYSUAF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5063 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5065 struct passwd *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5066 getpwuid (unsigned long uid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5067 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5068 #ifdef READ_SYSUAF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5069 struct UAF * up;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5070
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5071 if (!(up = get_uaf_uic (uid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5072 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5073 return cnv_uaf_pw (up);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5074 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5075 if (uid == sys_getuid ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5076 return getpwnam (egetenv ("USER"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5077 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5078 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5079 #endif /* not READ_SYSUAF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5080 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5081
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5082 /* return total address space available to the current process. This is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5083 the sum of the current p0 size, p1 size and free page table entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5084 available. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5085 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5086 vlimit (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5087 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5088 int item_code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5089 unsigned long free_pages;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5090 unsigned long frep0va;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5091 unsigned long frep1va;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5092 status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5093
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5094 item_code = JPI$_FREPTECNT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5095 if (((status = LIB$GETJPI (&item_code, 0, 0, &free_pages)) & 1) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5096 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5097 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5098 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5099 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5100 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5101 free_pages *= 512;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5103 item_code = JPI$_FREP0VA;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5104 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep0va)) & 1) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5105 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5106 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5107 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5108 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5109 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5110 item_code = JPI$_FREP1VA;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5111 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep1va)) & 1) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5112 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5113 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5114 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5115 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5116 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5118 return free_pages + frep0va + (0x7fffffff - frep1va);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5121 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5122 define_logical_name (char *varname, char *string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5123 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5124 struct dsc$descriptor_s strdsc =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5125 {strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5126 struct dsc$descriptor_s envdsc =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5127 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5128 struct dsc$descriptor_s lnmdsc =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5129 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5131 return LIB$SET_LOGICAL (&envdsc, &strdsc, &lnmdsc, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5132 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5134 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5135 delete_logical_name (char *varname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5136 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5137 struct dsc$descriptor_s envdsc =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5138 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5139 struct dsc$descriptor_s lnmdsc =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5140 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5142 return LIB$DELETE_LOGICAL (&envdsc, &lnmdsc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5143 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5145 execvp (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5146 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5147 error ("execvp system call not implemented");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5148 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5150 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5151 rename (char *from, char *to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5152 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5153 int status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5154 struct FAB from_fab = cc$rms_fab, to_fab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5155 struct NAM from_nam = cc$rms_nam, to_nam = cc$rms_nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5156 char from_esn[NAM$C_MAXRSS];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5157 char to_esn[NAM$C_MAXRSS];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5159 from_fab.fab$l_fna = from;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5160 from_fab.fab$b_fns = strlen (from);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5161 from_fab.fab$l_nam = &from_nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5162 from_fab.fab$l_fop = FAB$M_NAM;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5164 from_nam.nam$l_esa = from_esn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5165 from_nam.nam$b_ess = sizeof from_esn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5167 to_fab.fab$l_fna = to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5168 to_fab.fab$b_fns = strlen (to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5169 to_fab.fab$l_nam = &to_nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5170 to_fab.fab$l_fop = FAB$M_NAM;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5172 to_nam.nam$l_esa = to_esn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5173 to_nam.nam$b_ess = sizeof to_esn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5175 status = SYS$RENAME (&from_fab, 0, 0, &to_fab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5177 if (status & 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5178 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5179 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5180 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5181 if (status == RMS$_DEV)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5182 errno = EXDEV;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5183 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5184 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5185 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5186 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5187 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5188 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5190 /* This function renames a file like `rename', but it strips
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5191 the version number from the "to" filename, such that the "to" file is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5192 will always be a new version. It also sets the file protection once it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5193 finished. The protection that we will use is stored in vms_fab_final_pro,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5194 and was set when we did a creat_copy_attrs to create the file that we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5195 are renaming.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5197 We could use the chmod function, but Eunichs uses 3 bits per user category
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5198 to describe the protection, and VMS uses 4 (write and delete are separate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5199 bits). To maintain portability, the VMS implementation of `chmod' wires
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5200 the W and D bits together. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5201
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
5202
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5203 static char vms_file_written[NAM$C_MAXRSS];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5205 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5206 rename_sans_version (char *from, char *to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5207 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5208 short int chan;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5209 int stat;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5210 short int iosb[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5211 int status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5212 struct fibdef fib;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5213 struct FAB to_fab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5214 struct NAM to_nam = cc$rms_nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5215 struct dsc$descriptor fib_d ={sizeof (fib),0,0,(char*) &fib};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5216 struct dsc$descriptor fib_attr[2]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5217 = {{sizeof (vms_fab_final_pro),ATR$C_FPRO,0,(char*) &vms_fab_final_pro},{0,0,0,0}};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5218 char to_esn[NAM$C_MAXRSS];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5220 $DESCRIPTOR (disk,to_esn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5222 memset (&fib, 0, sizeof (fib));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5224 to_fab.fab$l_fna = to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5225 to_fab.fab$b_fns = strlen (to);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5226 to_fab.fab$l_nam = &to_nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5227 to_fab.fab$l_fop = FAB$M_NAM;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5229 to_nam.nam$l_esa = to_esn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5230 to_nam.nam$b_ess = sizeof to_esn;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5232 status = SYS$PARSE (&to_fab, 0, 0); /* figure out the full file name */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5234 if (to_nam.nam$l_fnb && NAM$M_EXP_VER)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5235 *(to_nam.nam$l_ver) = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5237 stat = rename (from, to_esn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5238 if (stat < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5239 return stat;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5241 strcpy (vms_file_written, to_esn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5243 to_fab.fab$l_fna = vms_file_written; /* this points to the versionless name */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5244 to_fab.fab$b_fns = strlen (vms_file_written);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5246 /* Now set the file protection to the correct value */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5247 SYS$OPEN (&to_fab, 0, 0); /* This fills in the nam$w_fid fields */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5249 /* Copy these fields into the fib */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5250 fib.fib$r_fid_overlay.fib$w_fid[0] = to_nam.nam$w_fid[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5251 fib.fib$r_fid_overlay.fib$w_fid[1] = to_nam.nam$w_fid[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5252 fib.fib$r_fid_overlay.fib$w_fid[2] = to_nam.nam$w_fid[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5254 SYS$CLOSE (&to_fab, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5256 stat = SYS$ASSIGN (&disk, &chan, 0, 0); /* open a channel to the disk */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5257 if (!stat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5258 LIB$SIGNAL (stat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5259 stat = SYS$QIOW (0, chan, IO$_MODIFY, iosb, 0, 0, &fib_d,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5260 0, 0, 0, &fib_attr, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5261 if (!stat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5262 LIB$SIGNAL (stat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5263 stat = SYS$DASSGN (chan);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5264 if (!stat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5265 LIB$SIGNAL (stat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5266 strcpy (vms_file_written, to_esn); /* We will write this to the terminal*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5267 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5268 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5270 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5271 link (char *file, char *new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5273 status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5274 struct FAB fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5275 struct NAM nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5276 unsigned short fid[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5277 char esa[NAM$C_MAXRSS];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5279 fab = cc$rms_fab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5280 fab.fab$l_fop = FAB$M_OFP;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5281 fab.fab$l_fna = file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5282 fab.fab$b_fns = strlen (file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5283 fab.fab$l_nam = &nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5285 nam = cc$rms_nam;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5286 nam.nam$l_esa = esa;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5287 nam.nam$b_ess = NAM$C_MAXRSS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5289 status = SYS$PARSE (&fab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5290 if ((status & 1) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5291 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5292 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5293 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5294 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5295 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5296 status = SYS$SEARCH (&fab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5297 if ((status & 1) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5298 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5299 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5300 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5301 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5302 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5304 fid[0] = nam.nam$w_fid[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5305 fid[1] = nam.nam$w_fid[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5306 fid[2] = nam.nam$w_fid[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5308 fab.fab$l_fna = new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5309 fab.fab$b_fns = strlen (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5311 status = SYS$PARSE (&fab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5312 if ((status & 1) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5313 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5314 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5315 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5316 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5317 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5319 nam.nam$w_fid[0] = fid[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5320 nam.nam$w_fid[1] = fid[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5321 nam.nam$w_fid[2] = fid[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5323 nam.nam$l_esa = nam.nam$l_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5324 nam.nam$b_esl = nam.nam$b_name + nam.nam$b_type + nam.nam$b_ver;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5326 status = SYS$ENTER (&fab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5327 if ((status & 1) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5328 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5329 errno = EVMSERR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5330 vaxc$errno = status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5331 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5332 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5334 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5335 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5337 #ifdef getenv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5338 /* If any place else asks for the TERM variable,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5339 allow it to be overridden with the EMACS_TERM variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5340 before attempting to translate the logical name TERM. As a last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5341 resort, ask for VAX C's special idea of the TERM variable. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5342 #undef getenv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5343 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5344 sys_getenv (char *name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5345 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5346 char *val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5347 static char buf[256];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5348 static struct dsc$descriptor_s equiv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5349 = {sizeof (buf), DSC$K_DTYPE_T, DSC$K_CLASS_S, buf};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5350 static struct dsc$descriptor_s d_name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5351 = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5352 short eqlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5354 if (!strcmp (name, "TERM"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5355 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5356 val = (char *) getenv ("EMACS_TERM");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5357 if (val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5358 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5361 d_name.dsc$w_length = strlen (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5362 d_name.dsc$a_pointer = name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5363 if (LIB$SYS_TRNLOG (&d_name, &eqlen, &equiv) == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5364 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5365 char *str = (char *) xmalloc (eqlen + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5366 memcpy (str, buf, eqlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5367 str[eqlen] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5368 /* This is a storage leak, but a pain to fix. With luck,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5369 no one will ever notice. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5370 return str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5371 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5372 return (char *) getenv (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5373 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5374 #endif /* getenv */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5376 #ifdef abort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5377 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5378 to force a call on the debugger from within the image. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5379 #undef abort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5380 sys_abort (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5381 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5382 reset_all_consoles ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5383 LIB$SIGNAL (SS$_DEBUG);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5384 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5385 #endif /* abort */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5387 #if 0 /* Apparently unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5388 /* The standard `sleep' routine works some other way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5389 and it stops working if you have ever quit out of it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5390 This one continues to work. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5392 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5393 sys_sleep (int timeval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5394 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5395 int time [2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5396 static int zero = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5397 static int large = -10000000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5399 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5401 SYS$CANTIM (1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5402 if (SYS$SETIMR (vms_timer_ef, time, 0, 1) & 1) /* Set timer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5403 SYS$WAITFR (vms_timer_ef); /* Wait for timer expiry only */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5404 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5405 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5407 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5408 bzero (register char *b, register int length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5409 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5410 short zero = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5411 long max_str = 65535;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5413 while (length > max_str) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5414 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5415 length -= max_str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5416 b += max_str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5417 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5418 max_str = length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5419 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5420 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5422 /* Saying `void' requires a declaration, above, where bcopy is used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5423 and that declaration causes pain for systems where bcopy is a macro. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5424 bcopy (register char *b1, register char *b2, register int length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5425 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5426 long max_str = 65535;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5428 while (length > max_str) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5429 (void) LIB$MOVC3 (&max_str, b1, b2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5430 length -= max_str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5431 b1 += max_str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5432 b2 += max_str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5433 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5434 max_str = length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5435 (void) LIB$MOVC3 (&length, b1, b2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5436 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5438 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5439 bcmp (register char *b1, register char *b2, register int length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5440 /* This could be a macro! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5441 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5442 struct dsc$descriptor_s src1 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b1};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5443 struct dsc$descriptor_s src2 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b2};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5445 return STR$COMPARE (&src1, &src2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5448 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5450 #ifndef HAVE_STRCASECMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5451 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5452 * From BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5453 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5454 static unsigned char charmap[] = {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5455 '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5456 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5457 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5458 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5459 '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5460 '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5461 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5462 '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5463 '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5464 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5465 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5466 '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5467 '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5468 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5469 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5470 '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5471 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5472 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5473 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5474 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5475 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5476 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5477 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5478 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5479 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5480 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5481 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5482 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5483 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5484 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5485 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5486 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5487 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5489 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5490 strcasecmp (char *s1, char *s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5491 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5492 unsigned char *cm = charmap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5493 unsigned char *us1 = (unsigned char *) s1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5494 unsigned char *us2 = (unsigned char *)s2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5496 while (cm[*us1] == cm[*us2++])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5497 if (*us1++ == '\0')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5498 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5500 return (cm[*us1] - cm[*--us2]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5501 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5502 #endif /* !HAVE_STRCASECMP */