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