0
|
1 /* Interfaces to system-dependent kernel and library entries.
|
|
2 Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Tinker Systems.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: FSF 19.30 except for some Windows-NT crap. */
|
|
23
|
|
24 /* Substantially cleaned up by Ben Wing, Dec. 1994 / Jan. 1995. */
|
|
25
|
|
26 /* In this file, open, read and write refer to the system calls,
|
|
27 not our sugared interfaces sys_open, sys_read and sys_write.
|
|
28 */
|
|
29
|
|
30 #define DONT_ENCAPSULATE
|
|
31
|
|
32 #include <config.h>
|
239
|
33
|
|
34 #ifdef WINDOWSNT
|
|
35 #include <direct.h>
|
|
36 /* <process.h> should not conflict with "process.h", as per ANSI definition.
|
|
37 This is not true though with visual c though. The trick below works with
|
|
38 VC4.2b and with VC5.0. It assumes that VC is installed in a kind of
|
|
39 standard way, so include files get to what/ever/path/include.
|
|
40 */
|
|
41 #include <../include/process.h>
|
|
42 #endif /* WINDOWSNT */
|
|
43
|
0
|
44 #include "lisp.h"
|
|
45
|
187
|
46 #include <stddef.h>
|
272
|
47 #include <stdlib.h>
|
187
|
48
|
0
|
49 /* ------------------------------- */
|
|
50 /* basic includes */
|
|
51 /* ------------------------------- */
|
|
52
|
|
53 #ifdef HAVE_TTY
|
|
54 #include "console-tty.h"
|
78
|
55 #else
|
|
56 #include "syssignal.h"
|
|
57 #include "systty.h"
|
0
|
58 #endif /* HAVE_TTY */
|
|
59
|
|
60 #include "console-stream.h"
|
|
61
|
|
62 #include "buffer.h"
|
|
63 #include "events.h"
|
|
64 #include "frame.h"
|
|
65 #include "redisplay.h"
|
|
66 #include "process.h"
|
|
67 #include "sysdep.h"
|
|
68 #include "window.h"
|
|
69
|
|
70 #include <setjmp.h>
|
2
|
71 #ifdef HAVE_LIBGEN_H /* Must come before sysfile.h */
|
|
72 #include <libgen.h>
|
|
73 #endif
|
0
|
74 #include "sysfile.h"
|
|
75 #include "syswait.h"
|
|
76 #include "sysdir.h"
|
|
77 #include "systime.h"
|
231
|
78 #if defined(WINDOWSNT) || defined(__CYGWIN32__)
|
100
|
79 #include "syssignal.h"
|
231
|
80 #endif
|
|
81 #ifndef WINDOWSNT
|
0
|
82 #include <sys/times.h>
|
100
|
83 #endif
|
255
|
84
|
239
|
85 #ifdef WINDOWSNT
|
|
86 #include <sys/utime.h>
|
255
|
87 #include <windows.h>
|
239
|
88 #include "ntheap.h"
|
179
|
89 #endif
|
|
90
|
0
|
91 /* ------------------------------- */
|
|
92 /* TTY definitions */
|
|
93 /* ------------------------------- */
|
|
94
|
|
95 #ifdef USG
|
|
96 #include <sys/utsname.h>
|
|
97 #if defined (TIOCGWINSZ) || defined (ISC4_0)
|
|
98 #ifdef NEED_SIOCTL
|
|
99 #include <sys/sioctl.h>
|
|
100 #endif
|
|
101 #ifdef NEED_PTEM_H
|
|
102 #include <sys/stream.h>
|
|
103 #include <sys/ptem.h>
|
|
104 #endif
|
|
105 #endif /* TIOCGWINSZ or ISC4_0 */
|
|
106 #endif /* USG */
|
|
107
|
|
108 #ifdef HAVE_SYS_STROPTS_H
|
185
|
109 #include <sys/stropts.h>
|
0
|
110 #endif /* HAVE_SYS_STROPTS_H */
|
|
111
|
|
112 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
|
|
113 #ifndef LPASS8
|
|
114 #define LPASS8 0
|
|
115 #endif
|
|
116
|
|
117 #ifndef HAVE_H_ERRNO
|
|
118 int h_errno;
|
|
119 #endif
|
|
120
|
|
121 #ifdef HAVE_TTY
|
|
122
|
|
123 static int baud_convert[] =
|
|
124 #ifdef BAUD_CONVERT
|
|
125 BAUD_CONVERT;
|
|
126 #else
|
|
127 {
|
|
128 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
|
|
129 1800, 2400, 4800, 9600, 19200, 38400
|
|
130 };
|
|
131 #endif
|
|
132
|
|
133 #endif
|
|
134
|
|
135 #ifdef AIXHFT
|
|
136 static void hft_init (struct console *c);
|
|
137 static void hft_reset (struct console *c);
|
274
|
138 #include <sys/termio.h>
|
0
|
139 #endif
|
|
140
|
|
141 /* ------------------------------- */
|
|
142 /* miscellaneous */
|
|
143 /* ------------------------------- */
|
|
144
|
|
145 #ifndef HAVE_UTIMES
|
|
146 #ifndef HAVE_STRUCT_UTIMBUF
|
|
147 /* We want to use utime rather than utimes, but we couldn't find the
|
|
148 structure declaration. We'll use the traditional one. */
|
|
149 struct utimbuf
|
|
150 {
|
|
151 long actime;
|
|
152 long modtime;
|
|
153 };
|
|
154 #endif
|
|
155 #endif
|
|
156
|
|
157
|
|
158 /************************************************************************/
|
|
159 /* subprocess control */
|
|
160 /************************************************************************/
|
|
161
|
|
162 #ifdef HAVE_TTY
|
|
163
|
|
164 #ifdef SIGTSTP
|
|
165
|
|
166 /* Arrange for character C to be read as the next input from
|
|
167 the terminal. */
|
|
168 void
|
|
169 stuff_char (struct console *con, int c)
|
|
170 {
|
|
171 int input_fd;
|
|
172
|
|
173 assert (CONSOLE_TTY_P (con));
|
|
174 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
175 /* Should perhaps error if in batch mode */
|
|
176 #ifdef TIOCSTI
|
|
177 ioctl (input_fd, TIOCSTI, &c);
|
|
178 #else /* no TIOCSTI */
|
|
179 error ("Cannot stuff terminal input characters in this version of Unix.");
|
|
180 #endif /* no TIOCSTI */
|
|
181 }
|
|
182
|
|
183 #endif /* SIGTSTP */
|
|
184
|
|
185 #endif /* HAVE_TTY */
|
|
186
|
|
187 void
|
|
188 set_exclusive_use (int fd)
|
|
189 {
|
|
190 #ifdef FIOCLEX
|
|
191 ioctl (fd, FIOCLEX, 0);
|
|
192 #endif
|
|
193 /* Ok to do nothing if this feature does not exist */
|
|
194 }
|
|
195
|
|
196 void
|
|
197 set_descriptor_non_blocking (int fd)
|
|
198 {
|
|
199 /* Stride people say it's a mystery why this is needed
|
|
200 as well as the O_NDELAY, but that it fails without this. */
|
|
201 /* For AIX: Apparently need this for non-blocking reads on sockets.
|
|
202 It seems that O_NONBLOCK applies only to FIFOs? From
|
|
203 lowry@watson.ibm.com (Andy Lowry). */
|
|
204 /* #### Should this be conditionalized on FIONBIO? */
|
|
205 #if defined (STRIDE) || (defined (pfa) && defined (HAVE_PTYS)) || defined (AIX)
|
|
206 {
|
|
207 int one = 1;
|
|
208 ioctl (fd, FIONBIO, &one);
|
|
209 }
|
|
210 #endif
|
|
211
|
|
212 #ifdef O_NONBLOCK /* The POSIX way */
|
|
213 fcntl (fd, F_SETFL, O_NONBLOCK);
|
|
214 #elif defined (O_NDELAY)
|
|
215 fcntl (fd, F_SETFL, O_NDELAY);
|
|
216 #endif /* O_NONBLOCK */
|
|
217 }
|
|
218
|
|
219 #if defined (NO_SUBPROCESSES)
|
|
220
|
|
221 #ifdef BSD
|
|
222 void
|
|
223 wait_without_blocking (void)
|
|
224 {
|
|
225 wait3 (0, WNOHANG | WUNTRACED, 0);
|
|
226 synch_process_alive = 0;
|
|
227 }
|
|
228 #endif /* BSD */
|
|
229
|
|
230 #endif /* NO_SUBPROCESSES */
|
|
231
|
|
232
|
|
233 void
|
|
234 wait_for_termination (int pid)
|
|
235 {
|
|
236 /* #### With the new improved SIGCHLD handling stuff, there is much
|
|
237 less danger of race conditions and some of the comments below
|
|
238 don't apply. This should be updated. */
|
163
|
239
|
|
240 #if defined (NO_SUBPROCESSES)
|
0
|
241 while (1)
|
|
242 {
|
163
|
243 /* No need to be tricky like below; we can just call wait(). */
|
|
244 /* #### should figure out how to write a wait_allowing_quit().
|
|
245 Since hardly any systems don't have subprocess support,
|
|
246 however, there doesn't seem to be much point. */
|
|
247 if (wait (0) == pid)
|
|
248 return;
|
|
249 }
|
|
250 #elif defined (HAVE_WAITPID)
|
|
251 /* Note that, whenever any subprocess terminates (asynch. or synch.),
|
|
252 the SIGCHLD handler will be called and it will call wait(). Thus
|
|
253 we cannot just call wait() ourselves, and we can't block SIGCHLD
|
|
254 and then call wait(), because then if an asynch. process dies
|
|
255 while we're waiting for our synch. process, Emacs will never
|
|
256 notice that the asynch. process died.
|
|
257
|
|
258 So, the general approach we take is to repeatedly block until a
|
|
259 signal arrives, and then check if our process died using kill
|
|
260 (pid, 0). (We could also check the value of `synch_process_alive',
|
|
261 since the SIGCHLD handler will reset that and we know that we're
|
|
262 only being called on synchronous processes, but this approach is
|
|
263 safer. I don't trust the proper delivery of SIGCHLD.
|
|
264
|
|
265 Note also that we cannot use any form of waitpid(). A loop with
|
|
266 WNOHANG will chew up CPU time; better to use sleep(). A loop
|
|
267 without WNOWAIT will screw up the SIGCHLD handler (actually this
|
|
268 is not true, if you duplicate the exit-status-reaping code; see
|
|
269 below). A loop with WNOWAIT will result in a race condition if
|
|
270 the process terminates between the process-status check and the
|
|
271 call to waitpid(). */
|
|
272
|
|
273 /* Formerly, immediate_quit was set around this function call, but
|
|
274 that could lead to problems if the QUIT happened when SIGCHLD was
|
|
275 blocked -- it would remain blocked. Yet another reason why
|
|
276 immediate_quit is a bad idea. In any case, there is no reason to
|
|
277 resort to this because either the SIGIO or the SIGALRM will stop
|
|
278 the block in EMACS_WAIT_FOR_SIGNAL(). */
|
|
279
|
|
280 /* Apparently there are bugs on some systems with the second method
|
|
281 used below (the EMACS_BLOCK_SIGNAL method), whereby zombie
|
|
282 processes get left around. It appears in those cases that the
|
|
283 SIGCHLD handler is never getting invoked. It's not clear whether
|
|
284 this is an Emacs bug or a kernel bug or both: on HPUX this
|
|
285 problem is observed only with XEmacs, but under Solaris 2.4 all
|
|
286 sorts of different programs have problems with zombies. The
|
|
287 method we use here does not require a working SIGCHLD (but will
|
|
288 not break if it is working), and should be safe. */
|
|
289 /*
|
|
290 We use waitpid(), contrary to the remarks above. There is no
|
|
291 race condition, because the three situations when sigchld_handler
|
|
292 is invoked should be handled OK:
|
|
293
|
|
294 - handler invoked before waitpid(): In this case, subprocess
|
|
295 status will be set by sigchld_handler. waitpid() here will
|
|
296 return -1 with errno set to ECHILD, which is a valid exit
|
|
297 condition.
|
|
298
|
|
299 - handler invoked during waitpid(): as above, except that errno
|
|
300 here will be set to EINTR. This will cause waitpid() to be
|
|
301 called again, and this time it will exit with ECHILD.
|
|
302
|
|
303 - handler invoked after waitpid(): The following code will reap
|
|
304 the subprocess. In the handler, wait() will return -1 because
|
|
305 there is no child to reap, and the handler will exit without
|
|
306 modifying child subprocess status. */
|
|
307 int ret, status;
|
|
308
|
|
309 /* Because the SIGCHLD handler can potentially reap the synchronous
|
|
310 subprocess, we should take care of that. */
|
|
311
|
|
312 /* Will stay in the do loop as long as:
|
|
313 1. Process is alive
|
|
314 2. Ctrl-G is not pressed */
|
|
315 do
|
|
316 {
|
0
|
317 QUIT;
|
163
|
318 ret = waitpid (pid, &status, 0);
|
|
319 /* waitpid returns 0 if the process is still alive. */
|
|
320 }
|
|
321 while (ret == 0 || (ret == -1 && errno == EINTR));
|
|
322
|
|
323 if (ret == pid) /* Success */
|
|
324 /* Set synch process globals. This is can also happen
|
|
325 in sigchld_handler, and that code is duplicated. */
|
|
326 {
|
|
327 synch_process_alive = 0;
|
|
328 if (WIFEXITED (status))
|
|
329 synch_process_retcode = WEXITSTATUS (status);
|
|
330 else if (WIFSIGNALED (status))
|
|
331 synch_process_death = signal_name (WTERMSIG (status));
|
|
332 }
|
|
333 /* On exiting the loop, ret will be -1, with errno set to ECHILD if
|
|
334 the child has already been reaped, e.g. in the signal handler. */
|
|
335
|
|
336 /* Otherwise, we've had some error condition here.
|
|
337 Per POSIX, the only other possibilities are:
|
|
338 - EFAULT (bus error accessing arg 2) or
|
|
339 - EINVAL (incorrect arguments),
|
|
340 which are both program bugs.
|
|
341
|
|
342 Since implementations may add their own error indicators on top,
|
|
343 we ignore it by default. */
|
|
344 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD)
|
|
345 while (1)
|
|
346 {
|
|
347 static int wait_debugging = 0; /* Set nonzero to make following
|
|
348 function work under dbx (at least for bsd). */
|
|
349 QUIT;
|
|
350 if (wait_debugging)
|
|
351 return;
|
|
352
|
|
353 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
|
354 /* Block SIGCHLD from happening during this check,
|
|
355 to avoid race conditions. */
|
|
356 if (kill (pid, 0) < 0)
|
0
|
357 {
|
163
|
358 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
359 return;
|
0
|
360 }
|
163
|
361 else
|
|
362 /* WARNING: Whatever this macro does *must* not allow SIGCHLD
|
|
363 to happen between the time that it's reenabled and when we
|
|
364 begin to block. Otherwise we may end up blocking for a
|
|
365 signal that has already arrived and isn't coming again.
|
|
366 Can you say "race condition"?
|
|
367
|
|
368 I assume that the system calls sigpause() or sigsuspend()
|
|
369 to provide this atomicness. If you're getting hangs in
|
|
370 sigpause()/sigsuspend(), then your OS doesn't implement
|
|
371 this properly (this applies under hpux9, for example).
|
|
372 Try defining BROKEN_WAIT_FOR_SIGNAL. */
|
|
373 EMACS_WAIT_FOR_SIGNAL (SIGCHLD);
|
|
374 }
|
|
375 #else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */
|
|
376 /* This approach is kind of cheesy but is guaranteed(?!) to work
|
|
377 for all systems. */
|
|
378 while (1)
|
|
379 {
|
|
380 QUIT;
|
0
|
381 if (kill (pid, 0) < 0)
|
|
382 return;
|
|
383 emacs_sleep (1);
|
|
384 }
|
163
|
385 #endif /* OS features */
|
0
|
386 }
|
|
387
|
|
388
|
|
389 #if !defined (NO_SUBPROCESSES)
|
|
390
|
|
391 /*
|
|
392 * flush any pending output
|
|
393 * (may flush input as well; it does not matter the way we use it)
|
|
394 */
|
185
|
395
|
0
|
396 void
|
|
397 flush_pending_output (int channel)
|
|
398 {
|
|
399 #ifdef HAVE_TERMIOS
|
|
400 /* If we try this, we get hit with SIGTTIN, because
|
|
401 the child's tty belongs to the child's pgrp. */
|
|
402 #elif defined (TCFLSH)
|
|
403 ioctl (channel, TCFLSH, 1);
|
|
404 #elif defined (TIOCFLUSH)
|
|
405 int zero = 0;
|
|
406 /* 3rd arg should be ignored
|
|
407 but some 4.2 kernels actually want the address of an int
|
|
408 and nonzero means something different. */
|
|
409 ioctl (channel, TIOCFLUSH, &zero);
|
|
410 #endif
|
|
411 }
|
|
412
|
|
413 #ifndef MSDOS
|
100
|
414 #ifndef WINDOWSNT
|
0
|
415 /* Set up the terminal at the other end of a pseudo-terminal that
|
|
416 we will be controlling an inferior through.
|
|
417 It should not echo or do line-editing, since that is done
|
|
418 in Emacs. No padding needed for insertion into an Emacs buffer. */
|
|
419
|
|
420 void
|
|
421 child_setup_tty (int out)
|
|
422 {
|
|
423 struct emacs_tty s;
|
|
424 EMACS_GET_TTY (out, &s);
|
|
425
|
|
426 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
|
|
427 assert (isatty(out));
|
|
428 s.main.c_oflag |= OPOST; /* Enable output postprocessing */
|
|
429 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */
|
|
430 #ifdef NLDLY
|
|
431 s.main.c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
|
|
432 /* No output delays */
|
|
433 #endif
|
|
434 s.main.c_lflag &= ~ECHO; /* Disable echo */
|
|
435 s.main.c_lflag |= ISIG; /* Enable signals */
|
|
436 #ifdef IUCLC
|
|
437 s.main.c_iflag &= ~IUCLC; /* Disable downcasing on input. */
|
|
438 #endif
|
|
439 #ifdef OLCUC
|
|
440 s.main.c_oflag &= ~OLCUC; /* Disable upcasing on output. */
|
|
441 #endif
|
100
|
442 s.main.c_oflag &= ~TAB3; /* Disable tab expansion */
|
0
|
443 #if defined (CSIZE) && defined (CS8)
|
|
444 s.main.c_cflag = (s.main.c_cflag & ~CSIZE) | CS8; /* Don't strip 8th bit */
|
|
445 #endif
|
|
446 #ifdef ISTRIP
|
|
447 s.main.c_iflag &= ~ISTRIP; /* Don't strip 8th bit on input */
|
|
448 #endif
|
|
449 #if 0
|
|
450 /* Unnecessary as long as ICANON is set */
|
|
451 s.main.c_cc[VMIN] = 1; /* minimum number of characters to accept */
|
|
452 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */
|
|
453 #endif /* 0 */
|
|
454
|
|
455 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */
|
175
|
456 s.main.c_cc[VEOF] = 04; /* ensure that EOF is Control-D */
|
0
|
457 s.main.c_cc[VERASE] = CDISABLE; /* disable erase processing */
|
|
458 s.main.c_cc[VKILL] = CDISABLE; /* disable kill processing */
|
|
459
|
|
460 #ifdef HPUX
|
|
461 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
|
|
462 #endif /* HPUX */
|
|
463
|
|
464 #ifdef AIX
|
|
465 #ifndef IBMR2AIX
|
|
466 /* AIX enhanced edit loses NULs, so disable it. */
|
|
467 s.main.c_line = 0;
|
|
468 s.main.c_iflag &= ~ASCEDIT;
|
|
469 #endif /* IBMR2AIX */
|
|
470 /* Also, PTY overloads NUL and BREAK.
|
|
471 don't ignore break, but don't signal either, so it looks like NUL.
|
|
472 This really serves a purpose only if running in an XTERM window
|
|
473 or via TELNET or the like, but does no harm elsewhere. */
|
|
474 s.main.c_iflag &= ~IGNBRK;
|
|
475 s.main.c_iflag &= ~BRKINT;
|
|
476 #endif /* AIX */
|
|
477 #ifdef SIGNALS_VIA_CHARACTERS
|
284
|
478 /* TTY `special characters' are used in process_send_signal
|
0
|
479 so set them here to something useful. */
|
|
480 s.main.c_cc[VQUIT] = '\\'&037; /* Control-\ */
|
|
481 s.main.c_cc[VINTR] = 'C' &037; /* Control-C */
|
284
|
482 s.main.c_cc[VSUSP] = 'Z' &037; /* Control-Z */
|
0
|
483 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
|
284
|
484 /* TTY `special characters' work better as signals, so disable
|
|
485 character forms */
|
0
|
486 s.main.c_cc[VQUIT] = CDISABLE;
|
|
487 s.main.c_cc[VINTR] = CDISABLE;
|
284
|
488 s.main.c_cc[VSUSP] = CDISABLE;
|
0
|
489 s.main.c_lflag &= ~ISIG;
|
|
490 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
|
|
491 s.main.c_cc[VEOL] = CDISABLE;
|
|
492 #if defined (CBAUD)
|
|
493 /* <mdiers> ### This is not portable. ###
|
|
494 POSIX does not specify CBAUD, and 4.4BSD does not have it.
|
|
495 Instead, POSIX suggests to use cfset{i,o}speed().
|
|
496 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal
|
|
497 I/O, O'Reilly 1991] */
|
|
498 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
|
|
499 #else
|
|
500 /* <mdiers> What to do upon failure? Just ignoring rc is probably
|
|
501 not acceptable, is it? */
|
|
502 if (cfsetispeed (&s.main, B9600) == -1) /* ignore */;
|
|
503 if (cfsetospeed (&s.main, B9600) == -1) /* ignore */;
|
|
504 #endif /* defined (CBAUD) */
|
|
505
|
|
506 #else /* not HAVE_TERMIO */
|
|
507
|
|
508 s.main.sg_flags &= ~(ECHO | CRMOD | ANYP | ALLDELAY | RAW | LCASE
|
|
509 | CBREAK | TANDEM);
|
|
510 s.main.sg_flags |= LPASS8;
|
|
511 s.main.sg_erase = 0377;
|
|
512 s.main.sg_kill = 0377;
|
|
513 s.lmode = LLITOUT | s.lmode; /* Don't strip 8th bit */
|
|
514
|
|
515 #endif /* not HAVE_TERMIO */
|
|
516 EMACS_SET_TTY (out, &s, 0);
|
|
517
|
|
518 #ifdef RTU
|
|
519 {
|
|
520 int zero = 0;
|
|
521 ioctl (out, FIOASYNC, &zero);
|
|
522 }
|
|
523 #endif /* RTU */
|
|
524 }
|
100
|
525 #endif /* WINDOWSNT */
|
0
|
526 #endif /* not MSDOS */
|
|
527
|
|
528 #endif /* not NO_SUBPROCESSES */
|
|
529
|
|
530
|
209
|
531 #if !defined (SIGTSTP) && !defined (USG_JOBCTRL)
|
0
|
532
|
239
|
533 #if defined(__STDC__) || defined(_MSC_VER)
|
|
534 #define SIG_PARAM_TYPE int
|
|
535 #else
|
|
536 #define SIG_PARAM_TYPE
|
|
537 #endif
|
|
538
|
0
|
539 /* Record a signal code and the handler for it. */
|
|
540 struct save_signal
|
|
541 {
|
|
542 int code;
|
239
|
543 SIGTYPE (*handler) (SIG_PARAM_TYPE);
|
0
|
544 };
|
|
545
|
|
546 static void
|
|
547 save_signal_handlers (struct save_signal *saved_handlers)
|
|
548 {
|
|
549 while (saved_handlers->code)
|
|
550 {
|
|
551 saved_handlers->handler
|
239
|
552 = (SIGTYPE (*) (SIG_PARAM_TYPE)) signal (saved_handlers->code, SIG_IGN);
|
0
|
553 saved_handlers++;
|
|
554 }
|
|
555 }
|
|
556
|
|
557 static void
|
|
558 restore_signal_handlers (struct save_signal *saved_handlers)
|
|
559 {
|
|
560 while (saved_handlers->code)
|
|
561 {
|
|
562 signal (saved_handlers->code, saved_handlers->handler);
|
|
563 saved_handlers++;
|
|
564 }
|
|
565 }
|
|
566
|
|
567 /* Fork a subshell. */
|
|
568 static void
|
|
569 sys_subshell (void)
|
|
570 {
|
|
571 #ifdef MSDOS
|
|
572 int st;
|
|
573 char oldwd[MAXPATHLEN+1]; /* Fixed length is safe on MSDOS. */
|
|
574 #endif /* MSDOS */
|
|
575 int pid;
|
|
576 struct save_signal saved_handlers[5];
|
|
577 Lisp_Object dir;
|
|
578 unsigned char *str = 0;
|
|
579 int len;
|
116
|
580 struct gcpro gcpro1;
|
0
|
581
|
|
582 saved_handlers[0].code = SIGINT;
|
|
583 saved_handlers[1].code = SIGQUIT;
|
|
584 saved_handlers[2].code = SIGTERM;
|
|
585 #ifdef SIGIO
|
|
586 saved_handlers[3].code = SIGIO;
|
|
587 saved_handlers[4].code = 0;
|
|
588 #else
|
|
589 saved_handlers[3].code = 0;
|
|
590 #endif
|
|
591
|
|
592 /* Mentioning current_buffer->buffer would mean including buffer.h,
|
|
593 which somehow wedges the hp compiler. So instead... */
|
|
594
|
|
595 if (NILP (Fboundp (Qdefault_directory)))
|
|
596 goto xyzzy;
|
|
597 dir = Fsymbol_value (Qdefault_directory);
|
|
598 if (!STRINGP (dir))
|
|
599 goto xyzzy;
|
116
|
600
|
|
601 GCPRO1 (dir);
|
|
602 dir = Funhandled_file_name_directory (dir);
|
|
603 dir = expand_and_dir_to_file (dir, Qnil);
|
|
604 UNGCPRO;
|
16
|
605 str = (unsigned char *) alloca (XSTRING_LENGTH (dir) + 2);
|
|
606 len = XSTRING_LENGTH (dir);
|
|
607 memcpy (str, XSTRING_DATA (dir), len);
|
0
|
608 /* #### Unix specific */
|
|
609 if (str[len - 1] != '/') str[len++] = '/';
|
|
610 str[len] = 0;
|
|
611 xyzzy:
|
|
612
|
179
|
613 #ifdef WINDOWSNT
|
|
614 pid = -1;
|
|
615 #else /* not WINDOWSNT */
|
|
616
|
211
|
617 pid = fork ();
|
0
|
618
|
|
619 if (pid == -1)
|
|
620 error ("Can't spawn subshell");
|
|
621 if (pid == 0)
|
179
|
622
|
|
623 #endif /* not WINDOWSNT */
|
0
|
624 {
|
|
625 char *sh = 0;
|
|
626
|
|
627 #ifdef MSDOS /* MW, Aug 1993 */
|
|
628 getwd (oldwd);
|
|
629 if (sh == 0)
|
|
630 sh = (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
|
|
631 #endif
|
|
632 if (sh == 0)
|
|
633 sh = (char *) egetenv ("SHELL");
|
|
634 if (sh == 0)
|
|
635 sh = "sh";
|
|
636
|
|
637 /* Use our buffer's default directory for the subshell. */
|
|
638 if (str)
|
|
639 sys_chdir (str);
|
|
640
|
263
|
641 #if !defined (NO_SUBPROCESSES) && !defined (WINDOWSNT)
|
0
|
642 close_process_descs (); /* Close Emacs's pipes/ptys */
|
|
643 #endif
|
|
644
|
|
645 #ifdef SET_EMACS_PRIORITY
|
|
646 if (emacs_priority != 0)
|
185
|
647 nice (-emacs_priority); /* Give the new shell the default priority */
|
0
|
648 #endif
|
|
649
|
|
650 #ifdef MSDOS
|
|
651 st = system (sh);
|
|
652 sys_chdir (oldwd);
|
|
653 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
|
|
654 if (st)
|
|
655 report_file_error ("Can't execute subshell",
|
|
656 Fcons (build_string (sh), Qnil));
|
|
657 #endif
|
|
658 #else /* not MSDOS */
|
179
|
659 #ifdef WINDOWSNT
|
|
660 /* Waits for process completion */
|
|
661 pid = _spawnlp (_P_WAIT, sh, sh, NULL);
|
|
662 if (pid == -1)
|
|
663 write (1, "Can't execute subshell", 22);
|
|
664
|
|
665 #if 0
|
|
666 /* This relates to the GNU Emacs console port, not required under X ? */
|
|
667 take_console ();
|
|
668 #endif
|
|
669 #else /* not WINDOWSNT */
|
0
|
670 execlp (sh, sh, 0);
|
|
671 write (1, "Can't execute subshell", 22);
|
|
672 _exit (1);
|
179
|
673 #endif /* not WINDOWSNT */
|
0
|
674 #endif /* not MSDOS */
|
|
675 }
|
|
676
|
|
677 save_signal_handlers (saved_handlers);
|
|
678 synch_process_alive = 1;
|
|
679 #ifndef MSDOS
|
|
680 wait_for_termination (pid);
|
|
681 #endif
|
|
682 restore_signal_handlers (saved_handlers);
|
|
683 }
|
|
684
|
209
|
685 #endif /* !defined (SIGTSTP) && !defined (USG_JOBCTRL) */
|
0
|
686
|
|
687
|
|
688
|
|
689 /* Suspend the Emacs process; give terminal to its superior. */
|
|
690 void
|
|
691 sys_suspend (void)
|
|
692 {
|
209
|
693 #if defined (SIGTSTP) && !defined (MSDOS)
|
0
|
694 {
|
|
695 int pgrp = EMACS_GET_PROCESS_GROUP ();
|
|
696 EMACS_KILLPG (pgrp, SIGTSTP);
|
|
697 }
|
|
698
|
|
699 #elif defined (USG_JOBCTRL)
|
|
700 /* If you don't know what this is don't mess with it */
|
|
701 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
|
|
702 kill (getpid (), SIGQUIT);
|
|
703
|
|
704 #else /* No SIGTSTP or USG_JOBCTRL */
|
|
705
|
|
706 /* On a system where suspending is not implemented,
|
|
707 instead fork a subshell and let it talk directly to the terminal
|
|
708 while we wait. */
|
|
709 sys_subshell ();
|
|
710
|
|
711 #endif
|
|
712 }
|
|
713
|
108
|
714 /* Suspend a process if possible; give terminal to its superior. */
|
|
715 void
|
185
|
716 sys_suspend_process (int process)
|
108
|
717 {
|
|
718 /* I don't doubt that it is possible to suspend processes on
|
|
719 * VMS machines or thost that use USG_JOBCTRL,
|
|
720 * but I don't know how to do it, so...
|
|
721 */
|
|
722 #if defined (SIGTSTP) && !defined (MSDOS)
|
|
723 kill(process, SIGTSTP);
|
|
724 #endif
|
|
725 }
|
263
|
726
|
|
727
|
|
728 /* Given FD, obtain pty buffer size. When no luck, a good guess is made,
|
|
729 so that the function works even fd is not a pty. */
|
|
730
|
|
731 int
|
|
732 get_pty_max_bytes (int fd)
|
|
733 {
|
|
734 int pty_max_bytes;
|
|
735
|
|
736 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
|
|
737 pty_max_bytes = fpathconf (fd, _PC_MAX_CANON);
|
|
738 if (pty_max_bytes < 0)
|
|
739 #endif
|
|
740 pty_max_bytes = 250;
|
|
741
|
|
742 /* Deduct one, to leave space for the eof. */
|
|
743 pty_max_bytes--;
|
|
744
|
|
745 return pty_max_bytes;
|
|
746 }
|
|
747
|
|
748 /* Figure out the eof character for the FD. */
|
|
749
|
|
750 Bufbyte
|
|
751 get_eof_char (int fd)
|
|
752 {
|
|
753 CONST Bufbyte ctrl_d = (Bufbyte) '\004';
|
|
754
|
|
755 if (!isatty (fd))
|
|
756 return ctrl_d;
|
|
757 #ifdef HAVE_TERMIOS
|
|
758 {
|
|
759 struct termios t;
|
|
760 tcgetattr (fd, &t);
|
|
761 #if 0
|
|
762 /* What is the following line designed to do??? -mrb */
|
|
763 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1))
|
|
764 return ctrl_d;
|
|
765 else
|
|
766 return (Bufbyte) t.c_cc[VEOF];
|
|
767 #endif
|
|
768 return t.c_cc[VEOF] == CDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF];
|
|
769 }
|
|
770 #else /* ! HAVE_TERMIOS */
|
|
771 /* On Berkeley descendants, the following IOCTL's retrieve the
|
|
772 current control characters. */
|
|
773 #if defined (TIOCGETC)
|
|
774 {
|
|
775 struct tchars c;
|
|
776 ioctl (fd, TIOCGETC, &c);
|
|
777 return (Bufbyte) c.t_eofc;
|
|
778 }
|
|
779 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
|
|
780 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
|
|
781 characters. */
|
|
782 #ifdef TCGETA
|
|
783 {
|
|
784 struct termio t;
|
|
785 ioctl (fd, TCGETA, &t);
|
|
786 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VINTR + 1))
|
|
787 return ctrl_d;
|
|
788 else
|
|
789 return (Bufbyte) t.c_cc[VINTR];
|
|
790 }
|
|
791 #else /* ! defined (TCGETA) */
|
|
792 /* Rather than complain, we'll just guess ^D, which is what
|
|
793 * earlier emacsen always used. */
|
|
794 return ctrl_d;
|
|
795 #endif /* ! defined (TCGETA) */
|
|
796 #endif /* ! defined (TIOCGETC) */
|
|
797 #endif /* ! defined (HAVE_TERMIOS) */
|
|
798 }
|
108
|
799
|
0
|
800 /* Set the logical window size associated with descriptor FD
|
|
801 to HEIGHT and WIDTH. This is used mainly with ptys. */
|
|
802
|
|
803 int
|
|
804 set_window_size (int fd, int height, int width)
|
|
805 {
|
|
806 #ifdef TIOCSWINSZ
|
|
807
|
|
808 /* BSD-style. */
|
|
809 struct winsize size;
|
|
810 size.ws_row = height;
|
|
811 size.ws_col = width;
|
|
812
|
|
813 if (ioctl (fd, TIOCSWINSZ, &size) == -1)
|
|
814 return 0; /* error */
|
|
815 else
|
|
816 return 1;
|
|
817
|
|
818 #elif defined (TIOCSSIZE)
|
|
819
|
|
820 /* SunOS - style. */
|
185
|
821 struct ttysize size;
|
0
|
822 size.ts_lines = height;
|
|
823 size.ts_cols = width;
|
|
824
|
|
825 if (ioctl (fd, TIOCGSIZE, &size) == -1)
|
|
826 return 0;
|
|
827 else
|
|
828 return 1;
|
|
829 #else
|
|
830 return -1;
|
|
831 #endif
|
|
832 }
|
|
833
|
|
834 #ifdef HAVE_PTYS
|
|
835
|
|
836 /* Set up the proper status flags for use of a pty. */
|
|
837
|
|
838 void
|
|
839 setup_pty (int fd)
|
|
840 {
|
|
841 /* I'm told that TOICREMOTE does not mean control chars
|
|
842 "can't be sent" but rather that they don't have
|
|
843 input-editing or signaling effects.
|
|
844 That should be good, because we have other ways
|
|
845 to do those things in Emacs.
|
|
846 However, telnet mode seems not to work on 4.2.
|
|
847 So TIOCREMOTE is turned off now. */
|
|
848
|
|
849 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
|
|
850 will hang. In particular, the "timeout" feature (which
|
|
851 causes a read to return if there is no data available)
|
|
852 does this. Also it is known that telnet mode will hang
|
|
853 in such a way that Emacs must be stopped (perhaps this
|
|
854 is the same problem).
|
185
|
855
|
0
|
856 If TIOCREMOTE is turned off, then there is a bug in
|
|
857 hp-ux which sometimes loses data. Apparently the
|
|
858 code which blocks the master process when the internal
|
|
859 buffer fills up does not work. Other than this,
|
|
860 though, everything else seems to work fine.
|
185
|
861
|
0
|
862 Since the latter lossage is more benign, we may as well
|
|
863 lose that way. -- cph */
|
|
864 #if defined (FIONBIO) && defined (SYSV_PTYS)
|
|
865 {
|
|
866 int on = 1;
|
|
867 ioctl (fd, FIONBIO, &on);
|
|
868 }
|
|
869 #endif
|
|
870 #ifdef IBMRTAIX
|
|
871 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
|
|
872 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
|
|
873 /* cause EMACS not to die when it should, i.e., when its own controlling */
|
|
874 /* tty goes away. I've complained to the AIX developers, and they may */
|
|
875 /* change this behavior, but I'm not going to hold my breath. */
|
|
876 signal (SIGHUP, SIG_IGN);
|
|
877 #endif
|
|
878 #ifdef TIOCPKT
|
|
879 /* In some systems (Linux through 2.0.0, at least), packet mode doesn't
|
|
880 get cleared when a pty is closed, so we need to clear it here.
|
|
881 Linux pre2.0.13 contained an attempted fix for this (from Ted Ts'o,
|
|
882 tytso@mit.edu), but apparently it messed up rlogind and telnetd, so he
|
|
883 removed the fix in pre2.0.14. - dkindred@cs.cmu.edu
|
|
884 */
|
|
885 {
|
|
886 int off = 0;
|
|
887 ioctl (fd, TIOCPKT, (char *)&off);
|
|
888 }
|
|
889 #endif
|
|
890 }
|
|
891 #endif /* HAVE_PTYS */
|
|
892
|
|
893
|
|
894 /************************************************************************/
|
|
895 /* TTY control */
|
|
896 /************************************************************************/
|
|
897
|
|
898 /* ------------------------------------------------------ */
|
|
899 /* get baud rate */
|
|
900 /* ------------------------------------------------------ */
|
|
901
|
|
902 /* It really makes more sense for the baud-rate to be console-specific
|
|
903 and not device-specific, but it's (at least potentially) used for output
|
|
904 decisions. */
|
|
905
|
|
906 void
|
|
907 init_baud_rate (struct device *d)
|
|
908 {
|
|
909 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
910 if (DEVICE_WIN_P (d) || DEVICE_STREAM_P (d))
|
|
911 {
|
|
912 DEVICE_BAUD_RATE (d) = 38400;
|
|
913 return;
|
|
914 }
|
|
915
|
|
916 #ifdef HAVE_TTY
|
|
917 assert (DEVICE_TTY_P (d));
|
|
918 {
|
|
919 int input_fd = CONSOLE_TTY_DATA (con)->infd;
|
209
|
920 #if defined (MSDOS) || defined(WIN32)
|
0
|
921 DEVICE_TTY_DATA (d)->ospeed = 15;
|
|
922 #elif defined (HAVE_TERMIOS)
|
|
923 struct termios sg;
|
185
|
924
|
0
|
925 sg.c_cflag = B9600;
|
|
926 tcgetattr (input_fd, &sg);
|
|
927 DEVICE_TTY_DATA (d)->ospeed = cfgetospeed (&sg);
|
|
928 # if defined (USE_GETOBAUD) && defined (getobaud)
|
|
929 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
|
|
930 if (DEVICE_TTY_DATA (d)->ospeed == 0)
|
|
931 DEVICE_TTY_DATA (d)->ospeed = getobaud (sg.c_cflag);
|
|
932 # endif
|
|
933 #elif defined (HAVE_TERMIO)
|
|
934 struct termio sg;
|
185
|
935
|
0
|
936 sg.c_cflag = B9600;
|
|
937 # ifdef HAVE_TCATTR
|
|
938 tcgetattr (input_fd, &sg);
|
|
939 # else
|
|
940 ioctl (input_fd, TCGETA, &sg);
|
|
941 # endif
|
|
942 DEVICE_TTY_DATA (d)->ospeed = sg.c_cflag & CBAUD;
|
209
|
943 #else /* neither TERMIOS nor TERMIO */
|
0
|
944 struct sgttyb sg;
|
185
|
945
|
0
|
946 sg.sg_ospeed = B9600;
|
|
947 if (ioctl (input_fd, TIOCGETP, &sg) < 0)
|
|
948 abort ();
|
|
949 DEVICE_TTY_DATA (d)->ospeed = sg.sg_ospeed;
|
|
950 #endif
|
|
951 }
|
185
|
952
|
0
|
953 DEVICE_BAUD_RATE (d) =
|
272
|
954 (DEVICE_TTY_DATA (d)->ospeed < countof (baud_convert)
|
0
|
955 ? baud_convert[DEVICE_TTY_DATA (d)->ospeed]
|
|
956 : 9600);
|
|
957
|
|
958 if (DEVICE_BAUD_RATE (d) == 0)
|
|
959 DEVICE_BAUD_RATE (d) = 1200;
|
|
960 #endif /* HAVE_TTY */
|
|
961 }
|
|
962
|
|
963
|
|
964 /* ------------------------------------------------------ */
|
|
965 /* SIGIO control */
|
|
966 /* ------------------------------------------------------ */
|
|
967
|
251
|
968 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
|
0
|
969
|
|
970 static void
|
|
971 init_sigio_on_device (struct device *d)
|
|
972 {
|
|
973 int filedesc = DEVICE_INFD (d);
|
|
974
|
|
975 #if defined (FIOSSAIOOWN)
|
|
976 { /* HPUX stuff */
|
|
977 int owner = getpid ();
|
|
978 int ioctl_status;
|
|
979 if (DEVICE_TTY_P (d))
|
|
980 {
|
|
981 ioctl_status = ioctl (filedesc, FIOGSAIOOWN,
|
|
982 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
983 ioctl_status = ioctl (filedesc, FIOSSAIOOWN, &owner);
|
|
984 }
|
|
985 #ifdef HAVE_WINDOW_SYSTEM
|
|
986 else if (!DEVICE_STREAM_P (d))
|
|
987 {
|
|
988 ioctl_status = ioctl (filedesc, SIOCGPGRP,
|
|
989 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
990 ioctl_status = ioctl (filedesc, SIOCSPGRP, &owner);
|
|
991 }
|
|
992 #endif
|
|
993 }
|
|
994 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
|
|
995 DEVICE_OLD_FCNTL_OWNER (d) = fcntl (filedesc, F_GETOWN, 0);
|
|
996 # ifdef F_SETOWN_SOCK_NEG
|
|
997 /* stdin is a socket here */
|
|
998 fcntl (filedesc, F_SETOWN, -getpid ());
|
|
999 # else
|
|
1000 fcntl (filedesc, F_SETOWN, getpid ());
|
|
1001 # endif
|
|
1002 #endif
|
|
1003 }
|
|
1004
|
|
1005 static void
|
|
1006 reset_sigio_on_device (struct device *d)
|
|
1007 {
|
|
1008 int filedesc = DEVICE_INFD (d);
|
|
1009
|
|
1010 #if defined (FIOSSAIOOWN)
|
|
1011 { /* HPUX stuff */
|
|
1012 int ioctl_status;
|
|
1013 if (DEVICE_TTY_P (d))
|
|
1014 {
|
|
1015 ioctl_status = ioctl (filedesc, FIOSSAIOOWN,
|
|
1016 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
1017 }
|
|
1018 #ifdef HAVE_WINDOW_SYSTEM
|
|
1019 else if (!DEVICE_STREAM_P (d))
|
|
1020 {
|
|
1021 ioctl_status = ioctl (filedesc, SIOCSPGRP,
|
|
1022 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
1023 }
|
|
1024 #endif
|
|
1025 }
|
|
1026 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
|
|
1027 fcntl (filedesc, F_SETOWN, DEVICE_OLD_FCNTL_OWNER (d));
|
|
1028 #endif
|
|
1029 }
|
|
1030
|
|
1031 static void
|
|
1032 request_sigio_on_device (struct device *d)
|
|
1033 {
|
|
1034 int filedesc = DEVICE_INFD (d);
|
|
1035
|
2
|
1036 #if defined (I_SETSIG) && !defined(HPUX10)
|
259
|
1037 {
|
|
1038 int events=0;
|
|
1039 ioctl (filedesc, I_GETSIG, &events);
|
|
1040 ioctl (filedesc, I_SETSIG, events | S_INPUT);
|
|
1041 }
|
0
|
1042 #elif defined (FASYNC)
|
259
|
1043 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) | FASYNC);
|
0
|
1044 #elif defined (FIOSSAIOSTAT)
|
|
1045 {
|
|
1046 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
|
|
1047 sockets and other devices for some bizarre reason. We guess
|
|
1048 that an X device is a socket, and tty devices aren't. We then
|
|
1049 use the following crud to do the appropriate thing. */
|
|
1050 int on = 1;
|
|
1051 int ioctl_status; /* ####DG: check if IOCTL succeeds here. */
|
|
1052
|
|
1053 if (DEVICE_TTY_P (d))
|
|
1054 {
|
|
1055 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &on);
|
|
1056 }
|
|
1057 #ifdef HAVE_WINDOW_SYSTEM
|
|
1058 else if (!DEVICE_STREAM_P (d))
|
|
1059 {
|
|
1060 ioctl_status = ioctl (filedesc, FIOASYNC, &on);
|
|
1061 }
|
|
1062 #endif
|
|
1063 }
|
|
1064 #elif defined (FIOASYNC)
|
|
1065 {
|
|
1066 int on = 1;
|
|
1067 ioctl (filedesc, FIOASYNC, &on);
|
|
1068 }
|
|
1069 #endif
|
|
1070
|
|
1071 #if defined (_CX_UX) /* #### Is this crap necessary? */
|
|
1072 EMACS_UNBLOCK_SIGNAL (SIGIO);
|
|
1073 #endif
|
|
1074 }
|
|
1075
|
|
1076 static void
|
|
1077 unrequest_sigio_on_device (struct device *d)
|
|
1078 {
|
|
1079 int filedesc = DEVICE_INFD (d);
|
|
1080
|
2
|
1081 #if defined (I_SETSIG) && !defined(HPUX10)
|
259
|
1082 {
|
|
1083 int events=0;
|
|
1084 ioctl (filedesc, I_GETSIG, &events);
|
|
1085 ioctl (filedesc, I_SETSIG, events & ~S_INPUT);
|
|
1086 }
|
0
|
1087 #elif defined (FASYNC)
|
259
|
1088 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) & ~FASYNC);
|
0
|
1089 #elif defined (FIOSSAIOSTAT)
|
|
1090 {
|
|
1091 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
|
|
1092 sockets and other devices for some bizarre reason. We guess
|
|
1093 that an X device is a socket, and tty devices aren't. We then
|
|
1094 use the following crud to do the appropriate thing. */
|
|
1095
|
|
1096 int off = 0;
|
|
1097 int ioctl_status;
|
|
1098
|
|
1099 /* See comment for request_sigio_on_device */
|
|
1100
|
|
1101 if (DEVICE_TTY_P (d))
|
|
1102 {
|
|
1103 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &off);
|
|
1104 }
|
185
|
1105 else
|
0
|
1106 {
|
|
1107 ioctl_status = ioctl (filedesc, FIOASYNC, &off);
|
|
1108 }
|
|
1109 }
|
|
1110 #elif defined (FIOASYNC)
|
|
1111 {
|
|
1112 int off = 0;
|
|
1113 ioctl (filedesc, FIOASYNC, &off);
|
|
1114 }
|
|
1115 #endif
|
|
1116 }
|
|
1117
|
|
1118 void
|
|
1119 request_sigio (void)
|
|
1120 {
|
|
1121 Lisp_Object devcons, concons;
|
|
1122
|
|
1123 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1124 {
|
|
1125 struct device *d;
|
|
1126
|
|
1127 d = XDEVICE (XCAR (devcons));
|
|
1128
|
|
1129 if (!DEVICE_STREAM_P (d))
|
|
1130 request_sigio_on_device (d);
|
|
1131 }
|
|
1132 }
|
|
1133
|
|
1134 void
|
|
1135 unrequest_sigio (void)
|
|
1136 {
|
|
1137 Lisp_Object devcons, concons;
|
|
1138
|
|
1139 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1140 {
|
|
1141 struct device *d;
|
|
1142
|
|
1143 d = XDEVICE (XCAR (devcons));
|
|
1144
|
|
1145 if (!DEVICE_STREAM_P (d))
|
|
1146 unrequest_sigio_on_device (d);
|
|
1147 }
|
|
1148 }
|
|
1149
|
|
1150 #endif /* SIGIO */
|
|
1151
|
|
1152 /* ------------------------------------------------------ */
|
|
1153 /* Changing Emacs's process group */
|
|
1154 /* ------------------------------------------------------ */
|
|
1155
|
|
1156 /* Saving and restoring the process group of Emacs's terminal. */
|
|
1157
|
|
1158 /* On some systems, apparently (?!) Emacs must be in its own process
|
|
1159 group in order to receive SIGIO correctly. On other systems
|
|
1160 (e.g. Solaris), it's not required and doing it makes things
|
|
1161 get fucked up. So, we only do it when
|
|
1162 SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP is defined. Basically,
|
|
1163 this is only required for BSD 4.2 systems. (Actually, I bet
|
|
1164 we don't have to do this at all -- those systems also
|
|
1165 required interrupt input, which we don't support.)
|
|
1166
|
|
1167 If Emacs was in its own process group (i.e. inherited_pgroup ==
|
|
1168 getpid ()), then we know we're running under a shell with job
|
|
1169 control (Emacs would never be run as part of a pipeline).
|
|
1170 Everything is fine.
|
|
1171
|
|
1172 If Emacs was not in its own process group, then we know we're
|
|
1173 running under a shell (or a caller) that doesn't know how to
|
|
1174 separate itself from Emacs (like sh). Emacs must be in its own
|
|
1175 process group in order to receive SIGIO correctly. In this
|
|
1176 situation, we put ourselves in our own pgroup, forcibly set the
|
|
1177 tty's pgroup to our pgroup, and make sure to restore and reinstate
|
|
1178 the tty's pgroup just like any other terminal setting. If
|
|
1179 inherited_group was not the tty's pgroup, then we'll get a
|
|
1180 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
|
|
1181 it goes foreground in the future, which is what should happen. */
|
|
1182
|
|
1183 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1184
|
|
1185 static int inherited_pgroup;
|
|
1186 static int inherited_tty_pgroup;
|
|
1187
|
|
1188 #endif
|
|
1189
|
|
1190 void
|
|
1191 munge_tty_process_group (void)
|
|
1192 {
|
|
1193 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1194 if (noninteractive)
|
|
1195 return;
|
|
1196
|
|
1197 /* Only do this munging if we have a device on the controlling
|
|
1198 terminal. See the large comment below. */
|
|
1199
|
|
1200 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
1201 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
1202 {
|
|
1203 int fd = open ("/dev/tty", O_RDWR, 0);
|
|
1204 int me = getpid ();
|
|
1205 EMACS_BLOCK_SIGNAL (SIGTTOU);
|
|
1206 EMACS_SET_TTY_PROCESS_GROUP (fd, &me);
|
|
1207 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
|
|
1208 close (fd);
|
|
1209 }
|
|
1210 #endif
|
|
1211 }
|
|
1212
|
|
1213 /* Split off the foreground process group to Emacs alone.
|
|
1214 When we are in the foreground, but not started in our own process
|
|
1215 group, redirect the TTY to point to our own process group. We need
|
|
1216 to be in our own process group to receive SIGIO properly. */
|
|
1217 static void
|
|
1218 munge_process_groups (void)
|
|
1219 {
|
|
1220 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1221 if (noninteractive)
|
|
1222 return;
|
|
1223
|
|
1224 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
1225
|
|
1226 munge_tty_process_group ();
|
|
1227 #endif
|
|
1228 }
|
|
1229
|
|
1230 void
|
|
1231 unmunge_tty_process_group (void)
|
|
1232 {
|
|
1233 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1234 {
|
|
1235 int fd = open ("/dev/tty", O_RDWR, 0);
|
|
1236 EMACS_BLOCK_SIGNAL (SIGTTOU);
|
|
1237 EMACS_SET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
|
|
1238 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
|
|
1239 close (fd);
|
|
1240 }
|
|
1241 #endif
|
|
1242 }
|
|
1243
|
|
1244 /* Set the tty to our original foreground group.
|
|
1245 Also restore the original process group (put us back into sh's
|
|
1246 process group), so that ^Z will suspend both us and sh. */
|
|
1247 static void
|
|
1248 unmunge_process_groups (void)
|
|
1249 {
|
|
1250 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1251 if (noninteractive)
|
|
1252 return;
|
|
1253
|
|
1254 unmunge_tty_process_group ();
|
|
1255
|
|
1256 EMACS_SET_PROCESS_GROUP (inherited_pgroup);
|
|
1257 #endif
|
|
1258 }
|
|
1259
|
|
1260 /* According to some old wisdom, we need to be in a separate process
|
|
1261 group for SIGIO to work correctly (at least on some systems ...).
|
|
1262 So go ahead and put ourselves into our own process group. This
|
|
1263 will fail if we're already in our own process group, but who cares.
|
|
1264 Also record whether we were in our own process group. (In general,
|
|
1265 we will already be in our own process group if we were started from
|
|
1266 a job-control shell like csh, but not if we were started from sh).
|
185
|
1267
|
0
|
1268 If we succeeded in changing our process group, then we will no
|
|
1269 longer be in the foreground process group of our controlling
|
|
1270 terminal. Therefore, if we have a console open onto this terminal,
|
|
1271 we have to change the controlling terminal's foreground process
|
|
1272 group (otherwise we will get stopped with a SIGTTIN signal when
|
|
1273 attempting to read from the terminal). It's important,
|
|
1274 however, that we do this *only* when we have a console open onto
|
|
1275 the terminal. It's a decidedly bad idea to do so otherwise,
|
|
1276 especially if XEmacs was started from the background. */
|
|
1277
|
|
1278 void
|
|
1279 init_process_group (void)
|
|
1280 {
|
|
1281 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1282 if (! noninteractive)
|
|
1283 {
|
|
1284 int fd = open ("/dev/tty", O_RDWR, 0);
|
|
1285 inherited_pgroup = EMACS_GET_PROCESS_GROUP ();
|
|
1286 EMACS_GET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
|
|
1287 close (fd);
|
|
1288 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
1289 }
|
|
1290 #endif
|
|
1291 }
|
|
1292
|
|
1293 void
|
|
1294 disconnect_controlling_terminal (void)
|
|
1295 {
|
|
1296 # ifdef HAVE_SETSID
|
|
1297 /* Controlling terminals are attached to a session.
|
|
1298 Create a new session for us; it will have no controlling
|
|
1299 terminal. This also, of course, puts us in our own
|
|
1300 process group. */
|
|
1301 setsid ();
|
|
1302 # else
|
|
1303 /* Put us in our own process group. */
|
|
1304 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
1305 # if defined (TIOCNOTTY)
|
|
1306 /* This is the older way of disconnecting the controlling
|
|
1307 terminal, on 4.3 BSD. We must open /dev/tty; using
|
|
1308 filedesc 0 is not sufficient because it could be
|
|
1309 something else (e.g. our stdin was redirected to
|
|
1310 another terminal).
|
|
1311 */
|
|
1312 {
|
|
1313 int j = open ("/dev/tty", O_RDWR, 0);
|
|
1314 ioctl (j, TIOCNOTTY, 0);
|
|
1315 close (j);
|
|
1316 }
|
|
1317 # endif /* TIOCNOTTY */
|
|
1318 /*
|
|
1319 On systems without TIOCNOTTY and without
|
|
1320 setsid(), we don't need to do anything more to
|
|
1321 disconnect our controlling terminal. Here is
|
|
1322 what the man page for termio(7) from a SYSV 3.2
|
|
1323 system says:
|
185
|
1324
|
0
|
1325 "The first terminal file opened by the process group leader
|
|
1326 of a terminal file not already associated with a process
|
|
1327 group becomes the control terminal for that process group.
|
|
1328 The control terminal plays a special role in handling quit
|
|
1329 and interrupt signals, as discussed below. The control
|
|
1330 terminal is inherited by a child process during a fork(2).
|
|
1331 A process can break this association by changing its process
|
|
1332 group using setpgrp(2)."
|
185
|
1333
|
0
|
1334 */
|
|
1335 # endif /* not HAVE_SETSID */
|
|
1336 }
|
|
1337
|
|
1338
|
|
1339 /* ------------------------------------------------------ */
|
|
1340 /* Getting and setting emacs_tty structures */
|
|
1341 /* ------------------------------------------------------ */
|
|
1342
|
153
|
1343 /* It's wrong to encase these into #ifdef HAVE_TTY because we need
|
|
1344 them for child TTY processes. */
|
157
|
1345 /* However, this does break NT support while we don't do child TTY processes */
|
|
1346 #ifndef WINDOWSNT
|
100
|
1347
|
0
|
1348 /* Set *TC to the parameters associated with the terminal FD.
|
|
1349 Return zero if all's well, or -1 if we ran into an error we
|
|
1350 couldn't deal with. */
|
|
1351 int
|
|
1352 emacs_get_tty (int fd, struct emacs_tty *settings)
|
|
1353 {
|
|
1354 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
|
|
1355 #ifdef HAVE_TCATTR
|
|
1356 /* We have those nifty POSIX tcmumbleattr functions. */
|
|
1357 if (tcgetattr (fd, &settings->main) < 0)
|
|
1358 return -1;
|
|
1359
|
209
|
1360 #elif defined HAVE_TERMIO
|
0
|
1361 /* The SYSV-style interface? */
|
|
1362 if (ioctl (fd, TCGETA, &settings->main) < 0)
|
|
1363 return -1;
|
|
1364
|
209
|
1365 #elif !defined MSDOS && !defined(WIN32)
|
0
|
1366 /* I give up - I hope you have the BSD ioctls. */
|
|
1367 if (ioctl (fd, TIOCGETP, &settings->main) < 0)
|
|
1368 return -1;
|
|
1369 #endif /* HAVE_TCATTR */
|
|
1370
|
|
1371 /* Suivant - Do we have to get struct ltchars data? */
|
|
1372 #ifdef HAVE_LTCHARS
|
|
1373 if (ioctl (fd, TIOCGLTC, &settings->ltchars) < 0)
|
|
1374 return -1;
|
|
1375 #endif
|
|
1376
|
|
1377 /* How about a struct tchars and a wordful of lmode bits? */
|
|
1378 #ifdef HAVE_TCHARS
|
|
1379 if (ioctl (fd, TIOCGETC, &settings->tchars) < 0
|
|
1380 || ioctl (fd, TIOCLGET, &settings->lmode) < 0)
|
|
1381 return -1;
|
|
1382 #endif
|
|
1383
|
|
1384 /* We have survived the tempest. */
|
|
1385 return 0;
|
|
1386 }
|
|
1387
|
|
1388 /* Set the parameters of the tty on FD according to the contents of
|
|
1389 *SETTINGS. If FLUSHP is non-zero, we discard input.
|
|
1390 Return 0 if all went well, and -1 if anything failed. */
|
|
1391
|
|
1392 int
|
|
1393 emacs_set_tty (int fd, struct emacs_tty *settings, int flushp)
|
|
1394 {
|
|
1395 /* Set the primary parameters - baud rate, character size, etcetera. */
|
|
1396 #ifdef HAVE_TCATTR
|
|
1397 int i;
|
|
1398 /* We have those nifty POSIX tcmumbleattr functions.
|
|
1399 William J. Smith <wjs@wiis.wang.com> writes:
|
|
1400 "POSIX 1003.1 defines tcsetattr() to return success if it was
|
|
1401 able to perform any of the requested actions, even if some
|
|
1402 of the requested actions could not be performed.
|
|
1403 We must read settings back to ensure tty setup properly.
|
|
1404 AIX requires this to keep tty from hanging occasionally." */
|
|
1405 /* This makes sure that we don't loop indefinitely in here. */
|
|
1406 for (i = 0 ; i < 10 ; i++)
|
|
1407 if (tcsetattr (fd, flushp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0)
|
|
1408 {
|
|
1409 if (errno == EINTR)
|
|
1410 continue;
|
|
1411 else
|
|
1412 return -1;
|
|
1413 }
|
|
1414 else
|
|
1415 {
|
|
1416 struct termios new;
|
|
1417
|
|
1418 /* Get the current settings, and see if they're what we asked for. */
|
|
1419 tcgetattr (fd, &new);
|
|
1420 /* We cannot use memcmp on the whole structure here because under
|
|
1421 * aix386 the termios structure has some reserved field that may
|
|
1422 * not be filled in.
|
|
1423 */
|
|
1424 if ( new.c_iflag == settings->main.c_iflag
|
|
1425 && new.c_oflag == settings->main.c_oflag
|
|
1426 && new.c_cflag == settings->main.c_cflag
|
|
1427 && new.c_lflag == settings->main.c_lflag
|
|
1428 && memcmp(new.c_cc, settings->main.c_cc, NCCS) == 0)
|
|
1429 break;
|
|
1430 else
|
|
1431 continue;
|
|
1432 }
|
209
|
1433 #elif defined HAVE_TERMIO
|
0
|
1434 /* The SYSV-style interface? */
|
|
1435 if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0)
|
|
1436 return -1;
|
|
1437
|
209
|
1438 #elif !defined(MSDOS) && !defined(WIN32)
|
0
|
1439 /* I give up - I hope you have the BSD ioctls. */
|
|
1440 if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
|
|
1441 return -1;
|
|
1442 #endif /* HAVE_TCATTR */
|
|
1443
|
|
1444 /* Suivant - Do we have to get struct ltchars data? */
|
|
1445 #ifdef HAVE_LTCHARS
|
|
1446 if (ioctl (fd, TIOCSLTC, &settings->ltchars) < 0)
|
|
1447 return -1;
|
|
1448 #endif
|
|
1449
|
|
1450 /* How about a struct tchars and a wordful of lmode bits? */
|
|
1451 #ifdef HAVE_TCHARS
|
|
1452 if (ioctl (fd, TIOCSETC, &settings->tchars) < 0
|
|
1453 || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
|
|
1454 return -1;
|
|
1455 #endif
|
185
|
1456
|
0
|
1457 /* We have survived the tempest. */
|
|
1458 return 0;
|
|
1459 }
|
|
1460
|
157
|
1461 #endif /* WINDOWSNT */
|
0
|
1462
|
|
1463 /* ------------------------------------------------------ */
|
|
1464 /* Initializing a device */
|
|
1465 /* ------------------------------------------------------ */
|
|
1466
|
|
1467 #ifdef HAVE_TTY
|
|
1468
|
|
1469 /* This may also be defined in stdio,
|
|
1470 but if so, this does no harm,
|
|
1471 and using the same name avoids wasting the other one's space. */
|
|
1472
|
|
1473 #if ((defined(USG) || defined(DGUX)) && !defined(__STDC__))
|
|
1474 char _sobuf[BUFSIZ+8];
|
|
1475 #elif (defined(USG) && !defined(LINUX) && !defined(_SCO_DS)) || defined(IRIX5)
|
|
1476 extern unsigned char _sobuf[BUFSIZ+8];
|
|
1477 #else
|
|
1478 char _sobuf[BUFSIZ];
|
|
1479 #endif
|
185
|
1480
|
0
|
1481 #if defined (TIOCGLTC) && defined (HAVE_LTCHARS) /* HAVE_LTCHARS */
|
|
1482 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
|
|
1483 #endif
|
|
1484 #ifdef TIOCGETC /* HAVE_TCHARS */
|
|
1485 #ifdef HAVE_TCHARS
|
|
1486 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
|
|
1487 #endif
|
185
|
1488 #endif
|
0
|
1489
|
|
1490 static void
|
|
1491 tty_init_sys_modes_on_device (struct device *d)
|
|
1492 {
|
|
1493 struct emacs_tty tty;
|
|
1494 int input_fd, output_fd;
|
|
1495 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1496
|
|
1497 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
1498 output_fd = CONSOLE_TTY_DATA (con)->outfd;
|
|
1499
|
|
1500 EMACS_GET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty);
|
|
1501 tty = CONSOLE_TTY_DATA (con)->old_tty;
|
|
1502
|
155
|
1503 con->tty_erase_char = Qnil;
|
|
1504
|
0
|
1505 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
|
155
|
1506 /* after all those years... */
|
|
1507 con->tty_erase_char = make_char (tty.main.c_cc[VERASE]);
|
0
|
1508 #ifdef DGUX
|
|
1509 /* This allows meta to be sent on 8th bit. */
|
|
1510 tty.main.c_iflag &= ~INPCK; /* don't check input for parity */
|
|
1511 #endif
|
|
1512 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */
|
|
1513 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */
|
|
1514 #ifdef ISTRIP
|
|
1515 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */
|
|
1516 #endif
|
|
1517 tty.main.c_lflag &= ~ECHO; /* Disable echo */
|
|
1518 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */
|
|
1519 #ifdef IEXTEN
|
|
1520 tty.main.c_lflag &= ~IEXTEN; /* Disable other editing characters. */
|
|
1521 #endif
|
|
1522 tty.main.c_lflag |= ISIG; /* Enable signals */
|
|
1523 if (TTY_FLAGS (con).flow_control)
|
|
1524 {
|
|
1525 tty.main.c_iflag |= IXON; /* Enable start/stop output control */
|
|
1526 #ifdef IXANY
|
|
1527 tty.main.c_iflag &= ~IXANY;
|
|
1528 #endif /* IXANY */
|
|
1529 }
|
|
1530 else
|
|
1531 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */
|
185
|
1532 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL
|
0
|
1533 on output */
|
|
1534 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */
|
|
1535 #ifdef CS8
|
|
1536 if (TTY_FLAGS (con).meta_key)
|
|
1537 {
|
|
1538 tty.main.c_cflag |= CS8; /* allow 8th bit on input */
|
|
1539 tty.main.c_cflag &= ~PARENB;/* Don't check parity */
|
|
1540 }
|
|
1541 #endif
|
|
1542 if (CONSOLE_TTY_DATA (con)->controlling_terminal)
|
|
1543 {
|
|
1544 tty.main.c_cc[VINTR] =
|
|
1545 CONSOLE_QUIT_CHAR (con); /* C-g (usually) gives SIGINT */
|
|
1546 /* Set up C-g for both SIGQUIT and SIGINT.
|
|
1547 We don't know which we will get, but we handle both alike
|
|
1548 so which one it really gives us does not matter. */
|
|
1549 tty.main.c_cc[VQUIT] = CONSOLE_QUIT_CHAR (con);
|
|
1550 }
|
|
1551 else
|
|
1552 {
|
|
1553 tty.main.c_cc[VINTR] = CDISABLE;
|
|
1554 tty.main.c_cc[VQUIT] = CDISABLE;
|
|
1555 }
|
|
1556 tty.main.c_cc[VMIN] = 1; /* Input should wait for at
|
|
1557 least 1 char */
|
|
1558 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */
|
|
1559 #ifdef VSWTCH
|
|
1560 tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use
|
|
1561 of C-z */
|
|
1562 #endif /* VSWTCH */
|
|
1563 /* There was some conditionalizing here on (mips or TCATTR), but
|
|
1564 I think that's wrong. There was one report of C-y (DSUSP) not being
|
|
1565 disabled on HP9000s700 systems, and this might fix it. */
|
|
1566 #ifdef VSUSP
|
|
1567 tty.main.c_cc[VSUSP] = CDISABLE;/* Turn off mips handling of C-z. */
|
|
1568 #endif /* VSUSP */
|
|
1569 #ifdef V_DSUSP
|
|
1570 tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */
|
|
1571 #endif /* V_DSUSP */
|
|
1572 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
|
|
1573 tty.main.c_cc[VDSUSP] = CDISABLE;
|
|
1574 #endif /* VDSUSP */
|
|
1575 #ifdef VLNEXT
|
|
1576 tty.main.c_cc[VLNEXT] = CDISABLE;
|
|
1577 #endif /* VLNEXT */
|
|
1578 #ifdef VREPRINT
|
|
1579 tty.main.c_cc[VREPRINT] = CDISABLE;
|
|
1580 #endif /* VREPRINT */
|
|
1581 #ifdef VWERASE
|
|
1582 tty.main.c_cc[VWERASE] = CDISABLE;
|
|
1583 #endif /* VWERASE */
|
|
1584 #ifdef VDISCARD
|
|
1585 tty.main.c_cc[VDISCARD] = CDISABLE;
|
|
1586 #endif /* VDISCARD */
|
|
1587 #ifdef VSTART
|
|
1588 tty.main.c_cc[VSTART] = CDISABLE;
|
|
1589 #endif /* VSTART */
|
|
1590 #ifdef VSTRT
|
|
1591 tty.main.c_cc[VSTRT] = CDISABLE; /* called VSTRT on some systems */
|
|
1592 #endif /* VSTART */
|
|
1593 #ifdef VSTOP
|
|
1594 tty.main.c_cc[VSTOP] = CDISABLE;
|
|
1595 #endif /* VSTOP */
|
|
1596 #ifdef SET_LINE_DISCIPLINE
|
|
1597 /* Need to explicitely request TERMIODISC line discipline or
|
|
1598 Ultrix's termios does not work correctly. */
|
|
1599 tty.main.c_line = SET_LINE_DISCIPLINE;
|
|
1600 #endif
|
185
|
1601
|
0
|
1602 #ifdef AIX
|
|
1603 #ifndef IBMR2AIX
|
|
1604 /* AIX enhanced edit loses NULs, so disable it. */
|
|
1605 tty.main.c_line = 0;
|
|
1606 tty.main.c_iflag &= ~ASCEDIT;
|
|
1607 #else
|
|
1608 tty.main.c_cc[VSTRT] = 255;
|
|
1609 tty.main.c_cc[VSTOP] = 255;
|
|
1610 tty.main.c_cc[VSUSP] = 255;
|
|
1611 tty.main.c_cc[VDSUSP] = 255;
|
|
1612 #endif /* IBMR2AIX */
|
|
1613 /* Also, PTY overloads NUL and BREAK.
|
|
1614 don't ignore break, but don't signal either, so it looks like NUL.
|
|
1615 This really serves a purpose only if running in an XTERM window
|
|
1616 or via TELNET or the like, but does no harm elsewhere. */
|
|
1617 tty.main.c_iflag &= ~IGNBRK;
|
|
1618 tty.main.c_iflag &= ~BRKINT;
|
|
1619 #endif /* AIX */
|
|
1620 #else /* if not HAVE_TERMIO */
|
209
|
1621 #if !defined(MSDOS) && !defined(WIN32)
|
155
|
1622 con->tty_erase_char = make_char (tty.main.sg_erase);
|
0
|
1623 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
|
|
1624 if (TTY_FLAGS (con).meta_key)
|
|
1625 tty.main.sg_flags |= ANYP;
|
|
1626 /* #### should we be using RAW mode here? */
|
|
1627 tty.main.sg_flags |= /* interrupt_input ? RAW : */ CBREAK;
|
209
|
1628 #endif /* not MSDOS or WIN32 */
|
0
|
1629 #endif /* not HAVE_TERMIO */
|
185
|
1630
|
0
|
1631 /* If going to use CBREAK mode, we must request C-g to interrupt
|
|
1632 and turn off start and stop chars, etc. If not going to use
|
|
1633 CBREAK mode, do this anyway so as to turn off local flow
|
|
1634 control for user coming over network on 4.2; in this case,
|
|
1635 only t_stopc and t_startc really matter. */
|
|
1636 #ifndef HAVE_TERMIO
|
|
1637 #ifdef HAVE_TCHARS
|
|
1638 /* Note: if not using CBREAK mode, it makes no difference how we
|
|
1639 set this */
|
|
1640 tty.tchars = new_tchars;
|
|
1641 tty.tchars.t_intrc = CONSOLE_QUIT_CHAR (con);
|
|
1642 if (TTY_FLAGS (con).flow_control)
|
|
1643 {
|
|
1644 tty.tchars.t_startc = '\021';
|
|
1645 tty.tchars.t_stopc = '\023';
|
|
1646 }
|
185
|
1647
|
0
|
1648 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH |
|
|
1649 CONSOLE_TTY_DATA (con)->old_tty.lmode;
|
185
|
1650
|
0
|
1651 #if defined (ultrix) || defined (__bsdi__)
|
|
1652 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
|
|
1653 anything, and leaving it in breaks the meta key. Go figure. */
|
|
1654 /* Turning off ONLCR is enough under BSD/386. Leave the general
|
|
1655 output post-processing flag alone since for some reason it
|
|
1656 doesn't get reset after XEmacs goes away. */
|
|
1657 tty.lmode &= ~LLITOUT;
|
|
1658 #endif
|
185
|
1659
|
0
|
1660 #endif /* HAVE_TCHARS */
|
|
1661 #endif /* not HAVE_TERMIO */
|
185
|
1662
|
0
|
1663 #ifdef HAVE_LTCHARS
|
|
1664 tty.ltchars = new_ltchars;
|
|
1665 #endif /* HAVE_LTCHARS */
|
|
1666 #ifdef MSDOS
|
|
1667 internal_terminal_init ();
|
|
1668 dos_ttraw ();
|
|
1669 #endif
|
185
|
1670
|
0
|
1671 EMACS_SET_TTY (input_fd, &tty, 0);
|
185
|
1672
|
0
|
1673 /* This code added to insure that, if flow-control is not to be used,
|
|
1674 we have an unlocked terminal at the start. */
|
185
|
1675
|
0
|
1676 #ifdef TCXONC
|
|
1677 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1);
|
|
1678 #endif
|
|
1679 #ifndef APOLLO
|
|
1680 #ifdef TIOCSTART
|
|
1681 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0);
|
|
1682 #endif
|
|
1683 #endif
|
185
|
1684
|
0
|
1685 #if defined (HAVE_TERMIOS) || defined (HPUX9)
|
|
1686 #ifdef TCOON
|
|
1687 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON);
|
|
1688 #endif
|
|
1689 #endif
|
|
1690 #ifdef AIXHFT
|
|
1691 hft_init (con);
|
|
1692 #ifdef IBMR2AIX
|
|
1693 {
|
|
1694 /* IBM's HFT device usually thinks a ^J should be LF/CR.
|
|
1695 We need it to be only LF. This is the way that is
|
|
1696 done. */
|
|
1697 struct termio tty;
|
185
|
1698
|
0
|
1699 if (ioctl (output_fd, HFTGETID, &tty) != -1)
|
|
1700 write (output_fd, "\033[20l", 5);
|
|
1701 }
|
|
1702 #endif
|
|
1703 #endif
|
|
1704
|
|
1705 #if 0 /* We do our own buffering with lstreams. */
|
|
1706 #ifdef _IOFBF
|
|
1707 /* This symbol is defined on recent USG systems.
|
|
1708 Someone says without this call USG won't really buffer the file
|
|
1709 even with a call to setbuf. */
|
|
1710 setvbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf, _IOFBF, sizeof _sobuf);
|
|
1711 #else
|
|
1712 setbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf);
|
|
1713 #endif
|
|
1714 #endif
|
|
1715 set_tty_modes (con);
|
|
1716 }
|
|
1717
|
|
1718 #endif /* HAVE_TTY */
|
|
1719
|
|
1720 void
|
|
1721 init_one_device (struct device *d)
|
|
1722 {
|
|
1723 #ifdef HAVE_TTY
|
|
1724 if (DEVICE_TTY_P (d))
|
|
1725 tty_init_sys_modes_on_device (d);
|
|
1726 #endif
|
251
|
1727 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
|
0
|
1728 if (!DEVICE_STREAM_P (d))
|
|
1729 {
|
|
1730 init_sigio_on_device (d);
|
|
1731 request_sigio_on_device (d);
|
|
1732 }
|
|
1733 #endif
|
|
1734 }
|
|
1735
|
|
1736 void
|
|
1737 init_one_console (struct console *con)
|
|
1738 {
|
|
1739 Lisp_Object devcons;
|
|
1740
|
|
1741 CONSOLE_DEVICE_LOOP (devcons, con)
|
|
1742 {
|
|
1743 struct device *d = XDEVICE (XCAR (devcons));
|
185
|
1744
|
0
|
1745 init_one_device (d);
|
|
1746 }
|
|
1747 }
|
|
1748
|
|
1749 void
|
|
1750 reinit_initial_console (void)
|
|
1751 {
|
|
1752 munge_process_groups ();
|
|
1753 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
1754 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
1755 init_one_console (XCONSOLE (Vcontrolling_terminal));
|
|
1756 }
|
|
1757
|
|
1758
|
|
1759 /* ------------------------------------------------------ */
|
|
1760 /* Other TTY functions */
|
|
1761 /* ------------------------------------------------------ */
|
|
1762
|
|
1763 #ifdef HAVE_TTY
|
|
1764
|
|
1765 #if 0 /* not currently used */
|
|
1766
|
|
1767 /* Return nonzero if safe to use tabs in output.
|
|
1768 At the time this is called, init_sys_modes has not been done yet. */
|
185
|
1769
|
0
|
1770 int
|
|
1771 tabs_safe_p (struct device *d)
|
|
1772 {
|
|
1773 #ifdef HAVE_TTY
|
|
1774 if (DEVICE_TTY_P (d))
|
|
1775 {
|
|
1776 struct emacs_tty tty;
|
185
|
1777
|
0
|
1778 EMACS_GET_TTY (DEVICE_INFD (d), &tty);
|
|
1779 return EMACS_TTY_TABS_OK (&tty);
|
|
1780 }
|
|
1781 #endif
|
|
1782 return 1;
|
|
1783 }
|
|
1784
|
|
1785 #endif /* 0 */
|
|
1786
|
|
1787 /* Get terminal size from system.
|
|
1788 Store number of lines into *heightp and width into *widthp.
|
|
1789 If zero or a negative number is stored, the value is not valid. */
|
|
1790
|
|
1791 void
|
|
1792 get_tty_device_size (struct device *d, int *widthp, int *heightp)
|
|
1793 {
|
|
1794 int input_fd = DEVICE_INFD (d);
|
|
1795
|
|
1796 assert (DEVICE_TTY_P (d));
|
|
1797
|
|
1798 #ifdef TIOCGWINSZ
|
|
1799 {
|
|
1800 /* BSD-style. */
|
|
1801 struct winsize size;
|
185
|
1802
|
0
|
1803 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1)
|
|
1804 *widthp = *heightp = 0;
|
|
1805 else
|
|
1806 {
|
|
1807 *widthp = size.ws_col;
|
|
1808 *heightp = size.ws_row;
|
|
1809 }
|
|
1810 }
|
209
|
1811 #elif defined TIOCGSIZE
|
0
|
1812 {
|
|
1813 /* SunOS - style. */
|
185
|
1814 struct ttysize size;
|
|
1815
|
0
|
1816 if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
|
|
1817 *widthp = *heightp = 0;
|
|
1818 else
|
|
1819 {
|
|
1820 *widthp = size.ts_cols;
|
|
1821 *heightp = size.ts_lines;
|
|
1822 }
|
|
1823 }
|
209
|
1824 #elif defined MSDOS
|
0
|
1825 *widthp = FrameCols ();
|
|
1826 *heightp = FrameRows ();
|
|
1827
|
|
1828 #else /* system doesn't know size */
|
|
1829
|
|
1830 *widthp = 0;
|
|
1831 *heightp = 0;
|
|
1832
|
209
|
1833 #endif /* not !TIOCGWINSZ */
|
0
|
1834 }
|
|
1835
|
|
1836 #endif /* HAVE_TTY */
|
|
1837
|
|
1838
|
|
1839 /* ------------------------------------------------------ */
|
|
1840 /* Is device 8 bit ? */
|
|
1841 /* ------------------------------------------------------ */
|
|
1842
|
|
1843 #ifdef HAVE_TTY
|
|
1844
|
|
1845 int
|
|
1846 eight_bit_tty (struct device *d)
|
|
1847 {
|
|
1848 struct emacs_tty s;
|
|
1849 int input_fd;
|
|
1850 int eight_bit = 0;
|
|
1851
|
|
1852 assert (DEVICE_TTY_P (d));
|
|
1853 input_fd = DEVICE_INFD (d);
|
|
1854
|
|
1855 EMACS_GET_TTY (input_fd, &s);
|
|
1856
|
|
1857 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
|
|
1858 eight_bit = (s.main.c_cflag & CSIZE) == CS8;
|
|
1859 #else
|
|
1860 eight_bit = 0; /* I don't know how to do it */
|
|
1861 #endif
|
|
1862 return eight_bit;
|
|
1863 }
|
|
1864
|
|
1865 #endif /* HAVE_TTY */
|
|
1866
|
|
1867
|
|
1868 /* ------------------------------------------------------ */
|
|
1869 /* Resetting a device */
|
|
1870 /* ------------------------------------------------------ */
|
|
1871
|
|
1872 #ifdef HAVE_TTY
|
|
1873
|
|
1874 /* Prepare the terminal for exiting Emacs; move the cursor to the
|
|
1875 bottom of the frame, turn off interrupt-driven I/O, etc. */
|
|
1876 static void
|
|
1877 tty_reset_sys_modes_on_device (struct device *d)
|
|
1878 {
|
|
1879 int input_fd, output_fd;
|
|
1880 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1881
|
|
1882 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
1883 output_fd = CONSOLE_TTY_DATA (con)->outfd;
|
|
1884
|
|
1885 #if defined (IBMR2AIX) && defined (AIXHFT)
|
|
1886 {
|
185
|
1887 /* HFT consoles normally use ^J as a LF/CR. We forced it to
|
0
|
1888 do the LF only. Now, we need to reset it. */
|
|
1889 struct termio tty;
|
185
|
1890
|
0
|
1891 if (ioctl (output_fd, HFTGETID, &tty) != -1)
|
|
1892 write (output_fd, "\033[20h", 5);
|
|
1893 }
|
|
1894 #endif
|
|
1895
|
|
1896 tty_redisplay_shutdown (con);
|
|
1897 /* reset_tty_modes() flushes the connection at its end. */
|
|
1898 reset_tty_modes (con);
|
185
|
1899
|
0
|
1900 #if defined (BSD)
|
|
1901 /* Avoid possible loss of output when changing terminal modes. */
|
|
1902 fsync (output_fd);
|
|
1903 #endif
|
|
1904
|
|
1905 while (EMACS_SET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0)
|
|
1906 < 0 && errno == EINTR)
|
|
1907 ;
|
185
|
1908
|
0
|
1909 #ifdef MSDOS
|
|
1910 dos_ttcooked ();
|
|
1911 #endif
|
185
|
1912
|
0
|
1913 #ifdef SET_LINE_DISCIPLINE
|
|
1914 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
|
|
1915 A different old line discipline is therefore not restored, yet.
|
|
1916 Restore the old line discipline by hand. */
|
|
1917 ioctl (input_fd, TIOCSETD, &old_tty.main.c_line);
|
|
1918 #endif
|
|
1919
|
|
1920 #ifdef AIXHFT
|
|
1921 hft_reset (con);
|
|
1922 #endif
|
|
1923
|
|
1924 }
|
|
1925
|
|
1926 #endif /* HAVE_TTY */
|
|
1927
|
|
1928 void
|
|
1929 reset_one_device (struct device *d)
|
|
1930 {
|
|
1931 #ifdef HAVE_TTY
|
|
1932 if (DEVICE_TTY_P (d))
|
|
1933 tty_reset_sys_modes_on_device (d);
|
|
1934 else
|
|
1935 #endif
|
|
1936 if (DEVICE_STREAM_P (d))
|
|
1937 fflush (CONSOLE_STREAM_DATA (XCONSOLE (DEVICE_CONSOLE (d)))->outfd);
|
251
|
1938 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
|
0
|
1939 if (!DEVICE_STREAM_P (d))
|
|
1940 {
|
|
1941 unrequest_sigio_on_device (d);
|
|
1942 reset_sigio_on_device (d);
|
|
1943 }
|
|
1944 #endif
|
|
1945 }
|
|
1946
|
|
1947 void
|
|
1948 reset_one_console (struct console *con)
|
|
1949 {
|
|
1950 /* Note: this can be called during GC. */
|
|
1951 Lisp_Object devcons;
|
|
1952
|
|
1953 CONSOLE_DEVICE_LOOP (devcons, con)
|
|
1954 {
|
|
1955 struct device *d = XDEVICE (XCAR (devcons));
|
185
|
1956
|
0
|
1957 reset_one_device (d);
|
|
1958 }
|
|
1959 }
|
|
1960
|
|
1961 void
|
|
1962 reset_all_consoles (void)
|
|
1963 {
|
|
1964 /* Note: this can be called during GC. */
|
|
1965 Lisp_Object concons;
|
|
1966
|
|
1967 CONSOLE_LOOP (concons)
|
|
1968 {
|
|
1969 struct console *con = XCONSOLE (XCAR (concons));
|
185
|
1970
|
0
|
1971 reset_one_console (con);
|
|
1972 }
|
|
1973
|
|
1974 unmunge_process_groups ();
|
|
1975 }
|
|
1976
|
|
1977 void
|
|
1978 reset_initial_console (void)
|
|
1979 {
|
|
1980 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
1981 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
1982 reset_one_console (XCONSOLE (Vcontrolling_terminal));
|
|
1983 unmunge_process_groups ();
|
|
1984 }
|
|
1985
|
|
1986
|
|
1987 /* ------------------------------------------------------ */
|
|
1988 /* extra TTY stuff under AIX */
|
|
1989 /* ------------------------------------------------------ */
|
|
1990
|
|
1991 #ifdef AIXHFT
|
|
1992
|
|
1993 /* Called from init_sys_modes. */
|
|
1994 static void
|
|
1995 hft_init (struct console *con)
|
|
1996 {
|
|
1997 int junk;
|
|
1998 int input_fd;
|
|
1999
|
|
2000 assert (CONSOLE_TTY_P (con));
|
|
2001 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
2002
|
|
2003 /* If we're not on an HFT we shouldn't do any of this. We determine
|
|
2004 if we are on an HFT by trying to get an HFT error code. If this
|
185
|
2005 call fails, we're not on an HFT. */
|
0
|
2006 #ifdef IBMR2AIX
|
|
2007 if (ioctl (input_fd, HFQERROR, &junk) < 0)
|
|
2008 return;
|
|
2009 #else /* not IBMR2AIX */
|
|
2010 if (ioctl (input_fd, HFQEIO, 0) < 0)
|
|
2011 return;
|
|
2012 #endif /* not IBMR2AIX */
|
|
2013
|
|
2014 /* On AIX the default hft keyboard mapping uses backspace rather than delete
|
|
2015 as the rubout key's ASCII code. Here this is changed. The bug is that
|
|
2016 there's no way to determine the old mapping, so in reset_one_console
|
|
2017 we need to assume that the normal map had been present. Of course, this
|
|
2018 code also doesn't help if on a terminal emulator which doesn't understand
|
|
2019 HFT VTD's. */
|
|
2020 {
|
|
2021 struct hfbuf buf;
|
|
2022 struct hfkeymap keymap;
|
|
2023
|
|
2024 buf.hf_bufp = (char *)&keymap;
|
|
2025 buf.hf_buflen = sizeof (keymap);
|
|
2026 keymap.hf_nkeys = 2;
|
|
2027 keymap.hfkey[0].hf_kpos = 15;
|
|
2028 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
|
|
2029 #ifdef IBMR2AIX
|
|
2030 keymap.hfkey[0].hf_keyidh = '<';
|
|
2031 #else /* not IBMR2AIX */
|
|
2032 keymap.hfkey[0].hf_page = '<';
|
|
2033 #endif /* not IBMR2AIX */
|
|
2034 keymap.hfkey[0].hf_char = 127;
|
|
2035 keymap.hfkey[1].hf_kpos = 15;
|
|
2036 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
|
|
2037 #ifdef IBMR2AIX
|
|
2038 keymap.hfkey[1].hf_keyidh = '<';
|
|
2039 #else /* not IBMR2AIX */
|
|
2040 keymap.hfkey[1].hf_page = '<';
|
|
2041 #endif /* not IBMR2AIX */
|
|
2042 keymap.hfkey[1].hf_char = 127;
|
|
2043 hftctl (input_fd, HFSKBD, &buf);
|
|
2044 }
|
|
2045 /* #### Should probably set a console TTY flag here. */
|
|
2046 #if 0
|
|
2047 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
|
|
2048 at times. */
|
|
2049 line_ins_del_ok = char_ins_del_ok = 0;
|
|
2050 #endif /* 0 */
|
|
2051 }
|
|
2052
|
|
2053 /* Reset the rubout key to backspace. */
|
|
2054
|
|
2055 static void
|
|
2056 hft_reset (struct console *con)
|
|
2057 {
|
|
2058 struct hfbuf buf;
|
|
2059 struct hfkeymap keymap;
|
|
2060 int junk;
|
|
2061 int input_fd;
|
|
2062
|
|
2063 assert (CONSOLE_TTY_P (con));
|
|
2064 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
2065
|
|
2066 #ifdef IBMR2AIX
|
|
2067 if (ioctl (input_fd, HFQERROR, &junk) < 0)
|
|
2068 return;
|
|
2069 #else /* not IBMR2AIX */
|
|
2070 if (ioctl (input_fd, HFQEIO, 0) < 0)
|
|
2071 return;
|
|
2072 #endif /* not IBMR2AIX */
|
|
2073
|
|
2074 buf.hf_bufp = (char *)&keymap;
|
|
2075 buf.hf_buflen = sizeof (keymap);
|
|
2076 keymap.hf_nkeys = 2;
|
|
2077 keymap.hfkey[0].hf_kpos = 15;
|
|
2078 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
|
|
2079 #ifdef IBMR2AIX
|
|
2080 keymap.hfkey[0].hf_keyidh = '<';
|
|
2081 #else /* not IBMR2AIX */
|
|
2082 keymap.hfkey[0].hf_page = '<';
|
|
2083 #endif /* not IBMR2AIX */
|
|
2084 keymap.hfkey[0].hf_char = 8;
|
|
2085 keymap.hfkey[1].hf_kpos = 15;
|
|
2086 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
|
|
2087 #ifdef IBMR2AIX
|
|
2088 keymap.hfkey[1].hf_keyidh = '<';
|
|
2089 #else /* not IBMR2AIX */
|
|
2090 keymap.hfkey[1].hf_page = '<';
|
|
2091 #endif /* not IBMR2AIX */
|
|
2092 keymap.hfkey[1].hf_char = 8;
|
|
2093 hftctl (input_fd, HFSKBD, &buf);
|
|
2094 }
|
|
2095
|
|
2096 #endif /* AIXHFT */
|
|
2097
|
|
2098
|
|
2099 /************************************************************************/
|
|
2100 /* limits of text/data segments */
|
|
2101 /************************************************************************/
|
|
2102
|
|
2103 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
|
|
2104 #ifndef CANNOT_DUMP
|
|
2105 #define NEED_STARTS
|
|
2106 #endif
|
|
2107
|
|
2108 #ifndef SYSTEM_MALLOC
|
|
2109 #ifndef NEED_STARTS
|
|
2110 #define NEED_STARTS
|
|
2111 #endif
|
|
2112 #endif
|
|
2113
|
|
2114 #ifdef NEED_STARTS
|
|
2115 /* Some systems that cannot dump also cannot implement these. */
|
|
2116
|
|
2117 /*
|
|
2118 * Return the address of the start of the text segment prior to
|
|
2119 * doing an unexec. After unexec the return value is undefined.
|
|
2120 * See crt0.c for further explanation and _start.
|
|
2121 *
|
|
2122 */
|
|
2123
|
185
|
2124 #ifdef __cplusplus
|
|
2125 extern "C" int _start ();
|
|
2126 #else
|
|
2127 extern int _start ();
|
|
2128 #endif
|
|
2129
|
0
|
2130 #ifndef HAVE_TEXT_START
|
|
2131 char *
|
|
2132 start_of_text (void)
|
|
2133 {
|
|
2134 #ifdef TEXT_START
|
|
2135 return ((char *) TEXT_START);
|
|
2136 #else
|
|
2137 #ifdef GOULD
|
|
2138 extern csrt ();
|
|
2139 return ((char *) csrt);
|
|
2140 #else /* not GOULD */
|
|
2141 return ((char *) _start);
|
|
2142 #endif /* GOULD */
|
|
2143 #endif /* TEXT_START */
|
|
2144 }
|
|
2145 #endif /* not HAVE_TEXT_START */
|
|
2146
|
|
2147 /*
|
|
2148 * Return the address of the start of the data segment prior to
|
|
2149 * doing an unexec. After unexec the return value is undefined.
|
|
2150 * See crt0.c for further information and definition of data_start.
|
|
2151 *
|
|
2152 * Apparently, on BSD systems this is etext at startup. On
|
|
2153 * USG systems (swapping) this is highly mmu dependent and
|
|
2154 * is also dependent on whether or not the program is running
|
|
2155 * with shared text. Generally there is a (possibly large)
|
|
2156 * gap between end of text and start of data with shared text.
|
|
2157 *
|
|
2158 * On Uniplus+ systems with shared text, data starts at a
|
|
2159 * fixed address. Each port (from a given oem) is generally
|
|
2160 * different, and the specific value of the start of data can
|
|
2161 * be obtained via the UniPlus+ specific "uvar" system call,
|
|
2162 * however the method outlined in crt0.c seems to be more portable.
|
|
2163 *
|
|
2164 * Probably what will have to happen when a USG unexec is available,
|
|
2165 * at least on UniPlus, is temacs will have to be made unshared so
|
|
2166 * that text and data are contiguous. Then once loadup is complete,
|
|
2167 * unexec will produce a shared executable where the data can be
|
|
2168 * at the normal shared text boundry and the startofdata variable
|
|
2169 * will be patched by unexec to the correct value.
|
|
2170 *
|
|
2171 */
|
185
|
2172
|
272
|
2173 #ifdef ORDINARY_LINK
|
|
2174 extern char **environ;
|
|
2175 #endif
|
|
2176
|
0
|
2177 void *
|
|
2178 start_of_data (void)
|
|
2179 {
|
|
2180 #ifdef DATA_START
|
|
2181 return ((char *) DATA_START);
|
|
2182 #else
|
|
2183 #ifdef ORDINARY_LINK
|
|
2184 /*
|
|
2185 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
|
|
2186 * data_start isn't defined. We take the address of environ, which
|
|
2187 * is known to live at or near the start of the system crt0.c, and
|
|
2188 * we don't sweat the handful of bytes that might lose.
|
|
2189 */
|
251
|
2190 #ifdef HEAP_IN_DATA
|
|
2191 extern char* static_heap_base;
|
|
2192 if (!initialized)
|
|
2193 return static_heap_base;
|
|
2194 #endif
|
0
|
2195 return((char *) &environ);
|
|
2196 #else
|
|
2197 extern int data_start;
|
|
2198 return ((char *) &data_start);
|
|
2199 #endif /* ORDINARY_LINK */
|
|
2200 #endif /* DATA_START */
|
|
2201 }
|
|
2202 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
|
|
2203
|
|
2204 #ifndef CANNOT_DUMP
|
|
2205 /* Some systems that cannot dump also cannot implement these. */
|
|
2206
|
|
2207 /*
|
|
2208 * Return the address of the end of the text segment prior to
|
|
2209 * doing an unexec. After unexec the return value is undefined.
|
|
2210 */
|
185
|
2211
|
0
|
2212 char *
|
|
2213 end_of_text (void)
|
|
2214 {
|
|
2215 #ifdef TEXT_END
|
|
2216 return ((char *) TEXT_END);
|
|
2217 #else
|
|
2218 extern int etext;
|
|
2219 return ((char *) &etext);
|
|
2220 #endif
|
|
2221 }
|
185
|
2222
|
0
|
2223 /*
|
|
2224 * Return the address of the end of the data segment prior to
|
|
2225 * doing an unexec. After unexec the return value is undefined.
|
|
2226 */
|
|
2227
|
|
2228 char *
|
|
2229 end_of_data (void)
|
|
2230 {
|
|
2231 #ifdef DATA_END
|
|
2232 return ((char *) DATA_END);
|
|
2233 #else
|
|
2234 extern int edata;
|
|
2235 return ((char *) &edata);
|
|
2236 #endif
|
|
2237 }
|
|
2238
|
|
2239 #endif /* not CANNOT_DUMP */
|
|
2240
|
|
2241
|
|
2242 /************************************************************************/
|
|
2243 /* get the system name */
|
|
2244 /************************************************************************/
|
|
2245
|
|
2246 /* init_system_name sets up the string for the Lisp function
|
|
2247 system-name to return. */
|
|
2248
|
|
2249 extern Lisp_Object Vsystem_name;
|
|
2250
|
209
|
2251 #ifdef HAVE_SOCKETS
|
0
|
2252 # include <sys/socket.h>
|
|
2253 # include <netdb.h>
|
209
|
2254 #endif /* HAVE_SOCKETS */
|
0
|
2255
|
|
2256 void
|
|
2257 init_system_name (void)
|
|
2258 {
|
282
|
2259 #if defined (WINDOWSNT)
|
|
2260 char hostname [MAX_COMPUTERNAME_LENGTH + 1];
|
|
2261 size_t size = sizeof(hostname);
|
|
2262 GetComputerName (hostname, &size);
|
|
2263 Vsystem_name = build_string (hostname);
|
|
2264 #elif !defined (HAVE_GETHOSTNAME)
|
0
|
2265 struct utsname uts;
|
|
2266 uname (&uts);
|
|
2267 Vsystem_name = build_string (uts.nodename);
|
|
2268 #else /* HAVE_GETHOSTNAME */
|
|
2269 unsigned int hostname_size = 256;
|
|
2270 char *hostname = (char *) alloca (hostname_size);
|
|
2271
|
|
2272 /* Try to get the host name; if the buffer is too short, try
|
|
2273 again. Apparently, the only indication gethostname gives of
|
|
2274 whether the buffer was large enough is the presence or absence
|
|
2275 of a '\0' in the string. Eech. */
|
|
2276 for (;;)
|
|
2277 {
|
|
2278 gethostname (hostname, hostname_size - 1);
|
|
2279 hostname[hostname_size - 1] = '\0';
|
|
2280
|
|
2281 /* Was the buffer large enough for the '\0'? */
|
|
2282 if (strlen (hostname) < (size_t) (hostname_size - 1))
|
|
2283 break;
|
|
2284
|
|
2285 hostname_size <<= 1;
|
|
2286 hostname = (char *) alloca (hostname_size);
|
|
2287 }
|
251
|
2288 # if defined( HAVE_SOCKETS) && !defined(BROKEN_CYGWIN)
|
0
|
2289 /* Turn the hostname into the official, fully-qualified hostname.
|
|
2290 Don't do this if we're going to dump; this can confuse system
|
|
2291 libraries on some machines and make the dumped emacs core dump. */
|
|
2292 # ifndef CANNOT_DUMP
|
|
2293 if (initialized)
|
|
2294 # endif /* not CANNOT_DUMP */
|
|
2295 {
|
272
|
2296 struct hostent *hp = NULL;
|
0
|
2297 int count;
|
|
2298 # ifdef TRY_AGAIN
|
|
2299 for (count = 0; count < 10; count++)
|
|
2300 {
|
|
2301 h_errno = 0;
|
|
2302 # endif
|
|
2303 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */
|
|
2304 stop_interrupts ();
|
|
2305 hp = gethostbyname (hostname);
|
|
2306 start_interrupts ();
|
|
2307 # ifdef TRY_AGAIN
|
|
2308 if (! (hp == 0 && h_errno == TRY_AGAIN))
|
|
2309 break;
|
|
2310 Fsleep_for (make_int (1));
|
|
2311 }
|
|
2312 # endif
|
|
2313 if (hp)
|
|
2314 {
|
|
2315 CONST char *fqdn = (CONST char *) hp->h_name;
|
|
2316
|
|
2317 if (!strchr (fqdn, '.'))
|
|
2318 {
|
|
2319 /* We still don't have a fully qualified domain name.
|
|
2320 Try to find one in the list of alternate names */
|
|
2321 char **alias = hp->h_aliases;
|
|
2322 while (*alias && !strchr (*alias, '.'))
|
|
2323 alias++;
|
|
2324 if (*alias)
|
|
2325 fqdn = *alias;
|
|
2326 }
|
|
2327 hostname = (char *) alloca (strlen (fqdn) + 1);
|
|
2328 strcpy (hostname, fqdn);
|
|
2329 }
|
|
2330 }
|
|
2331 # endif /* HAVE_SOCKETS */
|
|
2332 Vsystem_name = build_string (hostname);
|
209
|
2333 #endif /* HAVE_GETHOSTNAME */
|
0
|
2334 {
|
|
2335 Bufbyte *p;
|
|
2336 Bytecount i;
|
|
2337
|
16
|
2338 for (i = 0, p = XSTRING_DATA (Vsystem_name);
|
|
2339 i < XSTRING_LENGTH (Vsystem_name);
|
0
|
2340 i++, p++)
|
|
2341 {
|
|
2342 if (*p == ' ' || *p == '\t')
|
|
2343 *p = '-';
|
|
2344 }
|
|
2345 }
|
|
2346 }
|
|
2347
|
|
2348
|
|
2349 /************************************************************************/
|
|
2350 /* Emulation of select() */
|
|
2351 /************************************************************************/
|
|
2352
|
|
2353 #ifndef HAVE_SELECT
|
|
2354
|
|
2355 ERROR: XEmacs requires a working select().
|
|
2356
|
|
2357 #endif /* not HAVE_SELECT */
|
|
2358
|
|
2359
|
|
2360 /************************************************************************/
|
|
2361 /* Emulation of signal stuff */
|
|
2362 /************************************************************************/
|
|
2363
|
|
2364 /* BSD 4.1 crap deleted. 4.2 was released in 1983, for God's sake! I
|
|
2365 can't imagine that anyone is actually running that OS any more.
|
|
2366 You can't use X under it (I think) because there's no select().
|
|
2367 Anyway, the signal stuff has all been changed. If someone wants to
|
|
2368 get this stuff working again, look in the FSF Emacs sources. */
|
185
|
2369
|
0
|
2370 /* POSIX signals support - DJB */
|
|
2371
|
|
2372 #ifdef HAVE_SIGPROCMASK
|
|
2373
|
|
2374 /* #### Is there any reason this is static global rather than local? */
|
|
2375 static struct sigaction new_action, old_action;
|
|
2376
|
|
2377 signal_handler_t
|
|
2378 sys_do_signal (int signal_number, signal_handler_t action)
|
|
2379 {
|
|
2380 #if 0
|
|
2381
|
|
2382 /* XEmacs works better if system calls are *not* restarted.
|
|
2383 This allows C-g to interrupt reads and writes, on most systems.
|
|
2384
|
|
2385 #### Another possibility is to just longjmp() out of the signal
|
|
2386 handler. According to W.R. Stevens, this should be OK on all
|
|
2387 systems. However, I don't want to deal with the potential
|
|
2388 evil ramifications of this at this point. */
|
|
2389
|
|
2390 #ifdef DGUX
|
|
2391 /* This gets us restartable system calls for efficiency.
|
|
2392 The "else" code will work as well. */
|
|
2393 return (berk_signal (signal_number, action));
|
|
2394 #else
|
|
2395 sigemptyset (&new_action.sa_mask);
|
|
2396 new_action.sa_handler = action;
|
|
2397 #if defined (SA_RESTART)
|
|
2398 /* Emacs mostly works better with restartable system services. If this
|
|
2399 * flag exists, we probably want to turn it on here.
|
|
2400 */
|
|
2401 new_action.sa_flags = SA_RESTART;
|
|
2402 #else
|
|
2403 new_action.sa_flags = 0;
|
|
2404 #endif
|
|
2405 sigaction (signal_number, &new_action, &old_action);
|
|
2406 return (old_action.sa_handler);
|
|
2407 #endif /* DGUX */
|
|
2408
|
|
2409 #else /* not 0 */
|
|
2410
|
|
2411 sigemptyset (&new_action.sa_mask);
|
|
2412 new_action.sa_handler = action;
|
|
2413 #if defined (SA_INTERRUPT) /* don't restart system calls, under SunOS */
|
|
2414 new_action.sa_flags = SA_INTERRUPT;
|
|
2415 #else
|
|
2416 new_action.sa_flags = 0;
|
|
2417 #endif
|
|
2418 sigaction (signal_number, &new_action, &old_action);
|
179
|
2419 return (signal_handler_t) (old_action.sa_handler);
|
0
|
2420
|
|
2421 #endif /* not 0 */
|
|
2422 }
|
|
2423
|
|
2424 #elif defined (HAVE_SIGBLOCK)
|
|
2425
|
|
2426 /* We use sigvec() rather than signal() if we have it, because
|
|
2427 it lets us specify interruptible system calls. */
|
|
2428 signal_handler_t
|
|
2429 sys_do_signal (int signal_number, signal_handler_t action)
|
|
2430 {
|
|
2431 struct sigvec vec, ovec;
|
|
2432
|
|
2433 vec.sv_handler = action;
|
|
2434 vec.sv_mask = 0;
|
|
2435 #ifdef SV_INTERRUPT /* don't restart system calls */
|
|
2436 vec.sv_flags = SV_INTERRUPT;
|
|
2437 #else
|
|
2438 vec.sv_flags = 0;
|
|
2439 #endif
|
|
2440
|
|
2441 sigvec (signal_number, &vec, &ovec);
|
|
2442
|
|
2443 return (ovec.sv_handler);
|
|
2444 }
|
|
2445
|
|
2446 #endif /* HAVE_SIGBLOCK (HAVE_SIGPROCMASK) */
|
|
2447
|
|
2448
|
|
2449 /************************************************************************/
|
255
|
2450 /* Emulation of strerror() and errno support */
|
0
|
2451 /************************************************************************/
|
|
2452
|
|
2453 #ifndef HAVE_STRERROR
|
|
2454
|
|
2455 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__)
|
|
2456 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */
|
|
2457 /* Irix added here by gparker@sni-usa.com for XEmacs. */
|
|
2458 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */
|
|
2459 extern CONST char *sys_errlist[];
|
|
2460 extern int sys_nerr;
|
|
2461 #endif
|
|
2462
|
|
2463 #ifdef __NetBSD__
|
|
2464 extern char *sys_errlist[];
|
|
2465 extern int sys_nerr;
|
|
2466 #endif
|
|
2467
|
|
2468
|
|
2469 CONST char *
|
|
2470 strerror (int errnum)
|
|
2471 {
|
|
2472 if (errnum >= 0 && errnum < sys_nerr)
|
|
2473 return sys_errlist[errnum];
|
|
2474 return ((CONST char *) GETTEXT ("Unknown error"));
|
|
2475 }
|
|
2476
|
|
2477 #endif /* ! HAVE_STRERROR */
|
|
2478
|
255
|
2479 #ifdef WINDOWSNT
|
|
2480
|
|
2481 struct errentry {
|
|
2482 unsigned long oscode; /* Win32 error */
|
|
2483 int errnocode; /* unix errno */
|
|
2484 };
|
|
2485
|
|
2486 static struct errentry errtable[] = {
|
|
2487 { ERROR_INVALID_FUNCTION, EINVAL }, /* 1 */
|
|
2488 { ERROR_FILE_NOT_FOUND, ENOENT }, /* 2 */
|
|
2489 { ERROR_PATH_NOT_FOUND, ENOENT }, /* 3 */
|
|
2490 { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, /* 4 */
|
|
2491 { ERROR_ACCESS_DENIED, EACCES }, /* 5 */
|
|
2492 { ERROR_INVALID_HANDLE, EBADF }, /* 6 */
|
|
2493 { ERROR_ARENA_TRASHED, ENOMEM }, /* 7 */
|
|
2494 { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, /* 8 */
|
|
2495 { ERROR_INVALID_BLOCK, ENOMEM }, /* 9 */
|
|
2496 { ERROR_BAD_ENVIRONMENT, E2BIG }, /* 10 */
|
|
2497 { ERROR_BAD_FORMAT, ENOEXEC }, /* 11 */
|
|
2498 { ERROR_INVALID_ACCESS, EINVAL }, /* 12 */
|
|
2499 { ERROR_INVALID_DATA, EINVAL }, /* 13 */
|
|
2500 { ERROR_INVALID_DRIVE, ENOENT }, /* 15 */
|
|
2501 { ERROR_CURRENT_DIRECTORY, EACCES }, /* 16 */
|
|
2502 { ERROR_NOT_SAME_DEVICE, EXDEV }, /* 17 */
|
|
2503 { ERROR_NO_MORE_FILES, ENOENT }, /* 18 */
|
|
2504 { ERROR_LOCK_VIOLATION, EACCES }, /* 33 */
|
|
2505 { ERROR_BAD_NETPATH, ENOENT }, /* 53 */
|
|
2506 { ERROR_NETWORK_ACCESS_DENIED, EACCES }, /* 65 */
|
|
2507 { ERROR_BAD_NET_NAME, ENOENT }, /* 67 */
|
|
2508 { ERROR_FILE_EXISTS, EEXIST }, /* 80 */
|
|
2509 { ERROR_CANNOT_MAKE, EACCES }, /* 82 */
|
|
2510 { ERROR_FAIL_I24, EACCES }, /* 83 */
|
|
2511 { ERROR_INVALID_PARAMETER, EINVAL }, /* 87 */
|
|
2512 { ERROR_NO_PROC_SLOTS, EAGAIN }, /* 89 */
|
|
2513 { ERROR_DRIVE_LOCKED, EACCES }, /* 108 */
|
|
2514 { ERROR_BROKEN_PIPE, EPIPE }, /* 109 */
|
|
2515 { ERROR_DISK_FULL, ENOSPC }, /* 112 */
|
|
2516 { ERROR_INVALID_TARGET_HANDLE, EBADF }, /* 114 */
|
|
2517 { ERROR_INVALID_HANDLE, EINVAL }, /* 124 */
|
|
2518 { ERROR_WAIT_NO_CHILDREN, ECHILD }, /* 128 */
|
|
2519 { ERROR_CHILD_NOT_COMPLETE, ECHILD }, /* 129 */
|
|
2520 { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, /* 130 */
|
|
2521 { ERROR_NEGATIVE_SEEK, EINVAL }, /* 131 */
|
|
2522 { ERROR_SEEK_ON_DEVICE, EACCES }, /* 132 */
|
|
2523 { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, /* 145 */
|
|
2524 { ERROR_NOT_LOCKED, EACCES }, /* 158 */
|
|
2525 { ERROR_BAD_PATHNAME, ENOENT }, /* 161 */
|
|
2526 { ERROR_MAX_THRDS_REACHED, EAGAIN }, /* 164 */
|
|
2527 { ERROR_LOCK_FAILED, EACCES }, /* 167 */
|
|
2528 { ERROR_ALREADY_EXISTS, EEXIST }, /* 183 */
|
|
2529 { ERROR_FILENAME_EXCED_RANGE, ENOENT }, /* 206 */
|
|
2530 { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, /* 215 */
|
|
2531 { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } /* 1816 */
|
|
2532 };
|
|
2533
|
|
2534 /* The following two constants must be the minimum and maximum
|
|
2535 values in the (contiguous) range of Exec Failure errors. */
|
|
2536 #define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
|
|
2537 #define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
|
|
2538
|
|
2539 /* These are the low and high value in the range of errors that are
|
|
2540 access violations */
|
|
2541 #define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
|
|
2542 #define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
|
|
2543
|
|
2544 void
|
|
2545 mswindows_set_errno (unsigned long win32_error)
|
|
2546 {
|
|
2547 int i;
|
|
2548
|
|
2549 /* check the table for the OS error code */
|
|
2550 for (i = 0; i < sizeof(errtable)/sizeof(errtable[0]); ++i)
|
|
2551 {
|
|
2552 if (win32_error == errtable[i].oscode)
|
|
2553 {
|
|
2554 errno = errtable[i].errnocode;
|
|
2555 return;
|
|
2556 }
|
|
2557 }
|
|
2558
|
|
2559 /* The error code wasn't in the table. We check for a range of
|
|
2560 * EACCES errors or exec failure errors (ENOEXEC). Otherwise EINVAL is
|
|
2561 * returned. */
|
|
2562 if (win32_error >= MIN_EACCES_RANGE && win32_error <= MAX_EACCES_RANGE)
|
|
2563 errno = EACCES;
|
|
2564 else if (win32_error >= MIN_EXEC_ERROR && win32_error <= MAX_EXEC_ERROR)
|
|
2565 errno = ENOEXEC;
|
|
2566 else
|
|
2567 errno = EINVAL;
|
|
2568 }
|
|
2569
|
|
2570 void
|
|
2571 mswindows_set_last_errno (void)
|
|
2572 {
|
|
2573 mswindows_set_errno (GetLastError ());
|
|
2574 }
|
|
2575
|
|
2576 #endif /* WINDOWSNT */
|
0
|
2577
|
|
2578
|
|
2579 /************************************************************************/
|
|
2580 /* Encapsulations of system calls */
|
|
2581 /************************************************************************/
|
|
2582
|
|
2583 #define PATHNAME_CONVERT_OUT(path) \
|
272
|
2584 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA ((CONST Bufbyte *) path, path)
|
0
|
2585
|
|
2586 /***** MSDOS versions are in msdos.c *****/
|
|
2587
|
|
2588 /***************** low-level calls ****************/
|
|
2589
|
|
2590 /*
|
|
2591 * On USG systems the system calls are INTERRUPTIBLE by signals
|
|
2592 * that the user program has elected to catch. Thus the system call
|
|
2593 * must be retried in these cases. To handle this without massive
|
|
2594 * changes in the source code, we remap the standard system call names
|
|
2595 * to names for our own functions in sysdep.c that do the system call
|
|
2596 * with retries. Actually, for portability reasons, it is good
|
|
2597 * programming practice, as this example shows, to limit all actual
|
|
2598 * system calls to a single occurrence in the source. Sure, this
|
|
2599 * adds an extra level of function call overhead but it is almost
|
|
2600 * always negligible. Fred Fish, Unisoft Systems Inc.
|
|
2601 */
|
|
2602
|
|
2603 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better
|
|
2604 approach to programming and its connection to the silly
|
|
2605 interruptible-system-call business. To find it, look at
|
|
2606 Jamie's home page (http://www.netscape.com/people/jwz). */
|
|
2607
|
|
2608 #ifdef ENCAPSULATE_OPEN
|
|
2609 int
|
|
2610 sys_open (CONST char *path, int oflag, ...)
|
|
2611 {
|
|
2612 int mode;
|
|
2613 va_list ap;
|
185
|
2614
|
0
|
2615 va_start (ap, oflag);
|
|
2616 mode = va_arg (ap, int);
|
|
2617 va_end (ap);
|
|
2618
|
|
2619 PATHNAME_CONVERT_OUT (path);
|
|
2620 #ifdef INTERRUPTIBLE_OPEN
|
|
2621 {
|
|
2622 int rtnval;
|
|
2623 while ((rtnval = open (path, oflag, mode)) == -1
|
|
2624 && (errno == EINTR));
|
|
2625 return rtnval;
|
|
2626 }
|
|
2627 #else
|
|
2628 return open (path, oflag, mode);
|
|
2629 #endif
|
|
2630 }
|
|
2631 #endif /* ENCAPSULATE_OPEN */
|
|
2632
|
225
|
2633 /* Like sys_open, only when open() is interrupted by EINTR, check for
|
|
2634 QUIT. This allows the callers of this function to be interrupted
|
|
2635 with C-g when, say, reading from named pipes. However, this should
|
|
2636 be used with caution, as it can GC.
|
|
2637
|
|
2638 This function will not function as expected on systems where open()
|
|
2639 is not interrupted by C-g. However, the worst that can happen is
|
|
2640 the fallback to simple open(). */
|
|
2641 int
|
|
2642 interruptible_open (CONST char *path, int oflag, int mode)
|
|
2643 {
|
|
2644 /* This function can GC */
|
|
2645 size_t len = strlen (path);
|
|
2646 char *nonreloc = (char *) alloca (len + 1);
|
|
2647
|
|
2648 /* Must copy PATH, because it might be the data of a Lisp_String,
|
|
2649 which could be relocated by GC when checking for QUIT. */
|
|
2650 memcpy (nonreloc, path, len + 1);
|
|
2651
|
272
|
2652 PATHNAME_CONVERT_OUT (nonreloc);
|
225
|
2653
|
|
2654 for (;;)
|
|
2655 {
|
|
2656 int rtnval = open (nonreloc, oflag, mode);
|
|
2657 if (!(rtnval == -1 && errno == EINTR))
|
|
2658 return rtnval;
|
|
2659 /* open() was interrupted. Was QUIT responsible? */
|
|
2660 QUIT;
|
|
2661 }
|
|
2662 }
|
16
|
2663
|
0
|
2664 #ifdef ENCAPSULATE_CLOSE
|
|
2665 int
|
|
2666 sys_close (int fd)
|
|
2667 {
|
|
2668 #ifdef INTERRUPTIBLE_CLOSE
|
|
2669 int did_retry = 0;
|
203
|
2670 REGISTER int rtnval;
|
0
|
2671
|
|
2672 while ((rtnval = close (fd)) == -1
|
|
2673 && (errno == EINTR))
|
|
2674 did_retry = 1;
|
|
2675
|
|
2676 /* If close is interrupted SunOS 4.1 may or may not have closed the
|
|
2677 file descriptor. If it did the second close will fail with
|
|
2678 errno = EBADF. That means we have succeeded. */
|
|
2679 if (rtnval == -1 && did_retry && errno == EBADF)
|
|
2680 return 0;
|
|
2681
|
|
2682 return rtnval;
|
|
2683 #else
|
|
2684 return close (fd);
|
|
2685 #endif
|
|
2686 }
|
|
2687 #endif /* ENCAPSULATE_CLOSE */
|
|
2688
|
|
2689 int
|
272
|
2690 sys_read_1 (int fildes, void *buf, size_t nbyte, int allow_quit)
|
0
|
2691 {
|
|
2692 int rtnval;
|
|
2693
|
|
2694 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
|
|
2695 while ((rtnval = read (fildes, buf, nbyte)) == -1
|
|
2696 && (errno == EINTR))
|
|
2697 {
|
|
2698 if (allow_quit)
|
|
2699 REALLY_QUIT;
|
|
2700 }
|
|
2701 return rtnval;
|
|
2702 }
|
|
2703
|
|
2704 #ifdef ENCAPSULATE_READ
|
|
2705 int
|
272
|
2706 sys_read (int fildes, void *buf, size_t nbyte)
|
0
|
2707 {
|
|
2708 return sys_read_1 (fildes, buf, nbyte, 0);
|
|
2709 }
|
|
2710 #endif /* ENCAPSULATE_READ */
|
|
2711
|
|
2712 int
|
272
|
2713 sys_write_1 (int fildes, CONST void *buf, size_t nbyte, int allow_quit)
|
0
|
2714 {
|
|
2715 int rtnval;
|
|
2716 int bytes_written = 0;
|
185
|
2717 CONST char *b = (CONST char *) buf;
|
0
|
2718
|
|
2719 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
|
|
2720 while (nbyte > 0)
|
|
2721 {
|
|
2722 rtnval = write (fildes, b, nbyte);
|
|
2723
|
|
2724 if (allow_quit)
|
|
2725 REALLY_QUIT;
|
|
2726
|
|
2727 if (rtnval == -1)
|
|
2728 {
|
|
2729 if (errno == EINTR)
|
|
2730 continue;
|
|
2731 else
|
|
2732 return (bytes_written ? bytes_written : -1);
|
|
2733 }
|
|
2734 b += rtnval;
|
|
2735 nbyte -= rtnval;
|
|
2736 bytes_written += rtnval;
|
|
2737 }
|
|
2738 return (bytes_written);
|
|
2739 }
|
|
2740
|
|
2741 #ifdef ENCAPSULATE_WRITE
|
|
2742 int
|
272
|
2743 sys_write (int fildes, CONST void *buf, size_t nbyte)
|
0
|
2744 {
|
|
2745 return sys_write_1 (fildes, buf, nbyte, 0);
|
|
2746 }
|
|
2747 #endif /* ENCAPSULATE_WRITE */
|
|
2748
|
|
2749
|
|
2750 /**************** stdio calls ****************/
|
|
2751
|
|
2752 /* There is at least some evidence that the stdio calls are interruptible
|
|
2753 just like the normal system calls, at least on some systems. In any
|
|
2754 case, it doesn't hurt to encapsulate them. */
|
|
2755
|
|
2756 /* #### Should also encapsulate fflush().
|
|
2757 #### Should conceivably encapsulate getchar() etc. What a pain! */
|
|
2758
|
|
2759 #ifdef ENCAPSULATE_FOPEN
|
|
2760 FILE *
|
|
2761 sys_fopen (CONST char *path, CONST char *type)
|
|
2762 {
|
|
2763 PATHNAME_CONVERT_OUT (path);
|
|
2764 #ifdef INTERRUPTIBLE_OPEN
|
|
2765 {
|
|
2766 FILE *rtnval;
|
|
2767 while (!(rtnval = fopen (path, type)) && (errno == EINTR));
|
|
2768 return rtnval;
|
|
2769 }
|
|
2770 #else
|
|
2771 return fopen (path, type);
|
|
2772 #endif
|
|
2773 }
|
|
2774 #endif /* ENCAPSULATE_FOPEN */
|
|
2775
|
16
|
2776
|
0
|
2777 #ifdef ENCAPSULATE_FCLOSE
|
|
2778 int
|
|
2779 sys_fclose (FILE *stream)
|
|
2780 {
|
|
2781 #ifdef INTERRUPTIBLE_CLOSE
|
|
2782 int rtnval;
|
|
2783
|
|
2784 while ((rtnval = fclose (stream)) == EOF
|
|
2785 && (errno == EINTR))
|
|
2786 ;
|
|
2787 return rtnval;
|
|
2788 #else
|
|
2789 return fclose (stream);
|
|
2790 #endif
|
|
2791 }
|
|
2792 #endif /* ENCAPSULATE_FCLOSE */
|
|
2793
|
16
|
2794
|
0
|
2795 #ifdef ENCAPSULATE_FREAD
|
|
2796 size_t
|
|
2797 sys_fread (void *ptr, size_t size, size_t nitem, FILE *stream)
|
|
2798 {
|
|
2799 #ifdef INTERRUPTIBLE_IO
|
|
2800 size_t rtnval;
|
|
2801 size_t items_read = 0;
|
|
2802 char *b = (char *) ptr;
|
|
2803
|
|
2804 while (nitem > 0)
|
|
2805 {
|
|
2806 rtnval = fread (b, size, nitem, stream);
|
|
2807 if (rtnval == 0)
|
|
2808 {
|
|
2809 if (ferror (stream) && errno == EINTR)
|
|
2810 continue;
|
|
2811 else
|
|
2812 return items_read;
|
|
2813 }
|
|
2814 b += size*rtnval;
|
|
2815 nitem -= rtnval;
|
|
2816 items_read += rtnval;
|
|
2817 }
|
|
2818 return (items_read);
|
|
2819 #else
|
|
2820 return fread (ptr, size, nitem, stream);
|
|
2821 #endif
|
|
2822 }
|
|
2823 #endif /* ENCAPSULATE_FREAD */
|
|
2824
|
16
|
2825
|
0
|
2826 #ifdef ENCAPSULATE_FWRITE
|
|
2827 size_t
|
|
2828 sys_fwrite (CONST void *ptr, size_t size, size_t nitem, FILE *stream)
|
|
2829 {
|
|
2830 #ifdef INTERRUPTIBLE_IO
|
|
2831 size_t rtnval;
|
|
2832 size_t items_written = 0;
|
|
2833 CONST char *b = (CONST char *) ptr;
|
|
2834
|
|
2835 while (nitem > 0)
|
|
2836 {
|
|
2837 rtnval = fwrite (b, size, nitem, stream);
|
|
2838 if (rtnval == 0)
|
|
2839 {
|
|
2840 if (ferror (stream) && errno == EINTR)
|
|
2841 continue;
|
|
2842 else
|
|
2843 return items_written;
|
|
2844 }
|
|
2845 b += size*rtnval;
|
|
2846 nitem -= rtnval;
|
|
2847 items_written += rtnval;
|
|
2848 }
|
|
2849 return (items_written);
|
|
2850 #else
|
|
2851 return fwrite (ptr, size, nitem, stream);
|
|
2852 #endif
|
|
2853 }
|
|
2854 #endif /* ENCAPSULATE_FWRITE */
|
|
2855
|
|
2856
|
|
2857 /********************* directory calls *******************/
|
|
2858
|
|
2859 #ifdef ENCAPSULATE_CHDIR
|
|
2860 int
|
|
2861 sys_chdir (CONST char *path)
|
|
2862 {
|
|
2863 PATHNAME_CONVERT_OUT (path);
|
|
2864 #ifdef MSDOS
|
|
2865 return dos_chdir (path);
|
|
2866 #else
|
|
2867 return chdir (path);
|
|
2868 #endif
|
|
2869 }
|
|
2870 #endif /* ENCAPSULATE_CHDIR */
|
|
2871
|
16
|
2872
|
0
|
2873 #ifdef ENCAPSULATE_MKDIR
|
|
2874 int
|
272
|
2875 sys_mkdir (CONST char *path, mode_t mode)
|
0
|
2876 {
|
|
2877 PATHNAME_CONVERT_OUT (path);
|
|
2878 return mkdir (path, mode);
|
|
2879 }
|
|
2880 #endif /* ENCAPSULATE_MKDIR */
|
|
2881
|
16
|
2882
|
0
|
2883 #ifdef ENCAPSULATE_OPENDIR
|
|
2884 DIR *
|
|
2885 sys_opendir (CONST char *filename)
|
|
2886 {
|
|
2887 DIR *rtnval;
|
|
2888 PATHNAME_CONVERT_OUT (filename);
|
|
2889
|
|
2890 while (!(rtnval = opendir (filename))
|
|
2891 && (errno == EINTR))
|
|
2892 ;
|
|
2893 return rtnval;
|
|
2894 }
|
|
2895 #endif /* ENCAPSULATE_OPENDIR */
|
|
2896
|
16
|
2897
|
0
|
2898 #ifdef ENCAPSULATE_READDIR
|
|
2899 DIRENTRY *
|
|
2900 sys_readdir (DIR *dirp)
|
185
|
2901 {
|
0
|
2902 DIRENTRY *rtnval;
|
|
2903
|
|
2904 /* Apparently setting errno is necessary on some systems?
|
|
2905 Maybe readdir() doesn't always set errno ?! */
|
|
2906 while (!(errno = 0, rtnval = readdir (dirp))
|
|
2907 && (errno == EINTR))
|
|
2908 ;
|
70
|
2909 #ifndef MULE
|
0
|
2910 return rtnval;
|
70
|
2911 #else /* MULE */
|
|
2912 if (rtnval == NULL) /* End of directory */
|
|
2913 return NULL;
|
|
2914 {
|
|
2915 Extcount external_len;
|
|
2916 int ascii_filename_p = 1;
|
|
2917 CONST Extbyte * CONST external_name = (CONST Extbyte *) rtnval->d_name;
|
185
|
2918
|
70
|
2919 /* Optimize for the common all-ASCII case, computing len en passant */
|
|
2920 for (external_len = 0; external_name[external_len] ; external_len++)
|
|
2921 {
|
|
2922 if (!BYTE_ASCII_P (external_name[external_len]))
|
|
2923 ascii_filename_p = 0;
|
|
2924 }
|
|
2925 if (ascii_filename_p)
|
|
2926 return rtnval;
|
|
2927
|
|
2928 { /* Non-ASCII filename */
|
185
|
2929 static Bufbyte_dynarr *internal_DIRENTRY;
|
70
|
2930 CONST Bufbyte *internal_name;
|
|
2931 Bytecount internal_len;
|
|
2932 if (!internal_DIRENTRY)
|
|
2933 internal_DIRENTRY = Dynarr_new (Bufbyte);
|
|
2934 else
|
|
2935 Dynarr_reset (internal_DIRENTRY);
|
|
2936
|
|
2937 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval,
|
|
2938 offsetof (DIRENTRY, d_name));
|
|
2939
|
|
2940 internal_name =
|
|
2941 convert_from_external_format (external_name, external_len,
|
|
2942 &internal_len, FORMAT_FILENAME);
|
|
2943
|
|
2944 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len);
|
|
2945 Dynarr_add (internal_DIRENTRY, 0); /* zero-terminate */
|
|
2946 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0);
|
|
2947 }
|
|
2948 }
|
|
2949 #endif /* MULE */
|
0
|
2950 }
|
|
2951 #endif /* ENCAPSULATE_READDIR */
|
|
2952
|
16
|
2953
|
0
|
2954 #ifdef ENCAPSULATE_CLOSEDIR
|
|
2955 int
|
|
2956 sys_closedir (DIR *dirp)
|
|
2957 {
|
|
2958 int rtnval;
|
|
2959
|
|
2960 while ((rtnval = closedir (dirp)) == -1
|
|
2961 && (errno == EINTR))
|
|
2962 ;
|
|
2963 return rtnval;
|
|
2964 }
|
|
2965 #endif /* ENCAPSULATE_CLOSEDIR */
|
|
2966
|
16
|
2967
|
0
|
2968 #ifdef ENCAPSULATE_RMDIR
|
|
2969 int
|
|
2970 sys_rmdir (CONST char *path)
|
|
2971 {
|
|
2972 PATHNAME_CONVERT_OUT (path);
|
|
2973 return rmdir (path);
|
|
2974 }
|
|
2975 #endif /* ENCAPSULATE_RMDIR */
|
|
2976
|
|
2977
|
|
2978 /***************** file-information calls ******************/
|
|
2979
|
|
2980 #ifdef ENCAPSULATE_ACCESS
|
|
2981 int
|
|
2982 sys_access (CONST char *path, int mode)
|
|
2983 {
|
|
2984 PATHNAME_CONVERT_OUT (path);
|
|
2985 return access (path, mode);
|
|
2986 }
|
|
2987 #endif /* ENCAPSULATE_ACCESS */
|
|
2988
|
16
|
2989
|
2
|
2990 #ifdef HAVE_EACCESS
|
|
2991 #ifdef ENCAPSULATE_EACCESS
|
|
2992 int
|
|
2993 sys_eaccess (CONST char *path, int mode)
|
|
2994 {
|
|
2995 PATHNAME_CONVERT_OUT (path);
|
|
2996 return eaccess (path, mode);
|
|
2997 }
|
|
2998 #endif /* ENCAPSULATE_EACCESS */
|
|
2999 #endif /* HAVE_EACCESS */
|
|
3000
|
|
3001
|
0
|
3002 #ifdef ENCAPSULATE_LSTAT
|
|
3003 int
|
|
3004 sys_lstat (CONST char *path, struct stat *buf)
|
|
3005 {
|
|
3006 PATHNAME_CONVERT_OUT (path);
|
|
3007 return lstat (path, buf);
|
|
3008 }
|
|
3009 #endif /* ENCAPSULATE_LSTAT */
|
|
3010
|
16
|
3011
|
0
|
3012 #ifdef ENCAPSULATE_READLINK
|
|
3013 int
|
272
|
3014 sys_readlink (CONST char *path, char *buf, size_t bufsiz)
|
0
|
3015 {
|
|
3016 PATHNAME_CONVERT_OUT (path);
|
|
3017 /* #### currently we don't do conversions on the incoming data */
|
|
3018 return readlink (path, buf, bufsiz);
|
|
3019 }
|
|
3020 #endif /* ENCAPSULATE_READLINK */
|
|
3021
|
16
|
3022
|
0
|
3023 #ifdef ENCAPSULATE_STAT
|
|
3024 int
|
|
3025 sys_stat (CONST char *path, struct stat *buf)
|
|
3026 {
|
|
3027 PATHNAME_CONVERT_OUT (path);
|
|
3028 return stat (path, buf);
|
|
3029 }
|
|
3030 #endif /* ENCAPSULATE_STAT */
|
|
3031
|
|
3032
|
|
3033 /****************** file-manipulation calls *****************/
|
|
3034
|
|
3035 #ifdef ENCAPSULATE_CHMOD
|
|
3036 int
|
272
|
3037 sys_chmod (CONST char *path, mode_t mode)
|
0
|
3038 {
|
|
3039 PATHNAME_CONVERT_OUT (path);
|
|
3040 return chmod (path, mode);
|
|
3041 }
|
|
3042 #endif /* ENCAPSULATE_CHMOD */
|
|
3043
|
16
|
3044
|
0
|
3045 #ifdef ENCAPSULATE_CREAT
|
|
3046 int
|
272
|
3047 sys_creat (CONST char *path, mode_t mode)
|
0
|
3048 {
|
|
3049 PATHNAME_CONVERT_OUT (path);
|
|
3050 return creat (path, mode);
|
|
3051 }
|
|
3052 #endif /* ENCAPSULATE_CREAT */
|
|
3053
|
16
|
3054
|
0
|
3055 #ifdef ENCAPSULATE_LINK
|
|
3056 int
|
|
3057 sys_link (CONST char *existing, CONST char *new)
|
|
3058 {
|
|
3059 PATHNAME_CONVERT_OUT (existing);
|
|
3060 PATHNAME_CONVERT_OUT (new);
|
|
3061 return link (existing, new);
|
|
3062 }
|
|
3063 #endif /* ENCAPSULATE_LINK */
|
|
3064
|
16
|
3065
|
0
|
3066 #ifdef ENCAPSULATE_RENAME
|
|
3067 int
|
|
3068 sys_rename (CONST char *old, CONST char *new)
|
|
3069 {
|
|
3070 PATHNAME_CONVERT_OUT (old);
|
|
3071 PATHNAME_CONVERT_OUT (new);
|
|
3072 return rename (old, new);
|
|
3073 }
|
|
3074 #endif /* ENCAPSULATE_RENAME */
|
|
3075
|
16
|
3076
|
0
|
3077 #ifdef ENCAPSULATE_SYMLINK
|
|
3078 int
|
|
3079 sys_symlink (CONST char *name1, CONST char *name2)
|
|
3080 {
|
|
3081 PATHNAME_CONVERT_OUT (name1);
|
|
3082 PATHNAME_CONVERT_OUT (name2);
|
|
3083 return symlink (name1, name2);
|
|
3084 }
|
|
3085 #endif /* ENCAPSULATE_SYMLINK */
|
|
3086
|
16
|
3087
|
0
|
3088 #ifdef ENCAPSULATE_UNLINK
|
|
3089 int
|
|
3090 sys_unlink (CONST char *path)
|
|
3091 {
|
|
3092 PATHNAME_CONVERT_OUT (path);
|
|
3093 return unlink (path);
|
|
3094 }
|
|
3095 #endif /* ENCAPSULATE_UNLINK */
|
|
3096
|
16
|
3097
|
|
3098 #ifdef ENCAPSULATE_EXECVP
|
|
3099 int
|
82
|
3100 sys_execvp (CONST char *path, char * CONST * argv)
|
16
|
3101 {
|
82
|
3102 int i, argc;
|
272
|
3103 char ** new_argv;
|
185
|
3104
|
16
|
3105 PATHNAME_CONVERT_OUT (path);
|
82
|
3106 for (argc = 0; argv[argc]; argc++)
|
|
3107 ;
|
272
|
3108 new_argv = alloca_array (char *, argc + 1);
|
82
|
3109 for (i = 0; i < argc; i++)
|
272
|
3110 {
|
|
3111 new_argv[i] = argv[i];
|
|
3112 PATHNAME_CONVERT_OUT (new_argv[i]);
|
|
3113 }
|
82
|
3114 new_argv[argc] = NULL;
|
272
|
3115 return execvp (path, new_argv);
|
16
|
3116 }
|
|
3117 #endif /* ENCAPSULATE_EXECVP */
|
|
3118
|
0
|
3119
|
|
3120 /************************************************************************/
|
|
3121 /* Emulations of missing system calls */
|
|
3122 /************************************************************************/
|
|
3123
|
|
3124 /***** (these are primarily required for USG, it seems) *****/
|
|
3125
|
163
|
3126 #ifndef HAVE_GETCWD
|
|
3127 char *
|
|
3128 getcwd (char *pathname, int size)
|
|
3129 {
|
|
3130 return getwd (pathname);
|
|
3131 }
|
|
3132 #endif /* emulate getcwd */
|
|
3133
|
|
3134
|
|
3135 #if 0 /* mrb */
|
0
|
3136 /*
|
16
|
3137 * Warning, this function may not duplicate BSD 4.2 action properly
|
0
|
3138 * under error conditions.
|
|
3139 */
|
|
3140
|
|
3141 #ifndef HAVE_GETWD
|
|
3142 char *
|
|
3143 getwd (char *pathname)
|
|
3144 {
|
|
3145 char *npath, *spath;
|
|
3146 #if !__STDC__ && !defined(STDC_HEADERS)
|
|
3147 extern char *getcwd ();
|
|
3148 #endif
|
|
3149
|
|
3150 spath = npath = getcwd ((char *) 0, MAXPATHLEN);
|
|
3151 if (spath == 0)
|
|
3152 return spath;
|
|
3153 /* On Altos 3068, getcwd can return @hostname/dir, so discard
|
|
3154 up to first slash. Should be harmless on other systems. */
|
|
3155 while (*npath && *npath != '/')
|
|
3156 npath++;
|
|
3157 strcpy (pathname, npath);
|
|
3158 xfree (spath); /* getcwd uses malloc */
|
|
3159 return pathname;
|
|
3160 }
|
|
3161 #endif /* HAVE_GETWD */
|
163
|
3162 #endif /* 0 - mrb */
|
0
|
3163
|
|
3164 /*
|
|
3165 * Emulate rename using unlink/link. Note that this is
|
|
3166 * only partially correct. Also, doesn't enforce restriction
|
|
3167 * that files be of same type (regular->regular, dir->dir, etc).
|
|
3168 */
|
|
3169
|
|
3170 #ifndef HAVE_RENAME
|
|
3171 int
|
|
3172 rename (CONST char *from, CONST char *to)
|
|
3173 {
|
|
3174 if (access (from, 0) == 0)
|
|
3175 {
|
|
3176 unlink (to);
|
|
3177 if (link (from, to) == 0)
|
|
3178 if (unlink (from) == 0)
|
|
3179 return (0);
|
|
3180 }
|
|
3181 return (-1);
|
|
3182 }
|
16
|
3183 #endif /* HAVE_RENAME */
|
0
|
3184
|
|
3185 #ifdef HPUX
|
|
3186 #ifndef HAVE_PERROR
|
|
3187
|
|
3188 /* HPUX curses library references perror, but as far as we know
|
|
3189 it won't be called. Anyway this definition will do for now. */
|
|
3190
|
|
3191 perror (void)
|
|
3192 {
|
|
3193 }
|
|
3194
|
|
3195 #endif /* not HAVE_PERROR */
|
|
3196 #endif /* HPUX */
|
|
3197
|
|
3198 #ifndef HAVE_DUP2
|
|
3199
|
|
3200 /*
|
|
3201 * Emulate BSD dup2. First close newd if it already exists.
|
|
3202 * Then, attempt to dup oldd. If not successful, call dup2 recursively
|
|
3203 * until we are, then close the unsuccessful ones.
|
|
3204 */
|
|
3205
|
|
3206 int
|
|
3207 dup2 (int oldd, int newd)
|
|
3208 {
|
|
3209 int fd, ret;
|
185
|
3210
|
0
|
3211 sys_close (newd);
|
|
3212
|
|
3213 #ifdef F_DUPFD
|
|
3214 fd = fcntl (oldd, F_DUPFD, newd);
|
|
3215 if (fd != newd)
|
|
3216 error ("can't dup2 (%i,%i) : %s", oldd, newd, strerror (errno));
|
|
3217 #else
|
|
3218 fd = dup (old);
|
|
3219 if (fd == -1)
|
|
3220 return -1;
|
|
3221 if (fd == new)
|
|
3222 return new;
|
|
3223 ret = dup2 (old, new);
|
|
3224 sys_close (fd);
|
|
3225 return ret;
|
|
3226 #endif /* F_DUPFD */
|
|
3227 }
|
|
3228
|
|
3229 #endif /* not HAVE_DUP2 */
|
|
3230
|
|
3231 /*
|
|
3232 * Gettimeofday. Simulate as much as possible. Only accurate
|
|
3233 * to nearest second. Emacs doesn't use tzp so ignore it for now.
|
|
3234 */
|
|
3235
|
|
3236 #if !defined (HAVE_GETTIMEOFDAY)
|
185
|
3237
|
0
|
3238 int
|
|
3239 gettimeofday (struct timeval *tp, struct timezone *tzp)
|
|
3240 {
|
|
3241 extern long time ();
|
|
3242
|
185
|
3243 tp->tv_sec = time ((long *)0);
|
0
|
3244 tp->tv_usec = 0;
|
|
3245 if (tzp != 0)
|
|
3246 tzp->tz_minuteswest = -1;
|
|
3247 return (0);
|
|
3248 }
|
185
|
3249
|
0
|
3250 #endif /* !HAVE_GETTIMEOFDAY */
|
185
|
3251
|
0
|
3252 /* No need to encapsulate utime and utimes explicitly because all
|
|
3253 access to those functions goes through the following. */
|
|
3254
|
|
3255 int
|
|
3256 set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime)
|
|
3257 {
|
|
3258 #ifdef HAVE_UTIMES
|
|
3259 struct timeval tv[2];
|
|
3260 tv[0] = atime;
|
|
3261 tv[1] = mtime;
|
|
3262 return utimes (filename, tv);
|
|
3263 #else /* not HAVE_UTIMES */
|
|
3264 struct utimbuf utb;
|
|
3265 utb.actime = EMACS_SECS (atime);
|
|
3266 utb.modtime = EMACS_SECS (mtime);
|
|
3267 return utime (filename, &utb);
|
|
3268 #endif /* not HAVE_UTIMES */
|
|
3269 }
|
|
3270
|
|
3271 /* */
|
|
3272
|
|
3273 static long ticks_per_second;
|
|
3274 static long orig_user_ticks, orig_system_ticks;
|
|
3275 EMACS_TIME orig_real_time;
|
|
3276
|
|
3277 static int process_times_available;
|
|
3278
|
|
3279 /* Return the relative user and system tick count. We try to
|
|
3280 maintain calculations in terms of integers as long as possible
|
|
3281 for increased accuracy. */
|
|
3282
|
|
3283 static int
|
|
3284 get_process_times_1 (long *user_ticks, long *system_ticks)
|
|
3285 {
|
100
|
3286 #if defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WINDOWSNT)
|
0
|
3287 /* We have the POSIX times() function available. */
|
|
3288 struct tms tttt;
|
|
3289 times (&tttt);
|
|
3290 *user_ticks = (long) tttt.tms_utime;
|
|
3291 *system_ticks = (long) tttt.tms_stime;
|
|
3292 return 1;
|
|
3293 #elif defined (CLOCKS_PER_SEC)
|
100
|
3294 *user_ticks = (long) clock ();
|
|
3295 *system_ticks = 0;
|
0
|
3296 return 1;
|
|
3297 #else
|
|
3298 return 0;
|
|
3299 #endif
|
|
3300 }
|
|
3301
|
|
3302 void
|
|
3303 init_process_times_very_early (void)
|
|
3304 {
|
|
3305 #if defined (_SC_CLK_TCK)
|
|
3306 ticks_per_second = sysconf (_SC_CLK_TCK);
|
|
3307 #elif defined (CLK_TCK)
|
|
3308 ticks_per_second = CLK_TCK;
|
|
3309 #elif defined (CLOCKS_PER_SEC)
|
|
3310 ticks_per_second = CLOCKS_PER_SEC;
|
|
3311 #endif
|
|
3312
|
|
3313 process_times_available = get_process_times_1 (&orig_user_ticks,
|
|
3314 &orig_system_ticks);
|
|
3315 EMACS_GET_TIME (orig_real_time);
|
|
3316 }
|
|
3317
|
|
3318 /* Return the user and system times used up by this process so far. */
|
|
3319 void
|
|
3320 get_process_times (double *user_time, double *system_time, double *real_time)
|
|
3321 {
|
|
3322 EMACS_TIME curr_real_time;
|
|
3323 EMACS_TIME elapsed_time;
|
|
3324 long curr_user_ticks, curr_system_ticks;
|
|
3325
|
|
3326 EMACS_GET_TIME (curr_real_time);
|
|
3327 EMACS_SUB_TIME (elapsed_time, curr_real_time, orig_real_time);
|
|
3328 *real_time = (EMACS_SECS (elapsed_time)
|
|
3329 + ((double) EMACS_USECS (elapsed_time)) / 1000000);
|
|
3330 if (get_process_times_1 (&curr_user_ticks, &curr_system_ticks))
|
|
3331 {
|
|
3332 *user_time = (((double) (curr_user_ticks - orig_user_ticks))
|
|
3333 / ticks_per_second);
|
|
3334 *system_time = (((double) (curr_system_ticks - orig_system_ticks))
|
|
3335 / ticks_per_second);
|
|
3336 }
|
|
3337 else
|
|
3338 {
|
|
3339 /* MS-DOS or equally lame OS */
|
|
3340 *user_time = *real_time;
|
|
3341 *system_time = 0;
|
|
3342 }
|
|
3343 }
|
|
3344
|
|
3345 #ifndef HAVE_RANDOM
|
|
3346 #ifdef random
|
|
3347 #define HAVE_RANDOM
|
|
3348 #endif
|
|
3349 #endif
|
|
3350
|
|
3351 /* Figure out how many bits the system's random number generator uses.
|
|
3352 `random' and `lrand48' are assumed to return 31 usable bits.
|
|
3353 BSD `rand' returns a 31 bit value but the low order bits are unusable;
|
|
3354 so we'll shift it and treat it like the 15-bit USG `rand'. */
|
|
3355
|
|
3356 #ifndef RAND_BITS
|
|
3357 # ifdef HAVE_RANDOM
|
|
3358 # define RAND_BITS 31
|
|
3359 # else /* !HAVE_RANDOM */
|
|
3360 # ifdef HAVE_LRAND48
|
|
3361 # define RAND_BITS 31
|
|
3362 # define random lrand48
|
|
3363 # else /* !HAVE_LRAND48 */
|
|
3364 # define RAND_BITS 15
|
|
3365 # if RAND_MAX == 32767
|
|
3366 # define random rand
|
|
3367 # else /* RAND_MAX != 32767 */
|
|
3368 # if RAND_MAX == 2147483647
|
|
3369 # define random() (rand () >> 16)
|
|
3370 # else /* RAND_MAX != 2147483647 */
|
|
3371 # ifdef USG
|
|
3372 # define random rand
|
|
3373 # else
|
|
3374 # define random() (rand () >> 16)
|
|
3375 # endif /* !BSD */
|
|
3376 # endif /* RAND_MAX != 2147483647 */
|
|
3377 # endif /* RAND_MAX != 32767 */
|
|
3378 # endif /* !HAVE_LRAND48 */
|
|
3379 # endif /* !HAVE_RANDOM */
|
|
3380 #endif /* !RAND_BITS */
|
|
3381
|
|
3382 void seed_random (long arg);
|
|
3383 void
|
|
3384 seed_random (long arg)
|
|
3385 {
|
|
3386 #ifdef HAVE_RANDOM
|
|
3387 srandom ((unsigned int)arg);
|
|
3388 #else
|
|
3389 # ifdef HAVE_LRAND48
|
|
3390 srand48 (arg);
|
|
3391 # else
|
|
3392 srand ((unsigned int)arg);
|
|
3393 # endif
|
|
3394 #endif
|
|
3395 }
|
|
3396
|
|
3397 /*
|
|
3398 * Build a full Emacs-sized word out of whatever we've got.
|
|
3399 * This suffices even for a 64-bit architecture with a 15-bit rand.
|
|
3400 */
|
|
3401 long get_random (void);
|
|
3402 long
|
|
3403 get_random (void)
|
|
3404 {
|
|
3405 long val = random ();
|
|
3406 #if VALBITS > RAND_BITS
|
|
3407 val = (val << RAND_BITS) ^ random ();
|
|
3408 #if VALBITS > 2*RAND_BITS
|
|
3409 val = (val << RAND_BITS) ^ random ();
|
|
3410 #if VALBITS > 3*RAND_BITS
|
|
3411 val = (val << RAND_BITS) ^ random ();
|
|
3412 #if VALBITS > 4*RAND_BITS
|
|
3413 val = (val << RAND_BITS) ^ random ();
|
|
3414 #endif /* need at least 5 */
|
|
3415 #endif /* need at least 4 */
|
|
3416 #endif /* need at least 3 */
|
|
3417 #endif /* need at least 2 */
|
|
3418 return val & ((1L << VALBITS) - 1);
|
|
3419 }
|
|
3420
|
|
3421
|
|
3422 /************************************************************************/
|
|
3423 /* Strings corresponding to defined signals */
|
|
3424 /************************************************************************/
|
|
3425
|
|
3426 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST)
|
|
3427
|
231
|
3428 #if defined(WINDOWSNT) || defined(__CYGWIN32__)
|
|
3429 CONST char *sys_siglist[] =
|
100
|
3430 {
|
|
3431 "bum signal!!",
|
|
3432 "hangup",
|
|
3433 "interrupt",
|
|
3434 "quit",
|
|
3435 "illegal instruction",
|
|
3436 "trace trap",
|
|
3437 "iot instruction",
|
|
3438 "emt instruction",
|
|
3439 "floating point exception",
|
|
3440 "kill",
|
|
3441 "bus error",
|
|
3442 "segmentation violation",
|
|
3443 "bad argument to system call",
|
|
3444 "write on a pipe with no one to read it",
|
|
3445 "alarm clock",
|
|
3446 "software termination signal from kill",
|
|
3447 "status signal",
|
|
3448 "sendable stop signal not from tty",
|
|
3449 "stop signal from tty",
|
|
3450 "continue a stopped process",
|
|
3451 "child status has changed",
|
|
3452 "background read attempted from control tty",
|
|
3453 "background write attempted from control tty",
|
|
3454 "input record available at control tty",
|
|
3455 "exceeded CPU time limit",
|
|
3456 "exceeded file size limit"
|
|
3457 };
|
|
3458 #endif
|
|
3459
|
0
|
3460 #ifdef USG
|
|
3461 #ifdef AIX
|
|
3462 CONST char *sys_siglist[NSIG + 1] =
|
|
3463 {
|
|
3464 /* AIX has changed the signals a bit */
|
|
3465 DEFER_GETTEXT ("bogus signal"), /* 0 */
|
|
3466 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
|
|
3467 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
|
|
3468 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
|
|
3469 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
|
|
3470 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
|
|
3471 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
|
|
3472 DEFER_GETTEXT ("crash likely"), /* 7 SIGDANGER */
|
|
3473 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
|
|
3474 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
|
|
3475 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
|
|
3476 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
|
|
3477 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
|
|
3478 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
|
|
3479 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
|
|
3480 DEFER_GETTEXT ("software termination signum"), /* 15 SIGTERM */
|
|
3481 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
|
|
3482 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
|
|
3483 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
|
|
3484 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
|
|
3485 DEFER_GETTEXT ("bogus signal"), /* 20 */
|
|
3486 DEFER_GETTEXT ("bogus signal"), /* 21 */
|
|
3487 DEFER_GETTEXT ("bogus signal"), /* 22 */
|
|
3488 DEFER_GETTEXT ("bogus signal"), /* 23 */
|
|
3489 DEFER_GETTEXT ("bogus signal"), /* 24 */
|
|
3490 DEFER_GETTEXT ("LAN I/O interrupt"), /* 25 SIGAIO */
|
|
3491 DEFER_GETTEXT ("PTY I/O interrupt"), /* 26 SIGPTY */
|
|
3492 DEFER_GETTEXT ("I/O intervention required"), /* 27 SIGIOINT */
|
|
3493 #ifdef AIXHFT
|
|
3494 DEFER_GETTEXT ("HFT grant"), /* 28 SIGGRANT */
|
|
3495 DEFER_GETTEXT ("HFT retract"), /* 29 SIGRETRACT */
|
|
3496 DEFER_GETTEXT ("HFT sound done"), /* 30 SIGSOUND */
|
|
3497 DEFER_GETTEXT ("HFT input ready"), /* 31 SIGMSG */
|
|
3498 #endif
|
|
3499 0
|
|
3500 };
|
|
3501 #else /* USG, not AIX */
|
|
3502 CONST char *sys_siglist[NSIG + 1] =
|
|
3503 {
|
|
3504 DEFER_GETTEXT ("bogus signal"), /* 0 */
|
|
3505 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
|
|
3506 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
|
|
3507 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
|
|
3508 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
|
|
3509 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
|
|
3510 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
|
|
3511 DEFER_GETTEXT ("EMT instruction"), /* 7 SIGEMT */
|
|
3512 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
|
|
3513 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
|
|
3514 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
|
|
3515 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
|
|
3516 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
|
|
3517 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
|
|
3518 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
|
|
3519 DEFER_GETTEXT ("software termination signum"), /* 15 SIGTERM */
|
|
3520 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
|
|
3521 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
|
|
3522 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
|
|
3523 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
|
|
3524 #ifdef sun
|
|
3525 DEFER_GETTEXT ("window size changed"), /* 20 SIGWINCH */
|
|
3526 DEFER_GETTEXT ("urgent socket condition"), /* 21 SIGURG */
|
|
3527 DEFER_GETTEXT ("pollable event occurred"), /* 22 SIGPOLL */
|
|
3528 DEFER_GETTEXT ("stop (cannot be caught or ignored)"), /* 23 SIGSTOP */
|
|
3529 DEFER_GETTEXT ("user stop requested from tty"), /* 24 SIGTSTP */
|
|
3530 DEFER_GETTEXT ("stopped process has been continued"), /* 25 SIGCONT */
|
|
3531 DEFER_GETTEXT ("background tty read attempted"), /* 26 SIGTTIN */
|
|
3532 DEFER_GETTEXT ("background tty write attempted"), /* 27 SIGTTOU */
|
|
3533 DEFER_GETTEXT ("virtual timer expired"), /* 28 SIGVTALRM */
|
|
3534 DEFER_GETTEXT ("profiling timer expired"), /* 29 SIGPROF */
|
|
3535 DEFER_GETTEXT ("exceeded cpu limit"), /* 30 SIGXCPU */
|
|
3536 DEFER_GETTEXT ("exceeded file size limit"), /* 31 SIGXFSZ */
|
|
3537 DEFER_GETTEXT ("process's lwps are blocked"), /* 32 SIGWAITING */
|
|
3538 DEFER_GETTEXT ("special signal used by thread library"), /* 33 SIGLWP */
|
|
3539 #ifdef SIGFREEZE
|
|
3540 DEFER_GETTEXT ("special signal used by CPR"), /* 34 SIGFREEZE */
|
|
3541 #endif
|
|
3542 #ifdef SIGTHAW
|
|
3543 DEFER_GETTEXT ("special signal used by CPR"), /* 35 SIGTHAW */
|
|
3544 #endif
|
|
3545 #endif /* sun */
|
|
3546 0
|
|
3547 };
|
|
3548 #endif /* not AIX */
|
|
3549 #endif /* USG */
|
|
3550 #ifdef DGUX
|
|
3551 CONST char *sys_siglist[NSIG + 1] =
|
|
3552 {
|
|
3553 DEFER_GETTEXT ("null signal"), /* 0 SIGNULL */
|
|
3554 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
|
|
3555 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
|
|
3556 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
|
|
3557 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
|
|
3558 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
|
|
3559 DEFER_GETTEXT ("abort termination"), /* 6 SIGABRT */
|
|
3560 DEFER_GETTEXT ("SIGEMT"), /* 7 SIGEMT */
|
|
3561 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
|
|
3562 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
|
|
3563 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
|
|
3564 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
|
|
3565 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
|
|
3566 DEFER_GETTEXT ("write on a pipe with no reader"), /* 13 SIGPIPE */
|
|
3567 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
|
|
3568 DEFER_GETTEXT ("software termination signal"), /* 15 SIGTERM */
|
|
3569 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
|
|
3570 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
|
|
3571 DEFER_GETTEXT ("child stopped or terminated"), /* 18 SIGCLD */
|
|
3572 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
|
|
3573 DEFER_GETTEXT ("window size changed"), /* 20 SIGWINCH */
|
|
3574 DEFER_GETTEXT ("undefined"), /* 21 */
|
|
3575 DEFER_GETTEXT ("pollable event occurred"), /* 22 SIGPOLL */
|
|
3576 DEFER_GETTEXT ("sendable stop signal not from tty"), /* 23 SIGSTOP */
|
|
3577 DEFER_GETTEXT ("stop signal from tty"), /* 24 SIGSTP */
|
|
3578 DEFER_GETTEXT ("continue a stopped process"), /* 25 SIGCONT */
|
|
3579 DEFER_GETTEXT ("attempted background tty read"), /* 26 SIGTTIN */
|
|
3580 DEFER_GETTEXT ("attempted background tty write"), /* 27 SIGTTOU */
|
|
3581 DEFER_GETTEXT ("undefined"), /* 28 */
|
|
3582 DEFER_GETTEXT ("undefined"), /* 29 */
|
|
3583 DEFER_GETTEXT ("undefined"), /* 30 */
|
|
3584 DEFER_GETTEXT ("undefined"), /* 31 */
|
|
3585 DEFER_GETTEXT ("undefined"), /* 32 */
|
|
3586 DEFER_GETTEXT ("socket (TCP/IP) urgent data arrival"), /* 33 SIGURG */
|
|
3587 DEFER_GETTEXT ("I/O is possible"), /* 34 SIGIO */
|
|
3588 DEFER_GETTEXT ("exceeded cpu time limit"), /* 35 SIGXCPU */
|
|
3589 DEFER_GETTEXT ("exceeded file size limit"), /* 36 SIGXFSZ */
|
|
3590 DEFER_GETTEXT ("virtual time alarm"), /* 37 SIGVTALRM */
|
|
3591 DEFER_GETTEXT ("profiling time alarm"), /* 38 SIGPROF */
|
|
3592 DEFER_GETTEXT ("undefined"), /* 39 */
|
|
3593 DEFER_GETTEXT ("file record locks revoked"), /* 40 SIGLOST */
|
|
3594 DEFER_GETTEXT ("undefined"), /* 41 */
|
|
3595 DEFER_GETTEXT ("undefined"), /* 42 */
|
|
3596 DEFER_GETTEXT ("undefined"), /* 43 */
|
|
3597 DEFER_GETTEXT ("undefined"), /* 44 */
|
|
3598 DEFER_GETTEXT ("undefined"), /* 45 */
|
|
3599 DEFER_GETTEXT ("undefined"), /* 46 */
|
|
3600 DEFER_GETTEXT ("undefined"), /* 47 */
|
|
3601 DEFER_GETTEXT ("undefined"), /* 48 */
|
|
3602 DEFER_GETTEXT ("undefined"), /* 49 */
|
|
3603 DEFER_GETTEXT ("undefined"), /* 50 */
|
|
3604 DEFER_GETTEXT ("undefined"), /* 51 */
|
|
3605 DEFER_GETTEXT ("undefined"), /* 52 */
|
|
3606 DEFER_GETTEXT ("undefined"), /* 53 */
|
|
3607 DEFER_GETTEXT ("undefined"), /* 54 */
|
|
3608 DEFER_GETTEXT ("undefined"), /* 55 */
|
|
3609 DEFER_GETTEXT ("undefined"), /* 56 */
|
|
3610 DEFER_GETTEXT ("undefined"), /* 57 */
|
|
3611 DEFER_GETTEXT ("undefined"), /* 58 */
|
|
3612 DEFER_GETTEXT ("undefined"), /* 59 */
|
|
3613 DEFER_GETTEXT ("undefined"), /* 60 */
|
|
3614 DEFER_GETTEXT ("undefined"), /* 61 */
|
|
3615 DEFER_GETTEXT ("undefined"), /* 62 */
|
|
3616 DEFER_GETTEXT ("undefined"), /* 63 */
|
|
3617 DEFER_GETTEXT ("notification message in mess. queue"), /* 64 SIGDGNOTIFY */
|
|
3618 0
|
|
3619 };
|
|
3620 #endif /* DGUX */
|
|
3621
|
|
3622 #endif /* ! SYS_SIGLIST_DECLARED && ! HAVE_SYS_SIGLIST */
|
|
3623
|
|
3624
|
|
3625 /************************************************************************/
|
|
3626 /* Directory routines for systems that don't have them */
|
|
3627 /************************************************************************/
|
|
3628
|
|
3629 #ifdef SYSV_SYSTEM_DIR
|
|
3630
|
|
3631 #include <dirent.h>
|
|
3632
|
|
3633 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
|
|
3634 int
|
|
3635 closedir (DIR *dirp) /* stream from opendir */
|
|
3636 {
|
|
3637 int rtnval;
|
|
3638
|
|
3639 rtnval = sys_close (dirp->dd_fd);
|
|
3640
|
|
3641 /* Some systems (like Solaris) allocate the buffer and the DIR all
|
|
3642 in one block. Why in the world are we freeing this ourselves
|
|
3643 anyway? */
|
|
3644 #if ! (defined (sun) && defined (USG5_4))
|
|
3645 xfree ((char *) dirp->dd_buf); /* directory block defined in <dirent.h> */
|
|
3646 #endif
|
|
3647 xfree ((char *) dirp);
|
|
3648 return (rtnval);
|
|
3649 }
|
|
3650 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
|
|
3651 #endif /* SYSV_SYSTEM_DIR */
|
|
3652
|
|
3653 #ifdef NONSYSTEM_DIR_LIBRARY
|
|
3654
|
|
3655 DIR *
|
|
3656 opendir (CONST char *filename) /* name of directory */
|
|
3657 {
|
|
3658 DIR *dirp; /* -> malloc'ed storage */
|
|
3659 int fd; /* file descriptor for read */
|
|
3660 struct stat sbuf; /* result of fstat */
|
|
3661
|
|
3662 fd = sys_open (filename, 0);
|
|
3663 if (fd < 0)
|
|
3664 return 0;
|
|
3665
|
|
3666 if (fstat (fd, &sbuf) < 0
|
|
3667 || (sbuf.st_mode & S_IFMT) != S_IFDIR
|
|
3668 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
|
|
3669 {
|
|
3670 sys_close (fd);
|
|
3671 return 0; /* bad luck today */
|
|
3672 }
|
|
3673
|
|
3674 dirp->dd_fd = fd;
|
|
3675 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
|
|
3676
|
|
3677 return dirp;
|
|
3678 }
|
|
3679
|
|
3680 void
|
|
3681 closedir (DIR *dirp) /* stream from opendir */
|
|
3682 {
|
|
3683 sys_close (dirp->dd_fd);
|
|
3684 xfree (dirp);
|
|
3685 }
|
|
3686
|
|
3687
|
|
3688 #define DIRSIZ 14
|
|
3689 struct olddir
|
|
3690 {
|
|
3691 ino_t od_ino; /* inode */
|
|
3692 char od_name[DIRSIZ]; /* filename */
|
|
3693 };
|
|
3694
|
|
3695 static struct direct dir_static; /* simulated directory contents */
|
|
3696
|
|
3697 /* ARGUSED */
|
|
3698 struct direct *
|
|
3699 readdir (DIR *dirp) /* stream from opendir */
|
|
3700 {
|
|
3701 struct olddir *dp; /* -> directory data */
|
|
3702
|
|
3703 for (; ;)
|
|
3704 {
|
|
3705 if (dirp->dd_loc >= dirp->dd_size)
|
|
3706 dirp->dd_loc = dirp->dd_size = 0;
|
|
3707
|
|
3708 if (dirp->dd_size == 0 /* refill buffer */
|
|
3709 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
|
|
3710 return 0;
|
|
3711
|
|
3712 dp = (struct olddir *) &dirp->dd_buf[dirp->dd_loc];
|
|
3713 dirp->dd_loc += sizeof (struct olddir);
|
|
3714
|
|
3715 if (dp->od_ino != 0) /* not deleted entry */
|
|
3716 {
|
|
3717 dir_static.d_ino = dp->od_ino;
|
|
3718 strncpy (dir_static.d_name, dp->od_name, DIRSIZ);
|
|
3719 dir_static.d_name[DIRSIZ] = '\0';
|
|
3720 dir_static.d_namlen = strlen (dir_static.d_name);
|
|
3721 dir_static.d_reclen = sizeof (struct direct)
|
|
3722 - MAXNAMLEN + 3
|
|
3723 + dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
3724 return &dir_static; /* -> simulated structure */
|
|
3725 }
|
|
3726 }
|
|
3727 }
|
|
3728
|
|
3729
|
|
3730 #endif /* NONSYSTEM_DIR_LIBRARY */
|
|
3731
|
|
3732
|
|
3733 /* mkdir and rmdir functions, for systems which don't have them. */
|
|
3734
|
|
3735 #ifndef HAVE_MKDIR
|
|
3736 /*
|
|
3737 * Written by Robert Rother, Mariah Corporation, August 1985.
|
|
3738 *
|
|
3739 * If you want it, it's yours. All I ask in return is that if you
|
|
3740 * figure out how to do this in a Bourne Shell script you send me
|
|
3741 * a copy.
|
|
3742 * sdcsvax!rmr or rmr@uscd
|
|
3743 *
|
|
3744 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
|
|
3745 * subroutine. 11Mar86; hoptoad!gnu
|
|
3746 *
|
|
3747 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
|
|
3748 * subroutine didn't return EEXIST. It does now.
|
|
3749 */
|
|
3750
|
|
3751 /*
|
|
3752 * Make a directory.
|
|
3753 */
|
|
3754 #ifdef MKDIR_PROTOTYPE
|
|
3755 MKDIR_PROTOTYPE
|
|
3756 #else
|
|
3757 int
|
|
3758 mkdir (CONST char *dpath, int dmode)
|
|
3759 #endif
|
|
3760 {
|
|
3761 int cpid, status, fd;
|
|
3762 struct stat statbuf;
|
|
3763
|
|
3764 if (stat (dpath, &statbuf) == 0)
|
|
3765 {
|
|
3766 errno = EEXIST; /* Stat worked, so it already exists */
|
|
3767 return -1;
|
|
3768 }
|
|
3769
|
|
3770 /* If stat fails for a reason other than non-existence, return error */
|
|
3771 if (errno != ENOENT)
|
|
3772 return -1;
|
|
3773
|
|
3774 synch_process_alive = 1;
|
|
3775 switch (cpid = fork ())
|
|
3776 {
|
|
3777
|
|
3778 case -1: /* Error in fork() */
|
|
3779 return (-1); /* Errno is set already */
|
|
3780
|
|
3781 case 0: /* Child process */
|
|
3782 {
|
|
3783 /*
|
|
3784 * Cheap hack to set mode of new directory. Since this
|
|
3785 * child process is going away anyway, we zap its umask.
|
|
3786 * ####, this won't suffice to set SUID, SGID, etc. on this
|
|
3787 * directory. Does anybody care?
|
|
3788 */
|
|
3789 status = umask (0); /* Get current umask */
|
|
3790 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */
|
|
3791 fd = sys_open ("/dev/null", 2);
|
|
3792 if (fd >= 0)
|
|
3793 {
|
|
3794 dup2 (fd, 0);
|
|
3795 dup2 (fd, 1);
|
|
3796 dup2 (fd, 2);
|
|
3797 }
|
|
3798 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0);
|
|
3799 _exit (-1); /* Can't exec /bin/mkdir */
|
|
3800 }
|
|
3801
|
|
3802 default: /* Parent process */
|
|
3803 wait_for_termination (cpid);
|
|
3804 }
|
|
3805
|
|
3806 if (synch_process_death != 0 || synch_process_retcode != 0)
|
|
3807 {
|
|
3808 errno = EIO; /* We don't know why, but */
|
|
3809 return -1; /* /bin/mkdir failed */
|
|
3810 }
|
|
3811
|
|
3812 return 0;
|
|
3813 }
|
|
3814 #endif /* not HAVE_MKDIR */
|
|
3815
|
|
3816 #ifndef HAVE_RMDIR
|
|
3817 int
|
|
3818 rmdir (CONST char *dpath)
|
|
3819 {
|
|
3820 int cpid, status, fd;
|
|
3821 struct stat statbuf;
|
|
3822
|
|
3823 if (stat (dpath, &statbuf) != 0)
|
|
3824 {
|
|
3825 /* Stat just set errno. We don't have to */
|
|
3826 return -1;
|
|
3827 }
|
|
3828
|
|
3829 synch_process_alive = 1;
|
|
3830 switch (cpid = fork ())
|
|
3831 {
|
|
3832
|
|
3833 case -1: /* Error in fork() */
|
|
3834 return (-1); /* Errno is set already */
|
|
3835
|
|
3836 case 0: /* Child process */
|
|
3837 fd = sys_open("/dev/null", 2);
|
|
3838 if (fd >= 0)
|
|
3839 {
|
|
3840 dup2 (fd, 0);
|
|
3841 dup2 (fd, 1);
|
|
3842 dup2 (fd, 2);
|
|
3843 }
|
|
3844 execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
|
|
3845 _exit (-1); /* Can't exec /bin/mkdir */
|
|
3846
|
|
3847 default: /* Parent process */
|
|
3848 wait_for_termination (cpid);
|
|
3849 }
|
|
3850
|
|
3851 if (synch_process_death != 0 || synch_process_retcode != 0)
|
|
3852 {
|
|
3853 errno = EIO; /* We don't know why, but */
|
|
3854 return -1; /* /bin/rmdir failed */
|
|
3855 }
|
|
3856
|
|
3857 return 0;
|
|
3858 }
|
|
3859 #endif /* !HAVE_RMDIR */
|
|
3860
|
|
3861
|
|
3862 /************************************************************************/
|
|
3863 /* Misc. SunOS crap */
|
|
3864 /************************************************************************/
|
|
3865
|
|
3866 #ifdef USE_DL_STUBS
|
|
3867
|
|
3868 /* These are included on Sunos 4.1 when we do not use shared libraries.
|
|
3869 X11 libraries may refer to these functions but (we hope) do not
|
|
3870 actually call them. */
|
|
3871
|
|
3872 void *
|
|
3873 dlopen (void)
|
|
3874 {
|
|
3875 return 0;
|
|
3876 }
|
|
3877
|
|
3878 void *
|
|
3879 dlsym (void)
|
|
3880 {
|
|
3881 return 0;
|
|
3882 }
|
|
3883
|
|
3884 int
|
|
3885 dlclose (void)
|
|
3886 {
|
|
3887 return -1;
|
|
3888 }
|
|
3889
|
|
3890 #endif /* USE_DL_STUBS */
|
|
3891
|
|
3892
|
|
3893
|
|
3894 #ifndef HAVE_STRCASECMP
|
|
3895 /*
|
|
3896 * From BSD
|
|
3897 */
|
|
3898 static unsigned char charmap[] = {
|
|
3899 '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
|
|
3900 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
|
|
3901 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
|
|
3902 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
|
|
3903 '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
|
|
3904 '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
|
|
3905 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
|
|
3906 '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
|
|
3907 '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
3908 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
3909 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
3910 '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
|
|
3911 '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
3912 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
3913 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
3914 '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
|
|
3915 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
|
|
3916 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
|
|
3917 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
|
|
3918 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
|
|
3919 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
|
|
3920 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
|
|
3921 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
|
|
3922 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
|
|
3923 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
|
|
3924 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
|
|
3925 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
|
|
3926 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
|
|
3927 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
|
|
3928 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
|
|
3929 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
|
|
3930 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
|
|
3931 };
|
|
3932
|
|
3933 int
|
|
3934 strcasecmp (char *s1, char *s2)
|
|
3935 {
|
|
3936 unsigned char *cm = charmap;
|
|
3937 unsigned char *us1 = (unsigned char *) s1;
|
|
3938 unsigned char *us2 = (unsigned char *)s2;
|
|
3939
|
|
3940 while (cm[*us1] == cm[*us2++])
|
|
3941 if (*us1++ == '\0')
|
|
3942 return (0);
|
|
3943
|
|
3944 return (cm[*us1] - cm[*--us2]);
|
|
3945 }
|
|
3946 #endif /* !HAVE_STRCASECMP */
|