Mercurial > emacs
annotate src/sysdep.c @ 1126:94d76dbb5ce6
* xrdb.c: Don't include <X11/Xos.h>. Under R4, it stupidly
insists on defining SIGCHLD, even if it already has a definition.
(file_p): Use the constant 4 instead of R_OK; empirically, the
number is more portable than the symbol if you count the #include
hair you have to go through to get R_OK defined. Ffile_readable_p
does this too.
* xrdb.c (getuid): Declare this to return short.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Sun, 13 Sep 1992 12:48:38 +0000 |
parents | ff73961932eb |
children | 5c942f6b2d63 |
rev | line source |
---|---|
491 | 1 /* Interfaces to system-dependent kernel and library entries. |
579 | 2 Copyright (C) 1985, 1986, 1987, 1988, 1992 Free Software Foundation, Inc. |
491 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
21 #include <signal.h> | |
22 #include <setjmp.h> | |
23 | |
24 #include "config.h" | |
25 #include "lisp.h" | |
26 #undef NULL | |
27 | |
28 #define min(x,y) ((x) > (y) ? (y) : (x)) | |
29 | |
30 /* In this file, open, read and write refer to the system calls, | |
31 not our sugared interfaces sys_open, sys_read and sys_write. | |
32 Contrariwise, for systems where we use the system calls directly, | |
33 define sys_read, etc. here as aliases for them. */ | |
34 #ifndef read | |
35 #define sys_read read | |
36 #define sys_write write | |
37 #endif /* `read' is not a macro */ | |
38 | |
39 #undef read | |
40 #undef write | |
41 | |
42 #ifndef close | |
43 #define sys_close close | |
44 #else | |
45 #undef close | |
46 #endif | |
47 | |
48 #ifndef open | |
49 #define sys_open open | |
50 #else /* `open' is a macro */ | |
51 #undef open | |
52 #endif /* `open' is a macro */ | |
53 | |
54 #include <stdio.h> | |
55 #include <sys/types.h> | |
56 #include <sys/stat.h> | |
57 #include <errno.h> | |
58 | |
59 extern int errno; | |
60 #ifndef VMS | |
61 extern char *sys_errlist[]; | |
62 #endif | |
63 | |
64 #ifdef VMS | |
65 #include <rms.h> | |
66 #include <ttdef.h> | |
67 #include <tt2def.h> | |
68 #include <iodef.h> | |
69 #include <ssdef.h> | |
70 #include <descrip.h> | |
71 #include <fibdef.h> | |
72 #include <atrdef.h> | |
73 #include <ctype.h> | |
74 #include <string.h> | |
75 #ifdef __GNUC__ | |
76 #include <sys/file.h> | |
77 #else | |
78 #include <file.h> | |
79 #endif | |
80 #undef F_SETFL | |
81 #ifndef RAB$C_BID | |
82 #include <rab.h> | |
83 #endif | |
84 #define MAXIOSIZE ( 32 * PAGESIZE ) /* Don't I/O more than 32 blocks at a time */ | |
85 #endif /* VMS */ | |
86 | |
87 #ifndef BSD4_1 | |
88 #ifdef BSD /* this is done this way to avoid defined (BSD) || defined (USG) | |
89 because the vms compiler doesn't grok `defined' */ | |
90 #include <fcntl.h> | |
91 #endif | |
92 #ifdef USG | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
93 #ifndef USG5 |
491 | 94 #include <fcntl.h> |
95 #endif | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
96 #endif |
491 | 97 #endif /* not 4.1 bsd */ |
98 | |
99 /* Get DGUX definition for FASYNC - DJB */ | |
100 #ifdef DGUX | |
101 #include <sys/file.h> | |
102 #endif /* DGUX */ | |
103 | |
104 #include <sys/ioctl.h> | |
1048
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
105 #include "systty.h" |
491 | 106 |
107 #ifdef BSD | |
108 #ifdef BSD4_1 | |
109 #include <wait.h> | |
110 #else /* not 4.1 */ | |
111 #include <sys/wait.h> | |
112 #endif /* not 4.1 */ | |
113 #endif /* BSD */ | |
114 | |
115 #ifdef BROKEN_TIOCGWINSZ | |
116 #undef TIOCGWINSZ | |
117 #endif | |
118 | |
119 #ifdef USG | |
120 #include <sys/utsname.h> | |
121 #include <string.h> | |
122 #ifndef MEMORY_IN_STRING_H | |
123 #include <memory.h> | |
124 #endif | |
125 #ifdef TIOCGWINSZ | |
126 #ifdef NEED_SIOCTL | |
127 #include <sys/sioctl.h> | |
128 #endif | |
129 #ifdef NEED_PTEM_H | |
130 #include <sys/stream.h> | |
131 #include <sys/ptem.h> | |
132 #endif | |
133 #endif /* TIOCGWINSZ */ | |
134 #endif /* USG */ | |
135 | |
136 extern int quit_char; | |
137 | |
766 | 138 #include "frame.h" |
491 | 139 #include "window.h" |
140 #include "termhooks.h" | |
141 #include "termchar.h" | |
142 #include "termopts.h" | |
143 #include "dispextern.h" | |
144 #include "process.h" | |
145 | |
146 #ifdef NONSYSTEM_DIR_LIBRARY | |
147 #include "ndir.h" | |
148 #endif /* NONSYSTEM_DIR_LIBRARY */ | |
149 | |
579 | 150 #include "syssignal.h" |
151 #include "systime.h" | |
491 | 152 |
153 static int baud_convert[] = | |
154 #ifdef BAUD_CONVERT | |
155 BAUD_CONVERT; | |
156 #else | |
157 { | |
158 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200, | |
159 1800, 2400, 4800, 9600, 19200, 38400 | |
160 }; | |
161 #endif | |
162 | |
163 extern short ospeed; | |
164 | |
579 | 165 /* The file descriptor for Emacs's input terminal. |
166 Under Unix, this is always left zero; | |
167 under VMS, we place the input channel number here. | |
168 This allows us to write more code that works for both VMS and Unix. */ | |
169 static int input_fd; | |
170 | |
491 | 171 #ifdef VMS |
172 static struct iosb | |
173 { | |
174 short status; | |
175 short offset; | |
176 short termlen; | |
177 short term; | |
178 } input_iosb; | |
179 | |
180 int kbd_input_ast (); | |
181 | |
182 int waiting_for_ast; | |
183 int stop_input; | |
184 int input_ef = 0; | |
185 int timer_ef = 0; | |
186 int process_ef = 0; | |
187 int input_eflist; | |
188 int timer_eflist; | |
189 | |
190 static $DESCRIPTOR (input_dsc, "TT"); | |
191 static int terminator_mask[2] = { 0, 0 }; | |
192 | |
193 static struct sensemode { | |
194 short status; | |
195 unsigned char xmit_baud; | |
196 unsigned char rcv_baud; | |
197 unsigned char crfill; | |
198 unsigned char lffill; | |
199 unsigned char parity; | |
200 unsigned char unused; | |
201 char class; | |
202 char type; | |
203 short scr_wid; | |
204 unsigned long tt_char : 24, scr_len : 8; | |
205 unsigned long tt2_char; | |
206 } sensemode_iosb; | |
207 #endif /* VMS */ | |
208 | |
209 discard_tty_input () | |
210 { | |
579 | 211 struct emacs_tty buf; |
491 | 212 |
213 if (noninteractive) | |
214 return; | |
215 | |
216 /* Discarding input is not safe when the input could contain | |
217 replies from the X server. So don't do it. */ | |
218 if (read_socket_hook) | |
219 return; | |
220 | |
221 #ifdef VMS | |
222 end_kbd_input (); | |
579 | 223 SYS$QIOW (0, input_fd, IO$_READVBLK|IO$M_PURGE, input_iosb, 0, 0, |
224 &buf.main, 0, 0, terminator_mask, 0, 0); | |
491 | 225 queue_kbd_input (); |
226 #else /* not VMS */ | |
227 #ifdef APOLLO | |
228 { | |
229 int zero = 0; | |
230 ioctl (0, TIOCFLUSH, &zero); | |
231 } | |
232 #else /* not Apollo */ | |
579 | 233 EMACS_GET_TTY (input_fd, &buf); |
234 EMACS_SET_TTY (input_fd, &buf, 0); | |
491 | 235 #endif /* not Apollo */ |
236 #endif /* not VMS */ | |
237 } | |
238 | |
239 #ifdef SIGTSTP | |
240 | |
241 stuff_char (c) | |
242 char c; | |
243 { | |
244 /* Should perhaps error if in batch mode */ | |
245 #ifdef TIOCSTI | |
246 ioctl (0, TIOCSTI, &c); | |
247 #else /* no TIOCSTI */ | |
248 error ("Cannot stuff terminal input characters in this version of Unix."); | |
249 #endif /* no TIOCSTI */ | |
250 } | |
251 | |
252 #endif /* SIGTSTP */ | |
253 | |
254 init_baud_rate () | |
255 { | |
256 if (noninteractive) | |
257 ospeed = 0; | |
258 else | |
259 { | |
260 #ifdef VMS | |
579 | 261 struct sensemode sg; |
262 | |
263 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0, | |
491 | 264 &sg.class, 12, 0, 0, 0, 0 ); |
579 | 265 ospeed = sg.xmit_baud; |
266 #else /* not VMS */ | |
267 #ifdef HAVE_TERMIOS | |
268 struct termios sg; | |
269 | |
270 sg.c_cflag = (sg.c_cflag & ~CBAUD) | B9600; | |
271 tcgetattr (0, &sg); | |
272 ospeed = sg.c_cflag & CBAUD; | |
1048
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
273 #else /* neither VMS nor TERMIOS */ |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
274 #ifdef HAVE_TERMIO |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
275 struct termio sg; |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
276 |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
277 sg.c_cflag = (sg.c_cflag & ~CBAUD) | B9600; |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
278 #ifdef HAVE_TCATTR |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
279 tcgetattr (0, &sg); |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
280 #else |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
281 ioctl (fd, TIOCGETP, &sg); |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
282 #endif |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
283 ospeed = sg.c_cflag & CBAUD; |
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
284 #else /* neither VMS nor TERMIOS nor TERMIO */ |
579 | 285 struct sgttyb sg; |
286 | |
287 sg.sg_ospeed = B9600; | |
288 ioctl (0, TIOCGETP, &sg); | |
289 ospeed = sg.sg_ospeed; | |
1048
9899cb2199af
* sysdep.c (init_baud_rate): Re-arranged order of conditionals -
Jim Blandy <jimb@redhat.com>
parents:
1014
diff
changeset
|
290 #endif /* not HAVE_TERMIO */ |
579 | 291 #endif /* not HAVE_TERMIOS */ |
491 | 292 #endif /* not VMS */ |
293 } | |
294 | |
295 baud_rate = (ospeed < sizeof baud_convert / sizeof baud_convert[0] | |
296 ? baud_convert[ospeed] : 9600); | |
297 if (baud_rate == 0) | |
298 baud_rate = 1200; | |
299 } | |
300 | |
301 /*ARGSUSED*/ | |
302 set_exclusive_use (fd) | |
303 int fd; | |
304 { | |
305 #ifdef FIOCLEX | |
306 ioctl (fd, FIOCLEX, 0); | |
307 #endif | |
308 /* Ok to do nothing if this feature does not exist */ | |
309 } | |
310 | |
311 #ifndef subprocesses | |
312 | |
313 wait_without_blocking () | |
314 { | |
315 #ifdef BSD | |
316 wait3 (0, WNOHANG | WUNTRACED, 0); | |
317 #else | |
318 croak ("wait_without_blocking"); | |
319 #endif | |
320 synch_process_alive = 0; | |
321 } | |
322 | |
323 #endif /* not subprocesses */ | |
324 | |
325 int wait_debugging; /* Set nonzero to make following function work under dbx | |
326 (at least for bsd). */ | |
327 | |
328 SIGTYPE | |
329 wait_for_termination_signal () | |
330 {} | |
331 | |
332 /* Wait for subprocess with process id `pid' to terminate and | |
333 make sure it will get eliminated (not remain forever as a zombie) */ | |
334 | |
335 wait_for_termination (pid) | |
336 int pid; | |
337 { | |
338 while (1) | |
339 { | |
340 #ifdef subprocesses | |
341 #ifdef VMS | |
342 int status; | |
343 | |
344 status = sys$forcex (&pid, 0, 0); | |
345 break; | |
346 #else /* not VMS */ | |
347 | |
348 /* Exit if the process has terminated. */ | |
349 if (!synch_process_alive) | |
350 break; | |
351 /* Otherwise wait 1 second or until a signal comes in. */ | |
352 signal (SIGALRM, wait_for_termination_signal); | |
353 alarm (1); | |
354 pause (); | |
355 alarm (0); | |
356 signal (SIGALRM, SIG_IGN); | |
357 #endif /* not VMS */ | |
358 #else /* not subprocesses */ | |
359 #ifndef BSD4_1 | |
360 if (kill (pid, 0) < 0) | |
361 break; | |
362 wait (0); | |
363 #else /* BSD4_1 */ | |
364 int status; | |
365 status = wait (0); | |
366 if (status == pid || status == -1) | |
367 break; | |
368 #endif /* BSD4_1 */ | |
369 #endif /* not subprocesses */ | |
370 } | |
371 } | |
372 | |
373 #ifdef subprocesses | |
374 | |
375 /* | |
376 * flush any pending output | |
377 * (may flush input as well; it does not matter the way we use it) | |
378 */ | |
379 | |
380 flush_pending_output (channel) | |
381 int channel; | |
382 { | |
383 #ifdef HAVE_TERMIOS | |
384 /* If we try this, we get hit with SIGTTIN, because | |
385 the child's tty belongs to the child's pgrp. */ | |
386 #else | |
387 #ifdef TCFLSH | |
388 ioctl (channel, TCFLSH, 1); | |
389 #else | |
390 #ifdef TIOCFLUSH | |
391 int zero = 0; | |
392 /* 3rd arg should be ignored | |
393 but some 4.2 kernels actually want the address of an int | |
394 and nonzero means something different. */ | |
395 ioctl (channel, TIOCFLUSH, &zero); | |
396 #endif | |
397 #endif | |
398 #endif | |
399 } | |
400 | |
401 #ifndef VMS | |
402 /* Set up the terminal at the other end of a pseudo-terminal that | |
403 we will be controlling an inferior through. | |
404 It should not echo or do line-editing, since that is done | |
405 in Emacs. No padding needed for insertion into an Emacs buffer. */ | |
406 | |
407 child_setup_tty (out) | |
408 int out; | |
409 { | |
579 | 410 struct emacs_tty s; |
411 | |
412 EMACS_GET_TTY (out, &s); | |
413 | |
491 | 414 #ifdef HAVE_TERMIO |
579 | 415 s.main.c_oflag |= OPOST; /* Enable output postprocessing */ |
416 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */ | |
417 s.main.c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY); | |
418 /* No output delays */ | |
419 s.main.c_lflag &= ~ECHO; /* Disable echo */ | |
420 s.main.c_lflag |= ISIG; /* Enable signals */ | |
421 s.main.c_iflag &= ~IUCLC; /* Disable map of upper case to lower on | |
422 input */ | |
423 s.main.c_oflag &= ~OLCUC; /* Disable map of lower case to upper on | |
424 output */ | |
425 #if 0 | |
426 /* Said to be unnecesary: */ | |
427 s.main.c_cc[VMIN] = 1; /* minimum number of characters to accept */ | |
428 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */ | |
429 #endif | |
430 | |
431 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */ | |
432 s.main.c_cc[VEOF] = 04; /* insure that EOF is Control-D */ | |
433 s.main.c_cc[VERASE] = 0377; /* disable erase processing */ | |
434 s.main.c_cc[VKILL] = 0377; /* disable kill processing */ | |
435 | |
491 | 436 #ifdef HPUX |
579 | 437 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */ |
491 | 438 #endif /* HPUX */ |
579 | 439 |
491 | 440 #ifdef AIX |
441 /* AIX enhanced edit loses NULs, so disable it */ | |
442 #ifndef IBMR2AIX | |
579 | 443 s.main.c_line = 0; |
444 s.main.c_iflag &= ~ASCEDIT; | |
491 | 445 #endif |
446 /* Also, PTY overloads NUL and BREAK. | |
447 don't ignore break, but don't signal either, so it looks like NUL. */ | |
579 | 448 s.main.c_iflag &= ~IGNBRK; |
449 s.main.c_iflag &= ~BRKINT; | |
450 /* QUIT and INTR work better as signals, so disable character forms */ | |
451 s.main.c_cc[VQUIT] = 0377; | |
452 s.main.c_cc[VINTR] = 0377; | |
453 s.main.c_cc[VEOL] = 0377; | |
454 s.main.c_lflag &= ~ISIG; | |
455 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */ | |
491 | 456 #endif /* AIX */ |
457 | |
458 #else /* not HAVE_TERMIO */ | |
579 | 459 |
460 s.main.sg_flags &= ~(ECHO | CRMOD | ANYP | ALLDELAY | RAW | LCASE | |
461 | CBREAK | TANDEM); | |
462 s.main.sg_erase = 0377; | |
463 s.main.sg_kill = 0377; | |
464 | |
491 | 465 #endif /* not HAVE_TERMIO */ |
466 | |
579 | 467 EMACS_SET_TTY (out, &s, 0); |
491 | 468 |
469 #ifdef BSD4_1 | |
470 if (interrupt_input) | |
471 reset_sigio (); | |
472 #endif /* BSD4_1 */ | |
473 #ifdef RTU | |
474 { | |
475 int zero = 0; | |
476 ioctl (out, FIOASYNC, &zero); | |
477 } | |
478 #endif /* RTU */ | |
479 } | |
480 #endif /* not VMS */ | |
481 | |
482 #endif /* subprocesses */ | |
483 | |
484 /*ARGSUSED*/ | |
485 setpgrp_of_tty (pid) | |
486 int pid; | |
487 { | |
648 | 488 EMACS_SET_TTY_PGRP (input_fd, &pid); |
491 | 489 } |
490 | |
491 /* Record a signal code and the handler for it. */ | |
492 struct save_signal | |
493 { | |
494 int code; | |
495 SIGTYPE (*handler) (); | |
496 }; | |
497 | |
498 /* Suspend the Emacs process; give terminal to its superior. */ | |
499 | |
500 sys_suspend () | |
501 { | |
502 #ifdef VMS | |
503 unsigned long parent_id; | |
504 | |
505 parent_id = getppid (); | |
506 if (parent_id && parent_id != 0xffffffff) | |
507 { | |
508 SIGTYPE (*oldsig)() = (int) signal (SIGINT, SIG_IGN); | |
509 int status = LIB$ATTACH (&parent_id) & 1; | |
510 signal (SIGINT, oldsig); | |
511 return status; | |
512 } | |
513 else | |
514 { | |
515 struct { | |
516 int l; | |
517 char *a; | |
518 } d_prompt; | |
519 d_prompt.l = sizeof ("Emacs: "); /* Our special prompt */ | |
520 d_prompt.a = "Emacs: "; /* Just a reminder */ | |
521 lib$spawn (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt, 0); | |
522 return 1; | |
523 } | |
524 return -1; | |
525 #else | |
526 #ifdef SIGTSTP | |
527 | |
579 | 528 EMACS_KILLPG (getpgrp (0), SIGTSTP); |
491 | 529 |
530 #else /* No SIGTSTP */ | |
531 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */ | |
532 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */ | |
533 kill (getpid (), SIGQUIT); | |
534 | |
535 #else /* No SIGTSTP or USG_JOBCTRL */ | |
536 | |
537 /* On a system where suspending is not implemented, | |
538 instead fork a subshell and let it talk directly to the terminal | |
539 while we wait. */ | |
540 int pid = fork (); | |
541 struct save_signal saved_handlers[5]; | |
542 | |
543 saved_handlers[0].code = SIGINT; | |
544 saved_handlers[1].code = SIGQUIT; | |
545 saved_handlers[2].code = SIGTERM; | |
546 #ifdef SIGIO | |
547 saved_handlers[3].code = SIGIO; | |
548 saved_handlers[4].code = 0; | |
549 #else | |
550 saved_handlers[3].code = 0; | |
551 #endif | |
552 | |
553 if (pid == -1) | |
554 error ("Can't spawn subshell"); | |
555 if (pid == 0) | |
556 { | |
557 char *sh; | |
558 | |
559 sh = (char *) egetenv ("SHELL"); | |
560 if (sh == 0) | |
561 sh = "sh"; | |
562 /* Use our buffer's default directory for the subshell. */ | |
563 { | |
564 Lisp_Object dir; | |
565 unsigned char *str; | |
566 int len; | |
567 | |
568 /* mentioning current_buffer->buffer would mean including buffer.h, | |
569 which somehow wedges the hp compiler. So instead... */ | |
570 | |
571 dir = intern ("default-directory"); | |
572 /* Can't use NULL */ | |
573 if (XFASTINT (Fboundp (dir)) == XFASTINT (Qnil)) | |
574 goto xyzzy; | |
575 dir = Fsymbol_value (dir); | |
576 if (XTYPE (dir) != Lisp_String) | |
577 goto xyzzy; | |
578 | |
579 str = (unsigned char *) alloca (XSTRING (dir)->size + 2); | |
580 len = XSTRING (dir)->size; | |
581 bcopy (XSTRING (dir)->data, str, len); | |
582 if (str[len - 1] != '/') str[len++] = '/'; | |
583 str[len] = 0; | |
584 chdir (str); | |
585 } | |
586 xyzzy: | |
587 #ifdef subprocesses | |
588 close_process_descs (); /* Close Emacs's pipes/ptys */ | |
589 #endif | |
590 nice (-nice (0)); /* Give the new shell the default piority */ | |
591 execlp (sh, sh, 0); | |
592 write (1, "Can't execute subshell", 22); | |
593 _exit (1); | |
594 } | |
595 | |
596 save_signal_handlers (saved_handlers); | |
597 wait_for_termination (pid); | |
598 restore_signal_handlers (saved_handlers); | |
599 | |
600 #endif /* no USG_JOBCTRL */ | |
601 #endif /* no SIGTSTP */ | |
602 #endif /* not VMS */ | |
603 } | |
604 | |
605 save_signal_handlers (saved_handlers) | |
606 struct save_signal *saved_handlers; | |
607 { | |
608 while (saved_handlers->code) | |
609 { | |
692 | 610 saved_handlers->handler |
611 = (SIGTYPE (*) ()) signal (saved_handlers->code, SIG_IGN); | |
491 | 612 saved_handlers++; |
613 } | |
614 } | |
615 | |
616 restore_signal_handlers (saved_handlers) | |
617 struct save_signal *saved_handlers; | |
618 { | |
619 while (saved_handlers->code) | |
620 { | |
621 signal (saved_handlers->code, saved_handlers->handler); | |
622 saved_handlers++; | |
623 } | |
624 } | |
625 | |
626 #ifdef F_SETFL | |
627 | |
628 int old_fcntl_flags; | |
629 | |
630 init_sigio () | |
631 { | |
632 #ifdef FASYNC | |
633 old_fcntl_flags = fcntl (0, F_GETFL, 0) & ~FASYNC; | |
634 #endif | |
635 request_sigio (); | |
636 } | |
637 | |
638 reset_sigio () | |
639 { | |
640 unrequest_sigio (); | |
641 } | |
642 | |
643 #ifdef FASYNC /* F_SETFL does not imply existance of FASYNC */ | |
644 | |
645 request_sigio () | |
646 { | |
647 #ifdef SIGWINCH | |
638 | 648 sigunblock (sigmask (SIGWINCH)); |
491 | 649 #endif |
650 fcntl (0, F_SETFL, old_fcntl_flags | FASYNC); | |
651 | |
652 interrupts_deferred = 0; | |
653 } | |
654 | |
655 unrequest_sigio () | |
656 { | |
657 #ifdef SIGWINCH | |
638 | 658 sigblock (sigmask (SIGWINCH)); |
491 | 659 #endif |
660 fcntl (0, F_SETFL, old_fcntl_flags); | |
661 interrupts_deferred = 1; | |
662 } | |
663 | |
664 #else /* no FASYNC */ | |
665 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */ | |
666 | |
667 request_sigio () | |
668 { | |
669 int on = 1; | |
670 ioctl (0, FIOASYNC, &on); | |
671 interrupts_deferred = 0; | |
672 } | |
673 | |
674 unrequest_sigio () | |
675 { | |
676 int off = 0; | |
677 | |
678 ioctl (0, FIOASYNC, &off); | |
679 interrupts_deferred = 1; | |
680 } | |
681 | |
682 #else /* not FASYNC, not STRIDE */ | |
683 | |
684 request_sigio () | |
685 { | |
686 croak ("request_sigio"); | |
687 } | |
688 | |
689 unrequest_sigio () | |
690 { | |
691 croak ("unrequest_sigio"); | |
692 } | |
693 | |
694 #endif /* STRIDE */ | |
695 #endif /* FASYNC */ | |
696 #endif /* F_SETFL */ | |
697 | |
579 | 698 /* The initial tty mode bits */ |
699 struct emacs_tty old_tty; | |
491 | 700 |
701 int term_initted; /* 1 if outer tty status has been recorded */ | |
702 | |
579 | 703 #ifdef BSD4_1 |
704 /* BSD 4.1 needs to keep track of the lmode bits in order to start | |
705 sigio. */ | |
706 int lmode; | |
707 #endif | |
708 | |
491 | 709 #ifdef F_SETOWN |
710 int old_fcntl_owner; | |
711 #endif /* F_SETOWN */ | |
712 | |
713 /* This may also be defined in stdio, | |
714 but if so, this does no harm, | |
715 and using the same name avoids wasting the other one's space. */ | |
716 | |
717 #if defined (USG) || defined (DGUX) | |
718 unsigned char _sobuf[BUFSIZ+8]; | |
719 #else | |
720 char _sobuf[BUFSIZ]; | |
721 #endif | |
722 | |
723 #ifdef TIOCGLTC | |
724 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1}; | |
725 #endif | |
726 #ifdef TIOCGETC | |
727 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1}; | |
728 #endif | |
729 | |
730 init_sys_modes () | |
731 { | |
579 | 732 struct emacs_tty tty; |
733 | |
491 | 734 #ifdef VMS |
735 #if 0 | |
736 static int oob_chars[2] = {0, 1 << 7}; /* catch C-g's */ | |
737 extern int (*interrupt_signal) (); | |
738 #endif | |
739 #endif | |
740 | |
741 if (noninteractive) | |
742 return; | |
743 | |
744 #ifdef VMS | |
745 if (!input_ef) | |
746 input_ef = get_kbd_event_flag (); | |
747 /* LIB$GET_EF (&input_ef); */ | |
748 SYS$CLREF (input_ef); | |
749 waiting_for_ast = 0; | |
750 if (!timer_ef) | |
751 timer_ef = get_timer_event_flag (); | |
752 /* LIB$GET_EF (&timer_ef); */ | |
753 SYS$CLREF (timer_ef); | |
754 if (!process_ef) | |
755 { | |
756 LIB$GET_EF (&process_ef); | |
757 SYS$CLREF (process_ef); | |
758 } | |
759 if (input_ef / 32 != process_ef / 32) | |
760 croak ("Input and process event flags in different clusters."); | |
761 if (input_ef / 32 != timer_ef / 32) | |
762 croak ("Input and process event flags in different clusters."); | |
763 input_eflist = ((unsigned) 1 << (input_ef % 32)) | | |
764 ((unsigned) 1 << (process_ef % 32)); | |
765 timer_eflist = ((unsigned) 1 << (input_ef % 32)) | | |
766 ((unsigned) 1 << (timer_ef % 32)); | |
767 #ifndef VMS4_4 | |
768 sys_access_reinit (); | |
769 #endif | |
770 #endif /* not VMS */ | |
579 | 771 |
772 EMACS_GET_TTY (input_fd, &old_tty); | |
773 | |
491 | 774 if (!read_socket_hook && EQ (Vwindow_system, Qnil)) |
775 { | |
579 | 776 tty = old_tty; |
491 | 777 |
778 #ifdef HAVE_TERMIO | |
579 | 779 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */ |
780 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */ | |
491 | 781 #ifdef ISTRIP |
579 | 782 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */ |
491 | 783 #endif |
579 | 784 tty.main.c_lflag &= ~ECHO; /* Disable echo */ |
785 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */ | |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
786 #ifdef IEXTEN |
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
787 tty.main.c_iflag &= ~IEXTEN; /* Disable other editing characters. */ |
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
788 #endif |
579 | 789 tty.main.c_lflag |= ISIG; /* Enable signals */ |
491 | 790 if (flow_control) |
791 { | |
579 | 792 tty.main.c_iflag |= IXON; /* Enable start/stop output control */ |
491 | 793 #ifdef IXANY |
579 | 794 tty.main.c_iflag &= ~IXANY; |
491 | 795 #endif /* IXANY */ |
796 } | |
797 else | |
579 | 798 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */ |
799 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL | |
800 on output */ | |
801 tty.main.c_oflag &= ~TAB3; /* Disable tab expansion */ | |
491 | 802 #ifdef CS8 |
803 if (meta_key) | |
804 { | |
579 | 805 tty.main.c_cflag |= CS8; /* allow 8th bit on input */ |
806 tty.main.c_cflag &= ~PARENB;/* Don't check parity */ | |
491 | 807 } |
808 #endif | |
579 | 809 tty.main.c_cc[VINTR] = quit_char; /* C-g (usually) gives SIGINT */ |
491 | 810 /* Set up C-g for both SIGQUIT and SIGINT. |
811 We don't know which we will get, but we handle both alike | |
812 so which one it really gives us does not matter. */ | |
579 | 813 tty.main.c_cc[VQUIT] = quit_char; |
814 tty.main.c_cc[VMIN] = 1; /* Input should wait for at least 1 char */ | |
815 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */ | |
491 | 816 #ifdef VSWTCH |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
817 tty.main.c_cc[VSWTCH] = CDISABLE; /* Turn off shell layering use |
579 | 818 of C-z */ |
491 | 819 #endif /* VSWTCH */ |
820 #if defined (mips) || defined (HAVE_TCATTR) | |
821 #ifdef VSUSP | |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
822 tty.main.c_cc[VSUSP] = CDISABLE; /* Turn off mips handling of C-z. */ |
491 | 823 #endif /* VSUSP */ |
824 #ifdef V_DSUSP | |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
825 tty.main.c_cc[V_DSUSP] = CDISABLE; /* Turn off mips handling of C-y. */ |
491 | 826 #endif /* V_DSUSP */ |
1102
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
827 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */ |
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
828 tty.main.c_cc[VDSUSP] = CDISABLE; |
ff73961932eb
(init_sys_modes): Handle VDSUSP like V_DSUSP.
Richard M. Stallman <rms@gnu.org>
parents:
1048
diff
changeset
|
829 #endif /* VDSUSP */ |
491 | 830 #endif /* mips or HAVE_TCATTR */ |
831 #ifdef AIX | |
832 #ifndef IBMR2AIX | |
833 /* AIX enhanced edit loses NULs, so disable it */ | |
579 | 834 tty.main.c_line = 0; |
835 tty.main.c_iflag &= ~ASCEDIT; | |
491 | 836 #else |
579 | 837 tty.main.c_cc[VSTRT] = 255; |
838 tty.main.c_cc[VSTOP] = 255; | |
839 tty.main.c_cc[VSUSP] = 255; | |
840 tty.main.c_cc[VDSUSP] = 255; | |
491 | 841 #endif /* IBMR2AIX */ |
842 /* Also, PTY overloads NUL and BREAK. | |
843 don't ignore break, but don't signal either, so it looks like NUL. | |
844 This really serves a purpose only if running in an XTERM window | |
845 or via TELNET or the like, but does no harm elsewhere. */ | |
579 | 846 tty.main.c_iflag &= ~IGNBRK; |
847 tty.main.c_iflag &= ~BRKINT; | |
491 | 848 #endif |
849 #else /* if not HAVE_TERMIO */ | |
850 #ifdef VMS | |
579 | 851 tty.main.tt_char |= TT$M_NOECHO; |
491 | 852 if (meta_key) |
579 | 853 tty.main.tt_char |= TT$M_EIGHTBIT |
491 | 854 if (flow_control) |
579 | 855 tty.main.tt_char |= TT$M_TTSYNC; |
491 | 856 else |
579 | 857 tty.main.tt_char &= ~TT$M_TTSYNC; |
858 tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON; | |
491 | 859 #else /* not VMS (BSD, that is) */ |
579 | 860 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS); |
491 | 861 if (meta_key) |
579 | 862 tty.main.sg_flags |= ANYP; |
863 tty.main.sg_flags |= interrupt_input ? RAW : CBREAK; | |
491 | 864 #endif /* not VMS (BSD, that is) */ |
865 #endif /* not HAVE_TERMIO */ | |
866 | |
579 | 867 /* If going to use CBREAK mode, we must request C-g to interrupt |
868 and turn off start and stop chars, etc. If not going to use | |
869 CBREAK mode, do this anyway so as to turn off local flow | |
870 control for user coming over network on 4.2; in this case, | |
871 only t_stopc and t_startc really matter. */ | |
872 #ifndef HAVE_TERMIO | |
873 #ifdef TIOCGETC | |
874 /* Note: if not using CBREAK mode, it makes no difference how we | |
875 set this */ | |
876 tty.tchars = new_tchars; | |
877 tty.tchars.t_intrc = quit_char; | |
878 if (flow_control) | |
879 { | |
880 tty.tchars.t_startc = '\021'; | |
881 tty.tchars.t_stopc = '\023'; | |
882 } | |
883 | |
884 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */ | |
885 #ifndef LPASS8 | |
886 #define LPASS8 0 | |
491 | 887 #endif |
579 | 888 |
889 #ifdef BSD4_1 | |
890 #define LNOFLSH 0100000 | |
891 #endif | |
892 | |
893 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH | old_tty.lmode; | |
894 | |
895 #ifdef BSD4_1 | |
896 lmode = tty.lmode; | |
897 #endif | |
898 | |
899 #endif /* TIOCGETC */ | |
900 #endif /* not HAVE_TERMIO */ | |
901 | |
902 #ifdef TIOCGLTC | |
903 tty.ltchars = new_ltchars; | |
904 #endif /* TIOCGLTC */ | |
905 | |
906 EMACS_SET_TTY (input_fd, &tty, 0); | |
491 | 907 |
908 /* This code added to insure that, if flow-control is not to be used, | |
766 | 909 we have an unlocked terminal at the start. */ |
579 | 910 |
491 | 911 #ifdef TCXONC |
912 if (!flow_control) ioctl (0, TCXONC, 1); | |
913 #endif | |
914 #ifndef APOLLO | |
915 #ifdef TIOCSTART | |
916 if (!flow_control) ioctl (0, TIOCSTART, 0); | |
917 #endif | |
918 #endif | |
919 | |
920 #ifdef AIX | |
921 hft_init (); | |
922 #ifdef IBMR2AIX | |
923 { | |
924 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it | |
925 to be only LF. This is the way that is done. */ | |
926 struct termio tty; | |
927 | |
928 if (ioctl (1, HFTGETID, &tty) != -1) | |
929 write (1, "\033[20l", 5); | |
930 } | |
931 #endif | |
932 #endif | |
933 | |
934 #ifdef VMS | |
935 /* Appears to do nothing when in PASTHRU mode. | |
579 | 936 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0, |
491 | 937 interrupt_signal, oob_chars, 0, 0, 0, 0); |
938 */ | |
939 queue_kbd_input (0); | |
940 #endif /* VMS */ | |
941 } | |
942 | |
943 #ifdef F_SETFL | |
944 #ifdef F_GETOWN /* F_SETFL does not imply existance of F_GETOWN */ | |
945 if (interrupt_input) | |
946 { | |
947 old_fcntl_owner = fcntl (0, F_GETOWN, 0); | |
948 fcntl (0, F_SETOWN, getpid ()); | |
949 init_sigio (); | |
950 } | |
951 #endif /* F_GETOWN */ | |
952 #endif /* F_SETFL */ | |
953 | |
954 #ifdef BSD4_1 | |
955 if (interrupt_input) | |
956 init_sigio (); | |
957 #endif | |
958 | |
959 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */ | |
960 #undef _IOFBF | |
961 #endif | |
962 #ifdef _IOFBF | |
963 /* This symbol is defined on recent USG systems. | |
964 Someone says without this call USG won't really buffer the file | |
965 even with a call to setbuf. */ | |
966 setvbuf (stdout, _sobuf, _IOFBF, sizeof _sobuf); | |
967 #else | |
968 setbuf (stdout, _sobuf); | |
969 #endif | |
970 set_terminal_modes (); | |
971 if (term_initted && no_redraw_on_reenter) | |
972 { | |
973 if (display_completed) | |
974 direct_output_forward_char (0); | |
975 } | |
976 else | |
977 { | |
766 | 978 frame_garbaged = 1; |
979 #ifdef MULTI_FRAME | |
980 if (FRAMEP (Vterminal_frame)) | |
981 FRAME_GARBAGED_P (XFRAME (Vterminal_frame)) = 1; | |
491 | 982 #endif |
983 } | |
579 | 984 |
491 | 985 term_initted = 1; |
986 } | |
987 | |
988 /* Return nonzero if safe to use tabs in output. | |
989 At the time this is called, init_sys_modes has not been done yet. */ | |
990 | |
991 tabs_safe_p () | |
992 { | |
579 | 993 struct emacs_tty tty; |
994 | |
995 EMACS_GET_TTY (input_fd, &tty); | |
996 return EMACS_TTY_TABS_OK (&tty); | |
491 | 997 } |
998 | |
999 /* Get terminal size from system. | |
1000 Store number of lines into *heightp and width into *widthp. | |
1001 If zero or a negative number is stored, the value is not valid. */ | |
1002 | |
766 | 1003 get_frame_size (widthp, heightp) |
491 | 1004 int *widthp, *heightp; |
1005 { | |
579 | 1006 |
1007 #ifdef TIOCGWINSZ | |
1008 | |
1009 /* BSD-style. */ | |
1010 struct winsize size; | |
1011 | |
1012 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1) | |
1013 *widthp = *heightp = 0; | |
1014 else | |
1015 { | |
1016 *widthp = size.ws_col; | |
1017 *heightp = size.ws_row; | |
1018 } | |
1019 | |
1020 #else | |
491 | 1021 #ifdef TIOCGSIZE |
579 | 1022 |
1023 /* SunOS - style. */ | |
1024 struct ttysize size; | |
1025 | |
1026 if (ioctl (input_fd, TIOCGSIZE, &size) == -1) | |
1027 *widthp = *heightp = 0; | |
1028 else | |
1029 { | |
1030 *widthp = size.ts_cols; | |
1031 *heightp = size.ts_lines; | |
1032 } | |
1033 | |
1034 #else | |
491 | 1035 #ifdef VMS |
579 | 1036 |
1037 struct sensemode tty; | |
1038 | |
1039 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0, | |
491 | 1040 &tty.class, 12, 0, 0, 0, 0); |
1041 *widthp = tty.scr_wid; | |
1042 *heightp = tty.scr_len; | |
579 | 1043 |
491 | 1044 #else /* system doesn't know size */ |
579 | 1045 |
491 | 1046 *widthp = 0; |
1047 *heightp = 0; | |
579 | 1048 |
1049 #endif /* not VMS */ | |
1050 #endif /* not SunOS-style */ | |
1051 #endif /* not BSD-style */ | |
491 | 1052 } |
579 | 1053 |
491 | 1054 |
579 | 1055 /* Prepare the terminal for exiting Emacs; move the cursor to the |
766 | 1056 bottom of the frame, turn off interrupt-driven I/O, etc. */ |
491 | 1057 reset_sys_modes () |
1058 { | |
1059 if (noninteractive) | |
1060 { | |
1061 fflush (stdout); | |
1062 return; | |
1063 } | |
1064 if (!term_initted) | |
1065 return; | |
1066 if (read_socket_hook || !EQ (Vwindow_system, Qnil)) | |
1067 return; | |
766 | 1068 cursor_to (FRAME_HEIGHT (selected_frame) - 1, 0); |
1069 clear_end_of_line (FRAME_WIDTH (selected_frame)); | |
491 | 1070 /* clear_end_of_line may move the cursor */ |
766 | 1071 cursor_to (FRAME_HEIGHT (selected_frame) - 1, 0); |
491 | 1072 #ifdef IBMR2AIX |
1073 { | |
1074 /* HFT devices normally use ^J as a LF/CR. We forced it to | |
1075 do the LF only. Now, we need to reset it. */ | |
1076 struct termio tty; | |
1077 | |
1078 if (ioctl (1, HFTGETID, &tty) != -1) | |
1079 write (1, "\033[20h", 5); | |
1080 } | |
1081 #endif | |
1082 | |
1083 reset_terminal_modes (); | |
1084 fflush (stdout); | |
1085 #ifdef BSD | |
1086 #ifndef BSD4_1 | |
1087 /* Avoid possible loss of output when changing terminal modes. */ | |
1088 fsync (fileno (stdout)); | |
1089 #endif | |
1090 #endif | |
579 | 1091 |
491 | 1092 #ifdef F_SETFL |
1093 #ifdef F_SETOWN /* F_SETFL does not imply existance of F_SETOWN */ | |
1094 if (interrupt_input) | |
1095 { | |
1096 reset_sigio (); | |
1097 fcntl (0, F_SETOWN, old_fcntl_owner); | |
1098 } | |
1099 #endif /* F_SETOWN */ | |
1100 #endif /* F_SETFL */ | |
1101 #ifdef BSD4_1 | |
1102 if (interrupt_input) | |
1103 reset_sigio (); | |
1104 #endif /* BSD4_1 */ | |
579 | 1105 |
1106 while (EMACS_SET_TTY (input_fd, &old_tty, 0) < 0 && errno == EINTR) | |
1107 ; | |
491 | 1108 |
1109 #ifdef AIX | |
1110 hft_reset (); | |
1111 #endif | |
1112 } | |
1113 | |
1114 #ifdef HAVE_PTYS | |
1115 | |
1116 /* Set up the proper status flags for use of a pty. */ | |
1117 | |
1118 setup_pty (fd) | |
1119 int fd; | |
1120 { | |
1121 /* I'm told that TOICREMOTE does not mean control chars | |
1122 "can't be sent" but rather that they don't have | |
1123 input-editing or signaling effects. | |
1124 That should be good, because we have other ways | |
1125 to do those things in Emacs. | |
1126 However, telnet mode seems not to work on 4.2. | |
1127 So TIOCREMOTE is turned off now. */ | |
1128 | |
1129 /* Under hp-ux, if TIOCREMOTE is turned on, some calls | |
1130 will hang. In particular, the "timeout" feature (which | |
1131 causes a read to return if there is no data available) | |
1132 does this. Also it is known that telnet mode will hang | |
1133 in such a way that Emacs must be stopped (perhaps this | |
1134 is the same problem). | |
1135 | |
1136 If TIOCREMOTE is turned off, then there is a bug in | |
1137 hp-ux which sometimes loses data. Apparently the | |
1138 code which blocks the master process when the internal | |
1139 buffer fills up does not work. Other than this, | |
1140 though, everything else seems to work fine. | |
1141 | |
1142 Since the latter lossage is more benign, we may as well | |
1143 lose that way. -- cph */ | |
1144 #ifdef FIONBIO | |
1145 #ifdef SYSV_PTYS | |
1146 { | |
1147 int on = 1; | |
1148 ioctl (fd, FIONBIO, &on); | |
1149 } | |
1150 #endif | |
1151 #endif | |
1152 #ifdef IBMRTAIX | |
1153 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */ | |
1154 /* ignore SIGHUP once we've started a child on a pty. Note that this may */ | |
1155 /* cause EMACS not to die when it should, i.e., when its own controlling */ | |
1156 /* tty goes away. I've complained to the AIX developers, and they may */ | |
1157 /* change this behavior, but I'm not going to hold my breath. */ | |
1158 signal (SIGHUP, SIG_IGN); | |
1159 #endif | |
1160 } | |
1161 #endif /* HAVE_PTYS */ | |
1162 | |
1163 #ifdef VMS | |
1164 | |
1165 /* Assigning an input channel is done at the start of Emacs execution. | |
1166 This is called each time Emacs is resumed, also, but does nothing | |
1167 because input_chain is no longer zero. */ | |
1168 | |
1169 init_vms_input () | |
1170 { | |
1171 int status; | |
1172 | |
579 | 1173 if (input_fd == 0) |
491 | 1174 { |
579 | 1175 status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0); |
491 | 1176 if (! (status & 1)) |
1177 LIB$STOP (status); | |
1178 } | |
1179 } | |
1180 | |
1181 /* Deassigning the input channel is done before exiting. */ | |
1182 | |
1183 stop_vms_input () | |
1184 { | |
579 | 1185 return SYS$DASSGN (input_fd); |
491 | 1186 } |
1187 | |
1188 short input_buffer; | |
1189 | |
1190 /* Request reading one character into the keyboard buffer. | |
1191 This is done as soon as the buffer becomes empty. */ | |
1192 | |
1193 queue_kbd_input () | |
1194 { | |
1195 int status; | |
1196 waiting_for_ast = 0; | |
1197 stop_input = 0; | |
579 | 1198 status = SYS$QIO (0, input_fd, IO$_READVBLK, |
491 | 1199 &input_iosb, kbd_input_ast, 1, |
1200 &input_buffer, 1, 0, terminator_mask, 0, 0); | |
1201 } | |
1202 | |
1203 int input_count; | |
1204 | |
1205 /* Ast routine that is called when keyboard input comes in | |
1206 in accord with the SYS$QIO above. */ | |
1207 | |
1208 kbd_input_ast () | |
1209 { | |
1210 register int c = -1; | |
1211 int old_errno = errno; | |
648 | 1212 extern EMACS_TIME *input_available_clear_time; |
491 | 1213 |
1214 if (waiting_for_ast) | |
1215 SYS$SETEF (input_ef); | |
1216 waiting_for_ast = 0; | |
1217 input_count++; | |
1218 #ifdef ASTDEBUG | |
1219 if (input_count == 25) | |
1220 exit (1); | |
1221 printf ("Ast # %d,", input_count); | |
1222 printf (" iosb = %x, %x, %x, %x", | |
1223 input_iosb.offset, input_iosb.status, input_iosb.termlen, | |
1224 input_iosb.term); | |
1225 #endif | |
1226 if (input_iosb.offset) | |
1227 { | |
1228 c = input_buffer; | |
1229 #ifdef ASTDEBUG | |
1230 printf (", char = 0%o", c); | |
1231 #endif | |
1232 } | |
1233 #ifdef ASTDEBUG | |
1234 printf ("\n"); | |
1235 fflush (stdout); | |
1236 sleep (1); | |
1237 #endif | |
1238 if (! stop_input) | |
1239 queue_kbd_input (); | |
1240 if (c >= 0) | |
1241 { | |
1242 struct input_event e; | |
1243 e.kind = ascii_keystroke; | |
1244 XSET (buf[i].code, Lisp_Int, cbuf[i]); | |
766 | 1245 e.frame = selected_frame; |
491 | 1246 kbd_buffer_store_event (&e); |
1247 } | |
1248 | |
648 | 1249 if (input_available_clear_time) |
1250 EMACS_SET_SECS_USECS (*input_available_clear_time, 0, 0); | |
491 | 1251 errno = old_errno; |
1252 } | |
1253 | |
1254 /* Wait until there is something in kbd_buffer. */ | |
1255 | |
1256 wait_for_kbd_input () | |
1257 { | |
1258 extern int have_process_input, process_exited; | |
1259 | |
1260 /* If already something, avoid doing system calls. */ | |
1261 if (detect_input_pending ()) | |
1262 { | |
1263 return; | |
1264 } | |
1265 /* Clear a flag, and tell ast routine above to set it. */ | |
1266 SYS$CLREF (input_ef); | |
1267 waiting_for_ast = 1; | |
1268 /* Check for timing error: ast happened while we were doing that. */ | |
1269 if (!detect_input_pending ()) | |
1270 { | |
1271 /* No timing error: wait for flag to be set. */ | |
1272 set_waiting_for_input (0); | |
1273 SYS$WFLOR (input_ef, input_eflist); | |
1274 clear_waiting_for_input (0); | |
1275 if (!detect_input_pending ()) | |
1276 /* Check for subprocess input availability */ | |
1277 { | |
1278 int dsp = have_process_input || process_exited; | |
1279 | |
1280 SYS$CLREF (process_ef); | |
1281 if (have_process_input) | |
1282 process_command_input (); | |
1283 if (process_exited) | |
1284 process_exit (); | |
1285 if (dsp) | |
1286 { | |
1287 update_mode_lines++; | |
1288 redisplay_preserve_echo_area (); | |
1289 } | |
1290 } | |
1291 } | |
1292 waiting_for_ast = 0; | |
1293 } | |
1294 | |
1295 /* Get rid of any pending QIO, when we are about to suspend | |
1296 or when we want to throw away pending input. | |
1297 We wait for a positive sign that the AST routine has run | |
1298 and therefore there is no I/O request queued when we return. | |
1299 SYS$SETAST is used to avoid a timing error. */ | |
1300 | |
1301 end_kbd_input () | |
1302 { | |
1303 #ifdef ASTDEBUG | |
1304 printf ("At end_kbd_input.\n"); | |
1305 fflush (stdout); | |
1306 sleep (1); | |
1307 #endif | |
1308 if (LIB$AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */ | |
1309 { | |
579 | 1310 SYS$CANCEL (input_fd); |
491 | 1311 return; |
1312 } | |
1313 | |
1314 SYS$SETAST (0); | |
1315 /* Clear a flag, and tell ast routine above to set it. */ | |
1316 SYS$CLREF (input_ef); | |
1317 waiting_for_ast = 1; | |
1318 stop_input = 1; | |
579 | 1319 SYS$CANCEL (input_fd); |
491 | 1320 SYS$SETAST (1); |
1321 SYS$WAITFR (input_ef); | |
1322 waiting_for_ast = 0; | |
1323 } | |
1324 | |
1325 /* Wait for either input available or time interval expiry. */ | |
1326 | |
1327 input_wait_timeout (timeval) | |
1328 int timeval; /* Time to wait, in seconds */ | |
1329 { | |
1330 int time [2]; | |
1331 static int zero = 0; | |
1332 static int large = -10000000; | |
1333 | |
1334 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */ | |
1335 | |
1336 /* If already something, avoid doing system calls. */ | |
1337 if (detect_input_pending ()) | |
1338 { | |
1339 return; | |
1340 } | |
1341 /* Clear a flag, and tell ast routine above to set it. */ | |
1342 SYS$CLREF (input_ef); | |
1343 waiting_for_ast = 1; | |
1344 /* Check for timing error: ast happened while we were doing that. */ | |
1345 if (!detect_input_pending ()) | |
1346 { | |
1347 /* No timing error: wait for flag to be set. */ | |
1348 SYS$CANTIM (1, 0); | |
1349 if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */ | |
1350 SYS$WFLOR (timer_ef, timer_eflist); /* Wait for timer expiry or input */ | |
1351 } | |
1352 waiting_for_ast = 0; | |
1353 } | |
1354 | |
1355 /* The standard `sleep' routine works some other way | |
1356 and it stops working if you have ever quit out of it. | |
1357 This one continues to work. */ | |
1358 | |
1359 sys_sleep (timeval) | |
1360 int timeval; | |
1361 { | |
1362 int time [2]; | |
1363 static int zero = 0; | |
1364 static int large = -10000000; | |
1365 | |
1366 LIB$EMUL (&timeval, &large, &zero, time); /* Convert to VMS format */ | |
1367 | |
1368 SYS$CANTIM (1, 0); | |
1369 if (SYS$SETIMR (timer_ef, time, 0, 1) & 1) /* Set timer */ | |
1370 SYS$WAITFR (timer_ef); /* Wait for timer expiry only */ | |
1371 } | |
1372 | |
1373 init_sigio () | |
1374 { | |
1375 request_sigio (); | |
1376 } | |
1377 | |
1378 reset_sigio () | |
1379 { | |
1380 unrequest_sigio (); | |
1381 } | |
1382 | |
1383 request_sigio () | |
1384 { | |
1385 croak ("request sigio"); | |
1386 } | |
1387 | |
1388 unrequest_sigio () | |
1389 { | |
1390 croak ("unrequest sigio"); | |
1391 } | |
1392 | |
1393 #endif /* VMS */ | |
1394 | |
1395 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */ | |
1396 #ifndef CANNOT_DUMP | |
1397 #define NEED_STARTS | |
1398 #endif | |
1399 | |
1400 #ifndef SYSTEM_MALLOC | |
1401 #ifndef NEED_STARTS | |
1402 #define NEED_STARTS | |
1403 #endif | |
1404 #endif | |
1405 | |
1406 #ifdef NEED_STARTS | |
1407 /* Some systems that cannot dump also cannot implement these. */ | |
1408 | |
1409 /* | |
1410 * Return the address of the start of the text segment prior to | |
1411 * doing an unexec. After unexec the return value is undefined. | |
1412 * See crt0.c for further explanation and _start. | |
1413 * | |
1414 */ | |
1415 | |
1416 #ifndef CANNOT_UNEXEC | |
1417 char * | |
1418 start_of_text () | |
1419 { | |
1420 #ifdef TEXT_START | |
1421 return ((char *) TEXT_START); | |
1422 #else | |
1423 #ifdef GOULD | |
1424 extern csrt (); | |
1425 return ((char *) csrt); | |
1426 #else /* not GOULD */ | |
1427 extern int _start (); | |
1428 return ((char *) _start); | |
1429 #endif /* GOULD */ | |
1430 #endif /* TEXT_START */ | |
1431 } | |
1432 #endif /* not CANNOT_UNEXEC */ | |
1433 | |
1434 /* | |
1435 * Return the address of the start of the data segment prior to | |
1436 * doing an unexec. After unexec the return value is undefined. | |
1437 * See crt0.c for further information and definition of data_start. | |
1438 * | |
1439 * Apparently, on BSD systems this is etext at startup. On | |
1440 * USG systems (swapping) this is highly mmu dependent and | |
1441 * is also dependent on whether or not the program is running | |
1442 * with shared text. Generally there is a (possibly large) | |
1443 * gap between end of text and start of data with shared text. | |
1444 * | |
1445 * On Uniplus+ systems with shared text, data starts at a | |
1446 * fixed address. Each port (from a given oem) is generally | |
1447 * different, and the specific value of the start of data can | |
1448 * be obtained via the UniPlus+ specific "uvar" system call, | |
1449 * however the method outlined in crt0.c seems to be more portable. | |
1450 * | |
1451 * Probably what will have to happen when a USG unexec is available, | |
1452 * at least on UniPlus, is temacs will have to be made unshared so | |
1453 * that text and data are contiguous. Then once loadup is complete, | |
1454 * unexec will produce a shared executable where the data can be | |
1455 * at the normal shared text boundry and the startofdata variable | |
1456 * will be patched by unexec to the correct value. | |
1457 * | |
1458 */ | |
1459 | |
1460 char * | |
1461 start_of_data () | |
1462 { | |
1463 #ifdef DATA_START | |
1464 return ((char *) DATA_START); | |
1465 #else | |
1466 extern int data_start; | |
1467 return ((char *) &data_start); | |
1468 #endif | |
1469 } | |
1470 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */ | |
1471 | |
1472 #ifndef CANNOT_DUMP | |
1473 /* Some systems that cannot dump also cannot implement these. */ | |
1474 | |
1475 /* | |
1476 * Return the address of the end of the text segment prior to | |
1477 * doing an unexec. After unexec the return value is undefined. | |
1478 */ | |
1479 | |
1480 char * | |
1481 end_of_text () | |
1482 { | |
1483 #ifdef TEXT_END | |
1484 return ((char *) TEXT_END); | |
1485 #else | |
1486 extern int etext; | |
1487 return ((char *) &etext); | |
1488 #endif | |
1489 } | |
1490 | |
1491 /* | |
1492 * Return the address of the end of the data segment prior to | |
1493 * doing an unexec. After unexec the return value is undefined. | |
1494 */ | |
1495 | |
1496 char * | |
1497 end_of_data () | |
1498 { | |
1499 #ifdef DATA_END | |
1500 return ((char *) DATA_END); | |
1501 #else | |
1502 extern int edata; | |
1503 return ((char *) &edata); | |
1504 #endif | |
1505 } | |
1506 | |
1507 #endif /* not CANNOT_DUMP */ | |
1508 | |
1509 /* Get_system_name returns as its value | |
1510 a string for the Lisp function system-name to return. */ | |
1511 | |
1512 #ifdef BSD4_1 | |
1513 #include <whoami.h> | |
1514 #endif | |
1515 | |
1516 #ifdef USG | |
1517 /* Can't have this within the function since `static' is #defined to nothing */ | |
1518 static struct utsname get_system_name_name; | |
1519 #endif | |
1520 | |
1521 char * | |
1522 get_system_name () | |
1523 { | |
1524 #ifdef USG | |
1525 uname (&get_system_name_name); | |
1526 return (get_system_name_name.nodename); | |
1527 #else /* Not USG */ | |
1528 #ifdef BSD4_1 | |
1529 return sysname; | |
1530 #else /* not USG, not 4.1 */ | |
1531 static char system_name_saved[32]; | |
1532 #ifdef VMS | |
1533 char *sp; | |
1534 if ((sp = egetenv ("SYS$NODE")) == 0) | |
1535 sp = "vax-vms"; | |
1536 else | |
1537 { | |
1538 char *end; | |
1539 | |
1540 if ((end = index (sp, ':')) != 0) | |
1541 *end = '\0'; | |
1542 } | |
1543 strcpy (system_name_saved, sp); | |
1544 #else /* not VMS */ | |
1545 gethostname (system_name_saved, sizeof (system_name_saved)); | |
1546 #endif /* not VMS */ | |
1547 return system_name_saved; | |
1548 #endif /* not USG, not 4.1 */ | |
1549 #endif /* not USG */ | |
1550 } | |
1551 | |
1552 #ifndef VMS | |
1553 #ifndef HAVE_SELECT | |
1554 | |
1555 #ifdef HAVE_X_WINDOWS | |
1556 /* Cause explanatory error message at compile time, | |
1557 since the select emulation is not good enough for X. */ | |
1558 int *x = &x_windows_lose_if_no_select_system_call; | |
1559 #endif | |
1560 | |
1561 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs | |
1562 * Only checks read descriptors. | |
1563 */ | |
1564 /* How long to wait between checking fds in select */ | |
1565 #define SELECT_PAUSE 1 | |
1566 int select_alarmed; | |
1567 | |
1568 /* For longjmp'ing back to read_input_waiting. */ | |
1569 | |
1570 jmp_buf read_alarm_throw; | |
1571 | |
1572 /* Nonzero if the alarm signal should throw back to read_input_waiting. | |
1573 The read_socket_hook function sets this to 1 while it is waiting. */ | |
1574 | |
1575 int read_alarm_should_throw; | |
1576 | |
1577 SIGTYPE | |
1578 select_alarm () | |
1579 { | |
1580 select_alarmed = 1; | |
1581 #ifdef BSD4_1 | |
1582 sigrelse (SIGALRM); | |
1583 #else /* not BSD4_1 */ | |
1584 signal (SIGALRM, SIG_IGN); | |
1585 #endif /* not BSD4_1 */ | |
1586 if (read_alarm_should_throw) | |
1587 longjmp (read_alarm_throw, 1); | |
1588 } | |
1589 | |
1590 /* Only rfds are checked. */ | |
1591 int | |
1592 select (nfds, rfds, wfds, efds, timeout) | |
1593 int nfds; | |
1594 int *rfds, *wfds, *efds, *timeout; | |
1595 { | |
1596 int ravail = 0, orfds = 0, old_alarm; | |
1597 int timeoutval = timeout ? *timeout : 100000; | |
1598 int *local_timeout = &timeoutval; | |
1599 extern int proc_buffered_char[]; | |
1600 #ifndef subprocesses | |
1601 int process_tick = 0, update_tick = 0; | |
1602 #else | |
1603 extern int process_tick, update_tick; | |
1604 #endif | |
1605 SIGTYPE (*old_trap) (); | |
1606 unsigned char buf; | |
1607 | |
1608 if (rfds) | |
1609 { | |
1610 orfds = *rfds; | |
1611 *rfds = 0; | |
1612 } | |
1613 if (wfds) | |
1614 *wfds = 0; | |
1615 if (efds) | |
1616 *efds = 0; | |
1617 | |
1618 /* If we are looking only for the terminal, with no timeout, | |
1619 just read it and wait -- that's more efficient. */ | |
1620 if (orfds == 1 && *local_timeout == 100000 && process_tick == update_tick) | |
1621 { | |
1622 if (! detect_input_pending ()) | |
1623 read_input_waiting (); | |
1624 *rfds = 1; | |
1625 return 1; | |
1626 } | |
1627 | |
1628 /* Once a second, till the timer expires, check all the flagged read | |
1629 * descriptors to see if any input is available. If there is some then | |
1630 * set the corresponding bit in the return copy of rfds. | |
1631 */ | |
1632 while (1) | |
1633 { | |
1634 register int to_check, bit, fd; | |
1635 | |
1636 if (rfds) | |
1637 { | |
1638 for (to_check = nfds, bit = 1, fd = 0; --to_check >= 0; bit <<= 1, fd++) | |
1639 { | |
1640 if (orfds & bit) | |
1641 { | |
1642 int avail = 0, status = 0; | |
1643 | |
1644 if (bit == 1) | |
1645 avail = detect_input_pending (); /* Special keyboard handler */ | |
1646 else | |
1647 { | |
1648 #ifdef FIONREAD | |
1649 status = ioctl (fd, FIONREAD, &avail); | |
1650 #else /* no FIONREAD */ | |
1651 /* Hoping it will return -1 if nothing available | |
1652 or 0 if all 0 chars requested are read. */ | |
1653 if (proc_buffered_char[fd] >= 0) | |
1654 avail = 1; | |
1655 else | |
1656 { | |
1657 avail = read (fd, &buf, 1); | |
1658 if (avail > 0) | |
1659 proc_buffered_char[fd] = buf; | |
1660 } | |
1661 #endif /* no FIONREAD */ | |
1662 } | |
1663 if (status >= 0 && avail > 0) | |
1664 { | |
1665 (*rfds) |= bit; | |
1666 ravail++; | |
1667 } | |
1668 } | |
1669 } | |
1670 } | |
1671 if (*local_timeout == 0 || ravail != 0 || process_tick != update_tick) | |
1672 break; | |
1673 old_alarm = alarm (0); | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
1674 old_trap = signal (SIGALRM, select_alarm); |
491 | 1675 select_alarmed = 0; |
1676 alarm (SELECT_PAUSE); | |
1677 /* Wait for a SIGALRM (or maybe a SIGTINT) */ | |
1678 while (select_alarmed == 0 && *local_timeout != 0 | |
1679 && process_tick == update_tick) | |
1680 { | |
1681 /* If we are interested in terminal input, | |
1682 wait by reading the terminal. | |
1683 That makes instant wakeup for terminal input at least. */ | |
1684 if (orfds & 1) | |
1685 { | |
1686 read_input_waiting (); | |
1687 if (detect_input_pending ()) | |
1688 select_alarmed = 1; | |
1689 } | |
1690 else | |
1691 pause (); | |
1692 } | |
1693 (*local_timeout) -= SELECT_PAUSE; | |
1694 /* Reset the old alarm if there was one */ | |
1695 alarm (0); | |
1696 signal (SIGALRM, old_trap); | |
1697 if (old_alarm != 0) | |
1698 { | |
1699 /* Reset or forge an interrupt for the original handler. */ | |
1700 old_alarm -= SELECT_PAUSE; | |
1701 if (old_alarm <= 0) | |
1702 kill (getpid (), SIGALRM); /* Fake an alarm with the orig' handler */ | |
1703 else | |
1704 alarm (old_alarm); | |
1705 } | |
1706 if (*local_timeout == 0) /* Stop on timer being cleared */ | |
1707 break; | |
1708 } | |
1709 return ravail; | |
1710 } | |
1711 | |
1712 /* Read keyboard input into the standard buffer, | |
1713 waiting for at least one character. */ | |
1714 | |
1715 /* Make all keyboard buffers much bigger when using X windows. */ | |
1716 #ifdef HAVE_X_WINDOWS | |
1717 #define BUFFER_SIZE_FACTOR 16 | |
1718 #else | |
1719 #define BUFFER_SIZE_FACTOR 1 | |
1720 #endif | |
1721 | |
1722 read_input_waiting () | |
1723 { | |
1724 char buf[256 * BUFFER_SIZE_FACTOR]; | |
1725 struct input_event e; | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
1726 int nread, i; |
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
1727 extern int quit_char; |
491 | 1728 |
1729 if (read_socket_hook) | |
1730 { | |
1731 read_alarm_should_throw = 0; | |
1732 if (! setjmp (read_alarm_throw)) | |
1733 nread = (*read_socket_hook) (0, buf, 256 * BUFFER_SIZE_FACTOR, 1, 0); | |
1734 else | |
1735 nread = -1; | |
1736 } | |
1737 else | |
1738 nread = read (fileno (stdin), buf, 1); | |
1739 | |
1740 /* Scan the chars for C-g and store them in kbd_buffer. */ | |
1741 e.kind = ascii_keystroke; | |
766 | 1742 e.frame = selected_frame; |
491 | 1743 for (i = 0; i < nread; i++) |
1744 { | |
1745 XSET (e.code, Lisp_Int, buf[i]); | |
1746 kbd_buffer_store_event (&e); | |
1747 /* Don't look at input that follows a C-g too closely. | |
1748 This reduces lossage due to autorepeat on C-g. */ | |
1014
6e25f9b75841
* sysdep.c (select): There's no need to cast the return value of
Jim Blandy <jimb@redhat.com>
parents:
766
diff
changeset
|
1749 if (buf[i] == quit_char) |
491 | 1750 break; |
1751 } | |
1752 } | |
1753 | |
1754 #endif /* not HAVE_SELECT */ | |
1755 #endif /* not VMS */ | |
1756 | |
1757 #ifdef BSD4_1 | |
1758 /* VARARGS */ | |
1759 setpriority () | |
1760 { | |
1761 return 0; | |
1762 } | |
1763 | |
1764 /* | |
1765 * Partially emulate 4.2 open call. | |
1766 * open is defined as this in 4.1. | |
1767 * | |
1768 * - added by Michael Bloom @ Citicorp/TTI | |
1769 * | |
1770 */ | |
1771 | |
1772 int | |
1773 sys_open (path, oflag, mode) | |
1774 char *path; | |
1775 int oflag, mode; | |
1776 { | |
1777 if (oflag & O_CREAT) | |
1778 return creat (path, mode); | |
1779 else | |
1780 return open (path, oflag); | |
1781 } | |
1782 | |
1783 init_sigio () | |
1784 { | |
1785 if (noninteractive) | |
1786 return; | |
1787 lmode = LINTRUP | lmode; | |
1788 ioctl (0, TIOCLSET, &lmode); | |
1789 } | |
1790 | |
1791 reset_sigio () | |
1792 { | |
1793 if (noninteractive) | |
1794 return; | |
1795 lmode = ~LINTRUP & lmode; | |
1796 ioctl (0, TIOCLSET, &lmode); | |
1797 } | |
1798 | |
1799 request_sigio () | |
1800 { | |
1801 sigrelse (SIGTINT); | |
1802 | |
1803 interrupts_deferred = 0; | |
1804 } | |
1805 | |
1806 unrequest_sigio () | |
1807 { | |
1808 sighold (SIGTINT); | |
1809 | |
1810 interrupts_deferred = 1; | |
1811 } | |
1812 | |
1813 /* still inside #ifdef BSD4_1 */ | |
1814 #ifdef subprocesses | |
1815 | |
1816 int sigheld; /* Mask of held signals */ | |
1817 | |
1818 sigholdx (signum) | |
1819 int signum; | |
1820 { | |
1821 sigheld |= sigbit (signum); | |
1822 sighold (signum); | |
1823 } | |
1824 | |
1825 sigisheld (signum) | |
1826 int signum; | |
1827 { | |
1828 sigheld |= sigbit (signum); | |
1829 } | |
1830 | |
1831 sigunhold (signum) | |
1832 int signum; | |
1833 { | |
1834 sigheld &= ~sigbit (signum); | |
1835 sigrelse (signum); | |
1836 } | |
1837 | |
1838 sigfree () /* Free all held signals */ | |
1839 { | |
1840 int i; | |
1841 for (i = 0; i < NSIG; i++) | |
1842 if (sigheld & sigbit (i)) | |
1843 sigrelse (i); | |
1844 sigheld = 0; | |
1845 } | |
1846 | |
1847 sigbit (i) | |
1848 { | |
1849 return 1 << (i - 1); | |
1850 } | |
1851 #endif /* subprocesses */ | |
1852 #endif /* BSD4_1 */ | |
1853 | |
1854 /* POSIX signals support - DJB */ | |
1855 /* Anyone with POSIX signals should have ANSI C declarations */ | |
1856 | |
1857 #ifdef POSIX_SIGNALS | |
1858 | |
1859 sigset_t old_mask, empty_mask, full_mask, temp_mask; | |
1860 static struct sigaction new_action, old_action; | |
1861 | |
1862 init_signals () | |
1863 { | |
1864 #ifdef POSIX_SIGNALS | |
1865 sigemptyset (&signal_empty_mask); | |
1866 sigfillset (&signal_full_mask); | |
1867 #endif | |
1868 } | |
1869 | |
1870 int (*signal_handler_t) (); | |
1871 | |
1872 signal_handler_t | |
1873 sys_signal (int signal_number, signal_handler_t action) | |
1874 { | |
1875 #ifdef DGUX | |
1876 /* This gets us restartable system calls for efficiency. | |
1877 The "else" code will works as well. */ | |
1878 return (berk_signal (signal_number, action)); | |
1879 #else | |
1880 sigemptyset (&new_action.sa_mask); | |
1881 new_action.sa_handler = action; | |
1882 new_action.sa_flags = NULL; | |
709 | 1883 sigaction (signal_number, &new_action, &old_action); |
491 | 1884 return (old_action.sa_handler); |
1885 #endif /* DGUX */ | |
1886 } | |
1887 | |
638 | 1888 #ifndef __GNUC__ |
1889 /* If we're compiling with GCC, we don't need this function, since it | |
1890 can be written as a macro. */ | |
1891 sigset_t | |
1892 sys_sigmask (int sig) | |
1893 { | |
1894 sigset_t mask; | |
1895 sigemptyset (&mask); | |
1896 sigaddset (&mask, sig); | |
1897 return mask; | |
1898 } | |
1899 #endif | |
1900 | |
491 | 1901 int |
1902 sys_sigpause (sigset_t new_mask) | |
1903 { | |
1904 /* pause emulating berk sigpause... */ | |
1905 sigsuspend (&new_mask); | |
1906 return (EINTR); | |
1907 } | |
1908 | |
1909 /* I'd like to have these guys return pointers to the mask storage in here, | |
1910 but there'd be trouble if the code was saving multiple masks. I'll be | |
1911 safe and pass the structure. It normally won't be more than 2 bytes | |
1912 anyhow. - DJB */ | |
1913 | |
1914 sigset_t | |
1915 sys_sigblock (sigset_t new_mask) | |
1916 { | |
1917 sigset_t old_mask; | |
1918 sigprocmask (SIG_BLOCK, &new_mask, &old_mask); | |
1919 return (old_mask); | |
1920 } | |
1921 | |
1922 sigset_t | |
1923 sys_sigunblock (sigset_t new_mask) | |
1924 { | |
1925 sigset_t old_mask; | |
1926 sigprocmask (SIG_UNBLOCK, &new_mask, &old_mask); | |
1927 return (old_mask); | |
1928 } | |
1929 | |
1930 sigset_t | |
1931 sys_sigsetmask (sigset_t new_mask) | |
1932 { | |
1933 sigset_t old_mask; | |
1934 sigprocmask (SIG_SETMASK, &new_mask, &old_mask); | |
1935 return (old_mask); | |
1936 } | |
1937 | |
1938 #endif /* POSIX_SIGNALS */ | |
1939 | |
1940 #ifndef BSTRING | |
1941 | |
1942 void | |
1943 bzero (b, length) | |
1944 register char *b; | |
1945 register int length; | |
1946 { | |
1947 #ifdef VMS | |
1948 short zero = 0; | |
1949 long max_str = 65535; | |
1950 | |
1951 while (length > max_str) { | |
1952 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b); | |
1953 length -= max_str; | |
1954 b += max_str; | |
1955 } | |
1956 max_str = length; | |
1957 (void) LIB$MOVC5 (&zero, &zero, &zero, &max_str, b); | |
1958 #else | |
1959 while (length-- > 0) | |
1960 *b++ = 0; | |
1961 #endif /* not VMS */ | |
1962 } | |
1963 | |
1964 /* Saying `void' requires a declaration, above, where bcopy is used | |
1965 and that declaration causes pain for systems where bcopy is a macro. */ | |
1966 bcopy (b1, b2, length) | |
1967 register char *b1; | |
1968 register char *b2; | |
1969 register int length; | |
1970 { | |
1971 #ifdef VMS | |
1972 long max_str = 65535; | |
1973 | |
1974 while (length > max_str) { | |
1975 (void) LIB$MOVC3 (&max_str, b1, b2); | |
1976 length -= max_str; | |
1977 b1 += max_str; | |
1978 b2 += max_str; | |
1979 } | |
1980 max_str = length; | |
1981 (void) LIB$MOVC3 (&length, b1, b2); | |
1982 #else | |
1983 while (length-- > 0) | |
1984 *b2++ = *b1++; | |
1985 #endif /* not VMS */ | |
1986 } | |
1987 | |
1988 int | |
1989 bcmp (b1, b2, length) /* This could be a macro! */ | |
1990 register char *b1; | |
1991 register char *b2; | |
1992 register int length; | |
1993 { | |
1994 #ifdef VMS | |
1995 struct dsc$descriptor_s src1 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b1}; | |
1996 struct dsc$descriptor_s src2 = {length, DSC$K_DTYPE_T, DSC$K_CLASS_S, b2}; | |
1997 | |
1998 return STR$COMPARE (&src1, &src2); | |
1999 #else | |
2000 while (length-- > 0) | |
2001 if (*b1++ != *b2++) | |
2002 return 1; | |
2003 | |
2004 return 0; | |
2005 #endif /* not VMS */ | |
2006 } | |
2007 #endif /* not BSTRING */ | |
2008 | |
2009 #ifdef USG | |
2010 /* | |
2011 * The BSD random returns numbers in the range of | |
2012 * 0 to 2e31 - 1. The USG rand returns numbers in the | |
2013 * range of 0 to 2e15 - 1. This is probably not significant | |
2014 * in this usage. | |
2015 */ | |
2016 | |
2017 long | |
2018 random () | |
2019 { | |
2020 /* Arrange to return a range centered on zero. */ | |
2021 return (rand () << 15) + rand () - (1 << 29); | |
2022 } | |
2023 | |
2024 srandom (arg) | |
2025 int arg; | |
2026 { | |
2027 srand (arg); | |
2028 } | |
2029 | |
2030 #endif /* USG */ | |
2031 | |
2032 #ifdef BSD4_1 | |
2033 long random () | |
2034 { | |
2035 /* Arrange to return a range centered on zero. */ | |
2036 return (rand () << 15) + rand () - (1 << 29); | |
2037 } | |
2038 | |
2039 srandom (arg) | |
2040 int arg; | |
2041 { | |
2042 srand (arg); | |
2043 } | |
2044 #endif /* BSD4_1 */ | |
2045 | |
2046 #ifdef WRONG_NAME_INSQUE | |
2047 | |
2048 insque (q,p) | |
2049 caddr_t q,p; | |
2050 { | |
2051 _insque (q,p); | |
2052 } | |
2053 | |
2054 #endif | |
2055 | |
2056 #ifdef VMS | |
2057 | |
2058 #ifdef getenv | |
2059 /* If any place else asks for the TERM variable, | |
2060 allow it to be overridden with the EMACS_TERM variable | |
2061 before attempting to translate the logical name TERM. As a last | |
2062 resort, ask for VAX C's special idea of the TERM variable. */ | |
2063 #undef getenv | |
2064 char * | |
2065 sys_getenv (name) | |
2066 char *name; | |
2067 { | |
2068 register char *val; | |
2069 static char buf[256]; | |
2070 static struct dsc$descriptor_s equiv | |
2071 = {sizeof (buf), DSC$K_DTYPE_T, DSC$K_CLASS_S, buf}; | |
2072 static struct dsc$descriptor_s d_name | |
2073 = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0}; | |
2074 short eqlen; | |
2075 | |
2076 if (!strcmp (name, "TERM")) | |
2077 { | |
2078 val = (char *) getenv ("EMACS_TERM"); | |
2079 if (val) | |
2080 return val; | |
2081 } | |
2082 | |
2083 d_name.dsc$w_length = strlen (name); | |
2084 d_name.dsc$a_pointer = name; | |
2085 if (lib$sys_trnlog (&d_name, &eqlen, &equiv) == 1) | |
2086 { | |
2087 char *str = (char *) xmalloc (eqlen + 1); | |
2088 bcopy (buf, str, eqlen); | |
2089 str[eqlen] = '\0'; | |
2090 /* This is a storage leak, but a pain to fix. With luck, | |
2091 no one will ever notice. */ | |
2092 return str; | |
2093 } | |
2094 return (char *) getenv (name); | |
2095 } | |
2096 #endif /* getenv */ | |
2097 | |
2098 #ifdef abort | |
2099 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is | |
2100 to force a call on the debugger from within the image. */ | |
2101 #undef abort | |
2102 sys_abort () | |
2103 { | |
2104 reset_sys_modes (); | |
2105 LIB$SIGNAL (SS$_DEBUG); | |
2106 } | |
2107 #endif /* abort */ | |
2108 #endif /* VMS */ | |
2109 | |
2110 #ifdef VMS | |
2111 #ifdef LINK_CRTL_SHARE | |
2112 #ifdef SHAREABLE_LIB_BUG | |
2113 /* Variables declared noshare and initialized in shareable libraries | |
2114 cannot be shared. The VMS linker incorrectly forces you to use a private | |
2115 version which is uninitialized... If not for this "feature", we | |
2116 could use the C library definition of sys_nerr and sys_errlist. */ | |
2117 int sys_nerr = 35; | |
2118 char *sys_errlist[] = | |
2119 { | |
2120 "error 0", | |
2121 "not owner", | |
2122 "no such file or directory", | |
2123 "no such process", | |
2124 "interrupted system call", | |
2125 "i/o error", | |
2126 "no such device or address", | |
2127 "argument list too long", | |
2128 "exec format error", | |
2129 "bad file number", | |
2130 "no child process", | |
2131 "no more processes", | |
2132 "not enough memory", | |
2133 "permission denied", | |
2134 "bad address", | |
2135 "block device required", | |
2136 "mount devices busy", | |
2137 "file exists", | |
2138 "cross-device link", | |
2139 "no such device", | |
2140 "not a directory", | |
2141 "is a directory", | |
2142 "invalid argument", | |
2143 "file table overflow", | |
2144 "too many open files", | |
2145 "not a typewriter", | |
2146 "text file busy", | |
2147 "file too big", | |
2148 "no space left on device", | |
2149 "illegal seek", | |
2150 "read-only file system", | |
2151 "too many links", | |
2152 "broken pipe", | |
2153 "math argument", | |
2154 "result too large", | |
2155 "I/O stream empty", | |
2156 "vax/vms specific error code nontranslatable error" | |
2157 }; | |
2158 #endif /* SHAREABLE_LIB_BUG */ | |
2159 #endif /* LINK_CRTL_SHARE */ | |
2160 #endif /* VMS */ | |
2161 | |
2162 #ifdef INTERRUPTIBLE_OPEN | |
2163 | |
2164 int | |
2165 /* VARARGS 2 */ | |
2166 sys_open (path, oflag, mode) | |
2167 char *path; | |
2168 int oflag, mode; | |
2169 { | |
2170 register int rtnval; | |
2171 | |
2172 while ((rtnval = open (path, oflag, mode)) == -1 | |
2173 && (errno == EINTR)); | |
2174 return (rtnval); | |
2175 } | |
2176 | |
2177 #endif /* INTERRUPTIBLE_OPEN */ | |
2178 | |
2179 #ifdef INTERRUPTIBLE_CLOSE | |
2180 | |
2181 sys_close (fd) | |
2182 int fd; | |
2183 { | |
2184 register int rtnval; | |
2185 | |
2186 while ((rtnval = close (fd)) == -1 | |
2187 && (errno == EINTR)); | |
2188 return rtnval; | |
2189 } | |
2190 | |
2191 #endif /* INTERRUPTIBLE_CLOSE */ | |
2192 | |
2193 #ifdef INTERRUPTIBLE_IO | |
2194 | |
2195 int | |
2196 sys_read (fildes, buf, nbyte) | |
2197 int fildes; | |
2198 char *buf; | |
2199 unsigned int nbyte; | |
2200 { | |
2201 register int rtnval; | |
2202 | |
2203 while ((rtnval = read (fildes, buf, nbyte)) == -1 | |
2204 && (errno == EINTR)); | |
2205 return (rtnval); | |
2206 } | |
2207 | |
2208 int | |
2209 sys_write (fildes, buf, nbyte) | |
2210 int fildes; | |
2211 char *buf; | |
2212 unsigned int nbyte; | |
2213 { | |
2214 register int rtnval; | |
2215 | |
2216 while ((rtnval = write (fildes, buf, nbyte)) == -1 | |
2217 && (errno == EINTR)); | |
2218 return (rtnval); | |
2219 } | |
2220 | |
2221 #endif /* INTERRUPTIBLE_IO */ | |
2222 | |
2223 #ifdef USG | |
2224 /* | |
2225 * All of the following are for USG. | |
2226 * | |
2227 * On USG systems the system calls are INTERRUPTIBLE by signals | |
2228 * that the user program has elected to catch. Thus the system call | |
2229 * must be retried in these cases. To handle this without massive | |
2230 * changes in the source code, we remap the standard system call names | |
2231 * to names for our own functions in sysdep.c that do the system call | |
2232 * with retries. Actually, for portability reasons, it is good | |
2233 * programming practice, as this example shows, to limit all actual | |
2234 * system calls to a single occurance in the source. Sure, this | |
2235 * adds an extra level of function call overhead but it is almost | |
2236 * always negligible. Fred Fish, Unisoft Systems Inc. | |
2237 */ | |
2238 | |
2239 char *sys_siglist[NSIG + 1] = | |
2240 { | |
2241 #ifdef AIX | |
2242 /* AIX has changed the signals a bit */ | |
2243 "bogus signal", /* 0 */ | |
2244 "hangup", /* 1 SIGHUP */ | |
2245 "interrupt", /* 2 SIGINT */ | |
2246 "quit", /* 3 SIGQUIT */ | |
2247 "illegal instruction", /* 4 SIGILL */ | |
2248 "trace trap", /* 5 SIGTRAP */ | |
2249 "IOT instruction", /* 6 SIGIOT */ | |
2250 "crash likely", /* 7 SIGDANGER */ | |
2251 "floating point exception", /* 8 SIGFPE */ | |
2252 "kill", /* 9 SIGKILL */ | |
2253 "bus error", /* 10 SIGBUS */ | |
2254 "segmentation violation", /* 11 SIGSEGV */ | |
2255 "bad argument to system call", /* 12 SIGSYS */ | |
2256 "write on a pipe with no one to read it", /* 13 SIGPIPE */ | |
2257 "alarm clock", /* 14 SIGALRM */ | |
2258 "software termination signum", /* 15 SIGTERM */ | |
2259 "user defined signal 1", /* 16 SIGUSR1 */ | |
2260 "user defined signal 2", /* 17 SIGUSR2 */ | |
2261 "death of a child", /* 18 SIGCLD */ | |
2262 "power-fail restart", /* 19 SIGPWR */ | |
2263 "bogus signal", /* 20 */ | |
2264 "bogus signal", /* 21 */ | |
2265 "bogus signal", /* 22 */ | |
2266 "bogus signal", /* 23 */ | |
2267 "bogus signal", /* 24 */ | |
2268 "LAN I/O interrupt", /* 25 SIGAIO */ | |
2269 "PTY I/O interrupt", /* 26 SIGPTY */ | |
2270 "I/O intervention required", /* 27 SIGIOINT */ | |
2271 "HFT grant", /* 28 SIGGRANT */ | |
2272 "HFT retract", /* 29 SIGRETRACT */ | |
2273 "HFT sound done", /* 30 SIGSOUND */ | |
2274 "HFT input ready", /* 31 SIGMSG */ | |
2275 #else /* not AIX */ | |
2276 "bogus signal", /* 0 */ | |
2277 "hangup", /* 1 SIGHUP */ | |
2278 "interrupt", /* 2 SIGINT */ | |
2279 "quit", /* 3 SIGQUIT */ | |
2280 "illegal instruction", /* 4 SIGILL */ | |
2281 "trace trap", /* 5 SIGTRAP */ | |
2282 "IOT instruction", /* 6 SIGIOT */ | |
2283 "EMT instruction", /* 7 SIGEMT */ | |
2284 "floating point exception", /* 8 SIGFPE */ | |
2285 "kill", /* 9 SIGKILL */ | |
2286 "bus error", /* 10 SIGBUS */ | |
2287 "segmentation violation", /* 11 SIGSEGV */ | |
2288 "bad argument to system call", /* 12 SIGSYS */ | |
2289 "write on a pipe with no one to read it", /* 13 SIGPIPE */ | |
2290 "alarm clock", /* 14 SIGALRM */ | |
2291 "software termination signum", /* 15 SIGTERM */ | |
2292 "user defined signal 1", /* 16 SIGUSR1 */ | |
2293 "user defined signal 2", /* 17 SIGUSR2 */ | |
2294 "death of a child", /* 18 SIGCLD */ | |
2295 "power-fail restart", /* 19 SIGPWR */ | |
2296 #endif /* not AIX */ | |
2297 0 | |
2298 }; | |
2299 | |
2300 /* | |
2301 * Warning, this function may not duplicate 4.2 action properly | |
2302 * under error conditions. | |
2303 */ | |
2304 | |
2305 #ifndef MAXPATHLEN | |
2306 /* In 4.1, param.h fails to define this. */ | |
2307 #define MAXPATHLEN 1024 | |
2308 #endif | |
2309 | |
2310 #ifndef HAVE_GETWD | |
2311 | |
2312 char * | |
2313 getwd (pathname) | |
2314 char *pathname; | |
2315 { | |
2316 char *npath, *spath; | |
2317 extern char *getcwd (); | |
2318 | |
2319 spath = npath = getcwd ((char *) 0, MAXPATHLEN); | |
2320 /* On Altos 3068, getcwd can return @hostname/dir, so discard | |
2321 up to first slash. Should be harmless on other systems. */ | |
2322 while (*npath && *npath != '/') | |
2323 npath++; | |
2324 strcpy (pathname, npath); | |
2325 free (spath); /* getcwd uses malloc */ | |
2326 return pathname; | |
2327 } | |
2328 | |
2329 #endif /* HAVE_GETWD */ | |
2330 | |
2331 /* | |
2332 * Emulate rename using unlink/link. Note that this is | |
2333 * only partially correct. Also, doesn't enforce restriction | |
2334 * that files be of same type (regular->regular, dir->dir, etc). | |
2335 */ | |
2336 | |
621 | 2337 #ifndef HAVE_RENAME |
2338 | |
491 | 2339 rename (from, to) |
2340 char *from; | |
2341 char *to; | |
2342 { | |
2343 if (access (from, 0) == 0) | |
2344 { | |
2345 unlink (to); | |
2346 if (link (from, to) == 0) | |
2347 if (unlink (from) == 0) | |
2348 return (0); | |
2349 } | |
2350 return (-1); | |
2351 } | |
2352 | |
621 | 2353 #endif |
2354 | |
491 | 2355 /* Set priority value to PRIO. */ |
2356 | |
621 | 2357 int |
491 | 2358 setpriority (which, who, prio) |
2359 int which, who, prio; | |
2360 { | |
2361 int nice (); | |
2362 | |
2363 nice (prio - nice (0)); | |
2364 return (0); | |
2365 } | |
2366 | |
2367 #ifndef HAVE_VFORK | |
2368 | |
2369 /* | |
2370 * Substitute fork for vfork on USG flavors. | |
2371 */ | |
2372 | |
2373 vfork () | |
2374 { | |
2375 return (fork ()); | |
2376 } | |
2377 | |
2378 #endif /* not HAVE_VFORK */ | |
2379 | |
2380 #ifdef MISSING_UTIMES | |
2381 | |
2382 /* HPUX (among others) sets HAVE_TIMEVAL but does not implement utimes. */ | |
2383 | |
2384 utimes () | |
2385 { | |
2386 } | |
2387 #endif | |
2388 | |
2389 #ifdef IRIS_UTIME | |
2390 | |
2391 /* The IRIS (3.5) has timevals, but uses sys V utime, and doesn't have the | |
2392 utimbuf structure defined anywhere but in the man page. */ | |
2393 | |
2394 struct utimbuf | |
2395 { | |
2396 long actime; | |
2397 long modtime; | |
2398 }; | |
2399 | |
2400 utimes (name, tvp) | |
2401 char *name; | |
2402 struct timeval tvp[]; | |
2403 { | |
2404 struct utimbuf utb; | |
2405 utb.actime = tvp[0].tv_sec; | |
2406 utb.modtime = tvp[1].tv_sec; | |
2407 utime (name, &utb); | |
2408 } | |
2409 #endif /* IRIS_UTIME */ | |
2410 | |
2411 | |
2412 #ifdef HPUX | |
2413 #ifndef HAVE_PERROR | |
2414 | |
2415 /* HPUX curses library references perror, but as far as we know | |
2416 it won't be called. Anyway this definition will do for now. */ | |
2417 | |
2418 perror () | |
2419 { | |
2420 } | |
2421 | |
2422 #endif /* not HAVE_PERROR */ | |
2423 #endif /* HPUX */ | |
2424 | |
2425 #ifndef HAVE_DUP2 | |
2426 | |
2427 /* | |
2428 * Emulate BSD dup2. First close newd if it already exists. | |
2429 * Then, attempt to dup oldd. If not successful, call dup2 recursively | |
2430 * until we are, then close the unsuccessful ones. | |
2431 */ | |
2432 | |
2433 dup2 (oldd, newd) | |
2434 int oldd; | |
2435 int newd; | |
2436 { | |
2437 register int fd, ret; | |
2438 | |
2439 sys_close (newd); | |
2440 | |
2441 #ifdef F_DUPFD | |
2442 fd = fcntl (oldd, F_DUPFD, newd); | |
2443 if (fd != newd) | |
2444 error ("can't dup2 (%i,%i) : %s", oldd, newd, sys_errlist[errno]); | |
2445 #else | |
2446 fd = dup (old); | |
2447 if (fd == -1) | |
2448 return -1; | |
2449 if (fd == new) | |
2450 return new; | |
2451 ret = dup2 (old,new); | |
2452 sys_close (fd); | |
2453 return ret; | |
2454 #endif | |
2455 } | |
2456 | |
2457 #endif /* not HAVE_DUP2 */ | |
2458 | |
2459 /* | |
2460 * Gettimeofday. Simulate as much as possible. Only accurate | |
2461 * to nearest second. Emacs doesn't use tzp so ignore it for now. | |
2462 * Only needed when subprocesses are defined. | |
2463 */ | |
2464 | |
2465 #ifdef subprocesses | |
2466 #ifndef VMS | |
2467 #ifndef HAVE_GETTIMEOFDAY | |
2468 #ifdef HAVE_TIMEVAL | |
2469 | |
2470 /* ARGSUSED */ | |
2471 gettimeofday (tp, tzp) | |
2472 struct timeval *tp; | |
2473 struct timezone *tzp; | |
2474 { | |
2475 extern long time (); | |
2476 | |
2477 tp->tv_sec = time ((long *)0); | |
2478 tp->tv_usec = 0; | |
2479 tzp->tz_minuteswest = -1; | |
2480 } | |
2481 | |
2482 #endif | |
2483 #endif | |
2484 #endif | |
2485 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */ | |
2486 | |
2487 /* | |
2488 * This function will go away as soon as all the stubs fixed. (fnf) | |
2489 */ | |
2490 | |
2491 croak (badfunc) | |
2492 char *badfunc; | |
2493 { | |
2494 printf ("%s not yet implemented\r\n", badfunc); | |
2495 reset_sys_modes (); | |
2496 exit (1); | |
2497 } | |
2498 | |
2499 #endif /* USG */ | |
2500 | |
2501 #ifdef DGUX | |
2502 | |
2503 char *sys_siglist[NSIG + 1] = | |
2504 { | |
2505 "null signal", /* 0 SIGNULL */ | |
2506 "hangup", /* 1 SIGHUP */ | |
2507 "interrupt", /* 2 SIGINT */ | |
2508 "quit", /* 3 SIGQUIT */ | |
2509 "illegal instruction", /* 4 SIGILL */ | |
2510 "trace trap", /* 5 SIGTRAP */ | |
2511 "abort termination", /* 6 SIGABRT */ | |
2512 "SIGEMT", /* 7 SIGEMT */ | |
2513 "floating point exception", /* 8 SIGFPE */ | |
2514 "kill", /* 9 SIGKILL */ | |
2515 "bus error", /* 10 SIGBUS */ | |
2516 "segmentation violation", /* 11 SIGSEGV */ | |
2517 "bad argument to system call", /* 12 SIGSYS */ | |
2518 "write on a pipe with no reader", /* 13 SIGPIPE */ | |
2519 "alarm clock", /* 14 SIGALRM */ | |
2520 "software termination signal", /* 15 SIGTERM */ | |
2521 "user defined signal 1", /* 16 SIGUSR1 */ | |
2522 "user defined signal 2", /* 17 SIGUSR2 */ | |
2523 "child stopped or terminated", /* 18 SIGCLD */ | |
2524 "power-fail restart", /* 19 SIGPWR */ | |
2525 "window size changed", /* 20 SIGWINCH */ | |
2526 "undefined", /* 21 */ | |
2527 "pollable event occured", /* 22 SIGPOLL */ | |
2528 "sendable stop signal not from tty", /* 23 SIGSTOP */ | |
2529 "stop signal from tty", /* 24 SIGSTP */ | |
2530 "continue a stopped process", /* 25 SIGCONT */ | |
2531 "attempted background tty read", /* 26 SIGTTIN */ | |
2532 "attempted background tty write", /* 27 SIGTTOU */ | |
2533 "undefined", /* 28 */ | |
2534 "undefined", /* 29 */ | |
2535 "undefined", /* 30 */ | |
2536 "undefined", /* 31 */ | |
2537 "undefined", /* 32 */ | |
2538 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */ | |
2539 "I/O is possible", /* 34 SIGIO */ | |
2540 "exceeded cpu time limit", /* 35 SIGXCPU */ | |
2541 "exceeded file size limit", /* 36 SIGXFSZ */ | |
2542 "virtual time alarm", /* 37 SIGVTALRM */ | |
2543 "profiling time alarm", /* 38 SIGPROF */ | |
2544 "undefined", /* 39 */ | |
2545 "file record locks revoked", /* 40 SIGLOST */ | |
2546 "undefined", /* 41 */ | |
2547 "undefined", /* 42 */ | |
2548 "undefined", /* 43 */ | |
2549 "undefined", /* 44 */ | |
2550 "undefined", /* 45 */ | |
2551 "undefined", /* 46 */ | |
2552 "undefined", /* 47 */ | |
2553 "undefined", /* 48 */ | |
2554 "undefined", /* 49 */ | |
2555 "undefined", /* 50 */ | |
2556 "undefined", /* 51 */ | |
2557 "undefined", /* 52 */ | |
2558 "undefined", /* 53 */ | |
2559 "undefined", /* 54 */ | |
2560 "undefined", /* 55 */ | |
2561 "undefined", /* 56 */ | |
2562 "undefined", /* 57 */ | |
2563 "undefined", /* 58 */ | |
2564 "undefined", /* 59 */ | |
2565 "undefined", /* 60 */ | |
2566 "undefined", /* 61 */ | |
2567 "undefined", /* 62 */ | |
2568 "undefined", /* 63 */ | |
2569 "notification message in mess. queue", /* 64 SIGDGNOTIFY */ | |
2570 0 | |
2571 }; | |
2572 | |
2573 #endif /* DGUX */ | |
2574 | |
2575 /* Directory routines for systems that don't have them. */ | |
2576 | |
2577 #ifdef SYSV_SYSTEM_DIR | |
2578 | |
2579 #include <dirent.h> | |
2580 | |
2581 #ifndef AIX | |
2582 int | |
2583 closedir (dirp) | |
2584 register DIR *dirp; /* stream from opendir */ | |
2585 { | |
2586 sys_close (dirp->dd_fd); | |
2587 free ((char *) dirp->dd_buf); /* directory block defined in <dirent.h> */ | |
2588 free ((char *) dirp); | |
2589 } | |
2590 #endif /* not AIX */ | |
2591 #endif /* SYSV_SYSTEM_DIR */ | |
2592 | |
2593 #ifdef NONSYSTEM_DIR_LIBRARY | |
2594 | |
2595 DIR * | |
2596 opendir (filename) | |
2597 char *filename; /* name of directory */ | |
2598 { | |
2599 register DIR *dirp; /* -> malloc'ed storage */ | |
2600 register int fd; /* file descriptor for read */ | |
2601 struct stat sbuf; /* result of fstat */ | |
2602 | |
2603 fd = sys_open (filename, 0); | |
2604 if (fd < 0) | |
2605 return 0; | |
2606 | |
2607 if (fstat (fd, &sbuf) < 0 | |
2608 || (sbuf.st_mode & S_IFMT) != S_IFDIR | |
2609 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0) | |
2610 { | |
2611 sys_close (fd); | |
2612 return 0; /* bad luck today */ | |
2613 } | |
2614 | |
2615 dirp->dd_fd = fd; | |
2616 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */ | |
2617 | |
2618 return dirp; | |
2619 } | |
2620 | |
2621 void | |
2622 closedir (dirp) | |
2623 register DIR *dirp; /* stream from opendir */ | |
2624 { | |
2625 sys_close (dirp->dd_fd); | |
2626 free ((char *) dirp); | |
2627 } | |
2628 | |
2629 | |
2630 #ifndef VMS | |
2631 #define DIRSIZ 14 | |
2632 struct olddir | |
2633 { | |
2634 ino_t od_ino; /* inode */ | |
2635 char od_name[DIRSIZ]; /* filename */ | |
2636 }; | |
2637 #endif /* not VMS */ | |
2638 | |
2639 struct direct dir_static; /* simulated directory contents */ | |
2640 | |
2641 /* ARGUSED */ | |
2642 struct direct * | |
2643 readdir (dirp) | |
2644 register DIR *dirp; /* stream from opendir */ | |
2645 { | |
2646 #ifndef VMS | |
2647 register struct olddir *dp; /* -> directory data */ | |
2648 #else /* VMS */ | |
2649 register struct dir$_name *dp; /* -> directory data */ | |
2650 register struct dir$_version *dv; /* -> version data */ | |
2651 #endif /* VMS */ | |
2652 | |
2653 for (; ;) | |
2654 { | |
2655 if (dirp->dd_loc >= dirp->dd_size) | |
2656 dirp->dd_loc = dirp->dd_size = 0; | |
2657 | |
2658 if (dirp->dd_size == 0 /* refill buffer */ | |
2659 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0) | |
2660 return 0; | |
2661 | |
2662 #ifndef VMS | |
2663 dp = (struct olddir *) &dirp->dd_buf[dirp->dd_loc]; | |
2664 dirp->dd_loc += sizeof (struct olddir); | |
2665 | |
2666 if (dp->od_ino != 0) /* not deleted entry */ | |
2667 { | |
2668 dir_static.d_ino = dp->od_ino; | |
2669 strncpy (dir_static.d_name, dp->od_name, DIRSIZ); | |
2670 dir_static.d_name[DIRSIZ] = '\0'; | |
2671 dir_static.d_namlen = strlen (dir_static.d_name); | |
2672 dir_static.d_reclen = sizeof (struct direct) | |
2673 - MAXNAMLEN + 3 | |
2674 + dir_static.d_namlen - dir_static.d_namlen % 4; | |
2675 return &dir_static; /* -> simulated structure */ | |
2676 } | |
2677 #else /* VMS */ | |
2678 dp = (struct dir$_name *) dirp->dd_buf; | |
2679 if (dirp->dd_loc == 0) | |
2680 dirp->dd_loc = (dp->dir$b_namecount&1) ? dp->dir$b_namecount + 1 | |
2681 : dp->dir$b_namecount; | |
2682 dv = (struct dir$_version *)&dp->dir$t_name[dirp->dd_loc]; | |
2683 dir_static.d_ino = dv->dir$w_fid_num; | |
2684 dir_static.d_namlen = dp->dir$b_namecount; | |
2685 dir_static.d_reclen = sizeof (struct direct) | |
2686 - MAXNAMLEN + 3 | |
2687 + dir_static.d_namlen - dir_static.d_namlen % 4; | |
2688 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount); | |
2689 dir_static.d_name[dir_static.d_namlen] = '\0'; | |
2690 dirp->dd_loc = dirp->dd_size; /* only one record at a time */ | |
2691 return &dir_static; | |
2692 #endif /* VMS */ | |
2693 } | |
2694 } | |
2695 | |
2696 #ifdef VMS | |
2697 /* readdirver is just like readdir except it returns all versions of a file | |
2698 as separate entries. */ | |
2699 | |
2700 /* ARGUSED */ | |
2701 struct direct * | |
2702 readdirver (dirp) | |
2703 register DIR *dirp; /* stream from opendir */ | |
2704 { | |
2705 register struct dir$_name *dp; /* -> directory data */ | |
2706 register struct dir$_version *dv; /* -> version data */ | |
2707 | |
2708 if (dirp->dd_loc >= dirp->dd_size - sizeof (struct dir$_name)) | |
2709 dirp->dd_loc = dirp->dd_size = 0; | |
2710 | |
2711 if (dirp->dd_size == 0 /* refill buffer */ | |
2712 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0) | |
2713 return 0; | |
2714 | |
2715 dp = (struct dir$_name *) dirp->dd_buf; | |
2716 if (dirp->dd_loc == 0) | |
2717 dirp->dd_loc = (dp->dir$b_namecount & 1) ? dp->dir$b_namecount + 1 | |
2718 : dp->dir$b_namecount; | |
2719 dv = (struct dir$_version *) &dp->dir$t_name[dirp->dd_loc]; | |
2720 strncpy (dir_static.d_name, dp->dir$t_name, dp->dir$b_namecount); | |
2721 sprintf (&dir_static.d_name[dp->dir$b_namecount], ";%d", dv->dir$w_version); | |
2722 dir_static.d_namlen = strlen (dir_static.d_name); | |
2723 dir_static.d_ino = dv->dir$w_fid_num; | |
2724 dir_static.d_reclen = sizeof (struct direct) - MAXNAMLEN + 3 | |
2725 + dir_static.d_namlen - dir_static.d_namlen % 4; | |
2726 dirp->dd_loc = ((char *) (++dv) - dp->dir$t_name); | |
2727 return &dir_static; | |
2728 } | |
2729 | |
2730 #endif /* VMS */ | |
2731 | |
2732 #endif /* NONSYSTEM_DIR_LIBRARY */ | |
2733 | |
2734 /* Functions for VMS */ | |
2735 #ifdef VMS | |
579 | 2736 #include "vms-pwd.h" |
491 | 2737 #include <acldef.h> |
2738 #include <chpdef.h> | |
2739 #include <jpidef.h> | |
2740 | |
2741 /* Return as a string the VMS error string pertaining to STATUS. | |
2742 Reuses the same static buffer each time it is called. */ | |
2743 | |
2744 char * | |
2745 vmserrstr (status) | |
2746 int status; /* VMS status code */ | |
2747 { | |
2748 int bufadr[2]; | |
2749 short len; | |
2750 static char buf[257]; | |
2751 | |
2752 bufadr[0] = sizeof buf - 1; | |
2753 bufadr[1] = (int) buf; | |
2754 if (! (SYS$GETMSG (status, &len, bufadr, 0x1, 0) & 1)) | |
2755 return "untranslatable VMS error status"; | |
2756 buf[len] = '\0'; | |
2757 return buf; | |
2758 } | |
2759 | |
2760 #ifdef access | |
2761 #undef access | |
2762 | |
2763 /* The following is necessary because 'access' emulation by VMS C (2.0) does | |
2764 * not work correctly. (It also doesn't work well in version 2.3.) | |
2765 */ | |
2766 | |
2767 #ifdef VMS4_4 | |
2768 | |
2769 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \ | |
2770 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string } | |
2771 | |
2772 typedef union { | |
2773 struct { | |
2774 unsigned short s_buflen; | |
2775 unsigned short s_code; | |
2776 char *s_bufadr; | |
2777 unsigned short *s_retlenadr; | |
2778 } s; | |
2779 int end; | |
2780 } item; | |
2781 #define buflen s.s_buflen | |
2782 #define code s.s_code | |
2783 #define bufadr s.s_bufadr | |
2784 #define retlenadr s.s_retlenadr | |
2785 | |
2786 #define R_OK 4 /* test for read permission */ | |
2787 #define W_OK 2 /* test for write permission */ | |
2788 #define X_OK 1 /* test for execute (search) permission */ | |
2789 #define F_OK 0 /* test for presence of file */ | |
2790 | |
2791 int | |
2792 sys_access (path, mode) | |
2793 char *path; | |
2794 int mode; | |
2795 { | |
2796 static char *user = NULL; | |
2797 char dir_fn[512]; | |
2798 | |
2799 /* translate possible directory spec into .DIR file name, so brain-dead | |
2800 * access can treat the directory like a file. */ | |
2801 if (directory_file_name (path, dir_fn)) | |
2802 path = dir_fn; | |
2803 | |
2804 if (mode == F_OK) | |
2805 return access (path, mode); | |
2806 if (user == NULL && (user = (char *) getenv ("USER")) == NULL) | |
2807 return -1; | |
2808 { | |
2809 int stat; | |
2810 int flags; | |
2811 int acces; | |
2812 unsigned short int dummy; | |
2813 item itemlst[3]; | |
2814 static int constant = ACL$C_FILE; | |
2815 DESCRIPTOR (path_desc, path); | |
2816 DESCRIPTOR (user_desc, user); | |
2817 | |
2818 flags = 0; | |
2819 acces = 0; | |
2820 if ((mode & X_OK) && ((stat = access (path, mode)) < 0 || mode == X_OK)) | |
2821 return stat; | |
2822 if (mode & R_OK) | |
2823 acces |= CHP$M_READ; | |
2824 if (mode & W_OK) | |
2825 acces |= CHP$M_WRITE; | |
2826 itemlst[0].buflen = sizeof (int); | |
2827 itemlst[0].code = CHP$_FLAGS; | |
2828 itemlst[0].bufadr = (char *) &flags; | |
2829 itemlst[0].retlenadr = &dummy; | |
2830 itemlst[1].buflen = sizeof (int); | |
2831 itemlst[1].code = CHP$_ACCESS; | |
2832 itemlst[1].bufadr = (char *) &acces; | |
2833 itemlst[1].retlenadr = &dummy; | |
2834 itemlst[2].end = CHP$_END; | |
2835 stat = SYS$CHECK_ACCESS (&constant, &path_desc, &user_desc, itemlst); | |
2836 return stat == SS$_NORMAL ? 0 : -1; | |
2837 } | |
2838 } | |
2839 | |
2840 #else /* not VMS4_4 */ | |
2841 | |
2842 #include <prvdef.h> | |
2843 #define ACE$M_WRITE 2 | |
2844 #define ACE$C_KEYID 1 | |
2845 | |
2846 static unsigned short memid, grpid; | |
2847 static unsigned int uic; | |
2848 | |
2849 /* Called from init_sys_modes, so it happens not very often | |
2850 but at least each time Emacs is loaded. */ | |
2851 sys_access_reinit () | |
2852 { | |
2853 uic = 0; | |
2854 } | |
2855 | |
2856 int | |
2857 sys_access (filename, type) | |
2858 char * filename; | |
2859 int type; | |
2860 { | |
2861 struct FAB fab; | |
2862 struct XABPRO xab; | |
2863 int status, size, i, typecode, acl_controlled; | |
2864 unsigned int *aclptr, *aclend, aclbuf[60]; | |
2865 union prvdef prvmask; | |
2866 | |
2867 /* Get UIC and GRP values for protection checking. */ | |
2868 if (uic == 0) | |
2869 { | |
2870 status = LIB$GETJPI (&JPI$_UIC, 0, 0, &uic, 0, 0); | |
2871 if (! (status & 1)) | |
2872 return -1; | |
2873 memid = uic & 0xFFFF; | |
2874 grpid = uic >> 16; | |
2875 } | |
2876 | |
2877 if (type != 2) /* not checking write access */ | |
2878 return access (filename, type); | |
2879 | |
2880 /* Check write protection. */ | |
2881 | |
2882 #define CHECKPRIV(bit) (prvmask.bit) | |
2883 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE)) | |
2884 | |
2885 /* Find privilege bits */ | |
2886 status = sys$setprv (0, 0, 0, prvmask); | |
2887 if (! (status & 1)) | |
2888 error ("Unable to find privileges: %s", vmserrstr (status)); | |
2889 if (CHECKPRIV (PRV$V_BYPASS)) | |
2890 return 0; /* BYPASS enabled */ | |
2891 fab = cc$rms_fab; | |
2892 fab.fab$b_fac = FAB$M_GET; | |
2893 fab.fab$l_fna = filename; | |
2894 fab.fab$b_fns = strlen (filename); | |
2895 fab.fab$l_xab = &xab; | |
2896 xab = cc$rms_xabpro; | |
2897 xab.xab$l_aclbuf = aclbuf; | |
2898 xab.xab$w_aclsiz = sizeof (aclbuf); | |
2899 status = sys$open (&fab, 0, 0); | |
2900 if (! (status & 1)) | |
2901 return -1; | |
2902 sys$close (&fab, 0, 0); | |
2903 /* Check system access */ | |
2904 if (CHECKPRIV (PRV$V_SYSPRV) && WRITEABLE (XAB$V_SYS)) | |
2905 return 0; | |
2906 /* Check ACL entries, if any */ | |
2907 acl_controlled = 0; | |
2908 if (xab.xab$w_acllen > 0) | |
2909 { | |
2910 aclptr = aclbuf; | |
2911 aclend = &aclbuf[xab.xab$w_acllen / 4]; | |
2912 while (*aclptr && aclptr < aclend) | |
2913 { | |
2914 size = (*aclptr & 0xff) / 4; | |
2915 typecode = (*aclptr >> 8) & 0xff; | |
2916 if (typecode == ACE$C_KEYID) | |
2917 for (i = size - 1; i > 1; i--) | |
2918 if (aclptr[i] == uic) | |
2919 { | |
2920 acl_controlled = 1; | |
2921 if (aclptr[1] & ACE$M_WRITE) | |
2922 return 0; /* Write access through ACL */ | |
2923 } | |
2924 aclptr = &aclptr[size]; | |
2925 } | |
2926 if (acl_controlled) /* ACL specified, prohibits write access */ | |
2927 return -1; | |
2928 } | |
2929 /* No ACL entries specified, check normal protection */ | |
2930 if (WRITEABLE (XAB$V_WLD)) /* World writeable */ | |
2931 return 0; | |
2932 if (WRITEABLE (XAB$V_GRP) && | |
2933 (unsigned short) (xab.xab$l_uic >> 16) == grpid) | |
2934 return 0; /* Group writeable */ | |
2935 if (WRITEABLE (XAB$V_OWN) && | |
2936 (xab.xab$l_uic & 0xFFFF) == memid) | |
2937 return 0; /* Owner writeable */ | |
2938 | |
2939 return -1; /* Not writeable */ | |
2940 } | |
2941 #endif /* not VMS4_4 */ | |
2942 #endif /* access */ | |
2943 | |
2944 static char vtbuf[NAM$C_MAXRSS+1]; | |
2945 | |
2946 /* translate a vms file spec to a unix path */ | |
2947 char * | |
2948 sys_translate_vms (vfile) | |
2949 char * vfile; | |
2950 { | |
2951 char * p; | |
2952 char * targ; | |
2953 | |
2954 if (!vfile) | |
2955 return 0; | |
2956 | |
2957 targ = vtbuf; | |
2958 | |
2959 /* leading device or logical name is a root directory */ | |
2960 if (p = strchr (vfile, ':')) | |
2961 { | |
2962 *targ++ = '/'; | |
2963 while (vfile < p) | |
2964 *targ++ = *vfile++; | |
2965 vfile++; | |
2966 *targ++ = '/'; | |
2967 } | |
2968 p = vfile; | |
2969 if (*p == '[' || *p == '<') | |
2970 { | |
2971 while (*++vfile != *p + 2) | |
2972 switch (*vfile) | |
2973 { | |
2974 case '.': | |
2975 if (vfile[-1] == *p) | |
2976 *targ++ = '.'; | |
2977 *targ++ = '/'; | |
2978 break; | |
2979 | |
2980 case '-': | |
2981 *targ++ = '.'; | |
2982 *targ++ = '.'; | |
2983 break; | |
2984 | |
2985 default: | |
2986 *targ++ = *vfile; | |
2987 break; | |
2988 } | |
2989 vfile++; | |
2990 *targ++ = '/'; | |
2991 } | |
2992 while (*vfile) | |
2993 *targ++ = *vfile++; | |
2994 | |
2995 return vtbuf; | |
2996 } | |
2997 | |
2998 static char utbuf[NAM$C_MAXRSS+1]; | |
2999 | |
3000 /* translate a unix path to a VMS file spec */ | |
3001 char * | |
3002 sys_translate_unix (ufile) | |
3003 char * ufile; | |
3004 { | |
3005 int slash_seen = 0; | |
3006 char *p; | |
3007 char * targ; | |
3008 | |
3009 if (!ufile) | |
3010 return 0; | |
3011 | |
3012 targ = utbuf; | |
3013 | |
3014 if (*ufile == '/') | |
3015 { | |
3016 ufile++; | |
3017 } | |
3018 | |
3019 while (*ufile) | |
3020 { | |
3021 switch (*ufile) | |
3022 { | |
3023 case '/': | |
3024 if (slash_seen) | |
3025 if (index (&ufile[1], '/')) | |
3026 *targ++ = '.'; | |
3027 else | |
3028 *targ++ = ']'; | |
3029 else | |
3030 { | |
3031 *targ++ = ':'; | |
3032 if (index (&ufile[1], '/')) | |
3033 *targ++ = '['; | |
3034 slash_seen = 1; | |
3035 } | |
3036 break; | |
3037 | |
3038 case '.': | |
3039 if (strncmp (ufile, "./", 2) == 0) | |
3040 { | |
3041 if (!slash_seen) | |
3042 { | |
3043 *targ++ = '['; | |
3044 slash_seen = 1; | |
3045 } | |
3046 ufile++; /* skip the dot */ | |
3047 if (index (&ufile[1], '/')) | |
3048 *targ++ = '.'; | |
3049 else | |
3050 *targ++ = ']'; | |
3051 } | |
3052 else if (strncmp (ufile, "../", 3) == 0) | |
3053 { | |
3054 if (!slash_seen) | |
3055 { | |
3056 *targ++ = '['; | |
3057 slash_seen = 1; | |
3058 } | |
3059 *targ++ = '-'; | |
3060 ufile += 2; /* skip the dots */ | |
3061 if (index (&ufile[1], '/')) | |
3062 *targ++ = '.'; | |
3063 else | |
3064 *targ++ = ']'; | |
3065 } | |
3066 else | |
3067 *targ++ = *ufile; | |
3068 break; | |
3069 | |
3070 default: | |
3071 *targ++ = *ufile; | |
3072 break; | |
3073 } | |
3074 ufile++; | |
3075 } | |
3076 *targ = '\0'; | |
3077 | |
3078 return utbuf; | |
3079 } | |
3080 | |
3081 char * | |
3082 getwd (pathname) | |
3083 char *pathname; | |
3084 { | |
3085 char *ptr; | |
3086 strcpy (pathname, egetenv ("PATH")); | |
3087 | |
3088 ptr = pathname; | |
3089 while (*ptr) | |
3090 { | |
3091 if ('a' <= *ptr && *ptr <= 'z') | |
3092 *ptr -= 040; | |
3093 ptr++; | |
3094 } | |
3095 return pathname; | |
3096 } | |
3097 | |
3098 getppid () | |
3099 { | |
3100 long item_code = JPI$_OWNER; | |
3101 unsigned long parent_id; | |
3102 int status; | |
3103 | |
3104 if (((status = LIB$GETJPI (&item_code, 0, 0, &parent_id)) & 1) == 0) | |
3105 { | |
3106 errno = EVMSERR; | |
3107 vaxc$errno = status; | |
3108 return -1; | |
3109 } | |
3110 return parent_id; | |
3111 } | |
3112 | |
3113 #undef getuid | |
3114 unsigned | |
3115 sys_getuid () | |
3116 { | |
3117 return (getgid () << 16) | getuid (); | |
3118 } | |
3119 | |
3120 int | |
3121 sys_read (fildes, buf, nbyte) | |
3122 int fildes; | |
3123 char *buf; | |
3124 unsigned int nbyte; | |
3125 { | |
3126 return read (fildes, buf, (nbyte < MAXIOSIZE ? nbyte : MAXIOSIZE)); | |
3127 } | |
3128 | |
3129 #if 0 | |
3130 int | |
3131 sys_write (fildes, buf, nbyte) | |
3132 int fildes; | |
3133 char *buf; | |
3134 unsigned int nbyte; | |
3135 { | |
3136 register int nwrote, rtnval = 0; | |
3137 | |
3138 while (nbyte > MAXIOSIZE && (nwrote = write (fildes, buf, MAXIOSIZE)) > 0) { | |
3139 nbyte -= nwrote; | |
3140 buf += nwrote; | |
3141 rtnval += nwrote; | |
3142 } | |
3143 if (nwrote < 0) | |
3144 return rtnval ? rtnval : -1; | |
3145 if ((nwrote = write (fildes, buf, nbyte)) < 0) | |
3146 return rtnval ? rtnval : -1; | |
3147 return (rtnval + nwrote); | |
3148 } | |
3149 #endif /* 0 */ | |
3150 | |
3151 /* | |
3152 * VAX/VMS VAX C RTL really loses. It insists that records | |
3153 * end with a newline (carriage return) character, and if they | |
3154 * don't it adds one (nice of it isn't it!) | |
3155 * | |
3156 * Thus we do this stupidity below. | |
3157 */ | |
3158 | |
3159 int | |
3160 sys_write (fildes, buf, nbytes) | |
3161 int fildes; | |
3162 char *buf; | |
3163 unsigned int nbytes; | |
3164 { | |
3165 register char *p; | |
3166 register char *e; | |
525 | 3167 int sum = 0; |
3168 struct stat st; | |
3169 | |
3170 fstat (fildes, &st); | |
491 | 3171 p = buf; |
3172 while (nbytes > 0) | |
3173 { | |
525 | 3174 int len, retval; |
3175 | |
3176 /* Handle fixed-length files with carriage control. */ | |
3177 if (st.st_fab_rfm == FAB$C_FIX | |
3178 && ((st.st_fab_rat & (FAB$M_FTN | FAB$M_CR)) != 0)) | |
3179 { | |
3180 len = st.st_fab_mrs; | |
3181 retval = write (fildes, p, min (len, nbytes)); | |
3182 if (retval != len) | |
3183 return -1; | |
3184 retval++; /* This skips the implied carriage control */ | |
3185 } | |
3186 else | |
3187 { | |
3188 e = p + min (MAXIOSIZE, nbytes) - 1; | |
3189 while (*e != '\n' && e > p) e--; | |
3190 if (p == e) /* Ok.. so here we add a newline... sigh. */ | |
3191 e = p + min (MAXIOSIZE, nbytes) - 1; | |
3192 len = e + 1 - p; | |
3193 retval = write (fildes, p, len); | |
3194 if (retval != len) | |
3195 return -1; | |
3196 } | |
3197 p += retval; | |
3198 sum += retval; | |
491 | 3199 nbytes -= retval; |
3200 } | |
3201 return sum; | |
3202 } | |
3203 | |
3204 /* Create file NEW copying its attributes from file OLD. If | |
3205 OLD is 0 or does not exist, create based on the value of | |
3206 vms_stmlf_recfm. */ | |
3207 | |
3208 /* Protection value the file should ultimately have. | |
3209 Set by create_copy_attrs, and use by rename_sansversions. */ | |
3210 static unsigned short int fab_final_pro; | |
3211 | |
3212 int | |
3213 creat_copy_attrs (old, new) | |
3214 char *old, *new; | |
3215 { | |
3216 struct FAB fab = cc$rms_fab; | |
3217 struct XABPRO xabpro; | |
3218 char aclbuf[256]; /* Choice of size is arbitrary. See below. */ | |
3219 extern int vms_stmlf_recfm; | |
3220 | |
3221 if (old) | |
3222 { | |
3223 fab.fab$b_fac = FAB$M_GET; | |
3224 fab.fab$l_fna = old; | |
3225 fab.fab$b_fns = strlen (old); | |
3226 fab.fab$l_xab = (char *) &xabpro; | |
3227 xabpro = cc$rms_xabpro; | |
3228 xabpro.xab$l_aclbuf = aclbuf; | |
3229 xabpro.xab$w_aclsiz = sizeof aclbuf; | |
3230 /* Call $OPEN to fill in the fab & xabpro fields. */ | |
3231 if (sys$open (&fab, 0, 0) & 1) | |
3232 { | |
3233 sys$close (&fab, 0, 0); | |
3234 fab.fab$l_alq = 0; /* zero the allocation quantity */ | |
3235 if (xabpro.xab$w_acllen > 0) | |
3236 { | |
3237 if (xabpro.xab$w_acllen > sizeof aclbuf) | |
3238 /* If the acl buffer was too short, redo open with longer one. | |
3239 Wouldn't need to do this if there were some system imposed | |
3240 limit on the size of an ACL, but I can't find any such. */ | |
3241 { | |
3242 xabpro.xab$l_aclbuf = (char *) alloca (xabpro.xab$w_acllen); | |
3243 xabpro.xab$w_aclsiz = xabpro.xab$w_acllen; | |
3244 if (sys$open (&fab, 0, 0) & 1) | |
3245 sys$close (&fab, 0, 0); | |
3246 else | |
3247 old = 0; | |
3248 } | |
3249 } | |
3250 else | |
3251 xabpro.xab$l_aclbuf = 0; | |
3252 } | |
3253 else | |
3254 old = 0; | |
3255 } | |
3256 fab.fab$l_fna = new; | |
3257 fab.fab$b_fns = strlen (new); | |
3258 if (!old) | |
3259 { | |
3260 fab.fab$l_xab = 0; | |
3261 fab.fab$b_rfm = vms_stmlf_recfm ? FAB$C_STMLF : FAB$C_VAR; | |
3262 fab.fab$b_rat = FAB$M_CR; | |
3263 } | |
3264 | |
3265 /* Set the file protections such that we will be able to manipulate | |
3266 this file. Once we are done writing and renaming it, we will set | |
3267 the protections back. */ | |
3268 if (old) | |
3269 fab_final_pro = xabpro.xab$w_pro; | |
3270 else | |
3271 sys$setdfprot (0, &fab_final_pro); | |
3272 xabpro.xab$w_pro &= 0xff0f; /* set O:rewd for now. This is set back later. */ | |
3273 | |
3274 /* Create the new file with either default attrs or attrs copied | |
3275 from old file. */ | |
3276 if (!(SYS$CREATE (&fab, 0, 0) & 1)) | |
3277 return -1; | |
3278 sys$close (&fab, 0, 0); | |
3279 /* As this is a "replacement" for creat, return a file descriptor | |
3280 opened for writing. */ | |
3281 return open (new, O_WRONLY); | |
3282 } | |
3283 | |
3284 #ifdef creat | |
3285 #undef creat | |
3286 #include <varargs.h> | |
3287 #ifdef __GNUC__ | |
3288 #ifndef va_count | |
3289 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1)) | |
3290 #endif | |
3291 #endif | |
3292 | |
3293 sys_creat (va_alist) | |
3294 va_dcl | |
3295 { | |
3296 va_list list_incrementor; | |
3297 char *name; | |
3298 int mode; | |
3299 int rfd; /* related file descriptor */ | |
3300 int fd; /* Our new file descriptor */ | |
3301 int count; | |
3302 struct stat st_buf; | |
3303 char rfm[12]; | |
3304 char rat[15]; | |
3305 char mrs[13]; | |
3306 char fsz[13]; | |
3307 extern int vms_stmlf_recfm; | |
3308 | |
3309 va_count (count); | |
3310 va_start (list_incrementor); | |
3311 name = va_arg (list_incrementor, char *); | |
3312 mode = va_arg (list_incrementor, int); | |
3313 if (count > 2) | |
3314 rfd = va_arg (list_incrementor, int); | |
3315 va_end (list_incrementor); | |
3316 if (count > 2) | |
3317 { | |
3318 /* Use information from the related file descriptor to set record | |
3319 format of the newly created file. */ | |
3320 fstat (rfd, &st_buf); | |
3321 switch (st_buf.st_fab_rfm) | |
3322 { | |
3323 case FAB$C_FIX: | |
3324 strcpy (rfm, "rfm = fix"); | |
3325 sprintf (mrs, "mrs = %d", st_buf.st_fab_mrs); | |
3326 strcpy (rat, "rat = "); | |
3327 if (st_buf.st_fab_rat & FAB$M_CR) | |
3328 strcat (rat, "cr"); | |
3329 else if (st_buf.st_fab_rat & FAB$M_FTN) | |
3330 strcat (rat, "ftn"); | |
3331 else if (st_buf.st_fab_rat & FAB$M_PRN) | |
3332 strcat (rat, "prn"); | |
3333 if (st_buf.st_fab_rat & FAB$M_BLK) | |
3334 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN)) | |
3335 strcat (rat, ", blk"); | |
3336 else | |
3337 strcat (rat, "blk"); | |
3338 return creat (name, 0, rfm, rat, mrs); | |
3339 | |
3340 case FAB$C_VFC: | |
3341 strcpy (rfm, "rfm = vfc"); | |
3342 sprintf (fsz, "fsz = %d", st_buf.st_fab_fsz); | |
3343 strcpy (rat, "rat = "); | |
3344 if (st_buf.st_fab_rat & FAB$M_CR) | |
3345 strcat (rat, "cr"); | |
3346 else if (st_buf.st_fab_rat & FAB$M_FTN) | |
3347 strcat (rat, "ftn"); | |
3348 else if (st_buf.st_fab_rat & FAB$M_PRN) | |
3349 strcat (rat, "prn"); | |
3350 if (st_buf.st_fab_rat & FAB$M_BLK) | |
3351 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN)) | |
3352 strcat (rat, ", blk"); | |
3353 else | |
3354 strcat (rat, "blk"); | |
3355 return creat (name, 0, rfm, rat, fsz); | |
3356 | |
3357 case FAB$C_STM: | |
3358 strcpy (rfm, "rfm = stm"); | |
3359 break; | |
3360 | |
3361 case FAB$C_STMCR: | |
3362 strcpy (rfm, "rfm = stmcr"); | |
3363 break; | |
3364 | |
3365 case FAB$C_STMLF: | |
3366 strcpy (rfm, "rfm = stmlf"); | |
3367 break; | |
3368 | |
3369 case FAB$C_UDF: | |
3370 strcpy (rfm, "rfm = udf"); | |
3371 break; | |
3372 | |
3373 case FAB$C_VAR: | |
3374 strcpy (rfm, "rfm = var"); | |
3375 break; | |
3376 } | |
3377 strcpy (rat, "rat = "); | |
3378 if (st_buf.st_fab_rat & FAB$M_CR) | |
3379 strcat (rat, "cr"); | |
3380 else if (st_buf.st_fab_rat & FAB$M_FTN) | |
3381 strcat (rat, "ftn"); | |
3382 else if (st_buf.st_fab_rat & FAB$M_PRN) | |
3383 strcat (rat, "prn"); | |
3384 if (st_buf.st_fab_rat & FAB$M_BLK) | |
3385 if (st_buf.st_fab_rat & (FAB$M_CR|FAB$M_FTN|FAB$M_PRN)) | |
3386 strcat (rat, ", blk"); | |
3387 else | |
3388 strcat (rat, "blk"); | |
3389 } | |
3390 else | |
3391 { | |
3392 strcpy (rfm, vms_stmlf_recfm ? "rfm = stmlf" : "rfm=var"); | |
3393 strcpy (rat, "rat=cr"); | |
3394 } | |
3395 /* Until the VAX C RTL fixes the many bugs with modes, always use | |
3396 mode 0 to get the user's default protection. */ | |
3397 fd = creat (name, 0, rfm, rat); | |
3398 if (fd < 0 && errno == EEXIST) | |
3399 { | |
3400 if (unlink (name) < 0) | |
3401 report_file_error ("delete", build_string (name)); | |
3402 fd = creat (name, 0, rfm, rat); | |
3403 } | |
3404 return fd; | |
3405 } | |
3406 #endif /* creat */ | |
3407 | |
3408 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/ | |
3409 sys_fwrite (ptr, size, num, fp) | |
3410 register char * ptr; | |
3411 FILE * fp; | |
3412 { | |
3413 register int tot = num * size; | |
3414 | |
3415 while (tot--) | |
3416 fputc (*ptr++, fp); | |
3417 } | |
3418 | |
3419 /* | |
3420 * The VMS C library routine creat actually creates a new version of an | |
3421 * existing file rather than truncating the old version. There are times | |
3422 * when this is not the desired behavior, for instance, when writing an | |
3423 * auto save file (you only want one version), or when you don't have | |
3424 * write permission in the directory containing the file (but the file | |
3425 * itself is writable). Hence this routine, which is equivalent to | |
3426 * "close (creat (fn, 0));" on Unix if fn already exists. | |
3427 */ | |
3428 int | |
3429 vms_truncate (fn) | |
3430 char *fn; | |
3431 { | |
3432 struct FAB xfab = cc$rms_fab; | |
3433 struct RAB xrab = cc$rms_rab; | |
3434 int status; | |
3435 | |
3436 xfab.fab$l_fop = FAB$M_TEF; /* free allocated but unused blocks on close */ | |
3437 xfab.fab$b_fac = FAB$M_TRN | FAB$M_GET; /* allow truncate and get access */ | |
3438 xfab.fab$b_shr = FAB$M_NIL; /* allow no sharing - file must be locked */ | |
3439 xfab.fab$l_fna = fn; | |
3440 xfab.fab$b_fns = strlen (fn); | |
3441 xfab.fab$l_dna = ";0"; /* default to latest version of the file */ | |
3442 xfab.fab$b_dns = 2; | |
3443 xrab.rab$l_fab = &xfab; | |
3444 | |
3445 /* This gibberish opens the file, positions to the first record, and | |
3446 deletes all records from there until the end of file. */ | |
3447 if ((sys$open (&xfab) & 01) == 01) | |
3448 { | |
3449 if ((sys$connect (&xrab) & 01) == 01 && | |
3450 (sys$find (&xrab) & 01) == 01 && | |
3451 (sys$truncate (&xrab) & 01) == 01) | |
3452 status = 0; | |
3453 else | |
3454 status = -1; | |
3455 } | |
3456 else | |
3457 status = -1; | |
3458 sys$close (&xfab); | |
3459 return status; | |
3460 } | |
3461 | |
3462 /* Define this symbol to actually read SYSUAF.DAT. This requires either | |
3463 SYSPRV or a readable SYSUAF.DAT. */ | |
3464 | |
3465 #ifdef READ_SYSUAF | |
3466 /* | |
3467 * getuaf.c | |
3468 * | |
3469 * Routine to read the VMS User Authorization File and return | |
3470 * a specific user's record. | |
3471 */ | |
3472 | |
3473 static struct UAF retuaf; | |
3474 | |
3475 struct UAF * | |
3476 get_uaf_name (uname) | |
3477 char * uname; | |
3478 { | |
3479 register status; | |
3480 struct FAB uaf_fab; | |
3481 struct RAB uaf_rab; | |
3482 | |
3483 uaf_fab = cc$rms_fab; | |
3484 uaf_rab = cc$rms_rab; | |
3485 /* initialize fab fields */ | |
3486 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT"; | |
3487 uaf_fab.fab$b_fns = 21; | |
3488 uaf_fab.fab$b_fac = FAB$M_GET; | |
3489 uaf_fab.fab$b_org = FAB$C_IDX; | |
3490 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL; | |
3491 /* initialize rab fields */ | |
3492 uaf_rab.rab$l_fab = &uaf_fab; | |
3493 /* open the User Authorization File */ | |
3494 status = sys$open (&uaf_fab); | |
3495 if (!(status&1)) | |
3496 { | |
3497 errno = EVMSERR; | |
3498 vaxc$errno = status; | |
3499 return 0; | |
3500 } | |
3501 status = sys$connect (&uaf_rab); | |
3502 if (!(status&1)) | |
3503 { | |
3504 errno = EVMSERR; | |
3505 vaxc$errno = status; | |
3506 return 0; | |
3507 } | |
3508 /* read the requested record - index is in uname */ | |
3509 uaf_rab.rab$l_kbf = uname; | |
3510 uaf_rab.rab$b_ksz = strlen (uname); | |
3511 uaf_rab.rab$b_rac = RAB$C_KEY; | |
3512 uaf_rab.rab$l_ubf = (char *)&retuaf; | |
3513 uaf_rab.rab$w_usz = sizeof retuaf; | |
3514 status = sys$get (&uaf_rab); | |
3515 if (!(status&1)) | |
3516 { | |
3517 errno = EVMSERR; | |
3518 vaxc$errno = status; | |
3519 return 0; | |
3520 } | |
3521 /* close the User Authorization File */ | |
3522 status = sys$disconnect (&uaf_rab); | |
3523 if (!(status&1)) | |
3524 { | |
3525 errno = EVMSERR; | |
3526 vaxc$errno = status; | |
3527 return 0; | |
3528 } | |
3529 status = sys$close (&uaf_fab); | |
3530 if (!(status&1)) | |
3531 { | |
3532 errno = EVMSERR; | |
3533 vaxc$errno = status; | |
3534 return 0; | |
3535 } | |
3536 return &retuaf; | |
3537 } | |
3538 | |
3539 struct UAF * | |
3540 get_uaf_uic (uic) | |
3541 unsigned long uic; | |
3542 { | |
3543 register status; | |
3544 struct FAB uaf_fab; | |
3545 struct RAB uaf_rab; | |
3546 | |
3547 uaf_fab = cc$rms_fab; | |
3548 uaf_rab = cc$rms_rab; | |
3549 /* initialize fab fields */ | |
3550 uaf_fab.fab$l_fna = "SYS$SYSTEM:SYSUAF.DAT"; | |
3551 uaf_fab.fab$b_fns = 21; | |
3552 uaf_fab.fab$b_fac = FAB$M_GET; | |
3553 uaf_fab.fab$b_org = FAB$C_IDX; | |
3554 uaf_fab.fab$b_shr = FAB$M_GET|FAB$M_PUT|FAB$M_UPD|FAB$M_DEL; | |
3555 /* initialize rab fields */ | |
3556 uaf_rab.rab$l_fab = &uaf_fab; | |
3557 /* open the User Authorization File */ | |
3558 status = sys$open (&uaf_fab); | |
3559 if (!(status&1)) | |
3560 { | |
3561 errno = EVMSERR; | |
3562 vaxc$errno = status; | |
3563 return 0; | |
3564 } | |
3565 status = sys$connect (&uaf_rab); | |
3566 if (!(status&1)) | |
3567 { | |
3568 errno = EVMSERR; | |
3569 vaxc$errno = status; | |
3570 return 0; | |
3571 } | |
3572 /* read the requested record - index is in uic */ | |
3573 uaf_rab.rab$b_krf = 1; /* 1st alternate key */ | |
3574 uaf_rab.rab$l_kbf = (char *) &uic; | |
3575 uaf_rab.rab$b_ksz = sizeof uic; | |
3576 uaf_rab.rab$b_rac = RAB$C_KEY; | |
3577 uaf_rab.rab$l_ubf = (char *)&retuaf; | |
3578 uaf_rab.rab$w_usz = sizeof retuaf; | |
3579 status = sys$get (&uaf_rab); | |
3580 if (!(status&1)) | |
3581 { | |
3582 errno = EVMSERR; | |
3583 vaxc$errno = status; | |
3584 return 0; | |
3585 } | |
3586 /* close the User Authorization File */ | |
3587 status = sys$disconnect (&uaf_rab); | |
3588 if (!(status&1)) | |
3589 { | |
3590 errno = EVMSERR; | |
3591 vaxc$errno = status; | |
3592 return 0; | |
3593 } | |
3594 status = sys$close (&uaf_fab); | |
3595 if (!(status&1)) | |
3596 { | |
3597 errno = EVMSERR; | |
3598 vaxc$errno = status; | |
3599 return 0; | |
3600 } | |
3601 return &retuaf; | |
3602 } | |
3603 | |
3604 static struct passwd retpw; | |
3605 | |
3606 struct passwd * | |
3607 cnv_uaf_pw (up) | |
3608 struct UAF * up; | |
3609 { | |
3610 char * ptr; | |
3611 | |
3612 /* copy these out first because if the username is 32 chars, the next | |
3613 section will overwrite the first byte of the UIC */ | |
3614 retpw.pw_uid = up->uaf$w_mem; | |
3615 retpw.pw_gid = up->uaf$w_grp; | |
3616 | |
3617 /* I suppose this is not the best sytle, to possibly overwrite one | |
3618 byte beyond the end of the field, but what the heck... */ | |
3619 ptr = &up->uaf$t_username[UAF$S_USERNAME]; | |
3620 while (ptr[-1] == ' ') | |
3621 ptr--; | |
3622 *ptr = '\0'; | |
3623 strcpy (retpw.pw_name, up->uaf$t_username); | |
3624 | |
3625 /* the rest of these are counted ascii strings */ | |
3626 strncpy (retpw.pw_gecos, &up->uaf$t_owner[1], up->uaf$t_owner[0]); | |
3627 retpw.pw_gecos[up->uaf$t_owner[0]] = '\0'; | |
3628 strncpy (retpw.pw_dir, &up->uaf$t_defdev[1], up->uaf$t_defdev[0]); | |
3629 retpw.pw_dir[up->uaf$t_defdev[0]] = '\0'; | |
3630 strncat (retpw.pw_dir, &up->uaf$t_defdir[1], up->uaf$t_defdir[0]); | |
3631 retpw.pw_dir[up->uaf$t_defdev[0] + up->uaf$t_defdir[0]] = '\0'; | |
3632 strncpy (retpw.pw_shell, &up->uaf$t_defcli[1], up->uaf$t_defcli[0]); | |
3633 retpw.pw_shell[up->uaf$t_defcli[0]] = '\0'; | |
3634 | |
3635 return &retpw; | |
3636 } | |
3637 #else /* not READ_SYSUAF */ | |
3638 static struct passwd retpw; | |
3639 #endif /* not READ_SYSUAF */ | |
3640 | |
3641 struct passwd * | |
3642 getpwnam (name) | |
3643 char * name; | |
3644 { | |
3645 #ifdef READ_SYSUAF | |
3646 struct UAF *up; | |
3647 #else | |
3648 char * user; | |
3649 char * dir; | |
3650 unsigned char * full; | |
3651 #endif /* READ_SYSUAF */ | |
3652 char *ptr = name; | |
3653 | |
3654 while (*ptr) | |
3655 { | |
3656 if ('a' <= *ptr && *ptr <= 'z') | |
3657 *ptr -= 040; | |
3658 ptr++; | |
3659 } | |
3660 #ifdef READ_SYSUAF | |
3661 if (!(up = get_uaf_name (name))) | |
3662 return 0; | |
3663 return cnv_uaf_pw (up); | |
3664 #else | |
3665 if (strcmp (name, getenv ("USER")) == 0) | |
3666 { | |
3667 retpw.pw_uid = getuid (); | |
3668 retpw.pw_gid = getgid (); | |
3669 strcpy (retpw.pw_name, name); | |
3670 if (full = egetenv ("FULLNAME")) | |
3671 strcpy (retpw.pw_gecos, full); | |
3672 else | |
3673 *retpw.pw_gecos = '\0'; | |
3674 strcpy (retpw.pw_dir, egetenv ("HOME")); | |
3675 *retpw.pw_shell = '\0'; | |
3676 return &retpw; | |
3677 } | |
3678 else | |
3679 return 0; | |
3680 #endif /* not READ_SYSUAF */ | |
3681 } | |
3682 | |
3683 struct passwd * | |
3684 getpwuid (uid) | |
3685 unsigned long uid; | |
3686 { | |
3687 #ifdef READ_SYSUAF | |
3688 struct UAF * up; | |
3689 | |
3690 if (!(up = get_uaf_uic (uid))) | |
3691 return 0; | |
3692 return cnv_uaf_pw (up); | |
3693 #else | |
3694 if (uid == sys_getuid ()) | |
3695 return getpwnam (egetenv ("USER")); | |
3696 else | |
3697 return 0; | |
3698 #endif /* not READ_SYSUAF */ | |
3699 } | |
3700 | |
3701 /* return total address space available to the current process. This is | |
3702 the sum of the current p0 size, p1 size and free page table entries | |
3703 available. */ | |
3704 vlimit () | |
3705 { | |
3706 int item_code; | |
3707 unsigned long free_pages; | |
3708 unsigned long frep0va; | |
3709 unsigned long frep1va; | |
3710 register status; | |
3711 | |
3712 item_code = JPI$_FREPTECNT; | |
3713 if (((status = LIB$GETJPI (&item_code, 0, 0, &free_pages)) & 1) == 0) | |
3714 { | |
3715 errno = EVMSERR; | |
3716 vaxc$errno = status; | |
3717 return -1; | |
3718 } | |
3719 free_pages *= 512; | |
3720 | |
3721 item_code = JPI$_FREP0VA; | |
3722 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep0va)) & 1) == 0) | |
3723 { | |
3724 errno = EVMSERR; | |
3725 vaxc$errno = status; | |
3726 return -1; | |
3727 } | |
3728 item_code = JPI$_FREP1VA; | |
3729 if (((status = LIB$GETJPI (&item_code, 0, 0, &frep1va)) & 1) == 0) | |
3730 { | |
3731 errno = EVMSERR; | |
3732 vaxc$errno = status; | |
3733 return -1; | |
3734 } | |
3735 | |
3736 return free_pages + frep0va + (0x7fffffff - frep1va); | |
3737 } | |
3738 | |
3739 define_logical_name (varname, string) | |
3740 char *varname; | |
3741 char *string; | |
3742 { | |
3743 struct dsc$descriptor_s strdsc = | |
3744 {strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string}; | |
3745 struct dsc$descriptor_s envdsc = | |
3746 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname}; | |
3747 struct dsc$descriptor_s lnmdsc = | |
3748 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"}; | |
3749 | |
3750 return LIB$SET_LOGICAL (&envdsc, &strdsc, &lnmdsc, 0, 0); | |
3751 } | |
3752 | |
3753 delete_logical_name (varname) | |
3754 char *varname; | |
3755 { | |
3756 struct dsc$descriptor_s envdsc = | |
3757 {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname}; | |
3758 struct dsc$descriptor_s lnmdsc = | |
3759 {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"}; | |
3760 | |
3761 return LIB$DELETE_LOGICAL (&envdsc, &lnmdsc); | |
3762 } | |
3763 | |
3764 ulimit () | |
3765 {} | |
3766 | |
3767 setpriority () | |
3768 {} | |
3769 | |
3770 setpgrp () | |
3771 {} | |
3772 | |
3773 execvp () | |
3774 { | |
3775 error ("execvp system call not implemented"); | |
3776 } | |
3777 | |
3778 int | |
3779 rename (from, to) | |
3780 char *from, *to; | |
3781 { | |
3782 int status; | |
3783 struct FAB from_fab = cc$rms_fab, to_fab = cc$rms_fab; | |
3784 struct NAM from_nam = cc$rms_nam, to_nam = cc$rms_nam; | |
3785 char from_esn[NAM$C_MAXRSS]; | |
3786 char to_esn[NAM$C_MAXRSS]; | |
3787 | |
3788 from_fab.fab$l_fna = from; | |
3789 from_fab.fab$b_fns = strlen (from); | |
3790 from_fab.fab$l_nam = &from_nam; | |
3791 from_fab.fab$l_fop = FAB$M_NAM; | |
3792 | |
3793 from_nam.nam$l_esa = from_esn; | |
3794 from_nam.nam$b_ess = sizeof from_esn; | |
3795 | |
3796 to_fab.fab$l_fna = to; | |
3797 to_fab.fab$b_fns = strlen (to); | |
3798 to_fab.fab$l_nam = &to_nam; | |
3799 to_fab.fab$l_fop = FAB$M_NAM; | |
3800 | |
3801 to_nam.nam$l_esa = to_esn; | |
3802 to_nam.nam$b_ess = sizeof to_esn; | |
3803 | |
3804 status = SYS$RENAME (&from_fab, 0, 0, &to_fab); | |
3805 | |
3806 if (status & 1) | |
3807 return 0; | |
3808 else | |
3809 { | |
3810 if (status == RMS$_DEV) | |
3811 errno = EXDEV; | |
3812 else | |
3813 errno = EVMSERR; | |
3814 vaxc$errno = status; | |
3815 return -1; | |
3816 } | |
3817 } | |
3818 | |
3819 /* This function renames a file like `rename', but it strips | |
3820 the version number from the "to" filename, such that the "to" file is | |
3821 will always be a new version. It also sets the file protection once it is | |
3822 finished. The protection that we will use is stored in fab_final_pro, | |
3823 and was set when we did a creat_copy_attrs to create the file that we | |
3824 are renaming. | |
3825 | |
3826 We could use the chmod function, but Eunichs uses 3 bits per user category | |
3827 to describe the protection, and VMS uses 4 (write and delete are seperate | |
3828 bits). To maintain portability, the VMS implementation of `chmod' wires | |
3829 the W and D bits together. */ | |
3830 | |
3831 | |
3832 static struct fibdef fib; /* We need this initialized to zero */ | |
3833 char vms_file_written[NAM$C_MAXRSS]; | |
3834 | |
3835 int | |
3836 rename_sans_version (from,to) | |
3837 char *from, *to; | |
3838 { | |
3839 short int chan; | |
3840 int stat; | |
3841 short int iosb[4]; | |
3842 int status; | |
3843 struct FAB to_fab = cc$rms_fab; | |
3844 struct NAM to_nam = cc$rms_nam; | |
3845 struct dsc$descriptor fib_d ={sizeof (fib),0,0,(char*) &fib}; | |
3846 struct dsc$descriptor fib_attr[2] | |
3847 = {{sizeof (fab_final_pro),ATR$C_FPRO,0,(char*) &fab_final_pro},{0,0,0,0}}; | |
3848 char to_esn[NAM$C_MAXRSS]; | |
3849 | |
3850 $DESCRIPTOR (disk,to_esn); | |
3851 | |
3852 to_fab.fab$l_fna = to; | |
3853 to_fab.fab$b_fns = strlen (to); | |
3854 to_fab.fab$l_nam = &to_nam; | |
3855 to_fab.fab$l_fop = FAB$M_NAM; | |
3856 | |
3857 to_nam.nam$l_esa = to_esn; | |
3858 to_nam.nam$b_ess = sizeof to_esn; | |
3859 | |
3860 status = SYS$PARSE (&to_fab, 0, 0); /* figure out the full file name */ | |
3861 | |
3862 if (to_nam.nam$l_fnb && NAM$M_EXP_VER) | |
3863 *(to_nam.nam$l_ver) = '\0'; | |
3864 | |
3865 stat = rename (from, to_esn); | |
3866 if (stat < 0) | |
3867 return stat; | |
3868 | |
3869 strcpy (vms_file_written, to_esn); | |
3870 | |
3871 to_fab.fab$l_fna = vms_file_written; /* this points to the versionless name */ | |
3872 to_fab.fab$b_fns = strlen (vms_file_written); | |
3873 | |
3874 /* Now set the file protection to the correct value */ | |
3875 sys$open (&to_fab, 0, 0); /* This fills in the nam$w_fid fields */ | |
3876 | |
3877 /* Copy these fields into the fib */ | |
3878 fib.fib$r_fid_overlay.fib$w_fid[0] = to_nam.nam$w_fid[0]; | |
3879 fib.fib$r_fid_overlay.fib$w_fid[1] = to_nam.nam$w_fid[1]; | |
3880 fib.fib$r_fid_overlay.fib$w_fid[2] = to_nam.nam$w_fid[2]; | |
3881 | |
3882 sys$close (&to_fab, 0, 0); | |
3883 | |
3884 stat = sys$assign (&disk, &chan, 0, 0); /* open a channel to the disk */ | |
3885 if (!stat) | |
3886 lib$signal (stat); | |
3887 stat = sys$qiow (0, chan, IO$_MODIFY, iosb, 0, 0, &fib_d, | |
3888 0, 0, 0, &fib_attr, 0); | |
3889 if (!stat) | |
3890 lib$signal (stat); | |
3891 stat = sys$dassgn (chan); | |
3892 if (!stat) | |
3893 lib$signal (stat); | |
766 | 3894 strcpy (vms_file_written, to_esn); /* We will write this to the terminal*/ |
491 | 3895 return 0; |
3896 } | |
3897 | |
3898 link (file, new) | |
3899 char * file, * new; | |
3900 { | |
3901 register status; | |
3902 struct FAB fab; | |
3903 struct NAM nam; | |
3904 unsigned short fid[3]; | |
3905 char esa[NAM$C_MAXRSS]; | |
3906 | |
3907 fab = cc$rms_fab; | |
3908 fab.fab$l_fop = FAB$M_OFP; | |
3909 fab.fab$l_fna = file; | |
3910 fab.fab$b_fns = strlen (file); | |
3911 fab.fab$l_nam = &nam; | |
3912 | |
3913 nam = cc$rms_nam; | |
3914 nam.nam$l_esa = esa; | |
3915 nam.nam$b_ess = NAM$C_MAXRSS; | |
3916 | |
3917 status = SYS$PARSE (&fab); | |
3918 if ((status & 1) == 0) | |
3919 { | |
3920 errno = EVMSERR; | |
3921 vaxc$errno = status; | |
3922 return -1; | |
3923 } | |
3924 status = SYS$SEARCH (&fab); | |
3925 if ((status & 1) == 0) | |
3926 { | |
3927 errno = EVMSERR; | |
3928 vaxc$errno = status; | |
3929 return -1; | |
3930 } | |
3931 | |
3932 fid[0] = nam.nam$w_fid[0]; | |
3933 fid[1] = nam.nam$w_fid[1]; | |
3934 fid[2] = nam.nam$w_fid[2]; | |
3935 | |
3936 fab.fab$l_fna = new; | |
3937 fab.fab$b_fns = strlen (new); | |
3938 | |
3939 status = SYS$PARSE (&fab); | |
3940 if ((status & 1) == 0) | |
3941 { | |
3942 errno = EVMSERR; | |
3943 vaxc$errno = status; | |
3944 return -1; | |
3945 } | |
3946 | |
3947 nam.nam$w_fid[0] = fid[0]; | |
3948 nam.nam$w_fid[1] = fid[1]; | |
3949 nam.nam$w_fid[2] = fid[2]; | |
3950 | |
3951 nam.nam$l_esa = nam.nam$l_name; | |
3952 nam.nam$b_esl = nam.nam$b_name + nam.nam$b_type + nam.nam$b_ver; | |
3953 | |
3954 status = SYS$ENTER (&fab); | |
3955 if ((status & 1) == 0) | |
3956 { | |
3957 errno = EVMSERR; | |
3958 vaxc$errno = status; | |
3959 return -1; | |
3960 } | |
3961 | |
3962 return 0; | |
3963 } | |
3964 | |
3965 croak (badfunc) | |
3966 char *badfunc; | |
3967 { | |
3968 printf ("%s not yet implemented\r\n", badfunc); | |
3969 reset_sys_modes (); | |
3970 exit (1); | |
3971 } | |
3972 | |
3973 long | |
3974 random () | |
3975 { | |
3976 /* Arrange to return a range centered on zero. */ | |
3977 return rand () - (1 << 30); | |
3978 } | |
3979 | |
3980 srandom (seed) | |
3981 { | |
3982 srand (seed); | |
3983 } | |
3984 #endif /* VMS */ | |
3985 | |
3986 #ifdef AIX | |
3987 | |
3988 /* Called from init_sys_modes. */ | |
3989 hft_init () | |
3990 { | |
3991 int junk; | |
3992 | |
3993 /* If we're not on an HFT we shouldn't do any of this. We determine | |
3994 if we are on an HFT by trying to get an HFT error code. If this | |
3995 call fails, we're not on an HFT. */ | |
3996 #ifdef IBMR2AIX | |
3997 if (ioctl (0, HFQERROR, &junk) < 0) | |
3998 return; | |
3999 #else /* not IBMR2AIX */ | |
4000 if (ioctl (0, HFQEIO, 0) < 0) | |
4001 return; | |
4002 #endif /* not IBMR2AIX */ | |
4003 | |
4004 /* On AIX the default hft keyboard mapping uses backspace rather than delete | |
4005 as the rubout key's ASCII code. Here this is changed. The bug is that | |
4006 there's no way to determine the old mapping, so in reset_sys_modes | |
4007 we need to assume that the normal map had been present. Of course, this | |
4008 code also doesn't help if on a terminal emulator which doesn't understand | |
4009 HFT VTD's. */ | |
4010 { | |
4011 struct hfbuf buf; | |
4012 struct hfkeymap keymap; | |
4013 | |
4014 buf.hf_bufp = (char *)&keymap; | |
4015 buf.hf_buflen = sizeof (keymap); | |
4016 keymap.hf_nkeys = 2; | |
4017 keymap.hfkey[0].hf_kpos = 15; | |
4018 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE; | |
4019 #ifdef IBMR2AIX | |
4020 keymap.hfkey[0].hf_keyidh = '<'; | |
4021 #else /* not IBMR2AIX */ | |
4022 keymap.hfkey[0].hf_page = '<'; | |
4023 #endif /* not IBMR2AIX */ | |
4024 keymap.hfkey[0].hf_char = 127; | |
4025 keymap.hfkey[1].hf_kpos = 15; | |
4026 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT; | |
4027 #ifdef IBMR2AIX | |
4028 keymap.hfkey[1].hf_keyidh = '<'; | |
4029 #else /* not IBMR2AIX */ | |
4030 keymap.hfkey[1].hf_page = '<'; | |
4031 #endif /* not IBMR2AIX */ | |
4032 keymap.hfkey[1].hf_char = 127; | |
4033 hftctl (0, HFSKBD, &buf); | |
4034 } | |
4035 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly | |
4036 at times. */ | |
4037 line_ins_del_ok = char_ins_del_ok = 0; | |
4038 } | |
4039 | |
4040 /* Reset the rubout key to backspace. */ | |
4041 | |
4042 hft_reset () | |
4043 { | |
4044 struct hfbuf buf; | |
4045 struct hfkeymap keymap; | |
4046 int junk; | |
4047 | |
4048 #ifdef IBMR2AIX | |
4049 if (ioctl (0, HFQERROR, &junk) < 0) | |
4050 return; | |
4051 #else /* not IBMR2AIX */ | |
4052 if (ioctl (0, HFQEIO, 0) < 0) | |
4053 return; | |
4054 #endif /* not IBMR2AIX */ | |
4055 | |
4056 buf.hf_bufp = (char *)&keymap; | |
4057 buf.hf_buflen = sizeof (keymap); | |
4058 keymap.hf_nkeys = 2; | |
4059 keymap.hfkey[0].hf_kpos = 15; | |
4060 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE; | |
4061 #ifdef IBMR2AIX | |
4062 keymap.hfkey[0].hf_keyidh = '<'; | |
4063 #else /* not IBMR2AIX */ | |
4064 keymap.hfkey[0].hf_page = '<'; | |
4065 #endif /* not IBMR2AIX */ | |
4066 keymap.hfkey[0].hf_char = 8; | |
4067 keymap.hfkey[1].hf_kpos = 15; | |
4068 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT; | |
4069 #ifdef IBMR2AIX | |
4070 keymap.hfkey[1].hf_keyidh = '<'; | |
4071 #else /* not IBMR2AIX */ | |
4072 keymap.hfkey[1].hf_page = '<'; | |
4073 #endif /* not IBMR2AIX */ | |
4074 keymap.hfkey[1].hf_char = 8; | |
4075 hftctl (0, HFSKBD, &buf); | |
4076 } | |
4077 | |
4078 #endif /* AIX */ |