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