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