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