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