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
|
|
35 /* ------------------------------- */
|
|
36 /* basic includes */
|
|
37 /* ------------------------------- */
|
|
38
|
|
39 #ifdef HAVE_TTY
|
|
40 #include "console-tty.h"
|
78
|
41 #else
|
|
42 #include "syssignal.h"
|
|
43 #include "systty.h"
|
0
|
44 #endif /* HAVE_TTY */
|
|
45
|
|
46 #include "console-stream.h"
|
|
47
|
|
48 #include "buffer.h"
|
|
49 #include "events.h"
|
|
50 #include "frame.h"
|
|
51 #include "redisplay.h"
|
|
52 #include "process.h"
|
|
53 #include "sysdep.h"
|
|
54 #include "window.h"
|
|
55
|
|
56 #include <setjmp.h>
|
2
|
57 #ifdef HAVE_LIBGEN_H /* Must come before sysfile.h */
|
|
58 #include <libgen.h>
|
|
59 #endif
|
0
|
60 #include "sysfile.h"
|
|
61 #include "syswait.h"
|
|
62 #include "sysdir.h"
|
|
63 #include "systime.h"
|
100
|
64 #if defined(WINDOWSNT)
|
|
65 #include "syssignal.h"
|
|
66 #else
|
0
|
67 #include <sys/times.h>
|
100
|
68 #endif
|
0
|
69
|
179
|
70 #ifdef WINDOWSNT
|
|
71 #include <direct.h>
|
|
72 /* In process.h which conflicts with the local copy. */
|
|
73 #define _P_WAIT 0
|
|
74 int _CRTAPI1 _spawnlp (int, const char *, const char *, ...);
|
|
75 int _CRTAPI1 _getpid (void);
|
|
76 #endif
|
|
77
|
0
|
78 /* ------------------------------- */
|
|
79 /* VMS includes */
|
|
80 /* ------------------------------- */
|
|
81
|
|
82 #ifdef VMS
|
|
83 #include <ttdef.h>
|
|
84 #include <tt2def.h>
|
|
85 #include <iodef.h>
|
|
86 #include <ssdef.h>
|
|
87 #include <descrip.h>
|
|
88 #include <fibdef.h>
|
|
89 #include <atrdef.h>
|
|
90 #undef F_SETFL
|
|
91 #ifndef RAB/*$C_BID -- suppress compiler warnings */
|
|
92 #include <rab.h>
|
|
93 #endif
|
|
94 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
|
|
95 #endif /* VMS */
|
|
96
|
|
97 /* ------------------------------- */
|
|
98 /* TTY definitions */
|
|
99 /* ------------------------------- */
|
|
100
|
|
101 #ifdef USG
|
|
102 #include <sys/utsname.h>
|
|
103 #if defined (TIOCGWINSZ) || defined (ISC4_0)
|
|
104 #ifdef NEED_SIOCTL
|
|
105 #include <sys/sioctl.h>
|
|
106 #endif
|
|
107 #ifdef NEED_PTEM_H
|
|
108 #include <sys/stream.h>
|
|
109 #include <sys/ptem.h>
|
|
110 #endif
|
|
111 #endif /* TIOCGWINSZ or ISC4_0 */
|
|
112 #endif /* USG */
|
|
113
|
|
114 #ifdef HAVE_SYS_STROPTS_H
|
185
|
115 #include <sys/stropts.h>
|
0
|
116 #endif /* HAVE_SYS_STROPTS_H */
|
|
117
|
|
118 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
|
|
119 #ifndef LPASS8
|
|
120 #define LPASS8 0
|
|
121 #endif
|
|
122
|
|
123 #ifndef HAVE_H_ERRNO
|
|
124 int h_errno;
|
|
125 #endif
|
|
126
|
|
127 #ifdef HAVE_TTY
|
|
128
|
|
129 static int baud_convert[] =
|
|
130 #ifdef BAUD_CONVERT
|
|
131 BAUD_CONVERT;
|
|
132 #else
|
|
133 {
|
|
134 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
|
|
135 1800, 2400, 4800, 9600, 19200, 38400
|
|
136 };
|
|
137 #endif
|
|
138
|
|
139 #endif
|
|
140
|
|
141 #ifdef AIXHFT
|
|
142 static void hft_init (struct console *c);
|
|
143 static void hft_reset (struct console *c);
|
|
144 #endif
|
|
145
|
|
146 /* ------------------------------- */
|
|
147 /* miscellaneous */
|
|
148 /* ------------------------------- */
|
|
149
|
|
150 #ifndef HAVE_UTIMES
|
|
151 #ifndef HAVE_STRUCT_UTIMBUF
|
|
152 /* We want to use utime rather than utimes, but we couldn't find the
|
|
153 structure declaration. We'll use the traditional one. */
|
|
154 struct utimbuf
|
|
155 {
|
|
156 long actime;
|
|
157 long modtime;
|
|
158 };
|
|
159 #endif
|
|
160 #endif
|
|
161
|
|
162
|
|
163 /************************************************************************/
|
|
164 /* subprocess control */
|
|
165 /************************************************************************/
|
|
166
|
|
167 #ifdef HAVE_TTY
|
|
168
|
|
169 #ifdef SIGTSTP
|
|
170
|
|
171 /* Arrange for character C to be read as the next input from
|
|
172 the terminal. */
|
|
173 void
|
|
174 stuff_char (struct console *con, int c)
|
|
175 {
|
|
176 int input_fd;
|
|
177
|
|
178 assert (CONSOLE_TTY_P (con));
|
|
179 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
180 /* Should perhaps error if in batch mode */
|
|
181 #ifdef TIOCSTI
|
|
182 ioctl (input_fd, TIOCSTI, &c);
|
|
183 #else /* no TIOCSTI */
|
|
184 error ("Cannot stuff terminal input characters in this version of Unix.");
|
|
185 #endif /* no TIOCSTI */
|
|
186 }
|
|
187
|
|
188 #endif /* SIGTSTP */
|
|
189
|
|
190 #endif /* HAVE_TTY */
|
|
191
|
|
192 void
|
|
193 set_exclusive_use (int fd)
|
|
194 {
|
|
195 #ifdef FIOCLEX
|
|
196 ioctl (fd, FIOCLEX, 0);
|
|
197 #endif
|
|
198 /* Ok to do nothing if this feature does not exist */
|
|
199 }
|
|
200
|
|
201 void
|
|
202 set_descriptor_non_blocking (int fd)
|
|
203 {
|
|
204 /* Stride people say it's a mystery why this is needed
|
|
205 as well as the O_NDELAY, but that it fails without this. */
|
|
206 /* For AIX: Apparently need this for non-blocking reads on sockets.
|
|
207 It seems that O_NONBLOCK applies only to FIFOs? From
|
|
208 lowry@watson.ibm.com (Andy Lowry). */
|
|
209 /* #### Should this be conditionalized on FIONBIO? */
|
|
210 #if defined (STRIDE) || (defined (pfa) && defined (HAVE_PTYS)) || defined (AIX)
|
|
211 {
|
|
212 int one = 1;
|
|
213 ioctl (fd, FIONBIO, &one);
|
|
214 }
|
|
215 #endif
|
|
216
|
|
217 #ifdef O_NONBLOCK /* The POSIX way */
|
|
218 fcntl (fd, F_SETFL, O_NONBLOCK);
|
|
219 #elif defined (O_NDELAY)
|
|
220 fcntl (fd, F_SETFL, O_NDELAY);
|
|
221 #endif /* O_NONBLOCK */
|
|
222 }
|
|
223
|
|
224 #if defined (NO_SUBPROCESSES)
|
|
225
|
|
226 #ifdef BSD
|
|
227 void
|
|
228 wait_without_blocking (void)
|
|
229 {
|
|
230 wait3 (0, WNOHANG | WUNTRACED, 0);
|
|
231 synch_process_alive = 0;
|
|
232 }
|
|
233 #endif /* BSD */
|
|
234
|
|
235 #endif /* NO_SUBPROCESSES */
|
|
236
|
|
237
|
|
238 void
|
|
239 wait_for_termination (int pid)
|
|
240 {
|
|
241 /* #### With the new improved SIGCHLD handling stuff, there is much
|
|
242 less danger of race conditions and some of the comments below
|
|
243 don't apply. This should be updated. */
|
163
|
244
|
|
245 #if defined (NO_SUBPROCESSES)
|
0
|
246 while (1)
|
|
247 {
|
163
|
248 /* No need to be tricky like below; we can just call wait(). */
|
|
249 /* #### should figure out how to write a wait_allowing_quit().
|
|
250 Since hardly any systems don't have subprocess support,
|
|
251 however, there doesn't seem to be much point. */
|
|
252 if (wait (0) == pid)
|
|
253 return;
|
|
254 }
|
|
255 #elif defined (VMS)
|
|
256 int status = SYS$FORCEX (&pid, 0, 0);
|
|
257 return;
|
|
258
|
|
259 #elif defined (HAVE_WAITPID)
|
|
260 /* Note that, whenever any subprocess terminates (asynch. or synch.),
|
|
261 the SIGCHLD handler will be called and it will call wait(). Thus
|
|
262 we cannot just call wait() ourselves, and we can't block SIGCHLD
|
|
263 and then call wait(), because then if an asynch. process dies
|
|
264 while we're waiting for our synch. process, Emacs will never
|
|
265 notice that the asynch. process died.
|
|
266
|
|
267 So, the general approach we take is to repeatedly block until a
|
|
268 signal arrives, and then check if our process died using kill
|
|
269 (pid, 0). (We could also check the value of `synch_process_alive',
|
|
270 since the SIGCHLD handler will reset that and we know that we're
|
|
271 only being called on synchronous processes, but this approach is
|
|
272 safer. I don't trust the proper delivery of SIGCHLD.
|
|
273
|
|
274 Note also that we cannot use any form of waitpid(). A loop with
|
|
275 WNOHANG will chew up CPU time; better to use sleep(). A loop
|
|
276 without WNOWAIT will screw up the SIGCHLD handler (actually this
|
|
277 is not true, if you duplicate the exit-status-reaping code; see
|
|
278 below). A loop with WNOWAIT will result in a race condition if
|
|
279 the process terminates between the process-status check and the
|
|
280 call to waitpid(). */
|
|
281
|
|
282 /* Formerly, immediate_quit was set around this function call, but
|
|
283 that could lead to problems if the QUIT happened when SIGCHLD was
|
|
284 blocked -- it would remain blocked. Yet another reason why
|
|
285 immediate_quit is a bad idea. In any case, there is no reason to
|
|
286 resort to this because either the SIGIO or the SIGALRM will stop
|
|
287 the block in EMACS_WAIT_FOR_SIGNAL(). */
|
|
288
|
|
289 /* Apparently there are bugs on some systems with the second method
|
|
290 used below (the EMACS_BLOCK_SIGNAL method), whereby zombie
|
|
291 processes get left around. It appears in those cases that the
|
|
292 SIGCHLD handler is never getting invoked. It's not clear whether
|
|
293 this is an Emacs bug or a kernel bug or both: on HPUX this
|
|
294 problem is observed only with XEmacs, but under Solaris 2.4 all
|
|
295 sorts of different programs have problems with zombies. The
|
|
296 method we use here does not require a working SIGCHLD (but will
|
|
297 not break if it is working), and should be safe. */
|
|
298 /*
|
|
299 We use waitpid(), contrary to the remarks above. There is no
|
|
300 race condition, because the three situations when sigchld_handler
|
|
301 is invoked should be handled OK:
|
|
302
|
|
303 - handler invoked before waitpid(): In this case, subprocess
|
|
304 status will be set by sigchld_handler. waitpid() here will
|
|
305 return -1 with errno set to ECHILD, which is a valid exit
|
|
306 condition.
|
|
307
|
|
308 - handler invoked during waitpid(): as above, except that errno
|
|
309 here will be set to EINTR. This will cause waitpid() to be
|
|
310 called again, and this time it will exit with ECHILD.
|
|
311
|
|
312 - handler invoked after waitpid(): The following code will reap
|
|
313 the subprocess. In the handler, wait() will return -1 because
|
|
314 there is no child to reap, and the handler will exit without
|
|
315 modifying child subprocess status. */
|
|
316 int ret, status;
|
|
317
|
|
318 /* Because the SIGCHLD handler can potentially reap the synchronous
|
|
319 subprocess, we should take care of that. */
|
|
320
|
|
321 /* Will stay in the do loop as long as:
|
|
322 1. Process is alive
|
|
323 2. Ctrl-G is not pressed */
|
|
324 do
|
|
325 {
|
0
|
326 QUIT;
|
163
|
327 ret = waitpid (pid, &status, 0);
|
|
328 /* waitpid returns 0 if the process is still alive. */
|
|
329 }
|
|
330 while (ret == 0 || (ret == -1 && errno == EINTR));
|
|
331
|
|
332 if (ret == pid) /* Success */
|
|
333 /* Set synch process globals. This is can also happen
|
|
334 in sigchld_handler, and that code is duplicated. */
|
|
335 {
|
|
336 synch_process_alive = 0;
|
|
337 if (WIFEXITED (status))
|
|
338 synch_process_retcode = WEXITSTATUS (status);
|
|
339 else if (WIFSIGNALED (status))
|
|
340 synch_process_death = signal_name (WTERMSIG (status));
|
|
341 }
|
|
342 /* On exiting the loop, ret will be -1, with errno set to ECHILD if
|
|
343 the child has already been reaped, e.g. in the signal handler. */
|
|
344
|
|
345 /* Otherwise, we've had some error condition here.
|
|
346 Per POSIX, the only other possibilities are:
|
|
347 - EFAULT (bus error accessing arg 2) or
|
|
348 - EINVAL (incorrect arguments),
|
|
349 which are both program bugs.
|
|
350
|
|
351 Since implementations may add their own error indicators on top,
|
|
352 we ignore it by default. */
|
|
353 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD)
|
|
354 while (1)
|
|
355 {
|
|
356 static int wait_debugging = 0; /* Set nonzero to make following
|
|
357 function work under dbx (at least for bsd). */
|
|
358 QUIT;
|
|
359 if (wait_debugging)
|
|
360 return;
|
|
361
|
|
362 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
|
363 /* Block SIGCHLD from happening during this check,
|
|
364 to avoid race conditions. */
|
|
365 if (kill (pid, 0) < 0)
|
0
|
366 {
|
163
|
367 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
368 return;
|
0
|
369 }
|
163
|
370 else
|
|
371 /* WARNING: Whatever this macro does *must* not allow SIGCHLD
|
|
372 to happen between the time that it's reenabled and when we
|
|
373 begin to block. Otherwise we may end up blocking for a
|
|
374 signal that has already arrived and isn't coming again.
|
|
375 Can you say "race condition"?
|
|
376
|
|
377 I assume that the system calls sigpause() or sigsuspend()
|
|
378 to provide this atomicness. If you're getting hangs in
|
|
379 sigpause()/sigsuspend(), then your OS doesn't implement
|
|
380 this properly (this applies under hpux9, for example).
|
|
381 Try defining BROKEN_WAIT_FOR_SIGNAL. */
|
|
382 EMACS_WAIT_FOR_SIGNAL (SIGCHLD);
|
|
383 }
|
|
384 #else /* not HAVE_WAITPID and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */
|
|
385 /* This approach is kind of cheesy but is guaranteed(?!) to work
|
|
386 for all systems. */
|
|
387 while (1)
|
|
388 {
|
|
389 QUIT;
|
0
|
390 if (kill (pid, 0) < 0)
|
|
391 return;
|
|
392 emacs_sleep (1);
|
|
393 }
|
163
|
394 #endif /* OS features */
|
0
|
395 }
|
|
396
|
|
397
|
|
398 #if !defined (NO_SUBPROCESSES)
|
|
399
|
|
400 /*
|
|
401 * flush any pending output
|
|
402 * (may flush input as well; it does not matter the way we use it)
|
|
403 */
|
185
|
404
|
0
|
405 void
|
|
406 flush_pending_output (int channel)
|
|
407 {
|
|
408 #ifdef HAVE_TERMIOS
|
|
409 /* If we try this, we get hit with SIGTTIN, because
|
|
410 the child's tty belongs to the child's pgrp. */
|
|
411 #elif defined (TCFLSH)
|
|
412 ioctl (channel, TCFLSH, 1);
|
|
413 #elif defined (TIOCFLUSH)
|
|
414 int zero = 0;
|
|
415 /* 3rd arg should be ignored
|
|
416 but some 4.2 kernels actually want the address of an int
|
|
417 and nonzero means something different. */
|
|
418 ioctl (channel, TIOCFLUSH, &zero);
|
|
419 #endif
|
|
420 }
|
|
421
|
|
422 #ifndef VMS
|
|
423 #ifndef MSDOS
|
100
|
424 #ifndef WINDOWSNT
|
0
|
425 /* Set up the terminal at the other end of a pseudo-terminal that
|
|
426 we will be controlling an inferior through.
|
|
427 It should not echo or do line-editing, since that is done
|
|
428 in Emacs. No padding needed for insertion into an Emacs buffer. */
|
|
429
|
|
430 void
|
|
431 child_setup_tty (int out)
|
|
432 {
|
|
433 struct emacs_tty s;
|
|
434 EMACS_GET_TTY (out, &s);
|
|
435
|
|
436 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
|
|
437 assert (isatty(out));
|
|
438 s.main.c_oflag |= OPOST; /* Enable output postprocessing */
|
|
439 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */
|
|
440 #ifdef NLDLY
|
|
441 s.main.c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
|
|
442 /* No output delays */
|
|
443 #endif
|
|
444 s.main.c_lflag &= ~ECHO; /* Disable echo */
|
|
445 s.main.c_lflag |= ISIG; /* Enable signals */
|
|
446 #ifdef IUCLC
|
|
447 s.main.c_iflag &= ~IUCLC; /* Disable downcasing on input. */
|
|
448 #endif
|
|
449 #ifdef OLCUC
|
|
450 s.main.c_oflag &= ~OLCUC; /* Disable upcasing on output. */
|
|
451 #endif
|
100
|
452 s.main.c_oflag &= ~TAB3; /* Disable tab expansion */
|
0
|
453 #if defined (CSIZE) && defined (CS8)
|
|
454 s.main.c_cflag = (s.main.c_cflag & ~CSIZE) | CS8; /* Don't strip 8th bit */
|
|
455 #endif
|
|
456 #ifdef ISTRIP
|
|
457 s.main.c_iflag &= ~ISTRIP; /* Don't strip 8th bit on input */
|
|
458 #endif
|
|
459 #if 0
|
|
460 /* Unnecessary as long as ICANON is set */
|
|
461 s.main.c_cc[VMIN] = 1; /* minimum number of characters to accept */
|
|
462 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */
|
|
463 #endif /* 0 */
|
|
464
|
|
465 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */
|
175
|
466 s.main.c_cc[VEOF] = 04; /* ensure that EOF is Control-D */
|
0
|
467 s.main.c_cc[VERASE] = CDISABLE; /* disable erase processing */
|
|
468 s.main.c_cc[VKILL] = CDISABLE; /* disable kill processing */
|
|
469
|
|
470 #ifdef HPUX
|
|
471 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
|
|
472 #endif /* HPUX */
|
|
473
|
|
474 #ifdef AIX
|
|
475 #ifndef IBMR2AIX
|
|
476 /* AIX enhanced edit loses NULs, so disable it. */
|
|
477 s.main.c_line = 0;
|
|
478 s.main.c_iflag &= ~ASCEDIT;
|
|
479 #endif /* IBMR2AIX */
|
|
480 /* Also, PTY overloads NUL and BREAK.
|
|
481 don't ignore break, but don't signal either, so it looks like NUL.
|
|
482 This really serves a purpose only if running in an XTERM window
|
|
483 or via TELNET or the like, but does no harm elsewhere. */
|
|
484 s.main.c_iflag &= ~IGNBRK;
|
|
485 s.main.c_iflag &= ~BRKINT;
|
|
486 #endif /* AIX */
|
|
487 #ifdef SIGNALS_VIA_CHARACTERS
|
|
488 /* the QUIT and INTR character are used in process_send_signal
|
|
489 so set them here to something useful. */
|
|
490 s.main.c_cc[VQUIT] = '\\'&037; /* Control-\ */
|
|
491 s.main.c_cc[VINTR] = 'C' &037; /* Control-C */
|
|
492 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
|
|
493 /* QUIT and INTR work better as signals, so disable character forms */
|
|
494 s.main.c_cc[VQUIT] = CDISABLE;
|
|
495 s.main.c_cc[VINTR] = CDISABLE;
|
|
496 s.main.c_lflag &= ~ISIG;
|
|
497 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
|
|
498 s.main.c_cc[VEOL] = CDISABLE;
|
|
499 #if defined (CBAUD)
|
|
500 /* <mdiers> ### This is not portable. ###
|
|
501 POSIX does not specify CBAUD, and 4.4BSD does not have it.
|
|
502 Instead, POSIX suggests to use cfset{i,o}speed().
|
|
503 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal
|
|
504 I/O, O'Reilly 1991] */
|
|
505 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
|
|
506 #else
|
|
507 /* <mdiers> What to do upon failure? Just ignoring rc is probably
|
|
508 not acceptable, is it? */
|
|
509 if (cfsetispeed (&s.main, B9600) == -1) /* ignore */;
|
|
510 if (cfsetospeed (&s.main, B9600) == -1) /* ignore */;
|
|
511 #endif /* defined (CBAUD) */
|
|
512
|
|
513 #else /* not HAVE_TERMIO */
|
|
514
|
|
515 s.main.sg_flags &= ~(ECHO | CRMOD | ANYP | ALLDELAY | RAW | LCASE
|
|
516 | CBREAK | TANDEM);
|
|
517 s.main.sg_flags |= LPASS8;
|
|
518 s.main.sg_erase = 0377;
|
|
519 s.main.sg_kill = 0377;
|
|
520 s.lmode = LLITOUT | s.lmode; /* Don't strip 8th bit */
|
|
521
|
|
522 #endif /* not HAVE_TERMIO */
|
|
523 EMACS_SET_TTY (out, &s, 0);
|
|
524
|
|
525 #ifdef RTU
|
|
526 {
|
|
527 int zero = 0;
|
|
528 ioctl (out, FIOASYNC, &zero);
|
|
529 }
|
|
530 #endif /* RTU */
|
|
531 }
|
100
|
532 #endif /* WINDOWSNT */
|
0
|
533 #endif /* not MSDOS */
|
|
534 #endif /* not VMS */
|
|
535
|
|
536 #endif /* not NO_SUBPROCESSES */
|
|
537
|
|
538
|
|
539 #if !defined (VMS) && !defined (SIGTSTP) && !defined (USG_JOBCTRL)
|
|
540
|
|
541 /* Record a signal code and the handler for it. */
|
|
542 struct save_signal
|
|
543 {
|
|
544 int code;
|
|
545 SIGTYPE (*handler) ();
|
|
546 };
|
|
547
|
|
548 static void
|
|
549 save_signal_handlers (struct save_signal *saved_handlers)
|
|
550 {
|
|
551 while (saved_handlers->code)
|
|
552 {
|
|
553 saved_handlers->handler
|
|
554 = (SIGTYPE (*) ()) signal (saved_handlers->code, SIG_IGN);
|
|
555 saved_handlers++;
|
|
556 }
|
|
557 }
|
|
558
|
|
559 static void
|
|
560 restore_signal_handlers (struct save_signal *saved_handlers)
|
|
561 {
|
|
562 while (saved_handlers->code)
|
|
563 {
|
|
564 signal (saved_handlers->code, saved_handlers->handler);
|
|
565 saved_handlers++;
|
|
566 }
|
|
567 }
|
|
568
|
|
569 /* Fork a subshell. */
|
|
570 static void
|
|
571 sys_subshell (void)
|
|
572 {
|
|
573 #ifdef MSDOS
|
|
574 int st;
|
|
575 char oldwd[MAXPATHLEN+1]; /* Fixed length is safe on MSDOS. */
|
|
576 #endif /* MSDOS */
|
|
577 int pid;
|
|
578 struct save_signal saved_handlers[5];
|
|
579 Lisp_Object dir;
|
|
580 unsigned char *str = 0;
|
|
581 int len;
|
116
|
582 struct gcpro gcpro1;
|
0
|
583
|
|
584 saved_handlers[0].code = SIGINT;
|
|
585 saved_handlers[1].code = SIGQUIT;
|
|
586 saved_handlers[2].code = SIGTERM;
|
|
587 #ifdef SIGIO
|
|
588 saved_handlers[3].code = SIGIO;
|
|
589 saved_handlers[4].code = 0;
|
|
590 #else
|
|
591 saved_handlers[3].code = 0;
|
|
592 #endif
|
|
593
|
|
594 /* Mentioning current_buffer->buffer would mean including buffer.h,
|
|
595 which somehow wedges the hp compiler. So instead... */
|
|
596
|
|
597 if (NILP (Fboundp (Qdefault_directory)))
|
|
598 goto xyzzy;
|
|
599 dir = Fsymbol_value (Qdefault_directory);
|
|
600 if (!STRINGP (dir))
|
|
601 goto xyzzy;
|
116
|
602
|
|
603 GCPRO1 (dir);
|
|
604 dir = Funhandled_file_name_directory (dir);
|
|
605 dir = expand_and_dir_to_file (dir, Qnil);
|
|
606 UNGCPRO;
|
16
|
607 str = (unsigned char *) alloca (XSTRING_LENGTH (dir) + 2);
|
|
608 len = XSTRING_LENGTH (dir);
|
|
609 memcpy (str, XSTRING_DATA (dir), len);
|
0
|
610 /* #### Unix specific */
|
|
611 if (str[len - 1] != '/') str[len++] = '/';
|
|
612 str[len] = 0;
|
|
613 xyzzy:
|
|
614
|
179
|
615 #ifdef WINDOWSNT
|
|
616 pid = -1;
|
|
617 #else /* not WINDOWSNT */
|
|
618
|
0
|
619 pid = vfork ();
|
|
620
|
|
621 if (pid == -1)
|
|
622 error ("Can't spawn subshell");
|
|
623 if (pid == 0)
|
179
|
624
|
|
625 #endif /* not WINDOWSNT */
|
0
|
626 {
|
|
627 char *sh = 0;
|
|
628
|
|
629 #ifdef MSDOS /* MW, Aug 1993 */
|
|
630 getwd (oldwd);
|
|
631 if (sh == 0)
|
|
632 sh = (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
|
|
633 #endif
|
|
634 if (sh == 0)
|
|
635 sh = (char *) egetenv ("SHELL");
|
|
636 if (sh == 0)
|
|
637 sh = "sh";
|
|
638
|
|
639 /* Use our buffer's default directory for the subshell. */
|
|
640 if (str)
|
|
641 sys_chdir (str);
|
|
642
|
|
643 #if !defined (NO_SUBPROCESSES)
|
|
644 close_process_descs (); /* Close Emacs's pipes/ptys */
|
|
645 #endif
|
|
646
|
|
647 #ifdef SET_EMACS_PRIORITY
|
|
648 if (emacs_priority != 0)
|
185
|
649 nice (-emacs_priority); /* Give the new shell the default priority */
|
0
|
650 #endif
|
|
651
|
|
652 #ifdef MSDOS
|
|
653 st = system (sh);
|
|
654 sys_chdir (oldwd);
|
|
655 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
|
|
656 if (st)
|
|
657 report_file_error ("Can't execute subshell",
|
|
658 Fcons (build_string (sh), Qnil));
|
|
659 #endif
|
|
660 #else /* not MSDOS */
|
179
|
661 #ifdef WINDOWSNT
|
|
662 /* Waits for process completion */
|
|
663 pid = _spawnlp (_P_WAIT, sh, sh, NULL);
|
|
664 if (pid == -1)
|
|
665 write (1, "Can't execute subshell", 22);
|
|
666
|
|
667 #if 0
|
|
668 /* This relates to the GNU Emacs console port, not required under X ? */
|
|
669 take_console ();
|
|
670 #endif
|
|
671 #else /* not WINDOWSNT */
|
0
|
672 execlp (sh, sh, 0);
|
|
673 write (1, "Can't execute subshell", 22);
|
|
674 _exit (1);
|
179
|
675 #endif /* not WINDOWSNT */
|
0
|
676 #endif /* not MSDOS */
|
|
677 }
|
|
678
|
|
679 save_signal_handlers (saved_handlers);
|
|
680 synch_process_alive = 1;
|
|
681 #ifndef MSDOS
|
|
682 wait_for_termination (pid);
|
|
683 #endif
|
|
684 restore_signal_handlers (saved_handlers);
|
|
685 }
|
|
686
|
|
687 #endif /* !defined (VMS) && !defined (SIGTSTP) && !defined (USG_JOBCTRL) */
|
|
688
|
|
689
|
|
690
|
|
691 /* Suspend the Emacs process; give terminal to its superior. */
|
|
692 void
|
|
693 sys_suspend (void)
|
|
694 {
|
|
695 #ifdef VMS
|
|
696 /* "Foster" parentage allows emacs to return to a subprocess that attached
|
|
697 to the current emacs as a cheaper than starting a whole new process. This
|
|
698 is set up by KEPTEDITOR.COM. */
|
|
699 unsigned long parent_id, foster_parent_id;
|
|
700 char *fpid_string;
|
|
701
|
|
702 fpid_string = getenv ("EMACS_PARENT_PID");
|
|
703 if (fpid_string != NULL)
|
|
704 {
|
|
705 sscanf (fpid_string, "%x", &foster_parent_id);
|
|
706 if (foster_parent_id != 0)
|
|
707 parent_id = foster_parent_id;
|
|
708 else
|
|
709 parent_id = getppid ();
|
|
710 }
|
|
711 else
|
|
712 parent_id = getppid ();
|
|
713
|
|
714 xfree (fpid_string); /* On VMS, this was malloc'd */
|
|
715
|
|
716 if (parent_id && parent_id != 0xffffffff)
|
|
717 {
|
|
718 SIGTYPE (*oldsig)() = (int) signal (SIGINT, SIG_IGN);
|
|
719 int status = LIB$ATTACH (&parent_id) & 1;
|
|
720 signal (SIGINT, oldsig);
|
|
721 return status;
|
|
722 }
|
|
723 else
|
|
724 {
|
|
725 struct {
|
|
726 int l;
|
|
727 char *a;
|
|
728 } d_prompt;
|
|
729 d_prompt.l = sizeof ("Emacs: "); /* Our special prompt */
|
|
730 d_prompt.a = "Emacs: "; /* Just a reminder */
|
|
731 LIB$SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt, 0);
|
|
732 return 1;
|
|
733 }
|
|
734 return -1;
|
|
735 #elif defined (SIGTSTP) && !defined (MSDOS)
|
|
736 {
|
|
737 int pgrp = EMACS_GET_PROCESS_GROUP ();
|
|
738 EMACS_KILLPG (pgrp, SIGTSTP);
|
|
739 }
|
|
740
|
|
741 #elif defined (USG_JOBCTRL)
|
|
742 /* If you don't know what this is don't mess with it */
|
|
743 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
|
|
744 kill (getpid (), SIGQUIT);
|
|
745
|
|
746 #else /* No SIGTSTP or USG_JOBCTRL */
|
|
747
|
|
748 /* On a system where suspending is not implemented,
|
|
749 instead fork a subshell and let it talk directly to the terminal
|
|
750 while we wait. */
|
|
751 sys_subshell ();
|
|
752
|
|
753 #endif
|
|
754 }
|
|
755
|
108
|
756 /* Suspend a process if possible; give terminal to its superior. */
|
|
757 void
|
185
|
758 sys_suspend_process (int process)
|
108
|
759 {
|
|
760 /* I don't doubt that it is possible to suspend processes on
|
|
761 * VMS machines or thost that use USG_JOBCTRL,
|
|
762 * but I don't know how to do it, so...
|
|
763 */
|
|
764 #if defined (SIGTSTP) && !defined (MSDOS)
|
|
765 kill(process, SIGTSTP);
|
|
766 #endif
|
|
767 }
|
|
768
|
0
|
769 /* Set the logical window size associated with descriptor FD
|
|
770 to HEIGHT and WIDTH. This is used mainly with ptys. */
|
|
771
|
|
772 int
|
|
773 set_window_size (int fd, int height, int width)
|
|
774 {
|
|
775 #ifdef TIOCSWINSZ
|
|
776
|
|
777 /* BSD-style. */
|
|
778 struct winsize size;
|
|
779 size.ws_row = height;
|
|
780 size.ws_col = width;
|
|
781
|
|
782 if (ioctl (fd, TIOCSWINSZ, &size) == -1)
|
|
783 return 0; /* error */
|
|
784 else
|
|
785 return 1;
|
|
786
|
|
787 #elif defined (TIOCSSIZE)
|
|
788
|
|
789 /* SunOS - style. */
|
185
|
790 struct ttysize size;
|
0
|
791 size.ts_lines = height;
|
|
792 size.ts_cols = width;
|
|
793
|
|
794 if (ioctl (fd, TIOCGSIZE, &size) == -1)
|
|
795 return 0;
|
|
796 else
|
|
797 return 1;
|
|
798 #else
|
|
799 return -1;
|
|
800 #endif
|
|
801 }
|
|
802
|
|
803 #ifdef HAVE_PTYS
|
|
804
|
|
805 /* Set up the proper status flags for use of a pty. */
|
|
806
|
|
807 void
|
|
808 setup_pty (int fd)
|
|
809 {
|
|
810 /* I'm told that TOICREMOTE does not mean control chars
|
|
811 "can't be sent" but rather that they don't have
|
|
812 input-editing or signaling effects.
|
|
813 That should be good, because we have other ways
|
|
814 to do those things in Emacs.
|
|
815 However, telnet mode seems not to work on 4.2.
|
|
816 So TIOCREMOTE is turned off now. */
|
|
817
|
|
818 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
|
|
819 will hang. In particular, the "timeout" feature (which
|
|
820 causes a read to return if there is no data available)
|
|
821 does this. Also it is known that telnet mode will hang
|
|
822 in such a way that Emacs must be stopped (perhaps this
|
|
823 is the same problem).
|
185
|
824
|
0
|
825 If TIOCREMOTE is turned off, then there is a bug in
|
|
826 hp-ux which sometimes loses data. Apparently the
|
|
827 code which blocks the master process when the internal
|
|
828 buffer fills up does not work. Other than this,
|
|
829 though, everything else seems to work fine.
|
185
|
830
|
0
|
831 Since the latter lossage is more benign, we may as well
|
|
832 lose that way. -- cph */
|
|
833 #if defined (FIONBIO) && defined (SYSV_PTYS)
|
|
834 {
|
|
835 int on = 1;
|
|
836 ioctl (fd, FIONBIO, &on);
|
|
837 }
|
|
838 #endif
|
|
839 #ifdef IBMRTAIX
|
|
840 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
|
|
841 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
|
|
842 /* cause EMACS not to die when it should, i.e., when its own controlling */
|
|
843 /* tty goes away. I've complained to the AIX developers, and they may */
|
|
844 /* change this behavior, but I'm not going to hold my breath. */
|
|
845 signal (SIGHUP, SIG_IGN);
|
|
846 #endif
|
|
847 #ifdef TIOCPKT
|
|
848 /* In some systems (Linux through 2.0.0, at least), packet mode doesn't
|
|
849 get cleared when a pty is closed, so we need to clear it here.
|
|
850 Linux pre2.0.13 contained an attempted fix for this (from Ted Ts'o,
|
|
851 tytso@mit.edu), but apparently it messed up rlogind and telnetd, so he
|
|
852 removed the fix in pre2.0.14. - dkindred@cs.cmu.edu
|
|
853 */
|
|
854 {
|
|
855 int off = 0;
|
|
856 ioctl (fd, TIOCPKT, (char *)&off);
|
|
857 }
|
|
858 #endif
|
|
859 }
|
|
860 #endif /* HAVE_PTYS */
|
|
861
|
|
862
|
|
863 /************************************************************************/
|
|
864 /* TTY control */
|
|
865 /************************************************************************/
|
|
866
|
|
867 /* ------------------------------------------------------ */
|
|
868 /* get baud rate */
|
|
869 /* ------------------------------------------------------ */
|
|
870
|
|
871 /* It really makes more sense for the baud-rate to be console-specific
|
|
872 and not device-specific, but it's (at least potentially) used for output
|
|
873 decisions. */
|
|
874
|
|
875 void
|
|
876 init_baud_rate (struct device *d)
|
|
877 {
|
|
878 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
879 if (DEVICE_WIN_P (d) || DEVICE_STREAM_P (d))
|
|
880 {
|
|
881 DEVICE_BAUD_RATE (d) = 38400;
|
|
882 return;
|
|
883 }
|
|
884
|
|
885 #ifdef HAVE_TTY
|
|
886 assert (DEVICE_TTY_P (d));
|
|
887 {
|
|
888 int input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
889 #ifdef MSDOS
|
|
890 DEVICE_TTY_DATA (d)->ospeed = 15;
|
|
891 #elif defined (VMS)
|
|
892 struct vms_sensemode sg;
|
185
|
893
|
0
|
894 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0,
|
|
895 &sg.class, 12, 0, 0, 0, 0 );
|
|
896 DEVICE_TTY_DATA (d)->ospeed = sg.xmit_baud;
|
|
897 #elif defined (HAVE_TERMIOS)
|
|
898 struct termios sg;
|
185
|
899
|
0
|
900 sg.c_cflag = B9600;
|
|
901 tcgetattr (input_fd, &sg);
|
|
902 DEVICE_TTY_DATA (d)->ospeed = cfgetospeed (&sg);
|
|
903 # if defined (USE_GETOBAUD) && defined (getobaud)
|
|
904 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
|
|
905 if (DEVICE_TTY_DATA (d)->ospeed == 0)
|
|
906 DEVICE_TTY_DATA (d)->ospeed = getobaud (sg.c_cflag);
|
|
907 # endif
|
|
908 #elif defined (HAVE_TERMIO)
|
|
909 struct termio sg;
|
185
|
910
|
0
|
911 sg.c_cflag = B9600;
|
|
912 # ifdef HAVE_TCATTR
|
|
913 tcgetattr (input_fd, &sg);
|
|
914 # else
|
|
915 ioctl (input_fd, TCGETA, &sg);
|
|
916 # endif
|
|
917 DEVICE_TTY_DATA (d)->ospeed = sg.c_cflag & CBAUD;
|
|
918 #else /* neither VMS nor TERMIOS nor TERMIO */
|
|
919 struct sgttyb sg;
|
185
|
920
|
0
|
921 sg.sg_ospeed = B9600;
|
|
922 if (ioctl (input_fd, TIOCGETP, &sg) < 0)
|
|
923 abort ();
|
|
924 DEVICE_TTY_DATA (d)->ospeed = sg.sg_ospeed;
|
|
925 #endif
|
|
926 }
|
185
|
927
|
0
|
928 DEVICE_BAUD_RATE (d) =
|
|
929 (DEVICE_TTY_DATA (d)->ospeed < sizeof baud_convert / sizeof baud_convert[0]
|
|
930 ? baud_convert[DEVICE_TTY_DATA (d)->ospeed]
|
|
931 : 9600);
|
|
932
|
|
933 if (DEVICE_BAUD_RATE (d) == 0)
|
|
934 DEVICE_BAUD_RATE (d) = 1200;
|
|
935 #endif /* HAVE_TTY */
|
|
936 }
|
|
937
|
|
938
|
|
939 /* ------------------------------------------------------ */
|
|
940 /* SIGIO control */
|
|
941 /* ------------------------------------------------------ */
|
|
942
|
|
943 #ifdef SIGIO
|
|
944
|
|
945 static void
|
|
946 init_sigio_on_device (struct device *d)
|
|
947 {
|
|
948 int filedesc = DEVICE_INFD (d);
|
|
949
|
2
|
950 #if defined (I_SETSIG) && !defined(HPUX10)
|
0
|
951 ioctl (filedesc, I_GETSIG, &DEVICE_OLD_SIGIO_FLAG (d));
|
|
952 DEVICE_OLD_SIGIO_FLAG (d) &= ~S_INPUT;
|
|
953 #elif defined (FASYNC)
|
|
954 DEVICE_OLD_SIGIO_FLAG (d) =
|
|
955 fcntl (filedesc, F_GETFL, 0) & ~FASYNC;
|
|
956 #endif
|
|
957
|
|
958 #if defined (FIOSSAIOOWN)
|
|
959 { /* HPUX stuff */
|
|
960 int owner = getpid ();
|
|
961 int ioctl_status;
|
|
962 if (DEVICE_TTY_P (d))
|
|
963 {
|
|
964 ioctl_status = ioctl (filedesc, FIOGSAIOOWN,
|
|
965 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
966 ioctl_status = ioctl (filedesc, FIOSSAIOOWN, &owner);
|
|
967 }
|
|
968 #ifdef HAVE_WINDOW_SYSTEM
|
|
969 else if (!DEVICE_STREAM_P (d))
|
|
970 {
|
|
971 ioctl_status = ioctl (filedesc, SIOCGPGRP,
|
|
972 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
973 ioctl_status = ioctl (filedesc, SIOCSPGRP, &owner);
|
|
974 }
|
|
975 #endif
|
|
976 }
|
|
977 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
|
|
978 DEVICE_OLD_FCNTL_OWNER (d) = fcntl (filedesc, F_GETOWN, 0);
|
|
979 # ifdef F_SETOWN_SOCK_NEG
|
|
980 /* stdin is a socket here */
|
|
981 fcntl (filedesc, F_SETOWN, -getpid ());
|
|
982 # else
|
|
983 fcntl (filedesc, F_SETOWN, getpid ());
|
|
984 # endif
|
|
985 #endif
|
|
986 }
|
|
987
|
|
988 static void
|
|
989 reset_sigio_on_device (struct device *d)
|
|
990 {
|
|
991 int filedesc = DEVICE_INFD (d);
|
|
992
|
|
993 #if defined (FIOSSAIOOWN)
|
|
994 { /* HPUX stuff */
|
|
995 int owner = getpid ();
|
|
996 int ioctl_status;
|
|
997 if (DEVICE_TTY_P (d))
|
|
998 {
|
|
999 ioctl_status = ioctl (filedesc, FIOSSAIOOWN,
|
|
1000 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
1001 }
|
|
1002 #ifdef HAVE_WINDOW_SYSTEM
|
|
1003 else if (!DEVICE_STREAM_P (d))
|
|
1004 {
|
|
1005 ioctl_status = ioctl (filedesc, SIOCSPGRP,
|
|
1006 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
1007 }
|
|
1008 #endif
|
|
1009 }
|
|
1010 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
|
|
1011 fcntl (filedesc, F_SETOWN, DEVICE_OLD_FCNTL_OWNER (d));
|
|
1012 #endif
|
|
1013 }
|
|
1014
|
|
1015 static void
|
|
1016 request_sigio_on_device (struct device *d)
|
|
1017 {
|
|
1018 int filedesc = DEVICE_INFD (d);
|
|
1019
|
|
1020 /* prevent redundant ioctl()s, which may cause syslog messages
|
|
1021 (e.g. on Solaris) */
|
|
1022 if (d->sigio_enabled)
|
|
1023 return;
|
|
1024
|
2
|
1025 #if defined (I_SETSIG) && !defined(HPUX10)
|
0
|
1026 ioctl (filedesc, I_SETSIG, DEVICE_OLD_SIGIO_FLAG (d) | S_INPUT);
|
|
1027 #elif defined (FASYNC)
|
|
1028 fcntl (filedesc, F_SETFL, DEVICE_OLD_SIGIO_FLAG (d) | FASYNC);
|
|
1029 #elif defined (FIOSSAIOSTAT)
|
|
1030 {
|
|
1031 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
|
|
1032 sockets and other devices for some bizarre reason. We guess
|
|
1033 that an X device is a socket, and tty devices aren't. We then
|
|
1034 use the following crud to do the appropriate thing. */
|
|
1035 int on = 1;
|
|
1036 int ioctl_status; /* ####DG: check if IOCTL succeeds here. */
|
|
1037
|
|
1038 if (DEVICE_TTY_P (d))
|
|
1039 {
|
|
1040 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &on);
|
|
1041 }
|
|
1042 #ifdef HAVE_WINDOW_SYSTEM
|
|
1043 else if (!DEVICE_STREAM_P (d))
|
|
1044 {
|
|
1045 ioctl_status = ioctl (filedesc, FIOASYNC, &on);
|
|
1046 }
|
|
1047 #endif
|
|
1048 }
|
|
1049 #elif defined (FIOASYNC)
|
|
1050 {
|
|
1051 int on = 1;
|
|
1052 ioctl (filedesc, FIOASYNC, &on);
|
|
1053 }
|
|
1054 #endif
|
|
1055
|
|
1056 #if defined (_CX_UX) /* #### Is this crap necessary? */
|
|
1057 EMACS_UNBLOCK_SIGNAL (SIGIO);
|
|
1058 #endif
|
|
1059
|
|
1060 d->sigio_enabled = 1;
|
|
1061 }
|
|
1062
|
|
1063 static void
|
|
1064 unrequest_sigio_on_device (struct device *d)
|
|
1065 {
|
|
1066 int filedesc = DEVICE_INFD (d);
|
|
1067
|
|
1068 /* prevent redundant ioctl()s, which may cause syslog messages
|
|
1069 (e.g. on Solaris) */
|
|
1070 if (!d->sigio_enabled)
|
|
1071 return;
|
|
1072
|
2
|
1073 #if defined (I_SETSIG) && !defined(HPUX10)
|
0
|
1074 ioctl (filedesc, I_SETSIG, DEVICE_OLD_SIGIO_FLAG (d));
|
|
1075 #elif defined (FASYNC)
|
|
1076 fcntl (filedesc, F_SETFL, DEVICE_OLD_SIGIO_FLAG (d));
|
|
1077 #elif defined (FIOSSAIOSTAT)
|
|
1078 {
|
|
1079 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
|
|
1080 sockets and other devices for some bizarre reason. We guess
|
|
1081 that an X device is a socket, and tty devices aren't. We then
|
|
1082 use the following crud to do the appropriate thing. */
|
|
1083
|
|
1084 int off = 0;
|
|
1085 int ioctl_status;
|
|
1086
|
|
1087 /* See comment for request_sigio_on_device */
|
|
1088
|
|
1089 if (DEVICE_TTY_P (d))
|
|
1090 {
|
|
1091 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &off);
|
|
1092 }
|
185
|
1093 else
|
0
|
1094 {
|
|
1095 ioctl_status = ioctl (filedesc, FIOASYNC, &off);
|
|
1096 }
|
|
1097 }
|
|
1098 #elif defined (FIOASYNC)
|
|
1099 {
|
|
1100 int off = 0;
|
|
1101 ioctl (filedesc, FIOASYNC, &off);
|
|
1102 }
|
|
1103 #endif
|
|
1104
|
|
1105 d->sigio_enabled = 0;
|
|
1106 }
|
|
1107
|
|
1108 void
|
|
1109 request_sigio (void)
|
|
1110 {
|
|
1111 Lisp_Object devcons, concons;
|
|
1112
|
|
1113 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1114 {
|
|
1115 struct device *d;
|
|
1116
|
|
1117 d = XDEVICE (XCAR (devcons));
|
|
1118
|
|
1119 if (!DEVICE_STREAM_P (d))
|
|
1120 request_sigio_on_device (d);
|
|
1121 }
|
|
1122 }
|
|
1123
|
|
1124 void
|
|
1125 unrequest_sigio (void)
|
|
1126 {
|
|
1127 Lisp_Object devcons, concons;
|
|
1128
|
|
1129 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1130 {
|
|
1131 struct device *d;
|
|
1132
|
|
1133 d = XDEVICE (XCAR (devcons));
|
|
1134
|
|
1135 if (!DEVICE_STREAM_P (d))
|
|
1136 unrequest_sigio_on_device (d);
|
|
1137 }
|
|
1138 }
|
|
1139
|
|
1140 #endif /* SIGIO */
|
|
1141
|
|
1142 /* ------------------------------------------------------ */
|
|
1143 /* Changing Emacs's process group */
|
|
1144 /* ------------------------------------------------------ */
|
|
1145
|
|
1146 /* Saving and restoring the process group of Emacs's terminal. */
|
|
1147
|
|
1148 /* On some systems, apparently (?!) Emacs must be in its own process
|
|
1149 group in order to receive SIGIO correctly. On other systems
|
|
1150 (e.g. Solaris), it's not required and doing it makes things
|
|
1151 get fucked up. So, we only do it when
|
|
1152 SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP is defined. Basically,
|
|
1153 this is only required for BSD 4.2 systems. (Actually, I bet
|
|
1154 we don't have to do this at all -- those systems also
|
|
1155 required interrupt input, which we don't support.)
|
|
1156
|
|
1157 If Emacs was in its own process group (i.e. inherited_pgroup ==
|
|
1158 getpid ()), then we know we're running under a shell with job
|
|
1159 control (Emacs would never be run as part of a pipeline).
|
|
1160 Everything is fine.
|
|
1161
|
|
1162 If Emacs was not in its own process group, then we know we're
|
|
1163 running under a shell (or a caller) that doesn't know how to
|
|
1164 separate itself from Emacs (like sh). Emacs must be in its own
|
|
1165 process group in order to receive SIGIO correctly. In this
|
|
1166 situation, we put ourselves in our own pgroup, forcibly set the
|
|
1167 tty's pgroup to our pgroup, and make sure to restore and reinstate
|
|
1168 the tty's pgroup just like any other terminal setting. If
|
|
1169 inherited_group was not the tty's pgroup, then we'll get a
|
|
1170 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
|
|
1171 it goes foreground in the future, which is what should happen. */
|
|
1172
|
|
1173 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1174
|
|
1175 static int inherited_pgroup;
|
|
1176 static int inherited_tty_pgroup;
|
|
1177
|
|
1178 #endif
|
|
1179
|
|
1180 void
|
|
1181 munge_tty_process_group (void)
|
|
1182 {
|
|
1183 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1184 if (noninteractive)
|
|
1185 return;
|
|
1186
|
|
1187 /* Only do this munging if we have a device on the controlling
|
|
1188 terminal. See the large comment below. */
|
|
1189
|
|
1190 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
1191 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
1192 {
|
|
1193 int fd = open ("/dev/tty", O_RDWR, 0);
|
|
1194 int me = getpid ();
|
|
1195 EMACS_BLOCK_SIGNAL (SIGTTOU);
|
|
1196 EMACS_SET_TTY_PROCESS_GROUP (fd, &me);
|
|
1197 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
|
|
1198 close (fd);
|
|
1199 }
|
|
1200 #endif
|
|
1201 }
|
|
1202
|
|
1203 /* Split off the foreground process group to Emacs alone.
|
|
1204 When we are in the foreground, but not started in our own process
|
|
1205 group, redirect the TTY to point to our own process group. We need
|
|
1206 to be in our own process group to receive SIGIO properly. */
|
|
1207 static void
|
|
1208 munge_process_groups (void)
|
|
1209 {
|
|
1210 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1211 if (noninteractive)
|
|
1212 return;
|
|
1213
|
|
1214 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
1215
|
|
1216 munge_tty_process_group ();
|
|
1217 #endif
|
|
1218 }
|
|
1219
|
|
1220 void
|
|
1221 unmunge_tty_process_group (void)
|
|
1222 {
|
|
1223 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1224 {
|
|
1225 int fd = open ("/dev/tty", O_RDWR, 0);
|
|
1226 EMACS_BLOCK_SIGNAL (SIGTTOU);
|
|
1227 EMACS_SET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
|
|
1228 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
|
|
1229 close (fd);
|
|
1230 }
|
|
1231 #endif
|
|
1232 }
|
|
1233
|
|
1234 /* Set the tty to our original foreground group.
|
|
1235 Also restore the original process group (put us back into sh's
|
|
1236 process group), so that ^Z will suspend both us and sh. */
|
|
1237 static void
|
|
1238 unmunge_process_groups (void)
|
|
1239 {
|
|
1240 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1241 if (noninteractive)
|
|
1242 return;
|
|
1243
|
|
1244 unmunge_tty_process_group ();
|
|
1245
|
|
1246 EMACS_SET_PROCESS_GROUP (inherited_pgroup);
|
|
1247 #endif
|
|
1248 }
|
|
1249
|
|
1250 /* According to some old wisdom, we need to be in a separate process
|
|
1251 group for SIGIO to work correctly (at least on some systems ...).
|
|
1252 So go ahead and put ourselves into our own process group. This
|
|
1253 will fail if we're already in our own process group, but who cares.
|
|
1254 Also record whether we were in our own process group. (In general,
|
|
1255 we will already be in our own process group if we were started from
|
|
1256 a job-control shell like csh, but not if we were started from sh).
|
185
|
1257
|
0
|
1258 If we succeeded in changing our process group, then we will no
|
|
1259 longer be in the foreground process group of our controlling
|
|
1260 terminal. Therefore, if we have a console open onto this terminal,
|
|
1261 we have to change the controlling terminal's foreground process
|
|
1262 group (otherwise we will get stopped with a SIGTTIN signal when
|
|
1263 attempting to read from the terminal). It's important,
|
|
1264 however, that we do this *only* when we have a console open onto
|
|
1265 the terminal. It's a decidedly bad idea to do so otherwise,
|
|
1266 especially if XEmacs was started from the background. */
|
|
1267
|
|
1268 void
|
|
1269 init_process_group (void)
|
|
1270 {
|
|
1271 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1272 if (! noninteractive)
|
|
1273 {
|
|
1274 int fd = open ("/dev/tty", O_RDWR, 0);
|
|
1275 inherited_pgroup = EMACS_GET_PROCESS_GROUP ();
|
|
1276 EMACS_GET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
|
|
1277 close (fd);
|
|
1278 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
1279 }
|
|
1280 #endif
|
|
1281 }
|
|
1282
|
|
1283 void
|
|
1284 disconnect_controlling_terminal (void)
|
|
1285 {
|
|
1286 # ifdef HAVE_SETSID
|
|
1287 /* Controlling terminals are attached to a session.
|
|
1288 Create a new session for us; it will have no controlling
|
|
1289 terminal. This also, of course, puts us in our own
|
|
1290 process group. */
|
|
1291 setsid ();
|
|
1292 # else
|
|
1293 /* Put us in our own process group. */
|
|
1294 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
1295 # if defined (TIOCNOTTY)
|
|
1296 /* This is the older way of disconnecting the controlling
|
|
1297 terminal, on 4.3 BSD. We must open /dev/tty; using
|
|
1298 filedesc 0 is not sufficient because it could be
|
|
1299 something else (e.g. our stdin was redirected to
|
|
1300 another terminal).
|
|
1301 */
|
|
1302 {
|
|
1303 int j = open ("/dev/tty", O_RDWR, 0);
|
|
1304 ioctl (j, TIOCNOTTY, 0);
|
|
1305 close (j);
|
|
1306 }
|
|
1307 # endif /* TIOCNOTTY */
|
|
1308 /*
|
|
1309 On systems without TIOCNOTTY and without
|
|
1310 setsid(), we don't need to do anything more to
|
|
1311 disconnect our controlling terminal. Here is
|
|
1312 what the man page for termio(7) from a SYSV 3.2
|
|
1313 system says:
|
185
|
1314
|
0
|
1315 "The first terminal file opened by the process group leader
|
|
1316 of a terminal file not already associated with a process
|
|
1317 group becomes the control terminal for that process group.
|
|
1318 The control terminal plays a special role in handling quit
|
|
1319 and interrupt signals, as discussed below. The control
|
|
1320 terminal is inherited by a child process during a fork(2).
|
|
1321 A process can break this association by changing its process
|
|
1322 group using setpgrp(2)."
|
185
|
1323
|
0
|
1324 */
|
|
1325 # endif /* not HAVE_SETSID */
|
|
1326 }
|
|
1327
|
|
1328
|
|
1329 /* ------------------------------------------------------ */
|
|
1330 /* Getting and setting emacs_tty structures */
|
|
1331 /* ------------------------------------------------------ */
|
|
1332
|
153
|
1333 /* It's wrong to encase these into #ifdef HAVE_TTY because we need
|
|
1334 them for child TTY processes. */
|
157
|
1335 /* However, this does break NT support while we don't do child TTY processes */
|
|
1336 #ifndef WINDOWSNT
|
100
|
1337
|
0
|
1338 /* Set *TC to the parameters associated with the terminal FD.
|
|
1339 Return zero if all's well, or -1 if we ran into an error we
|
|
1340 couldn't deal with. */
|
|
1341 int
|
|
1342 emacs_get_tty (int fd, struct emacs_tty *settings)
|
|
1343 {
|
|
1344 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
|
|
1345 #ifdef HAVE_TCATTR
|
|
1346 /* We have those nifty POSIX tcmumbleattr functions. */
|
|
1347 if (tcgetattr (fd, &settings->main) < 0)
|
|
1348 return -1;
|
|
1349
|
|
1350 #else
|
|
1351 #ifdef HAVE_TERMIO
|
|
1352 /* The SYSV-style interface? */
|
|
1353 if (ioctl (fd, TCGETA, &settings->main) < 0)
|
|
1354 return -1;
|
|
1355
|
|
1356 #else
|
|
1357 #ifdef VMS
|
|
1358 /* Vehemently Monstrous System? :-) */
|
|
1359 if (! (SYS$QIOW (0, fd, IO$_SENSEMODE, settings, 0, 0,
|
|
1360 &settings->main.class, 12, 0, 0, 0, 0)
|
|
1361 & 1))
|
|
1362 return -1;
|
|
1363
|
|
1364 #else
|
|
1365 #ifndef MSDOS
|
|
1366 /* I give up - I hope you have the BSD ioctls. */
|
|
1367 if (ioctl (fd, TIOCGETP, &settings->main) < 0)
|
|
1368 return -1;
|
|
1369 #endif /* not MSDOS */
|
|
1370 #endif /* not VMS */
|
|
1371 #endif /* HAVE_TERMIO */
|
|
1372 #endif /* HAVE_TCATTR */
|
|
1373
|
|
1374 /* Suivant - Do we have to get struct ltchars data? */
|
|
1375 #ifdef HAVE_LTCHARS
|
|
1376 if (ioctl (fd, TIOCGLTC, &settings->ltchars) < 0)
|
|
1377 return -1;
|
|
1378 #endif
|
|
1379
|
|
1380 /* How about a struct tchars and a wordful of lmode bits? */
|
|
1381 #ifdef HAVE_TCHARS
|
|
1382 if (ioctl (fd, TIOCGETC, &settings->tchars) < 0
|
|
1383 || ioctl (fd, TIOCLGET, &settings->lmode) < 0)
|
|
1384 return -1;
|
|
1385 #endif
|
|
1386
|
|
1387 /* We have survived the tempest. */
|
|
1388 return 0;
|
|
1389 }
|
|
1390
|
|
1391 /* Set the parameters of the tty on FD according to the contents of
|
|
1392 *SETTINGS. If FLUSHP is non-zero, we discard input.
|
|
1393 Return 0 if all went well, and -1 if anything failed. */
|
|
1394
|
|
1395 int
|
|
1396 emacs_set_tty (int fd, struct emacs_tty *settings, int flushp)
|
|
1397 {
|
|
1398 /* Set the primary parameters - baud rate, character size, etcetera. */
|
|
1399 #ifdef HAVE_TCATTR
|
|
1400 int i;
|
|
1401 /* We have those nifty POSIX tcmumbleattr functions.
|
|
1402 William J. Smith <wjs@wiis.wang.com> writes:
|
|
1403 "POSIX 1003.1 defines tcsetattr() to return success if it was
|
|
1404 able to perform any of the requested actions, even if some
|
|
1405 of the requested actions could not be performed.
|
|
1406 We must read settings back to ensure tty setup properly.
|
|
1407 AIX requires this to keep tty from hanging occasionally." */
|
|
1408 /* This makes sure that we don't loop indefinitely in here. */
|
|
1409 for (i = 0 ; i < 10 ; i++)
|
|
1410 if (tcsetattr (fd, flushp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0)
|
|
1411 {
|
|
1412 if (errno == EINTR)
|
|
1413 continue;
|
|
1414 else
|
|
1415 return -1;
|
|
1416 }
|
|
1417 else
|
|
1418 {
|
|
1419 struct termios new;
|
|
1420
|
|
1421 /* Get the current settings, and see if they're what we asked for. */
|
|
1422 tcgetattr (fd, &new);
|
|
1423 /* We cannot use memcmp on the whole structure here because under
|
|
1424 * aix386 the termios structure has some reserved field that may
|
|
1425 * not be filled in.
|
|
1426 */
|
|
1427 if ( new.c_iflag == settings->main.c_iflag
|
|
1428 && new.c_oflag == settings->main.c_oflag
|
|
1429 && new.c_cflag == settings->main.c_cflag
|
|
1430 && new.c_lflag == settings->main.c_lflag
|
|
1431 && memcmp(new.c_cc, settings->main.c_cc, NCCS) == 0)
|
|
1432 break;
|
|
1433 else
|
|
1434 continue;
|
|
1435 }
|
|
1436 #else
|
|
1437 #ifdef HAVE_TERMIO
|
|
1438 /* The SYSV-style interface? */
|
|
1439 if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0)
|
|
1440 return -1;
|
|
1441
|
|
1442 #else
|
|
1443 #ifdef VMS
|
|
1444 /* Vehemently Monstrous System? :-) */
|
|
1445 if (! (SYS$QIOW (0, fd, IO$_SETMODE, &input_iosb, 0, 0,
|
|
1446 &settings->main.class, 12, 0, 0, 0, 0)
|
|
1447 & 1))
|
|
1448 return -1;
|
|
1449
|
|
1450 #else
|
|
1451 #ifndef MSDOS
|
|
1452 /* I give up - I hope you have the BSD ioctls. */
|
|
1453 if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
|
|
1454 return -1;
|
|
1455 #endif /* not MSDOS */
|
|
1456 #endif /* VMS */
|
|
1457 #endif /* HAVE_TERMIO */
|
|
1458 #endif /* HAVE_TCATTR */
|
|
1459
|
|
1460 /* Suivant - Do we have to get struct ltchars data? */
|
|
1461 #ifdef HAVE_LTCHARS
|
|
1462 if (ioctl (fd, TIOCSLTC, &settings->ltchars) < 0)
|
|
1463 return -1;
|
|
1464 #endif
|
|
1465
|
|
1466 /* How about a struct tchars and a wordful of lmode bits? */
|
|
1467 #ifdef HAVE_TCHARS
|
|
1468 if (ioctl (fd, TIOCSETC, &settings->tchars) < 0
|
|
1469 || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
|
|
1470 return -1;
|
|
1471 #endif
|
185
|
1472
|
0
|
1473 /* We have survived the tempest. */
|
|
1474 return 0;
|
|
1475 }
|
|
1476
|
157
|
1477 #endif /* WINDOWSNT */
|
0
|
1478
|
|
1479 /* ------------------------------------------------------ */
|
|
1480 /* Initializing a device */
|
|
1481 /* ------------------------------------------------------ */
|
|
1482
|
|
1483 #ifdef HAVE_TTY
|
|
1484
|
|
1485 /* This may also be defined in stdio,
|
|
1486 but if so, this does no harm,
|
|
1487 and using the same name avoids wasting the other one's space. */
|
|
1488
|
|
1489 #if ((defined(USG) || defined(DGUX)) && !defined(__STDC__))
|
|
1490 char _sobuf[BUFSIZ+8];
|
|
1491 #elif (defined(USG) && !defined(LINUX) && !defined(_SCO_DS)) || defined(IRIX5)
|
|
1492 extern unsigned char _sobuf[BUFSIZ+8];
|
|
1493 #else
|
|
1494 char _sobuf[BUFSIZ];
|
|
1495 #endif
|
185
|
1496
|
0
|
1497 #if defined (TIOCGLTC) && defined (HAVE_LTCHARS) /* HAVE_LTCHARS */
|
|
1498 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
|
|
1499 #endif
|
|
1500 #ifdef TIOCGETC /* HAVE_TCHARS */
|
|
1501 #ifdef HAVE_TCHARS
|
|
1502 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
|
|
1503 #endif
|
185
|
1504 #endif
|
0
|
1505
|
|
1506 static void
|
|
1507 tty_init_sys_modes_on_device (struct device *d)
|
|
1508 {
|
|
1509 struct emacs_tty tty;
|
|
1510 int input_fd, output_fd;
|
|
1511 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1512
|
|
1513 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
1514 output_fd = CONSOLE_TTY_DATA (con)->outfd;
|
|
1515
|
|
1516 EMACS_GET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty);
|
|
1517 tty = CONSOLE_TTY_DATA (con)->old_tty;
|
|
1518
|
155
|
1519 con->tty_erase_char = Qnil;
|
|
1520
|
0
|
1521 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
|
155
|
1522 /* after all those years... */
|
|
1523 con->tty_erase_char = make_char (tty.main.c_cc[VERASE]);
|
0
|
1524 #ifdef DGUX
|
|
1525 /* This allows meta to be sent on 8th bit. */
|
|
1526 tty.main.c_iflag &= ~INPCK; /* don't check input for parity */
|
|
1527 #endif
|
|
1528 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */
|
|
1529 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */
|
|
1530 #ifdef ISTRIP
|
|
1531 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */
|
|
1532 #endif
|
|
1533 tty.main.c_lflag &= ~ECHO; /* Disable echo */
|
|
1534 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */
|
|
1535 #ifdef IEXTEN
|
|
1536 tty.main.c_lflag &= ~IEXTEN; /* Disable other editing characters. */
|
|
1537 #endif
|
|
1538 tty.main.c_lflag |= ISIG; /* Enable signals */
|
|
1539 if (TTY_FLAGS (con).flow_control)
|
|
1540 {
|
|
1541 tty.main.c_iflag |= IXON; /* Enable start/stop output control */
|
|
1542 #ifdef IXANY
|
|
1543 tty.main.c_iflag &= ~IXANY;
|
|
1544 #endif /* IXANY */
|
|
1545 }
|
|
1546 else
|
|
1547 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */
|
185
|
1548 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL
|
0
|
1549 on output */
|
|
1550 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */
|
|
1551 #ifdef CS8
|
|
1552 if (TTY_FLAGS (con).meta_key)
|
|
1553 {
|
|
1554 tty.main.c_cflag |= CS8; /* allow 8th bit on input */
|
|
1555 tty.main.c_cflag &= ~PARENB;/* Don't check parity */
|
|
1556 }
|
|
1557 #endif
|
|
1558 if (CONSOLE_TTY_DATA (con)->controlling_terminal)
|
|
1559 {
|
|
1560 tty.main.c_cc[VINTR] =
|
|
1561 CONSOLE_QUIT_CHAR (con); /* C-g (usually) gives SIGINT */
|
|
1562 /* Set up C-g for both SIGQUIT and SIGINT.
|
|
1563 We don't know which we will get, but we handle both alike
|
|
1564 so which one it really gives us does not matter. */
|
|
1565 tty.main.c_cc[VQUIT] = CONSOLE_QUIT_CHAR (con);
|
|
1566 }
|
|
1567 else
|
|
1568 {
|
|
1569 tty.main.c_cc[VINTR] = CDISABLE;
|
|
1570 tty.main.c_cc[VQUIT] = CDISABLE;
|
|
1571 }
|
|
1572 tty.main.c_cc[VMIN] = 1; /* Input should wait for at
|
|
1573 least 1 char */
|
|
1574 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */
|
|
1575 #ifdef VSWTCH
|
|
1576 tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use
|
|
1577 of C-z */
|
|
1578 #endif /* VSWTCH */
|
|
1579 /* There was some conditionalizing here on (mips or TCATTR), but
|
|
1580 I think that's wrong. There was one report of C-y (DSUSP) not being
|
|
1581 disabled on HP9000s700 systems, and this might fix it. */
|
|
1582 #ifdef VSUSP
|
|
1583 tty.main.c_cc[VSUSP] = CDISABLE;/* Turn off mips handling of C-z. */
|
|
1584 #endif /* VSUSP */
|
|
1585 #ifdef V_DSUSP
|
|
1586 tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */
|
|
1587 #endif /* V_DSUSP */
|
|
1588 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
|
|
1589 tty.main.c_cc[VDSUSP] = CDISABLE;
|
|
1590 #endif /* VDSUSP */
|
|
1591 #ifdef VLNEXT
|
|
1592 tty.main.c_cc[VLNEXT] = CDISABLE;
|
|
1593 #endif /* VLNEXT */
|
|
1594 #ifdef VREPRINT
|
|
1595 tty.main.c_cc[VREPRINT] = CDISABLE;
|
|
1596 #endif /* VREPRINT */
|
|
1597 #ifdef VWERASE
|
|
1598 tty.main.c_cc[VWERASE] = CDISABLE;
|
|
1599 #endif /* VWERASE */
|
|
1600 #ifdef VDISCARD
|
|
1601 tty.main.c_cc[VDISCARD] = CDISABLE;
|
|
1602 #endif /* VDISCARD */
|
|
1603 #ifdef VSTART
|
|
1604 tty.main.c_cc[VSTART] = CDISABLE;
|
|
1605 #endif /* VSTART */
|
|
1606 #ifdef VSTRT
|
|
1607 tty.main.c_cc[VSTRT] = CDISABLE; /* called VSTRT on some systems */
|
|
1608 #endif /* VSTART */
|
|
1609 #ifdef VSTOP
|
|
1610 tty.main.c_cc[VSTOP] = CDISABLE;
|
|
1611 #endif /* VSTOP */
|
|
1612 #ifdef SET_LINE_DISCIPLINE
|
|
1613 /* Need to explicitely request TERMIODISC line discipline or
|
|
1614 Ultrix's termios does not work correctly. */
|
|
1615 tty.main.c_line = SET_LINE_DISCIPLINE;
|
|
1616 #endif
|
185
|
1617
|
0
|
1618 #ifdef AIX
|
|
1619 #ifndef IBMR2AIX
|
|
1620 /* AIX enhanced edit loses NULs, so disable it. */
|
|
1621 tty.main.c_line = 0;
|
|
1622 tty.main.c_iflag &= ~ASCEDIT;
|
|
1623 #else
|
|
1624 tty.main.c_cc[VSTRT] = 255;
|
|
1625 tty.main.c_cc[VSTOP] = 255;
|
|
1626 tty.main.c_cc[VSUSP] = 255;
|
|
1627 tty.main.c_cc[VDSUSP] = 255;
|
|
1628 #endif /* IBMR2AIX */
|
|
1629 /* Also, PTY overloads NUL and BREAK.
|
|
1630 don't ignore break, but don't signal either, so it looks like NUL.
|
|
1631 This really serves a purpose only if running in an XTERM window
|
|
1632 or via TELNET or the like, but does no harm elsewhere. */
|
|
1633 tty.main.c_iflag &= ~IGNBRK;
|
|
1634 tty.main.c_iflag &= ~BRKINT;
|
|
1635 #endif /* AIX */
|
|
1636 #else /* if not HAVE_TERMIO */
|
|
1637 #ifndef MSDOS
|
155
|
1638 con->tty_erase_char = make_char (tty.main.sg_erase);
|
0
|
1639 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
|
|
1640 if (TTY_FLAGS (con).meta_key)
|
|
1641 tty.main.sg_flags |= ANYP;
|
|
1642 /* #### should we be using RAW mode here? */
|
|
1643 tty.main.sg_flags |= /* interrupt_input ? RAW : */ CBREAK;
|
|
1644 #endif /* not MSDOS */
|
|
1645 #endif /* not HAVE_TERMIO */
|
185
|
1646
|
0
|
1647 /* If going to use CBREAK mode, we must request C-g to interrupt
|
|
1648 and turn off start and stop chars, etc. If not going to use
|
|
1649 CBREAK mode, do this anyway so as to turn off local flow
|
|
1650 control for user coming over network on 4.2; in this case,
|
|
1651 only t_stopc and t_startc really matter. */
|
|
1652 #ifndef HAVE_TERMIO
|
|
1653 #ifdef HAVE_TCHARS
|
|
1654 /* Note: if not using CBREAK mode, it makes no difference how we
|
|
1655 set this */
|
|
1656 tty.tchars = new_tchars;
|
|
1657 tty.tchars.t_intrc = CONSOLE_QUIT_CHAR (con);
|
|
1658 if (TTY_FLAGS (con).flow_control)
|
|
1659 {
|
|
1660 tty.tchars.t_startc = '\021';
|
|
1661 tty.tchars.t_stopc = '\023';
|
|
1662 }
|
185
|
1663
|
0
|
1664 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH |
|
|
1665 CONSOLE_TTY_DATA (con)->old_tty.lmode;
|
185
|
1666
|
0
|
1667 #if defined (ultrix) || defined (__bsdi__)
|
|
1668 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
|
|
1669 anything, and leaving it in breaks the meta key. Go figure. */
|
|
1670 /* Turning off ONLCR is enough under BSD/386. Leave the general
|
|
1671 output post-processing flag alone since for some reason it
|
|
1672 doesn't get reset after XEmacs goes away. */
|
|
1673 tty.lmode &= ~LLITOUT;
|
|
1674 #endif
|
185
|
1675
|
0
|
1676 #endif /* HAVE_TCHARS */
|
|
1677 #endif /* not HAVE_TERMIO */
|
185
|
1678
|
0
|
1679 #ifdef HAVE_LTCHARS
|
|
1680 tty.ltchars = new_ltchars;
|
|
1681 #endif /* HAVE_LTCHARS */
|
|
1682 #ifdef MSDOS
|
|
1683 internal_terminal_init ();
|
|
1684 dos_ttraw ();
|
|
1685 #endif
|
185
|
1686
|
0
|
1687 EMACS_SET_TTY (input_fd, &tty, 0);
|
185
|
1688
|
0
|
1689 /* This code added to insure that, if flow-control is not to be used,
|
|
1690 we have an unlocked terminal at the start. */
|
185
|
1691
|
0
|
1692 #ifdef TCXONC
|
|
1693 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1);
|
|
1694 #endif
|
|
1695 #ifndef APOLLO
|
|
1696 #ifdef TIOCSTART
|
|
1697 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0);
|
|
1698 #endif
|
|
1699 #endif
|
185
|
1700
|
0
|
1701 #if defined (HAVE_TERMIOS) || defined (HPUX9)
|
|
1702 #ifdef TCOON
|
|
1703 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON);
|
|
1704 #endif
|
|
1705 #endif
|
|
1706 #ifdef AIXHFT
|
|
1707 hft_init (con);
|
|
1708 #ifdef IBMR2AIX
|
|
1709 {
|
|
1710 /* IBM's HFT device usually thinks a ^J should be LF/CR.
|
|
1711 We need it to be only LF. This is the way that is
|
|
1712 done. */
|
|
1713 struct termio tty;
|
185
|
1714
|
0
|
1715 if (ioctl (output_fd, HFTGETID, &tty) != -1)
|
|
1716 write (output_fd, "\033[20l", 5);
|
|
1717 }
|
|
1718 #endif
|
|
1719 #endif
|
|
1720
|
|
1721 #ifdef VMS
|
|
1722 /* Appears to do nothing when in PASTHRU mode.
|
|
1723 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
|
|
1724 interrupt_signal, oob_chars, 0, 0, 0, 0);
|
|
1725 */
|
|
1726 queue_kbd_input (0);
|
|
1727 #endif /* VMS */
|
|
1728
|
|
1729 #if 0 /* We do our own buffering with lstreams. */
|
|
1730 #ifdef _IOFBF
|
|
1731 /* This symbol is defined on recent USG systems.
|
|
1732 Someone says without this call USG won't really buffer the file
|
|
1733 even with a call to setbuf. */
|
|
1734 setvbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf, _IOFBF, sizeof _sobuf);
|
|
1735 #else
|
|
1736 setbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf);
|
|
1737 #endif
|
|
1738 #endif
|
|
1739 set_tty_modes (con);
|
|
1740 }
|
|
1741
|
|
1742 #endif /* HAVE_TTY */
|
|
1743
|
|
1744 void
|
|
1745 init_one_device (struct device *d)
|
|
1746 {
|
|
1747 #ifdef HAVE_TTY
|
|
1748 if (DEVICE_TTY_P (d))
|
|
1749 tty_init_sys_modes_on_device (d);
|
|
1750 #endif
|
|
1751 #ifdef SIGIO
|
|
1752 if (!DEVICE_STREAM_P (d))
|
|
1753 {
|
|
1754 init_sigio_on_device (d);
|
|
1755 request_sigio_on_device (d);
|
|
1756 }
|
|
1757 #endif
|
|
1758 }
|
|
1759
|
|
1760 void
|
|
1761 init_one_console (struct console *con)
|
|
1762 {
|
|
1763 Lisp_Object devcons;
|
|
1764
|
|
1765 CONSOLE_DEVICE_LOOP (devcons, con)
|
|
1766 {
|
|
1767 struct device *d = XDEVICE (XCAR (devcons));
|
185
|
1768
|
0
|
1769 init_one_device (d);
|
|
1770 }
|
|
1771 }
|
|
1772
|
|
1773 void
|
|
1774 reinit_initial_console (void)
|
|
1775 {
|
|
1776 munge_process_groups ();
|
|
1777 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
1778 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
1779 init_one_console (XCONSOLE (Vcontrolling_terminal));
|
|
1780 }
|
|
1781
|
|
1782
|
|
1783 /* ------------------------------------------------------ */
|
|
1784 /* Other TTY functions */
|
|
1785 /* ------------------------------------------------------ */
|
|
1786
|
|
1787 #ifdef HAVE_TTY
|
|
1788
|
|
1789 #if 0 /* not currently used */
|
|
1790
|
|
1791 /* Return nonzero if safe to use tabs in output.
|
|
1792 At the time this is called, init_sys_modes has not been done yet. */
|
185
|
1793
|
0
|
1794 int
|
|
1795 tabs_safe_p (struct device *d)
|
|
1796 {
|
|
1797 #ifdef HAVE_TTY
|
|
1798 if (DEVICE_TTY_P (d))
|
|
1799 {
|
|
1800 struct emacs_tty tty;
|
185
|
1801
|
0
|
1802 EMACS_GET_TTY (DEVICE_INFD (d), &tty);
|
|
1803 return EMACS_TTY_TABS_OK (&tty);
|
|
1804 }
|
|
1805 #endif
|
|
1806 return 1;
|
|
1807 }
|
|
1808
|
|
1809 #endif /* 0 */
|
|
1810
|
|
1811 /* Get terminal size from system.
|
|
1812 Store number of lines into *heightp and width into *widthp.
|
|
1813 If zero or a negative number is stored, the value is not valid. */
|
|
1814
|
|
1815 void
|
|
1816 get_tty_device_size (struct device *d, int *widthp, int *heightp)
|
|
1817 {
|
|
1818 int input_fd = DEVICE_INFD (d);
|
|
1819
|
|
1820 assert (DEVICE_TTY_P (d));
|
|
1821
|
|
1822 #ifdef TIOCGWINSZ
|
|
1823 {
|
|
1824 /* BSD-style. */
|
|
1825 struct winsize size;
|
185
|
1826
|
0
|
1827 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1)
|
|
1828 *widthp = *heightp = 0;
|
|
1829 else
|
|
1830 {
|
|
1831 *widthp = size.ws_col;
|
|
1832 *heightp = size.ws_row;
|
|
1833 }
|
|
1834 }
|
|
1835 #else
|
|
1836 #ifdef TIOCGSIZE
|
|
1837 {
|
|
1838 /* SunOS - style. */
|
185
|
1839 struct ttysize size;
|
|
1840
|
0
|
1841 if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
|
|
1842 *widthp = *heightp = 0;
|
|
1843 else
|
|
1844 {
|
|
1845 *widthp = size.ts_cols;
|
|
1846 *heightp = size.ts_lines;
|
|
1847 }
|
|
1848 }
|
|
1849 #else
|
|
1850 #ifdef VMS
|
|
1851 {
|
|
1852 struct vms_sensemode tty;
|
185
|
1853
|
0
|
1854 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0,
|
|
1855 &tty.class, 12, 0, 0, 0, 0);
|
|
1856 *widthp = tty.scr_wid;
|
|
1857 *heightp = tty.scr_len;
|
|
1858 }
|
|
1859 #else
|
|
1860 #ifdef MSDOS
|
|
1861
|
|
1862 *widthp = FrameCols ();
|
|
1863 *heightp = FrameRows ();
|
|
1864
|
|
1865 #else /* system doesn't know size */
|
|
1866
|
|
1867 *widthp = 0;
|
|
1868 *heightp = 0;
|
|
1869
|
|
1870 #endif /* not MSDOS */
|
|
1871 #endif /* not VMS */
|
|
1872 #endif /* not SunOS-style */
|
|
1873 #endif /* not BSD-style */
|
|
1874 }
|
|
1875
|
|
1876 #endif /* HAVE_TTY */
|
|
1877
|
|
1878
|
|
1879 /* ------------------------------------------------------ */
|
|
1880 /* Is device 8 bit ? */
|
|
1881 /* ------------------------------------------------------ */
|
|
1882
|
|
1883 #ifdef HAVE_TTY
|
|
1884
|
|
1885 int
|
|
1886 eight_bit_tty (struct device *d)
|
|
1887 {
|
|
1888 struct emacs_tty s;
|
|
1889 int input_fd;
|
|
1890 int eight_bit = 0;
|
|
1891
|
|
1892 assert (DEVICE_TTY_P (d));
|
|
1893 input_fd = DEVICE_INFD (d);
|
|
1894
|
|
1895 EMACS_GET_TTY (input_fd, &s);
|
|
1896
|
|
1897 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
|
|
1898 eight_bit = (s.main.c_cflag & CSIZE) == CS8;
|
|
1899 #else
|
|
1900 eight_bit = 0; /* I don't know how to do it */
|
|
1901 #endif
|
|
1902 return eight_bit;
|
|
1903 }
|
|
1904
|
|
1905 #endif /* HAVE_TTY */
|
|
1906
|
|
1907
|
|
1908 /* ------------------------------------------------------ */
|
|
1909 /* Resetting a device */
|
|
1910 /* ------------------------------------------------------ */
|
|
1911
|
|
1912 #ifdef HAVE_TTY
|
|
1913
|
|
1914 /* Prepare the terminal for exiting Emacs; move the cursor to the
|
|
1915 bottom of the frame, turn off interrupt-driven I/O, etc. */
|
|
1916 static void
|
|
1917 tty_reset_sys_modes_on_device (struct device *d)
|
|
1918 {
|
|
1919 int input_fd, output_fd;
|
|
1920 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1921
|
|
1922 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
1923 output_fd = CONSOLE_TTY_DATA (con)->outfd;
|
|
1924
|
|
1925 #if defined (IBMR2AIX) && defined (AIXHFT)
|
|
1926 {
|
185
|
1927 /* HFT consoles normally use ^J as a LF/CR. We forced it to
|
0
|
1928 do the LF only. Now, we need to reset it. */
|
|
1929 struct termio tty;
|
185
|
1930
|
0
|
1931 if (ioctl (output_fd, HFTGETID, &tty) != -1)
|
|
1932 write (output_fd, "\033[20h", 5);
|
|
1933 }
|
|
1934 #endif
|
|
1935
|
|
1936 tty_redisplay_shutdown (con);
|
|
1937 /* reset_tty_modes() flushes the connection at its end. */
|
|
1938 reset_tty_modes (con);
|
185
|
1939
|
0
|
1940 #if defined (BSD)
|
|
1941 /* Avoid possible loss of output when changing terminal modes. */
|
|
1942 fsync (output_fd);
|
|
1943 #endif
|
|
1944
|
|
1945 while (EMACS_SET_TTY (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0)
|
|
1946 < 0 && errno == EINTR)
|
|
1947 ;
|
185
|
1948
|
0
|
1949 #ifdef MSDOS
|
|
1950 dos_ttcooked ();
|
|
1951 #endif
|
185
|
1952
|
0
|
1953 #ifdef SET_LINE_DISCIPLINE
|
|
1954 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
|
|
1955 A different old line discipline is therefore not restored, yet.
|
|
1956 Restore the old line discipline by hand. */
|
|
1957 ioctl (input_fd, TIOCSETD, &old_tty.main.c_line);
|
|
1958 #endif
|
|
1959
|
|
1960 #ifdef AIXHFT
|
|
1961 hft_reset (con);
|
|
1962 #endif
|
|
1963
|
|
1964 #ifdef VMS
|
|
1965 stop_vms_input (con);
|
|
1966 #endif
|
|
1967 }
|
|
1968
|
|
1969 #endif /* HAVE_TTY */
|
|
1970
|
|
1971 void
|
|
1972 reset_one_device (struct device *d)
|
|
1973 {
|
|
1974 #ifdef HAVE_TTY
|
|
1975 if (DEVICE_TTY_P (d))
|
|
1976 tty_reset_sys_modes_on_device (d);
|
|
1977 else
|
|
1978 #endif
|
|
1979 if (DEVICE_STREAM_P (d))
|
|
1980 fflush (CONSOLE_STREAM_DATA (XCONSOLE (DEVICE_CONSOLE (d)))->outfd);
|
|
1981 #ifdef SIGIO
|
|
1982 if (!DEVICE_STREAM_P (d))
|
|
1983 {
|
|
1984 unrequest_sigio_on_device (d);
|
|
1985 reset_sigio_on_device (d);
|
|
1986 }
|
|
1987 #endif
|
|
1988 }
|
|
1989
|
|
1990 void
|
|
1991 reset_one_console (struct console *con)
|
|
1992 {
|
|
1993 /* Note: this can be called during GC. */
|
|
1994 Lisp_Object devcons;
|
|
1995
|
|
1996 CONSOLE_DEVICE_LOOP (devcons, con)
|
|
1997 {
|
|
1998 struct device *d = XDEVICE (XCAR (devcons));
|
185
|
1999
|
0
|
2000 reset_one_device (d);
|
|
2001 }
|
|
2002 }
|
|
2003
|
|
2004 void
|
|
2005 reset_all_consoles (void)
|
|
2006 {
|
|
2007 /* Note: this can be called during GC. */
|
|
2008 Lisp_Object concons;
|
|
2009
|
|
2010 CONSOLE_LOOP (concons)
|
|
2011 {
|
|
2012 struct console *con = XCONSOLE (XCAR (concons));
|
185
|
2013
|
0
|
2014 reset_one_console (con);
|
|
2015 }
|
|
2016
|
|
2017 unmunge_process_groups ();
|
|
2018 }
|
|
2019
|
|
2020 void
|
|
2021 reset_initial_console (void)
|
|
2022 {
|
|
2023 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
2024 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
2025 reset_one_console (XCONSOLE (Vcontrolling_terminal));
|
|
2026 unmunge_process_groups ();
|
|
2027 }
|
|
2028
|
|
2029
|
|
2030 /* ------------------------------------------------------ */
|
|
2031 /* extra TTY stuff under AIX */
|
|
2032 /* ------------------------------------------------------ */
|
|
2033
|
|
2034 #ifdef AIXHFT
|
|
2035
|
|
2036 /* Called from init_sys_modes. */
|
|
2037 static void
|
|
2038 hft_init (struct console *con)
|
|
2039 {
|
|
2040 int junk;
|
|
2041 int input_fd;
|
|
2042
|
|
2043 assert (CONSOLE_TTY_P (con));
|
|
2044 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
2045
|
|
2046 /* If we're not on an HFT we shouldn't do any of this. We determine
|
|
2047 if we are on an HFT by trying to get an HFT error code. If this
|
185
|
2048 call fails, we're not on an HFT. */
|
0
|
2049 #ifdef IBMR2AIX
|
|
2050 if (ioctl (input_fd, HFQERROR, &junk) < 0)
|
|
2051 return;
|
|
2052 #else /* not IBMR2AIX */
|
|
2053 if (ioctl (input_fd, HFQEIO, 0) < 0)
|
|
2054 return;
|
|
2055 #endif /* not IBMR2AIX */
|
|
2056
|
|
2057 /* On AIX the default hft keyboard mapping uses backspace rather than delete
|
|
2058 as the rubout key's ASCII code. Here this is changed. The bug is that
|
|
2059 there's no way to determine the old mapping, so in reset_one_console
|
|
2060 we need to assume that the normal map had been present. Of course, this
|
|
2061 code also doesn't help if on a terminal emulator which doesn't understand
|
|
2062 HFT VTD's. */
|
|
2063 {
|
|
2064 struct hfbuf buf;
|
|
2065 struct hfkeymap keymap;
|
|
2066
|
|
2067 buf.hf_bufp = (char *)&keymap;
|
|
2068 buf.hf_buflen = sizeof (keymap);
|
|
2069 keymap.hf_nkeys = 2;
|
|
2070 keymap.hfkey[0].hf_kpos = 15;
|
|
2071 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
|
|
2072 #ifdef IBMR2AIX
|
|
2073 keymap.hfkey[0].hf_keyidh = '<';
|
|
2074 #else /* not IBMR2AIX */
|
|
2075 keymap.hfkey[0].hf_page = '<';
|
|
2076 #endif /* not IBMR2AIX */
|
|
2077 keymap.hfkey[0].hf_char = 127;
|
|
2078 keymap.hfkey[1].hf_kpos = 15;
|
|
2079 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
|
|
2080 #ifdef IBMR2AIX
|
|
2081 keymap.hfkey[1].hf_keyidh = '<';
|
|
2082 #else /* not IBMR2AIX */
|
|
2083 keymap.hfkey[1].hf_page = '<';
|
|
2084 #endif /* not IBMR2AIX */
|
|
2085 keymap.hfkey[1].hf_char = 127;
|
|
2086 hftctl (input_fd, HFSKBD, &buf);
|
|
2087 }
|
|
2088 /* #### Should probably set a console TTY flag here. */
|
|
2089 #if 0
|
|
2090 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
|
|
2091 at times. */
|
|
2092 line_ins_del_ok = char_ins_del_ok = 0;
|
|
2093 #endif /* 0 */
|
|
2094 }
|
|
2095
|
|
2096 /* Reset the rubout key to backspace. */
|
|
2097
|
|
2098 static void
|
|
2099 hft_reset (struct console *con)
|
|
2100 {
|
|
2101 struct hfbuf buf;
|
|
2102 struct hfkeymap keymap;
|
|
2103 int junk;
|
|
2104 int input_fd;
|
|
2105
|
|
2106 assert (CONSOLE_TTY_P (con));
|
|
2107 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
2108
|
|
2109 #ifdef IBMR2AIX
|
|
2110 if (ioctl (input_fd, HFQERROR, &junk) < 0)
|
|
2111 return;
|
|
2112 #else /* not IBMR2AIX */
|
|
2113 if (ioctl (input_fd, HFQEIO, 0) < 0)
|
|
2114 return;
|
|
2115 #endif /* not IBMR2AIX */
|
|
2116
|
|
2117 buf.hf_bufp = (char *)&keymap;
|
|
2118 buf.hf_buflen = sizeof (keymap);
|
|
2119 keymap.hf_nkeys = 2;
|
|
2120 keymap.hfkey[0].hf_kpos = 15;
|
|
2121 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
|
|
2122 #ifdef IBMR2AIX
|
|
2123 keymap.hfkey[0].hf_keyidh = '<';
|
|
2124 #else /* not IBMR2AIX */
|
|
2125 keymap.hfkey[0].hf_page = '<';
|
|
2126 #endif /* not IBMR2AIX */
|
|
2127 keymap.hfkey[0].hf_char = 8;
|
|
2128 keymap.hfkey[1].hf_kpos = 15;
|
|
2129 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
|
|
2130 #ifdef IBMR2AIX
|
|
2131 keymap.hfkey[1].hf_keyidh = '<';
|
|
2132 #else /* not IBMR2AIX */
|
|
2133 keymap.hfkey[1].hf_page = '<';
|
|
2134 #endif /* not IBMR2AIX */
|
|
2135 keymap.hfkey[1].hf_char = 8;
|
|
2136 hftctl (input_fd, HFSKBD, &buf);
|
|
2137 }
|
|
2138
|
|
2139 #endif /* AIXHFT */
|
|
2140
|
|
2141
|
|
2142 /* ------------------------------------------------------ */
|
|
2143 /* TTY stuff under VMS */
|
|
2144 /* ------------------------------------------------------ */
|
|
2145
|
|
2146 /***** #### this is all broken ****/
|
|
2147
|
|
2148 #ifdef VMS
|
|
2149
|
|
2150 /* Assigning an input channel is done at the start of Emacs execution.
|
|
2151 This is called each time Emacs is resumed, also, but does nothing
|
|
2152 because input_chain is no longer zero. */
|
|
2153
|
|
2154 void
|
|
2155 init_vms_input (void)
|
|
2156 {
|
|
2157 /* #### broken. */
|
|
2158 int status;
|
185
|
2159
|
0
|
2160 if (input_fd == 0)
|
|
2161 {
|
|
2162 status = SYS$ASSIGN (&vms_input_dsc, &input_fd, 0, 0);
|
|
2163 if (! (status & 1))
|
|
2164 LIB$STOP (status);
|
|
2165 }
|
|
2166 }
|
|
2167
|
|
2168 /* Deassigning the input channel is done before exiting. */
|
|
2169
|
|
2170 static void
|
|
2171 stop_vms_input (struct console *con)
|
|
2172 {
|
|
2173 int input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
2174 return SYS$DASSGN (input_fd);
|
|
2175 }
|
|
2176
|
|
2177 static short vms_input_buffer;
|
|
2178
|
|
2179 /* Request reading one character into the keyboard buffer.
|
|
2180 This is done as soon as the buffer becomes empty. */
|
|
2181
|
|
2182 static void
|
|
2183 queue_vms_kbd_input (struct console *con)
|
|
2184 {
|
|
2185 int input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
2186 int status;
|
|
2187 vms_waiting_for_ast = 0;
|
|
2188 vms_stop_input = 0;
|
|
2189 status = SYS$QIO (0, input_fd, IO$_READVBLK,
|
|
2190 &vms_input_iosb, vms_kbd_input_ast, 1,
|
|
2191 &vms_input_buffer, 1, 0, vms_terminator_mask, 0, 0);
|
|
2192 }
|
|
2193
|
|
2194 static int vms_input_count;
|
|
2195
|
|
2196 /* Ast routine that is called when keyboard input comes in
|
|
2197 in accord with the SYS$QIO above. */
|
|
2198
|
|
2199 static void
|
|
2200 vms_kbd_input_ast (struct console *con)
|
|
2201 {
|
|
2202 int c = -1;
|
|
2203 int old_errno = errno;
|
|
2204 extern EMACS_TIME *input_available_clear_time;
|
|
2205
|
|
2206 if (vms_waiting_for_ast)
|
|
2207 SYS$SETEF (vms_input_ef);
|
|
2208 vms_waiting_for_ast = 0;
|
|
2209 vms_input_count++;
|
|
2210 #ifdef ASTDEBUG
|
|
2211 if (vms_input_count == 25)
|
|
2212 exit (1);
|
|
2213 printf ("Ast # %d,", vms_input_count);
|
|
2214 printf (" iosb = %x, %x, %x, %x",
|
185
|
2215 vms_input_iosb.offset, vms_input_iosb.status,
|
0
|
2216 vms_input_iosb.termlen, vms_input_iosb.term);
|
|
2217 #endif
|
|
2218 if (vms_input_iosb.offset)
|
|
2219 {
|
|
2220 c = vms_input_buffer;
|
|
2221 #ifdef ASTDEBUG
|
|
2222 printf (", char = 0%o", c);
|
|
2223 #endif
|
|
2224 }
|
|
2225 #ifdef ASTDEBUG
|
|
2226 printf ("\n");
|
|
2227 fflush (stdout);
|
|
2228 emacs_sleep (1);
|
|
2229 #endif
|
|
2230 if (! vms_stop_input)
|
|
2231 queue_vms_kbd_input (con);
|
|
2232 if (c >= 0)
|
|
2233 kbd_buffer_store_char (c);
|
|
2234
|
|
2235 if (input_available_clear_time)
|
|
2236 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0);
|
|
2237 errno = old_errno;
|
|
2238 }
|
|
2239
|
|
2240 #if 0 /* Unused */
|
|
2241 /* Wait until there is something in kbd_buffer. */
|
|
2242
|
|
2243 void
|
|
2244 vms_wait_for_kbd_input (void)
|
|
2245 {
|
|
2246 /* This function can GC */
|
|
2247 extern int have_process_input, process_exited;
|
|
2248
|
|
2249 /* If already something, avoid doing system calls. */
|
|
2250 if (detect_input_pending (0))
|
|
2251 {
|
|
2252 return;
|
|
2253 }
|
|
2254 /* Clear a flag, and tell ast routine above to set it. */
|
|
2255 SYS$CLREF (vms_input_ef);
|
|
2256 vms_waiting_for_ast = 1;
|
|
2257 /* Check for timing error: ast happened while we were doing that. */
|
|
2258 if (!detect_input_pending (0))
|
|
2259 {
|
|
2260 /* No timing error: wait for flag to be set. */
|
|
2261 set_waiting_for_input (0);
|
|
2262 SYS$WFLOR (vms_input_ef, vms_input_eflist);
|
|
2263 clear_waiting_for_input (0);
|
|
2264 if (!detect_input_pending (0))
|
|
2265 /* Check for subprocess input availability */
|
|
2266 {
|
|
2267 int dsp = have_process_input || process_exited;
|
|
2268
|
|
2269 SYS$CLREF (vms_process_ef);
|
|
2270 if (have_process_input)
|
|
2271 process_command_input ();
|
|
2272 if (process_exited)
|
|
2273 process_exit ();
|
|
2274 if (dsp)
|
|
2275 {
|
|
2276 MARK_MODELINE_CHANGED;
|
|
2277 redisplay ();
|
|
2278 }
|
|
2279 }
|
|
2280 }
|
|
2281 vms_waiting_for_ast = 0;
|
|
2282 }
|
|
2283 #endif
|
|
2284
|
|
2285 /* Get rid of any pending QIO, when we are about to suspend
|
|
2286 or when we want to throw away pending input.
|
|
2287 We wait for a positive sign that the AST routine has run
|
|
2288 and therefore there is no I/O request queued when we return.
|
|
2289 SYS$SETAST is used to avoid a timing error. */
|
|
2290
|
|
2291 static void
|
|
2292 vms_end_kbd_input (struct console *con)
|
|
2293 {
|
|
2294 int input_fd;
|
|
2295
|
|
2296 assert (CONSOLE_TTY_P (con));
|
|
2297 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
2298 #ifdef ASTDEBUG
|
|
2299 printf ("At end_kbd_input.\n");
|
|
2300 fflush (stdout);
|
|
2301 emacs_sleep (1);
|
|
2302 #endif
|
|
2303 if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_char! */
|
|
2304 {
|
|
2305 SYS$CANCEL (input_fd);
|
|
2306 return;
|
|
2307 }
|
|
2308
|
|
2309 SYS$SETAST (0);
|
|
2310 /* Clear a flag, and tell ast routine above to set it. */
|
|
2311 SYS$CLREF (vms_input_ef);
|
|
2312 vms_waiting_for_ast = 1;
|
|
2313 vms_stop_input = 1;
|
|
2314 SYS$CANCEL (input_fd);
|
|
2315 SYS$SETAST (1);
|
|
2316 SYS$WAITFR (vms_input_ef);
|
|
2317 vms_waiting_for_ast = 0;
|
|
2318 }
|
|
2319
|
|
2320 #if 0 /* Unused */
|
|
2321 /* Wait for either input available or time interval expiry. */
|
|
2322
|
|
2323 void
|
|
2324 vms_input_wait_timeout (int timeval) /* Time to wait, in seconds */
|
|
2325 {
|
|
2326 int time [2];
|
|
2327 static int zero = 0;
|
|
2328 static int large = -10000000;
|
|
2329
|
|
2330 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */
|
|
2331
|
|
2332 /* If already something, avoid doing system calls. */
|
|
2333 if (detect_input_pending (0))
|
|
2334 {
|
|
2335 return;
|
|
2336 }
|
|
2337 /* Clear a flag, and tell ast routine above to set it. */
|
|
2338 SYS$CLREF (vms_input_ef);
|
|
2339 vms_waiting_for_ast = 1;
|
|
2340 /* Check for timing error: ast happened while we were doing that. */
|
|
2341 if (!detect_input_pending (0))
|
|
2342 {
|
|
2343 /* No timing error: wait for flag to be set. */
|
|
2344 SYS$CANTIM (1, 0);
|
|
2345 if (SYS$SETIMR (vms_timer_ef, time, 0, 1) & 1) /* Set timer */
|
|
2346 SYS$WFLOR (vms_timer_ef, vms_timer_eflist); /* Wait for timer expiry or input */
|
|
2347 }
|
|
2348 vms_waiting_for_ast = 0;
|
|
2349 }
|
|
2350 #endif /* 0 */
|
|
2351
|
|
2352 #endif /* VMS */
|
|
2353
|
|
2354
|
|
2355 /************************************************************************/
|
|
2356 /* limits of text/data segments */
|
|
2357 /************************************************************************/
|
|
2358
|
|
2359 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
|
|
2360 #ifndef CANNOT_DUMP
|
|
2361 #define NEED_STARTS
|
|
2362 #endif
|
|
2363
|
|
2364 #ifndef SYSTEM_MALLOC
|
|
2365 #ifndef NEED_STARTS
|
|
2366 #define NEED_STARTS
|
|
2367 #endif
|
|
2368 #endif
|
|
2369
|
|
2370 #ifdef NEED_STARTS
|
|
2371 /* Some systems that cannot dump also cannot implement these. */
|
|
2372
|
|
2373 /*
|
|
2374 * Return the address of the start of the text segment prior to
|
|
2375 * doing an unexec. After unexec the return value is undefined.
|
|
2376 * See crt0.c for further explanation and _start.
|
|
2377 *
|
|
2378 */
|
|
2379
|
185
|
2380 #ifdef __cplusplus
|
|
2381 extern "C" int _start ();
|
|
2382 #else
|
|
2383 extern int _start ();
|
|
2384 #endif
|
|
2385
|
0
|
2386 #ifndef HAVE_TEXT_START
|
|
2387 char *
|
|
2388 start_of_text (void)
|
|
2389 {
|
|
2390 #ifdef TEXT_START
|
|
2391 return ((char *) TEXT_START);
|
|
2392 #else
|
|
2393 #ifdef GOULD
|
|
2394 extern csrt ();
|
|
2395 return ((char *) csrt);
|
|
2396 #else /* not GOULD */
|
|
2397 return ((char *) _start);
|
|
2398 #endif /* GOULD */
|
|
2399 #endif /* TEXT_START */
|
|
2400 }
|
|
2401 #endif /* not HAVE_TEXT_START */
|
|
2402
|
|
2403 /*
|
|
2404 * Return the address of the start of the data segment prior to
|
|
2405 * doing an unexec. After unexec the return value is undefined.
|
|
2406 * See crt0.c for further information and definition of data_start.
|
|
2407 *
|
|
2408 * Apparently, on BSD systems this is etext at startup. On
|
|
2409 * USG systems (swapping) this is highly mmu dependent and
|
|
2410 * is also dependent on whether or not the program is running
|
|
2411 * with shared text. Generally there is a (possibly large)
|
|
2412 * gap between end of text and start of data with shared text.
|
|
2413 *
|
|
2414 * On Uniplus+ systems with shared text, data starts at a
|
|
2415 * fixed address. Each port (from a given oem) is generally
|
|
2416 * different, and the specific value of the start of data can
|
|
2417 * be obtained via the UniPlus+ specific "uvar" system call,
|
|
2418 * however the method outlined in crt0.c seems to be more portable.
|
|
2419 *
|
|
2420 * Probably what will have to happen when a USG unexec is available,
|
|
2421 * at least on UniPlus, is temacs will have to be made unshared so
|
|
2422 * that text and data are contiguous. Then once loadup is complete,
|
|
2423 * unexec will produce a shared executable where the data can be
|
|
2424 * at the normal shared text boundry and the startofdata variable
|
|
2425 * will be patched by unexec to the correct value.
|
|
2426 *
|
|
2427 */
|
185
|
2428
|
0
|
2429 void *
|
|
2430 start_of_data (void)
|
|
2431 {
|
|
2432 #ifdef DATA_START
|
|
2433 return ((char *) DATA_START);
|
|
2434 #else
|
|
2435 #ifdef ORDINARY_LINK
|
|
2436 /*
|
|
2437 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
|
|
2438 * data_start isn't defined. We take the address of environ, which
|
|
2439 * is known to live at or near the start of the system crt0.c, and
|
|
2440 * we don't sweat the handful of bytes that might lose.
|
|
2441 */
|
|
2442 extern char **environ;
|
|
2443
|
|
2444 return((char *) &environ);
|
|
2445 #else
|
|
2446 extern int data_start;
|
|
2447 return ((char *) &data_start);
|
|
2448 #endif /* ORDINARY_LINK */
|
|
2449 #endif /* DATA_START */
|
|
2450 }
|
|
2451 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
|
|
2452
|
|
2453 #ifndef CANNOT_DUMP
|
|
2454 /* Some systems that cannot dump also cannot implement these. */
|
|
2455
|
|
2456 /*
|
|
2457 * Return the address of the end of the text segment prior to
|
|
2458 * doing an unexec. After unexec the return value is undefined.
|
|
2459 */
|
185
|
2460
|
0
|
2461 char *
|
|
2462 end_of_text (void)
|
|
2463 {
|
|
2464 #ifdef TEXT_END
|
|
2465 return ((char *) TEXT_END);
|
|
2466 #else
|
|
2467 extern int etext;
|
|
2468 return ((char *) &etext);
|
|
2469 #endif
|
|
2470 }
|
185
|
2471
|
0
|
2472 /*
|
|
2473 * Return the address of the end of the data segment prior to
|
|
2474 * doing an unexec. After unexec the return value is undefined.
|
|
2475 */
|
|
2476
|
|
2477 char *
|
|
2478 end_of_data (void)
|
|
2479 {
|
|
2480 #ifdef DATA_END
|
|
2481 return ((char *) DATA_END);
|
|
2482 #else
|
|
2483 extern int edata;
|
|
2484 return ((char *) &edata);
|
|
2485 #endif
|
|
2486 }
|
|
2487
|
|
2488 #endif /* not CANNOT_DUMP */
|
|
2489
|
|
2490
|
|
2491 /************************************************************************/
|
|
2492 /* get the system name */
|
|
2493 /************************************************************************/
|
|
2494
|
|
2495 /* init_system_name sets up the string for the Lisp function
|
|
2496 system-name to return. */
|
|
2497
|
|
2498 extern Lisp_Object Vsystem_name;
|
|
2499
|
|
2500 #if defined (HAVE_SOCKETS) && !defined (VMS)
|
|
2501 # include <sys/socket.h>
|
|
2502 # include <netdb.h>
|
|
2503 #endif /* HAVE_SOCKETS and not VMS */
|
|
2504
|
|
2505 void
|
|
2506 init_system_name (void)
|
|
2507 {
|
|
2508 #if defined (VMS)
|
|
2509 char *sp, *end;
|
|
2510 if ((sp = egetenv ("SYS$NODE")) == 0)
|
|
2511 Vsystem_name = build_string ("vax-vms");
|
|
2512 else if ((end = strchr (sp, ':')) == 0)
|
|
2513 Vsystem_name = build_string (sp);
|
|
2514 else
|
|
2515 Vsystem_name = make_string ((Bufbyte *) sp, end - sp);
|
|
2516 #elif !defined (HAVE_GETHOSTNAME)
|
|
2517 struct utsname uts;
|
|
2518 uname (&uts);
|
|
2519 Vsystem_name = build_string (uts.nodename);
|
|
2520 #else /* HAVE_GETHOSTNAME */
|
|
2521 unsigned int hostname_size = 256;
|
|
2522 char *hostname = (char *) alloca (hostname_size);
|
|
2523
|
|
2524 /* Try to get the host name; if the buffer is too short, try
|
|
2525 again. Apparently, the only indication gethostname gives of
|
|
2526 whether the buffer was large enough is the presence or absence
|
|
2527 of a '\0' in the string. Eech. */
|
|
2528 for (;;)
|
|
2529 {
|
|
2530 gethostname (hostname, hostname_size - 1);
|
|
2531 hostname[hostname_size - 1] = '\0';
|
|
2532
|
|
2533 /* Was the buffer large enough for the '\0'? */
|
|
2534 if (strlen (hostname) < (size_t) (hostname_size - 1))
|
|
2535 break;
|
|
2536
|
|
2537 hostname_size <<= 1;
|
|
2538 hostname = (char *) alloca (hostname_size);
|
|
2539 }
|
|
2540 # ifdef HAVE_SOCKETS
|
|
2541 /* Turn the hostname into the official, fully-qualified hostname.
|
|
2542 Don't do this if we're going to dump; this can confuse system
|
|
2543 libraries on some machines and make the dumped emacs core dump. */
|
|
2544 # ifndef CANNOT_DUMP
|
|
2545 if (initialized)
|
|
2546 # endif /* not CANNOT_DUMP */
|
|
2547 {
|
|
2548 struct hostent *hp;
|
|
2549 int count;
|
|
2550 # ifdef TRY_AGAIN
|
|
2551 for (count = 0; count < 10; count++)
|
|
2552 {
|
|
2553 h_errno = 0;
|
|
2554 # endif
|
|
2555 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */
|
|
2556 stop_interrupts ();
|
|
2557 hp = gethostbyname (hostname);
|
|
2558 start_interrupts ();
|
|
2559 # ifdef TRY_AGAIN
|
|
2560 if (! (hp == 0 && h_errno == TRY_AGAIN))
|
|
2561 break;
|
|
2562 Fsleep_for (make_int (1));
|
|
2563 }
|
|
2564 # endif
|
|
2565 if (hp)
|
|
2566 {
|
|
2567 CONST char *fqdn = (CONST char *) hp->h_name;
|
|
2568
|
|
2569 if (!strchr (fqdn, '.'))
|
|
2570 {
|
|
2571 /* We still don't have a fully qualified domain name.
|
|
2572 Try to find one in the list of alternate names */
|
|
2573 char **alias = hp->h_aliases;
|
|
2574 while (*alias && !strchr (*alias, '.'))
|
|
2575 alias++;
|
|
2576 if (*alias)
|
|
2577 fqdn = *alias;
|
|
2578 }
|
|
2579 hostname = (char *) alloca (strlen (fqdn) + 1);
|
|
2580 strcpy (hostname, fqdn);
|
|
2581 }
|
|
2582 }
|
|
2583 # endif /* HAVE_SOCKETS */
|
|
2584 Vsystem_name = build_string (hostname);
|
|
2585 #endif /* HAVE_GETHOSTNAME and not VMS */
|
|
2586 {
|
|
2587 Bufbyte *p;
|
|
2588 Bytecount i;
|
|
2589
|
16
|
2590 for (i = 0, p = XSTRING_DATA (Vsystem_name);
|
|
2591 i < XSTRING_LENGTH (Vsystem_name);
|
0
|
2592 i++, p++)
|
|
2593 {
|
|
2594 if (*p == ' ' || *p == '\t')
|
|
2595 *p = '-';
|
|
2596 }
|
|
2597 }
|
|
2598 }
|
|
2599
|
|
2600
|
|
2601 /************************************************************************/
|
|
2602 /* Emulation of select() */
|
|
2603 /************************************************************************/
|
|
2604
|
|
2605 #ifndef VMS
|
|
2606 #ifndef HAVE_SELECT
|
|
2607
|
|
2608 ERROR: XEmacs requires a working select().
|
|
2609
|
|
2610 #endif /* not HAVE_SELECT */
|
|
2611 #endif /* not VMS */
|
|
2612
|
|
2613
|
|
2614 /************************************************************************/
|
|
2615 /* Emulation of signal stuff */
|
|
2616 /************************************************************************/
|
|
2617
|
|
2618 /* BSD 4.1 crap deleted. 4.2 was released in 1983, for God's sake! I
|
|
2619 can't imagine that anyone is actually running that OS any more.
|
|
2620 You can't use X under it (I think) because there's no select().
|
|
2621 Anyway, the signal stuff has all been changed. If someone wants to
|
|
2622 get this stuff working again, look in the FSF Emacs sources. */
|
185
|
2623
|
0
|
2624 /* POSIX signals support - DJB */
|
|
2625
|
|
2626 #ifdef HAVE_SIGPROCMASK
|
|
2627
|
|
2628 /* #### Is there any reason this is static global rather than local? */
|
|
2629 static struct sigaction new_action, old_action;
|
|
2630
|
|
2631 signal_handler_t
|
|
2632 sys_do_signal (int signal_number, signal_handler_t action)
|
|
2633 {
|
|
2634 #if 0
|
|
2635
|
|
2636 /* XEmacs works better if system calls are *not* restarted.
|
|
2637 This allows C-g to interrupt reads and writes, on most systems.
|
|
2638
|
|
2639 #### Another possibility is to just longjmp() out of the signal
|
|
2640 handler. According to W.R. Stevens, this should be OK on all
|
|
2641 systems. However, I don't want to deal with the potential
|
|
2642 evil ramifications of this at this point. */
|
|
2643
|
|
2644 #ifdef DGUX
|
|
2645 /* This gets us restartable system calls for efficiency.
|
|
2646 The "else" code will work as well. */
|
|
2647 return (berk_signal (signal_number, action));
|
|
2648 #else
|
|
2649 sigemptyset (&new_action.sa_mask);
|
|
2650 new_action.sa_handler = action;
|
|
2651 #if defined (SA_RESTART)
|
|
2652 /* Emacs mostly works better with restartable system services. If this
|
|
2653 * flag exists, we probably want to turn it on here.
|
|
2654 */
|
|
2655 new_action.sa_flags = SA_RESTART;
|
|
2656 #else
|
|
2657 new_action.sa_flags = 0;
|
|
2658 #endif
|
|
2659 sigaction (signal_number, &new_action, &old_action);
|
|
2660 return (old_action.sa_handler);
|
|
2661 #endif /* DGUX */
|
|
2662
|
|
2663 #else /* not 0 */
|
|
2664
|
|
2665 sigemptyset (&new_action.sa_mask);
|
|
2666 new_action.sa_handler = action;
|
|
2667 #if defined (SA_INTERRUPT) /* don't restart system calls, under SunOS */
|
|
2668 new_action.sa_flags = SA_INTERRUPT;
|
|
2669 #else
|
|
2670 new_action.sa_flags = 0;
|
|
2671 #endif
|
|
2672 sigaction (signal_number, &new_action, &old_action);
|
179
|
2673 return (signal_handler_t) (old_action.sa_handler);
|
0
|
2674
|
|
2675 #endif /* not 0 */
|
|
2676 }
|
|
2677
|
|
2678 #elif defined (HAVE_SIGBLOCK)
|
|
2679
|
|
2680 /* We use sigvec() rather than signal() if we have it, because
|
|
2681 it lets us specify interruptible system calls. */
|
|
2682 signal_handler_t
|
|
2683 sys_do_signal (int signal_number, signal_handler_t action)
|
|
2684 {
|
|
2685 struct sigvec vec, ovec;
|
|
2686
|
|
2687 vec.sv_handler = action;
|
|
2688 vec.sv_mask = 0;
|
|
2689 #ifdef SV_INTERRUPT /* don't restart system calls */
|
|
2690 vec.sv_flags = SV_INTERRUPT;
|
|
2691 #else
|
|
2692 vec.sv_flags = 0;
|
|
2693 #endif
|
|
2694
|
|
2695 sigvec (signal_number, &vec, &ovec);
|
|
2696
|
|
2697 return (ovec.sv_handler);
|
|
2698 }
|
|
2699
|
|
2700 #endif /* HAVE_SIGBLOCK (HAVE_SIGPROCMASK) */
|
|
2701
|
|
2702
|
|
2703 /************************************************************************/
|
|
2704 /* Emulation of strerror() */
|
|
2705 /************************************************************************/
|
|
2706
|
|
2707 #ifndef HAVE_STRERROR
|
|
2708
|
|
2709 #if defined (VMS) && defined (LINK_CRTL_SHARE) && defined (SHAREABLE_LIB_BUG)
|
|
2710
|
|
2711 /* Variables declared noshare and initialized in sharable libraries
|
|
2712 cannot be shared. The VMS linker incorrectly forces you to use a private
|
|
2713 version which is uninitialized... If not for this "feature", we
|
|
2714 could use the C library definition of sys_nerr and sys_errlist. */
|
|
2715 CONST char *sys_errlist[] =
|
|
2716 {
|
|
2717 "error 0",
|
|
2718 "not owner",
|
|
2719 "no such file or directory",
|
|
2720 "no such process",
|
|
2721 "interrupted system call",
|
|
2722 "I/O error",
|
|
2723 "no such device or address",
|
|
2724 "argument list too long",
|
|
2725 "exec format error",
|
|
2726 "bad file number",
|
|
2727 "no child process",
|
|
2728 "no more processes",
|
|
2729 "not enough memory",
|
|
2730 "permission denied",
|
|
2731 "bad address",
|
|
2732 "block device required",
|
|
2733 "mount devices busy",
|
|
2734 "file exists",
|
|
2735 "cross-device link",
|
|
2736 "no such device",
|
|
2737 "not a directory",
|
|
2738 "is a directory",
|
|
2739 "invalid argument",
|
|
2740 "file table overflow",
|
|
2741 "too many open files",
|
|
2742 "not a typewriter",
|
|
2743 "text file busy",
|
|
2744 "file too big",
|
|
2745 "no space left on device",
|
|
2746 "illegal seek",
|
|
2747 "read-only file system",
|
|
2748 "too many links",
|
|
2749 "broken pipe",
|
|
2750 "math argument",
|
|
2751 "result too large",
|
|
2752 "I/O stream empty",
|
|
2753 "vax/vms specific error code nontranslatable error"
|
|
2754 };
|
|
2755 int sys_nerr = countof (sys_errlist);
|
|
2756
|
|
2757 #endif /* VMS & LINK_CRTL_SHARE & SHAREABLE_LIB_BUG */
|
|
2758
|
|
2759
|
|
2760 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__)
|
|
2761 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */
|
|
2762 /* Irix added here by gparker@sni-usa.com for XEmacs. */
|
|
2763 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */
|
|
2764 extern CONST char *sys_errlist[];
|
|
2765 extern int sys_nerr;
|
|
2766 #endif
|
|
2767
|
|
2768 #ifdef __NetBSD__
|
|
2769 extern char *sys_errlist[];
|
|
2770 extern int sys_nerr;
|
|
2771 #endif
|
|
2772
|
|
2773
|
|
2774 CONST char *
|
|
2775 strerror (int errnum)
|
|
2776 {
|
|
2777 if (errnum >= 0 && errnum < sys_nerr)
|
|
2778 return sys_errlist[errnum];
|
|
2779 return ((CONST char *) GETTEXT ("Unknown error"));
|
|
2780 }
|
|
2781
|
|
2782 #endif /* ! HAVE_STRERROR */
|
|
2783
|
|
2784
|
|
2785
|
|
2786 /************************************************************************/
|
|
2787 /* Encapsulations of system calls */
|
|
2788 /************************************************************************/
|
|
2789
|
|
2790 #define PATHNAME_CONVERT_OUT(path) \
|
|
2791 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (path, path)
|
|
2792
|
|
2793 /***** VMS versions are at the bottom of this file *****/
|
|
2794 /***** MSDOS versions are in msdos.c *****/
|
|
2795
|
|
2796 /***************** low-level calls ****************/
|
|
2797
|
|
2798 /*
|
|
2799 * On USG systems the system calls are INTERRUPTIBLE by signals
|
|
2800 * that the user program has elected to catch. Thus the system call
|
|
2801 * must be retried in these cases. To handle this without massive
|
|
2802 * changes in the source code, we remap the standard system call names
|
|
2803 * to names for our own functions in sysdep.c that do the system call
|
|
2804 * with retries. Actually, for portability reasons, it is good
|
|
2805 * programming practice, as this example shows, to limit all actual
|
|
2806 * system calls to a single occurrence in the source. Sure, this
|
|
2807 * adds an extra level of function call overhead but it is almost
|
|
2808 * always negligible. Fred Fish, Unisoft Systems Inc.
|
|
2809 */
|
|
2810
|
|
2811 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better
|
|
2812 approach to programming and its connection to the silly
|
|
2813 interruptible-system-call business. To find it, look at
|
|
2814 Jamie's home page (http://www.netscape.com/people/jwz). */
|
|
2815
|
|
2816 #ifdef ENCAPSULATE_OPEN
|
|
2817 int
|
|
2818 sys_open (CONST char *path, int oflag, ...)
|
|
2819 {
|
|
2820 int mode;
|
|
2821 va_list ap;
|
185
|
2822
|
0
|
2823 va_start (ap, oflag);
|
|
2824 mode = va_arg (ap, int);
|
|
2825 va_end (ap);
|
|
2826
|
|
2827 PATHNAME_CONVERT_OUT (path);
|
|
2828 #ifdef INTERRUPTIBLE_OPEN
|
|
2829 {
|
|
2830 int rtnval;
|
|
2831 while ((rtnval = open (path, oflag, mode)) == -1
|
|
2832 && (errno == EINTR));
|
|
2833 return rtnval;
|
|
2834 }
|
|
2835 #else
|
|
2836 return open (path, oflag, mode);
|
|
2837 #endif
|
|
2838 }
|
|
2839 #endif /* ENCAPSULATE_OPEN */
|
|
2840
|
16
|
2841
|
0
|
2842 #ifdef ENCAPSULATE_CLOSE
|
|
2843 int
|
|
2844 sys_close (int fd)
|
|
2845 {
|
|
2846 #ifdef INTERRUPTIBLE_CLOSE
|
|
2847 int did_retry = 0;
|
|
2848 register int rtnval;
|
|
2849
|
|
2850 while ((rtnval = close (fd)) == -1
|
|
2851 && (errno == EINTR))
|
|
2852 did_retry = 1;
|
|
2853
|
|
2854 /* If close is interrupted SunOS 4.1 may or may not have closed the
|
|
2855 file descriptor. If it did the second close will fail with
|
|
2856 errno = EBADF. That means we have succeeded. */
|
|
2857 if (rtnval == -1 && did_retry && errno == EBADF)
|
|
2858 return 0;
|
|
2859
|
|
2860 return rtnval;
|
|
2861 #else
|
|
2862 return close (fd);
|
|
2863 #endif
|
|
2864 }
|
|
2865 #endif /* ENCAPSULATE_CLOSE */
|
|
2866
|
|
2867 int
|
|
2868 sys_read_1 (int fildes, void *buf, unsigned int nbyte, int allow_quit)
|
|
2869 {
|
|
2870 #ifdef VMS
|
|
2871 return vms_read (fildes, buf, nbyte);
|
|
2872 #else
|
|
2873 int rtnval;
|
|
2874
|
|
2875 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
|
|
2876 while ((rtnval = read (fildes, buf, nbyte)) == -1
|
|
2877 && (errno == EINTR))
|
|
2878 {
|
|
2879 if (allow_quit)
|
|
2880 REALLY_QUIT;
|
|
2881 }
|
|
2882 return rtnval;
|
|
2883 #endif
|
|
2884 }
|
|
2885
|
|
2886 #ifdef ENCAPSULATE_READ
|
|
2887 int
|
|
2888 sys_read (int fildes, void *buf, unsigned int nbyte)
|
|
2889 {
|
|
2890 return sys_read_1 (fildes, buf, nbyte, 0);
|
|
2891 }
|
|
2892 #endif /* ENCAPSULATE_READ */
|
|
2893
|
|
2894 int
|
|
2895 sys_write_1 (int fildes, CONST void *buf, unsigned int nbyte, int allow_quit)
|
|
2896 {
|
|
2897 #ifdef VMS
|
|
2898 return vms_write (fildes, buf, nbyte);
|
|
2899 #else
|
|
2900 int rtnval;
|
|
2901 int bytes_written = 0;
|
185
|
2902 CONST char *b = (CONST char *) buf;
|
0
|
2903
|
|
2904 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
|
|
2905 while (nbyte > 0)
|
|
2906 {
|
|
2907 rtnval = write (fildes, b, nbyte);
|
|
2908
|
|
2909 if (allow_quit)
|
|
2910 REALLY_QUIT;
|
|
2911
|
|
2912 if (rtnval == -1)
|
|
2913 {
|
|
2914 if (errno == EINTR)
|
|
2915 continue;
|
|
2916 else
|
|
2917 return (bytes_written ? bytes_written : -1);
|
|
2918 }
|
|
2919 b += rtnval;
|
|
2920 nbyte -= rtnval;
|
|
2921 bytes_written += rtnval;
|
|
2922 }
|
|
2923 return (bytes_written);
|
|
2924 #endif
|
|
2925 }
|
|
2926
|
|
2927 #ifdef ENCAPSULATE_WRITE
|
|
2928 int
|
|
2929 sys_write (int fildes, CONST void *buf, unsigned int nbyte)
|
|
2930 {
|
|
2931 return sys_write_1 (fildes, buf, nbyte, 0);
|
|
2932 }
|
|
2933 #endif /* ENCAPSULATE_WRITE */
|
|
2934
|
|
2935
|
|
2936 /**************** stdio calls ****************/
|
|
2937
|
|
2938 /* There is at least some evidence that the stdio calls are interruptible
|
|
2939 just like the normal system calls, at least on some systems. In any
|
|
2940 case, it doesn't hurt to encapsulate them. */
|
|
2941
|
|
2942 /* #### Should also encapsulate fflush().
|
|
2943 #### Should conceivably encapsulate getchar() etc. What a pain! */
|
|
2944
|
|
2945 #ifdef ENCAPSULATE_FOPEN
|
|
2946 FILE *
|
|
2947 sys_fopen (CONST char *path, CONST char *type)
|
|
2948 {
|
|
2949 PATHNAME_CONVERT_OUT (path);
|
|
2950 #ifdef INTERRUPTIBLE_OPEN
|
|
2951 {
|
|
2952 FILE *rtnval;
|
|
2953 while (!(rtnval = fopen (path, type)) && (errno == EINTR));
|
|
2954 return rtnval;
|
|
2955 }
|
|
2956 #else
|
|
2957 return fopen (path, type);
|
|
2958 #endif
|
|
2959 }
|
|
2960 #endif /* ENCAPSULATE_FOPEN */
|
|
2961
|
16
|
2962
|
0
|
2963 #ifdef ENCAPSULATE_FCLOSE
|
|
2964 int
|
|
2965 sys_fclose (FILE *stream)
|
|
2966 {
|
|
2967 #ifdef INTERRUPTIBLE_CLOSE
|
|
2968 int rtnval;
|
|
2969
|
|
2970 while ((rtnval = fclose (stream)) == EOF
|
|
2971 && (errno == EINTR))
|
|
2972 ;
|
|
2973 return rtnval;
|
|
2974 #else
|
|
2975 return fclose (stream);
|
|
2976 #endif
|
|
2977 }
|
|
2978 #endif /* ENCAPSULATE_FCLOSE */
|
|
2979
|
16
|
2980
|
0
|
2981 #ifdef ENCAPSULATE_FREAD
|
|
2982 size_t
|
|
2983 sys_fread (void *ptr, size_t size, size_t nitem, FILE *stream)
|
|
2984 {
|
|
2985 #ifdef INTERRUPTIBLE_IO
|
|
2986 size_t rtnval;
|
|
2987 size_t items_read = 0;
|
|
2988 char *b = (char *) ptr;
|
|
2989
|
|
2990 while (nitem > 0)
|
|
2991 {
|
|
2992 rtnval = fread (b, size, nitem, stream);
|
|
2993 if (rtnval == 0)
|
|
2994 {
|
|
2995 if (ferror (stream) && errno == EINTR)
|
|
2996 continue;
|
|
2997 else
|
|
2998 return items_read;
|
|
2999 }
|
|
3000 b += size*rtnval;
|
|
3001 nitem -= rtnval;
|
|
3002 items_read += rtnval;
|
|
3003 }
|
|
3004 return (items_read);
|
|
3005 #else
|
|
3006 return fread (ptr, size, nitem, stream);
|
|
3007 #endif
|
|
3008 }
|
|
3009 #endif /* ENCAPSULATE_FREAD */
|
|
3010
|
16
|
3011
|
0
|
3012 #ifdef ENCAPSULATE_FWRITE
|
|
3013 size_t
|
|
3014 sys_fwrite (CONST void *ptr, size_t size, size_t nitem, FILE *stream)
|
|
3015 {
|
|
3016 #ifdef INTERRUPTIBLE_IO
|
|
3017 size_t rtnval;
|
|
3018 size_t items_written = 0;
|
|
3019 CONST char *b = (CONST char *) ptr;
|
|
3020
|
|
3021 while (nitem > 0)
|
|
3022 {
|
|
3023 rtnval = fwrite (b, size, nitem, stream);
|
|
3024 if (rtnval == 0)
|
|
3025 {
|
|
3026 if (ferror (stream) && errno == EINTR)
|
|
3027 continue;
|
|
3028 else
|
|
3029 return items_written;
|
|
3030 }
|
|
3031 b += size*rtnval;
|
|
3032 nitem -= rtnval;
|
|
3033 items_written += rtnval;
|
|
3034 }
|
|
3035 return (items_written);
|
|
3036 #elif defined (VMS)
|
|
3037 return vms_fwrite (ptr, size, nitem, stream);
|
|
3038 #else
|
|
3039 return fwrite (ptr, size, nitem, stream);
|
|
3040 #endif
|
|
3041 }
|
|
3042 #endif /* ENCAPSULATE_FWRITE */
|
|
3043
|
|
3044
|
|
3045 /********************* directory calls *******************/
|
|
3046
|
|
3047 #ifdef ENCAPSULATE_CHDIR
|
|
3048 int
|
|
3049 sys_chdir (CONST char *path)
|
|
3050 {
|
|
3051 PATHNAME_CONVERT_OUT (path);
|
|
3052 #ifdef MSDOS
|
|
3053 return dos_chdir (path);
|
|
3054 #else
|
|
3055 return chdir (path);
|
|
3056 #endif
|
|
3057 }
|
|
3058 #endif /* ENCAPSULATE_CHDIR */
|
|
3059
|
16
|
3060
|
0
|
3061 #ifdef ENCAPSULATE_MKDIR
|
|
3062 int
|
|
3063 sys_mkdir (CONST char *path, int mode)
|
|
3064 {
|
|
3065 PATHNAME_CONVERT_OUT (path);
|
|
3066 return mkdir (path, mode);
|
|
3067 }
|
|
3068 #endif /* ENCAPSULATE_MKDIR */
|
|
3069
|
16
|
3070
|
0
|
3071 #ifdef ENCAPSULATE_OPENDIR
|
|
3072 DIR *
|
|
3073 sys_opendir (CONST char *filename)
|
|
3074 {
|
|
3075 DIR *rtnval;
|
|
3076 PATHNAME_CONVERT_OUT (filename);
|
|
3077
|
|
3078 while (!(rtnval = opendir (filename))
|
|
3079 && (errno == EINTR))
|
|
3080 ;
|
|
3081 return rtnval;
|
|
3082 }
|
|
3083 #endif /* ENCAPSULATE_OPENDIR */
|
|
3084
|
16
|
3085
|
0
|
3086 #ifdef ENCAPSULATE_READDIR
|
|
3087 DIRENTRY *
|
|
3088 sys_readdir (DIR *dirp)
|
185
|
3089 {
|
0
|
3090 DIRENTRY *rtnval;
|
|
3091
|
|
3092 /* Apparently setting errno is necessary on some systems?
|
|
3093 Maybe readdir() doesn't always set errno ?! */
|
|
3094 while (!(errno = 0, rtnval = readdir (dirp))
|
|
3095 && (errno == EINTR))
|
|
3096 ;
|
70
|
3097 #ifndef MULE
|
0
|
3098 return rtnval;
|
70
|
3099 #else /* MULE */
|
|
3100 if (rtnval == NULL) /* End of directory */
|
|
3101 return NULL;
|
|
3102 {
|
|
3103 Extcount external_len;
|
|
3104 int ascii_filename_p = 1;
|
|
3105 CONST Extbyte * CONST external_name = (CONST Extbyte *) rtnval->d_name;
|
185
|
3106
|
70
|
3107 /* Optimize for the common all-ASCII case, computing len en passant */
|
|
3108 for (external_len = 0; external_name[external_len] ; external_len++)
|
|
3109 {
|
|
3110 if (!BYTE_ASCII_P (external_name[external_len]))
|
|
3111 ascii_filename_p = 0;
|
|
3112 }
|
|
3113 if (ascii_filename_p)
|
|
3114 return rtnval;
|
|
3115
|
|
3116 { /* Non-ASCII filename */
|
185
|
3117 static Bufbyte_dynarr *internal_DIRENTRY;
|
70
|
3118 CONST Bufbyte *internal_name;
|
|
3119 Bytecount internal_len;
|
|
3120 if (!internal_DIRENTRY)
|
|
3121 internal_DIRENTRY = Dynarr_new (Bufbyte);
|
|
3122 else
|
|
3123 Dynarr_reset (internal_DIRENTRY);
|
|
3124
|
|
3125 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval,
|
|
3126 offsetof (DIRENTRY, d_name));
|
|
3127
|
|
3128 internal_name =
|
|
3129 convert_from_external_format (external_name, external_len,
|
|
3130 &internal_len, FORMAT_FILENAME);
|
|
3131
|
|
3132 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len);
|
|
3133 Dynarr_add (internal_DIRENTRY, 0); /* zero-terminate */
|
|
3134 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0);
|
|
3135 }
|
|
3136 }
|
|
3137 #endif /* MULE */
|
0
|
3138 }
|
|
3139 #endif /* ENCAPSULATE_READDIR */
|
|
3140
|
16
|
3141
|
0
|
3142 #ifdef ENCAPSULATE_CLOSEDIR
|
|
3143 int
|
|
3144 sys_closedir (DIR *dirp)
|
|
3145 {
|
|
3146 int rtnval;
|
|
3147
|
|
3148 while ((rtnval = closedir (dirp)) == -1
|
|
3149 && (errno == EINTR))
|
|
3150 ;
|
|
3151 return rtnval;
|
|
3152 }
|
|
3153 #endif /* ENCAPSULATE_CLOSEDIR */
|
|
3154
|
16
|
3155
|
0
|
3156 #ifdef ENCAPSULATE_RMDIR
|
|
3157 int
|
|
3158 sys_rmdir (CONST char *path)
|
|
3159 {
|
|
3160 PATHNAME_CONVERT_OUT (path);
|
|
3161 return rmdir (path);
|
|
3162 }
|
|
3163 #endif /* ENCAPSULATE_RMDIR */
|
|
3164
|
|
3165
|
|
3166 /***************** file-information calls ******************/
|
|
3167
|
|
3168 #ifdef ENCAPSULATE_ACCESS
|
|
3169 int
|
|
3170 sys_access (CONST char *path, int mode)
|
|
3171 {
|
|
3172 PATHNAME_CONVERT_OUT (path);
|
|
3173 #ifdef VMS
|
|
3174 return vms_access (path, mode);
|
|
3175 #else
|
|
3176 return access (path, mode);
|
|
3177 #endif
|
|
3178 }
|
|
3179 #endif /* ENCAPSULATE_ACCESS */
|
|
3180
|
16
|
3181
|
2
|
3182 #ifdef HAVE_EACCESS
|
|
3183 #ifdef ENCAPSULATE_EACCESS
|
|
3184 int
|
|
3185 sys_eaccess (CONST char *path, int mode)
|
|
3186 {
|
|
3187 PATHNAME_CONVERT_OUT (path);
|
|
3188 return eaccess (path, mode);
|
|
3189 }
|
|
3190 #endif /* ENCAPSULATE_EACCESS */
|
|
3191 #endif /* HAVE_EACCESS */
|
|
3192
|
|
3193
|
0
|
3194 #ifdef ENCAPSULATE_LSTAT
|
|
3195 int
|
|
3196 sys_lstat (CONST char *path, struct stat *buf)
|
|
3197 {
|
|
3198 PATHNAME_CONVERT_OUT (path);
|
|
3199 return lstat (path, buf);
|
|
3200 }
|
|
3201 #endif /* ENCAPSULATE_LSTAT */
|
|
3202
|
16
|
3203
|
0
|
3204 #ifdef ENCAPSULATE_READLINK
|
|
3205 int
|
|
3206 sys_readlink (CONST char *path, char *buf, int bufsiz)
|
|
3207 {
|
|
3208 PATHNAME_CONVERT_OUT (path);
|
|
3209 /* #### currently we don't do conversions on the incoming data */
|
|
3210 return readlink (path, buf, bufsiz);
|
|
3211 }
|
|
3212 #endif /* ENCAPSULATE_READLINK */
|
|
3213
|
16
|
3214
|
0
|
3215 #ifdef ENCAPSULATE_STAT
|
|
3216 int
|
|
3217 sys_stat (CONST char *path, struct stat *buf)
|
|
3218 {
|
|
3219 PATHNAME_CONVERT_OUT (path);
|
|
3220 return stat (path, buf);
|
|
3221 }
|
|
3222 #endif /* ENCAPSULATE_STAT */
|
|
3223
|
|
3224
|
|
3225 /****************** file-manipulation calls *****************/
|
|
3226
|
|
3227 #ifdef ENCAPSULATE_CHMOD
|
|
3228 int
|
|
3229 sys_chmod (CONST char *path, int mode)
|
|
3230 {
|
|
3231 PATHNAME_CONVERT_OUT (path);
|
|
3232 return chmod (path, mode);
|
|
3233 }
|
|
3234 #endif /* ENCAPSULATE_CHMOD */
|
|
3235
|
16
|
3236
|
0
|
3237 #ifdef ENCAPSULATE_CREAT
|
|
3238 int
|
|
3239 sys_creat (CONST char *path, int mode)
|
|
3240 {
|
|
3241 PATHNAME_CONVERT_OUT (path);
|
|
3242 return creat (path, mode);
|
|
3243 }
|
|
3244 #endif /* ENCAPSULATE_CREAT */
|
|
3245
|
16
|
3246
|
0
|
3247 #ifdef ENCAPSULATE_LINK
|
|
3248 int
|
|
3249 sys_link (CONST char *existing, CONST char *new)
|
|
3250 {
|
|
3251 PATHNAME_CONVERT_OUT (existing);
|
|
3252 PATHNAME_CONVERT_OUT (new);
|
|
3253 return link (existing, new);
|
|
3254 }
|
|
3255 #endif /* ENCAPSULATE_LINK */
|
|
3256
|
16
|
3257
|
0
|
3258 #ifdef ENCAPSULATE_RENAME
|
|
3259 int
|
|
3260 sys_rename (CONST char *old, CONST char *new)
|
|
3261 {
|
|
3262 PATHNAME_CONVERT_OUT (old);
|
|
3263 PATHNAME_CONVERT_OUT (new);
|
|
3264 return rename (old, new);
|
|
3265 }
|
|
3266 #endif /* ENCAPSULATE_RENAME */
|
|
3267
|
16
|
3268
|
0
|
3269 #ifdef ENCAPSULATE_SYMLINK
|
|
3270 int
|
|
3271 sys_symlink (CONST char *name1, CONST char *name2)
|
|
3272 {
|
|
3273 PATHNAME_CONVERT_OUT (name1);
|
|
3274 PATHNAME_CONVERT_OUT (name2);
|
|
3275 return symlink (name1, name2);
|
|
3276 }
|
|
3277 #endif /* ENCAPSULATE_SYMLINK */
|
|
3278
|
16
|
3279
|
0
|
3280 #ifdef ENCAPSULATE_UNLINK
|
|
3281 int
|
|
3282 sys_unlink (CONST char *path)
|
|
3283 {
|
|
3284 PATHNAME_CONVERT_OUT (path);
|
|
3285 return unlink (path);
|
|
3286 }
|
|
3287 #endif /* ENCAPSULATE_UNLINK */
|
|
3288
|
16
|
3289
|
|
3290 #ifdef ENCAPSULATE_EXECVP
|
|
3291 int
|
82
|
3292 sys_execvp (CONST char *path, char * CONST * argv)
|
16
|
3293 {
|
82
|
3294 int i, argc;
|
|
3295 CONST char ** new_argv;
|
185
|
3296
|
16
|
3297 PATHNAME_CONVERT_OUT (path);
|
82
|
3298 for (argc = 0; argv[argc]; argc++)
|
|
3299 ;
|
185
|
3300 new_argv = alloca_array (CONST char *, argc + 1);
|
82
|
3301 for (i = 0; i < argc; i++)
|
|
3302 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (argv[i], new_argv[i]);
|
|
3303 new_argv[argc] = NULL;
|
|
3304 return execvp (path, (char **) new_argv);
|
16
|
3305 }
|
|
3306 #endif /* ENCAPSULATE_EXECVP */
|
|
3307
|
0
|
3308
|
|
3309 /************************************************************************/
|
|
3310 /* Emulations of missing system calls */
|
|
3311 /************************************************************************/
|
|
3312
|
|
3313 /***** (these are primarily required for USG, it seems) *****/
|
|
3314
|
163
|
3315 #ifndef HAVE_GETCWD
|
|
3316 char *
|
|
3317 getcwd (char *pathname, int size)
|
|
3318 {
|
|
3319 return getwd (pathname);
|
|
3320 }
|
|
3321 #endif /* emulate getcwd */
|
|
3322
|
|
3323
|
|
3324 #if 0 /* mrb */
|
0
|
3325 /*
|
16
|
3326 * Warning, this function may not duplicate BSD 4.2 action properly
|
0
|
3327 * under error conditions.
|
|
3328 */
|
|
3329
|
|
3330 #ifndef HAVE_GETWD
|
|
3331 char *
|
|
3332 getwd (char *pathname)
|
|
3333 {
|
|
3334 char *npath, *spath;
|
|
3335 #if !__STDC__ && !defined(STDC_HEADERS)
|
|
3336 extern char *getcwd ();
|
|
3337 #endif
|
|
3338
|
|
3339 spath = npath = getcwd ((char *) 0, MAXPATHLEN);
|
|
3340 if (spath == 0)
|
|
3341 return spath;
|
|
3342 /* On Altos 3068, getcwd can return @hostname/dir, so discard
|
|
3343 up to first slash. Should be harmless on other systems. */
|
|
3344 while (*npath && *npath != '/')
|
|
3345 npath++;
|
|
3346 strcpy (pathname, npath);
|
|
3347 xfree (spath); /* getcwd uses malloc */
|
|
3348 return pathname;
|
|
3349 }
|
|
3350 #endif /* HAVE_GETWD */
|
163
|
3351 #endif /* 0 - mrb */
|
0
|
3352
|
|
3353 /*
|
|
3354 * Emulate rename using unlink/link. Note that this is
|
|
3355 * only partially correct. Also, doesn't enforce restriction
|
|
3356 * that files be of same type (regular->regular, dir->dir, etc).
|
|
3357 */
|
|
3358
|
|
3359 #ifndef HAVE_RENAME
|
|
3360 int
|
|
3361 rename (CONST char *from, CONST char *to)
|
|
3362 {
|
|
3363 if (access (from, 0) == 0)
|
|
3364 {
|
|
3365 unlink (to);
|
|
3366 if (link (from, to) == 0)
|
|
3367 if (unlink (from) == 0)
|
|
3368 return (0);
|
|
3369 }
|
|
3370 return (-1);
|
|
3371 }
|
16
|
3372 #endif /* HAVE_RENAME */
|
0
|
3373
|
|
3374 #ifdef HPUX
|
|
3375 #ifndef HAVE_PERROR
|
|
3376
|
|
3377 /* HPUX curses library references perror, but as far as we know
|
|
3378 it won't be called. Anyway this definition will do for now. */
|
|
3379
|
|
3380 perror (void)
|
|
3381 {
|
|
3382 }
|
|
3383
|
|
3384 #endif /* not HAVE_PERROR */
|
|
3385 #endif /* HPUX */
|
|
3386
|
|
3387 #ifndef HAVE_DUP2
|
|
3388
|
|
3389 /*
|
|
3390 * Emulate BSD dup2. First close newd if it already exists.
|
|
3391 * Then, attempt to dup oldd. If not successful, call dup2 recursively
|
|
3392 * until we are, then close the unsuccessful ones.
|
|
3393 */
|
|
3394
|
|
3395 int
|
|
3396 dup2 (int oldd, int newd)
|
|
3397 {
|
|
3398 int fd, ret;
|
185
|
3399
|
0
|
3400 sys_close (newd);
|
|
3401
|
|
3402 #ifdef F_DUPFD
|
|
3403 fd = fcntl (oldd, F_DUPFD, newd);
|
|
3404 if (fd != newd)
|
|
3405 error ("can't dup2 (%i,%i) : %s", oldd, newd, strerror (errno));
|
|
3406 #else
|
|
3407 fd = dup (old);
|
|
3408 if (fd == -1)
|
|
3409 return -1;
|
|
3410 if (fd == new)
|
|
3411 return new;
|
|
3412 ret = dup2 (old, new);
|
|
3413 sys_close (fd);
|
|
3414 return ret;
|
|
3415 #endif /* F_DUPFD */
|
|
3416 }
|
|
3417
|
|
3418 #endif /* not HAVE_DUP2 */
|
|
3419
|
|
3420 /*
|
|
3421 * Gettimeofday. Simulate as much as possible. Only accurate
|
|
3422 * to nearest second. Emacs doesn't use tzp so ignore it for now.
|
|
3423 */
|
|
3424
|
|
3425 #if !defined (HAVE_GETTIMEOFDAY)
|
185
|
3426
|
0
|
3427 int
|
|
3428 gettimeofday (struct timeval *tp, struct timezone *tzp)
|
|
3429 {
|
|
3430 extern long time ();
|
|
3431
|
185
|
3432 tp->tv_sec = time ((long *)0);
|
0
|
3433 tp->tv_usec = 0;
|
|
3434 if (tzp != 0)
|
|
3435 tzp->tz_minuteswest = -1;
|
|
3436 return (0);
|
|
3437 }
|
185
|
3438
|
0
|
3439 #endif /* !HAVE_GETTIMEOFDAY */
|
185
|
3440
|
0
|
3441 /* No need to encapsulate utime and utimes explicitly because all
|
|
3442 access to those functions goes through the following. */
|
|
3443
|
|
3444 int
|
|
3445 set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime)
|
|
3446 {
|
|
3447 #ifdef HAVE_UTIMES
|
|
3448 struct timeval tv[2];
|
|
3449 tv[0] = atime;
|
|
3450 tv[1] = mtime;
|
|
3451 return utimes (filename, tv);
|
|
3452 #else /* not HAVE_UTIMES */
|
|
3453 struct utimbuf utb;
|
|
3454 utb.actime = EMACS_SECS (atime);
|
|
3455 utb.modtime = EMACS_SECS (mtime);
|
|
3456 return utime (filename, &utb);
|
|
3457 #endif /* not HAVE_UTIMES */
|
|
3458 }
|
|
3459
|
|
3460 /* */
|
|
3461
|
|
3462 static long ticks_per_second;
|
|
3463 static long orig_user_ticks, orig_system_ticks;
|
|
3464 EMACS_TIME orig_real_time;
|
|
3465
|
|
3466 static int process_times_available;
|
|
3467
|
|
3468 /* Return the relative user and system tick count. We try to
|
|
3469 maintain calculations in terms of integers as long as possible
|
|
3470 for increased accuracy. */
|
|
3471
|
|
3472 static int
|
|
3473 get_process_times_1 (long *user_ticks, long *system_ticks)
|
|
3474 {
|
100
|
3475 #if defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WINDOWSNT)
|
0
|
3476 /* We have the POSIX times() function available. */
|
|
3477 struct tms tttt;
|
|
3478 times (&tttt);
|
|
3479 *user_ticks = (long) tttt.tms_utime;
|
|
3480 *system_ticks = (long) tttt.tms_stime;
|
|
3481 return 1;
|
|
3482 #elif defined (CLOCKS_PER_SEC)
|
100
|
3483 *user_ticks = (long) clock ();
|
|
3484 *system_ticks = 0;
|
0
|
3485 return 1;
|
|
3486 #else
|
|
3487 return 0;
|
|
3488 #endif
|
|
3489 }
|
|
3490
|
|
3491 void
|
|
3492 init_process_times_very_early (void)
|
|
3493 {
|
|
3494 #if defined (_SC_CLK_TCK)
|
|
3495 ticks_per_second = sysconf (_SC_CLK_TCK);
|
|
3496 #elif defined (CLK_TCK)
|
|
3497 ticks_per_second = CLK_TCK;
|
|
3498 #elif defined (CLOCKS_PER_SEC)
|
|
3499 ticks_per_second = CLOCKS_PER_SEC;
|
|
3500 #endif
|
|
3501
|
|
3502 process_times_available = get_process_times_1 (&orig_user_ticks,
|
|
3503 &orig_system_ticks);
|
|
3504 EMACS_GET_TIME (orig_real_time);
|
|
3505 }
|
|
3506
|
|
3507 /* Return the user and system times used up by this process so far. */
|
|
3508 void
|
|
3509 get_process_times (double *user_time, double *system_time, double *real_time)
|
|
3510 {
|
|
3511 EMACS_TIME curr_real_time;
|
|
3512 EMACS_TIME elapsed_time;
|
|
3513 long curr_user_ticks, curr_system_ticks;
|
|
3514
|
|
3515 EMACS_GET_TIME (curr_real_time);
|
|
3516 EMACS_SUB_TIME (elapsed_time, curr_real_time, orig_real_time);
|
|
3517 *real_time = (EMACS_SECS (elapsed_time)
|
|
3518 + ((double) EMACS_USECS (elapsed_time)) / 1000000);
|
|
3519 if (get_process_times_1 (&curr_user_ticks, &curr_system_ticks))
|
|
3520 {
|
|
3521 *user_time = (((double) (curr_user_ticks - orig_user_ticks))
|
|
3522 / ticks_per_second);
|
|
3523 *system_time = (((double) (curr_system_ticks - orig_system_ticks))
|
|
3524 / ticks_per_second);
|
|
3525 }
|
|
3526 else
|
|
3527 {
|
|
3528 /* MS-DOS or equally lame OS */
|
|
3529 *user_time = *real_time;
|
|
3530 *system_time = 0;
|
|
3531 }
|
|
3532 }
|
|
3533
|
|
3534 #ifndef HAVE_RANDOM
|
|
3535 #ifdef random
|
|
3536 #define HAVE_RANDOM
|
|
3537 #endif
|
|
3538 #endif
|
|
3539
|
|
3540 /* Figure out how many bits the system's random number generator uses.
|
|
3541 `random' and `lrand48' are assumed to return 31 usable bits.
|
|
3542 BSD `rand' returns a 31 bit value but the low order bits are unusable;
|
|
3543 so we'll shift it and treat it like the 15-bit USG `rand'. */
|
|
3544
|
|
3545 #ifndef RAND_BITS
|
|
3546 # ifdef HAVE_RANDOM
|
|
3547 # define RAND_BITS 31
|
|
3548 # else /* !HAVE_RANDOM */
|
|
3549 # ifdef HAVE_LRAND48
|
|
3550 # define RAND_BITS 31
|
|
3551 # define random lrand48
|
|
3552 # else /* !HAVE_LRAND48 */
|
|
3553 # define RAND_BITS 15
|
|
3554 # if RAND_MAX == 32767
|
|
3555 # define random rand
|
|
3556 # else /* RAND_MAX != 32767 */
|
|
3557 # if RAND_MAX == 2147483647
|
|
3558 # define random() (rand () >> 16)
|
|
3559 # else /* RAND_MAX != 2147483647 */
|
|
3560 # ifdef USG
|
|
3561 # define random rand
|
|
3562 # else
|
|
3563 # define random() (rand () >> 16)
|
|
3564 # endif /* !BSD */
|
|
3565 # endif /* RAND_MAX != 2147483647 */
|
|
3566 # endif /* RAND_MAX != 32767 */
|
|
3567 # endif /* !HAVE_LRAND48 */
|
|
3568 # endif /* !HAVE_RANDOM */
|
|
3569 #endif /* !RAND_BITS */
|
|
3570
|
|
3571 void seed_random (long arg);
|
|
3572 void
|
|
3573 seed_random (long arg)
|
|
3574 {
|
|
3575 #ifdef HAVE_RANDOM
|
|
3576 srandom ((unsigned int)arg);
|
|
3577 #else
|
|
3578 # ifdef HAVE_LRAND48
|
|
3579 srand48 (arg);
|
|
3580 # else
|
|
3581 srand ((unsigned int)arg);
|
|
3582 # endif
|
|
3583 #endif
|
|
3584 }
|
|
3585
|
|
3586 /*
|
|
3587 * Build a full Emacs-sized word out of whatever we've got.
|
|
3588 * This suffices even for a 64-bit architecture with a 15-bit rand.
|
|
3589 */
|
|
3590 long get_random (void);
|
|
3591 long
|
|
3592 get_random (void)
|
|
3593 {
|
|
3594 long val = random ();
|
|
3595 #if VALBITS > RAND_BITS
|
|
3596 val = (val << RAND_BITS) ^ random ();
|
|
3597 #if VALBITS > 2*RAND_BITS
|
|
3598 val = (val << RAND_BITS) ^ random ();
|
|
3599 #if VALBITS > 3*RAND_BITS
|
|
3600 val = (val << RAND_BITS) ^ random ();
|
|
3601 #if VALBITS > 4*RAND_BITS
|
|
3602 val = (val << RAND_BITS) ^ random ();
|
|
3603 #endif /* need at least 5 */
|
|
3604 #endif /* need at least 4 */
|
|
3605 #endif /* need at least 3 */
|
|
3606 #endif /* need at least 2 */
|
|
3607 return val & ((1L << VALBITS) - 1);
|
|
3608 }
|
|
3609
|
|
3610 #ifdef WRONG_NAME_INSQUE
|
|
3611
|
|
3612 void
|
|
3613 insque (caddr_t q, caddr_t p)
|
|
3614 {
|
|
3615 _insque (q,p);
|
|
3616 }
|
|
3617
|
|
3618 #endif
|
|
3619
|
|
3620
|
|
3621 /************************************************************************/
|
|
3622 /* Strings corresponding to defined signals */
|
|
3623 /************************************************************************/
|
|
3624
|
|
3625 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST)
|
|
3626
|
100
|
3627 #ifdef WINDOWSNT
|
|
3628 char *sys_siglist[] =
|
|
3629 {
|
|
3630 "bum signal!!",
|
|
3631 "hangup",
|
|
3632 "interrupt",
|
|
3633 "quit",
|
|
3634 "illegal instruction",
|
|
3635 "trace trap",
|
|
3636 "iot instruction",
|
|
3637 "emt instruction",
|
|
3638 "floating point exception",
|
|
3639 "kill",
|
|
3640 "bus error",
|
|
3641 "segmentation violation",
|
|
3642 "bad argument to system call",
|
|
3643 "write on a pipe with no one to read it",
|
|
3644 "alarm clock",
|
|
3645 "software termination signal from kill",
|
|
3646 "status signal",
|
|
3647 "sendable stop signal not from tty",
|
|
3648 "stop signal from tty",
|
|
3649 "continue a stopped process",
|
|
3650 "child status has changed",
|
|
3651 "background read attempted from control tty",
|
|
3652 "background write attempted from control tty",
|
|
3653 "input record available at control tty",
|
|
3654 "exceeded CPU time limit",
|
|
3655 "exceeded file size limit"
|
|
3656 };
|
|
3657 #endif
|
|
3658
|
0
|
3659 #ifdef USG
|
|
3660 #ifdef AIX
|
|
3661 CONST char *sys_siglist[NSIG + 1] =
|
|
3662 {
|
|
3663 /* AIX has changed the signals a bit */
|
|
3664 DEFER_GETTEXT ("bogus signal"), /* 0 */
|
|
3665 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
|
|
3666 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
|
|
3667 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
|
|
3668 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
|
|
3669 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
|
|
3670 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
|
|
3671 DEFER_GETTEXT ("crash likely"), /* 7 SIGDANGER */
|
|
3672 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
|
|
3673 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
|
|
3674 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
|
|
3675 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
|
|
3676 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
|
|
3677 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
|
|
3678 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
|
|
3679 DEFER_GETTEXT ("software termination signum"), /* 15 SIGTERM */
|
|
3680 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
|
|
3681 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
|
|
3682 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
|
|
3683 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
|
|
3684 DEFER_GETTEXT ("bogus signal"), /* 20 */
|
|
3685 DEFER_GETTEXT ("bogus signal"), /* 21 */
|
|
3686 DEFER_GETTEXT ("bogus signal"), /* 22 */
|
|
3687 DEFER_GETTEXT ("bogus signal"), /* 23 */
|
|
3688 DEFER_GETTEXT ("bogus signal"), /* 24 */
|
|
3689 DEFER_GETTEXT ("LAN I/O interrupt"), /* 25 SIGAIO */
|
|
3690 DEFER_GETTEXT ("PTY I/O interrupt"), /* 26 SIGPTY */
|
|
3691 DEFER_GETTEXT ("I/O intervention required"), /* 27 SIGIOINT */
|
|
3692 #ifdef AIXHFT
|
|
3693 DEFER_GETTEXT ("HFT grant"), /* 28 SIGGRANT */
|
|
3694 DEFER_GETTEXT ("HFT retract"), /* 29 SIGRETRACT */
|
|
3695 DEFER_GETTEXT ("HFT sound done"), /* 30 SIGSOUND */
|
|
3696 DEFER_GETTEXT ("HFT input ready"), /* 31 SIGMSG */
|
|
3697 #endif
|
|
3698 0
|
|
3699 };
|
|
3700 #else /* USG, not AIX */
|
|
3701 CONST char *sys_siglist[NSIG + 1] =
|
|
3702 {
|
|
3703 DEFER_GETTEXT ("bogus signal"), /* 0 */
|
|
3704 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
|
|
3705 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
|
|
3706 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
|
|
3707 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
|
|
3708 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
|
|
3709 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
|
|
3710 DEFER_GETTEXT ("EMT instruction"), /* 7 SIGEMT */
|
|
3711 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
|
|
3712 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
|
|
3713 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
|
|
3714 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
|
|
3715 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
|
|
3716 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
|
|
3717 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
|
|
3718 DEFER_GETTEXT ("software termination signum"), /* 15 SIGTERM */
|
|
3719 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
|
|
3720 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
|
|
3721 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
|
|
3722 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
|
|
3723 #ifdef sun
|
|
3724 DEFER_GETTEXT ("window size changed"), /* 20 SIGWINCH */
|
|
3725 DEFER_GETTEXT ("urgent socket condition"), /* 21 SIGURG */
|
|
3726 DEFER_GETTEXT ("pollable event occurred"), /* 22 SIGPOLL */
|
|
3727 DEFER_GETTEXT ("stop (cannot be caught or ignored)"), /* 23 SIGSTOP */
|
|
3728 DEFER_GETTEXT ("user stop requested from tty"), /* 24 SIGTSTP */
|
|
3729 DEFER_GETTEXT ("stopped process has been continued"), /* 25 SIGCONT */
|
|
3730 DEFER_GETTEXT ("background tty read attempted"), /* 26 SIGTTIN */
|
|
3731 DEFER_GETTEXT ("background tty write attempted"), /* 27 SIGTTOU */
|
|
3732 DEFER_GETTEXT ("virtual timer expired"), /* 28 SIGVTALRM */
|
|
3733 DEFER_GETTEXT ("profiling timer expired"), /* 29 SIGPROF */
|
|
3734 DEFER_GETTEXT ("exceeded cpu limit"), /* 30 SIGXCPU */
|
|
3735 DEFER_GETTEXT ("exceeded file size limit"), /* 31 SIGXFSZ */
|
|
3736 DEFER_GETTEXT ("process's lwps are blocked"), /* 32 SIGWAITING */
|
|
3737 DEFER_GETTEXT ("special signal used by thread library"), /* 33 SIGLWP */
|
|
3738 #ifdef SIGFREEZE
|
|
3739 DEFER_GETTEXT ("special signal used by CPR"), /* 34 SIGFREEZE */
|
|
3740 #endif
|
|
3741 #ifdef SIGTHAW
|
|
3742 DEFER_GETTEXT ("special signal used by CPR"), /* 35 SIGTHAW */
|
|
3743 #endif
|
|
3744 #endif /* sun */
|
|
3745 0
|
|
3746 };
|
|
3747 #endif /* not AIX */
|
|
3748 #endif /* USG */
|
|
3749 #ifdef DGUX
|
|
3750 CONST char *sys_siglist[NSIG + 1] =
|
|
3751 {
|
|
3752 DEFER_GETTEXT ("null signal"), /* 0 SIGNULL */
|
|
3753 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
|
|
3754 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
|
|
3755 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
|
|
3756 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
|
|
3757 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
|
|
3758 DEFER_GETTEXT ("abort termination"), /* 6 SIGABRT */
|
|
3759 DEFER_GETTEXT ("SIGEMT"), /* 7 SIGEMT */
|
|
3760 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
|
|
3761 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
|
|
3762 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
|
|
3763 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
|
|
3764 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
|
|
3765 DEFER_GETTEXT ("write on a pipe with no reader"), /* 13 SIGPIPE */
|
|
3766 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
|
|
3767 DEFER_GETTEXT ("software termination signal"), /* 15 SIGTERM */
|
|
3768 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
|
|
3769 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
|
|
3770 DEFER_GETTEXT ("child stopped or terminated"), /* 18 SIGCLD */
|
|
3771 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
|
|
3772 DEFER_GETTEXT ("window size changed"), /* 20 SIGWINCH */
|
|
3773 DEFER_GETTEXT ("undefined"), /* 21 */
|
|
3774 DEFER_GETTEXT ("pollable event occurred"), /* 22 SIGPOLL */
|
|
3775 DEFER_GETTEXT ("sendable stop signal not from tty"), /* 23 SIGSTOP */
|
|
3776 DEFER_GETTEXT ("stop signal from tty"), /* 24 SIGSTP */
|
|
3777 DEFER_GETTEXT ("continue a stopped process"), /* 25 SIGCONT */
|
|
3778 DEFER_GETTEXT ("attempted background tty read"), /* 26 SIGTTIN */
|
|
3779 DEFER_GETTEXT ("attempted background tty write"), /* 27 SIGTTOU */
|
|
3780 DEFER_GETTEXT ("undefined"), /* 28 */
|
|
3781 DEFER_GETTEXT ("undefined"), /* 29 */
|
|
3782 DEFER_GETTEXT ("undefined"), /* 30 */
|
|
3783 DEFER_GETTEXT ("undefined"), /* 31 */
|
|
3784 DEFER_GETTEXT ("undefined"), /* 32 */
|
|
3785 DEFER_GETTEXT ("socket (TCP/IP) urgent data arrival"), /* 33 SIGURG */
|
|
3786 DEFER_GETTEXT ("I/O is possible"), /* 34 SIGIO */
|
|
3787 DEFER_GETTEXT ("exceeded cpu time limit"), /* 35 SIGXCPU */
|
|
3788 DEFER_GETTEXT ("exceeded file size limit"), /* 36 SIGXFSZ */
|
|
3789 DEFER_GETTEXT ("virtual time alarm"), /* 37 SIGVTALRM */
|
|
3790 DEFER_GETTEXT ("profiling time alarm"), /* 38 SIGPROF */
|
|
3791 DEFER_GETTEXT ("undefined"), /* 39 */
|
|
3792 DEFER_GETTEXT ("file record locks revoked"), /* 40 SIGLOST */
|
|
3793 DEFER_GETTEXT ("undefined"), /* 41 */
|
|
3794 DEFER_GETTEXT ("undefined"), /* 42 */
|
|
3795 DEFER_GETTEXT ("undefined"), /* 43 */
|
|
3796 DEFER_GETTEXT ("undefined"), /* 44 */
|
|
3797 DEFER_GETTEXT ("undefined"), /* 45 */
|
|
3798 DEFER_GETTEXT ("undefined"), /* 46 */
|
|
3799 DEFER_GETTEXT ("undefined"), /* 47 */
|
|
3800 DEFER_GETTEXT ("undefined"), /* 48 */
|
|
3801 DEFER_GETTEXT ("undefined"), /* 49 */
|
|
3802 DEFER_GETTEXT ("undefined"), /* 50 */
|
|
3803 DEFER_GETTEXT ("undefined"), /* 51 */
|
|
3804 DEFER_GETTEXT ("undefined"), /* 52 */
|
|
3805 DEFER_GETTEXT ("undefined"), /* 53 */
|
|
3806 DEFER_GETTEXT ("undefined"), /* 54 */
|
|
3807 DEFER_GETTEXT ("undefined"), /* 55 */
|
|
3808 DEFER_GETTEXT ("undefined"), /* 56 */
|
|
3809 DEFER_GETTEXT ("undefined"), /* 57 */
|
|
3810 DEFER_GETTEXT ("undefined"), /* 58 */
|
|
3811 DEFER_GETTEXT ("undefined"), /* 59 */
|
|
3812 DEFER_GETTEXT ("undefined"), /* 60 */
|
|
3813 DEFER_GETTEXT ("undefined"), /* 61 */
|
|
3814 DEFER_GETTEXT ("undefined"), /* 62 */
|
|
3815 DEFER_GETTEXT ("undefined"), /* 63 */
|
|
3816 DEFER_GETTEXT ("notification message in mess. queue"), /* 64 SIGDGNOTIFY */
|
|
3817 0
|
|
3818 };
|
|
3819 #endif /* DGUX */
|
|
3820
|
|
3821 #endif /* ! SYS_SIGLIST_DECLARED && ! HAVE_SYS_SIGLIST */
|
|
3822
|
|
3823
|
|
3824 /************************************************************************/
|
|
3825 /* Directory routines for systems that don't have them */
|
|
3826 /************************************************************************/
|
|
3827
|
|
3828 #ifdef SYSV_SYSTEM_DIR
|
|
3829
|
|
3830 #include <dirent.h>
|
|
3831
|
|
3832 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
|
|
3833 int
|
|
3834 closedir (DIR *dirp) /* stream from opendir */
|
|
3835 {
|
|
3836 int rtnval;
|
|
3837
|
|
3838 rtnval = sys_close (dirp->dd_fd);
|
|
3839
|
|
3840 /* Some systems (like Solaris) allocate the buffer and the DIR all
|
|
3841 in one block. Why in the world are we freeing this ourselves
|
|
3842 anyway? */
|
|
3843 #if ! (defined (sun) && defined (USG5_4))
|
|
3844 xfree ((char *) dirp->dd_buf); /* directory block defined in <dirent.h> */
|
|
3845 #endif
|
|
3846 xfree ((char *) dirp);
|
|
3847 return (rtnval);
|
|
3848 }
|
|
3849 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
|
|
3850 #endif /* SYSV_SYSTEM_DIR */
|
|
3851
|
|
3852 #ifdef NONSYSTEM_DIR_LIBRARY
|
|
3853
|
|
3854 DIR *
|
|
3855 opendir (CONST char *filename) /* name of directory */
|
|
3856 {
|
|
3857 DIR *dirp; /* -> malloc'ed storage */
|
|
3858 int fd; /* file descriptor for read */
|
|
3859 struct stat sbuf; /* result of fstat */
|
|
3860
|
|
3861 fd = sys_open (filename, 0);
|
|
3862 if (fd < 0)
|
|
3863 return 0;
|
|
3864
|
|
3865 if (fstat (fd, &sbuf) < 0
|
|
3866 || (sbuf.st_mode & S_IFMT) != S_IFDIR
|
|
3867 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
|
|
3868 {
|
|
3869 sys_close (fd);
|
|
3870 return 0; /* bad luck today */
|
|
3871 }
|
|
3872
|
|
3873 dirp->dd_fd = fd;
|
|
3874 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
|
|
3875
|
|
3876 return dirp;
|
|
3877 }
|
|
3878
|
|
3879 void
|
|
3880 closedir (DIR *dirp) /* stream from opendir */
|
|
3881 {
|
|
3882 sys_close (dirp->dd_fd);
|
|
3883 xfree (dirp);
|
|
3884 }
|
|
3885
|
|
3886
|
|
3887 #ifndef VMS
|
|
3888 #define DIRSIZ 14
|
|
3889 struct olddir
|
|
3890 {
|
|
3891 ino_t od_ino; /* inode */
|
|
3892 char od_name[DIRSIZ]; /* filename */
|
|
3893 };
|
|
3894 #endif /* not VMS */
|
|
3895
|
|
3896 static struct direct dir_static; /* simulated directory contents */
|
|
3897
|
|
3898 /* ARGUSED */
|
|
3899 struct direct *
|
|
3900 readdir (DIR *dirp) /* stream from opendir */
|
|
3901 {
|
|
3902 #ifndef VMS
|
|
3903 struct olddir *dp; /* -> directory data */
|
|
3904 #else /* VMS */
|
|
3905 struct dir$_name *dp; /* -> directory data */
|
|
3906 struct dir$_version *dv; /* -> version data */
|
|
3907 #endif /* VMS */
|
|
3908
|
|
3909 for (; ;)
|
|
3910 {
|
|
3911 if (dirp->dd_loc >= dirp->dd_size)
|
|
3912 dirp->dd_loc = dirp->dd_size = 0;
|
|
3913
|
|
3914 if (dirp->dd_size == 0 /* refill buffer */
|
|
3915 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
|
|
3916 return 0;
|
|
3917
|
|
3918 #ifndef VMS
|
|
3919 dp = (struct olddir *) &dirp->dd_buf[dirp->dd_loc];
|
|
3920 dirp->dd_loc += sizeof (struct olddir);
|
|
3921
|
|
3922 if (dp->od_ino != 0) /* not deleted entry */
|
|
3923 {
|
|
3924 dir_static.d_ino = dp->od_ino;
|
|
3925 strncpy (dir_static.d_name, dp->od_name, DIRSIZ);
|
|
3926 dir_static.d_name[DIRSIZ] = '\0';
|
|
3927 dir_static.d_namlen = strlen (dir_static.d_name);
|
|
3928 dir_static.d_reclen = sizeof (struct direct)
|
|
3929 - MAXNAMLEN + 3
|
|
3930 + dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
3931 return &dir_static; /* -> simulated structure */
|
|
3932 }
|
|
3933 #else /* VMS */
|
|
3934 dp = (struct dir$_name *) dirp->dd_buf;
|
|
3935 if (dirp->dd_loc == 0)
|
|
3936 dirp->dd_loc = (dp->dir$b_namecount&1) ? dp->dir$b_namecount + 1
|
|
3937 : dp->dir$b_namecount;
|
|
3938 dv = (struct dir$_version *)&dp->dir$t_name[dirp->dd_loc];
|
|
3939 dir_static.d_ino = dv->dir$w_fid_num;
|
|
3940 dir_static.d_namlen = dp->dir$b_namecount;
|
|
3941 dir_static.d_reclen = sizeof (struct direct)
|
|
3942 - MAXNAMLEN + 3
|
|
3943 + dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
3944 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount);
|
|
3945 dir_static.d_name[dir_static.d_namlen] = '\0';
|
|
3946 dirp->dd_loc = dirp->dd_size; /* only one record at a time */
|
|
3947 return &dir_static;
|
|
3948 #endif /* VMS */
|
|
3949 }
|
|
3950 }
|
|
3951
|
|
3952 #ifdef VMS
|
|
3953 /* readdirver is just like readdir except it returns all versions of a file
|
|
3954 as separate entries. */
|
|
3955
|
|
3956 /* ARGUSED */
|
|
3957 struct direct *
|
|
3958 readdirver (DIR *dirp) /* stream from opendir */
|
|
3959 {
|
|
3960 struct dir$_name *dp; /* -> directory data */
|
|
3961 struct dir$_version *dv; /* -> version data */
|
|
3962
|
|
3963 if (dirp->dd_loc >= dirp->dd_size - sizeof (struct dir$_name))
|
|
3964 dirp->dd_loc = dirp->dd_size = 0;
|
|
3965
|
|
3966 if (dirp->dd_size == 0 /* refill buffer */
|
|
3967 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
|
|
3968 return 0;
|
|
3969
|
|
3970 dp = (struct dir$_name *) dirp->dd_buf;
|
|
3971 if (dirp->dd_loc == 0)
|
|
3972 dirp->dd_loc = (dp->dir$b_namecount & 1) ? dp->dir$b_namecount + 1
|
|
3973 : dp->dir$b_namecount;
|
|
3974 dv = (struct dir$_version *) &dp->dir$t_name[dirp->dd_loc];
|
|
3975 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount);
|
|
3976 sprintf (&dir_static.d_name[dp->dir$b_namecount], ";%d", dv->dir$w_version);
|
|
3977 dir_static.d_namlen = strlen (dir_static.d_name);
|
|
3978 dir_static.d_ino = dv->dir$w_fid_num;
|
|
3979 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3
|
|
3980 + dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
3981 dirp->dd_loc = ((char *) (++dv) - dp->dir$t_name);
|
|
3982 return &dir_static;
|
|
3983 }
|
|
3984
|
|
3985 #endif /* VMS */
|
|
3986
|
|
3987 #endif /* NONSYSTEM_DIR_LIBRARY */
|
|
3988
|
|
3989
|
|
3990 /* mkdir and rmdir functions, for systems which don't have them. */
|
|
3991
|
|
3992 #ifndef HAVE_MKDIR
|
|
3993 /*
|
|
3994 * Written by Robert Rother, Mariah Corporation, August 1985.
|
|
3995 *
|
|
3996 * If you want it, it's yours. All I ask in return is that if you
|
|
3997 * figure out how to do this in a Bourne Shell script you send me
|
|
3998 * a copy.
|
|
3999 * sdcsvax!rmr or rmr@uscd
|
|
4000 *
|
|
4001 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
|
|
4002 * subroutine. 11Mar86; hoptoad!gnu
|
|
4003 *
|
|
4004 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
|
|
4005 * subroutine didn't return EEXIST. It does now.
|
|
4006 */
|
|
4007
|
|
4008 /*
|
|
4009 * Make a directory.
|
|
4010 */
|
|
4011 #ifdef MKDIR_PROTOTYPE
|
|
4012 MKDIR_PROTOTYPE
|
|
4013 #else
|
|
4014 int
|
|
4015 mkdir (CONST char *dpath, int dmode)
|
|
4016 #endif
|
|
4017 {
|
|
4018 int cpid, status, fd;
|
|
4019 struct stat statbuf;
|
|
4020
|
|
4021 if (stat (dpath, &statbuf) == 0)
|
|
4022 {
|
|
4023 errno = EEXIST; /* Stat worked, so it already exists */
|
|
4024 return -1;
|
|
4025 }
|
|
4026
|
|
4027 /* If stat fails for a reason other than non-existence, return error */
|
|
4028 if (errno != ENOENT)
|
|
4029 return -1;
|
|
4030
|
|
4031 synch_process_alive = 1;
|
|
4032 switch (cpid = fork ())
|
|
4033 {
|
|
4034
|
|
4035 case -1: /* Error in fork() */
|
|
4036 return (-1); /* Errno is set already */
|
|
4037
|
|
4038 case 0: /* Child process */
|
|
4039 {
|
|
4040 /*
|
|
4041 * Cheap hack to set mode of new directory. Since this
|
|
4042 * child process is going away anyway, we zap its umask.
|
|
4043 * ####, this won't suffice to set SUID, SGID, etc. on this
|
|
4044 * directory. Does anybody care?
|
|
4045 */
|
|
4046 status = umask (0); /* Get current umask */
|
|
4047 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */
|
|
4048 fd = sys_open ("/dev/null", 2);
|
|
4049 if (fd >= 0)
|
|
4050 {
|
|
4051 dup2 (fd, 0);
|
|
4052 dup2 (fd, 1);
|
|
4053 dup2 (fd, 2);
|
|
4054 }
|
|
4055 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0);
|
|
4056 _exit (-1); /* Can't exec /bin/mkdir */
|
|
4057 }
|
|
4058
|
|
4059 default: /* Parent process */
|
|
4060 wait_for_termination (cpid);
|
|
4061 }
|
|
4062
|
|
4063 if (synch_process_death != 0 || synch_process_retcode != 0)
|
|
4064 {
|
|
4065 errno = EIO; /* We don't know why, but */
|
|
4066 return -1; /* /bin/mkdir failed */
|
|
4067 }
|
|
4068
|
|
4069 return 0;
|
|
4070 }
|
|
4071 #endif /* not HAVE_MKDIR */
|
|
4072
|
|
4073 #ifndef HAVE_RMDIR
|
|
4074 int
|
|
4075 rmdir (CONST char *dpath)
|
|
4076 {
|
|
4077 int cpid, status, fd;
|
|
4078 struct stat statbuf;
|
|
4079
|
|
4080 if (stat (dpath, &statbuf) != 0)
|
|
4081 {
|
|
4082 /* Stat just set errno. We don't have to */
|
|
4083 return -1;
|
|
4084 }
|
|
4085
|
|
4086 synch_process_alive = 1;
|
|
4087 switch (cpid = fork ())
|
|
4088 {
|
|
4089
|
|
4090 case -1: /* Error in fork() */
|
|
4091 return (-1); /* Errno is set already */
|
|
4092
|
|
4093 case 0: /* Child process */
|
|
4094 fd = sys_open("/dev/null", 2);
|
|
4095 if (fd >= 0)
|
|
4096 {
|
|
4097 dup2 (fd, 0);
|
|
4098 dup2 (fd, 1);
|
|
4099 dup2 (fd, 2);
|
|
4100 }
|
|
4101 execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
|
|
4102 _exit (-1); /* Can't exec /bin/mkdir */
|
|
4103
|
|
4104 default: /* Parent process */
|
|
4105 wait_for_termination (cpid);
|
|
4106 }
|
|
4107
|
|
4108 if (synch_process_death != 0 || synch_process_retcode != 0)
|
|
4109 {
|
|
4110 errno = EIO; /* We don't know why, but */
|
|
4111 return -1; /* /bin/rmdir failed */
|
|
4112 }
|
|
4113
|
|
4114 return 0;
|
|
4115 }
|
|
4116 #endif /* !HAVE_RMDIR */
|
|
4117
|
|
4118
|
|
4119 /************************************************************************/
|
|
4120 /* Misc. SunOS crap */
|
|
4121 /************************************************************************/
|
|
4122
|
|
4123 #ifdef USE_DL_STUBS
|
|
4124
|
|
4125 /* These are included on Sunos 4.1 when we do not use shared libraries.
|
|
4126 X11 libraries may refer to these functions but (we hope) do not
|
|
4127 actually call them. */
|
|
4128
|
|
4129 void *
|
|
4130 dlopen (void)
|
|
4131 {
|
|
4132 return 0;
|
|
4133 }
|
|
4134
|
|
4135 void *
|
|
4136 dlsym (void)
|
|
4137 {
|
|
4138 return 0;
|
|
4139 }
|
|
4140
|
|
4141 int
|
|
4142 dlclose (void)
|
|
4143 {
|
|
4144 return -1;
|
|
4145 }
|
|
4146
|
|
4147 #endif /* USE_DL_STUBS */
|
|
4148
|
|
4149
|
|
4150 /************************************************************************/
|
|
4151 /* VMS emulation of system calls */
|
|
4152 /************************************************************************/
|
|
4153
|
|
4154 #ifdef VMS
|
|
4155 #include "vms-pwd.h"
|
|
4156 #include <acldef.h>
|
|
4157 #include <chpdef.h>
|
|
4158 #include <jpidef.h>
|
|
4159
|
|
4160 /* Return as a string the VMS error string pertaining to STATUS.
|
|
4161 Reuses the same static buffer each time it is called. */
|
|
4162
|
|
4163 char *
|
|
4164 vmserrstr (int status) /* VMS status code */
|
|
4165 {
|
|
4166 int bufadr[2];
|
|
4167 short len;
|
|
4168 static char buf[257];
|
|
4169
|
|
4170 bufadr[0] = sizeof buf - 1;
|
|
4171 bufadr[1] = (int) buf;
|
|
4172 if (! (SYS$GETMSG (status, &len, bufadr, 0x1, 0) & 1))
|
|
4173 return "untranslatable VMS error status";
|
|
4174 buf[len] = '\0';
|
|
4175 return buf;
|
|
4176 }
|
|
4177
|
|
4178 #ifdef access
|
|
4179 #undef access
|
185
|
4180
|
0
|
4181 /* The following is necessary because 'access' emulation by VMS C (2.0) does
|
|
4182 * not work correctly. (It also doesn't work well in version 2.3.)
|
|
4183 */
|
|
4184
|
|
4185 #ifdef VMS4_4
|
|
4186
|
|
4187 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
|
|
4188 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
|
|
4189
|
|
4190 typedef union {
|
|
4191 struct {
|
|
4192 unsigned short s_buflen;
|
|
4193 unsigned short s_code;
|
|
4194 char *s_bufadr;
|
|
4195 unsigned short *s_retlenadr;
|
|
4196 } s;
|
|
4197 int end;
|
|
4198 } item;
|
|
4199 #define buflen s.s_buflen
|
|
4200 #define code s.s_code
|
|
4201 #define bufadr s.s_bufadr
|
|
4202 #define retlenadr s.s_retlenadr
|
|
4203
|
|
4204 #define R_OK 4 /* test for read permission */
|
|
4205 #define W_OK 2 /* test for write permission */
|
|
4206 #define X_OK 1 /* test for execute (search) permission */
|
|
4207 #define F_OK 0 /* test for presence of file */
|
|
4208
|
|
4209 int
|
|
4210 vms_access (CONST char *path, int mode)
|
|
4211 {
|
|
4212 static char *user = NULL;
|
|
4213 char dir_fn[512];
|
|
4214
|
|
4215 /* translate possible directory spec into .DIR file name, so brain-dead
|
|
4216 * access can treat the directory like a file. */
|
|
4217 if (directory_file_name (path, dir_fn))
|
|
4218 path = dir_fn;
|
185
|
4219
|
0
|
4220 if (mode == F_OK)
|
|
4221 return access (path, mode);
|
|
4222 if (user == NULL && (user = (char *) getenv ("USER")) == NULL)
|
|
4223 return -1;
|
|
4224 {
|
|
4225 int stat;
|
|
4226 int flags;
|
|
4227 int acces;
|
|
4228 unsigned short int dummy;
|
|
4229 item itemlst[3];
|
|
4230 static int constant = ACL$C_FILE;
|
|
4231 DESCRIPTOR (path_desc, path);
|
|
4232 DESCRIPTOR (user_desc, user);
|
185
|
4233
|
0
|
4234 flags = 0;
|
|
4235 acces = 0;
|
|
4236 if ((mode & X_OK) && ((stat = access (path, mode)) < 0 || mode == X_OK))
|
|
4237 return stat;
|
|
4238 if (mode & R_OK)
|
|
4239 acces |= CHP$M_READ;
|
|
4240 if (mode & W_OK)
|
|
4241 acces |= CHP$M_WRITE;
|
|
4242 itemlst[0].buflen = sizeof (int);
|
|
4243 itemlst[0].code = CHP$_FLAGS;
|
|
4244 itemlst[0].bufadr = (char *) &flags;
|
|
4245 itemlst[0].retlenadr = &dummy;
|
|
4246 itemlst[1].buflen = sizeof (int);
|
|
4247 itemlst[1].code = CHP$_ACCESS;
|
|
4248 itemlst[1].bufadr = (char *) &acces;
|
|
4249 itemlst[1].retlenadr = &dummy;
|
|
4250 itemlst[2].end = CHP$_END;
|
|
4251 stat = SYS$CHECK_ACCESS (&constant, &path_desc, &user_desc, itemlst);
|
|
4252 return stat == SS$_NORMAL ? 0 : -1;
|
|
4253 }
|
|
4254 }
|
|
4255
|
|
4256 #else /* not VMS4_4 */
|
|
4257
|
|
4258 #include <prvdef.h>
|
|
4259 #define ACE$M_WRITE 2
|
|
4260 #define ACE$C_KEYID 1
|
|
4261
|
|
4262 static unsigned short vms_memid, vms_grpid;
|
|
4263 static unsigned int vms_uic;
|
|
4264
|
|
4265 /* Called from init_sys_modes, so it happens not very often
|
|
4266 but at least each time Emacs is loaded. */
|
|
4267 sys_access_reinit (void)
|
|
4268 {
|
|
4269 vms_uic = 0;
|
|
4270 }
|
|
4271
|
|
4272 int
|
|
4273 vms_access (CONST char *filename, int type)
|
|
4274 {
|
|
4275 struct FAB fab;
|
|
4276 struct XABPRO xab;
|
|
4277 int status, size, i, typecode, acl_controlled;
|
|
4278 unsigned int *aclptr, *aclend, aclbuf[60];
|
|
4279 union prvdef prvmask;
|
|
4280
|
|
4281 /* Get UIC and GRP values for protection checking. */
|
|
4282 if (vms_uic == 0)
|
|
4283 {
|
|
4284 status = LIB$GETJPI (&JPI$_UIC, 0, 0, &vms_uic, 0, 0);
|
|
4285 if (! (status & 1))
|
|
4286 return -1;
|
|
4287 vms_memid = vms_uic & 0xFFFF;
|
|
4288 vms_grpid = vms_uic >> 16;
|
|
4289 }
|
|
4290
|
|
4291 if (type != 2) /* not checking write access */
|
|
4292 return access (filename, type);
|
|
4293
|
|
4294 /* Check write protection. */
|
185
|
4295
|
0
|
4296 #define CHECKPRIV(bit) (prvmask.bit)
|
|
4297 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
|
|
4298
|
|
4299 /* Find privilege bits */
|
|
4300 status = SYS$SETPRV (0, 0, 0, prvmask);
|
|
4301 if (! (status & 1))
|
|
4302 error ("Unable to find privileges: %s", vmserrstr (status));
|
|
4303 if (CHECKPRIV (PRV$V_BYPASS))
|
|
4304 return 0; /* BYPASS enabled */
|
|
4305 fab = cc$rms_fab;
|
|
4306 fab.fab$b_fac = FAB$M_GET;
|
|
4307 fab.fab$l_fna = filename;
|
|
4308 fab.fab$b_fns = strlen (filename);
|
|
4309 fab.fab$l_xab = &xab;
|
|
4310 xab = cc$rms_xabpro;
|
|
4311 xab.xab$l_aclbuf = aclbuf;
|
|
4312 xab.xab$w_aclsiz = sizeof (aclbuf);
|
|
4313 status = SYS$OPEN (&fab, 0, 0);
|
|
4314 if (! (status & 1))
|
|
4315 return -1;
|
|
4316 SYS$CLOSE (&fab, 0, 0);
|
|
4317 /* Check system access */
|
|
4318 if (CHECKPRIV (PRV$V_SYSPRV) && WRITEABLE (XAB$V_SYS))
|
|
4319 return 0;
|
|
4320 /* Check ACL entries, if any */
|
|
4321 acl_controlled = 0;
|
|
4322 if (xab.xab$w_acllen > 0)
|
|
4323 {
|
|
4324 aclptr = aclbuf;
|
|
4325 aclend = &aclbuf[xab.xab$w_acllen / 4];
|
|
4326 while (*aclptr && aclptr < aclend)
|
|
4327 {
|
|
4328 size = (*aclptr & 0xff) / 4;
|
|
4329 typecode = (*aclptr >> 8) & 0xff;
|
|
4330 if (typecode == ACE$C_KEYID)
|
|
4331 for (i = size - 1; i > 1; i--)
|
|
4332 if (aclptr[i] == vms_uic)
|
|
4333 {
|
|
4334 acl_controlled = 1;
|
|
4335 if (aclptr[1] & ACE$M_WRITE)
|
|
4336 return 0; /* Write access through ACL */
|
|
4337 }
|
|
4338 aclptr = &aclptr[size];
|
|
4339 }
|
|
4340 if (acl_controlled) /* ACL specified, prohibits write access */
|
|
4341 return -1;
|
|
4342 }
|
|
4343 /* No ACL entries specified, check normal protection */
|
|
4344 if (WRITEABLE (XAB$V_WLD)) /* World writeable */
|
|
4345 return 0;
|
|
4346 if (WRITEABLE (XAB$V_GRP) &&
|
|
4347 (unsigned short) (xab.xab$l_uic >> 16) == vms_grpid)
|
|
4348 return 0; /* Group writeable */
|
|
4349 if (WRITEABLE (XAB$V_OWN) &&
|
|
4350 (xab.xab$l_uic & 0xFFFF) == vms_memid)
|
|
4351 return 0; /* Owner writeable */
|
|
4352
|
|
4353 return -1; /* Not writeable */
|
|
4354 }
|
|
4355 #endif /* not VMS4_4 */
|
|
4356 #endif /* access */
|
185
|
4357
|
0
|
4358 static char vtbuf[NAM$C_MAXRSS+1];
|
|
4359
|
|
4360 /* translate a vms file spec to a unix path */
|
|
4361 char *
|
|
4362 sys_translate_vms (char *vfile)
|
|
4363 {
|
|
4364 char * p;
|
|
4365 char * targ;
|
|
4366
|
|
4367 if (!vfile)
|
|
4368 return 0;
|
|
4369
|
|
4370 targ = vtbuf;
|
|
4371
|
|
4372 /* leading device or logical name is a root directory */
|
|
4373 if (p = strchr (vfile, ':'))
|
|
4374 {
|
|
4375 *targ++ = '/';
|
|
4376 while (vfile < p)
|
|
4377 *targ++ = *vfile++;
|
|
4378 vfile++;
|
|
4379 *targ++ = '/';
|
|
4380 }
|
|
4381 p = vfile;
|
|
4382 if (*p == '[' || *p == '<')
|
|
4383 {
|
|
4384 while (*++vfile != *p + 2)
|
|
4385 switch (*vfile)
|
|
4386 {
|
|
4387 case '.':
|
|
4388 if (vfile[-1] == *p)
|
|
4389 *targ++ = '.';
|
|
4390 *targ++ = '/';
|
|
4391 break;
|
|
4392
|
|
4393 case '-':
|
|
4394 *targ++ = '.';
|
|
4395 *targ++ = '.';
|
|
4396 break;
|
185
|
4397
|
0
|
4398 default:
|
|
4399 *targ++ = *vfile;
|
|
4400 break;
|
|
4401 }
|
|
4402 vfile++;
|
|
4403 *targ++ = '/';
|
|
4404 }
|
|
4405 while (*vfile)
|
|
4406 *targ++ = *vfile++;
|
|
4407
|
|
4408 return vtbuf;
|
|
4409 }
|
|
4410
|
|
4411 static char utbuf[NAM$C_MAXRSS+1];
|
|
4412
|
|
4413 /* translate a unix path to a VMS file spec */
|
|
4414 char *
|
|
4415 sys_translate_unix (char *ufile)
|
|
4416 {
|
|
4417 int slash_seen = 0;
|
|
4418 char *p;
|
|
4419 char * targ;
|
|
4420
|
|
4421 if (!ufile)
|
|
4422 return 0;
|
|
4423
|
|
4424 targ = utbuf;
|
|
4425
|
|
4426 if (*ufile == '/')
|
|
4427 {
|
|
4428 ufile++;
|
|
4429 }
|
|
4430
|
|
4431 while (*ufile)
|
|
4432 {
|
|
4433 switch (*ufile)
|
|
4434 {
|
|
4435 case '/':
|
|
4436 if (slash_seen)
|
|
4437 if (strchr (&ufile[1], '/'))
|
|
4438 *targ++ = '.';
|
|
4439 else
|
|
4440 *targ++ = ']';
|
|
4441 else
|
|
4442 {
|
|
4443 *targ++ = ':';
|
|
4444 if (strchr (&ufile[1], '/'))
|
|
4445 *targ++ = '[';
|
|
4446 slash_seen = 1;
|
|
4447 }
|
|
4448 break;
|
|
4449
|
|
4450 case '.':
|
|
4451 if (strncmp (ufile, "./", 2) == 0)
|
|
4452 {
|
|
4453 if (!slash_seen)
|
|
4454 {
|
|
4455 *targ++ = '[';
|
|
4456 slash_seen = 1;
|
|
4457 }
|
|
4458 ufile++; /* skip the dot */
|
|
4459 if (strchr (&ufile[1], '/'))
|
|
4460 *targ++ = '.';
|
|
4461 else
|
|
4462 *targ++ = ']';
|
|
4463 }
|
|
4464 else if (strncmp (ufile, "../", 3) == 0)
|
|
4465 {
|
|
4466 if (!slash_seen)
|
|
4467 {
|
|
4468 *targ++ = '[';
|
|
4469 slash_seen = 1;
|
|
4470 }
|
|
4471 *targ++ = '-';
|
|
4472 ufile += 2; /* skip the dots */
|
|
4473 if (strchr (&ufile[1], '/'))
|
|
4474 *targ++ = '.';
|
|
4475 else
|
|
4476 *targ++ = ']';
|
|
4477 }
|
|
4478 else
|
|
4479 *targ++ = *ufile;
|
|
4480 break;
|
|
4481
|
|
4482 default:
|
|
4483 *targ++ = *ufile;
|
|
4484 break;
|
|
4485 }
|
|
4486 ufile++;
|
|
4487 }
|
|
4488 *targ = '\0';
|
185
|
4489
|
0
|
4490 return utbuf;
|
|
4491 }
|
|
4492
|
|
4493 char *
|
|
4494 getwd (char *pathname)
|
|
4495 {
|
|
4496 char *ptr;
|
|
4497 strcpy (pathname, egetenv ("PATH"));
|
|
4498
|
|
4499 ptr = pathname;
|
|
4500 while (*ptr)
|
|
4501 {
|
|
4502 /* #### This is evil. Smashes (shared) result of egetenv */
|
|
4503 *ptr = toupper (* (unsigned char *) ptr);
|
|
4504 ptr++;
|
|
4505 }
|
|
4506 return pathname;
|
|
4507 }
|
|
4508
|
|
4509 int
|
|
4510 getppid (void)
|
|
4511 {
|
|
4512 long item_code = JPI$_OWNER;
|
|
4513 unsigned long parent_id;
|
|
4514 int status;
|
|
4515
|
|
4516 if (((status = LIB$GETJPI (&item_code, 0, 0, &parent_id)) & 1) == 0)
|
|
4517 {
|
|
4518 errno = EVMSERR;
|
|
4519 vaxc$errno = status;
|
|
4520 return -1;
|
|
4521 }
|
|
4522 return parent_id;
|
|
4523 }
|
|
4524
|
|
4525 #undef getuid
|
|
4526 unsigned int
|
|
4527 sys_getuid (void)
|
|
4528 {
|
|
4529 return (getgid () << 16) | getuid ();
|
|
4530 }
|
|
4531
|
|
4532 int
|
|
4533 vms_read (int fildes, CONST void *buf, unsigned int nbyte)
|
|
4534 {
|
|
4535 return read (fildes, buf, (nbyte < MAXIOSIZE ? nbyte : MAXIOSIZE));
|
|
4536 }
|
|
4537
|
|
4538 #if 0
|
|
4539 int
|
|
4540 vms_write (int fildes, CONST void *buf, unsigned int nbyte)
|
|
4541 {
|
|
4542 int nwrote, rtnval = 0;
|
|
4543
|
|
4544 while (nbyte > MAXIOSIZE && (nwrote = write (fildes, buf, MAXIOSIZE)) > 0)
|
|
4545 {
|
|
4546 nbyte -= nwrote;
|
|
4547 buf += nwrote;
|
|
4548 rtnval += nwrote;
|
|
4549 }
|
|
4550 if (nwrote < 0)
|
|
4551 return rtnval ? rtnval : -1;
|
|
4552 if ((nwrote = write (fildes, buf, nbyte)) < 0)
|
|
4553 return rtnval ? rtnval : -1;
|
|
4554 return (rtnval + nwrote);
|
|
4555 }
|
|
4556 #endif /* 0 */
|
|
4557
|
|
4558 /*
|
|
4559 * VAX/VMS VAX C RTL really loses. It insists that records
|
|
4560 * end with a newline (carriage return) character, and if they
|
|
4561 * don't it adds one (nice of it isn't it!)
|
|
4562 *
|
|
4563 * Thus we do this stupidity below.
|
|
4564 */
|
|
4565
|
|
4566 int
|
|
4567 vms_write (int fildes, CONST void *buf, unsigned int nbytes)
|
|
4568 {
|
|
4569 char *p;
|
|
4570 char *e;
|
|
4571 int sum = 0;
|
|
4572 struct stat st;
|
|
4573
|
|
4574 fstat (fildes, &st);
|
|
4575 p = buf;
|
|
4576 while (nbytes > 0)
|
|
4577 {
|
|
4578 int len, retval;
|
|
4579
|
|
4580 /* Handle fixed-length files with carriage control. */
|
|
4581 if (st.st_fab_rfm == FAB$C_FIX
|
|
4582 && ((st.st_fab_rat & (FAB$M_FTN | FAB$M_CR)) != 0))
|
|
4583 {
|
|
4584 len = st.st_fab_mrs;
|
|
4585 retval = write (fildes, p, min (len, nbytes));
|
|
4586 if (retval != len)
|
|
4587 return -1;
|
|
4588 retval++; /* This skips the implied carriage control */
|
|
4589 }
|
|
4590 else
|
|
4591 {
|
|
4592 e = p + min (MAXIOSIZE, nbytes) - 1;
|
|
4593 while (*e != '\n' && e > p) e--;
|
|
4594 if (p == e) /* Ok.. so here we add a newline... sigh. */
|
|
4595 e = p + min (MAXIOSIZE, nbytes) - 1;
|
|
4596 len = e + 1 - p;
|
|
4597 retval = write (fildes, p, len);
|
|
4598 if (retval != len)
|
|
4599 return -1;
|
|
4600 }
|
|
4601 p += retval;
|
|
4602 sum += retval;
|
|
4603 nbytes -= retval;
|
|
4604 }
|
|
4605 return sum;
|
|
4606 }
|
|
4607
|
|
4608 /* Create file NEW copying its attributes from file OLD. If
|
|
4609 OLD is 0 or does not exist, create based on the value of
|
|
4610 vms_stmlf_recfm. */
|
|
4611
|
|
4612 /* Protection value the file should ultimately have.
|
|
4613 Set by create_copy_attrs, and use by rename_sansversions. */
|
|
4614 static unsigned short int vms_fab_final_pro;
|
|
4615
|
|
4616 int
|
|
4617 creat_copy_attrs (char *old, char *new)
|
|
4618 {
|
|
4619 struct FAB fab = cc$rms_fab;
|
|
4620 struct XABPRO xabpro;
|
|
4621 char aclbuf[256]; /* Choice of size is arbitrary. See below. */
|
|
4622 extern int vms_stmlf_recfm;
|
|
4623
|
|
4624 if (old)
|
|
4625 {
|
|
4626 fab.fab$b_fac = FAB$M_GET;
|
|
4627 fab.fab$l_fna = old;
|
|
4628 fab.fab$b_fns = strlen (old);
|
|
4629 fab.fab$l_xab = (char *) &xabpro;
|
|
4630 xabpro = cc$rms_xabpro;
|
|
4631 xabpro.xab$l_aclbuf = aclbuf;
|
|
4632 xabpro.xab$w_aclsiz = sizeof aclbuf;
|
|
4633 /* Call $OPEN to fill in the fab & xabpro fields. */
|
|
4634 if (SYS$OPEN (&fab, 0, 0) & 1)
|
|
4635 {
|
|
4636 SYS$CLOSE (&fab, 0, 0);
|
|
4637 fab.fab$l_alq = 0; /* zero the allocation quantity */
|
|
4638 if (xabpro.xab$w_acllen > 0)
|
|
4639 {
|
|
4640 if (xabpro.xab$w_acllen > sizeof aclbuf)
|
|
4641 /* If the acl buffer was too short, redo open with longer one.
|
|
4642 Wouldn't need to do this if there were some system imposed
|
|
4643 limit on the size of an ACL, but I can't find any such. */
|
|
4644 {
|
|
4645 xabpro.xab$l_aclbuf = (char *) alloca (xabpro.xab$w_acllen);
|
|
4646 xabpro.xab$w_aclsiz = xabpro.xab$w_acllen;
|
|
4647 if (SYS$OPEN (&fab, 0, 0) & 1)
|
|
4648 SYS$CLOSE (&fab, 0, 0);
|
|
4649 else
|
|
4650 old = 0;
|
|
4651 }
|
|
4652 }
|
|
4653 else
|
|
4654 xabpro.xab$l_aclbuf = 0;
|
|
4655 }
|
|
4656 else
|
|
4657 old = 0;
|
|
4658 }
|
|
4659 fab.fab$l_fna = new;
|
|
4660 fab.fab$b_fns = strlen (new);
|
|
4661 if (!old)
|
|
4662 {
|
|
4663 fab.fab$l_xab = 0;
|
|
4664 fab.fab$b_rfm = vms_stmlf_recfm ? FAB$C_STMLF : FAB$C_VAR;
|
|
4665 fab.fab$b_rat = FAB$M_CR;
|
|
4666 }
|
|
4667
|
|
4668 /* Set the file protections such that we will be able to manipulate
|
|
4669 this file. Once we are done writing and renaming it, we will set
|
|
4670 the protections back. */
|
|
4671 if (old)
|
|
4672 vms_fab_final_pro = xabpro.xab$w_pro;
|
|
4673 else
|
|
4674 SYS$SETDFPROT (0, &vms_fab_final_pro);
|
|
4675 xabpro.xab$w_pro &= 0xff0f; /* set O:rewd for now. This is set back later. */
|
|
4676
|
|
4677 /* Create the new file with either default attrs or attrs copied
|
|
4678 from old file. */
|
|
4679 if (!(SYS$CREATE (&fab, 0, 0) & 1))
|
|
4680 return -1;
|
|
4681 SYS$CLOSE (&fab, 0, 0);
|
|
4682 /* As this is a "replacement" for creat, return a file descriptor
|
|
4683 opened for writing. */
|
|
4684 return open (new, O_WRONLY);
|
|
4685 }
|
|
4686
|
|
4687 int
|
|
4688 vms_creat (CONST char *path, int mode, ...)
|
|
4689 {
|
|
4690 int rfd; /* related file descriptor */
|
|
4691 int fd; /* Our new file descriptor */
|
|
4692 int count;
|
|
4693 struct stat st_buf;
|
|
4694 char rfm[12];
|
|
4695 char rat[15];
|
|
4696 char mrs[13];
|
|
4697 char fsz[13];
|
|
4698 extern int vms_stmlf_recfm;
|
|
4699
|
|
4700 /* #### there was some weird machine-dependent code to determine how many
|
|
4701 arguments were passed to this function. This certainly won't work
|
|
4702 under ANSI C. */
|
|
4703 if (count > 2)
|
|
4704 rfd = fix this;
|
|
4705 if (count > 2)
|
|
4706 {
|
|
4707 /* Use information from the related file descriptor to set record
|
|
4708 format of the newly created file. */
|
|
4709 fstat (rfd, &st_buf);
|
|
4710 switch (st_buf.st_fab_rfm)
|
|
4711 {
|
|
4712 case FAB$C_FIX:
|
|
4713 strcpy (rfm, "rfm = fix");
|
|
4714 sprintf (mrs, "mrs = %d", st_buf.st_fab_mrs);
|
|
4715 strcpy (rat, "rat = ");
|
|
4716 if (st_buf.st_fab_rat & FAB$M_CR)
|
|
4717 strcat (rat, "cr");
|
|
4718 else if (st_buf.st_fab_rat & FAB$M_FTN)
|
|
4719 strcat (rat, "ftn");
|
|
4720 else if (st_buf.st_fab_rat & FAB$M_PRN)
|
|
4721 strcat (rat, "prn");
|
|
4722 if (st_buf.st_fab_rat & FAB$M_BLK)
|
|
4723 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN))
|
|
4724 strcat (rat, ", blk");
|
|
4725 else
|
|
4726 strcat (rat, "blk");
|
|
4727 return creat (name, 0, rfm, rat, mrs);
|
|
4728
|
|
4729 case FAB$C_VFC:
|
|
4730 strcpy (rfm, "rfm = vfc");
|
|
4731 sprintf (fsz, "fsz = %d", st_buf.st_fab_fsz);
|
|
4732 strcpy (rat, "rat = ");
|
|
4733 if (st_buf.st_fab_rat & FAB$M_CR)
|
|
4734 strcat (rat, "cr");
|
|
4735 else if (st_buf.st_fab_rat & FAB$M_FTN)
|
|
4736 strcat (rat, "ftn");
|
|
4737 else if (st_buf.st_fab_rat & FAB$M_PRN)
|
|
4738 strcat (rat, "prn");
|
|
4739 if (st_buf.st_fab_rat & FAB$M_BLK)
|
|
4740 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN))
|
|
4741 strcat (rat, ", blk");
|
|
4742 else
|
|
4743 strcat (rat, "blk");
|
|
4744 return creat (name, 0, rfm, rat, fsz);
|
|
4745
|
|
4746 case FAB$C_STM:
|
|
4747 strcpy (rfm, "rfm = stm");
|
|
4748 break;
|
|
4749
|
|
4750 case FAB$C_STMCR:
|
|
4751 strcpy (rfm, "rfm = stmcr");
|
|
4752 break;
|
|
4753
|
|
4754 case FAB$C_STMLF:
|
|
4755 strcpy (rfm, "rfm = stmlf");
|
|
4756 break;
|
|
4757
|
|
4758 case FAB$C_UDF:
|
|
4759 strcpy (rfm, "rfm = udf");
|
|
4760 break;
|
|
4761
|
|
4762 case FAB$C_VAR:
|
|
4763 strcpy (rfm, "rfm = var");
|
|
4764 break;
|
|
4765 }
|
|
4766 strcpy (rat, "rat = ");
|
|
4767 if (st_buf.st_fab_rat & FAB$M_CR)
|
|
4768 strcat (rat, "cr");
|
|
4769 else if (st_buf.st_fab_rat & FAB$M_FTN)
|
|
4770 strcat (rat, "ftn");
|
|
4771 else if (st_buf.st_fab_rat & FAB$M_PRN)
|
|
4772 strcat (rat, "prn");
|
|
4773 if (st_buf.st_fab_rat & FAB$M_BLK)
|
|
4774 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN))
|
|
4775 strcat (rat, ", blk");
|
|
4776 else
|
|
4777 strcat (rat, "blk");
|
|
4778 }
|
|
4779 else
|
|
4780 {
|
|
4781 strcpy (rfm, vms_stmlf_recfm ? "rfm = stmlf" : "rfm=var");
|
|
4782 strcpy (rat, "rat=cr");
|
|
4783 }
|
|
4784 /* Until the VAX C RTL fixes the many bugs with modes, always use
|
|
4785 mode 0 to get the user's default protection. */
|
|
4786 fd = creat (name, 0, rfm, rat);
|
|
4787 if (fd < 0 && errno == EEXIST)
|
|
4788 {
|
|
4789 if (unlink (name) < 0)
|
|
4790 report_file_error ("delete", build_string (name));
|
|
4791 fd = creat (name, 0, rfm, rat);
|
|
4792 }
|
|
4793 return fd;
|
|
4794 }
|
|
4795
|
|
4796 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
|
|
4797 int
|
|
4798 vms_fwrite (CONST void *ptr, int size, int num, FILE *fp)
|
|
4799 {
|
|
4800 int tot = num * size;
|
|
4801
|
|
4802 while (tot--)
|
|
4803 fputc (* (CONST char *) ptr++, fp);
|
|
4804 return (num);
|
|
4805 }
|
|
4806
|
|
4807 /*
|
|
4808 * The VMS C library routine creat actually creates a new version of an
|
|
4809 * existing file rather than truncating the old version. There are times
|
|
4810 * when this is not the desired behavior, for instance, when writing an
|
|
4811 * auto save file (you only want one version), or when you don't have
|
|
4812 * write permission in the directory containing the file (but the file
|
185
|
4813 * itself is writable). Hence this routine, which is equivalent to
|
0
|
4814 * "close (creat (fn, 0));" on Unix if fn already exists.
|
|
4815 */
|
|
4816 int
|
|
4817 vms_truncate (char *fn)
|
|
4818 {
|
|
4819 struct FAB xfab = cc$rms_fab;
|
|
4820 struct RAB xrab = cc$rms_rab;
|
|
4821 int status;
|
|
4822
|
|
4823 xfab.fab$l_fop = FAB$M_TEF; /* free allocated but unused blocks on close */
|
|
4824 xfab.fab$b_fac = FAB$M_TRN | FAB$M_GET; /* allow truncate and get access */
|
|
4825 xfab.fab$b_shr = FAB$M_NIL; /* allow no sharing - file must be locked */
|
|
4826 xfab.fab$l_fna = fn;
|
|
4827 xfab.fab$b_fns = strlen (fn);
|
|
4828 xfab.fab$l_dna = ";0"; /* default to latest version of the file */
|
|
4829 xfab.fab$b_dns = 2;
|
|
4830 xrab.rab$l_fab = &xfab;
|
|
4831
|
|
4832 /* This gibberish opens the file, positions to the first record, and
|
|
4833 deletes all records from there until the end of file. */
|
|
4834 if ((SYS$OPEN (&xfab) & 01) == 01)
|
|
4835 {
|
|
4836 if ((SYS$CONNECT (&xrab) & 01) == 01 &&
|
|
4837 (SYS$FIND (&xrab) & 01) == 01 &&
|
|
4838 (SYS$TRUNCATE (&xrab) & 01) == 01)
|
|
4839 status = 0;
|
|
4840 else
|
|
4841 status = -1;
|
|
4842 }
|
|
4843 else
|
|
4844 status = -1;
|
|
4845 SYS$CLOSE (&xfab);
|
|
4846 return status;
|
|
4847 }
|
|
4848
|
|
4849 /* Define this symbol to actually read SYSUAF.DAT. This requires either
|
|
4850 SYSPRV or a readable SYSUAF.DAT. */
|
|
4851
|
|
4852 #ifdef READ_SYSUAF
|
|
4853 /*
|
|
4854 * getuaf.c
|
|
4855 *
|
|
4856 * Routine to read the VMS User Authorization File and return
|
|
4857 * a specific user's record.
|
|
4858 */
|
|
4859
|
|
4860 static struct UAF vms_retuaf;
|
|
4861
|
|
4862 static struct UAF *
|
|
4863 get_uaf_name (char *uname)
|
|
4864 {
|
|
4865 status;
|
|
4866 struct FAB uaf_fab;
|
|
4867 struct RAB uaf_rab;
|
185
|
4868
|
0
|
4869 uaf_fab = cc$rms_fab;
|
|
4870 uaf_rab = cc$rms_rab;
|
|
4871 /* initialize fab fields */
|
|
4872 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT";
|
|
4873 uaf_fab.fab$b_fns = 21;
|
|
4874 uaf_fab.fab$b_fac = FAB$M_GET;
|
|
4875 uaf_fab.fab$b_org = FAB$C_IDX;
|
|
4876 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL;
|
|
4877 /* initialize rab fields */
|
|
4878 uaf_rab.rab$l_fab = &uaf_fab;
|
|
4879 /* open the User Authorization File */
|
|
4880 status = SYS$OPEN (&uaf_fab);
|
|
4881 if (!(status&1))
|
|
4882 {
|
|
4883 errno = EVMSERR;
|
|
4884 vaxc$errno = status;
|
|
4885 return 0;
|
|
4886 }
|
|
4887 status = SYS$CONNECT (&uaf_rab);
|
|
4888 if (!(status&1))
|
|
4889 {
|
|
4890 errno = EVMSERR;
|
|
4891 vaxc$errno = status;
|
|
4892 return 0;
|
|
4893 }
|
|
4894 /* read the requested record - index is in uname */
|
|
4895 uaf_rab.rab$l_kbf = uname;
|
|
4896 uaf_rab.rab$b_ksz = strlen (uname);
|
|
4897 uaf_rab.rab$b_rac = RAB$C_KEY;
|
|
4898 uaf_rab.rab$l_ubf = (char *)&vms_retuaf;
|
|
4899 uaf_rab.rab$w_usz = sizeof vms_retuaf;
|
|
4900 status = SYS$GET (&uaf_rab);
|
|
4901 if (!(status&1))
|
|
4902 {
|
|
4903 errno = EVMSERR;
|
|
4904 vaxc$errno = status;
|
|
4905 return 0;
|
|
4906 }
|
|
4907 /* close the User Authorization File */
|
|
4908 status = SYS$DISCONNECT (&uaf_rab);
|
|
4909 if (!(status&1))
|
|
4910 {
|
|
4911 errno = EVMSERR;
|
|
4912 vaxc$errno = status;
|
|
4913 return 0;
|
|
4914 }
|
|
4915 status = SYS$CLOSE (&uaf_fab);
|
|
4916 if (!(status&1))
|
|
4917 {
|
|
4918 errno = EVMSERR;
|
|
4919 vaxc$errno = status;
|
|
4920 return 0;
|
|
4921 }
|
|
4922 return &vms_retuaf;
|
|
4923 }
|
|
4924
|
|
4925 static struct UAF *
|
|
4926 get_uaf_uic (unsigned long uic)
|
|
4927 {
|
|
4928 status;
|
|
4929 struct FAB uaf_fab;
|
|
4930 struct RAB uaf_rab;
|
185
|
4931
|
0
|
4932 uaf_fab = cc$rms_fab;
|
|
4933 uaf_rab = cc$rms_rab;
|
|
4934 /* initialize fab fields */
|
|
4935 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT";
|
|
4936 uaf_fab.fab$b_fns = 21;
|
|
4937 uaf_fab.fab$b_fac = FAB$M_GET;
|
|
4938 uaf_fab.fab$b_org = FAB$C_IDX;
|
|
4939 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL;
|
|
4940 /* initialize rab fields */
|
|
4941 uaf_rab.rab$l_fab = &uaf_fab;
|
|
4942 /* open the User Authorization File */
|
|
4943 status = SYS$OPEN (&uaf_fab);
|
|
4944 if (!(status&1))
|
|
4945 {
|
|
4946 errno = EVMSERR;
|
|
4947 vaxc$errno = status;
|
|
4948 return 0;
|
|
4949 }
|
|
4950 status = SYS$CONNECT (&uaf_rab);
|
|
4951 if (!(status&1))
|
|
4952 {
|
|
4953 errno = EVMSERR;
|
|
4954 vaxc$errno = status;
|
|
4955 return 0;
|
|
4956 }
|
|
4957 /* read the requested record - index is in uic */
|
|
4958 uaf_rab.rab$b_krf = 1; /* 1st alternate key */
|
|
4959 uaf_rab.rab$l_kbf = (char *) &uic;
|
|
4960 uaf_rab.rab$b_ksz = sizeof uic;
|
|
4961 uaf_rab.rab$b_rac = RAB$C_KEY;
|
|
4962 uaf_rab.rab$l_ubf = (char *)&vms_retuaf;
|
|
4963 uaf_rab.rab$w_usz = sizeof vms_retuaf;
|
|
4964 status = SYS$GET (&uaf_rab);
|
|
4965 if (!(status&1))
|
|
4966 {
|
|
4967 errno = EVMSERR;
|
|
4968 vaxc$errno = status;
|
|
4969 return 0;
|
|
4970 }
|
|
4971 /* close the User Authorization File */
|
|
4972 status = SYS$DISCONNECT (&uaf_rab);
|
|
4973 if (!(status&1))
|
|
4974 {
|
|
4975 errno = EVMSERR;
|
|
4976 vaxc$errno = status;
|
|
4977 return 0;
|
|
4978 }
|
|
4979 status = SYS$CLOSE (&uaf_fab);
|
|
4980 if (!(status&1))
|
|
4981 {
|
|
4982 errno = EVMSERR;
|
|
4983 vaxc$errno = status;
|
|
4984 return 0;
|
|
4985 }
|
|
4986 return &vms_retuaf;
|
|
4987 }
|
|
4988
|
|
4989 static struct passwd vms_retpw;
|
|
4990
|
|
4991 static struct passwd *
|
|
4992 cnv_uaf_pw (struct UAF *up)
|
|
4993 {
|
|
4994 char * ptr;
|
|
4995
|
|
4996 /* copy these out first because if the username is 32 chars, the next
|
|
4997 section will overwrite the first byte of the UIC */
|
|
4998 vms_retpw.pw_uid = up->uaf$w_mem;
|
|
4999 vms_retpw.pw_gid = up->uaf$w_grp;
|
|
5000
|
|
5001 /* I suppose this is not the best sytle, to possibly overwrite one
|
|
5002 byte beyond the end of the field, but what the heck... */
|
|
5003 ptr = &up->uaf$t_username[UAF$S_USERNAME];
|
|
5004 while (ptr[-1] == ' ')
|
|
5005 ptr--;
|
|
5006 *ptr = '\0';
|
|
5007 strcpy (vms_retpw.pw_name, up->uaf$t_username);
|
|
5008
|
|
5009 /* the rest of these are counted ascii strings */
|
|
5010 strncpy (vms_retpw.pw_gecos, &up->uaf$t_owner[1], up->uaf$t_owner[0]);
|
|
5011 vms_retpw.pw_gecos[up->uaf$t_owner[0]] = '\0';
|
|
5012 strncpy (vms_retpw.pw_dir, &up->uaf$t_defdev[1], up->uaf$t_defdev[0]);
|
|
5013 vms_retpw.pw_dir[up->uaf$t_defdev[0]] = '\0';
|
|
5014 strncat (vms_retpw.pw_dir, &up->uaf$t_defdir[1], up->uaf$t_defdir[0]);
|
|
5015 vms_retpw.pw_dir[up->uaf$t_defdev[0] + up->uaf$t_defdir[0]] = '\0';
|
|
5016 strncpy (vms_retpw.pw_shell, &up->uaf$t_defcli[1], up->uaf$t_defcli[0]);
|
|
5017 vms_retpw.pw_shell[up->uaf$t_defcli[0]] = '\0';
|
|
5018
|
|
5019 return &vms_retpw;
|
|
5020 }
|
|
5021 #else /* not READ_SYSUAF */
|
|
5022 static struct passwd vms_retpw;
|
|
5023 #endif /* not READ_SYSUAF */
|
|
5024
|
|
5025 struct passwd *
|
|
5026 getpwnam (char *name)
|
|
5027 {
|
|
5028 #ifdef READ_SYSUAF
|
|
5029 struct UAF *up;
|
|
5030 #else
|
|
5031 char * user;
|
|
5032 char * dir;
|
|
5033 unsigned char * full;
|
|
5034 #endif /* READ_SYSUAF */
|
|
5035 char *ptr = name;
|
|
5036
|
|
5037 while (*ptr)
|
|
5038 {
|
|
5039 *ptr = toupper (* (unsigned char *) ptr);
|
|
5040 ptr++;
|
|
5041 }
|
|
5042 #ifdef READ_SYSUAF
|
|
5043 if (!(up = get_uaf_name (name)))
|
|
5044 return 0;
|
|
5045 return cnv_uaf_pw (up);
|
|
5046 #else
|
|
5047 if (strcmp (name, getenv ("USER")) == 0)
|
|
5048 {
|
|
5049 vms_retpw.pw_uid = getuid ();
|
|
5050 vms_retpw.pw_gid = getgid ();
|
|
5051 strcpy (vms_retpw.pw_name, name);
|
|
5052 if (full = egetenv ("FULLNAME"))
|
|
5053 strcpy (vms_retpw.pw_gecos, full);
|
|
5054 else
|
|
5055 *vms_retpw.pw_gecos = '\0';
|
|
5056 strcpy (vms_retpw.pw_dir, egetenv ("HOME"));
|
|
5057 *vms_retpw.pw_shell = '\0';
|
|
5058 return &vms_retpw;
|
|
5059 }
|
|
5060 else
|
|
5061 return 0;
|
|
5062 #endif /* not READ_SYSUAF */
|
|
5063 }
|
|
5064
|
|
5065 struct passwd *
|
|
5066 getpwuid (unsigned long uid)
|
|
5067 {
|
|
5068 #ifdef READ_SYSUAF
|
|
5069 struct UAF * up;
|
|
5070
|
|
5071 if (!(up = get_uaf_uic (uid)))
|
|
5072 return 0;
|
|
5073 return cnv_uaf_pw (up);
|
|
5074 #else
|
|
5075 if (uid == sys_getuid ())
|
|
5076 return getpwnam (egetenv ("USER"));
|
|
5077 else
|
|
5078 return 0;
|
|
5079 #endif /* not READ_SYSUAF */
|
|
5080 }
|
|
5081
|
|
5082 /* return total address space available to the current process. This is
|
|
5083 the sum of the current p0 size, p1 size and free page table entries
|
|
5084 available. */
|
|
5085 int
|
|
5086 vlimit (void)
|
|
5087 {
|
|
5088 int item_code;
|
|
5089 unsigned long free_pages;
|
|
5090 unsigned long frep0va;
|
|
5091 unsigned long frep1va;
|
|
5092 status;
|
|
5093
|
|
5094 item_code = JPI$_FREPTECNT;
|
|
5095 if (((status = LIB$GETJPI (&item_code, 0, 0, &free_pages)) & 1) == 0)
|
|
5096 {
|
|
5097 errno = EVMSERR;
|
|
5098 vaxc$errno = status;
|
|
5099 return -1;
|
|
5100 }
|
|
5101 free_pages *= 512;
|
|
5102
|
|
5103 item_code = JPI$_FREP0VA;
|
|
5104 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep0va)) & 1) == 0)
|
|
5105 {
|
|
5106 errno = EVMSERR;
|
|
5107 vaxc$errno = status;
|
|
5108 return -1;
|
|
5109 }
|
|
5110 item_code = JPI$_FREP1VA;
|
|
5111 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep1va)) & 1) == 0)
|
|
5112 {
|
|
5113 errno = EVMSERR;
|
|
5114 vaxc$errno = status;
|
|
5115 return -1;
|
|
5116 }
|
|
5117
|
|
5118 return free_pages + frep0va + (0x7fffffff - frep1va);
|
|
5119 }
|
|
5120
|
|
5121 int
|
|
5122 define_logical_name (char *varname, char *string)
|
|
5123 {
|
|
5124 struct dsc$descriptor_s strdsc =
|
|
5125 {strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string};
|
|
5126 struct dsc$descriptor_s envdsc =
|
|
5127 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname};
|
|
5128 struct dsc$descriptor_s lnmdsc =
|
|
5129 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"};
|
|
5130
|
|
5131 return LIB$SET_LOGICAL (&envdsc, &strdsc, &lnmdsc, 0, 0);
|
|
5132 }
|
|
5133
|
|
5134 int
|
|
5135 delete_logical_name (char *varname)
|
|
5136 {
|
|
5137 struct dsc$descriptor_s envdsc =
|
|
5138 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname};
|
|
5139 struct dsc$descriptor_s lnmdsc =
|
|
5140 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"};
|
|
5141
|
|
5142 return LIB$DELETE_LOGICAL (&envdsc, &lnmdsc);
|
|
5143 }
|
|
5144
|
|
5145 execvp (void)
|
|
5146 {
|
|
5147 error ("execvp system call not implemented");
|
|
5148 }
|
|
5149
|
|
5150 int
|
|
5151 rename (char *from, char *to)
|
|
5152 {
|
|
5153 int status;
|
|
5154 struct FAB from_fab = cc$rms_fab, to_fab = cc$rms_fab;
|
|
5155 struct NAM from_nam = cc$rms_nam, to_nam = cc$rms_nam;
|
|
5156 char from_esn[NAM$C_MAXRSS];
|
|
5157 char to_esn[NAM$C_MAXRSS];
|
|
5158
|
|
5159 from_fab.fab$l_fna = from;
|
|
5160 from_fab.fab$b_fns = strlen (from);
|
|
5161 from_fab.fab$l_nam = &from_nam;
|
|
5162 from_fab.fab$l_fop = FAB$M_NAM;
|
|
5163
|
|
5164 from_nam.nam$l_esa = from_esn;
|
|
5165 from_nam.nam$b_ess = sizeof from_esn;
|
|
5166
|
|
5167 to_fab.fab$l_fna = to;
|
|
5168 to_fab.fab$b_fns = strlen (to);
|
|
5169 to_fab.fab$l_nam = &to_nam;
|
|
5170 to_fab.fab$l_fop = FAB$M_NAM;
|
|
5171
|
|
5172 to_nam.nam$l_esa = to_esn;
|
|
5173 to_nam.nam$b_ess = sizeof to_esn;
|
|
5174
|
|
5175 status = SYS$RENAME (&from_fab, 0, 0, &to_fab);
|
|
5176
|
|
5177 if (status & 1)
|
|
5178 return 0;
|
|
5179 else
|
|
5180 {
|
|
5181 if (status == RMS$_DEV)
|
|
5182 errno = EXDEV;
|
|
5183 else
|
|
5184 errno = EVMSERR;
|
|
5185 vaxc$errno = status;
|
|
5186 return -1;
|
|
5187 }
|
|
5188 }
|
|
5189
|
|
5190 /* This function renames a file like `rename', but it strips
|
|
5191 the version number from the "to" filename, such that the "to" file is
|
|
5192 will always be a new version. It also sets the file protection once it is
|
|
5193 finished. The protection that we will use is stored in vms_fab_final_pro,
|
|
5194 and was set when we did a creat_copy_attrs to create the file that we
|
|
5195 are renaming.
|
|
5196
|
|
5197 We could use the chmod function, but Eunichs uses 3 bits per user category
|
|
5198 to describe the protection, and VMS uses 4 (write and delete are separate
|
|
5199 bits). To maintain portability, the VMS implementation of `chmod' wires
|
|
5200 the W and D bits together. */
|
|
5201
|
185
|
5202
|
0
|
5203 static char vms_file_written[NAM$C_MAXRSS];
|
|
5204
|
|
5205 int
|
|
5206 rename_sans_version (char *from, char *to)
|
|
5207 {
|
|
5208 short int chan;
|
|
5209 int stat;
|
|
5210 short int iosb[4];
|
|
5211 int status;
|
|
5212 struct fibdef fib;
|
|
5213 struct FAB to_fab = cc$rms_fab;
|
|
5214 struct NAM to_nam = cc$rms_nam;
|
|
5215 struct dsc$descriptor fib_d ={sizeof (fib),0,0,(char*) &fib};
|
|
5216 struct dsc$descriptor fib_attr[2]
|
|
5217 = {{sizeof (vms_fab_final_pro),ATR$C_FPRO,0,(char*) &vms_fab_final_pro},{0,0,0,0}};
|
|
5218 char to_esn[NAM$C_MAXRSS];
|
|
5219
|
|
5220 $DESCRIPTOR (disk,to_esn);
|
|
5221
|
|
5222 memset (&fib, 0, sizeof (fib));
|
|
5223
|
|
5224 to_fab.fab$l_fna = to;
|
|
5225 to_fab.fab$b_fns = strlen (to);
|
|
5226 to_fab.fab$l_nam = &to_nam;
|
|
5227 to_fab.fab$l_fop = FAB$M_NAM;
|
|
5228
|
|
5229 to_nam.nam$l_esa = to_esn;
|
|
5230 to_nam.nam$b_ess = sizeof to_esn;
|
|
5231
|
|
5232 status = SYS$PARSE (&to_fab, 0, 0); /* figure out the full file name */
|
|
5233
|
|
5234 if (to_nam.nam$l_fnb && NAM$M_EXP_VER)
|
|
5235 *(to_nam.nam$l_ver) = '\0';
|
|
5236
|
|
5237 stat = rename (from, to_esn);
|
|
5238 if (stat < 0)
|
|
5239 return stat;
|
|
5240
|
|
5241 strcpy (vms_file_written, to_esn);
|
|
5242
|
|
5243 to_fab.fab$l_fna = vms_file_written; /* this points to the versionless name */
|
|
5244 to_fab.fab$b_fns = strlen (vms_file_written);
|
|
5245
|
|
5246 /* Now set the file protection to the correct value */
|
|
5247 SYS$OPEN (&to_fab, 0, 0); /* This fills in the nam$w_fid fields */
|
|
5248
|
|
5249 /* Copy these fields into the fib */
|
|
5250 fib.fib$r_fid_overlay.fib$w_fid[0] = to_nam.nam$w_fid[0];
|
|
5251 fib.fib$r_fid_overlay.fib$w_fid[1] = to_nam.nam$w_fid[1];
|
|
5252 fib.fib$r_fid_overlay.fib$w_fid[2] = to_nam.nam$w_fid[2];
|
|
5253
|
|
5254 SYS$CLOSE (&to_fab, 0, 0);
|
|
5255
|
|
5256 stat = SYS$ASSIGN (&disk, &chan, 0, 0); /* open a channel to the disk */
|
|
5257 if (!stat)
|
|
5258 LIB$SIGNAL (stat);
|
|
5259 stat = SYS$QIOW (0, chan, IO$_MODIFY, iosb, 0, 0, &fib_d,
|
|
5260 0, 0, 0, &fib_attr, 0);
|
|
5261 if (!stat)
|
|
5262 LIB$SIGNAL (stat);
|
|
5263 stat = SYS$DASSGN (chan);
|
|
5264 if (!stat)
|
|
5265 LIB$SIGNAL (stat);
|
|
5266 strcpy (vms_file_written, to_esn); /* We will write this to the terminal*/
|
|
5267 return 0;
|
|
5268 }
|
|
5269
|
|
5270 int
|
|
5271 link (char *file, char *new)
|
|
5272 {
|
|
5273 status;
|
|
5274 struct FAB fab;
|
|
5275 struct NAM nam;
|
|
5276 unsigned short fid[3];
|
|
5277 char esa[NAM$C_MAXRSS];
|
|
5278
|
|
5279 fab = cc$rms_fab;
|
|
5280 fab.fab$l_fop = FAB$M_OFP;
|
|
5281 fab.fab$l_fna = file;
|
|
5282 fab.fab$b_fns = strlen (file);
|
|
5283 fab.fab$l_nam = &nam;
|
|
5284
|
|
5285 nam = cc$rms_nam;
|
|
5286 nam.nam$l_esa = esa;
|
|
5287 nam.nam$b_ess = NAM$C_MAXRSS;
|
|
5288
|
|
5289 status = SYS$PARSE (&fab);
|
|
5290 if ((status & 1) == 0)
|
|
5291 {
|
|
5292 errno = EVMSERR;
|
|
5293 vaxc$errno = status;
|
|
5294 return -1;
|
|
5295 }
|
|
5296 status = SYS$SEARCH (&fab);
|
|
5297 if ((status & 1) == 0)
|
|
5298 {
|
|
5299 errno = EVMSERR;
|
|
5300 vaxc$errno = status;
|
|
5301 return -1;
|
|
5302 }
|
|
5303
|
|
5304 fid[0] = nam.nam$w_fid[0];
|
|
5305 fid[1] = nam.nam$w_fid[1];
|
|
5306 fid[2] = nam.nam$w_fid[2];
|
|
5307
|
|
5308 fab.fab$l_fna = new;
|
|
5309 fab.fab$b_fns = strlen (new);
|
|
5310
|
|
5311 status = SYS$PARSE (&fab);
|
|
5312 if ((status & 1) == 0)
|
|
5313 {
|
|
5314 errno = EVMSERR;
|
|
5315 vaxc$errno = status;
|
|
5316 return -1;
|
|
5317 }
|
|
5318
|
|
5319 nam.nam$w_fid[0] = fid[0];
|
|
5320 nam.nam$w_fid[1] = fid[1];
|
|
5321 nam.nam$w_fid[2] = fid[2];
|
|
5322
|
|
5323 nam.nam$l_esa = nam.nam$l_name;
|
|
5324 nam.nam$b_esl = nam.nam$b_name + nam.nam$b_type + nam.nam$b_ver;
|
|
5325
|
|
5326 status = SYS$ENTER (&fab);
|
|
5327 if ((status & 1) == 0)
|
|
5328 {
|
|
5329 errno = EVMSERR;
|
|
5330 vaxc$errno = status;
|
|
5331 return -1;
|
|
5332 }
|
|
5333
|
|
5334 return 0;
|
|
5335 }
|
|
5336
|
|
5337 #ifdef getenv
|
|
5338 /* If any place else asks for the TERM variable,
|
|
5339 allow it to be overridden with the EMACS_TERM variable
|
|
5340 before attempting to translate the logical name TERM. As a last
|
|
5341 resort, ask for VAX C's special idea of the TERM variable. */
|
|
5342 #undef getenv
|
|
5343 char *
|
|
5344 sys_getenv (char *name)
|
|
5345 {
|
|
5346 char *val;
|
|
5347 static char buf[256];
|
|
5348 static struct dsc$descriptor_s equiv
|
|
5349 = {sizeof (buf), DSC$K_DTYPE_T, DSC$K_CLASS_S, buf};
|
|
5350 static struct dsc$descriptor_s d_name
|
|
5351 = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
|
|
5352 short eqlen;
|
|
5353
|
|
5354 if (!strcmp (name, "TERM"))
|
|
5355 {
|
|
5356 val = (char *) getenv ("EMACS_TERM");
|
|
5357 if (val)
|
|
5358 return val;
|
|
5359 }
|
|
5360
|
|
5361 d_name.dsc$w_length = strlen (name);
|
|
5362 d_name.dsc$a_pointer = name;
|
|
5363 if (LIB$SYS_TRNLOG (&d_name, &eqlen, &equiv) == 1)
|
|
5364 {
|
|
5365 char *str = (char *) xmalloc (eqlen + 1);
|
|
5366 memcpy (str, buf, eqlen);
|
|
5367 str[eqlen] = '\0';
|
|
5368 /* This is a storage leak, but a pain to fix. With luck,
|
|
5369 no one will ever notice. */
|
|
5370 return str;
|
|
5371 }
|
|
5372 return (char *) getenv (name);
|
|
5373 }
|
|
5374 #endif /* getenv */
|
|
5375
|
|
5376 #ifdef abort
|
|
5377 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
|
|
5378 to force a call on the debugger from within the image. */
|
|
5379 #undef abort
|
|
5380 sys_abort (void)
|
|
5381 {
|
|
5382 reset_all_consoles ();
|
|
5383 LIB$SIGNAL (SS$_DEBUG);
|
|
5384 }
|
|
5385 #endif /* abort */
|
|
5386
|
|
5387 #if 0 /* Apparently unused */
|
|
5388 /* The standard `sleep' routine works some other way
|
|
5389 and it stops working if you have ever quit out of it.
|
|
5390 This one continues to work. */
|
|
5391
|
|
5392 void
|
|
5393 sys_sleep (int timeval)
|
|
5394 {
|
|
5395 int time [2];
|
|
5396 static int zero = 0;
|
|
5397 static int large = -10000000;
|
|
5398
|
|
5399 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */
|
|
5400
|
|
5401 SYS$CANTIM (1, 0);
|
|
5402 if (SYS$SETIMR (vms_timer_ef, time, 0, 1) & 1) /* Set timer */
|
|
5403 SYS$WAITFR (vms_timer_ef); /* Wait for timer expiry only */
|
|
5404 }
|
|
5405 #endif /* 0 */
|
|
5406
|
|
5407 void
|
|
5408 bzero (register char *b, register int length)
|
|
5409 {
|
|
5410 short zero = 0;
|
|
5411 long max_str = 65535;
|
|
5412
|
|
5413 while (length > max_str) {
|
|
5414 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
|
|
5415 length -= max_str;
|
|
5416 b += max_str;
|
|
5417 }
|
|
5418 max_str = length;
|
|
5419 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b);
|
|
5420 }
|
|
5421
|
|
5422 /* Saying `void' requires a declaration, above, where bcopy is used
|
|
5423 and that declaration causes pain for systems where bcopy is a macro. */
|
|
5424 bcopy (register char *b1, register char *b2, register int length)
|
|
5425 {
|
|
5426 long max_str = 65535;
|
|
5427
|
|
5428 while (length > max_str) {
|
|
5429 (void) LIB$MOVC3 (&max_str, b1, b2);
|
|
5430 length -= max_str;
|
|
5431 b1 += max_str;
|
|
5432 b2 += max_str;
|
|
5433 }
|
|
5434 max_str = length;
|
|
5435 (void) LIB$MOVC3 (&length, b1, b2);
|
|
5436 }
|
|
5437
|
|
5438 int
|
|
5439 bcmp (register char *b1, register char *b2, register int length)
|
|
5440 /* This could be a macro! */
|
|
5441 {
|
|
5442 struct dsc$descriptor_s src1 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b1};
|
|
5443 struct dsc$descriptor_s src2 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b2};
|
|
5444
|
|
5445 return STR$COMPARE (&src1, &src2);
|
|
5446 }
|
|
5447
|
|
5448 #endif /* VMS */
|
|
5449
|
|
5450 #ifndef HAVE_STRCASECMP
|
|
5451 /*
|
|
5452 * From BSD
|
|
5453 */
|
|
5454 static unsigned char charmap[] = {
|
|
5455 '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
|
|
5456 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
|
|
5457 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
|
|
5458 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
|
|
5459 '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
|
|
5460 '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
|
|
5461 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
|
|
5462 '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
|
|
5463 '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
5464 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
5465 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
5466 '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
|
|
5467 '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
5468 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
5469 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
5470 '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
|
|
5471 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
|
|
5472 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
|
|
5473 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
|
|
5474 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
|
|
5475 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
|
|
5476 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
|
|
5477 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
|
|
5478 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
|
|
5479 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
|
|
5480 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
|
|
5481 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
|
|
5482 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
|
|
5483 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
|
|
5484 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
|
|
5485 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
|
|
5486 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
|
|
5487 };
|
|
5488
|
|
5489 int
|
|
5490 strcasecmp (char *s1, char *s2)
|
|
5491 {
|
|
5492 unsigned char *cm = charmap;
|
|
5493 unsigned char *us1 = (unsigned char *) s1;
|
|
5494 unsigned char *us2 = (unsigned char *)s2;
|
|
5495
|
|
5496 while (cm[*us1] == cm[*us2++])
|
|
5497 if (*us1++ == '\0')
|
|
5498 return (0);
|
|
5499
|
|
5500 return (cm[*us1] - cm[*--us2]);
|
|
5501 }
|
|
5502 #endif /* !HAVE_STRCASECMP */
|