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