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