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