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