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