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