Mercurial > emacs
annotate src/sysdep.c @ 3613:f37a9c897699
* scroll-bar.el (scroll-bar-mode): Variable deleted.
(scroll-bar-mode): Function changed to consult default-frame-alist
instead of the variable.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Thu, 10 Jun 1993 12:18:36 +0000 |
parents | be31c90ee59d |
children | 3e6cc11cfe9f |
rev | line source |
---|---|
491 | 1 /* Interfaces to system-dependent kernel and library entries. |
2961 | 2 Copyright (C) 1985, 1986, 1987, 1988, 1993 Free Software Foundation, Inc. |
491 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
21 #include <signal.h> | |
22 #include <setjmp.h> | |
23 | |
24 #include "config.h" | |
25 #include "lisp.h" | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
26 #include "blockinput.h" |
491 | 27 #undef NULL |
28 | |
29 #define min(x,y) ((x) > (y) ? (y) : (x)) | |
30 | |
31 /* In this file, open, read and write refer to the system calls, | |
32 not our sugared interfaces sys_open, sys_read and sys_write. | |
33 Contrariwise, for systems where we use the system calls directly, | |
34 define sys_read, etc. here as aliases for them. */ | |
35 #ifndef read | |
36 #define sys_read read | |
37 #define sys_write write | |
38 #endif /* `read' is not a macro */ | |
39 | |
40 #undef read | |
41 #undef write | |
42 | |
43 #ifndef close | |
44 #define sys_close close | |
45 #else | |
46 #undef close | |
47 #endif | |
48 | |
49 #ifndef open | |
50 #define sys_open open | |
51 #else /* `open' is a macro */ | |
52 #undef open | |
53 #endif /* `open' is a macro */ | |
54 | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
55 /* Does anyone other than VMS need this? */ |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
56 #ifndef fwrite |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
57 #define sys_fwrite fwrite |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
58 #else |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
59 #undef fwrite |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
60 #endif |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
61 |
491 | 62 #include <stdio.h> |
63 #include <sys/types.h> | |
64 #include <sys/stat.h> | |
65 #include <errno.h> | |
66 | |
67 extern int errno; | |
68 #ifndef VMS | |
69 extern char *sys_errlist[]; | |
70 #endif | |
71 | |
72 #ifdef VMS | |
73 #include <rms.h> | |
74 #include <ttdef.h> | |
75 #include <tt2def.h> | |
76 #include <iodef.h> | |
77 #include <ssdef.h> | |
78 #include <descrip.h> | |
79 #include <fibdef.h> | |
80 #include <atrdef.h> | |
81 #include <ctype.h> | |
82 #include <string.h> | |
83 #ifdef __GNUC__ | |
84 #include <sys/file.h> | |
85 #else | |
86 #include <file.h> | |
87 #endif | |
88 #undef F_SETFL | |
89 #ifndef RAB$C_BID | |
90 #include <rab.h> | |
91 #endif | |
92 #define MAXIOSIZE ( 32 * PAGESIZE ) /* Don't I/O more than 32 blocks at a time */ | |
93 #endif /* VMS */ | |
94 | |
95 #ifndef BSD4_1 | |
96 #ifdef BSD /* this is done this way to avoid defined (BSD) || defined (USG) | |
97 because the vms compiler doesn't grok `defined' */ | |
98 #include <fcntl.h> | |
99 #endif | |
100 #ifdef USG | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
101 #ifndef USG5 |
491 | 102 #include <fcntl.h> |
103 #endif | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
104 #endif |
491 | 105 #endif /* not 4.1 bsd */ |
106 | |
3604
be31c90ee59d
* sysdep.c: Remove clause for DGUX support of FASYNC; add clause
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
107 #ifdef BROKEN_FASYNC |
be31c90ee59d
* sysdep.c: Remove clause for DGUX support of FASYNC; add clause
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
108 /* On some systems (DGUX comes to mind real fast) FASYNC causes |
be31c90ee59d
* sysdep.c: Remove clause for DGUX support of FASYNC; add clause
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
109 background writes to the terminal to stop all processes in the |
be31c90ee59d
* sysdep.c: Remove clause for DGUX support of FASYNC; add clause
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
110 process group when invoked under the csh (and probably any shell |
be31c90ee59d
* sysdep.c: Remove clause for DGUX support of FASYNC; add clause
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
111 with job control). This stops Emacs dead in its tracks when coming |
be31c90ee59d
* sysdep.c: Remove clause for DGUX support of FASYNC; add clause
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
112 up under X11. */ |
be31c90ee59d
* sysdep.c: Remove clause for DGUX support of FASYNC; add clause
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
113 #undef FASYNC |
be31c90ee59d
* sysdep.c: Remove clause for DGUX support of FASYNC; add clause
Jim Blandy <jimb@redhat.com>
parents:
3591
diff
changeset
|
114 #endif |
491 | 115 |
116 #include <sys/ioctl.h> | |
1048
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
117 #include "systty.h" |
491 | 118 |
119 #ifdef BSD | |
120 #ifdef BSD4_1 | |
121 #include <wait.h> | |
122 #else /* not 4.1 */ | |
123 #include <sys/wait.h> | |
124 #endif /* not 4.1 */ | |
125 #endif /* BSD */ | |
126 | |
127 #ifdef BROKEN_TIOCGWINSZ | |
128 #undef TIOCGWINSZ | |
129 #endif | |
130 | |
131 #ifdef USG | |
132 #include <sys/utsname.h> | |
133 #include <string.h> | |
134 #ifndef MEMORY_IN_STRING_H | |
135 #include <memory.h> | |
136 #endif | |
137 #ifdef TIOCGWINSZ | |
138 #ifdef NEED_SIOCTL | |
139 #include <sys/sioctl.h> | |
140 #endif | |
141 #ifdef NEED_PTEM_H | |
142 #include <sys/stream.h> | |
143 #include <sys/ptem.h> | |
144 #endif | |
145 #endif /* TIOCGWINSZ */ | |
146 #endif /* USG */ | |
147 | |
148 extern int quit_char; | |
149 | |
766 | 150 #include "frame.h" |
491 | 151 #include "window.h" |
152 #include "termhooks.h" | |
153 #include "termchar.h" | |
154 #include "termopts.h" | |
155 #include "dispextern.h" | |
156 #include "process.h" | |
157 | |
158 #ifdef NONSYSTEM_DIR_LIBRARY | |
159 #include "ndir.h" | |
160 #endif /* NONSYSTEM_DIR_LIBRARY */ | |
161 | |
579 | 162 #include "syssignal.h" |
163 #include "systime.h" | |
491 | 164 |
165 static int baud_convert[] = | |
166 #ifdef BAUD_CONVERT | |
167 BAUD_CONVERT; | |
168 #else | |
169 { | |
170 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200, | |
171 1800, 2400, 4800, 9600, 19200, 38400 | |
172 }; | |
173 #endif | |
174 | |
175 extern short ospeed; | |
176 | |
579 | 177 /* The file descriptor for Emacs's input terminal. |
178 Under Unix, this is always left zero; | |
179 under VMS, we place the input channel number here. | |
180 This allows us to write more code that works for both VMS and Unix. */ | |
181 static int input_fd; | |
182 | |
491 | 183 discard_tty_input () |
184 { | |
579 | 185 struct emacs_tty buf; |
491 | 186 |
187 if (noninteractive) | |
188 return; | |
189 | |
190 /* Discarding input is not safe when the input could contain | |
191 replies from the X server. So don't do it. */ | |
192 if (read_socket_hook) | |
193 return; | |
194 | |
195 #ifdef VMS | |
196 end_kbd_input (); | |
579 | 197 SYS$QIOW (0, input_fd, IO$_READVBLK|IO$M_PURGE, input_iosb, 0, 0, |
198 &buf.main, 0, 0, terminator_mask, 0, 0); | |
491 | 199 queue_kbd_input (); |
200 #else /* not VMS */ | |
201 #ifdef APOLLO | |
202 { | |
203 int zero = 0; | |
204 ioctl (0, TIOCFLUSH, &zero); | |
205 } | |
206 #else /* not Apollo */ | |
579 | 207 EMACS_GET_TTY (input_fd, &buf); |
208 EMACS_SET_TTY (input_fd, &buf, 0); | |
491 | 209 #endif /* not Apollo */ |
210 #endif /* not VMS */ | |
211 } | |
212 | |
213 #ifdef SIGTSTP | |
214 | |
215 stuff_char (c) | |
216 char c; | |
217 { | |
218 /* Should perhaps error if in batch mode */ | |
219 #ifdef TIOCSTI | |
220 ioctl (0, TIOCSTI, &c); | |
221 #else /* no TIOCSTI */ | |
222 error ("Cannot stuff terminal input characters in this version of Unix."); | |
223 #endif /* no TIOCSTI */ | |
224 } | |
225 | |
226 #endif /* SIGTSTP */ | |
227 | |
228 init_baud_rate () | |
229 { | |
230 if (noninteractive) | |
231 ospeed = 0; | |
232 else | |
233 { | |
234 #ifdef VMS | |
579 | 235 struct sensemode sg; |
236 | |
237 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0, | |
491 | 238 &sg.class, 12, 0, 0, 0, 0 ); |
579 | 239 ospeed = sg.xmit_baud; |
240 #else /* not VMS */ | |
241 #ifdef HAVE_TERMIOS | |
242 struct termios sg; | |
243 | |
244 sg.c_cflag = (sg.c_cflag & ~CBAUD) | B9600; | |
245 tcgetattr (0, &sg); | |
3559
a9b886b3f976
(init_baud_rate) [HAVE_TERMIOS]: Use cfgetospeed.
Richard M. Stallman <rms@gnu.org>
parents:
3472
diff
changeset
|
246 ospeed = cfgetospeed (&sg); |
1048
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
247 #else /* neither VMS nor TERMIOS */ |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
248 #ifdef HAVE_TERMIO |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
249 struct termio sg; |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
250 |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
251 sg.c_cflag = (sg.c_cflag & ~CBAUD) | B9600; |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
252 #ifdef HAVE_TCATTR |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
253 tcgetattr (0, &sg); |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
254 #else |
2121
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
255 ioctl (input_fd, TCGETA, &sg); |
1048
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
256 #endif |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
257 ospeed = sg.c_cflag & CBAUD; |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
258 #else /* neither VMS nor TERMIOS nor TERMIO */ |
579 | 259 struct sgttyb sg; |
260 | |
261 sg.sg_ospeed = B9600; | |
3559
a9b886b3f976
(init_baud_rate) [HAVE_TERMIOS]: Use cfgetospeed.
Richard M. Stallman <rms@gnu.org>
parents:
3472
diff
changeset
|
262 if (ioctl (0, TIOCGETP, &sg) < 0) |
a9b886b3f976
(init_baud_rate) [HAVE_TERMIOS]: Use cfgetospeed.
Richard M. Stallman <rms@gnu.org>
parents:
3472
diff
changeset
|
263 abort (); |
579 | 264 ospeed = sg.sg_ospeed; |
1048
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
265 #endif /* not HAVE_TERMIO */ |
579 | 266 #endif /* not HAVE_TERMIOS */ |
491 | 267 #endif /* not VMS */ |
268 } | |
269 | |
270 baud_rate = (ospeed < sizeof baud_convert / sizeof baud_convert[0] | |
271 ? baud_convert[ospeed] : 9600); | |
272 if (baud_rate == 0) | |
273 baud_rate = 1200; | |
274 } | |
275 | |
276 /*ARGSUSED*/ | |
277 set_exclusive_use (fd) | |
278 int fd; | |
279 { | |
280 #ifdef FIOCLEX | |
281 ioctl (fd, FIOCLEX, 0); | |
282 #endif | |
283 /* Ok to do nothing if this feature does not exist */ | |
284 } | |
285 | |
286 #ifndef subprocesses | |
287 | |
288 wait_without_blocking () | |
289 { | |
290 #ifdef BSD | |
291 wait3 (0, WNOHANG | WUNTRACED, 0); | |
292 #else | |
293 croak ("wait_without_blocking"); | |
294 #endif | |
295 synch_process_alive = 0; | |
296 } | |
297 | |
298 #endif /* not subprocesses */ | |
299 | |
300 int wait_debugging; /* Set nonzero to make following function work under dbx | |
301 (at least for bsd). */ | |
302 | |
303 SIGTYPE | |
304 wait_for_termination_signal () | |
305 {} | |
306 | |
307 /* Wait for subprocess with process id `pid' to terminate and | |
308 make sure it will get eliminated (not remain forever as a zombie) */ | |
309 | |
310 wait_for_termination (pid) | |
311 int pid; | |
312 { | |
313 while (1) | |
314 { | |
315 #ifdef subprocesses | |
316 #ifdef VMS | |
317 int status; | |
318 | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
319 status = SYS$FORCEX (&pid, 0, 0); |
491 | 320 break; |
321 #else /* not VMS */ | |
3334
7900edb84c4f
(wait_for_termination): Delete LINUX conditionals.
Richard M. Stallman <rms@gnu.org>
parents:
3321
diff
changeset
|
322 #if defined (BSD) || (defined (HPUX) && !defined (HPUX_5)) |
2942
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
323 /* Note that kill returns -1 even if the process is just a zombie now. |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
324 But inevitably a SIGCHLD interrupt should be generated |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
325 and child_sig will do wait3 and make the process go away. */ |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
326 /* There is some indication that there is a bug involved with |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
327 termination of subprocesses, perhaps involving a kernel bug too, |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
328 but no idea what it is. Just as a hunch we signal SIGCHLD to see |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
329 if that causes the problem to go away or get worse. */ |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
330 sigsetmask (sigmask (SIGCHLD)); |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
331 if (0 > kill (pid, 0)) |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
332 { |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
333 sigsetmask (SIGEMPTYMASK); |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
334 kill (getpid (), SIGCHLD); |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
335 break; |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
336 } |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
337 if (wait_debugging) |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
338 sleep (1); |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
339 else |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
340 sigpause (SIGEMPTYMASK); |
3334
7900edb84c4f
(wait_for_termination): Delete LINUX conditionals.
Richard M. Stallman <rms@gnu.org>
parents:
3321
diff
changeset
|
341 #else /* not BSD, and not HPUX version >= 6 */ |
7900edb84c4f
(wait_for_termination): Delete LINUX conditionals.
Richard M. Stallman <rms@gnu.org>
parents:
3321
diff
changeset
|
342 #if defined (UNIPLUS) |
2942
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
343 if (0 > kill (pid, 0)) |
491 | 344 break; |
2942
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
345 wait (0); |
3334
7900edb84c4f
(wait_for_termination): Delete LINUX conditionals.
Richard M. Stallman <rms@gnu.org>
parents:
3321
diff
changeset
|
346 #else /* neither BSD nor UNIPLUS: random sysV */ |
3301
aaf396661221
(wait_for_termination): Add POSIX_SIGNALS alternative.
Richard M. Stallman <rms@gnu.org>
parents:
3292
diff
changeset
|
347 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */ |
aaf396661221
(wait_for_termination): Add POSIX_SIGNALS alternative.
Richard M. Stallman <rms@gnu.org>
parents:
3292
diff
changeset
|
348 sigblock (sigmask (SIGCHLD)); |
aaf396661221
(wait_for_termination): Add POSIX_SIGNALS alternative.
Richard M. Stallman <rms@gnu.org>
parents:
3292
diff
changeset
|
349 if (0 > kill (pid, 0)) |
aaf396661221
(wait_for_termination): Add POSIX_SIGNALS alternative.
Richard M. Stallman <rms@gnu.org>
parents:
3292
diff
changeset
|
350 { |
aaf396661221
(wait_for_termination): Add POSIX_SIGNALS alternative.
Richard M. Stallman <rms@gnu.org>
parents:
3292
diff
changeset
|
351 sigunblock (sigmask (SIGCHLD)); |
aaf396661221
(wait_for_termination): Add POSIX_SIGNALS alternative.
Richard M. Stallman <rms@gnu.org>
parents:
3292
diff
changeset
|
352 break; |
aaf396661221
(wait_for_termination): Add POSIX_SIGNALS alternative.
Richard M. Stallman <rms@gnu.org>
parents:
3292
diff
changeset
|
353 } |
3472
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
354 sigpause (SIGEMPTYMASK); |
3301
aaf396661221
(wait_for_termination): Add POSIX_SIGNALS alternative.
Richard M. Stallman <rms@gnu.org>
parents:
3292
diff
changeset
|
355 #else /* not POSIX_SIGNALS */ |
2942
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
356 #ifdef HAVE_SYSV_SIGPAUSE |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
357 sighold (SIGCHLD); |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
358 if (0 > kill (pid, 0)) |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
359 { |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
360 sigrelse (SIGCHLD); |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
361 break; |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
362 } |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
363 sigpause (SIGCHLD); |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
364 #else /* not HAVE_SYSV_SIGPAUSE */ |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
365 if (0 > kill (pid, 0)) |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
366 break; |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
367 /* Using sleep instead of pause avoids timing error. |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
368 If the inferior dies just before the sleep, |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
369 we lose just one second. */ |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
370 sleep (1); |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
371 #endif /* not HAVE_SYSV_SIGPAUSE */ |
3301
aaf396661221
(wait_for_termination): Add POSIX_SIGNALS alternative.
Richard M. Stallman <rms@gnu.org>
parents:
3292
diff
changeset
|
372 #endif /* not POSIX_SIGNALS */ |
2942
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
373 #endif /* not UNIPLUS */ |
9ac629dc3a4b
(wait_for_termination): Copy code from 18.59 (but sans BSD4_1 alternatives).
Richard M. Stallman <rms@gnu.org>
parents:
2939
diff
changeset
|
374 #endif /* not BSD, and not HPUX version >= 6 */ |
491 | 375 #endif /* not VMS */ |
376 #else /* not subprocesses */ | |
377 #ifndef BSD4_1 | |
378 if (kill (pid, 0) < 0) | |
379 break; | |
380 wait (0); | |
381 #else /* BSD4_1 */ | |
382 int status; | |
383 status = wait (0); | |
384 if (status == pid || status == -1) | |
385 break; | |
386 #endif /* BSD4_1 */ | |
387 #endif /* not subprocesses */ | |
388 } | |
389 } | |
390 | |
391 #ifdef subprocesses | |
392 | |
393 /* | |
394 * flush any pending output | |
395 * (may flush input as well; it does not matter the way we use it) | |
396 */ | |
397 | |
398 flush_pending_output (channel) | |
399 int channel; | |
400 { | |
401 #ifdef HAVE_TERMIOS | |
402 /* If we try this, we get hit with SIGTTIN, because | |
403 the child's tty belongs to the child's pgrp. */ | |
404 #else | |
405 #ifdef TCFLSH | |
406 ioctl (channel, TCFLSH, 1); | |
407 #else | |
408 #ifdef TIOCFLUSH | |
409 int zero = 0; | |
410 /* 3rd arg should be ignored | |
411 but some 4.2 kernels actually want the address of an int | |
412 and nonzero means something different. */ | |
413 ioctl (channel, TIOCFLUSH, &zero); | |
414 #endif | |
415 #endif | |
416 #endif | |
417 } | |
418 | |
419 #ifndef VMS | |
420 /* Set up the terminal at the other end of a pseudo-terminal that | |
421 we will be controlling an inferior through. | |
422 It should not echo or do line-editing, since that is done | |
423 in Emacs. No padding needed for insertion into an Emacs buffer. */ | |
424 | |
425 child_setup_tty (out) | |
426 int out; | |
427 { | |
579 | 428 struct emacs_tty s; |
429 | |
430 EMACS_GET_TTY (out, &s); | |
431 | |
1927
c6dc1a37aeb4
* sysdep.c (child_setup_tty): Recognize HAVE_TERMIOS as well as
Jim Blandy <jimb@redhat.com>
parents:
1596
diff
changeset
|
432 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) |
579 | 433 s.main.c_oflag |= OPOST; /* Enable output postprocessing */ |
434 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */ | |
435 s.main.c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY); | |
436 /* No output delays */ | |
437 s.main.c_lflag &= ~ECHO; /* Disable echo */ | |
438 s.main.c_lflag |= ISIG; /* Enable signals */ | |
439 s.main.c_iflag &= ~IUCLC; /* Disable map of upper case to lower on | |
440 input */ | |
441 s.main.c_oflag &= ~OLCUC; /* Disable map of lower case to upper on | |
442 output */ | |
443 #if 0 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
444 /* Said to be unnecessary: */ |
579 | 445 s.main.c_cc[VMIN] = 1; /* minimum number of characters to accept */ |
446 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */ | |
447 #endif | |
448 | |
449 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */ | |
450 s.main.c_cc[VEOF] = 04; /* insure that EOF is Control-D */ | |
451 s.main.c_cc[VERASE] = 0377; /* disable erase processing */ | |
452 s.main.c_cc[VKILL] = 0377; /* disable kill processing */ | |
453 | |
491 | 454 #ifdef HPUX |
579 | 455 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */ |
491 | 456 #endif /* HPUX */ |
579 | 457 |
491 | 458 #ifdef AIX |
459 /* AIX enhanced edit loses NULs, so disable it */ | |
460 #ifndef IBMR2AIX | |
579 | 461 s.main.c_line = 0; |
462 s.main.c_iflag &= ~ASCEDIT; | |
491 | 463 #endif |
464 /* Also, PTY overloads NUL and BREAK. | |
465 don't ignore break, but don't signal either, so it looks like NUL. */ | |
579 | 466 s.main.c_iflag &= ~IGNBRK; |
467 s.main.c_iflag &= ~BRKINT; | |
468 /* QUIT and INTR work better as signals, so disable character forms */ | |
469 s.main.c_cc[VQUIT] = 0377; | |
470 s.main.c_cc[VINTR] = 0377; | |
3321
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
471 #ifdef SIGNALS_VIA_CHARACTERS |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
472 /* the QUIT and INTR character are used in process_send_signal |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
473 so set them here to something useful. */ |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
474 if (s.main.c_cc[VQUIT] == 0377) |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
475 s.main.c_cc[VQUIT] = '\\'&037; /* Control-\ */ |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
476 if (s.main.c_cc[VINTR] == 0377) |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
477 s.main.c_cc[VINTR] = 'C'&037; /* Control-C */ |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
478 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */ |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
479 /* QUIT and INTR work better as signals, so disable character forms */ |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
480 s.main.c_cc[VQUIT] = 0377; |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
481 s.main.c_cc[VINTR] = 0377; |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
482 s.main.c_lflag &= ~ISIG; |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
483 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */ |
579 | 484 s.main.c_cc[VEOL] = 0377; |
485 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */ | |
491 | 486 #endif /* AIX */ |
487 | |
488 #else /* not HAVE_TERMIO */ | |
579 | 489 |
490 s.main.sg_flags &= ~(ECHO | CRMOD | ANYP | ALLDELAY | RAW | LCASE | |
491 | CBREAK | TANDEM); | |
492 s.main.sg_erase = 0377; | |
493 s.main.sg_kill = 0377; | |
494 | |
491 | 495 #endif /* not HAVE_TERMIO */ |
496 | |
579 | 497 EMACS_SET_TTY (out, &s, 0); |
491 | 498 |
499 #ifdef BSD4_1 | |
500 if (interrupt_input) | |
501 reset_sigio (); | |
502 #endif /* BSD4_1 */ | |
503 #ifdef RTU | |
504 { | |
505 int zero = 0; | |
506 ioctl (out, FIOASYNC, &zero); | |
507 } | |
508 #endif /* RTU */ | |
509 } | |
510 #endif /* not VMS */ | |
511 | |
512 #endif /* subprocesses */ | |
513 | |
514 /*ARGSUSED*/ | |
515 setpgrp_of_tty (pid) | |
516 int pid; | |
517 { | |
648 | 518 EMACS_SET_TTY_PGRP (input_fd, &pid); |
491 | 519 } |
520 | |
521 /* Record a signal code and the handler for it. */ | |
522 struct save_signal | |
523 { | |
524 int code; | |
525 SIGTYPE (*handler) (); | |
526 }; | |
527 | |
528 /* Suspend the Emacs process; give terminal to its superior. */ | |
529 | |
530 sys_suspend () | |
531 { | |
532 #ifdef VMS | |
1171
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
533 /* "Foster" parentage allows emacs to return to a subprocess that attached |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
534 to the current emacs as a cheaper than starting a whole new process. This |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
535 is set up by KEPTEDITOR.COM. */ |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
536 unsigned long parent_id, foster_parent_id; |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
537 char *fpid_string; |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
538 |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
539 fpid_string = getenv ("EMACS_PARENT_PID"); |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
540 if (fpid_string != NULL) |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
541 { |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
542 sscanf (fpid_string, "%x", &foster_parent_id); |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
543 if (foster_parent_id != 0) |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
544 parent_id = foster_parent_id; |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
545 else |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
546 parent_id = getppid (); |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
547 } |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
548 else |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
549 parent_id = getppid (); |
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
550 |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
551 xfree (fpid_string); /* On VMS, this was malloc'd */ |
1171
5c942f6b2d63
(sys_suspend): Read EMACS_PARENT_PID envvar for parent.
Richard M. Stallman <rms@gnu.org>
parents:
1102
diff
changeset
|
552 |
491 | 553 if (parent_id && parent_id != 0xffffffff) |
554 { | |
555 SIGTYPE (*oldsig)() = (int) signal (SIGINT, SIG_IGN); | |
556 int status = LIB$ATTACH (&parent_id) & 1; | |
557 signal (SIGINT, oldsig); | |
558 return status; | |
559 } | |
560 else | |
561 { | |
562 struct { | |
563 int l; | |
564 char *a; | |
565 } d_prompt; | |
566 d_prompt.l = sizeof ("Emacs: "); /* Our special prompt */ | |
567 d_prompt.a = "Emacs: "; /* Just a reminder */ | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
568 LIB$SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt, 0); |
491 | 569 return 1; |
570 } | |
571 return -1; | |
572 #else | |
573 #ifdef SIGTSTP | |
574 | |
3472
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
575 #ifdef GETPGRP_NO_ARG |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
576 EMACS_KILLPG (getpgrp (), SIGTSTP); |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
577 #else |
579 | 578 EMACS_KILLPG (getpgrp (0), SIGTSTP); |
3472
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
579 #endif |
491 | 580 |
581 #else /* No SIGTSTP */ | |
582 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */ | |
583 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */ | |
584 kill (getpid (), SIGQUIT); | |
585 | |
586 #else /* No SIGTSTP or USG_JOBCTRL */ | |
587 | |
588 /* On a system where suspending is not implemented, | |
589 instead fork a subshell and let it talk directly to the terminal | |
590 while we wait. */ | |
591 int pid = fork (); | |
592 struct save_signal saved_handlers[5]; | |
593 | |
594 saved_handlers[0].code = SIGINT; | |
595 saved_handlers[1].code = SIGQUIT; | |
596 saved_handlers[2].code = SIGTERM; | |
597 #ifdef SIGIO | |
598 saved_handlers[3].code = SIGIO; | |
599 saved_handlers[4].code = 0; | |
600 #else | |
601 saved_handlers[3].code = 0; | |
602 #endif | |
603 | |
604 if (pid == -1) | |
605 error ("Can't spawn subshell"); | |
606 if (pid == 0) | |
607 { | |
608 char *sh; | |
609 | |
610 sh = (char *) egetenv ("SHELL"); | |
611 if (sh == 0) | |
612 sh = "sh"; | |
613 /* Use our buffer's default directory for the subshell. */ | |
614 { | |
615 Lisp_Object dir; | |
616 unsigned char *str; | |
617 int len; | |
618 | |
619 /* mentioning current_buffer->buffer would mean including buffer.h, | |
620 which somehow wedges the hp compiler. So instead... */ | |
621 | |
622 dir = intern ("default-directory"); | |
623 /* Can't use NULL */ | |
624 if (XFASTINT (Fboundp (dir)) == XFASTINT (Qnil)) | |
625 goto xyzzy; | |
626 dir = Fsymbol_value (dir); | |
627 if (XTYPE (dir) != Lisp_String) | |
628 goto xyzzy; | |
629 | |
630 str = (unsigned char *) alloca (XSTRING (dir)->size + 2); | |
631 len = XSTRING (dir)->size; | |
632 bcopy (XSTRING (dir)->data, str, len); | |
633 if (str[len - 1] != '/') str[len++] = '/'; | |
634 str[len] = 0; | |
635 chdir (str); | |
636 } | |
637 xyzzy: | |
638 #ifdef subprocesses | |
639 close_process_descs (); /* Close Emacs's pipes/ptys */ | |
640 #endif | |
1203
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
641 |
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
642 #ifdef PRIO_PROCESS |
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
643 { |
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
644 extern int emacs_priority; |
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
645 |
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
646 if (emacs_priority) |
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
647 nice (-emacs_priority); |
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
648 } |
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
649 #endif |
bc1acd76b294
* sysdep.c (sys_suspend): Don't try to use "nice (- nice (0))" to
Jim Blandy <jimb@redhat.com>
parents:
1171
diff
changeset
|
650 |
491 | 651 execlp (sh, sh, 0); |
652 write (1, "Can't execute subshell", 22); | |
653 _exit (1); | |
654 } | |
655 | |
656 save_signal_handlers (saved_handlers); | |
2939
34492be68ced
* sysdep.c (sys_suspend): Set synch_process_alive, so that
Jim Blandy <jimb@redhat.com>
parents:
2913
diff
changeset
|
657 synch_process_alive = 1; |
491 | 658 wait_for_termination (pid); |
659 restore_signal_handlers (saved_handlers); | |
660 | |
661 #endif /* no USG_JOBCTRL */ | |
662 #endif /* no SIGTSTP */ | |
663 #endif /* not VMS */ | |
664 } | |
665 | |
666 save_signal_handlers (saved_handlers) | |
667 struct save_signal *saved_handlers; | |
668 { | |
669 while (saved_handlers->code) | |
670 { | |
692 | 671 saved_handlers->handler |
672 = (SIGTYPE (*) ()) signal (saved_handlers->code, SIG_IGN); | |
491 | 673 saved_handlers++; |
674 } | |
675 } | |
676 | |
677 restore_signal_handlers (saved_handlers) | |
678 struct save_signal *saved_handlers; | |
679 { | |
680 while (saved_handlers->code) | |
681 { | |
682 signal (saved_handlers->code, saved_handlers->handler); | |
683 saved_handlers++; | |
684 } | |
685 } | |
686 | |
687 #ifdef F_SETFL | |
688 | |
689 int old_fcntl_flags; | |
690 | |
691 init_sigio () | |
692 { | |
693 #ifdef FASYNC | |
694 old_fcntl_flags = fcntl (0, F_GETFL, 0) & ~FASYNC; | |
695 #endif | |
696 request_sigio (); | |
697 } | |
698 | |
699 reset_sigio () | |
700 { | |
701 unrequest_sigio (); | |
702 } | |
703 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
704 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */ |
491 | 705 |
706 request_sigio () | |
707 { | |
708 #ifdef SIGWINCH | |
638 | 709 sigunblock (sigmask (SIGWINCH)); |
491 | 710 #endif |
711 fcntl (0, F_SETFL, old_fcntl_flags | FASYNC); | |
712 | |
713 interrupts_deferred = 0; | |
714 } | |
715 | |
716 unrequest_sigio () | |
717 { | |
718 #ifdef SIGWINCH | |
638 | 719 sigblock (sigmask (SIGWINCH)); |
491 | 720 #endif |
721 fcntl (0, F_SETFL, old_fcntl_flags); | |
722 interrupts_deferred = 1; | |
723 } | |
724 | |
725 #else /* no FASYNC */ | |
726 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */ | |
727 | |
728 request_sigio () | |
729 { | |
730 int on = 1; | |
731 ioctl (0, FIOASYNC, &on); | |
732 interrupts_deferred = 0; | |
733 } | |
734 | |
735 unrequest_sigio () | |
736 { | |
737 int off = 0; | |
738 | |
739 ioctl (0, FIOASYNC, &off); | |
740 interrupts_deferred = 1; | |
741 } | |
742 | |
743 #else /* not FASYNC, not STRIDE */ | |
744 | |
745 request_sigio () | |
746 { | |
747 croak ("request_sigio"); | |
748 } | |
749 | |
750 unrequest_sigio () | |
751 { | |
752 croak ("unrequest_sigio"); | |
753 } | |
754 | |
755 #endif /* STRIDE */ | |
756 #endif /* FASYNC */ | |
757 #endif /* F_SETFL */ | |
758 | |
2656
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
759 /* Getting and setting emacs_tty structures. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
760 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
761 /* Set *TC to the parameters associated with the terminal FD. |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
762 Return zero if all's well, or -1 if we ran into an error we |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
763 couldn't deal with. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
764 int |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
765 emacs_get_tty (fd, settings) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
766 int fd; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
767 struct emacs_tty *settings; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
768 { |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
769 /* Retrieve the primary parameters - baud rate, character size, etcetera. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
770 #ifdef HAVE_TCATTR |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
771 /* We have those nifty POSIX tcmumbleattr functions. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
772 if (tcgetattr (fd, &settings->main) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
773 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
774 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
775 #else |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
776 #ifdef HAVE_TERMIO |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
777 /* The SYSV-style interface? */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
778 if (ioctl (fd, TCGETA, &settings->main) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
779 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
780 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
781 #else |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
782 #ifdef VMS |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
783 /* Vehemently Monstrous System? :-) */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
784 if (! (SYS$QIOW (0, fd, IO$_SENSEMODE, settings, 0, 0, |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
785 &settings->main.class, 12, 0, 0, 0, 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
786 & 1)) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
787 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
788 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
789 #else |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
790 /* I give up - I hope you have the BSD ioctls. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
791 if (ioctl (fd, TIOCGETP, &settings->main) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
792 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
793 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
794 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
795 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
796 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
797 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
798 /* Suivant - Do we have to get struct ltchars data? */ |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
799 #ifdef HAVE_LTCHARS |
2656
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
800 if (ioctl (fd, TIOCGLTC, &settings->ltchars) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
801 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
802 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
803 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
804 /* How about a struct tchars and a wordful of lmode bits? */ |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
805 #ifdef HAVE_TCHARS |
2656
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
806 if (ioctl (fd, TIOCGETC, &settings->tchars) < 0 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
807 || ioctl (fd, TIOCLGET, &settings->lmode) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
808 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
809 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
810 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
811 /* We have survived the tempest. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
812 return 0; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
813 } |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
814 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
815 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
816 /* Set the parameters of the tty on FD according to the contents of |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
817 *SETTINGS. If WAITP is non-zero, we wait for all queued output to |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
818 be written before making the change; otherwise, we forget any |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
819 queued input and make the change immediately. |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
820 Return 0 if all went well, and -1 if anything failed. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
821 int |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
822 emacs_set_tty (fd, settings, waitp) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
823 int fd; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
824 struct emacs_tty *settings; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
825 int waitp; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
826 { |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
827 /* Set the primary parameters - baud rate, character size, etcetera. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
828 #ifdef HAVE_TCATTR |
3321
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
829 int i; |
2656
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
830 /* We have those nifty POSIX tcmumbleattr functions. |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
831 William J. Smith <wjs@wiis.wang.com> writes: |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
832 "POSIX 1003.1 defines tcsetattr() to return success if it was |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
833 able to perform any of the requested actions, even if some |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
834 of the requested actions could not be performed. |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
835 We must read settings back to ensure tty setup properly. |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
836 AIX requires this to keep tty from hanging occasionally." */ |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
837 /* This make sure that we don't loop indefinitely in here. */ |
3321
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
838 for (i = 0 ; i < 10 ; i++) |
2656
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
839 if (tcsetattr (fd, waitp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
840 { |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
841 if (errno == EINTR) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
842 continue; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
843 else |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
844 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
845 } |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
846 else |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
847 { |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
848 struct termios new; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
849 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
850 /* Get the current settings, and see if they're what we asked for. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
851 tcgetattr (fd, &new); |
3321
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
852 /* We cannot use memcmp on the whole structure here because under |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
853 * aix386 the termios structure has some reserved field that may |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
854 * not be filled in. |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
855 */ |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
856 if ( new.c_iflag == settings->main.c_iflag |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
857 && new.c_oflag == settings->main.c_oflag |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
858 && new.c_cflag == settings->main.c_cflag |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
859 && new.c_lflag == settings->main.c_lflag |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
860 && memcmp(new.c_cc, settings->main.c_cc, NCCS) == 0) |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
861 break; |
d2adfd22a854
(child_setup_tty) [AIX SIGNALS_VIA_CHARACTERS]: Install
Richard M. Stallman <rms@gnu.org>
parents:
3301
diff
changeset
|
862 else |
2656
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
863 continue; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
864 } |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
865 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
866 #else |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
867 #ifdef HAVE_TERMIO |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
868 /* The SYSV-style interface? */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
869 if (ioctl (fd, waitp ? TCSETAW : TCSETAF, &settings->main) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
870 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
871 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
872 #else |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
873 #ifdef VMS |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
874 /* Vehemently Monstrous System? :-) */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
875 if (! (SYS$QIOW (0, fd, IO$_SETMODE, &input_iosb, 0, 0, |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
876 &settings->main.class, 12, 0, 0, 0, 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
877 & 1)) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
878 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
879 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
880 #else |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
881 /* I give up - I hope you have the BSD ioctls. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
882 if (ioctl (fd, (waitp) ? TIOCSETP : TIOCSETN, &settings->main) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
883 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
884 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
885 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
886 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
887 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
888 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
889 /* Suivant - Do we have to get struct ltchars data? */ |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
890 #ifdef HAVE_LTCHARS |
2656
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
891 if (ioctl (fd, TIOCSLTC, &settings->ltchars) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
892 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
893 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
894 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
895 /* How about a struct tchars and a wordful of lmode bits? */ |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
896 #ifdef HAVE_TCHARS |
2656
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
897 if (ioctl (fd, TIOCSETC, &settings->tchars) < 0 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
898 || ioctl (fd, TIOCLSET, &settings->lmode) < 0) |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
899 return -1; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
900 #endif |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
901 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
902 /* We have survived the tempest. */ |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
903 return 0; |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
904 } |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
905 |
93eda11d38de
* systty.h (EMACS_GET_TTY, EMACS_SET_TTY): Move these into
Jim Blandy <jimb@redhat.com>
parents:
2589
diff
changeset
|
906 |
579 | 907 /* The initial tty mode bits */ |
908 struct emacs_tty old_tty; | |
491 | 909 |
910 int term_initted; /* 1 if outer tty status has been recorded */ | |
911 | |
579 | 912 #ifdef BSD4_1 |
913 /* BSD 4.1 needs to keep track of the lmode bits in order to start | |
914 sigio. */ | |
915 int lmode; | |
916 #endif | |
917 | |
491 | 918 #ifdef F_SETOWN |
919 int old_fcntl_owner; | |
920 #endif /* F_SETOWN */ | |
921 | |
922 /* This may also be defined in stdio, | |
923 but if so, this does no harm, | |
924 and using the same name avoids wasting the other one's space. */ | |
925 | |
926 #if defined (USG) || defined (DGUX) | |
927 unsigned char _sobuf[BUFSIZ+8]; | |
928 #else | |
929 char _sobuf[BUFSIZ]; | |
930 #endif | |
931 | |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
932 #ifdef HAVE_LTCHARS |
491 | 933 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1}; |
934 #endif | |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
935 #ifdef HAVE_TCHARS |
491 | 936 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1}; |
937 #endif | |
938 | |
939 init_sys_modes () | |
940 { | |
579 | 941 struct emacs_tty tty; |
942 | |
491 | 943 #ifdef VMS |
944 #if 0 | |
945 static int oob_chars[2] = {0, 1 << 7}; /* catch C-g's */ | |
946 extern int (*interrupt_signal) (); | |
947 #endif | |
948 #endif | |
949 | |
950 if (noninteractive) | |
951 return; | |
952 | |
953 #ifdef VMS | |
954 if (!input_ef) | |
955 input_ef = get_kbd_event_flag (); | |
956 /* LIB$GET_EF (&input_ef); */ | |
957 SYS$CLREF (input_ef); | |
958 waiting_for_ast = 0; | |
959 if (!timer_ef) | |
960 timer_ef = get_timer_event_flag (); | |
961 /* LIB$GET_EF (&timer_ef); */ | |
962 SYS$CLREF (timer_ef); | |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
963 #if 0 |
491 | 964 if (!process_ef) |
965 { | |
966 LIB$GET_EF (&process_ef); | |
967 SYS$CLREF (process_ef); | |
968 } | |
969 if (input_ef / 32 != process_ef / 32) | |
970 croak ("Input and process event flags in different clusters."); | |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
971 #endif |
491 | 972 if (input_ef / 32 != timer_ef / 32) |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
973 croak ("Input and timer event flags in different clusters."); |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
974 #if 0 |
491 | 975 input_eflist = ((unsigned) 1 << (input_ef % 32)) | |
976 ((unsigned) 1 << (process_ef % 32)); | |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
977 #endif |
491 | 978 timer_eflist = ((unsigned) 1 << (input_ef % 32)) | |
979 ((unsigned) 1 << (timer_ef % 32)); | |
980 #ifndef VMS4_4 | |
981 sys_access_reinit (); | |
982 #endif | |
983 #endif /* not VMS */ | |
579 | 984 |
985 EMACS_GET_TTY (input_fd, &old_tty); | |
986 | |
491 | 987 if (!read_socket_hook && EQ (Vwindow_system, Qnil)) |
988 { | |
579 | 989 tty = old_tty; |
491 | 990 |
1927
c6dc1a37aeb4
* sysdep.c (child_setup_tty): Recognize HAVE_TERMIOS as well as
Jim Blandy <jimb@redhat.com>
parents:
1596
diff
changeset
|
991 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS) |
579 | 992 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */ |
993 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */ | |
491 | 994 #ifdef ISTRIP |
579 | 995 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */ |
491 | 996 #endif |
579 | 997 tty.main.c_lflag &= ~ECHO; /* Disable echo */ |
998 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */ | |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
999 #ifdef IEXTEN |
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
1000 tty.main.c_iflag &= ~IEXTEN; /* Disable other editing characters. */ |
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
1001 #endif |
579 | 1002 tty.main.c_lflag |= ISIG; /* Enable signals */ |
491 | 1003 if (flow_control) |
1004 { | |
579 | 1005 tty.main.c_iflag |= IXON; /* Enable start/stop output control */ |
491 | 1006 #ifdef IXANY |
579 | 1007 tty.main.c_iflag &= ~IXANY; |
491 | 1008 #endif /* IXANY */ |
1009 } | |
1010 else | |
579 | 1011 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */ |
1012 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL | |
1013 on output */ | |
1014 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */ | |
491 | 1015 #ifdef CS8 |
1016 if (meta_key) | |
1017 { | |
579 | 1018 tty.main.c_cflag |= CS8; /* allow 8th bit on input */ |
1019 tty.main.c_cflag &= ~PARENB;/* Don't check parity */ | |
491 | 1020 } |
1021 #endif | |
579 | 1022 tty.main.c_cc[VINTR] = quit_char; /* C-g (usually) gives SIGINT */ |
491 | 1023 /* Set up C-g for both SIGQUIT and SIGINT. |
1024 We don't know which we will get, but we handle both alike | |
1025 so which one it really gives us does not matter. */ | |
579 | 1026 tty.main.c_cc[VQUIT] = quit_char; |
1027 tty.main.c_cc[VMIN] = 1; /* Input should wait for at least 1 char */ | |
1028 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */ | |
491 | 1029 #ifdef VSWTCH |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
1030 tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use |
579 | 1031 of C-z */ |
491 | 1032 #endif /* VSWTCH */ |
1033 #if defined (mips) || defined (HAVE_TCATTR) | |
1034 #ifdef VSUSP | |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
1035 tty.main.c_cc[VSUSP] = CDISABLE; /* Turn off mips handling of C-z. */ |
491 | 1036 #endif /* VSUSP */ |
1037 #ifdef V_DSUSP | |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
1038 tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */ |
491 | 1039 #endif /* V_DSUSP */ |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
1040 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */ |
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
1041 tty.main.c_cc[VDSUSP] = CDISABLE; |
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
1042 #endif /* VDSUSP */ |
3472
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1043 #ifdef VLNEXT |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1044 tty.main.c_cc[VLNEXT] = CDISABLE; |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1045 #endif /* VLNEXT */ |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1046 #ifdef VREPRINT |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1047 tty.main.c_cc[VREPRINT] = CDISABLE; |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1048 #endif /* VREPRINT */ |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1049 #ifdef VWERASE |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1050 tty.main.c_cc[VWERASE] = CDISABLE; |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1051 #endif /* VWERASE */ |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1052 #ifdef VDISCARD |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1053 tty.main.c_cc[VDISCARD] = CDISABLE; |
6f05f6e83e94
(wait_for_termination): Fix sigpause in POSIX_SIGNALS case.
Richard M. Stallman <rms@gnu.org>
parents:
3334
diff
changeset
|
1054 #endif /* VDISCARD */ |
491 | 1055 #endif /* mips or HAVE_TCATTR */ |
1056 #ifdef AIX | |
1057 #ifndef IBMR2AIX | |
1058 /* AIX enhanced edit loses NULs, so disable it */ | |
579 | 1059 tty.main.c_line = 0; |
1060 tty.main.c_iflag &= ~ASCEDIT; | |
491 | 1061 #else |
579 | 1062 tty.main.c_cc[VSTRT] = 255; |
1063 tty.main.c_cc[VSTOP] = 255; | |
1064 tty.main.c_cc[VSUSP] = 255; | |
1065 tty.main.c_cc[VDSUSP] = 255; | |
491 | 1066 #endif /* IBMR2AIX */ |
1067 /* Also, PTY overloads NUL and BREAK. | |
1068 don't ignore break, but don't signal either, so it looks like NUL. | |
1069 This really serves a purpose only if running in an XTERM window | |
1070 or via TELNET or the like, but does no harm elsewhere. */ | |
579 | 1071 tty.main.c_iflag &= ~IGNBRK; |
1072 tty.main.c_iflag &= ~BRKINT; | |
491 | 1073 #endif |
1074 #else /* if not HAVE_TERMIO */ | |
1075 #ifdef VMS | |
579 | 1076 tty.main.tt_char |= TT$M_NOECHO; |
491 | 1077 if (meta_key) |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
1078 tty.main.tt_char |= TT$M_EIGHTBIT; |
491 | 1079 if (flow_control) |
579 | 1080 tty.main.tt_char |= TT$M_TTSYNC; |
491 | 1081 else |
579 | 1082 tty.main.tt_char &= ~TT$M_TTSYNC; |
1083 tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON; | |
491 | 1084 #else /* not VMS (BSD, that is) */ |
579 | 1085 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS); |
491 | 1086 if (meta_key) |
579 | 1087 tty.main.sg_flags |= ANYP; |
1088 tty.main.sg_flags |= interrupt_input ? RAW : CBREAK; | |
491 | 1089 #endif /* not VMS (BSD, that is) */ |
1090 #endif /* not HAVE_TERMIO */ | |
1091 | |
579 | 1092 /* If going to use CBREAK mode, we must request C-g to interrupt |
1093 and turn off start and stop chars, etc. If not going to use | |
1094 CBREAK mode, do this anyway so as to turn off local flow | |
1095 control for user coming over network on 4.2; in this case, | |
1096 only t_stopc and t_startc really matter. */ | |
1097 #ifndef HAVE_TERMIO | |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
1098 #ifdef HAVE_TCHARS |
579 | 1099 /* Note: if not using CBREAK mode, it makes no difference how we |
1100 set this */ | |
1101 tty.tchars = new_tchars; | |
1102 tty.tchars.t_intrc = quit_char; | |
1103 if (flow_control) | |
1104 { | |
1105 tty.tchars.t_startc = '\021'; | |
1106 tty.tchars.t_stopc = '\023'; | |
1107 } | |
1108 | |
1109 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */ | |
1110 #ifndef LPASS8 | |
1111 #define LPASS8 0 | |
491 | 1112 #endif |
579 | 1113 |
1114 #ifdef BSD4_1 | |
1115 #define LNOFLSH 0100000 | |
1116 #endif | |
1117 | |
1118 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH | old_tty.lmode; | |
1119 | |
1120 #ifdef BSD4_1 | |
1121 lmode = tty.lmode; | |
1122 #endif | |
1123 | |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
1124 #endif /* HAVE_TCHARS */ |
579 | 1125 #endif /* not HAVE_TERMIO */ |
1126 | |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
1127 #ifdef HAVE_LTCHARS |
579 | 1128 tty.ltchars = new_ltchars; |
3157
84825e357019
* systty.h (HAVE_LTCHARS, HAVE_TCHARS): New macros; define them if
Jim Blandy <jimb@redhat.com>
parents:
3150
diff
changeset
|
1129 #endif /* HAVE_LTCHARS */ |
579 | 1130 |
1131 EMACS_SET_TTY (input_fd, &tty, 0); | |
491 | 1132 |
1133 /* This code added to insure that, if flow-control is not to be used, | |
766 | 1134 we have an unlocked terminal at the start. */ |
579 | 1135 |
491 | 1136 #ifdef TCXONC |
1137 if (!flow_control) ioctl (0, TCXONC, 1); | |
1138 #endif | |
1139 #ifndef APOLLO | |
1140 #ifdef TIOCSTART | |
1141 if (!flow_control) ioctl (0, TIOCSTART, 0); | |
1142 #endif | |
1143 #endif | |
1144 | |
1145 #ifdef AIX | |
1146 hft_init (); | |
1147 #ifdef IBMR2AIX | |
1148 { | |
1149 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it | |
1150 to be only LF. This is the way that is done. */ | |
1151 struct termio tty; | |
1152 | |
1153 if (ioctl (1, HFTGETID, &tty) != -1) | |
1154 write (1, "\033[20l", 5); | |
1155 } | |
1156 #endif | |
1157 #endif | |
1158 | |
1159 #ifdef VMS | |
1160 /* Appears to do nothing when in PASTHRU mode. | |
579 | 1161 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0, |
491 | 1162 interrupt_signal, oob_chars, 0, 0, 0, 0); |
1163 */ | |
1164 queue_kbd_input (0); | |
1165 #endif /* VMS */ | |
1166 } | |
1167 | |
1168 #ifdef F_SETFL | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
1169 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */ |
491 | 1170 if (interrupt_input) |
1171 { | |
1172 old_fcntl_owner = fcntl (0, F_GETOWN, 0); | |
1173 fcntl (0, F_SETOWN, getpid ()); | |
1174 init_sigio (); | |
1175 } | |
1176 #endif /* F_GETOWN */ | |
1177 #endif /* F_SETFL */ | |
1178 | |
1179 #ifdef BSD4_1 | |
1180 if (interrupt_input) | |
1181 init_sigio (); | |
1182 #endif | |
1183 | |
1184 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */ | |
1185 #undef _IOFBF | |
1186 #endif | |
1187 #ifdef _IOFBF | |
1188 /* This symbol is defined on recent USG systems. | |
1189 Someone says without this call USG won't really buffer the file | |
1190 even with a call to setbuf. */ | |
1191 setvbuf (stdout, _sobuf, _IOFBF, sizeof _sobuf); | |
1192 #else | |
1193 setbuf (stdout, _sobuf); | |
1194 #endif | |
1195 set_terminal_modes (); | |
1196 if (term_initted && no_redraw_on_reenter) | |
1197 { | |
1198 if (display_completed) | |
1199 direct_output_forward_char (0); | |
1200 } | |
1201 else | |
1202 { | |
766 | 1203 frame_garbaged = 1; |
1204 #ifdef MULTI_FRAME | |
1205 if (FRAMEP (Vterminal_frame)) | |
1206 FRAME_GARBAGED_P (XFRAME (Vterminal_frame)) = 1; | |
491 | 1207 #endif |
1208 } | |
579 | 1209 |
491 | 1210 term_initted = 1; |
1211 } | |
1212 | |
1213 /* Return nonzero if safe to use tabs in output. | |
1214 At the time this is called, init_sys_modes has not been done yet. */ | |
1215 | |
1216 tabs_safe_p () | |
1217 { | |
579 | 1218 struct emacs_tty tty; |
1219 | |
1220 EMACS_GET_TTY (input_fd, &tty); | |
1221 return EMACS_TTY_TABS_OK (&tty); | |
491 | 1222 } |
1223 | |
1224 /* Get terminal size from system. | |
1225 Store number of lines into *heightp and width into *widthp. | |
1226 If zero or a negative number is stored, the value is not valid. */ | |
1227 | |
766 | 1228 get_frame_size (widthp, heightp) |
491 | 1229 int *widthp, *heightp; |
1230 { | |
579 | 1231 |
1232 #ifdef TIOCGWINSZ | |
1233 | |
1234 /* BSD-style. */ | |
1235 struct winsize size; | |
1236 | |
1237 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1) | |
1238 *widthp = *heightp = 0; | |
1239 else | |
1240 { | |
1241 *widthp = size.ws_col; | |
1242 *heightp = size.ws_row; | |
1243 } | |
1244 | |
1245 #else | |
491 | 1246 #ifdef TIOCGSIZE |
579 | 1247 |
1248 /* SunOS - style. */ | |
1249 struct ttysize size; | |
1250 | |
1251 if (ioctl (input_fd, TIOCGSIZE, &size) == -1) | |
1252 *widthp = *heightp = 0; | |
1253 else | |
1254 { | |
1255 *widthp = size.ts_cols; | |
1256 *heightp = size.ts_lines; | |
1257 } | |
1258 | |
1259 #else | |
491 | 1260 #ifdef VMS |
579 | 1261 |
1262 struct sensemode tty; | |
1263 | |
1264 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0, | |
491 | 1265 &tty.class, 12, 0, 0, 0, 0); |
1266 *widthp = tty.scr_wid; | |
1267 *heightp = tty.scr_len; | |
579 | 1268 |
491 | 1269 #else /* system doesn't know size */ |
579 | 1270 |
491 | 1271 *widthp = 0; |
1272 *heightp = 0; | |
579 | 1273 |
1274 #endif /* not VMS */ | |
1275 #endif /* not SunOS-style */ | |
1276 #endif /* not BSD-style */ | |
491 | 1277 } |
579 | 1278 |
491 | 1279 |
579 | 1280 /* Prepare the terminal for exiting Emacs; move the cursor to the |
766 | 1281 bottom of the frame, turn off interrupt-driven I/O, etc. */ |
491 | 1282 reset_sys_modes () |
1283 { | |
1284 if (noninteractive) | |
1285 { | |
1286 fflush (stdout); | |
1287 return; | |
1288 } | |
1289 if (!term_initted) | |
1290 return; | |
1291 if (read_socket_hook || !EQ (Vwindow_system, Qnil)) | |
1292 return; | |
766 | 1293 cursor_to (FRAME_HEIGHT (selected_frame) - 1, 0); |
1294 clear_end_of_line (FRAME_WIDTH (selected_frame)); | |
491 | 1295 /* clear_end_of_line may move the cursor */ |
766 | 1296 cursor_to (FRAME_HEIGHT (selected_frame) - 1, 0); |
491 | 1297 #ifdef IBMR2AIX |
1298 { | |
1299 /* HFT devices normally use ^J as a LF/CR. We forced it to | |
1300 do the LF only. Now, we need to reset it. */ | |
1301 struct termio tty; | |
1302 | |
1303 if (ioctl (1, HFTGETID, &tty) != -1) | |
1304 write (1, "\033[20h", 5); | |
1305 } | |
1306 #endif | |
1307 | |
1308 reset_terminal_modes (); | |
1309 fflush (stdout); | |
1310 #ifdef BSD | |
1311 #ifndef BSD4_1 | |
1312 /* Avoid possible loss of output when changing terminal modes. */ | |
1313 fsync (fileno (stdout)); | |
1314 #endif | |
1315 #endif | |
579 | 1316 |
491 | 1317 #ifdef F_SETFL |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
1318 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */ |
491 | 1319 if (interrupt_input) |
1320 { | |
1321 reset_sigio (); | |
1322 fcntl (0, F_SETOWN, old_fcntl_owner); | |
1323 } | |
1324 #endif /* F_SETOWN */ | |
1325 #endif /* F_SETFL */ | |
1326 #ifdef BSD4_1 | |
1327 if (interrupt_input) | |
1328 reset_sigio (); | |
1329 #endif /* BSD4_1 */ | |
579 | 1330 |
2873
f1cd54cf1b67
* sysdep.c (reset_sys_modes): Test the return value of
Jim Blandy <jimb@redhat.com>
parents:
2656
diff
changeset
|
1331 while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR) |
579 | 1332 ; |
491 | 1333 |
1334 #ifdef AIX | |
1335 hft_reset (); | |
1336 #endif | |
1337 } | |
1338 | |
1339 #ifdef HAVE_PTYS | |
1340 | |
1341 /* Set up the proper status flags for use of a pty. */ | |
1342 | |
1343 setup_pty (fd) | |
1344 int fd; | |
1345 { | |
1346 /* I'm told that TOICREMOTE does not mean control chars | |
1347 "can't be sent" but rather that they don't have | |
1348 input-editing or signaling effects. | |
1349 That should be good, because we have other ways | |
1350 to do those things in Emacs. | |
1351 However, telnet mode seems not to work on 4.2. | |
1352 So TIOCREMOTE is turned off now. */ | |
1353 | |
1354 /* Under hp-ux, if TIOCREMOTE is turned on, some calls | |
1355 will hang. In particular, the "timeout" feature (which | |
1356 causes a read to return if there is no data available) | |
1357 does this. Also it is known that telnet mode will hang | |
1358 in such a way that Emacs must be stopped (perhaps this | |
1359 is the same problem). | |
1360 | |
1361 If TIOCREMOTE is turned off, then there is a bug in | |
1362 hp-ux which sometimes loses data. Apparently the | |
1363 code which blocks the master process when the internal | |
1364 buffer fills up does not work. Other than this, | |
1365 though, everything else seems to work fine. | |
1366 | |
1367 Since the latter lossage is more benign, we may as well | |
1368 lose that way. -- cph */ | |
1369 #ifdef FIONBIO | |
1370 #ifdef SYSV_PTYS | |
1371 { | |
1372 int on = 1; | |
1373 ioctl (fd, FIONBIO, &on); | |
1374 } | |
1375 #endif | |
1376 #endif | |
1377 #ifdef IBMRTAIX | |
1378 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */ | |
1379 /* ignore SIGHUP once we've started a child on a pty. Note that this may */ | |
1380 /* cause EMACS not to die when it should, i.e., when its own controlling */ | |
1381 /* tty goes away. I've complained to the AIX developers, and they may */ | |
1382 /* change this behavior, but I'm not going to hold my breath. */ | |
1383 signal (SIGHUP, SIG_IGN); | |
1384 #endif | |
1385 } | |
1386 #endif /* HAVE_PTYS */ | |
1387 | |
1388 #ifdef VMS | |
1389 | |
1390 /* Assigning an input channel is done at the start of Emacs execution. | |
1391 This is called each time Emacs is resumed, also, but does nothing | |
1392 because input_chain is no longer zero. */ | |
1393 | |
1394 init_vms_input () | |
1395 { | |
1396 int status; | |
1397 | |
579 | 1398 if (input_fd == 0) |
491 | 1399 { |
579 | 1400 status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0); |
491 | 1401 if (! (status & 1)) |
1402 LIB$STOP (status); | |
1403 } | |
1404 } | |
1405 | |
1406 /* Deassigning the input channel is done before exiting. */ | |
1407 | |
1408 stop_vms_input () | |
1409 { | |
579 | 1410 return SYS$DASSGN (input_fd); |
491 | 1411 } |
1412 | |
1413 short input_buffer; | |
1414 | |
1415 /* Request reading one character into the keyboard buffer. | |
1416 This is done as soon as the buffer becomes empty. */ | |
1417 | |
1418 queue_kbd_input () | |
1419 { | |
1420 int status; | |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1421 extern kbd_input_ast (); |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1422 |
491 | 1423 waiting_for_ast = 0; |
1424 stop_input = 0; | |
579 | 1425 status = SYS$QIO (0, input_fd, IO$_READVBLK, |
491 | 1426 &input_iosb, kbd_input_ast, 1, |
1427 &input_buffer, 1, 0, terminator_mask, 0, 0); | |
1428 } | |
1429 | |
1430 int input_count; | |
1431 | |
1432 /* Ast routine that is called when keyboard input comes in | |
1433 in accord with the SYS$QIO above. */ | |
1434 | |
1435 kbd_input_ast () | |
1436 { | |
1437 register int c = -1; | |
1438 int old_errno = errno; | |
648 | 1439 extern EMACS_TIME *input_available_clear_time; |
491 | 1440 |
1441 if (waiting_for_ast) | |
1442 SYS$SETEF (input_ef); | |
1443 waiting_for_ast = 0; | |
1444 input_count++; | |
1445 #ifdef ASTDEBUG | |
1446 if (input_count == 25) | |
1447 exit (1); | |
1448 printf ("Ast # %d,", input_count); | |
1449 printf (" iosb = %x, %x, %x, %x", | |
1450 input_iosb.offset, input_iosb.status, input_iosb.termlen, | |
1451 input_iosb.term); | |
1452 #endif | |
1453 if (input_iosb.offset) | |
1454 { | |
1455 c = input_buffer; | |
1456 #ifdef ASTDEBUG | |
1457 printf (", char = 0%o", c); | |
1458 #endif | |
1459 } | |
1460 #ifdef ASTDEBUG | |
1461 printf ("\n"); | |
1462 fflush (stdout); | |
1463 sleep (1); | |
1464 #endif | |
1465 if (! stop_input) | |
1466 queue_kbd_input (); | |
1467 if (c >= 0) | |
1468 { | |
1469 struct input_event e; | |
1470 e.kind = ascii_keystroke; | |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1471 XSET (e.code, Lisp_Int, c); |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1472 #ifdef MULTI_FRAME |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1473 XSET(e.frame_or_window, Lisp_Frame, selected_frame); |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1474 #else |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1475 e.frame_or_window = Qnil; |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1476 #endif |
491 | 1477 kbd_buffer_store_event (&e); |
1478 } | |
648 | 1479 if (input_available_clear_time) |
1480 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | |
491 | 1481 errno = old_errno; |
1482 } | |
1483 | |
1484 /* Wait until there is something in kbd_buffer. */ | |
1485 | |
1486 wait_for_kbd_input () | |
1487 { | |
1488 extern int have_process_input, process_exited; | |
1489 | |
1490 /* If already something, avoid doing system calls. */ | |
1491 if (detect_input_pending ()) | |
1492 { | |
1493 return; | |
1494 } | |
1495 /* Clear a flag, and tell ast routine above to set it. */ | |
1496 SYS$CLREF (input_ef); | |
1497 waiting_for_ast = 1; | |
1498 /* Check for timing error: ast happened while we were doing that. */ | |
1499 if (!detect_input_pending ()) | |
1500 { | |
1501 /* No timing error: wait for flag to be set. */ | |
1502 set_waiting_for_input (0); | |
1503 SYS$WFLOR (input_ef, input_eflist); | |
1504 clear_waiting_for_input (0); | |
1505 if (!detect_input_pending ()) | |
1506 /* Check for subprocess input availability */ | |
1507 { | |
1508 int dsp = have_process_input || process_exited; | |
1509 | |
1510 SYS$CLREF (process_ef); | |
1511 if (have_process_input) | |
1512 process_command_input (); | |
1513 if (process_exited) | |
1514 process_exit (); | |
1515 if (dsp) | |
1516 { | |
1517 update_mode_lines++; | |
1518 redisplay_preserve_echo_area (); | |
1519 } | |
1520 } | |
1521 } | |
1522 waiting_for_ast = 0; | |
1523 } | |
1524 | |
1525 /* Get rid of any pending QIO, when we are about to suspend | |
1526 or when we want to throw away pending input. | |
1527 We wait for a positive sign that the AST routine has run | |
1528 and therefore there is no I/O request queued when we return. | |
1529 SYS$SETAST is used to avoid a timing error. */ | |
1530 | |
1531 end_kbd_input () | |
1532 { | |
1533 #ifdef ASTDEBUG | |
1534 printf ("At end_kbd_input.\n"); | |
1535 fflush (stdout); | |
1536 sleep (1); | |
1537 #endif | |
1538 if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */ | |
1539 { | |
579 | 1540 SYS$CANCEL (input_fd); |
491 | 1541 return; |
1542 } | |
1543 | |
1544 SYS$SETAST (0); | |
1545 /* Clear a flag, and tell ast routine above to set it. */ | |
1546 SYS$CLREF (input_ef); | |
1547 waiting_for_ast = 1; | |
1548 stop_input = 1; | |
579 | 1549 SYS$CANCEL (input_fd); |
491 | 1550 SYS$SETAST (1); |
1551 SYS$WAITFR (input_ef); | |
1552 waiting_for_ast = 0; | |
1553 } | |
1554 | |
1555 /* Wait for either input available or time interval expiry. */ | |
1556 | |
1557 input_wait_timeout (timeval) | |
1558 int timeval; /* Time to wait, in seconds */ | |
1559 { | |
1560 int time [2]; | |
1561 static int zero = 0; | |
1562 static int large = -10000000; | |
1563 | |
1564 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */ | |
1565 | |
1566 /* If already something, avoid doing system calls. */ | |
1567 if (detect_input_pending ()) | |
1568 { | |
1569 return; | |
1570 } | |
1571 /* Clear a flag, and tell ast routine above to set it. */ | |
1572 SYS$CLREF (input_ef); | |
1573 waiting_for_ast = 1; | |
1574 /* Check for timing error: ast happened while we were doing that. */ | |
1575 if (!detect_input_pending ()) | |
1576 { | |
1577 /* No timing error: wait for flag to be set. */ | |
1578 SYS$CANTIM (1, 0); | |
1579 if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */ | |
1580 SYS$WFLOR (timer_ef, timer_eflist); /* Wait for timer expiry or input */ | |
1581 } | |
1582 waiting_for_ast = 0; | |
1583 } | |
1584 | |
1585 /* The standard `sleep' routine works some other way | |
1586 and it stops working if you have ever quit out of it. | |
1587 This one continues to work. */ | |
1588 | |
1589 sys_sleep (timeval) | |
1590 int timeval; | |
1591 { | |
1592 int time [2]; | |
1593 static int zero = 0; | |
1594 static int large = -10000000; | |
1595 | |
1596 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */ | |
1597 | |
1598 SYS$CANTIM (1, 0); | |
1599 if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */ | |
1600 SYS$WAITFR (timer_ef); /* Wait for timer expiry only */ | |
1601 } | |
1602 | |
1603 init_sigio () | |
1604 { | |
1605 request_sigio (); | |
1606 } | |
1607 | |
1608 reset_sigio () | |
1609 { | |
1610 unrequest_sigio (); | |
1611 } | |
1612 | |
1613 request_sigio () | |
1614 { | |
1615 croak ("request sigio"); | |
1616 } | |
1617 | |
1618 unrequest_sigio () | |
1619 { | |
1620 croak ("unrequest sigio"); | |
1621 } | |
1622 | |
1623 #endif /* VMS */ | |
1624 | |
1625 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */ | |
1626 #ifndef CANNOT_DUMP | |
1627 #define NEED_STARTS | |
1628 #endif | |
1629 | |
1630 #ifndef SYSTEM_MALLOC | |
1631 #ifndef NEED_STARTS | |
1632 #define NEED_STARTS | |
1633 #endif | |
1634 #endif | |
1635 | |
1636 #ifdef NEED_STARTS | |
1637 /* Some systems that cannot dump also cannot implement these. */ | |
1638 | |
1639 /* | |
1640 * Return the address of the start of the text segment prior to | |
1641 * doing an unexec. After unexec the return value is undefined. | |
1642 * See crt0.c for further explanation and _start. | |
1643 * | |
1644 */ | |
1645 | |
1646 #ifndef CANNOT_UNEXEC | |
1647 char * | |
1648 start_of_text () | |
1649 { | |
1650 #ifdef TEXT_START | |
1651 return ((char *) TEXT_START); | |
1652 #else | |
1653 #ifdef GOULD | |
1654 extern csrt (); | |
1655 return ((char *) csrt); | |
1656 #else /* not GOULD */ | |
1657 extern int _start (); | |
1658 return ((char *) _start); | |
1659 #endif /* GOULD */ | |
1660 #endif /* TEXT_START */ | |
1661 } | |
1662 #endif /* not CANNOT_UNEXEC */ | |
1663 | |
1664 /* | |
1665 * Return the address of the start of the data segment prior to | |
1666 * doing an unexec. After unexec the return value is undefined. | |
1667 * See crt0.c for further information and definition of data_start. | |
1668 * | |
1669 * Apparently, on BSD systems this is etext at startup. On | |
1670 * USG systems (swapping) this is highly mmu dependent and | |
1671 * is also dependent on whether or not the program is running | |
1672 * with shared text. Generally there is a (possibly large) | |
1673 * gap between end of text and start of data with shared text. | |
1674 * | |
1675 * On Uniplus+ systems with shared text, data starts at a | |
1676 * fixed address. Each port (from a given oem) is generally | |
1677 * different, and the specific value of the start of data can | |
1678 * be obtained via the UniPlus+ specific "uvar" system call, | |
1679 * however the method outlined in crt0.c seems to be more portable. | |
1680 * | |
1681 * Probably what will have to happen when a USG unexec is available, | |
1682 * at least on UniPlus, is temacs will have to be made unshared so | |
1683 * that text and data are contiguous. Then once loadup is complete, | |
1684 * unexec will produce a shared executable where the data can be | |
1685 * at the normal shared text boundry and the startofdata variable | |
1686 * will be patched by unexec to the correct value. | |
1687 * | |
1688 */ | |
1689 | |
1690 char * | |
1691 start_of_data () | |
1692 { | |
1693 #ifdef DATA_START | |
1694 return ((char *) DATA_START); | |
1695 #else | |
2121
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1696 #ifdef ORDINARY_LINK |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1697 /* |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1698 * This is a hack. Since we're not linking crt0.c or pre_crt0.c, |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1699 * data_start isn't defined. We take the address of environ, which |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1700 * is known to live at or near the start of the system crt0.c, and |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1701 * we don't sweat the handful of bytes that might lose. |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1702 */ |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1703 extern char **environ; |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1704 |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1705 return((char *) &environ); |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1706 #else |
491 | 1707 extern int data_start; |
1708 return ((char *) &data_start); | |
2121
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1709 #endif /* ORDINARY_LINK */ |
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
1710 #endif /* DATA_START */ |
491 | 1711 } |
1712 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */ | |
1713 | |
1714 #ifndef CANNOT_DUMP | |
1715 /* Some systems that cannot dump also cannot implement these. */ | |
1716 | |
1717 /* | |
1718 * Return the address of the end of the text segment prior to | |
1719 * doing an unexec. After unexec the return value is undefined. | |
1720 */ | |
1721 | |
1722 char * | |
1723 end_of_text () | |
1724 { | |
1725 #ifdef TEXT_END | |
1726 return ((char *) TEXT_END); | |
1727 #else | |
1728 extern int etext; | |
1729 return ((char *) &etext); | |
1730 #endif | |
1731 } | |
1732 | |
1733 /* | |
1734 * Return the address of the end of the data segment prior to | |
1735 * doing an unexec. After unexec the return value is undefined. | |
1736 */ | |
1737 | |
1738 char * | |
1739 end_of_data () | |
1740 { | |
1741 #ifdef DATA_END | |
1742 return ((char *) DATA_END); | |
1743 #else | |
1744 extern int edata; | |
1745 return ((char *) &edata); | |
1746 #endif | |
1747 } | |
1748 | |
1749 #endif /* not CANNOT_DUMP */ | |
1750 | |
1751 /* Get_system_name returns as its value | |
1752 a string for the Lisp function system-name to return. */ | |
1753 | |
1754 #ifdef BSD4_1 | |
1755 #include <whoami.h> | |
1756 #endif | |
1757 | |
1496
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1758 /* Can't have this within the function since `static' is #defined to |
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1759 nothing for some USG systems. */ |
491 | 1760 #ifdef USG |
1496
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1761 #ifdef HAVE_GETHOSTNAME |
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1762 static char get_system_name_name[256]; |
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1763 #else /* not HAVE_GETHOSTNAME */ |
491 | 1764 static struct utsname get_system_name_name; |
1496
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1765 #endif /* not HAVE_GETHOSTNAME */ |
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1766 #endif /* USG */ |
491 | 1767 |
3150
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1768 #ifndef BSD4_1 |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1769 #ifndef USG |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1770 #ifndef VMS |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1771 #ifdef HAVE_SOCKETS |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1772 #include <sys/socket.h> |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1773 #include <netdb.h> |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1774 #endif /* HAVE_SOCKETS */ |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1775 #endif /* not VMS */ |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1776 #endif /* not USG */ |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1777 #endif /* not BSD4_1 */ |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1778 |
491 | 1779 char * |
1780 get_system_name () | |
1781 { | |
1782 #ifdef USG | |
1496
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1783 #ifdef HAVE_GETHOSTNAME |
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1784 gethostname (get_system_name_name, sizeof (get_system_name_name)); |
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1785 return get_system_name_name; |
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1786 #else /* not HAVE_GETHOSTNAME */ |
491 | 1787 uname (&get_system_name_name); |
1788 return (get_system_name_name.nodename); | |
1496
f9010847a5f5
(get_system_name): Use gethostname for USG systems
Richard M. Stallman <rms@gnu.org>
parents:
1203
diff
changeset
|
1789 #endif /* not HAVE_GETHOSTNAME */ |
491 | 1790 #else /* Not USG */ |
1791 #ifdef BSD4_1 | |
1792 return sysname; | |
1793 #else /* not USG, not 4.1 */ | |
1794 static char system_name_saved[32]; | |
1795 #ifdef VMS | |
1796 char *sp; | |
1797 if ((sp = egetenv ("SYS$NODE")) == 0) | |
1798 sp = "vax-vms"; | |
1799 else | |
1800 { | |
1801 char *end; | |
1802 | |
1803 if ((end = index (sp, ':')) != 0) | |
1804 *end = '\0'; | |
1805 } | |
1806 strcpy (system_name_saved, sp); | |
1807 #else /* not VMS */ | |
1808 gethostname (system_name_saved, sizeof (system_name_saved)); | |
3150
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1809 #ifdef HAVE_SOCKETS |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1810 /* Turn the hostname into the official, fully-qualified hostname. |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1811 Don't do this if we're going to dump; this can confuse system |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1812 libraries on some machines and make the dumped emacs core dump. */ |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1813 #ifndef CANNOT_DUMP |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1814 if (initialized) |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1815 #endif /* not CANNOT_DUMP */ |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1816 { |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1817 struct hostent *hp; |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1818 hp = gethostbyname (system_name_saved); |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1819 if (hp && strlen (hp->h_name) < sizeof(system_name_saved)) |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1820 strcpy (system_name_saved, hp->h_name); |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1821 } |
afc59d5d30c6
[HAVE_SOCKETS]: Include socket.h, netdb.h.
Richard M. Stallman <rms@gnu.org>
parents:
3106
diff
changeset
|
1822 #endif /* HAVE_SOCKETS */ |
491 | 1823 #endif /* not VMS */ |
1824 return system_name_saved; | |
1825 #endif /* not USG, not 4.1 */ | |
1826 #endif /* not USG */ | |
1827 } | |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1828 |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1829 #ifdef VMS |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1830 #ifndef HAVE_GETHOSTNAME |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1831 void gethostname(buf, len) |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1832 char *buf; |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1833 int len; |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1834 { |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1835 char *s; |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1836 s = getenv ("SYS$NODE"); |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1837 if (s == NULL) |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1838 buf[0] = '\0'; |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1839 else { |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1840 strncpy (buf, s, len - 2); |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1841 buf[len - 1] = '\0'; |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1842 } /* else */ |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1843 } /* static void gethostname */ |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1844 #endif /* ! HAVE_GETHOSTNAME */ |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1845 #endif /* VMS */ |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
1846 |
491 | 1847 |
1848 #ifndef VMS | |
1849 #ifndef HAVE_SELECT | |
1850 | |
1851 #ifdef HAVE_X_WINDOWS | |
1852 /* Cause explanatory error message at compile time, | |
1853 since the select emulation is not good enough for X. */ | |
1854 int *x = &x_windows_lose_if_no_select_system_call; | |
1855 #endif | |
1856 | |
1857 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs | |
1858 * Only checks read descriptors. | |
1859 */ | |
1860 /* How long to wait between checking fds in select */ | |
1861 #define SELECT_PAUSE 1 | |
1862 int select_alarmed; | |
1863 | |
1864 /* For longjmp'ing back to read_input_waiting. */ | |
1865 | |
1866 jmp_buf read_alarm_throw; | |
1867 | |
1868 /* Nonzero if the alarm signal should throw back to read_input_waiting. | |
1869 The read_socket_hook function sets this to 1 while it is waiting. */ | |
1870 | |
1871 int read_alarm_should_throw; | |
1872 | |
1873 SIGTYPE | |
1874 select_alarm () | |
1875 { | |
1876 select_alarmed = 1; | |
1877 #ifdef BSD4_1 | |
1878 sigrelse (SIGALRM); | |
1879 #else /* not BSD4_1 */ | |
1880 signal (SIGALRM, SIG_IGN); | |
1881 #endif /* not BSD4_1 */ | |
1882 if (read_alarm_should_throw) | |
1883 longjmp (read_alarm_throw, 1); | |
1884 } | |
1885 | |
1886 /* Only rfds are checked. */ | |
1887 int | |
1888 select (nfds, rfds, wfds, efds, timeout) | |
1889 int nfds; | |
1890 int *rfds, *wfds, *efds, *timeout; | |
1891 { | |
1892 int ravail = 0, orfds = 0, old_alarm; | |
1893 int timeoutval = timeout ? *timeout : 100000; | |
1894 int *local_timeout = &timeoutval; | |
1895 extern int proc_buffered_char[]; | |
1896 #ifndef subprocesses | |
1897 int process_tick = 0, update_tick = 0; | |
1898 #else | |
1899 extern int process_tick, update_tick; | |
1900 #endif | |
1901 SIGTYPE (*old_trap) (); | |
1902 unsigned char buf; | |
1903 | |
1904 if (rfds) | |
1905 { | |
1906 orfds = *rfds; | |
1907 *rfds = 0; | |
1908 } | |
1909 if (wfds) | |
1910 *wfds = 0; | |
1911 if (efds) | |
1912 *efds = 0; | |
1913 | |
1914 /* If we are looking only for the terminal, with no timeout, | |
1915 just read it and wait -- that's more efficient. */ | |
1916 if (orfds == 1 && *local_timeout == 100000 && process_tick == update_tick) | |
1917 { | |
1918 if (! detect_input_pending ()) | |
1919 read_input_waiting (); | |
1920 *rfds = 1; | |
1921 return 1; | |
1922 } | |
1923 | |
1924 /* Once a second, till the timer expires, check all the flagged read | |
1925 * descriptors to see if any input is available. If there is some then | |
1926 * set the corresponding bit in the return copy of rfds. | |
1927 */ | |
1928 while (1) | |
1929 { | |
1930 register int to_check, bit, fd; | |
1931 | |
1932 if (rfds) | |
1933 { | |
1934 for (to_check = nfds, bit = 1, fd = 0; --to_check >= 0; bit <<= 1, fd++) | |
1935 { | |
1936 if (orfds & bit) | |
1937 { | |
1938 int avail = 0, status = 0; | |
1939 | |
1940 if (bit == 1) | |
1941 avail = detect_input_pending (); /* Special keyboard handler */ | |
1942 else | |
1943 { | |
1944 #ifdef FIONREAD | |
1945 status = ioctl (fd, FIONREAD, &avail); | |
1946 #else /* no FIONREAD */ | |
1947 /* Hoping it will return -1 if nothing available | |
1948 or 0 if all 0 chars requested are read. */ | |
1949 if (proc_buffered_char[fd] >= 0) | |
1950 avail = 1; | |
1951 else | |
1952 { | |
1953 avail = read (fd, &buf, 1); | |
1954 if (avail > 0) | |
1955 proc_buffered_char[fd] = buf; | |
1956 } | |
1957 #endif /* no FIONREAD */ | |
1958 } | |
1959 if (status >= 0 && avail > 0) | |
1960 { | |
1961 (*rfds) |= bit; | |
1962 ravail++; | |
1963 } | |
1964 } | |
1965 } | |
1966 } | |
1967 if (*local_timeout == 0 || ravail != 0 || process_tick != update_tick) | |
1968 break; | |
1969 old_alarm = alarm (0); | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
1970 old_trap = signal (SIGALRM, select_alarm); |
491 | 1971 select_alarmed = 0; |
1972 alarm (SELECT_PAUSE); | |
1973 /* Wait for a SIGALRM (or maybe a SIGTINT) */ | |
1974 while (select_alarmed == 0 && *local_timeout != 0 | |
1975 && process_tick == update_tick) | |
1976 { | |
1977 /* If we are interested in terminal input, | |
1978 wait by reading the terminal. | |
1979 That makes instant wakeup for terminal input at least. */ | |
1980 if (orfds & 1) | |
1981 { | |
1982 read_input_waiting (); | |
1983 if (detect_input_pending ()) | |
1984 select_alarmed = 1; | |
1985 } | |
1986 else | |
1987 pause (); | |
1988 } | |
1989 (*local_timeout) -= SELECT_PAUSE; | |
1990 /* Reset the old alarm if there was one */ | |
1991 alarm (0); | |
1992 signal (SIGALRM, old_trap); | |
1993 if (old_alarm != 0) | |
1994 { | |
1995 /* Reset or forge an interrupt for the original handler. */ | |
1996 old_alarm -= SELECT_PAUSE; | |
1997 if (old_alarm <= 0) | |
1998 kill (getpid (), SIGALRM); /* Fake an alarm with the orig' handler */ | |
1999 else | |
2000 alarm (old_alarm); | |
2001 } | |
2002 if (*local_timeout == 0) /* Stop on timer being cleared */ | |
2003 break; | |
2004 } | |
2005 return ravail; | |
2006 } | |
2007 | |
2008 /* Read keyboard input into the standard buffer, | |
2009 waiting for at least one character. */ | |
2010 | |
2011 /* Make all keyboard buffers much bigger when using X windows. */ | |
2012 #ifdef HAVE_X_WINDOWS | |
2013 #define BUFFER_SIZE_FACTOR 16 | |
2014 #else | |
2015 #define BUFFER_SIZE_FACTOR 1 | |
2016 #endif | |
2017 | |
2018 read_input_waiting () | |
2019 { | |
2020 char buf[256 * BUFFER_SIZE_FACTOR]; | |
2021 struct input_event e; | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
2022 int nread, i; |
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
2023 extern int quit_char; |
491 | 2024 |
2025 if (read_socket_hook) | |
2026 { | |
2027 read_alarm_should_throw = 0; | |
2028 if (! setjmp (read_alarm_throw)) | |
2029 nread = (*read_socket_hook) (0, buf, 256 * BUFFER_SIZE_FACTOR, 1, 0); | |
2030 else | |
2031 nread = -1; | |
2032 } | |
2033 else | |
2034 nread = read (fileno (stdin), buf, 1); | |
2035 | |
2036 /* Scan the chars for C-g and store them in kbd_buffer. */ | |
2037 e.kind = ascii_keystroke; | |
2121
ebc56bb13048
* sysdep.c (read_input_waiting): Set e.frame_or_window, not
Jim Blandy <jimb@redhat.com>
parents:
1927
diff
changeset
|
2038 e.frame_or_window = selected_frame; |
2589
5f41134610a6
(read_pending_input): Fix the garbaged-modifiers bug under System Vs previous
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2439
diff
changeset
|
2039 e.modifiers = 0; |
491 | 2040 for (i = 0; i < nread; i++) |
2041 { | |
2042 XSET (e.code, Lisp_Int, buf[i]); | |
2043 kbd_buffer_store_event (&e); | |
2044 /* Don't look at input that follows a C-g too closely. | |
2045 This reduces lossage due to autorepeat on C-g. */ | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
2046 if (buf[i] == quit_char) |
491 | 2047 break; |
2048 } | |
2049 } | |
2050 | |
2051 #endif /* not HAVE_SELECT */ | |
2052 #endif /* not VMS */ | |
2053 | |
2054 #ifdef BSD4_1 | |
2055 /* | |
2056 * Partially emulate 4.2 open call. | |
2057 * open is defined as this in 4.1. | |
2058 * | |
2059 * - added by Michael Bloom @ Citicorp/TTI | |
2060 * | |
2061 */ | |
2062 | |
2063 int | |
2064 sys_open (path, oflag, mode) | |
2065 char *path; | |
2066 int oflag, mode; | |
2067 { | |
2068 if (oflag & O_CREAT) | |
2069 return creat (path, mode); | |
2070 else | |
2071 return open (path, oflag); | |
2072 } | |
2073 | |
2074 init_sigio () | |
2075 { | |
2076 if (noninteractive) | |
2077 return; | |
2078 lmode = LINTRUP | lmode; | |
2079 ioctl (0, TIOCLSET, &lmode); | |
2080 } | |
2081 | |
2082 reset_sigio () | |
2083 { | |
2084 if (noninteractive) | |
2085 return; | |
2086 lmode = ~LINTRUP & lmode; | |
2087 ioctl (0, TIOCLSET, &lmode); | |
2088 } | |
2089 | |
2090 request_sigio () | |
2091 { | |
2092 sigrelse (SIGTINT); | |
2093 | |
2094 interrupts_deferred = 0; | |
2095 } | |
2096 | |
2097 unrequest_sigio () | |
2098 { | |
2099 sighold (SIGTINT); | |
2100 | |
2101 interrupts_deferred = 1; | |
2102 } | |
2103 | |
2104 /* still inside #ifdef BSD4_1 */ | |
2105 #ifdef subprocesses | |
2106 | |
2107 int sigheld; /* Mask of held signals */ | |
2108 | |
2109 sigholdx (signum) | |
2110 int signum; | |
2111 { | |
2112 sigheld |= sigbit (signum); | |
2113 sighold (signum); | |
2114 } | |
2115 | |
2116 sigisheld (signum) | |
2117 int signum; | |
2118 { | |
2119 sigheld |= sigbit (signum); | |
2120 } | |
2121 | |
2122 sigunhold (signum) | |
2123 int signum; | |
2124 { | |
2125 sigheld &= ~sigbit (signum); | |
2126 sigrelse (signum); | |
2127 } | |
2128 | |
2129 sigfree () /* Free all held signals */ | |
2130 { | |
2131 int i; | |
2132 for (i = 0; i < NSIG; i++) | |
2133 if (sigheld & sigbit (i)) | |
2134 sigrelse (i); | |
2135 sigheld = 0; | |
2136 } | |
2137 | |
2138 sigbit (i) | |
2139 { | |
2140 return 1 << (i - 1); | |
2141 } | |
2142 #endif /* subprocesses */ | |
2143 #endif /* BSD4_1 */ | |
2144 | |
2145 /* POSIX signals support - DJB */ | |
2146 /* Anyone with POSIX signals should have ANSI C declarations */ | |
2147 | |
2148 #ifdef POSIX_SIGNALS | |
2149 | |
2150 sigset_t old_mask, empty_mask, full_mask, temp_mask; | |
2151 static struct sigaction new_action, old_action; | |
2152 | |
2153 init_signals () | |
2154 { | |
2913
409c1022bad5
Some changes from Michael K. Johnson for Linux.
Jim Blandy <jimb@redhat.com>
parents:
2873
diff
changeset
|
2155 sigemptyset (&empty_mask); |
409c1022bad5
Some changes from Michael K. Johnson for Linux.
Jim Blandy <jimb@redhat.com>
parents:
2873
diff
changeset
|
2156 sigfillset (&full_mask); |
491 | 2157 } |
2158 | |
2159 signal_handler_t | |
2160 sys_signal (int signal_number, signal_handler_t action) | |
2161 { | |
2162 #ifdef DGUX | |
2163 /* This gets us restartable system calls for efficiency. | |
2164 The "else" code will works as well. */ | |
2165 return (berk_signal (signal_number, action)); | |
2166 #else | |
2167 sigemptyset (&new_action.sa_mask); | |
2168 new_action.sa_handler = action; | |
3292
6209d0e98e35
(sys_signal): Use 0, not NULL, to set sa_flags.
Richard M. Stallman <rms@gnu.org>
parents:
3268
diff
changeset
|
2169 new_action.sa_flags = 0; |
709 | 2170 sigaction (signal_number, &new_action, &old_action); |
491 | 2171 return (old_action.sa_handler); |
2172 #endif /* DGUX */ | |
2173 } | |
2174 | |
638 | 2175 #ifndef __GNUC__ |
2176 /* If we're compiling with GCC, we don't need this function, since it | |
2177 can be written as a macro. */ | |
2178 sigset_t | |
2179 sys_sigmask (int sig) | |
2180 { | |
2181 sigset_t mask; | |
2182 sigemptyset (&mask); | |
2183 sigaddset (&mask, sig); | |
2184 return mask; | |
2185 } | |
2186 #endif | |
2187 | |
491 | 2188 int |
2189 sys_sigpause (sigset_t new_mask) | |
2190 { | |
2191 /* pause emulating berk sigpause... */ | |
2192 sigsuspend (&new_mask); | |
2193 return (EINTR); | |
2194 } | |
2195 | |
2196 /* I'd like to have these guys return pointers to the mask storage in here, | |
2197 but there'd be trouble if the code was saving multiple masks. I'll be | |
2198 safe and pass the structure. It normally won't be more than 2 bytes | |
2199 anyhow. - DJB */ | |
2200 | |
2201 sigset_t | |
2202 sys_sigblock (sigset_t new_mask) | |
2203 { | |
2204 sigset_t old_mask; | |
2205 sigprocmask (SIG_BLOCK, &new_mask, &old_mask); | |
2206 return (old_mask); | |
2207 } | |
2208 | |
2209 sigset_t | |
2210 sys_sigunblock (sigset_t new_mask) | |
2211 { | |
2212 sigset_t old_mask; | |
2213 sigprocmask (SIG_UNBLOCK, &new_mask, &old_mask); | |
2214 return (old_mask); | |
2215 } | |
2216 | |
2217 sigset_t | |
2218 sys_sigsetmask (sigset_t new_mask) | |
2219 { | |
2220 sigset_t old_mask; | |
2221 sigprocmask (SIG_SETMASK, &new_mask, &old_mask); | |
2222 return (old_mask); | |
2223 } | |
2224 | |
2225 #endif /* POSIX_SIGNALS */ | |
2226 | |
2227 #ifndef BSTRING | |
2228 | |
2229 void | |
2230 bzero (b, length) | |
2231 register char *b; | |
2232 register int length; | |
2233 { | |
2234 #ifdef VMS | |
2235 short zero = 0; | |
2236 long max_str = 65535; | |
2237 | |
2238 while (length > max_str) { | |
2239 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b); | |
2240 length -= max_str; | |
2241 b += max_str; | |
2242 } | |
2243 max_str = length; | |
2244 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b); | |
2245 #else | |
2246 while (length-- > 0) | |
2247 *b++ = 0; | |
2248 #endif /* not VMS */ | |
2249 } | |
2250 | |
2251 /* Saying `void' requires a declaration, above, where bcopy is used | |
2252 and that declaration causes pain for systems where bcopy is a macro. */ | |
2253 bcopy (b1, b2, length) | |
2254 register char *b1; | |
2255 register char *b2; | |
2256 register int length; | |
2257 { | |
2258 #ifdef VMS | |
2259 long max_str = 65535; | |
2260 | |
2261 while (length > max_str) { | |
2262 (void) LIB$MOVC3 (&max_str, b1, b2); | |
2263 length -= max_str; | |
2264 b1 += max_str; | |
2265 b2 += max_str; | |
2266 } | |
2267 max_str = length; | |
2268 (void) LIB$MOVC3 (&length, b1, b2); | |
2269 #else | |
2270 while (length-- > 0) | |
2271 *b2++ = *b1++; | |
2272 #endif /* not VMS */ | |
2273 } | |
2274 | |
2275 int | |
2276 bcmp (b1, b2, length) /* This could be a macro! */ | |
2277 register char *b1; | |
2278 register char *b2; | |
2279 register int length; | |
2280 { | |
2281 #ifdef VMS | |
2282 struct dsc$descriptor_s src1 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b1}; | |
2283 struct dsc$descriptor_s src2 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b2}; | |
2284 | |
2285 return STR$COMPARE (&src1, &src2); | |
2286 #else | |
2287 while (length-- > 0) | |
2288 if (*b1++ != *b2++) | |
2289 return 1; | |
2290 | |
2291 return 0; | |
2292 #endif /* not VMS */ | |
2293 } | |
2294 #endif /* not BSTRING */ | |
2295 | |
2332
bc2f7dc78412
* sysdep.c (random, srandom): Don't define these if HAVE_RANDOM is
Jim Blandy <jimb@redhat.com>
parents:
2287
diff
changeset
|
2296 #ifndef HAVE_RANDOM |
491 | 2297 #ifdef USG |
2298 /* | |
2299 * The BSD random returns numbers in the range of | |
2300 * 0 to 2e31 - 1. The USG rand returns numbers in the | |
2301 * range of 0 to 2e15 - 1. This is probably not significant | |
2302 * in this usage. | |
2303 */ | |
2304 | |
2305 long | |
2306 random () | |
2307 { | |
2308 /* Arrange to return a range centered on zero. */ | |
2309 return (rand () << 15) + rand () - (1 << 29); | |
2310 } | |
2311 | |
2312 srandom (arg) | |
2313 int arg; | |
2314 { | |
2315 srand (arg); | |
2316 } | |
2317 | |
2318 #endif /* USG */ | |
2319 | |
2320 #ifdef BSD4_1 | |
2321 long random () | |
2322 { | |
2323 /* Arrange to return a range centered on zero. */ | |
2324 return (rand () << 15) + rand () - (1 << 29); | |
2325 } | |
2326 | |
2327 srandom (arg) | |
2328 int arg; | |
2329 { | |
2330 srand (arg); | |
2331 } | |
2332 #endif /* BSD4_1 */ | |
2332
bc2f7dc78412
* sysdep.c (random, srandom): Don't define these if HAVE_RANDOM is
Jim Blandy <jimb@redhat.com>
parents:
2287
diff
changeset
|
2333 #endif |
491 | 2334 |
2335 #ifdef WRONG_NAME_INSQUE | |
2336 | |
2337 insque (q,p) | |
2338 caddr_t q,p; | |
2339 { | |
2340 _insque (q,p); | |
2341 } | |
2342 | |
2343 #endif | |
2344 | |
2345 #ifdef VMS | |
2346 | |
2347 #ifdef getenv | |
2348 /* If any place else asks for the TERM variable, | |
2349 allow it to be overridden with the EMACS_TERM variable | |
2350 before attempting to translate the logical name TERM. As a last | |
2351 resort, ask for VAX C's special idea of the TERM variable. */ | |
2352 #undef getenv | |
2353 char * | |
2354 sys_getenv (name) | |
2355 char *name; | |
2356 { | |
2357 register char *val; | |
2358 static char buf[256]; | |
2359 static struct dsc$descriptor_s equiv | |
2360 = {sizeof (buf), DSC$K_DTYPE_T, DSC$K_CLASS_S, buf}; | |
2361 static struct dsc$descriptor_s d_name | |
2362 = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0}; | |
2363 short eqlen; | |
2364 | |
2365 if (!strcmp (name, "TERM")) | |
2366 { | |
2367 val = (char *) getenv ("EMACS_TERM"); | |
2368 if (val) | |
2369 return val; | |
2370 } | |
2371 | |
2372 d_name.dsc$w_length = strlen (name); | |
2373 d_name.dsc$a_pointer = name; | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
2374 if (LIB$SYS_TRNLOG (&d_name, &eqlen, &equiv) == 1) |
491 | 2375 { |
2376 char *str = (char *) xmalloc (eqlen + 1); | |
2377 bcopy (buf, str, eqlen); | |
2378 str[eqlen] = '\0'; | |
2379 /* This is a storage leak, but a pain to fix. With luck, | |
2380 no one will ever notice. */ | |
2381 return str; | |
2382 } | |
2383 return (char *) getenv (name); | |
2384 } | |
2385 #endif /* getenv */ | |
2386 | |
2387 #ifdef abort | |
2388 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is | |
2389 to force a call on the debugger from within the image. */ | |
2390 #undef abort | |
2391 sys_abort () | |
2392 { | |
2393 reset_sys_modes (); | |
2394 LIB$SIGNAL (SS$_DEBUG); | |
2395 } | |
2396 #endif /* abort */ | |
2397 #endif /* VMS */ | |
2398 | |
2399 #ifdef VMS | |
2400 #ifdef LINK_CRTL_SHARE | |
2401 #ifdef SHAREABLE_LIB_BUG | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
2402 /* Variables declared noshare and initialized in sharable libraries |
491 | 2403 cannot be shared. The VMS linker incorrectly forces you to use a private |
2404 version which is uninitialized... If not for this "feature", we | |
2405 could use the C library definition of sys_nerr and sys_errlist. */ | |
2406 int sys_nerr = 35; | |
2407 char *sys_errlist[] = | |
2408 { | |
2409 "error 0", | |
2410 "not owner", | |
2411 "no such file or directory", | |
2412 "no such process", | |
2413 "interrupted system call", | |
2414 "i/o error", | |
2415 "no such device or address", | |
2416 "argument list too long", | |
2417 "exec format error", | |
2418 "bad file number", | |
2419 "no child process", | |
2420 "no more processes", | |
2421 "not enough memory", | |
2422 "permission denied", | |
2423 "bad address", | |
2424 "block device required", | |
2425 "mount devices busy", | |
2426 "file exists", | |
2427 "cross-device link", | |
2428 "no such device", | |
2429 "not a directory", | |
2430 "is a directory", | |
2431 "invalid argument", | |
2432 "file table overflow", | |
2433 "too many open files", | |
2434 "not a typewriter", | |
2435 "text file busy", | |
2436 "file too big", | |
2437 "no space left on device", | |
2438 "illegal seek", | |
2439 "read-only file system", | |
2440 "too many links", | |
2441 "broken pipe", | |
2442 "math argument", | |
2443 "result too large", | |
2444 "I/O stream empty", | |
2445 "vax/vms specific error code nontranslatable error" | |
2446 }; | |
2447 #endif /* SHAREABLE_LIB_BUG */ | |
2448 #endif /* LINK_CRTL_SHARE */ | |
2449 #endif /* VMS */ | |
2450 | |
2451 #ifdef INTERRUPTIBLE_OPEN | |
2452 | |
2453 int | |
2454 /* VARARGS 2 */ | |
2455 sys_open (path, oflag, mode) | |
2456 char *path; | |
2457 int oflag, mode; | |
2458 { | |
2459 register int rtnval; | |
2460 | |
2461 while ((rtnval = open (path, oflag, mode)) == -1 | |
2462 && (errno == EINTR)); | |
2463 return (rtnval); | |
2464 } | |
2465 | |
2466 #endif /* INTERRUPTIBLE_OPEN */ | |
2467 | |
2468 #ifdef INTERRUPTIBLE_CLOSE | |
2469 | |
2470 sys_close (fd) | |
2471 int fd; | |
2472 { | |
2473 register int rtnval; | |
2474 | |
2475 while ((rtnval = close (fd)) == -1 | |
2476 && (errno == EINTR)); | |
2477 return rtnval; | |
2478 } | |
2479 | |
2480 #endif /* INTERRUPTIBLE_CLOSE */ | |
2481 | |
2482 #ifdef INTERRUPTIBLE_IO | |
2483 | |
2484 int | |
2485 sys_read (fildes, buf, nbyte) | |
2486 int fildes; | |
2487 char *buf; | |
2488 unsigned int nbyte; | |
2489 { | |
2490 register int rtnval; | |
2491 | |
2492 while ((rtnval = read (fildes, buf, nbyte)) == -1 | |
2493 && (errno == EINTR)); | |
2494 return (rtnval); | |
2495 } | |
2496 | |
2497 int | |
2498 sys_write (fildes, buf, nbyte) | |
2499 int fildes; | |
2500 char *buf; | |
2501 unsigned int nbyte; | |
2502 { | |
2503 register int rtnval; | |
2504 | |
2505 while ((rtnval = write (fildes, buf, nbyte)) == -1 | |
2506 && (errno == EINTR)); | |
2507 return (rtnval); | |
2508 } | |
2509 | |
2510 #endif /* INTERRUPTIBLE_IO */ | |
2511 | |
2512 #ifdef USG | |
2513 /* | |
2514 * All of the following are for USG. | |
2515 * | |
2516 * On USG systems the system calls are INTERRUPTIBLE by signals | |
2517 * that the user program has elected to catch. Thus the system call | |
2518 * must be retried in these cases. To handle this without massive | |
2519 * changes in the source code, we remap the standard system call names | |
2520 * to names for our own functions in sysdep.c that do the system call | |
2521 * with retries. Actually, for portability reasons, it is good | |
2522 * programming practice, as this example shows, to limit all actual | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
2523 * system calls to a single occurrence in the source. Sure, this |
491 | 2524 * adds an extra level of function call overhead but it is almost |
2525 * always negligible. Fred Fish, Unisoft Systems Inc. | |
2526 */ | |
2527 | |
2913
409c1022bad5
Some changes from Michael K. Johnson for Linux.
Jim Blandy <jimb@redhat.com>
parents:
2873
diff
changeset
|
2528 #ifndef HAVE_SYS_SIGLIST |
491 | 2529 char *sys_siglist[NSIG + 1] = |
2530 { | |
2531 #ifdef AIX | |
2532 /* AIX has changed the signals a bit */ | |
2533 "bogus signal", /* 0 */ | |
2534 "hangup", /* 1 SIGHUP */ | |
2535 "interrupt", /* 2 SIGINT */ | |
2536 "quit", /* 3 SIGQUIT */ | |
2537 "illegal instruction", /* 4 SIGILL */ | |
2538 "trace trap", /* 5 SIGTRAP */ | |
2539 "IOT instruction", /* 6 SIGIOT */ | |
2540 "crash likely", /* 7 SIGDANGER */ | |
2541 "floating point exception", /* 8 SIGFPE */ | |
2542 "kill", /* 9 SIGKILL */ | |
2543 "bus error", /* 10 SIGBUS */ | |
2544 "segmentation violation", /* 11 SIGSEGV */ | |
2545 "bad argument to system call", /* 12 SIGSYS */ | |
2546 "write on a pipe with no one to read it", /* 13 SIGPIPE */ | |
2547 "alarm clock", /* 14 SIGALRM */ | |
2548 "software termination signum", /* 15 SIGTERM */ | |
2549 "user defined signal 1", /* 16 SIGUSR1 */ | |
2550 "user defined signal 2", /* 17 SIGUSR2 */ | |
2551 "death of a child", /* 18 SIGCLD */ | |
2552 "power-fail restart", /* 19 SIGPWR */ | |
2553 "bogus signal", /* 20 */ | |
2554 "bogus signal", /* 21 */ | |
2555 "bogus signal", /* 22 */ | |
2556 "bogus signal", /* 23 */ | |
2557 "bogus signal", /* 24 */ | |
2558 "LAN I/O interrupt", /* 25 SIGAIO */ | |
2559 "PTY I/O interrupt", /* 26 SIGPTY */ | |
2560 "I/O intervention required", /* 27 SIGIOINT */ | |
2561 "HFT grant", /* 28 SIGGRANT */ | |
2562 "HFT retract", /* 29 SIGRETRACT */ | |
2563 "HFT sound done", /* 30 SIGSOUND */ | |
2564 "HFT input ready", /* 31 SIGMSG */ | |
2565 #else /* not AIX */ | |
2566 "bogus signal", /* 0 */ | |
2567 "hangup", /* 1 SIGHUP */ | |
2568 "interrupt", /* 2 SIGINT */ | |
2569 "quit", /* 3 SIGQUIT */ | |
2570 "illegal instruction", /* 4 SIGILL */ | |
2571 "trace trap", /* 5 SIGTRAP */ | |
2572 "IOT instruction", /* 6 SIGIOT */ | |
2573 "EMT instruction", /* 7 SIGEMT */ | |
2574 "floating point exception", /* 8 SIGFPE */ | |
2575 "kill", /* 9 SIGKILL */ | |
2576 "bus error", /* 10 SIGBUS */ | |
2577 "segmentation violation", /* 11 SIGSEGV */ | |
2578 "bad argument to system call", /* 12 SIGSYS */ | |
2579 "write on a pipe with no one to read it", /* 13 SIGPIPE */ | |
2580 "alarm clock", /* 14 SIGALRM */ | |
2581 "software termination signum", /* 15 SIGTERM */ | |
2582 "user defined signal 1", /* 16 SIGUSR1 */ | |
2583 "user defined signal 2", /* 17 SIGUSR2 */ | |
2584 "death of a child", /* 18 SIGCLD */ | |
2585 "power-fail restart", /* 19 SIGPWR */ | |
2586 #endif /* not AIX */ | |
2587 0 | |
2588 }; | |
3268
760a82a8767e
* sysdep.c (sys_siglist): Comment out #endif trailer.
Jim Blandy <jimb@redhat.com>
parents:
3239
diff
changeset
|
2589 #endif /* HAVE_SYS_SIGLIST */ |
491 | 2590 |
2591 /* | |
2592 * Warning, this function may not duplicate 4.2 action properly | |
2593 * under error conditions. | |
2594 */ | |
2595 | |
2596 #ifndef MAXPATHLEN | |
2597 /* In 4.1, param.h fails to define this. */ | |
2598 #define MAXPATHLEN 1024 | |
2599 #endif | |
2600 | |
2601 #ifndef HAVE_GETWD | |
2602 | |
2603 char * | |
2604 getwd (pathname) | |
2605 char *pathname; | |
2606 { | |
2607 char *npath, *spath; | |
2608 extern char *getcwd (); | |
2609 | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
2610 BLOCK_INPUT; /* getcwd uses malloc */ |
491 | 2611 spath = npath = getcwd ((char *) 0, MAXPATHLEN); |
2612 /* On Altos 3068, getcwd can return @hostname/dir, so discard | |
2613 up to first slash. Should be harmless on other systems. */ | |
2614 while (*npath && *npath != '/') | |
2615 npath++; | |
2616 strcpy (pathname, npath); | |
2617 free (spath); /* getcwd uses malloc */ | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
2618 UNBLOCK_INPUT; |
491 | 2619 return pathname; |
2620 } | |
2621 | |
2622 #endif /* HAVE_GETWD */ | |
2623 | |
2624 /* | |
2625 * Emulate rename using unlink/link. Note that this is | |
2626 * only partially correct. Also, doesn't enforce restriction | |
2627 * that files be of same type (regular->regular, dir->dir, etc). | |
2628 */ | |
2629 | |
621 | 2630 #ifndef HAVE_RENAME |
2631 | |
491 | 2632 rename (from, to) |
2633 char *from; | |
2634 char *to; | |
2635 { | |
2636 if (access (from, 0) == 0) | |
2637 { | |
2638 unlink (to); | |
2639 if (link (from, to) == 0) | |
2640 if (unlink (from) == 0) | |
2641 return (0); | |
2642 } | |
2643 return (-1); | |
2644 } | |
2645 | |
621 | 2646 #endif |
2647 | |
491 | 2648 #ifndef HAVE_VFORK |
2649 | |
2650 /* | |
2651 * Substitute fork for vfork on USG flavors. | |
2652 */ | |
2653 | |
2654 vfork () | |
2655 { | |
2656 return (fork ()); | |
2657 } | |
2658 | |
2659 #endif /* not HAVE_VFORK */ | |
2660 | |
2661 #ifdef MISSING_UTIMES | |
2662 | |
2663 /* HPUX (among others) sets HAVE_TIMEVAL but does not implement utimes. */ | |
2664 | |
2665 utimes () | |
2666 { | |
2667 } | |
2668 #endif | |
2669 | |
2670 #ifdef IRIS_UTIME | |
2671 | |
2672 /* The IRIS (3.5) has timevals, but uses sys V utime, and doesn't have the | |
2673 utimbuf structure defined anywhere but in the man page. */ | |
2674 | |
2675 struct utimbuf | |
2676 { | |
2677 long actime; | |
2678 long modtime; | |
2679 }; | |
2680 | |
2681 utimes (name, tvp) | |
2682 char *name; | |
2683 struct timeval tvp[]; | |
2684 { | |
2685 struct utimbuf utb; | |
2686 utb.actime = tvp[0].tv_sec; | |
2687 utb.modtime = tvp[1].tv_sec; | |
2688 utime (name, &utb); | |
2689 } | |
2690 #endif /* IRIS_UTIME */ | |
2691 | |
2692 | |
2693 #ifdef HPUX | |
2694 #ifndef HAVE_PERROR | |
2695 | |
2696 /* HPUX curses library references perror, but as far as we know | |
2697 it won't be called. Anyway this definition will do for now. */ | |
2698 | |
2699 perror () | |
2700 { | |
2701 } | |
2702 | |
2703 #endif /* not HAVE_PERROR */ | |
2704 #endif /* HPUX */ | |
2705 | |
2706 #ifndef HAVE_DUP2 | |
2707 | |
2708 /* | |
2709 * Emulate BSD dup2. First close newd if it already exists. | |
2710 * Then, attempt to dup oldd. If not successful, call dup2 recursively | |
2711 * until we are, then close the unsuccessful ones. | |
2712 */ | |
2713 | |
2714 dup2 (oldd, newd) | |
2715 int oldd; | |
2716 int newd; | |
2717 { | |
2718 register int fd, ret; | |
2719 | |
2720 sys_close (newd); | |
2721 | |
2722 #ifdef F_DUPFD | |
2723 fd = fcntl (oldd, F_DUPFD, newd); | |
2724 if (fd != newd) | |
2725 error ("can't dup2 (%i,%i) : %s", oldd, newd, sys_errlist[errno]); | |
2726 #else | |
2727 fd = dup (old); | |
2728 if (fd == -1) | |
2729 return -1; | |
2730 if (fd == new) | |
2731 return new; | |
2732 ret = dup2 (old,new); | |
2733 sys_close (fd); | |
2734 return ret; | |
2735 #endif | |
2736 } | |
2737 | |
2738 #endif /* not HAVE_DUP2 */ | |
2739 | |
2740 /* | |
2741 * Gettimeofday. Simulate as much as possible. Only accurate | |
2742 * to nearest second. Emacs doesn't use tzp so ignore it for now. | |
2743 * Only needed when subprocesses are defined. | |
2744 */ | |
2745 | |
2746 #ifdef subprocesses | |
2747 #ifndef VMS | |
2748 #ifndef HAVE_GETTIMEOFDAY | |
2749 #ifdef HAVE_TIMEVAL | |
2750 | |
2751 /* ARGSUSED */ | |
2752 gettimeofday (tp, tzp) | |
2753 struct timeval *tp; | |
2754 struct timezone *tzp; | |
2755 { | |
2756 extern long time (); | |
2757 | |
2758 tp->tv_sec = time ((long *)0); | |
2759 tp->tv_usec = 0; | |
3239
2e4882a32671
(gettimeofday): Don't store in *tzp if tzp is 0.
Richard M. Stallman <rms@gnu.org>
parents:
3157
diff
changeset
|
2760 if (tzp != 0) |
2e4882a32671
(gettimeofday): Don't store in *tzp if tzp is 0.
Richard M. Stallman <rms@gnu.org>
parents:
3157
diff
changeset
|
2761 tzp->tz_minuteswest = -1; |
491 | 2762 } |
2763 | |
2764 #endif | |
2765 #endif | |
2766 #endif | |
2767 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */ | |
2768 | |
2769 /* | |
2770 * This function will go away as soon as all the stubs fixed. (fnf) | |
2771 */ | |
2772 | |
2773 croak (badfunc) | |
2774 char *badfunc; | |
2775 { | |
2776 printf ("%s not yet implemented\r\n", badfunc); | |
2777 reset_sys_modes (); | |
2778 exit (1); | |
2779 } | |
2780 | |
2781 #endif /* USG */ | |
2782 | |
2783 #ifdef DGUX | |
2784 | |
2785 char *sys_siglist[NSIG + 1] = | |
2786 { | |
2787 "null signal", /* 0 SIGNULL */ | |
2788 "hangup", /* 1 SIGHUP */ | |
2789 "interrupt", /* 2 SIGINT */ | |
2790 "quit", /* 3 SIGQUIT */ | |
2791 "illegal instruction", /* 4 SIGILL */ | |
2792 "trace trap", /* 5 SIGTRAP */ | |
2793 "abort termination", /* 6 SIGABRT */ | |
2794 "SIGEMT", /* 7 SIGEMT */ | |
2795 "floating point exception", /* 8 SIGFPE */ | |
2796 "kill", /* 9 SIGKILL */ | |
2797 "bus error", /* 10 SIGBUS */ | |
2798 "segmentation violation", /* 11 SIGSEGV */ | |
2799 "bad argument to system call", /* 12 SIGSYS */ | |
2800 "write on a pipe with no reader", /* 13 SIGPIPE */ | |
2801 "alarm clock", /* 14 SIGALRM */ | |
2802 "software termination signal", /* 15 SIGTERM */ | |
2803 "user defined signal 1", /* 16 SIGUSR1 */ | |
2804 "user defined signal 2", /* 17 SIGUSR2 */ | |
2805 "child stopped or terminated", /* 18 SIGCLD */ | |
2806 "power-fail restart", /* 19 SIGPWR */ | |
2807 "window size changed", /* 20 SIGWINCH */ | |
2808 "undefined", /* 21 */ | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
2809 "pollable event occurred", /* 22 SIGPOLL */ |
491 | 2810 "sendable stop signal not from tty", /* 23 SIGSTOP */ |
2811 "stop signal from tty", /* 24 SIGSTP */ | |
2812 "continue a stopped process", /* 25 SIGCONT */ | |
2813 "attempted background tty read", /* 26 SIGTTIN */ | |
2814 "attempted background tty write", /* 27 SIGTTOU */ | |
2815 "undefined", /* 28 */ | |
2816 "undefined", /* 29 */ | |
2817 "undefined", /* 30 */ | |
2818 "undefined", /* 31 */ | |
2819 "undefined", /* 32 */ | |
2820 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */ | |
2821 "I/O is possible", /* 34 SIGIO */ | |
2822 "exceeded cpu time limit", /* 35 SIGXCPU */ | |
2823 "exceeded file size limit", /* 36 SIGXFSZ */ | |
2824 "virtual time alarm", /* 37 SIGVTALRM */ | |
2825 "profiling time alarm", /* 38 SIGPROF */ | |
2826 "undefined", /* 39 */ | |
2827 "file record locks revoked", /* 40 SIGLOST */ | |
2828 "undefined", /* 41 */ | |
2829 "undefined", /* 42 */ | |
2830 "undefined", /* 43 */ | |
2831 "undefined", /* 44 */ | |
2832 "undefined", /* 45 */ | |
2833 "undefined", /* 46 */ | |
2834 "undefined", /* 47 */ | |
2835 "undefined", /* 48 */ | |
2836 "undefined", /* 49 */ | |
2837 "undefined", /* 50 */ | |
2838 "undefined", /* 51 */ | |
2839 "undefined", /* 52 */ | |
2840 "undefined", /* 53 */ | |
2841 "undefined", /* 54 */ | |
2842 "undefined", /* 55 */ | |
2843 "undefined", /* 56 */ | |
2844 "undefined", /* 57 */ | |
2845 "undefined", /* 58 */ | |
2846 "undefined", /* 59 */ | |
2847 "undefined", /* 60 */ | |
2848 "undefined", /* 61 */ | |
2849 "undefined", /* 62 */ | |
2850 "undefined", /* 63 */ | |
2851 "notification message in mess. queue", /* 64 SIGDGNOTIFY */ | |
2852 0 | |
2853 }; | |
2854 | |
2855 #endif /* DGUX */ | |
2856 | |
2857 /* Directory routines for systems that don't have them. */ | |
2858 | |
2859 #ifdef SYSV_SYSTEM_DIR | |
2860 | |
2861 #include <dirent.h> | |
2862 | |
2863 #ifndef AIX | |
2864 int | |
2865 closedir (dirp) | |
2866 register DIR *dirp; /* stream from opendir */ | |
2867 { | |
2868 sys_close (dirp->dd_fd); | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
2869 xfree ((char *) dirp->dd_buf); /* directory block defined in <dirent.h> */ |
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
2870 xfree ((char *) dirp); |
491 | 2871 } |
2872 #endif /* not AIX */ | |
2873 #endif /* SYSV_SYSTEM_DIR */ | |
2874 | |
2875 #ifdef NONSYSTEM_DIR_LIBRARY | |
2876 | |
2877 DIR * | |
2878 opendir (filename) | |
2879 char *filename; /* name of directory */ | |
2880 { | |
2881 register DIR *dirp; /* -> malloc'ed storage */ | |
2882 register int fd; /* file descriptor for read */ | |
2883 struct stat sbuf; /* result of fstat */ | |
2884 | |
2885 fd = sys_open (filename, 0); | |
2886 if (fd < 0) | |
2887 return 0; | |
2888 | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
2889 BLOCK_INPUT; |
491 | 2890 if (fstat (fd, &sbuf) < 0 |
2891 || (sbuf.st_mode & S_IFMT) != S_IFDIR | |
2892 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0) | |
2893 { | |
2894 sys_close (fd); | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
2895 UNBLOCK_INPUT; |
491 | 2896 return 0; /* bad luck today */ |
2897 } | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
2898 UNBLOCK_INPUT; |
491 | 2899 |
2900 dirp->dd_fd = fd; | |
2901 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */ | |
2902 | |
2903 return dirp; | |
2904 } | |
2905 | |
2906 void | |
2907 closedir (dirp) | |
2908 register DIR *dirp; /* stream from opendir */ | |
2909 { | |
2910 sys_close (dirp->dd_fd); | |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
2911 xfree ((char *) dirp); |
491 | 2912 } |
2913 | |
2914 | |
2915 #ifndef VMS | |
2916 #define DIRSIZ 14 | |
2917 struct olddir | |
2918 { | |
2919 ino_t od_ino; /* inode */ | |
2920 char od_name[DIRSIZ]; /* filename */ | |
2921 }; | |
2922 #endif /* not VMS */ | |
2923 | |
2924 struct direct dir_static; /* simulated directory contents */ | |
2925 | |
2926 /* ARGUSED */ | |
2927 struct direct * | |
2928 readdir (dirp) | |
2929 register DIR *dirp; /* stream from opendir */ | |
2930 { | |
2931 #ifndef VMS | |
2932 register struct olddir *dp; /* -> directory data */ | |
2933 #else /* VMS */ | |
2934 register struct dir$_name *dp; /* -> directory data */ | |
2935 register struct dir$_version *dv; /* -> version data */ | |
2936 #endif /* VMS */ | |
2937 | |
2938 for (; ;) | |
2939 { | |
2940 if (dirp->dd_loc >= dirp->dd_size) | |
2941 dirp->dd_loc = dirp->dd_size = 0; | |
2942 | |
2943 if (dirp->dd_size == 0 /* refill buffer */ | |
2944 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0) | |
2945 return 0; | |
2946 | |
2947 #ifndef VMS | |
2948 dp = (struct olddir *) &dirp->dd_buf[dirp->dd_loc]; | |
2949 dirp->dd_loc += sizeof (struct olddir); | |
2950 | |
2951 if (dp->od_ino != 0) /* not deleted entry */ | |
2952 { | |
2953 dir_static.d_ino = dp->od_ino; | |
2954 strncpy (dir_static.d_name, dp->od_name, DIRSIZ); | |
2955 dir_static.d_name[DIRSIZ] = '\0'; | |
2956 dir_static.d_namlen = strlen (dir_static.d_name); | |
2957 dir_static.d_reclen = sizeof (struct direct) | |
2958 - MAXNAMLEN + 3 | |
2959 + dir_static.d_namlen - dir_static.d_namlen % 4; | |
2960 return &dir_static; /* -> simulated structure */ | |
2961 } | |
2962 #else /* VMS */ | |
2963 dp = (struct dir$_name *) dirp->dd_buf; | |
2964 if (dirp->dd_loc == 0) | |
2965 dirp->dd_loc = (dp->dir$b_namecount&1) ? dp->dir$b_namecount + 1 | |
2966 : dp->dir$b_namecount; | |
2967 dv = (struct dir$_version *)&dp->dir$t_name[dirp->dd_loc]; | |
2968 dir_static.d_ino = dv->dir$w_fid_num; | |
2969 dir_static.d_namlen = dp->dir$b_namecount; | |
2970 dir_static.d_reclen = sizeof (struct direct) | |
2971 - MAXNAMLEN + 3 | |
2972 + dir_static.d_namlen - dir_static.d_namlen % 4; | |
2973 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount); | |
2974 dir_static.d_name[dir_static.d_namlen] = '\0'; | |
2975 dirp->dd_loc = dirp->dd_size; /* only one record at a time */ | |
2976 return &dir_static; | |
2977 #endif /* VMS */ | |
2978 } | |
2979 } | |
2980 | |
2981 #ifdef VMS | |
2982 /* readdirver is just like readdir except it returns all versions of a file | |
2983 as separate entries. */ | |
2984 | |
2985 /* ARGUSED */ | |
2986 struct direct * | |
2987 readdirver (dirp) | |
2988 register DIR *dirp; /* stream from opendir */ | |
2989 { | |
2990 register struct dir$_name *dp; /* -> directory data */ | |
2991 register struct dir$_version *dv; /* -> version data */ | |
2992 | |
2993 if (dirp->dd_loc >= dirp->dd_size - sizeof (struct dir$_name)) | |
2994 dirp->dd_loc = dirp->dd_size = 0; | |
2995 | |
2996 if (dirp->dd_size == 0 /* refill buffer */ | |
2997 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0) | |
2998 return 0; | |
2999 | |
3000 dp = (struct dir$_name *) dirp->dd_buf; | |
3001 if (dirp->dd_loc == 0) | |
3002 dirp->dd_loc = (dp->dir$b_namecount & 1) ? dp->dir$b_namecount + 1 | |
3003 : dp->dir$b_namecount; | |
3004 dv = (struct dir$_version *) &dp->dir$t_name[dirp->dd_loc]; | |
3005 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount); | |
3006 sprintf (&dir_static.d_name[dp->dir$b_namecount], ";%d", dv->dir$w_version); | |
3007 dir_static.d_namlen = strlen (dir_static.d_name); | |
3008 dir_static.d_ino = dv->dir$w_fid_num; | |
3009 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 | |
3010 + dir_static.d_namlen - dir_static.d_namlen % 4; | |
3011 dirp->dd_loc = ((char *) (++dv) - dp->dir$t_name); | |
3012 return &dir_static; | |
3013 } | |
3014 | |
3015 #endif /* VMS */ | |
3016 | |
3017 #endif /* NONSYSTEM_DIR_LIBRARY */ | |
3018 | |
3019 /* Functions for VMS */ | |
3020 #ifdef VMS | |
579 | 3021 #include "vms-pwd.h" |
491 | 3022 #include <acldef.h> |
3023 #include <chpdef.h> | |
3024 #include <jpidef.h> | |
3025 | |
3026 /* Return as a string the VMS error string pertaining to STATUS. | |
3027 Reuses the same static buffer each time it is called. */ | |
3028 | |
3029 char * | |
3030 vmserrstr (status) | |
3031 int status; /* VMS status code */ | |
3032 { | |
3033 int bufadr[2]; | |
3034 short len; | |
3035 static char buf[257]; | |
3036 | |
3037 bufadr[0] = sizeof buf - 1; | |
3038 bufadr[1] = (int) buf; | |
3039 if (! (SYS$GETMSG (status, &len, bufadr, 0x1, 0) & 1)) | |
3040 return "untranslatable VMS error status"; | |
3041 buf[len] = '\0'; | |
3042 return buf; | |
3043 } | |
3044 | |
3045 #ifdef access | |
3046 #undef access | |
3047 | |
3048 /* The following is necessary because 'access' emulation by VMS C (2.0) does | |
3049 * not work correctly. (It also doesn't work well in version 2.3.) | |
3050 */ | |
3051 | |
3052 #ifdef VMS4_4 | |
3053 | |
3054 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \ | |
3055 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string } | |
3056 | |
3057 typedef union { | |
3058 struct { | |
3059 unsigned short s_buflen; | |
3060 unsigned short s_code; | |
3061 char *s_bufadr; | |
3062 unsigned short *s_retlenadr; | |
3063 } s; | |
3064 int end; | |
3065 } item; | |
3066 #define buflen s.s_buflen | |
3067 #define code s.s_code | |
3068 #define bufadr s.s_bufadr | |
3069 #define retlenadr s.s_retlenadr | |
3070 | |
3071 #define R_OK 4 /* test for read permission */ | |
3072 #define W_OK 2 /* test for write permission */ | |
3073 #define X_OK 1 /* test for execute (search) permission */ | |
3074 #define F_OK 0 /* test for presence of file */ | |
3075 | |
3076 int | |
3077 sys_access (path, mode) | |
3078 char *path; | |
3079 int mode; | |
3080 { | |
3081 static char *user = NULL; | |
3082 char dir_fn[512]; | |
3083 | |
3084 /* translate possible directory spec into .DIR file name, so brain-dead | |
3085 * access can treat the directory like a file. */ | |
3086 if (directory_file_name (path, dir_fn)) | |
3087 path = dir_fn; | |
3088 | |
3089 if (mode == F_OK) | |
3090 return access (path, mode); | |
3091 if (user == NULL && (user = (char *) getenv ("USER")) == NULL) | |
3092 return -1; | |
3093 { | |
3094 int stat; | |
3095 int flags; | |
3096 int acces; | |
3097 unsigned short int dummy; | |
3098 item itemlst[3]; | |
3099 static int constant = ACL$C_FILE; | |
3100 DESCRIPTOR (path_desc, path); | |
3101 DESCRIPTOR (user_desc, user); | |
3102 | |
3103 flags = 0; | |
3104 acces = 0; | |
3105 if ((mode & X_OK) && ((stat = access (path, mode)) < 0 || mode == X_OK)) | |
3106 return stat; | |
3107 if (mode & R_OK) | |
3108 acces |= CHP$M_READ; | |
3109 if (mode & W_OK) | |
3110 acces |= CHP$M_WRITE; | |
3111 itemlst[0].buflen = sizeof (int); | |
3112 itemlst[0].code = CHP$_FLAGS; | |
3113 itemlst[0].bufadr = (char *) &flags; | |
3114 itemlst[0].retlenadr = &dummy; | |
3115 itemlst[1].buflen = sizeof (int); | |
3116 itemlst[1].code = CHP$_ACCESS; | |
3117 itemlst[1].bufadr = (char *) &acces; | |
3118 itemlst[1].retlenadr = &dummy; | |
3119 itemlst[2].end = CHP$_END; | |
3120 stat = SYS$CHECK_ACCESS (&constant, &path_desc, &user_desc, itemlst); | |
3121 return stat == SS$_NORMAL ? 0 : -1; | |
3122 } | |
3123 } | |
3124 | |
3125 #else /* not VMS4_4 */ | |
3126 | |
3127 #include <prvdef.h> | |
3128 #define ACE$M_WRITE 2 | |
3129 #define ACE$C_KEYID 1 | |
3130 | |
3131 static unsigned short memid, grpid; | |
3132 static unsigned int uic; | |
3133 | |
3134 /* Called from init_sys_modes, so it happens not very often | |
3135 but at least each time Emacs is loaded. */ | |
3136 sys_access_reinit () | |
3137 { | |
3138 uic = 0; | |
3139 } | |
3140 | |
3141 int | |
3142 sys_access (filename, type) | |
3143 char * filename; | |
3144 int type; | |
3145 { | |
3146 struct FAB fab; | |
3147 struct XABPRO xab; | |
3148 int status, size, i, typecode, acl_controlled; | |
3149 unsigned int *aclptr, *aclend, aclbuf[60]; | |
3150 union prvdef prvmask; | |
3151 | |
3152 /* Get UIC and GRP values for protection checking. */ | |
3153 if (uic == 0) | |
3154 { | |
3155 status = LIB$GETJPI (&JPI$_UIC, 0, 0, &uic, 0, 0); | |
3156 if (! (status & 1)) | |
3157 return -1; | |
3158 memid = uic & 0xFFFF; | |
3159 grpid = uic >> 16; | |
3160 } | |
3161 | |
3162 if (type != 2) /* not checking write access */ | |
3163 return access (filename, type); | |
3164 | |
3165 /* Check write protection. */ | |
3166 | |
3167 #define CHECKPRIV(bit) (prvmask.bit) | |
3168 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE)) | |
3169 | |
3170 /* Find privilege bits */ | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3171 status = SYS$SETPRV (0, 0, 0, prvmask); |
491 | 3172 if (! (status & 1)) |
3173 error ("Unable to find privileges: %s", vmserrstr (status)); | |
3174 if (CHECKPRIV (PRV$V_BYPASS)) | |
3175 return 0; /* BYPASS enabled */ | |
3176 fab = cc$rms_fab; | |
3177 fab.fab$b_fac = FAB$M_GET; | |
3178 fab.fab$l_fna = filename; | |
3179 fab.fab$b_fns = strlen (filename); | |
3180 fab.fab$l_xab = &xab; | |
3181 xab = cc$rms_xabpro; | |
3182 xab.xab$l_aclbuf = aclbuf; | |
3183 xab.xab$w_aclsiz = sizeof (aclbuf); | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3184 status = SYS$OPEN (&fab, 0, 0); |
491 | 3185 if (! (status & 1)) |
3186 return -1; | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3187 SYS$CLOSE (&fab, 0, 0); |
491 | 3188 /* Check system access */ |
3189 if (CHECKPRIV (PRV$V_SYSPRV) && WRITEABLE (XAB$V_SYS)) | |
3190 return 0; | |
3191 /* Check ACL entries, if any */ | |
3192 acl_controlled = 0; | |
3193 if (xab.xab$w_acllen > 0) | |
3194 { | |
3195 aclptr = aclbuf; | |
3196 aclend = &aclbuf[xab.xab$w_acllen / 4]; | |
3197 while (*aclptr && aclptr < aclend) | |
3198 { | |
3199 size = (*aclptr & 0xff) / 4; | |
3200 typecode = (*aclptr >> 8) & 0xff; | |
3201 if (typecode == ACE$C_KEYID) | |
3202 for (i = size - 1; i > 1; i--) | |
3203 if (aclptr[i] == uic) | |
3204 { | |
3205 acl_controlled = 1; | |
3206 if (aclptr[1] & ACE$M_WRITE) | |
3207 return 0; /* Write access through ACL */ | |
3208 } | |
3209 aclptr = &aclptr[size]; | |
3210 } | |
3211 if (acl_controlled) /* ACL specified, prohibits write access */ | |
3212 return -1; | |
3213 } | |
3214 /* No ACL entries specified, check normal protection */ | |
3215 if (WRITEABLE (XAB$V_WLD)) /* World writeable */ | |
3216 return 0; | |
3217 if (WRITEABLE (XAB$V_GRP) && | |
3218 (unsigned short) (xab.xab$l_uic >> 16) == grpid) | |
3219 return 0; /* Group writeable */ | |
3220 if (WRITEABLE (XAB$V_OWN) && | |
3221 (xab.xab$l_uic & 0xFFFF) == memid) | |
3222 return 0; /* Owner writeable */ | |
3223 | |
3224 return -1; /* Not writeable */ | |
3225 } | |
3226 #endif /* not VMS4_4 */ | |
3227 #endif /* access */ | |
3228 | |
3229 static char vtbuf[NAM$C_MAXRSS+1]; | |
3230 | |
3231 /* translate a vms file spec to a unix path */ | |
3232 char * | |
3233 sys_translate_vms (vfile) | |
3234 char * vfile; | |
3235 { | |
3236 char * p; | |
3237 char * targ; | |
3238 | |
3239 if (!vfile) | |
3240 return 0; | |
3241 | |
3242 targ = vtbuf; | |
3243 | |
3244 /* leading device or logical name is a root directory */ | |
3245 if (p = strchr (vfile, ':')) | |
3246 { | |
3247 *targ++ = '/'; | |
3248 while (vfile < p) | |
3249 *targ++ = *vfile++; | |
3250 vfile++; | |
3251 *targ++ = '/'; | |
3252 } | |
3253 p = vfile; | |
3254 if (*p == '[' || *p == '<') | |
3255 { | |
3256 while (*++vfile != *p + 2) | |
3257 switch (*vfile) | |
3258 { | |
3259 case '.': | |
3260 if (vfile[-1] == *p) | |
3261 *targ++ = '.'; | |
3262 *targ++ = '/'; | |
3263 break; | |
3264 | |
3265 case '-': | |
3266 *targ++ = '.'; | |
3267 *targ++ = '.'; | |
3268 break; | |
3269 | |
3270 default: | |
3271 *targ++ = *vfile; | |
3272 break; | |
3273 } | |
3274 vfile++; | |
3275 *targ++ = '/'; | |
3276 } | |
3277 while (*vfile) | |
3278 *targ++ = *vfile++; | |
3279 | |
3280 return vtbuf; | |
3281 } | |
3282 | |
3283 static char utbuf[NAM$C_MAXRSS+1]; | |
3284 | |
3285 /* translate a unix path to a VMS file spec */ | |
3286 char * | |
3287 sys_translate_unix (ufile) | |
3288 char * ufile; | |
3289 { | |
3290 int slash_seen = 0; | |
3291 char *p; | |
3292 char * targ; | |
3293 | |
3294 if (!ufile) | |
3295 return 0; | |
3296 | |
3297 targ = utbuf; | |
3298 | |
3299 if (*ufile == '/') | |
3300 { | |
3301 ufile++; | |
3302 } | |
3303 | |
3304 while (*ufile) | |
3305 { | |
3306 switch (*ufile) | |
3307 { | |
3308 case '/': | |
3309 if (slash_seen) | |
3310 if (index (&ufile[1], '/')) | |
3311 *targ++ = '.'; | |
3312 else | |
3313 *targ++ = ']'; | |
3314 else | |
3315 { | |
3316 *targ++ = ':'; | |
3317 if (index (&ufile[1], '/')) | |
3318 *targ++ = '['; | |
3319 slash_seen = 1; | |
3320 } | |
3321 break; | |
3322 | |
3323 case '.': | |
3324 if (strncmp (ufile, "./", 2) == 0) | |
3325 { | |
3326 if (!slash_seen) | |
3327 { | |
3328 *targ++ = '['; | |
3329 slash_seen = 1; | |
3330 } | |
3331 ufile++; /* skip the dot */ | |
3332 if (index (&ufile[1], '/')) | |
3333 *targ++ = '.'; | |
3334 else | |
3335 *targ++ = ']'; | |
3336 } | |
3337 else if (strncmp (ufile, "../", 3) == 0) | |
3338 { | |
3339 if (!slash_seen) | |
3340 { | |
3341 *targ++ = '['; | |
3342 slash_seen = 1; | |
3343 } | |
3344 *targ++ = '-'; | |
3345 ufile += 2; /* skip the dots */ | |
3346 if (index (&ufile[1], '/')) | |
3347 *targ++ = '.'; | |
3348 else | |
3349 *targ++ = ']'; | |
3350 } | |
3351 else | |
3352 *targ++ = *ufile; | |
3353 break; | |
3354 | |
3355 default: | |
3356 *targ++ = *ufile; | |
3357 break; | |
3358 } | |
3359 ufile++; | |
3360 } | |
3361 *targ = '\0'; | |
3362 | |
3363 return utbuf; | |
3364 } | |
3365 | |
3366 char * | |
3367 getwd (pathname) | |
3368 char *pathname; | |
3369 { | |
3370 char *ptr; | |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
3371 extern char *getcwd (); |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
3372 |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
3373 #define MAXPATHLEN 1024 |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
3374 |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
3375 ptr = xmalloc (MAXPATHLEN); |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
3376 getcwd (ptr, MAXPATHLEN); |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
3377 strcpy (pathname, ptr); |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
2332
diff
changeset
|
3378 xfree (ptr); |
2264
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
3379 |
87934d212841
Some VMS changes from Richard Levitte <levitte@e.kth.se>:
Jim Blandy <jimb@redhat.com>
parents:
2121
diff
changeset
|
3380 return pathname; |
491 | 3381 } |
3382 | |
3383 getppid () | |
3384 { | |
3385 long item_code = JPI$_OWNER; | |
3386 unsigned long parent_id; | |
3387 int status; | |
3388 | |
3389 if (((status = LIB$GETJPI (&item_code, 0, 0, &parent_id)) & 1) == 0) | |
3390 { | |
3391 errno = EVMSERR; | |
3392 vaxc$errno = status; | |
3393 return -1; | |
3394 } | |
3395 return parent_id; | |
3396 } | |
3397 | |
3398 #undef getuid | |
3399 unsigned | |
3400 sys_getuid () | |
3401 { | |
3402 return (getgid () << 16) | getuid (); | |
3403 } | |
3404 | |
3405 int | |
3406 sys_read (fildes, buf, nbyte) | |
3407 int fildes; | |
3408 char *buf; | |
3409 unsigned int nbyte; | |
3410 { | |
3411 return read (fildes, buf, (nbyte < MAXIOSIZE ? nbyte : MAXIOSIZE)); | |
3412 } | |
3413 | |
3414 #if 0 | |
3415 int | |
3416 sys_write (fildes, buf, nbyte) | |
3417 int fildes; | |
3418 char *buf; | |
3419 unsigned int nbyte; | |
3420 { | |
3421 register int nwrote, rtnval = 0; | |
3422 | |
3423 while (nbyte > MAXIOSIZE && (nwrote = write (fildes, buf, MAXIOSIZE)) > 0) { | |
3424 nbyte -= nwrote; | |
3425 buf += nwrote; | |
3426 rtnval += nwrote; | |
3427 } | |
3428 if (nwrote < 0) | |
3429 return rtnval ? rtnval : -1; | |
3430 if ((nwrote = write (fildes, buf, nbyte)) < 0) | |
3431 return rtnval ? rtnval : -1; | |
3432 return (rtnval + nwrote); | |
3433 } | |
3434 #endif /* 0 */ | |
3435 | |
3436 /* | |
3437 * VAX/VMS VAX C RTL really loses. It insists that records | |
3438 * end with a newline (carriage return) character, and if they | |
3439 * don't it adds one (nice of it isn't it!) | |
3440 * | |
3441 * Thus we do this stupidity below. | |
3442 */ | |
3443 | |
3444 int | |
3445 sys_write (fildes, buf, nbytes) | |
3446 int fildes; | |
3447 char *buf; | |
3448 unsigned int nbytes; | |
3449 { | |
3450 register char *p; | |
3451 register char *e; | |
525 | 3452 int sum = 0; |
3453 struct stat st; | |
3454 | |
3455 fstat (fildes, &st); | |
491 | 3456 p = buf; |
3457 while (nbytes > 0) | |
3458 { | |
525 | 3459 int len, retval; |
3460 | |
3461 /* Handle fixed-length files with carriage control. */ | |
3462 if (st.st_fab_rfm == FAB$C_FIX | |
3463 && ((st.st_fab_rat & (FAB$M_FTN | FAB$M_CR)) != 0)) | |
3464 { | |
3465 len = st.st_fab_mrs; | |
3466 retval = write (fildes, p, min (len, nbytes)); | |
3467 if (retval != len) | |
3468 return -1; | |
3469 retval++; /* This skips the implied carriage control */ | |
3470 } | |
3471 else | |
3472 { | |
3473 e = p + min (MAXIOSIZE, nbytes) - 1; | |
3474 while (*e != '\n' && e > p) e--; | |
3475 if (p == e) /* Ok.. so here we add a newline... sigh. */ | |
3476 e = p + min (MAXIOSIZE, nbytes) - 1; | |
3477 len = e + 1 - p; | |
3478 retval = write (fildes, p, len); | |
3479 if (retval != len) | |
3480 return -1; | |
3481 } | |
3482 p += retval; | |
3483 sum += retval; | |
491 | 3484 nbytes -= retval; |
3485 } | |
3486 return sum; | |
3487 } | |
3488 | |
3489 /* Create file NEW copying its attributes from file OLD. If | |
3490 OLD is 0 or does not exist, create based on the value of | |
3491 vms_stmlf_recfm. */ | |
3492 | |
3493 /* Protection value the file should ultimately have. | |
3494 Set by create_copy_attrs, and use by rename_sansversions. */ | |
3495 static unsigned short int fab_final_pro; | |
3496 | |
3497 int | |
3498 creat_copy_attrs (old, new) | |
3499 char *old, *new; | |
3500 { | |
3501 struct FAB fab = cc$rms_fab; | |
3502 struct XABPRO xabpro; | |
3503 char aclbuf[256]; /* Choice of size is arbitrary. See below. */ | |
3504 extern int vms_stmlf_recfm; | |
3505 | |
3506 if (old) | |
3507 { | |
3508 fab.fab$b_fac = FAB$M_GET; | |
3509 fab.fab$l_fna = old; | |
3510 fab.fab$b_fns = strlen (old); | |
3511 fab.fab$l_xab = (char *) &xabpro; | |
3512 xabpro = cc$rms_xabpro; | |
3513 xabpro.xab$l_aclbuf = aclbuf; | |
3514 xabpro.xab$w_aclsiz = sizeof aclbuf; | |
3515 /* Call $OPEN to fill in the fab & xabpro fields. */ | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3516 if (SYS$OPEN (&fab, 0, 0) & 1) |
491 | 3517 { |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3518 SYS$CLOSE (&fab, 0, 0); |
491 | 3519 fab.fab$l_alq = 0; /* zero the allocation quantity */ |
3520 if (xabpro.xab$w_acllen > 0) | |
3521 { | |
3522 if (xabpro.xab$w_acllen > sizeof aclbuf) | |
3523 /* If the acl buffer was too short, redo open with longer one. | |
3524 Wouldn't need to do this if there were some system imposed | |
3525 limit on the size of an ACL, but I can't find any such. */ | |
3526 { | |
3527 xabpro.xab$l_aclbuf = (char *) alloca (xabpro.xab$w_acllen); | |
3528 xabpro.xab$w_aclsiz = xabpro.xab$w_acllen; | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3529 if (SYS$OPEN (&fab, 0, 0) & 1) |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3530 SYS$CLOSE (&fab, 0, 0); |
491 | 3531 else |
3532 old = 0; | |
3533 } | |
3534 } | |
3535 else | |
3536 xabpro.xab$l_aclbuf = 0; | |
3537 } | |
3538 else | |
3539 old = 0; | |
3540 } | |
3541 fab.fab$l_fna = new; | |
3542 fab.fab$b_fns = strlen (new); | |
3543 if (!old) | |
3544 { | |
3545 fab.fab$l_xab = 0; | |
3546 fab.fab$b_rfm = vms_stmlf_recfm ? FAB$C_STMLF : FAB$C_VAR; | |
3547 fab.fab$b_rat = FAB$M_CR; | |
3548 } | |
3549 | |
3550 /* Set the file protections such that we will be able to manipulate | |
3551 this file. Once we are done writing and renaming it, we will set | |
3552 the protections back. */ | |
3553 if (old) | |
3554 fab_final_pro = xabpro.xab$w_pro; | |
3555 else | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3556 SYS$SETDFPROT (0, &fab_final_pro); |
491 | 3557 xabpro.xab$w_pro &= 0xff0f; /* set O:rewd for now. This is set back later. */ |
3558 | |
3559 /* Create the new file with either default attrs or attrs copied | |
3560 from old file. */ | |
3561 if (!(SYS$CREATE (&fab, 0, 0) & 1)) | |
3562 return -1; | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3563 SYS$CLOSE (&fab, 0, 0); |
491 | 3564 /* As this is a "replacement" for creat, return a file descriptor |
3565 opened for writing. */ | |
3566 return open (new, O_WRONLY); | |
3567 } | |
3568 | |
3569 #ifdef creat | |
3570 #undef creat | |
3571 #include <varargs.h> | |
3572 #ifdef __GNUC__ | |
3573 #ifndef va_count | |
3574 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1)) | |
3575 #endif | |
3576 #endif | |
3577 | |
3578 sys_creat (va_alist) | |
3579 va_dcl | |
3580 { | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
3581 va_list list_incrementer; |
491 | 3582 char *name; |
3583 int mode; | |
3584 int rfd; /* related file descriptor */ | |
3585 int fd; /* Our new file descriptor */ | |
3586 int count; | |
3587 struct stat st_buf; | |
3588 char rfm[12]; | |
3589 char rat[15]; | |
3590 char mrs[13]; | |
3591 char fsz[13]; | |
3592 extern int vms_stmlf_recfm; | |
3593 | |
3594 va_count (count); | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
3595 va_start (list_incrementer); |
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
3596 name = va_arg (list_incrementer, char *); |
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
3597 mode = va_arg (list_incrementer, int); |
491 | 3598 if (count > 2) |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
3599 rfd = va_arg (list_incrementer, int); |
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
3600 va_end (list_incrementer); |
491 | 3601 if (count > 2) |
3602 { | |
3603 /* Use information from the related file descriptor to set record | |
3604 format of the newly created file. */ | |
3605 fstat (rfd, &st_buf); | |
3606 switch (st_buf.st_fab_rfm) | |
3607 { | |
3608 case FAB$C_FIX: | |
3609 strcpy (rfm, "rfm = fix"); | |
3610 sprintf (mrs, "mrs = %d", st_buf.st_fab_mrs); | |
3611 strcpy (rat, "rat = "); | |
3612 if (st_buf.st_fab_rat & FAB$M_CR) | |
3613 strcat (rat, "cr"); | |
3614 else if (st_buf.st_fab_rat & FAB$M_FTN) | |
3615 strcat (rat, "ftn"); | |
3616 else if (st_buf.st_fab_rat & FAB$M_PRN) | |
3617 strcat (rat, "prn"); | |
3618 if (st_buf.st_fab_rat & FAB$M_BLK) | |
3619 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN)) | |
3620 strcat (rat, ", blk"); | |
3621 else | |
3622 strcat (rat, "blk"); | |
3623 return creat (name, 0, rfm, rat, mrs); | |
3624 | |
3625 case FAB$C_VFC: | |
3626 strcpy (rfm, "rfm = vfc"); | |
3627 sprintf (fsz, "fsz = %d", st_buf.st_fab_fsz); | |
3628 strcpy (rat, "rat = "); | |
3629 if (st_buf.st_fab_rat & FAB$M_CR) | |
3630 strcat (rat, "cr"); | |
3631 else if (st_buf.st_fab_rat & FAB$M_FTN) | |
3632 strcat (rat, "ftn"); | |
3633 else if (st_buf.st_fab_rat & FAB$M_PRN) | |
3634 strcat (rat, "prn"); | |
3635 if (st_buf.st_fab_rat & FAB$M_BLK) | |
3636 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN)) | |
3637 strcat (rat, ", blk"); | |
3638 else | |
3639 strcat (rat, "blk"); | |
3640 return creat (name, 0, rfm, rat, fsz); | |
3641 | |
3642 case FAB$C_STM: | |
3643 strcpy (rfm, "rfm = stm"); | |
3644 break; | |
3645 | |
3646 case FAB$C_STMCR: | |
3647 strcpy (rfm, "rfm = stmcr"); | |
3648 break; | |
3649 | |
3650 case FAB$C_STMLF: | |
3651 strcpy (rfm, "rfm = stmlf"); | |
3652 break; | |
3653 | |
3654 case FAB$C_UDF: | |
3655 strcpy (rfm, "rfm = udf"); | |
3656 break; | |
3657 | |
3658 case FAB$C_VAR: | |
3659 strcpy (rfm, "rfm = var"); | |
3660 break; | |
3661 } | |
3662 strcpy (rat, "rat = "); | |
3663 if (st_buf.st_fab_rat & FAB$M_CR) | |
3664 strcat (rat, "cr"); | |
3665 else if (st_buf.st_fab_rat & FAB$M_FTN) | |
3666 strcat (rat, "ftn"); | |
3667 else if (st_buf.st_fab_rat & FAB$M_PRN) | |
3668 strcat (rat, "prn"); | |
3669 if (st_buf.st_fab_rat & FAB$M_BLK) | |
3670 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN)) | |
3671 strcat (rat, ", blk"); | |
3672 else | |
3673 strcat (rat, "blk"); | |
3674 } | |
3675 else | |
3676 { | |
3677 strcpy (rfm, vms_stmlf_recfm ? "rfm = stmlf" : "rfm=var"); | |
3678 strcpy (rat, "rat=cr"); | |
3679 } | |
3680 /* Until the VAX C RTL fixes the many bugs with modes, always use | |
3681 mode 0 to get the user's default protection. */ | |
3682 fd = creat (name, 0, rfm, rat); | |
3683 if (fd < 0 && errno == EEXIST) | |
3684 { | |
3685 if (unlink (name) < 0) | |
3686 report_file_error ("delete", build_string (name)); | |
3687 fd = creat (name, 0, rfm, rat); | |
3688 } | |
3689 return fd; | |
3690 } | |
3691 #endif /* creat */ | |
3692 | |
3693 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/ | |
3694 sys_fwrite (ptr, size, num, fp) | |
3695 register char * ptr; | |
3696 FILE * fp; | |
3697 { | |
3698 register int tot = num * size; | |
3699 | |
3700 while (tot--) | |
3701 fputc (*ptr++, fp); | |
3702 } | |
3703 | |
3704 /* | |
3705 * The VMS C library routine creat actually creates a new version of an | |
3706 * existing file rather than truncating the old version. There are times | |
3707 * when this is not the desired behavior, for instance, when writing an | |
3708 * auto save file (you only want one version), or when you don't have | |
3709 * write permission in the directory containing the file (but the file | |
3710 * itself is writable). Hence this routine, which is equivalent to | |
3711 * "close (creat (fn, 0));" on Unix if fn already exists. | |
3712 */ | |
3713 int | |
3714 vms_truncate (fn) | |
3715 char *fn; | |
3716 { | |
3717 struct FAB xfab = cc$rms_fab; | |
3718 struct RAB xrab = cc$rms_rab; | |
3719 int status; | |
3720 | |
3721 xfab.fab$l_fop = FAB$M_TEF; /* free allocated but unused blocks on close */ | |
3722 xfab.fab$b_fac = FAB$M_TRN | FAB$M_GET; /* allow truncate and get access */ | |
3723 xfab.fab$b_shr = FAB$M_NIL; /* allow no sharing - file must be locked */ | |
3724 xfab.fab$l_fna = fn; | |
3725 xfab.fab$b_fns = strlen (fn); | |
3726 xfab.fab$l_dna = ";0"; /* default to latest version of the file */ | |
3727 xfab.fab$b_dns = 2; | |
3728 xrab.rab$l_fab = &xfab; | |
3729 | |
3730 /* This gibberish opens the file, positions to the first record, and | |
3731 deletes all records from there until the end of file. */ | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3732 if ((SYS$OPEN (&xfab) & 01) == 01) |
491 | 3733 { |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3734 if ((SYS$CONNECT (&xrab) & 01) == 01 && |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3735 (SYS$FIND (&xrab) & 01) == 01 && |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3736 (SYS$TRUNCATE (&xrab) & 01) == 01) |
491 | 3737 status = 0; |
3738 else | |
3739 status = -1; | |
3740 } | |
3741 else | |
3742 status = -1; | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3743 SYS$CLOSE (&xfab); |
491 | 3744 return status; |
3745 } | |
3746 | |
3747 /* Define this symbol to actually read SYSUAF.DAT. This requires either | |
3748 SYSPRV or a readable SYSUAF.DAT. */ | |
3749 | |
3750 #ifdef READ_SYSUAF | |
3751 /* | |
3752 * getuaf.c | |
3753 * | |
3754 * Routine to read the VMS User Authorization File and return | |
3755 * a specific user's record. | |
3756 */ | |
3757 | |
3758 static struct UAF retuaf; | |
3759 | |
3760 struct UAF * | |
3761 get_uaf_name (uname) | |
3762 char * uname; | |
3763 { | |
3764 register status; | |
3765 struct FAB uaf_fab; | |
3766 struct RAB uaf_rab; | |
3767 | |
3768 uaf_fab = cc$rms_fab; | |
3769 uaf_rab = cc$rms_rab; | |
3770 /* initialize fab fields */ | |
3771 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT"; | |
3772 uaf_fab.fab$b_fns = 21; | |
3773 uaf_fab.fab$b_fac = FAB$M_GET; | |
3774 uaf_fab.fab$b_org = FAB$C_IDX; | |
3775 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL; | |
3776 /* initialize rab fields */ | |
3777 uaf_rab.rab$l_fab = &uaf_fab; | |
3778 /* open the User Authorization File */ | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3779 status = SYS$OPEN (&uaf_fab); |
491 | 3780 if (!(status&1)) |
3781 { | |
3782 errno = EVMSERR; | |
3783 vaxc$errno = status; | |
3784 return 0; | |
3785 } | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3786 status = SYS$CONNECT (&uaf_rab); |
491 | 3787 if (!(status&1)) |
3788 { | |
3789 errno = EVMSERR; | |
3790 vaxc$errno = status; | |
3791 return 0; | |
3792 } | |
3793 /* read the requested record - index is in uname */ | |
3794 uaf_rab.rab$l_kbf = uname; | |
3795 uaf_rab.rab$b_ksz = strlen (uname); | |
3796 uaf_rab.rab$b_rac = RAB$C_KEY; | |
3797 uaf_rab.rab$l_ubf = (char *)&retuaf; | |
3798 uaf_rab.rab$w_usz = sizeof retuaf; | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3799 status = SYS$GET (&uaf_rab); |
491 | 3800 if (!(status&1)) |
3801 { | |
3802 errno = EVMSERR; | |
3803 vaxc$errno = status; | |
3804 return 0; | |
3805 } | |
3806 /* close the User Authorization File */ | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3807 status = SYS$DISCONNECT (&uaf_rab); |
491 | 3808 if (!(status&1)) |
3809 { | |
3810 errno = EVMSERR; | |
3811 vaxc$errno = status; | |
3812 return 0; | |
3813 } | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3814 status = SYS$CLOSE (&uaf_fab); |
491 | 3815 if (!(status&1)) |
3816 { | |
3817 errno = EVMSERR; | |
3818 vaxc$errno = status; | |
3819 return 0; | |
3820 } | |
3821 return &retuaf; | |
3822 } | |
3823 | |
3824 struct UAF * | |
3825 get_uaf_uic (uic) | |
3826 unsigned long uic; | |
3827 { | |
3828 register status; | |
3829 struct FAB uaf_fab; | |
3830 struct RAB uaf_rab; | |
3831 | |
3832 uaf_fab = cc$rms_fab; | |
3833 uaf_rab = cc$rms_rab; | |
3834 /* initialize fab fields */ | |
3835 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT"; | |
3836 uaf_fab.fab$b_fns = 21; | |
3837 uaf_fab.fab$b_fac = FAB$M_GET; | |
3838 uaf_fab.fab$b_org = FAB$C_IDX; | |
3839 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL; | |
3840 /* initialize rab fields */ | |
3841 uaf_rab.rab$l_fab = &uaf_fab; | |
3842 /* open the User Authorization File */ | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3843 status = SYS$OPEN (&uaf_fab); |
491 | 3844 if (!(status&1)) |
3845 { | |
3846 errno = EVMSERR; | |
3847 vaxc$errno = status; | |
3848 return 0; | |
3849 } | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3850 status = SYS$CONNECT (&uaf_rab); |
491 | 3851 if (!(status&1)) |
3852 { | |
3853 errno = EVMSERR; | |
3854 vaxc$errno = status; | |
3855 return 0; | |
3856 } | |
3857 /* read the requested record - index is in uic */ | |
3858 uaf_rab.rab$b_krf = 1; /* 1st alternate key */ | |
3859 uaf_rab.rab$l_kbf = (char *) &uic; | |
3860 uaf_rab.rab$b_ksz = sizeof uic; | |
3861 uaf_rab.rab$b_rac = RAB$C_KEY; | |
3862 uaf_rab.rab$l_ubf = (char *)&retuaf; | |
3863 uaf_rab.rab$w_usz = sizeof retuaf; | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3864 status = SYS$GET (&uaf_rab); |
491 | 3865 if (!(status&1)) |
3866 { | |
3867 errno = EVMSERR; | |
3868 vaxc$errno = status; | |
3869 return 0; | |
3870 } | |
3871 /* close the User Authorization File */ | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3872 status = SYS$DISCONNECT (&uaf_rab); |
491 | 3873 if (!(status&1)) |
3874 { | |
3875 errno = EVMSERR; | |
3876 vaxc$errno = status; | |
3877 return 0; | |
3878 } | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
3879 status = SYS$CLOSE (&uaf_fab); |
491 | 3880 if (!(status&1)) |
3881 { | |
3882 errno = EVMSERR; | |
3883 vaxc$errno = status; | |
3884 return 0; | |
3885 } | |
3886 return &retuaf; | |
3887 } | |
3888 | |
3889 static struct passwd retpw; | |
3890 | |
3891 struct passwd * | |
3892 cnv_uaf_pw (up) | |
3893 struct UAF * up; | |
3894 { | |
3895 char * ptr; | |
3896 | |
3897 /* copy these out first because if the username is 32 chars, the next | |
3898 section will overwrite the first byte of the UIC */ | |
3899 retpw.pw_uid = up->uaf$w_mem; | |
3900 retpw.pw_gid = up->uaf$w_grp; | |
3901 | |
3902 /* I suppose this is not the best sytle, to possibly overwrite one | |
3903 byte beyond the end of the field, but what the heck... */ | |
3904 ptr = &up->uaf$t_username[UAF$S_USERNAME]; | |
3905 while (ptr[-1] == ' ') | |
3906 ptr--; | |
3907 *ptr = '\0'; | |
3908 strcpy (retpw.pw_name, up->uaf$t_username); | |
3909 | |
3910 /* the rest of these are counted ascii strings */ | |
3911 strncpy (retpw.pw_gecos, &up->uaf$t_owner[1], up->uaf$t_owner[0]); | |
3912 retpw.pw_gecos[up->uaf$t_owner[0]] = '\0'; | |
3913 strncpy (retpw.pw_dir, &up->uaf$t_defdev[1], up->uaf$t_defdev[0]); | |
3914 retpw.pw_dir[up->uaf$t_defdev[0]] = '\0'; | |
3915 strncat (retpw.pw_dir, &up->uaf$t_defdir[1], up->uaf$t_defdir[0]); | |
3916 retpw.pw_dir[up->uaf$t_defdev[0] + up->uaf$t_defdir[0]] = '\0'; | |
3917 strncpy (retpw.pw_shell, &up->uaf$t_defcli[1], up->uaf$t_defcli[0]); | |
3918 retpw.pw_shell[up->uaf$t_defcli[0]] = '\0'; | |
3919 | |
3920 return &retpw; | |
3921 } | |
3922 #else /* not READ_SYSUAF */ | |
3923 static struct passwd retpw; | |
3924 #endif /* not READ_SYSUAF */ | |
3925 | |
3926 struct passwd * | |
3927 getpwnam (name) | |
3928 char * name; | |
3929 { | |
3930 #ifdef READ_SYSUAF | |
3931 struct UAF *up; | |
3932 #else | |
3933 char * user; | |
3934 char * dir; | |
3935 unsigned char * full; | |
3936 #endif /* READ_SYSUAF */ | |
3937 char *ptr = name; | |
3938 | |
3939 while (*ptr) | |
3940 { | |
3941 if ('a' <= *ptr && *ptr <= 'z') | |
3942 *ptr -= 040; | |
3943 ptr++; | |
3944 } | |
3945 #ifdef READ_SYSUAF | |
3946 if (!(up = get_uaf_name (name))) | |
3947 return 0; | |
3948 return cnv_uaf_pw (up); | |
3949 #else | |
3950 if (strcmp (name, getenv ("USER")) == 0) | |
3951 { | |
3952 retpw.pw_uid = getuid (); | |
3953 retpw.pw_gid = getgid (); | |
3954 strcpy (retpw.pw_name, name); | |
3955 if (full = egetenv ("FULLNAME")) | |
3956 strcpy (retpw.pw_gecos, full); | |
3957 else | |
3958 *retpw.pw_gecos = '\0'; | |
3959 strcpy (retpw.pw_dir, egetenv ("HOME")); | |
3960 *retpw.pw_shell = '\0'; | |
3961 return &retpw; | |
3962 } | |
3963 else | |
3964 return 0; | |
3965 #endif /* not READ_SYSUAF */ | |
3966 } | |
3967 | |
3968 struct passwd * | |
3969 getpwuid (uid) | |
3970 unsigned long uid; | |
3971 { | |
3972 #ifdef READ_SYSUAF | |
3973 struct UAF * up; | |
3974 | |
3975 if (!(up = get_uaf_uic (uid))) | |
3976 return 0; | |
3977 return cnv_uaf_pw (up); | |
3978 #else | |
3979 if (uid == sys_getuid ()) | |
3980 return getpwnam (egetenv ("USER")); | |
3981 else | |
3982 return 0; | |
3983 #endif /* not READ_SYSUAF */ | |
3984 } | |
3985 | |
3986 /* return total address space available to the current process. This is | |
3987 the sum of the current p0 size, p1 size and free page table entries | |
3988 available. */ | |
3989 vlimit () | |
3990 { | |
3991 int item_code; | |
3992 unsigned long free_pages; | |
3993 unsigned long frep0va; | |
3994 unsigned long frep1va; | |
3995 register status; | |
3996 | |
3997 item_code = JPI$_FREPTECNT; | |
3998 if (((status = LIB$GETJPI (&item_code, 0, 0, &free_pages)) & 1) == 0) | |
3999 { | |
4000 errno = EVMSERR; | |
4001 vaxc$errno = status; | |
4002 return -1; | |
4003 } | |
4004 free_pages *= 512; | |
4005 | |
4006 item_code = JPI$_FREP0VA; | |
4007 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep0va)) & 1) == 0) | |
4008 { | |
4009 errno = EVMSERR; | |
4010 vaxc$errno = status; | |
4011 return -1; | |
4012 } | |
4013 item_code = JPI$_FREP1VA; | |
4014 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep1va)) & 1) == 0) | |
4015 { | |
4016 errno = EVMSERR; | |
4017 vaxc$errno = status; | |
4018 return -1; | |
4019 } | |
4020 | |
4021 return free_pages + frep0va + (0x7fffffff - frep1va); | |
4022 } | |
4023 | |
4024 define_logical_name (varname, string) | |
4025 char *varname; | |
4026 char *string; | |
4027 { | |
4028 struct dsc$descriptor_s strdsc = | |
4029 {strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string}; | |
4030 struct dsc$descriptor_s envdsc = | |
4031 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname}; | |
4032 struct dsc$descriptor_s lnmdsc = | |
4033 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"}; | |
4034 | |
4035 return LIB$SET_LOGICAL (&envdsc, &strdsc, &lnmdsc, 0, 0); | |
4036 } | |
4037 | |
4038 delete_logical_name (varname) | |
4039 char *varname; | |
4040 { | |
4041 struct dsc$descriptor_s envdsc = | |
4042 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname}; | |
4043 struct dsc$descriptor_s lnmdsc = | |
4044 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"}; | |
4045 | |
4046 return LIB$DELETE_LOGICAL (&envdsc, &lnmdsc); | |
4047 } | |
4048 | |
4049 ulimit () | |
4050 {} | |
4051 | |
4052 setpgrp () | |
4053 {} | |
4054 | |
4055 execvp () | |
4056 { | |
4057 error ("execvp system call not implemented"); | |
4058 } | |
4059 | |
4060 int | |
4061 rename (from, to) | |
4062 char *from, *to; | |
4063 { | |
4064 int status; | |
4065 struct FAB from_fab = cc$rms_fab, to_fab = cc$rms_fab; | |
4066 struct NAM from_nam = cc$rms_nam, to_nam = cc$rms_nam; | |
4067 char from_esn[NAM$C_MAXRSS]; | |
4068 char to_esn[NAM$C_MAXRSS]; | |
4069 | |
4070 from_fab.fab$l_fna = from; | |
4071 from_fab.fab$b_fns = strlen (from); | |
4072 from_fab.fab$l_nam = &from_nam; | |
4073 from_fab.fab$l_fop = FAB$M_NAM; | |
4074 | |
4075 from_nam.nam$l_esa = from_esn; | |
4076 from_nam.nam$b_ess = sizeof from_esn; | |
4077 | |
4078 to_fab.fab$l_fna = to; | |
4079 to_fab.fab$b_fns = strlen (to); | |
4080 to_fab.fab$l_nam = &to_nam; | |
4081 to_fab.fab$l_fop = FAB$M_NAM; | |
4082 | |
4083 to_nam.nam$l_esa = to_esn; | |
4084 to_nam.nam$b_ess = sizeof to_esn; | |
4085 | |
4086 status = SYS$RENAME (&from_fab, 0, 0, &to_fab); | |
4087 | |
4088 if (status & 1) | |
4089 return 0; | |
4090 else | |
4091 { | |
4092 if (status == RMS$_DEV) | |
4093 errno = EXDEV; | |
4094 else | |
4095 errno = EVMSERR; | |
4096 vaxc$errno = status; | |
4097 return -1; | |
4098 } | |
4099 } | |
4100 | |
4101 /* This function renames a file like `rename', but it strips | |
4102 the version number from the "to" filename, such that the "to" file is | |
4103 will always be a new version. It also sets the file protection once it is | |
4104 finished. The protection that we will use is stored in fab_final_pro, | |
4105 and was set when we did a creat_copy_attrs to create the file that we | |
4106 are renaming. | |
4107 | |
4108 We could use the chmod function, but Eunichs uses 3 bits per user category | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3559
diff
changeset
|
4109 to describe the protection, and VMS uses 4 (write and delete are separate |
491 | 4110 bits). To maintain portability, the VMS implementation of `chmod' wires |
4111 the W and D bits together. */ | |
4112 | |
4113 | |
4114 static struct fibdef fib; /* We need this initialized to zero */ | |
4115 char vms_file_written[NAM$C_MAXRSS]; | |
4116 | |
4117 int | |
4118 rename_sans_version (from,to) | |
4119 char *from, *to; | |
4120 { | |
4121 short int chan; | |
4122 int stat; | |
4123 short int iosb[4]; | |
4124 int status; | |
4125 struct FAB to_fab = cc$rms_fab; | |
4126 struct NAM to_nam = cc$rms_nam; | |
4127 struct dsc$descriptor fib_d ={sizeof (fib),0,0,(char*) &fib}; | |
4128 struct dsc$descriptor fib_attr[2] | |
4129 = {{sizeof (fab_final_pro),ATR$C_FPRO,0,(char*) &fab_final_pro},{0,0,0,0}}; | |
4130 char to_esn[NAM$C_MAXRSS]; | |
4131 | |
4132 $DESCRIPTOR (disk,to_esn); | |
4133 | |
4134 to_fab.fab$l_fna = to; | |
4135 to_fab.fab$b_fns = strlen (to); | |
4136 to_fab.fab$l_nam = &to_nam; | |
4137 to_fab.fab$l_fop = FAB$M_NAM; | |
4138 | |
4139 to_nam.nam$l_esa = to_esn; | |
4140 to_nam.nam$b_ess = sizeof to_esn; | |
4141 | |
4142 status = SYS$PARSE (&to_fab, 0, 0); /* figure out the full file name */ | |
4143 | |
4144 if (to_nam.nam$l_fnb && NAM$M_EXP_VER) | |
4145 *(to_nam.nam$l_ver) = '\0'; | |
4146 | |
4147 stat = rename (from, to_esn); | |
4148 if (stat < 0) | |
4149 return stat; | |
4150 | |
4151 strcpy (vms_file_written, to_esn); | |
4152 | |
4153 to_fab.fab$l_fna = vms_file_written; /* this points to the versionless name */ | |
4154 to_fab.fab$b_fns = strlen (vms_file_written); | |
4155 | |
4156 /* Now set the file protection to the correct value */ | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
4157 SYS$OPEN (&to_fab, 0, 0); /* This fills in the nam$w_fid fields */ |
491 | 4158 |
4159 /* Copy these fields into the fib */ | |
4160 fib.fib$r_fid_overlay.fib$w_fid[0] = to_nam.nam$w_fid[0]; | |
4161 fib.fib$r_fid_overlay.fib$w_fid[1] = to_nam.nam$w_fid[1]; | |
4162 fib.fib$r_fid_overlay.fib$w_fid[2] = to_nam.nam$w_fid[2]; | |
4163 | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
4164 SYS$CLOSE (&to_fab, 0, 0); |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
4165 |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
4166 stat = SYS$ASSIGN (&disk, &chan, 0, 0); /* open a channel to the disk */ |
491 | 4167 if (!stat) |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
4168 LIB$SIGNAL (stat); |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
4169 stat = SYS$QIOW (0, chan, IO$_MODIFY, iosb, 0, 0, &fib_d, |
491 | 4170 0, 0, 0, &fib_attr, 0); |
4171 if (!stat) | |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
4172 LIB$SIGNAL (stat); |
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
4173 stat = SYS$DASSGN (chan); |
491 | 4174 if (!stat) |
1596
0e105bd23f44
* systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents:
1570
diff
changeset
|
4175 LIB$SIGNAL (stat); |
766 | 4176 strcpy (vms_file_written, to_esn); /* We will write this to the terminal*/ |
491 | 4177 return 0; |
4178 } | |
4179 | |
4180 link (file, new) | |
4181 char * file, * new; | |
4182 { | |
4183 register status; | |
4184 struct FAB fab; | |
4185 struct NAM nam; | |
4186 unsigned short fid[3]; | |
4187 char esa[NAM$C_MAXRSS]; | |
4188 | |
4189 fab = cc$rms_fab; | |
4190 fab.fab$l_fop = FAB$M_OFP; | |
4191 fab.fab$l_fna = file; | |
4192 fab.fab$b_fns = strlen (file); | |
4193 fab.fab$l_nam = &nam; | |
4194 | |
4195 nam = cc$rms_nam; | |
4196 nam.nam$l_esa = esa; | |
4197 nam.nam$b_ess = NAM$C_MAXRSS; | |
4198 | |
4199 status = SYS$PARSE (&fab); | |
4200 if ((status & 1) == 0) | |
4201 { | |
4202 errno = EVMSERR; | |
4203 vaxc$errno = status; | |
4204 return -1; | |
4205 } | |
4206 status = SYS$SEARCH (&fab); | |
4207 if ((status & 1) == 0) | |
4208 { | |
4209 errno = EVMSERR; | |
4210 vaxc$errno = status; | |
4211 return -1; | |
4212 } | |
4213 | |
4214 fid[0] = nam.nam$w_fid[0]; | |
4215 fid[1] = nam.nam$w_fid[1]; | |
4216 fid[2] = nam.nam$w_fid[2]; | |
4217 | |
4218 fab.fab$l_fna = new; | |
4219 fab.fab$b_fns = strlen (new); | |
4220 | |
4221 status = SYS$PARSE (&fab); | |
4222 if ((status & 1) == 0) | |
4223 { | |
4224 errno = EVMSERR; | |
4225 vaxc$errno = status; | |
4226 return -1; | |
4227 } | |
4228 | |
4229 nam.nam$w_fid[0] = fid[0]; | |
4230 nam.nam$w_fid[1] = fid[1]; | |
4231 nam.nam$w_fid[2] = fid[2]; | |
4232 | |
4233 nam.nam$l_esa = nam.nam$l_name; | |
4234 nam.nam$b_esl = nam.nam$b_name + nam.nam$b_type + nam.nam$b_ver; | |
4235 | |
4236 status = SYS$ENTER (&fab); | |
4237 if ((status & 1) == 0) | |
4238 { | |
4239 errno = EVMSERR; | |
4240 vaxc$errno = status; | |
4241 return -1; | |
4242 } | |
4243 | |
4244 return 0; | |
4245 } | |
4246 | |
4247 croak (badfunc) | |
4248 char *badfunc; | |
4249 { | |
4250 printf ("%s not yet implemented\r\n", badfunc); | |
4251 reset_sys_modes (); | |
4252 exit (1); | |
4253 } | |
4254 | |
4255 long | |
4256 random () | |
4257 { | |
4258 /* Arrange to return a range centered on zero. */ | |
4259 return rand () - (1 << 30); | |
4260 } | |
4261 | |
4262 srandom (seed) | |
4263 { | |
4264 srand (seed); | |
4265 } | |
4266 #endif /* VMS */ | |
4267 | |
4268 #ifdef AIX | |
4269 | |
4270 /* Called from init_sys_modes. */ | |
4271 hft_init () | |
4272 { | |
4273 int junk; | |
4274 | |
4275 /* If we're not on an HFT we shouldn't do any of this. We determine | |
4276 if we are on an HFT by trying to get an HFT error code. If this | |
4277 call fails, we're not on an HFT. */ | |
4278 #ifdef IBMR2AIX | |
4279 if (ioctl (0, HFQERROR, &junk) < 0) | |
4280 return; | |
4281 #else /* not IBMR2AIX */ | |
4282 if (ioctl (0, HFQEIO, 0) < 0) | |
4283 return; | |
4284 #endif /* not IBMR2AIX */ | |
4285 | |
4286 /* On AIX the default hft keyboard mapping uses backspace rather than delete | |
4287 as the rubout key's ASCII code. Here this is changed. The bug is that | |
4288 there's no way to determine the old mapping, so in reset_sys_modes | |
4289 we need to assume that the normal map had been present. Of course, this | |
4290 code also doesn't help if on a terminal emulator which doesn't understand | |
4291 HFT VTD's. */ | |
4292 { | |
4293 struct hfbuf buf; | |
4294 struct hfkeymap keymap; | |
4295 | |
4296 buf.hf_bufp = (char *)&keymap; | |
4297 buf.hf_buflen = sizeof (keymap); | |
4298 keymap.hf_nkeys = 2; | |
4299 keymap.hfkey[0].hf_kpos = 15; | |
4300 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE; | |
4301 #ifdef IBMR2AIX | |
4302 keymap.hfkey[0].hf_keyidh = '<'; | |
4303 #else /* not IBMR2AIX */ | |
4304 keymap.hfkey[0].hf_page = '<'; | |
4305 #endif /* not IBMR2AIX */ | |
4306 keymap.hfkey[0].hf_char = 127; | |
4307 keymap.hfkey[1].hf_kpos = 15; | |
4308 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT; | |
4309 #ifdef IBMR2AIX | |
4310 keymap.hfkey[1].hf_keyidh = '<'; | |
4311 #else /* not IBMR2AIX */ | |
4312 keymap.hfkey[1].hf_page = '<'; | |
4313 #endif /* not IBMR2AIX */ | |
4314 keymap.hfkey[1].hf_char = 127; | |
4315 hftctl (0, HFSKBD, &buf); | |
4316 } | |
4317 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly | |
4318 at times. */ | |
4319 line_ins_del_ok = char_ins_del_ok = 0; | |
4320 } | |
4321 | |
4322 /* Reset the rubout key to backspace. */ | |
4323 | |
4324 hft_reset () | |
4325 { | |
4326 struct hfbuf buf; | |
4327 struct hfkeymap keymap; | |
4328 int junk; | |
4329 | |
4330 #ifdef IBMR2AIX | |
4331 if (ioctl (0, HFQERROR, &junk) < 0) | |
4332 return; | |
4333 #else /* not IBMR2AIX */ | |
4334 if (ioctl (0, HFQEIO, 0) < 0) | |
4335 return; | |
4336 #endif /* not IBMR2AIX */ | |
4337 | |
4338 buf.hf_bufp = (char *)&keymap; | |
4339 buf.hf_buflen = sizeof (keymap); | |
4340 keymap.hf_nkeys = 2; | |
4341 keymap.hfkey[0].hf_kpos = 15; | |
4342 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE; | |
4343 #ifdef IBMR2AIX | |
4344 keymap.hfkey[0].hf_keyidh = '<'; | |
4345 #else /* not IBMR2AIX */ | |
4346 keymap.hfkey[0].hf_page = '<'; | |
4347 #endif /* not IBMR2AIX */ | |
4348 keymap.hfkey[0].hf_char = 8; | |
4349 keymap.hfkey[1].hf_kpos = 15; | |
4350 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT; | |
4351 #ifdef IBMR2AIX | |
4352 keymap.hfkey[1].hf_keyidh = '<'; | |
4353 #else /* not IBMR2AIX */ | |
4354 keymap.hfkey[1].hf_page = '<'; | |
4355 #endif /* not IBMR2AIX */ | |
4356 keymap.hfkey[1].hf_char = 8; | |
4357 hftctl (0, HFSKBD, &buf); | |
4358 } | |
4359 | |
4360 #endif /* AIX */ |