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