1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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)
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.
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. */
26 #include "blockinput.h"
29 #define min(x,y) ((x) > (y) ? (y) : (x))
31 /* In this file, open, read and write refer to the system calls,
32 not our sugared interfaces sys_open, sys_read and sys_write.
33 Contrariwise, for systems where we use the system calls directly,
34 define sys_read, etc. here as aliases for them. */
37 #define sys_write write
38 #endif /* `read' is not a macro */
44 #define sys_close close
51 #else /* `open' is a macro */
53 #endif /* `open' is a macro */
55 /* Does anyone other than VMS need this? */
57 #define sys_fwrite fwrite
63 #include <sys/types.h>
69 extern char *sys_errlist
[];
92 #define MAXIOSIZE ( 32 * PAGESIZE ) /* Don't I/O more than 32 blocks at a time */
96 #ifdef BSD /* this is done this way to avoid defined (BSD) || defined (USG)
97 because the vms compiler doesn't grok `defined' */
105 #endif /* not 4.1 bsd */
108 /* On some systems (DGUX comes to mind real fast) FASYNC causes
109 background writes to the terminal to stop all processes in the
110 process group when invoked under the csh (and probably any shell
111 with job control). This stops Emacs dead in its tracks when coming
116 #include <sys/ioctl.h>
120 #ifdef BROKEN_TIOCGWINSZ
125 #include <sys/utsname.h>
127 #ifndef MEMORY_IN_STRING_H
132 #include <sys/sioctl.h>
135 #include <sys/stream.h>
136 #include <sys/ptem.h>
138 #endif /* TIOCGWINSZ */
141 extern int quit_char
;
145 #include "termhooks.h"
146 #include "termchar.h"
147 #include "termopts.h"
148 #include "dispextern.h"
151 #ifdef NONSYSTEM_DIR_LIBRARY
153 #endif /* NONSYSTEM_DIR_LIBRARY */
155 #include "syssignal.h"
158 static int baud_convert
[] =
163 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
164 1800, 2400, 4800, 9600, 19200, 38400
170 /* The file descriptor for Emacs's input terminal.
171 Under Unix, this is normaly zero except when using X;
172 under VMS, we place the input channel number here.
173 This allows us to write more code that works for both VMS and Unix. */
176 /* Specify a different file descriptor for further input operations. */
185 /* Discard pending input on descriptor input_fd. */
189 struct emacs_tty buf
;
194 /* Discarding input is not safe when the input could contain
195 replies from the X server. So don't do it. */
196 if (read_socket_hook
)
201 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
202 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
208 ioctl (input_fd
, TIOCFLUSH
, &zero
);
210 #else /* not Apollo */
211 EMACS_GET_TTY (input_fd
, &buf
);
212 EMACS_SET_TTY (input_fd
, &buf
, 0);
213 #endif /* not Apollo */
219 /* Arrange for character C to be read as the next input from
225 /* Should perhaps error if in batch mode */
227 ioctl (input_fd
, TIOCSTI
, &c
);
228 #else /* no TIOCSTI */
229 error ("Cannot stuff terminal input characters in this version of Unix.");
230 #endif /* no TIOCSTI */
244 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
245 &sg
.class, 12, 0, 0, 0, 0 );
246 ospeed
= sg
.xmit_baud
;
251 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | B9600
;
252 tcgetattr (input_fd
, &sg
);
253 ospeed
= cfgetospeed (&sg
);
254 #else /* neither VMS nor TERMIOS */
258 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | B9600
;
260 tcgetattr (input_fd
, &sg
);
262 ioctl (input_fd
, TCGETA
, &sg
);
264 ospeed
= sg
.c_cflag
& CBAUD
;
265 #else /* neither VMS nor TERMIOS nor TERMIO */
268 sg
.sg_ospeed
= B9600
;
269 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
271 ospeed
= sg
.sg_ospeed
;
272 #endif /* not HAVE_TERMIO */
273 #endif /* not HAVE_TERMIOS */
277 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
278 ? baud_convert
[ospeed
] : 9600);
284 set_exclusive_use (fd
)
288 ioctl (fd
, FIOCLEX
, 0);
290 /* Ok to do nothing if this feature does not exist */
295 wait_without_blocking ()
298 wait3 (0, WNOHANG
| WUNTRACED
, 0);
300 croak ("wait_without_blocking");
302 synch_process_alive
= 0;
305 #endif /* not subprocesses */
307 int wait_debugging
; /* Set nonzero to make following function work under dbx
308 (at least for bsd). */
311 wait_for_termination_signal ()
314 /* Wait for subprocess with process id `pid' to terminate and
315 make sure it will get eliminated (not remain forever as a zombie) */
317 wait_for_termination (pid
)
326 status
= SYS$
FORCEX (&pid
, 0, 0);
329 #if defined (BSD) || (defined (HPUX) && !defined (HPUX_5))
330 /* Note that kill returns -1 even if the process is just a zombie now.
331 But inevitably a SIGCHLD interrupt should be generated
332 and child_sig will do wait3 and make the process go away. */
333 /* There is some indication that there is a bug involved with
334 termination of subprocesses, perhaps involving a kernel bug too,
335 but no idea what it is. Just as a hunch we signal SIGCHLD to see
336 if that causes the problem to go away or get worse. */
337 sigsetmask (sigmask (SIGCHLD
));
338 if (0 > kill (pid
, 0))
340 sigsetmask (SIGEMPTYMASK
);
341 kill (getpid (), SIGCHLD
);
347 sigpause (SIGEMPTYMASK
);
348 #else /* not BSD, and not HPUX version >= 6 */
349 #if defined (UNIPLUS)
350 if (0 > kill (pid
, 0))
353 #else /* neither BSD nor UNIPLUS: random sysV */
354 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
355 sigblock (sigmask (SIGCHLD
));
356 if (0 > kill (pid
, 0))
358 sigunblock (sigmask (SIGCHLD
));
361 sigpause (SIGEMPTYMASK
);
362 #else /* not POSIX_SIGNALS */
363 #ifdef HAVE_SYSV_SIGPAUSE
365 if (0 > kill (pid
, 0))
371 #else /* not HAVE_SYSV_SIGPAUSE */
372 if (0 > kill (pid
, 0))
374 /* Using sleep instead of pause avoids timing error.
375 If the inferior dies just before the sleep,
376 we lose just one second. */
378 #endif /* not HAVE_SYSV_SIGPAUSE */
379 #endif /* not POSIX_SIGNALS */
380 #endif /* not UNIPLUS */
381 #endif /* not BSD, and not HPUX version >= 6 */
383 #else /* not subprocesses */
385 if (kill (pid
, 0) < 0)
391 if (status
== pid
|| status
== -1)
394 #endif /* not subprocesses */
401 * flush any pending output
402 * (may flush input as well; it does not matter the way we use it)
405 flush_pending_output (channel
)
409 /* If we try this, we get hit with SIGTTIN, because
410 the child's tty belongs to the child's pgrp. */
413 ioctl (channel
, TCFLSH
, 1);
417 /* 3rd arg should be ignored
418 but some 4.2 kernels actually want the address of an int
419 and nonzero means something different. */
420 ioctl (channel
, TIOCFLUSH
, &zero
);
427 /* Set up the terminal at the other end of a pseudo-terminal that
428 we will be controlling an inferior through.
429 It should not echo or do line-editing, since that is done
430 in Emacs. No padding needed for insertion into an Emacs buffer. */
432 child_setup_tty (out
)
437 EMACS_GET_TTY (out
, &s
);
439 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
440 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
441 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
442 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
443 /* No output delays */
444 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
445 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
446 s
.main
.c_iflag
&= ~IUCLC
; /* Disable map of upper case to lower on
448 s
.main
.c_oflag
&= ~OLCUC
; /* Disable map of lower case to upper on
451 /* Said to be unnecessary: */
452 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
453 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
456 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
457 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
458 s
.main
.c_cc
[VERASE
] = 0377; /* disable erase processing */
459 s
.main
.c_cc
[VKILL
] = 0377; /* disable kill processing */
462 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
466 /* AIX enhanced edit loses NULs, so disable it */
469 s
.main
.c_iflag
&= ~ASCEDIT
;
471 /* Also, PTY overloads NUL and BREAK.
472 don't ignore break, but don't signal either, so it looks like NUL. */
473 s
.main
.c_iflag
&= ~IGNBRK
;
474 s
.main
.c_iflag
&= ~BRKINT
;
475 /* QUIT and INTR work better as signals, so disable character forms */
476 s
.main
.c_cc
[VINTR
] = 0377;
477 #ifdef SIGNALS_VIA_CHARACTERS
478 /* the QUIT and INTR character are used in process_send_signal
479 so set them here to something useful. */
480 if (s
.main
.c_cc
[VQUIT
] == 0377)
481 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
482 if (s
.main
.c_cc
[VINTR
] == 0377)
483 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
484 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
485 /* QUIT and INTR work better as signals, so disable character forms */
486 s
.main
.c_cc
[VQUIT
] = 0377;
487 s
.main
.c_cc
[VINTR
] = 0377;
488 s
.main
.c_lflag
&= ~ISIG
;
489 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
490 s
.main
.c_cc
[VEOL
] = 0377;
491 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
494 #else /* not HAVE_TERMIO */
496 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
498 s
.main
.sg_erase
= 0377;
499 s
.main
.sg_kill
= 0377;
501 #endif /* not HAVE_TERMIO */
503 EMACS_SET_TTY (out
, &s
, 0);
512 ioctl (out
, FIOASYNC
, &zero
);
518 #endif /* subprocesses */
524 EMACS_SET_TTY_PGRP (input_fd
, &pid
);
527 /* Record a signal code and the handler for it. */
531 SIGTYPE (*handler
) ();
534 /* Suspend the Emacs process; give terminal to its superior. */
539 /* "Foster" parentage allows emacs to return to a subprocess that attached
540 to the current emacs as a cheaper than starting a whole new process. This
541 is set up by KEPTEDITOR.COM. */
542 unsigned long parent_id
, foster_parent_id
;
545 fpid_string
= getenv ("EMACS_PARENT_PID");
546 if (fpid_string
!= NULL
)
548 sscanf (fpid_string
, "%x", &foster_parent_id
);
549 if (foster_parent_id
!= 0)
550 parent_id
= foster_parent_id
;
552 parent_id
= getppid ();
555 parent_id
= getppid ();
557 xfree (fpid_string
); /* On VMS, this was malloc'd */
559 if (parent_id
&& parent_id
!= 0xffffffff)
561 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
562 int status
= LIB$
ATTACH (&parent_id
) & 1;
563 signal (SIGINT
, oldsig
);
572 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
573 d_prompt
.a
= "Emacs: "; /* Just a reminder */
574 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
583 int pgrp
= getpgrp ();
585 int pgrp
= getpgrp (0);
587 EMACS_KILLPG (pgrp
, SIGTSTP
);
590 #else /* No SIGTSTP */
591 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
592 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
593 kill (getpid (), SIGQUIT
);
595 #else /* No SIGTSTP or USG_JOBCTRL */
597 /* On a system where suspending is not implemented,
598 instead fork a subshell and let it talk directly to the terminal
601 struct save_signal saved_handlers
[5];
603 saved_handlers
[0].code
= SIGINT
;
604 saved_handlers
[1].code
= SIGQUIT
;
605 saved_handlers
[2].code
= SIGTERM
;
607 saved_handlers
[3].code
= SIGIO
;
608 saved_handlers
[4].code
= 0;
610 saved_handlers
[3].code
= 0;
614 error ("Can't spawn subshell");
619 sh
= (char *) egetenv ("SHELL");
622 /* Use our buffer's default directory for the subshell. */
628 /* mentioning current_buffer->buffer would mean including buffer.h,
629 which somehow wedges the hp compiler. So instead... */
631 dir
= intern ("default-directory");
633 if (XFASTINT (Fboundp (dir
)) == XFASTINT (Qnil
))
635 dir
= Fsymbol_value (dir
);
636 if (XTYPE (dir
) != Lisp_String
)
639 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
640 len
= XSTRING (dir
)->size
;
641 bcopy (XSTRING (dir
)->data
, str
, len
);
642 if (str
[len
- 1] != '/') str
[len
++] = '/';
648 close_process_descs (); /* Close Emacs's pipes/ptys */
653 extern int emacs_priority
;
656 nice (-emacs_priority
);
661 write (1, "Can't execute subshell", 22);
665 save_signal_handlers (saved_handlers
);
666 synch_process_alive
= 1;
667 wait_for_termination (pid
);
668 restore_signal_handlers (saved_handlers
);
670 #endif /* no USG_JOBCTRL */
671 #endif /* no SIGTSTP */
675 save_signal_handlers (saved_handlers
)
676 struct save_signal
*saved_handlers
;
678 while (saved_handlers
->code
)
680 saved_handlers
->handler
681 = (SIGTYPE (*) ()) signal (saved_handlers
->code
, SIG_IGN
);
686 restore_signal_handlers (saved_handlers
)
687 struct save_signal
*saved_handlers
;
689 while (saved_handlers
->code
)
691 signal (saved_handlers
->code
, saved_handlers
->handler
);
703 old_fcntl_flags
= fcntl (input_fd
, F_GETFL
, 0) & ~FASYNC
;
713 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
718 sigunblock (sigmask (SIGWINCH
));
720 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
722 interrupts_deferred
= 0;
728 sigblock (sigmask (SIGWINCH
));
730 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
731 interrupts_deferred
= 1;
734 #else /* no FASYNC */
735 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
740 ioctl (input_fd
, FIOASYNC
, &on
);
741 interrupts_deferred
= 0;
748 ioctl (input_fd
, FIOASYNC
, &off
);
749 interrupts_deferred
= 1;
752 #else /* not FASYNC, not STRIDE */
756 croak ("request_sigio");
761 croak ("unrequest_sigio");
768 /* Saving and restoring the process group of Emacs's terminal. */
772 /* The process group of which Emacs was a member when it initially
775 If Emacs was in its own process group (i.e. inherited_pgroup ==
776 getpid ()), then we know we're running under a shell with job
777 control (Emacs would never be run as part of a pipeline).
780 If Emacs was not in its own process group, then we know we're
781 running under a shell (or a caller) that doesn't know how to
782 separate itself from Emacs (like sh). Emacs must be in its own
783 process group in order to receive SIGIO correctly. In this
784 situation, we put ourselves in our own pgroup, forcibly set the
785 tty's pgroup to our pgroup, and make sure to restore and reinstate
786 the tty's pgroup just like any other terminal setting. If
787 inherited_group was not the tty's pgroup, then we'll get a
788 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
789 it goes foreground in the future, which is what should happen. */
790 int inherited_pgroup
;
792 /* Split off the foreground process group to Emacs alone.
793 When we are in the foreground, but not started in our own process
794 group, redirect the TTY to point to our own process group. We need
795 to be in our own process group to receive SIGIO properly. */
796 narrow_foreground_group ()
800 setpgrp (0, inherited_pgroup
);
801 if (inherited_pgroup
!= me
)
802 EMACS_SET_TTY_PGRP (input_fd
, &me
);
806 /* Set the tty to our original foreground group. */
807 widen_foreground_group ()
809 if (inherited_pgroup
!= getpid ())
810 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
811 setpgrp (0, inherited_pgroup
);
816 /* Getting and setting emacs_tty structures. */
818 /* Set *TC to the parameters associated with the terminal FD.
819 Return zero if all's well, or -1 if we ran into an error we
820 couldn't deal with. */
822 emacs_get_tty (fd
, settings
)
824 struct emacs_tty
*settings
;
826 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
828 /* We have those nifty POSIX tcmumbleattr functions. */
829 if (tcgetattr (fd
, &settings
->main
) < 0)
834 /* The SYSV-style interface? */
835 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
840 /* Vehemently Monstrous System? :-) */
841 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
842 &settings
->main
.class, 12, 0, 0, 0, 0)
847 /* I give up - I hope you have the BSD ioctls. */
848 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
855 /* Suivant - Do we have to get struct ltchars data? */
857 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
861 /* How about a struct tchars and a wordful of lmode bits? */
863 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
864 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
868 /* We have survived the tempest. */
873 /* Set the parameters of the tty on FD according to the contents of
874 *SETTINGS. If WAITP is non-zero, we wait for all queued output to
875 be written before making the change; otherwise, we forget any
876 queued input and make the change immediately.
877 Return 0 if all went well, and -1 if anything failed. */
879 emacs_set_tty (fd
, settings
, waitp
)
881 struct emacs_tty
*settings
;
884 /* Set the primary parameters - baud rate, character size, etcetera. */
887 /* We have those nifty POSIX tcmumbleattr functions.
888 William J. Smith <wjs@wiis.wang.com> writes:
889 "POSIX 1003.1 defines tcsetattr() to return success if it was
890 able to perform any of the requested actions, even if some
891 of the requested actions could not be performed.
892 We must read settings back to ensure tty setup properly.
893 AIX requires this to keep tty from hanging occasionally." */
894 /* This make sure that we don't loop indefinitely in here. */
895 for (i
= 0 ; i
< 10 ; i
++)
896 if (tcsetattr (fd
, waitp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
907 /* Get the current settings, and see if they're what we asked for. */
908 tcgetattr (fd
, &new);
909 /* We cannot use memcmp on the whole structure here because under
910 * aix386 the termios structure has some reserved field that may
913 if ( new.c_iflag
== settings
->main
.c_iflag
914 && new.c_oflag
== settings
->main
.c_oflag
915 && new.c_cflag
== settings
->main
.c_cflag
916 && new.c_lflag
== settings
->main
.c_lflag
917 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
925 /* The SYSV-style interface? */
926 if (ioctl (fd
, waitp
? TCSETAW
: TCSETAF
, &settings
->main
) < 0)
931 /* Vehemently Monstrous System? :-) */
932 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
933 &settings
->main
.class, 12, 0, 0, 0, 0)
938 /* I give up - I hope you have the BSD ioctls. */
939 if (ioctl (fd
, (waitp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
946 /* Suivant - Do we have to get struct ltchars data? */
948 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
952 /* How about a struct tchars and a wordful of lmode bits? */
954 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
955 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
959 /* We have survived the tempest. */
964 /* The initial tty mode bits */
965 struct emacs_tty old_tty
;
967 int term_initted
; /* 1 if outer tty status has been recorded */
970 /* BSD 4.1 needs to keep track of the lmode bits in order to start
978 #endif /* F_SETOWN */
979 #endif /* F_SETOWN_BUG */
981 /* This may also be defined in stdio,
982 but if so, this does no harm,
983 and using the same name avoids wasting the other one's space. */
985 #if defined (USG) || defined (DGUX)
986 unsigned char _sobuf
[BUFSIZ
+8];
992 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
995 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1000 struct emacs_tty tty
;
1004 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1005 extern int (*interrupt_signal
) ();
1014 input_ef
= get_kbd_event_flag ();
1015 /* LIB$GET_EF (&input_ef); */
1016 SYS$
CLREF (input_ef
);
1017 waiting_for_ast
= 0;
1019 timer_ef
= get_timer_event_flag ();
1020 /* LIB$GET_EF (&timer_ef); */
1021 SYS$
CLREF (timer_ef
);
1025 LIB$
GET_EF (&process_ef
);
1026 SYS$
CLREF (process_ef
);
1028 if (input_ef
/ 32 != process_ef
/ 32)
1029 croak ("Input and process event flags in different clusters.");
1031 if (input_ef
/ 32 != timer_ef
/ 32)
1032 croak ("Input and timer event flags in different clusters.");
1034 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1035 ((unsigned) 1 << (process_ef
% 32));
1037 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1038 ((unsigned) 1 << (timer_ef
% 32));
1040 sys_access_reinit ();
1042 #endif /* not VMS */
1045 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1046 narrow_foreground_group ();
1049 EMACS_GET_TTY (input_fd
, &old_tty
);
1051 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1055 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1056 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1057 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1059 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1061 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1062 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1064 tty
.main
.c_iflag
&= ~IEXTEN
; /* Disable other editing characters. */
1066 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1069 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1071 tty
.main
.c_iflag
&= ~IXANY
;
1075 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1076 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1078 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1082 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1083 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1086 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1087 /* Set up C-g for both SIGQUIT and SIGINT.
1088 We don't know which we will get, but we handle both alike
1089 so which one it really gives us does not matter. */
1090 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1091 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1092 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1094 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1097 #if defined (mips) || defined (HAVE_TCATTR)
1099 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1102 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1103 #endif /* V_DSUSP */
1104 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1105 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1108 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1111 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1112 #endif /* VREPRINT */
1114 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1115 #endif /* VWERASE */
1117 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1118 #endif /* VDISCARD */
1119 #endif /* mips or HAVE_TCATTR */
1122 /* AIX enhanced edit loses NULs, so disable it */
1123 tty
.main
.c_line
= 0;
1124 tty
.main
.c_iflag
&= ~ASCEDIT
;
1126 tty
.main
.c_cc
[VSTRT
] = 255;
1127 tty
.main
.c_cc
[VSTOP
] = 255;
1128 tty
.main
.c_cc
[VSUSP
] = 255;
1129 tty
.main
.c_cc
[VDSUSP
] = 255;
1130 #endif /* IBMR2AIX */
1131 /* Also, PTY overloads NUL and BREAK.
1132 don't ignore break, but don't signal either, so it looks like NUL.
1133 This really serves a purpose only if running in an XTERM window
1134 or via TELNET or the like, but does no harm elsewhere. */
1135 tty
.main
.c_iflag
&= ~IGNBRK
;
1136 tty
.main
.c_iflag
&= ~BRKINT
;
1138 #else /* if not HAVE_TERMIO */
1140 tty
.main
.tt_char
|= TT$M_NOECHO
;
1142 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1144 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1146 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1147 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1148 #else /* not VMS (BSD, that is) */
1149 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1151 tty
.main
.sg_flags
|= ANYP
;
1152 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1153 #endif /* not VMS (BSD, that is) */
1154 #endif /* not HAVE_TERMIO */
1156 /* If going to use CBREAK mode, we must request C-g to interrupt
1157 and turn off start and stop chars, etc. If not going to use
1158 CBREAK mode, do this anyway so as to turn off local flow
1159 control for user coming over network on 4.2; in this case,
1160 only t_stopc and t_startc really matter. */
1163 /* Note: if not using CBREAK mode, it makes no difference how we
1165 tty
.tchars
= new_tchars
;
1166 tty
.tchars
.t_intrc
= quit_char
;
1169 tty
.tchars
.t_startc
= '\021';
1170 tty
.tchars
.t_stopc
= '\023';
1173 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
1179 #define LNOFLSH 0100000
1182 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1184 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1185 anything, and leaving it in breaks the meta key. Go figure. */
1186 tty
.lmode
&= ~LLITOUT
;
1193 #endif /* HAVE_TCHARS */
1194 #endif /* not HAVE_TERMIO */
1197 tty
.ltchars
= new_ltchars
;
1198 #endif /* HAVE_LTCHARS */
1200 EMACS_SET_TTY (input_fd
, &tty
, 0);
1202 /* This code added to insure that, if flow-control is not to be used,
1203 we have an unlocked terminal at the start. */
1206 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1210 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1218 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1219 to be only LF. This is the way that is done. */
1222 if (ioctl (1, HFTGETID
, &tty
) != -1)
1223 write (1, "\033[20l", 5);
1229 /* Appears to do nothing when in PASTHRU mode.
1230 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1231 interrupt_signal, oob_chars, 0, 0, 0, 0);
1233 queue_kbd_input (0);
1238 #ifndef F_SETOWN_BUG
1239 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1240 if (interrupt_input
)
1242 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1243 fcntl (input_fd
, F_SETOWN
, getpid ());
1246 #endif /* F_GETOWN */
1247 #endif /* F_SETOWN_BUG */
1248 #endif /* F_SETFL */
1251 if (interrupt_input
)
1255 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1259 /* This symbol is defined on recent USG systems.
1260 Someone says without this call USG won't really buffer the file
1261 even with a call to setbuf. */
1262 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
1264 setbuf (stdout
, _sobuf
);
1266 set_terminal_modes ();
1267 if (term_initted
&& no_redraw_on_reenter
)
1269 if (display_completed
)
1270 direct_output_forward_char (0);
1276 if (FRAMEP (Vterminal_frame
))
1277 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1284 /* Return nonzero if safe to use tabs in output.
1285 At the time this is called, init_sys_modes has not been done yet. */
1289 struct emacs_tty tty
;
1291 EMACS_GET_TTY (input_fd
, &tty
);
1292 return EMACS_TTY_TABS_OK (&tty
);
1295 /* Get terminal size from system.
1296 Store number of lines into *heightp and width into *widthp.
1297 If zero or a negative number is stored, the value is not valid. */
1299 get_frame_size (widthp
, heightp
)
1300 int *widthp
, *heightp
;
1306 struct winsize size
;
1308 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1309 *widthp
= *heightp
= 0;
1312 *widthp
= size
.ws_col
;
1313 *heightp
= size
.ws_row
;
1319 /* SunOS - style. */
1320 struct ttysize size
;
1322 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1323 *widthp
= *heightp
= 0;
1326 *widthp
= size
.ts_cols
;
1327 *heightp
= size
.ts_lines
;
1333 struct sensemode tty
;
1335 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1336 &tty
.class, 12, 0, 0, 0, 0);
1337 *widthp
= tty
.scr_wid
;
1338 *heightp
= tty
.scr_len
;
1340 #else /* system doesn't know size */
1345 #endif /* not VMS */
1346 #endif /* not SunOS-style */
1347 #endif /* not BSD-style */
1351 /* Prepare the terminal for exiting Emacs; move the cursor to the
1352 bottom of the frame, turn off interrupt-driven I/O, etc. */
1362 if (read_socket_hook
|| !EQ (Vwindow_system
, Qnil
))
1364 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1365 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1366 /* clear_end_of_line may move the cursor */
1367 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1370 /* HFT devices normally use ^J as a LF/CR. We forced it to
1371 do the LF only. Now, we need to reset it. */
1374 if (ioctl (1, HFTGETID
, &tty
) != -1)
1375 write (1, "\033[20h", 5);
1379 reset_terminal_modes ();
1383 /* Avoid possible loss of output when changing terminal modes. */
1384 fsync (fileno (stdout
));
1389 #ifndef F_SETOWN_BUG
1390 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1391 if (interrupt_input
)
1394 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1396 #endif /* F_SETOWN */
1397 #endif /* F_SETOWN_BUG */
1398 #endif /* F_SETFL */
1400 if (interrupt_input
)
1404 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1412 widen_foreground_group ();
1418 /* Set up the proper status flags for use of a pty. */
1423 /* I'm told that TOICREMOTE does not mean control chars
1424 "can't be sent" but rather that they don't have
1425 input-editing or signaling effects.
1426 That should be good, because we have other ways
1427 to do those things in Emacs.
1428 However, telnet mode seems not to work on 4.2.
1429 So TIOCREMOTE is turned off now. */
1431 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1432 will hang. In particular, the "timeout" feature (which
1433 causes a read to return if there is no data available)
1434 does this. Also it is known that telnet mode will hang
1435 in such a way that Emacs must be stopped (perhaps this
1436 is the same problem).
1438 If TIOCREMOTE is turned off, then there is a bug in
1439 hp-ux which sometimes loses data. Apparently the
1440 code which blocks the master process when the internal
1441 buffer fills up does not work. Other than this,
1442 though, everything else seems to work fine.
1444 Since the latter lossage is more benign, we may as well
1445 lose that way. -- cph */
1450 ioctl (fd
, FIONBIO
, &on
);
1455 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1456 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1457 /* cause EMACS not to die when it should, i.e., when its own controlling */
1458 /* tty goes away. I've complained to the AIX developers, and they may */
1459 /* change this behavior, but I'm not going to hold my breath. */
1460 signal (SIGHUP
, SIG_IGN
);
1463 #endif /* HAVE_PTYS */
1467 /* Assigning an input channel is done at the start of Emacs execution.
1468 This is called each time Emacs is resumed, also, but does nothing
1469 because input_chain is no longer zero. */
1477 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1483 /* Deassigning the input channel is done before exiting. */
1487 return SYS$
DASSGN (input_fd
);
1492 /* Request reading one character into the keyboard buffer.
1493 This is done as soon as the buffer becomes empty. */
1498 extern kbd_input_ast ();
1500 waiting_for_ast
= 0;
1502 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1503 &input_iosb
, kbd_input_ast
, 1,
1504 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1509 /* Ast routine that is called when keyboard input comes in
1510 in accord with the SYS$QIO above. */
1514 register int c
= -1;
1515 int old_errno
= errno
;
1516 extern EMACS_TIME
*input_available_clear_time
;
1518 if (waiting_for_ast
)
1519 SYS$
SETEF (input_ef
);
1520 waiting_for_ast
= 0;
1523 if (input_count
== 25)
1525 printf ("Ast # %d,", input_count
);
1526 printf (" iosb = %x, %x, %x, %x",
1527 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1530 if (input_iosb
.offset
)
1534 printf (", char = 0%o", c
);
1546 struct input_event e
;
1547 e
.kind
= ascii_keystroke
;
1548 XSET (e
.code
, Lisp_Int
, c
);
1550 XSET(e
.frame_or_window
, Lisp_Frame
, selected_frame
);
1552 e
.frame_or_window
= Qnil
;
1554 kbd_buffer_store_event (&e
);
1556 if (input_available_clear_time
)
1557 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1561 /* Wait until there is something in kbd_buffer. */
1563 wait_for_kbd_input ()
1565 extern int have_process_input
, process_exited
;
1567 /* If already something, avoid doing system calls. */
1568 if (detect_input_pending ())
1572 /* Clear a flag, and tell ast routine above to set it. */
1573 SYS$
CLREF (input_ef
);
1574 waiting_for_ast
= 1;
1575 /* Check for timing error: ast happened while we were doing that. */
1576 if (!detect_input_pending ())
1578 /* No timing error: wait for flag to be set. */
1579 set_waiting_for_input (0);
1580 SYS$
WFLOR (input_ef
, input_eflist
);
1581 clear_waiting_for_input (0);
1582 if (!detect_input_pending ())
1583 /* Check for subprocess input availability */
1585 int dsp
= have_process_input
|| process_exited
;
1587 SYS$
CLREF (process_ef
);
1588 if (have_process_input
)
1589 process_command_input ();
1594 update_mode_lines
++;
1595 redisplay_preserve_echo_area ();
1599 waiting_for_ast
= 0;
1602 /* Get rid of any pending QIO, when we are about to suspend
1603 or when we want to throw away pending input.
1604 We wait for a positive sign that the AST routine has run
1605 and therefore there is no I/O request queued when we return.
1606 SYS$SETAST is used to avoid a timing error. */
1611 printf ("At end_kbd_input.\n");
1615 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
1617 SYS$
CANCEL (input_fd
);
1622 /* Clear a flag, and tell ast routine above to set it. */
1623 SYS$
CLREF (input_ef
);
1624 waiting_for_ast
= 1;
1626 SYS$
CANCEL (input_fd
);
1628 SYS$
WAITFR (input_ef
);
1629 waiting_for_ast
= 0;
1632 /* Wait for either input available or time interval expiry. */
1634 input_wait_timeout (timeval
)
1635 int timeval
; /* Time to wait, in seconds */
1638 static int zero
= 0;
1639 static int large
= -10000000;
1641 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1643 /* If already something, avoid doing system calls. */
1644 if (detect_input_pending ())
1648 /* Clear a flag, and tell ast routine above to set it. */
1649 SYS$
CLREF (input_ef
);
1650 waiting_for_ast
= 1;
1651 /* Check for timing error: ast happened while we were doing that. */
1652 if (!detect_input_pending ())
1654 /* No timing error: wait for flag to be set. */
1656 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1657 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
1659 waiting_for_ast
= 0;
1662 /* The standard `sleep' routine works some other way
1663 and it stops working if you have ever quit out of it.
1664 This one continues to work. */
1670 static int zero
= 0;
1671 static int large
= -10000000;
1673 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1676 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1677 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
1692 croak ("request sigio");
1697 croak ("unrequest sigio");
1702 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
1707 #ifndef SYSTEM_MALLOC
1714 /* Some systems that cannot dump also cannot implement these. */
1717 * Return the address of the start of the text segment prior to
1718 * doing an unexec. After unexec the return value is undefined.
1719 * See crt0.c for further explanation and _start.
1723 #ifndef CANNOT_UNEXEC
1728 return ((char *) TEXT_START
);
1732 return ((char *) csrt
);
1733 #else /* not GOULD */
1734 extern int _start ();
1735 return ((char *) _start
);
1737 #endif /* TEXT_START */
1739 #endif /* not CANNOT_UNEXEC */
1742 * Return the address of the start of the data segment prior to
1743 * doing an unexec. After unexec the return value is undefined.
1744 * See crt0.c for further information and definition of data_start.
1746 * Apparently, on BSD systems this is etext at startup. On
1747 * USG systems (swapping) this is highly mmu dependent and
1748 * is also dependent on whether or not the program is running
1749 * with shared text. Generally there is a (possibly large)
1750 * gap between end of text and start of data with shared text.
1752 * On Uniplus+ systems with shared text, data starts at a
1753 * fixed address. Each port (from a given oem) is generally
1754 * different, and the specific value of the start of data can
1755 * be obtained via the UniPlus+ specific "uvar" system call,
1756 * however the method outlined in crt0.c seems to be more portable.
1758 * Probably what will have to happen when a USG unexec is available,
1759 * at least on UniPlus, is temacs will have to be made unshared so
1760 * that text and data are contiguous. Then once loadup is complete,
1761 * unexec will produce a shared executable where the data can be
1762 * at the normal shared text boundry and the startofdata variable
1763 * will be patched by unexec to the correct value.
1771 return ((char *) DATA_START
);
1773 #ifdef ORDINARY_LINK
1775 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
1776 * data_start isn't defined. We take the address of environ, which
1777 * is known to live at or near the start of the system crt0.c, and
1778 * we don't sweat the handful of bytes that might lose.
1780 extern char **environ
;
1782 return((char *) &environ
);
1784 extern int data_start
;
1785 return ((char *) &data_start
);
1786 #endif /* ORDINARY_LINK */
1787 #endif /* DATA_START */
1789 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
1792 /* Some systems that cannot dump also cannot implement these. */
1795 * Return the address of the end of the text segment prior to
1796 * doing an unexec. After unexec the return value is undefined.
1803 return ((char *) TEXT_END
);
1806 return ((char *) &etext
);
1811 * Return the address of the end of the data segment prior to
1812 * doing an unexec. After unexec the return value is undefined.
1819 return ((char *) DATA_END
);
1822 return ((char *) &edata
);
1826 #endif /* not CANNOT_DUMP */
1828 /* Get_system_name returns as its value
1829 a string for the Lisp function system-name to return. */
1835 /* Can't have this within the function since `static' is #defined to
1836 nothing for some USG systems. */
1838 #ifdef HAVE_GETHOSTNAME
1839 static char get_system_name_name
[256];
1840 #else /* not HAVE_GETHOSTNAME */
1841 static struct utsname get_system_name_name
;
1842 #endif /* not HAVE_GETHOSTNAME */
1849 #include <sys/socket.h>
1851 #endif /* HAVE_SOCKETS */
1852 #endif /* not VMS */
1853 #endif /* not USG */
1854 #endif /* not BSD4_1 */
1860 #ifdef HAVE_GETHOSTNAME
1861 gethostname (get_system_name_name
, sizeof (get_system_name_name
));
1862 return get_system_name_name
;
1863 #else /* not HAVE_GETHOSTNAME */
1864 uname (&get_system_name_name
);
1865 return (get_system_name_name
.nodename
);
1866 #endif /* not HAVE_GETHOSTNAME */
1870 #else /* not USG, not 4.1 */
1871 static char system_name_saved
[32];
1874 if ((sp
= egetenv ("SYS$NODE")) == 0)
1880 if ((end
= index (sp
, ':')) != 0)
1883 strcpy (system_name_saved
, sp
);
1885 gethostname (system_name_saved
, sizeof (system_name_saved
));
1887 /* Turn the hostname into the official, fully-qualified hostname.
1888 Don't do this if we're going to dump; this can confuse system
1889 libraries on some machines and make the dumped emacs core dump. */
1892 #endif /* not CANNOT_DUMP */
1895 hp
= gethostbyname (system_name_saved
);
1896 if (hp
&& strlen (hp
->h_name
) < sizeof(system_name_saved
))
1897 strcpy (system_name_saved
, hp
->h_name
);
1899 #endif /* HAVE_SOCKETS */
1900 #endif /* not VMS */
1901 return system_name_saved
;
1902 #endif /* not USG, not 4.1 */
1903 #endif /* not USG */
1907 #ifndef HAVE_GETHOSTNAME
1908 void gethostname(buf
, len
)
1913 s
= getenv ("SYS$NODE");
1917 strncpy (buf
, s
, len
- 2);
1918 buf
[len
- 1] = '\0';
1920 } /* static void gethostname */
1921 #endif /* ! HAVE_GETHOSTNAME */
1928 #ifdef HAVE_X_WINDOWS
1929 /* Cause explanatory error message at compile time,
1930 since the select emulation is not good enough for X. */
1931 int *x
= &x_windows_lose_if_no_select_system_call
;
1934 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
1935 * Only checks read descriptors.
1937 /* How long to wait between checking fds in select */
1938 #define SELECT_PAUSE 1
1941 /* For longjmp'ing back to read_input_waiting. */
1943 jmp_buf read_alarm_throw
;
1945 /* Nonzero if the alarm signal should throw back to read_input_waiting.
1946 The read_socket_hook function sets this to 1 while it is waiting. */
1948 int read_alarm_should_throw
;
1956 #else /* not BSD4_1 */
1957 signal (SIGALRM
, SIG_IGN
);
1958 #endif /* not BSD4_1 */
1959 if (read_alarm_should_throw
)
1960 longjmp (read_alarm_throw
, 1);
1963 /* Only rfds are checked. */
1965 select (nfds
, rfds
, wfds
, efds
, timeout
)
1967 int *rfds
, *wfds
, *efds
, *timeout
;
1969 int ravail
= 0, orfds
= 0, old_alarm
;
1970 int timeoutval
= timeout
? *timeout
: 100000;
1971 int *local_timeout
= &timeoutval
;
1972 extern int proc_buffered_char
[];
1973 #ifndef subprocesses
1974 int process_tick
= 0, update_tick
= 0;
1976 extern int process_tick
, update_tick
;
1978 SIGTYPE (*old_trap
) ();
1991 /* If we are looking only for the terminal, with no timeout,
1992 just read it and wait -- that's more efficient. */
1993 if (orfds
== 1 && *local_timeout
== 100000 && process_tick
== update_tick
)
1995 if (! detect_input_pending ())
1996 read_input_waiting ();
2001 /* Once a second, till the timer expires, check all the flagged read
2002 * descriptors to see if any input is available. If there is some then
2003 * set the corresponding bit in the return copy of rfds.
2007 register int to_check
, bit
, fd
;
2011 for (to_check
= nfds
, bit
= 1, fd
= 0; --to_check
>= 0; bit
<<= 1, fd
++)
2015 int avail
= 0, status
= 0;
2018 avail
= detect_input_pending (); /* Special keyboard handler */
2022 status
= ioctl (fd
, FIONREAD
, &avail
);
2023 #else /* no FIONREAD */
2024 /* Hoping it will return -1 if nothing available
2025 or 0 if all 0 chars requested are read. */
2026 if (proc_buffered_char
[fd
] >= 0)
2030 avail
= read (fd
, &buf
, 1);
2032 proc_buffered_char
[fd
] = buf
;
2034 #endif /* no FIONREAD */
2036 if (status
>= 0 && avail
> 0)
2044 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2046 old_alarm
= alarm (0);
2047 old_trap
= signal (SIGALRM
, select_alarm
);
2049 alarm (SELECT_PAUSE
);
2050 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2051 while (select_alarmed
== 0 && *local_timeout
!= 0
2052 && process_tick
== update_tick
)
2054 /* If we are interested in terminal input,
2055 wait by reading the terminal.
2056 That makes instant wakeup for terminal input at least. */
2059 read_input_waiting ();
2060 if (detect_input_pending ())
2066 (*local_timeout
) -= SELECT_PAUSE
;
2067 /* Reset the old alarm if there was one */
2069 signal (SIGALRM
, old_trap
);
2072 /* Reset or forge an interrupt for the original handler. */
2073 old_alarm
-= SELECT_PAUSE
;
2075 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2079 if (*local_timeout
== 0) /* Stop on timer being cleared */
2085 /* Read keyboard input into the standard buffer,
2086 waiting for at least one character. */
2088 /* Make all keyboard buffers much bigger when using X windows. */
2089 #ifdef HAVE_X_WINDOWS
2090 #define BUFFER_SIZE_FACTOR 16
2092 #define BUFFER_SIZE_FACTOR 1
2095 read_input_waiting ()
2097 char buf
[256 * BUFFER_SIZE_FACTOR
];
2098 struct input_event e
;
2100 extern int quit_char
;
2102 if (read_socket_hook
)
2104 read_alarm_should_throw
= 0;
2105 if (! setjmp (read_alarm_throw
))
2106 nread
= (*read_socket_hook
) (0, buf
, 256 * BUFFER_SIZE_FACTOR
, 1, 0);
2111 nread
= read (fileno (stdin
), buf
, 1);
2113 /* Scan the chars for C-g and store them in kbd_buffer. */
2114 e
.kind
= ascii_keystroke
;
2115 e
.frame_or_window
= selected_frame
;
2117 for (i
= 0; i
< nread
; i
++)
2119 XSET (e
.code
, Lisp_Int
, buf
[i
]);
2120 kbd_buffer_store_event (&e
);
2121 /* Don't look at input that follows a C-g too closely.
2122 This reduces lossage due to autorepeat on C-g. */
2123 if (buf
[i
] == quit_char
)
2128 #endif /* not HAVE_SELECT */
2129 #endif /* not VMS */
2133 * Partially emulate 4.2 open call.
2134 * open is defined as this in 4.1.
2136 * - added by Michael Bloom @ Citicorp/TTI
2141 sys_open (path
, oflag
, mode
)
2145 if (oflag
& O_CREAT
)
2146 return creat (path
, mode
);
2148 return open (path
, oflag
);
2155 lmode
= LINTRUP
| lmode
;
2156 ioctl (0, TIOCLSET
, &lmode
);
2163 lmode
= ~LINTRUP
& lmode
;
2164 ioctl (0, TIOCLSET
, &lmode
);
2171 interrupts_deferred
= 0;
2178 interrupts_deferred
= 1;
2181 /* still inside #ifdef BSD4_1 */
2184 int sigheld
; /* Mask of held signals */
2189 sigheld
|= sigbit (signum
);
2196 sigheld
|= sigbit (signum
);
2202 sigheld
&= ~sigbit (signum
);
2206 sigfree () /* Free all held signals */
2209 for (i
= 0; i
< NSIG
; i
++)
2210 if (sigheld
& sigbit (i
))
2217 return 1 << (i
- 1);
2219 #endif /* subprocesses */
2222 /* POSIX signals support - DJB */
2223 /* Anyone with POSIX signals should have ANSI C declarations */
2225 #ifdef POSIX_SIGNALS
2227 sigset_t old_mask
, empty_mask
, full_mask
, temp_mask
;
2228 static struct sigaction new_action
, old_action
;
2232 sigemptyset (&empty_mask
);
2233 sigfillset (&full_mask
);
2237 sys_signal (int signal_number
, signal_handler_t action
)
2240 /* This gets us restartable system calls for efficiency.
2241 The "else" code will works as well. */
2242 return (berk_signal (signal_number
, action
));
2244 sigemptyset (&new_action
.sa_mask
);
2245 new_action
.sa_handler
= action
;
2246 new_action
.sa_flags
= 0;
2247 sigaction (signal_number
, &new_action
, &old_action
);
2248 return (old_action
.sa_handler
);
2253 /* If we're compiling with GCC, we don't need this function, since it
2254 can be written as a macro. */
2256 sys_sigmask (int sig
)
2259 sigemptyset (&mask
);
2260 sigaddset (&mask
, sig
);
2266 sys_sigpause (sigset_t new_mask
)
2268 /* pause emulating berk sigpause... */
2269 sigsuspend (&new_mask
);
2273 /* I'd like to have these guys return pointers to the mask storage in here,
2274 but there'd be trouble if the code was saving multiple masks. I'll be
2275 safe and pass the structure. It normally won't be more than 2 bytes
2279 sys_sigblock (sigset_t new_mask
)
2282 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2287 sys_sigunblock (sigset_t new_mask
)
2290 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2295 sys_sigsetmask (sigset_t new_mask
)
2298 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2302 #endif /* POSIX_SIGNALS */
2309 register int length
;
2313 long max_str
= 65535;
2315 while (length
> max_str
) {
2316 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
2321 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
2323 while (length
-- > 0)
2325 #endif /* not VMS */
2328 /* Saying `void' requires a declaration, above, where bcopy is used
2329 and that declaration causes pain for systems where bcopy is a macro. */
2330 bcopy (b1
, b2
, length
)
2333 register int length
;
2336 long max_str
= 65535;
2338 while (length
> max_str
) {
2339 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
2345 (void) LIB$
MOVC3 (&length
, b1
, b2
);
2347 while (length
-- > 0)
2349 #endif /* not VMS */
2353 bcmp (b1
, b2
, length
) /* This could be a macro! */
2356 register int length
;
2359 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
2360 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
2362 return STR$
COMPARE (&src1
, &src2
);
2364 while (length
-- > 0)
2369 #endif /* not VMS */
2371 #endif /* not BSTRING */
2376 * The BSD random returns numbers in the range of
2377 * 0 to 2e31 - 1. The USG rand returns numbers in the
2378 * range of 0 to 2e15 - 1. This is probably not significant
2385 /* Arrange to return a range centered on zero. */
2386 return (rand () << 15) + rand () - (1 << 29);
2400 /* Arrange to return a range centered on zero. */
2401 return (rand () << 15) + rand () - (1 << 29);
2412 #ifdef WRONG_NAME_INSQUE
2425 /* If any place else asks for the TERM variable,
2426 allow it to be overridden with the EMACS_TERM variable
2427 before attempting to translate the logical name TERM. As a last
2428 resort, ask for VAX C's special idea of the TERM variable. */
2435 static char buf
[256];
2436 static struct dsc$descriptor_s equiv
2437 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2438 static struct dsc$descriptor_s d_name
2439 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2442 if (!strcmp (name
, "TERM"))
2444 val
= (char *) getenv ("EMACS_TERM");
2449 d_name
.dsc$w_length
= strlen (name
);
2450 d_name
.dsc$a_pointer
= name
;
2451 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2453 char *str
= (char *) xmalloc (eqlen
+ 1);
2454 bcopy (buf
, str
, eqlen
);
2456 /* This is a storage leak, but a pain to fix. With luck,
2457 no one will ever notice. */
2460 return (char *) getenv (name
);
2465 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2466 to force a call on the debugger from within the image. */
2471 LIB$
SIGNAL (SS$_DEBUG
);
2477 #ifdef LINK_CRTL_SHARE
2478 #ifdef SHAREABLE_LIB_BUG
2479 /* Variables declared noshare and initialized in sharable libraries
2480 cannot be shared. The VMS linker incorrectly forces you to use a private
2481 version which is uninitialized... If not for this "feature", we
2482 could use the C library definition of sys_nerr and sys_errlist. */
2484 char *sys_errlist
[] =
2488 "no such file or directory",
2490 "interrupted system call",
2492 "no such device or address",
2493 "argument list too long",
2494 "exec format error",
2497 "no more processes",
2498 "not enough memory",
2499 "permission denied",
2501 "block device required",
2502 "mount devices busy",
2504 "cross-device link",
2509 "file table overflow",
2510 "too many open files",
2514 "no space left on device",
2516 "read-only file system",
2522 "vax/vms specific error code nontranslatable error"
2524 #endif /* SHAREABLE_LIB_BUG */
2525 #endif /* LINK_CRTL_SHARE */
2528 #ifdef INTERRUPTIBLE_OPEN
2532 sys_open (path
, oflag
, mode
)
2536 register int rtnval
;
2538 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2539 && (errno
== EINTR
));
2543 #endif /* INTERRUPTIBLE_OPEN */
2545 #ifdef INTERRUPTIBLE_CLOSE
2550 register int rtnval
;
2552 while ((rtnval
= close (fd
)) == -1
2553 && (errno
== EINTR
));
2557 #endif /* INTERRUPTIBLE_CLOSE */
2559 #ifdef INTERRUPTIBLE_IO
2562 sys_read (fildes
, buf
, nbyte
)
2567 register int rtnval
;
2569 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
2570 && (errno
== EINTR
));
2575 sys_write (fildes
, buf
, nbyte
)
2580 register int rtnval
;
2582 while ((rtnval
= write (fildes
, buf
, nbyte
)) == -1
2583 && (errno
== EINTR
));
2587 #endif /* INTERRUPTIBLE_IO */
2592 * Substitute fork for vfork on USG flavors.
2600 #endif /* not HAVE_VFORK */
2604 * All of the following are for USG.
2606 * On USG systems the system calls are INTERRUPTIBLE by signals
2607 * that the user program has elected to catch. Thus the system call
2608 * must be retried in these cases. To handle this without massive
2609 * changes in the source code, we remap the standard system call names
2610 * to names for our own functions in sysdep.c that do the system call
2611 * with retries. Actually, for portability reasons, it is good
2612 * programming practice, as this example shows, to limit all actual
2613 * system calls to a single occurrence in the source. Sure, this
2614 * adds an extra level of function call overhead but it is almost
2615 * always negligible. Fred Fish, Unisoft Systems Inc.
2618 #ifndef HAVE_SYS_SIGLIST
2619 char *sys_siglist
[NSIG
+ 1] =
2622 /* AIX has changed the signals a bit */
2623 "bogus signal", /* 0 */
2624 "hangup", /* 1 SIGHUP */
2625 "interrupt", /* 2 SIGINT */
2626 "quit", /* 3 SIGQUIT */
2627 "illegal instruction", /* 4 SIGILL */
2628 "trace trap", /* 5 SIGTRAP */
2629 "IOT instruction", /* 6 SIGIOT */
2630 "crash likely", /* 7 SIGDANGER */
2631 "floating point exception", /* 8 SIGFPE */
2632 "kill", /* 9 SIGKILL */
2633 "bus error", /* 10 SIGBUS */
2634 "segmentation violation", /* 11 SIGSEGV */
2635 "bad argument to system call", /* 12 SIGSYS */
2636 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2637 "alarm clock", /* 14 SIGALRM */
2638 "software termination signum", /* 15 SIGTERM */
2639 "user defined signal 1", /* 16 SIGUSR1 */
2640 "user defined signal 2", /* 17 SIGUSR2 */
2641 "death of a child", /* 18 SIGCLD */
2642 "power-fail restart", /* 19 SIGPWR */
2643 "bogus signal", /* 20 */
2644 "bogus signal", /* 21 */
2645 "bogus signal", /* 22 */
2646 "bogus signal", /* 23 */
2647 "bogus signal", /* 24 */
2648 "LAN I/O interrupt", /* 25 SIGAIO */
2649 "PTY I/O interrupt", /* 26 SIGPTY */
2650 "I/O intervention required", /* 27 SIGIOINT */
2651 "HFT grant", /* 28 SIGGRANT */
2652 "HFT retract", /* 29 SIGRETRACT */
2653 "HFT sound done", /* 30 SIGSOUND */
2654 "HFT input ready", /* 31 SIGMSG */
2656 "bogus signal", /* 0 */
2657 "hangup", /* 1 SIGHUP */
2658 "interrupt", /* 2 SIGINT */
2659 "quit", /* 3 SIGQUIT */
2660 "illegal instruction", /* 4 SIGILL */
2661 "trace trap", /* 5 SIGTRAP */
2662 "IOT instruction", /* 6 SIGIOT */
2663 "EMT instruction", /* 7 SIGEMT */
2664 "floating point exception", /* 8 SIGFPE */
2665 "kill", /* 9 SIGKILL */
2666 "bus error", /* 10 SIGBUS */
2667 "segmentation violation", /* 11 SIGSEGV */
2668 "bad argument to system call", /* 12 SIGSYS */
2669 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2670 "alarm clock", /* 14 SIGALRM */
2671 "software termination signum", /* 15 SIGTERM */
2672 "user defined signal 1", /* 16 SIGUSR1 */
2673 "user defined signal 2", /* 17 SIGUSR2 */
2674 "death of a child", /* 18 SIGCLD */
2675 "power-fail restart", /* 19 SIGPWR */
2676 #endif /* not AIX */
2679 #endif /* HAVE_SYS_SIGLIST */
2682 * Warning, this function may not duplicate 4.2 action properly
2683 * under error conditions.
2687 /* In 4.1, param.h fails to define this. */
2688 #define MAXPATHLEN 1024
2697 char *npath
, *spath
;
2698 extern char *getcwd ();
2700 BLOCK_INPUT
; /* getcwd uses malloc */
2701 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
2702 /* On Altos 3068, getcwd can return @hostname/dir, so discard
2703 up to first slash. Should be harmless on other systems. */
2704 while (*npath
&& *npath
!= '/')
2706 strcpy (pathname
, npath
);
2707 free (spath
); /* getcwd uses malloc */
2712 #endif /* HAVE_GETWD */
2715 * Emulate rename using unlink/link. Note that this is
2716 * only partially correct. Also, doesn't enforce restriction
2717 * that files be of same type (regular->regular, dir->dir, etc).
2726 if (access (from
, 0) == 0)
2729 if (link (from
, to
) == 0)
2730 if (unlink (from
) == 0)
2738 #ifdef MISSING_UTIMES
2740 /* HPUX (among others) sets HAVE_TIMEVAL but does not implement utimes. */
2749 /* The IRIS (3.5) has timevals, but uses sys V utime, and doesn't have the
2750 utimbuf structure defined anywhere but in the man page. */
2760 struct timeval tvp
[];
2763 utb
.actime
= tvp
[0].tv_sec
;
2764 utb
.modtime
= tvp
[1].tv_sec
;
2767 #endif /* IRIS_UTIME */
2773 /* HPUX curses library references perror, but as far as we know
2774 it won't be called. Anyway this definition will do for now. */
2780 #endif /* not HAVE_PERROR */
2786 * Emulate BSD dup2. First close newd if it already exists.
2787 * Then, attempt to dup oldd. If not successful, call dup2 recursively
2788 * until we are, then close the unsuccessful ones.
2795 register int fd
, ret
;
2800 fd
= fcntl (oldd
, F_DUPFD
, newd
);
2802 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, sys_errlist
[errno
]);
2809 ret
= dup2 (old
,new);
2815 #endif /* not HAVE_DUP2 */
2818 * Gettimeofday. Simulate as much as possible. Only accurate
2819 * to nearest second. Emacs doesn't use tzp so ignore it for now.
2820 * Only needed when subprocesses are defined.
2825 #ifndef HAVE_GETTIMEOFDAY
2829 gettimeofday (tp
, tzp
)
2831 struct timezone
*tzp
;
2833 extern long time ();
2835 tp
->tv_sec
= time ((long *)0);
2838 tzp
->tz_minuteswest
= -1;
2844 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
2847 * This function will go away as soon as all the stubs fixed. (fnf)
2853 printf ("%s not yet implemented\r\n", badfunc
);
2862 char *sys_siglist
[NSIG
+ 1] =
2864 "null signal", /* 0 SIGNULL */
2865 "hangup", /* 1 SIGHUP */
2866 "interrupt", /* 2 SIGINT */
2867 "quit", /* 3 SIGQUIT */
2868 "illegal instruction", /* 4 SIGILL */
2869 "trace trap", /* 5 SIGTRAP */
2870 "abort termination", /* 6 SIGABRT */
2871 "SIGEMT", /* 7 SIGEMT */
2872 "floating point exception", /* 8 SIGFPE */
2873 "kill", /* 9 SIGKILL */
2874 "bus error", /* 10 SIGBUS */
2875 "segmentation violation", /* 11 SIGSEGV */
2876 "bad argument to system call", /* 12 SIGSYS */
2877 "write on a pipe with no reader", /* 13 SIGPIPE */
2878 "alarm clock", /* 14 SIGALRM */
2879 "software termination signal", /* 15 SIGTERM */
2880 "user defined signal 1", /* 16 SIGUSR1 */
2881 "user defined signal 2", /* 17 SIGUSR2 */
2882 "child stopped or terminated", /* 18 SIGCLD */
2883 "power-fail restart", /* 19 SIGPWR */
2884 "window size changed", /* 20 SIGWINCH */
2885 "undefined", /* 21 */
2886 "pollable event occurred", /* 22 SIGPOLL */
2887 "sendable stop signal not from tty", /* 23 SIGSTOP */
2888 "stop signal from tty", /* 24 SIGSTP */
2889 "continue a stopped process", /* 25 SIGCONT */
2890 "attempted background tty read", /* 26 SIGTTIN */
2891 "attempted background tty write", /* 27 SIGTTOU */
2892 "undefined", /* 28 */
2893 "undefined", /* 29 */
2894 "undefined", /* 30 */
2895 "undefined", /* 31 */
2896 "undefined", /* 32 */
2897 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
2898 "I/O is possible", /* 34 SIGIO */
2899 "exceeded cpu time limit", /* 35 SIGXCPU */
2900 "exceeded file size limit", /* 36 SIGXFSZ */
2901 "virtual time alarm", /* 37 SIGVTALRM */
2902 "profiling time alarm", /* 38 SIGPROF */
2903 "undefined", /* 39 */
2904 "file record locks revoked", /* 40 SIGLOST */
2905 "undefined", /* 41 */
2906 "undefined", /* 42 */
2907 "undefined", /* 43 */
2908 "undefined", /* 44 */
2909 "undefined", /* 45 */
2910 "undefined", /* 46 */
2911 "undefined", /* 47 */
2912 "undefined", /* 48 */
2913 "undefined", /* 49 */
2914 "undefined", /* 50 */
2915 "undefined", /* 51 */
2916 "undefined", /* 52 */
2917 "undefined", /* 53 */
2918 "undefined", /* 54 */
2919 "undefined", /* 55 */
2920 "undefined", /* 56 */
2921 "undefined", /* 57 */
2922 "undefined", /* 58 */
2923 "undefined", /* 59 */
2924 "undefined", /* 60 */
2925 "undefined", /* 61 */
2926 "undefined", /* 62 */
2927 "undefined", /* 63 */
2928 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
2934 /* Directory routines for systems that don't have them. */
2936 #ifdef SYSV_SYSTEM_DIR
2940 #ifndef HAVE_CLOSEDIR
2943 register DIR *dirp
; /* stream from opendir */
2945 sys_close (dirp
->dd_fd
);
2947 /* Some systems (like Solaris) allocate the buffer and the DIR all
2948 in one block. Why in the world are we freeing this ourselves
2950 #if ! (defined (sun) && defined (USG5_4))
2951 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
2953 xfree ((char *) dirp
);
2955 #endif /* not HAVE_CLOSEDIR */
2956 #endif /* SYSV_SYSTEM_DIR */
2958 #ifdef NONSYSTEM_DIR_LIBRARY
2962 char *filename
; /* name of directory */
2964 register DIR *dirp
; /* -> malloc'ed storage */
2965 register int fd
; /* file descriptor for read */
2966 struct stat sbuf
; /* result of fstat */
2968 fd
= sys_open (filename
, 0);
2973 if (fstat (fd
, &sbuf
) < 0
2974 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
2975 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
2979 return 0; /* bad luck today */
2984 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
2991 register DIR *dirp
; /* stream from opendir */
2993 sys_close (dirp
->dd_fd
);
2994 xfree ((char *) dirp
);
3002 ino_t od_ino
; /* inode */
3003 char od_name
[DIRSIZ
]; /* filename */
3005 #endif /* not VMS */
3007 struct direct dir_static
; /* simulated directory contents */
3012 register DIR *dirp
; /* stream from opendir */
3015 register struct olddir
*dp
; /* -> directory data */
3017 register struct dir$_name
*dp
; /* -> directory data */
3018 register struct dir$_version
*dv
; /* -> version data */
3023 if (dirp
->dd_loc
>= dirp
->dd_size
)
3024 dirp
->dd_loc
= dirp
->dd_size
= 0;
3026 if (dirp
->dd_size
== 0 /* refill buffer */
3027 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3031 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3032 dirp
->dd_loc
+= sizeof (struct olddir
);
3034 if (dp
->od_ino
!= 0) /* not deleted entry */
3036 dir_static
.d_ino
= dp
->od_ino
;
3037 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3038 dir_static
.d_name
[DIRSIZ
] = '\0';
3039 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3040 dir_static
.d_reclen
= sizeof (struct direct
)
3042 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3043 return &dir_static
; /* -> simulated structure */
3046 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3047 if (dirp
->dd_loc
== 0)
3048 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3049 : dp
->dir$b_namecount
;
3050 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3051 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3052 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3053 dir_static
.d_reclen
= sizeof (struct direct
)
3055 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3056 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3057 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3058 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3065 /* readdirver is just like readdir except it returns all versions of a file
3066 as separate entries. */
3071 register DIR *dirp
; /* stream from opendir */
3073 register struct dir$_name
*dp
; /* -> directory data */
3074 register struct dir$_version
*dv
; /* -> version data */
3076 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3077 dirp
->dd_loc
= dirp
->dd_size
= 0;
3079 if (dirp
->dd_size
== 0 /* refill buffer */
3080 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3083 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3084 if (dirp
->dd_loc
== 0)
3085 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3086 : dp
->dir$b_namecount
;
3087 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3088 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3089 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3090 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3091 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3092 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3093 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3094 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3100 #endif /* NONSYSTEM_DIR_LIBRARY */
3103 /* mkdir and rmdir functions, for systems which don't have them. */
3107 * Written by Robert Rother, Mariah Corporation, August 1985.
3109 * If you want it, it's yours. All I ask in return is that if you
3110 * figure out how to do this in a Bourne Shell script you send me
3112 * sdcsvax!rmr or rmr@uscd
3114 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3115 * subroutine. 11Mar86; hoptoad!gnu
3117 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3118 * subroutine didn't return EEXIST. It does now.
3125 mkdir (dpath
, dmode
)
3129 int cpid
, status
, fd
;
3130 struct stat statbuf
;
3132 if (stat (dpath
, &statbuf
) == 0)
3134 errno
= EEXIST
; /* Stat worked, so it already exists */
3138 /* If stat fails for a reason other than non-existence, return error */
3139 if (errno
!= ENOENT
)
3142 synch_process_alive
= 1;
3143 switch (cpid
= fork ())
3146 case -1: /* Error in fork */
3147 return (-1); /* Errno is set already */
3149 case 0: /* Child process */
3151 * Cheap hack to set mode of new directory. Since this
3152 * child process is going away anyway, we zap its umask.
3153 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3154 * directory. Does anybody care?
3156 status
= umask (0); /* Get current umask */
3157 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3158 fd
= sys_open("/dev/null", 2);
3165 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3166 _exit (-1); /* Can't exec /bin/mkdir */
3168 default: /* Parent process */
3169 wait_for_termination (cpid
);
3172 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3174 errno
= EIO
; /* We don't know why, but */
3175 return -1; /* /bin/mkdir failed */
3180 #endif /* not HAVE_MKDIR */
3187 int cpid
, status
, fd
;
3188 struct stat statbuf
;
3190 if (stat (dpath
, &statbuf
) != 0)
3192 /* Stat just set errno. We don't have to */
3196 synch_process_alive
= 1;
3197 switch (cpid
= fork ())
3200 case -1: /* Error in fork */
3201 return (-1); /* Errno is set already */
3203 case 0: /* Child process */
3204 fd
= sys_open("/dev/null", 2);
3211 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3212 _exit (-1); /* Can't exec /bin/mkdir */
3214 default: /* Parent process */
3215 wait_for_termination (cpid
);
3218 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3220 errno
= EIO
; /* We don't know why, but */
3221 return -1; /* /bin/rmdir failed */
3226 #endif /* !HAVE_RMDIR */
3230 /* Functions for VMS */
3232 #include "vms-pwd.h"
3237 /* Return as a string the VMS error string pertaining to STATUS.
3238 Reuses the same static buffer each time it is called. */
3242 int status
; /* VMS status code */
3246 static char buf
[257];
3248 bufadr
[0] = sizeof buf
- 1;
3249 bufadr
[1] = (int) buf
;
3250 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3251 return "untranslatable VMS error status";
3259 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3260 * not work correctly. (It also doesn't work well in version 2.3.)
3265 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3266 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3270 unsigned short s_buflen
;
3271 unsigned short s_code
;
3273 unsigned short *s_retlenadr
;
3277 #define buflen s.s_buflen
3278 #define code s.s_code
3279 #define bufadr s.s_bufadr
3280 #define retlenadr s.s_retlenadr
3282 #define R_OK 4 /* test for read permission */
3283 #define W_OK 2 /* test for write permission */
3284 #define X_OK 1 /* test for execute (search) permission */
3285 #define F_OK 0 /* test for presence of file */
3288 sys_access (path
, mode
)
3292 static char *user
= NULL
;
3295 /* translate possible directory spec into .DIR file name, so brain-dead
3296 * access can treat the directory like a file. */
3297 if (directory_file_name (path
, dir_fn
))
3301 return access (path
, mode
);
3302 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3308 unsigned short int dummy
;
3310 static int constant
= ACL$C_FILE
;
3311 DESCRIPTOR (path_desc
, path
);
3312 DESCRIPTOR (user_desc
, user
);
3316 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3319 acces
|= CHP$M_READ
;
3321 acces
|= CHP$M_WRITE
;
3322 itemlst
[0].buflen
= sizeof (int);
3323 itemlst
[0].code
= CHP$_FLAGS
;
3324 itemlst
[0].bufadr
= (char *) &flags
;
3325 itemlst
[0].retlenadr
= &dummy
;
3326 itemlst
[1].buflen
= sizeof (int);
3327 itemlst
[1].code
= CHP$_ACCESS
;
3328 itemlst
[1].bufadr
= (char *) &acces
;
3329 itemlst
[1].retlenadr
= &dummy
;
3330 itemlst
[2].end
= CHP$_END
;
3331 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3332 return stat
== SS$_NORMAL
? 0 : -1;
3336 #else /* not VMS4_4 */
3339 #define ACE$M_WRITE 2
3340 #define ACE$C_KEYID 1
3342 static unsigned short memid
, grpid
;
3343 static unsigned int uic
;
3345 /* Called from init_sys_modes, so it happens not very often
3346 but at least each time Emacs is loaded. */
3347 sys_access_reinit ()
3353 sys_access (filename
, type
)
3359 int status
, size
, i
, typecode
, acl_controlled
;
3360 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3361 union prvdef prvmask
;
3363 /* Get UIC and GRP values for protection checking. */
3366 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3369 memid
= uic
& 0xFFFF;
3373 if (type
!= 2) /* not checking write access */
3374 return access (filename
, type
);
3376 /* Check write protection. */
3378 #define CHECKPRIV(bit) (prvmask.bit)
3379 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3381 /* Find privilege bits */
3382 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3384 error ("Unable to find privileges: %s", vmserrstr (status
));
3385 if (CHECKPRIV (PRV$V_BYPASS
))
3386 return 0; /* BYPASS enabled */
3388 fab
.fab$b_fac
= FAB$M_GET
;
3389 fab
.fab$l_fna
= filename
;
3390 fab
.fab$b_fns
= strlen (filename
);
3391 fab
.fab$l_xab
= &xab
;
3392 xab
= cc$rms_xabpro
;
3393 xab
.xab$l_aclbuf
= aclbuf
;
3394 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3395 status
= SYS$
OPEN (&fab
, 0, 0);
3398 SYS$
CLOSE (&fab
, 0, 0);
3399 /* Check system access */
3400 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITEABLE (XAB$V_SYS
))
3402 /* Check ACL entries, if any */
3404 if (xab
.xab$w_acllen
> 0)
3407 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3408 while (*aclptr
&& aclptr
< aclend
)
3410 size
= (*aclptr
& 0xff) / 4;
3411 typecode
= (*aclptr
>> 8) & 0xff;
3412 if (typecode
== ACE$C_KEYID
)
3413 for (i
= size
- 1; i
> 1; i
--)
3414 if (aclptr
[i
] == uic
)
3417 if (aclptr
[1] & ACE$M_WRITE
)
3418 return 0; /* Write access through ACL */
3420 aclptr
= &aclptr
[size
];
3422 if (acl_controlled
) /* ACL specified, prohibits write access */
3425 /* No ACL entries specified, check normal protection */
3426 if (WRITEABLE (XAB$V_WLD
)) /* World writeable */
3428 if (WRITEABLE (XAB$V_GRP
) &&
3429 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3430 return 0; /* Group writeable */
3431 if (WRITEABLE (XAB$V_OWN
) &&
3432 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3433 return 0; /* Owner writeable */
3435 return -1; /* Not writeable */
3437 #endif /* not VMS4_4 */
3440 static char vtbuf
[NAM$C_MAXRSS
+1];
3442 /* translate a vms file spec to a unix path */
3444 sys_translate_vms (vfile
)
3455 /* leading device or logical name is a root directory */
3456 if (p
= strchr (vfile
, ':'))
3465 if (*p
== '[' || *p
== '<')
3467 while (*++vfile
!= *p
+ 2)
3471 if (vfile
[-1] == *p
)
3494 static char utbuf
[NAM$C_MAXRSS
+1];
3496 /* translate a unix path to a VMS file spec */
3498 sys_translate_unix (ufile
)
3521 if (index (&ufile
[1], '/'))
3528 if (index (&ufile
[1], '/'))
3535 if (strncmp (ufile
, "./", 2) == 0)
3542 ufile
++; /* skip the dot */
3543 if (index (&ufile
[1], '/'))
3548 else if (strncmp (ufile
, "../", 3) == 0)
3556 ufile
+= 2; /* skip the dots */
3557 if (index (&ufile
[1], '/'))
3582 extern char *getcwd ();
3584 #define MAXPATHLEN 1024
3586 ptr
= xmalloc (MAXPATHLEN
);
3587 getcwd (ptr
, MAXPATHLEN
);
3588 strcpy (pathname
, ptr
);
3596 long item_code
= JPI$_OWNER
;
3597 unsigned long parent_id
;
3600 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
3603 vaxc$errno
= status
;
3613 return (getgid () << 16) | getuid ();
3617 sys_read (fildes
, buf
, nbyte
)
3622 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
3627 sys_write (fildes
, buf
, nbyte
)
3632 register int nwrote
, rtnval
= 0;
3634 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
3640 return rtnval
? rtnval
: -1;
3641 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
3642 return rtnval
? rtnval
: -1;
3643 return (rtnval
+ nwrote
);
3648 * VAX/VMS VAX C RTL really loses. It insists that records
3649 * end with a newline (carriage return) character, and if they
3650 * don't it adds one (nice of it isn't it!)
3652 * Thus we do this stupidity below.
3656 sys_write (fildes
, buf
, nbytes
)
3659 unsigned int nbytes
;
3666 fstat (fildes
, &st
);
3672 /* Handle fixed-length files with carriage control. */
3673 if (st
.st_fab_rfm
== FAB$C_FIX
3674 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
3676 len
= st
.st_fab_mrs
;
3677 retval
= write (fildes
, p
, min (len
, nbytes
));
3680 retval
++; /* This skips the implied carriage control */
3684 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3685 while (*e
!= '\n' && e
> p
) e
--;
3686 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
3687 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3689 retval
= write (fildes
, p
, len
);
3700 /* Create file NEW copying its attributes from file OLD. If
3701 OLD is 0 or does not exist, create based on the value of
3704 /* Protection value the file should ultimately have.
3705 Set by create_copy_attrs, and use by rename_sansversions. */
3706 static unsigned short int fab_final_pro
;
3709 creat_copy_attrs (old
, new)
3712 struct FAB fab
= cc$rms_fab
;
3713 struct XABPRO xabpro
;
3714 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
3715 extern int vms_stmlf_recfm
;
3719 fab
.fab$b_fac
= FAB$M_GET
;
3720 fab
.fab$l_fna
= old
;
3721 fab
.fab$b_fns
= strlen (old
);
3722 fab
.fab$l_xab
= (char *) &xabpro
;
3723 xabpro
= cc$rms_xabpro
;
3724 xabpro
.xab$l_aclbuf
= aclbuf
;
3725 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
3726 /* Call $OPEN to fill in the fab & xabpro fields. */
3727 if (SYS$
OPEN (&fab
, 0, 0) & 1)
3729 SYS$
CLOSE (&fab
, 0, 0);
3730 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
3731 if (xabpro
.xab$w_acllen
> 0)
3733 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
3734 /* If the acl buffer was too short, redo open with longer one.
3735 Wouldn't need to do this if there were some system imposed
3736 limit on the size of an ACL, but I can't find any such. */
3738 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
3739 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
3740 if (SYS$
OPEN (&fab
, 0, 0) & 1)
3741 SYS$
CLOSE (&fab
, 0, 0);
3747 xabpro
.xab$l_aclbuf
= 0;
3752 fab
.fab$l_fna
= new;
3753 fab
.fab$b_fns
= strlen (new);
3757 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
3758 fab
.fab$b_rat
= FAB$M_CR
;
3761 /* Set the file protections such that we will be able to manipulate
3762 this file. Once we are done writing and renaming it, we will set
3763 the protections back. */
3765 fab_final_pro
= xabpro
.xab$w_pro
;
3767 SYS$
SETDFPROT (0, &fab_final_pro
);
3768 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
3770 /* Create the new file with either default attrs or attrs copied
3772 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
3774 SYS$
CLOSE (&fab
, 0, 0);
3775 /* As this is a "replacement" for creat, return a file descriptor
3776 opened for writing. */
3777 return open (new, O_WRONLY
);
3782 #include <varargs.h>
3785 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
3789 sys_creat (va_alist
)
3792 va_list list_incrementer
;
3795 int rfd
; /* related file descriptor */
3796 int fd
; /* Our new file descriptor */
3803 extern int vms_stmlf_recfm
;
3806 va_start (list_incrementer
);
3807 name
= va_arg (list_incrementer
, char *);
3808 mode
= va_arg (list_incrementer
, int);
3810 rfd
= va_arg (list_incrementer
, int);
3811 va_end (list_incrementer
);
3814 /* Use information from the related file descriptor to set record
3815 format of the newly created file. */
3816 fstat (rfd
, &st_buf
);
3817 switch (st_buf
.st_fab_rfm
)
3820 strcpy (rfm
, "rfm = fix");
3821 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
3822 strcpy (rat
, "rat = ");
3823 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3825 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3826 strcat (rat
, "ftn");
3827 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3828 strcat (rat
, "prn");
3829 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3830 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3831 strcat (rat
, ", blk");
3833 strcat (rat
, "blk");
3834 return creat (name
, 0, rfm
, rat
, mrs
);
3837 strcpy (rfm
, "rfm = vfc");
3838 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
3839 strcpy (rat
, "rat = ");
3840 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3842 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3843 strcat (rat
, "ftn");
3844 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3845 strcat (rat
, "prn");
3846 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3847 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3848 strcat (rat
, ", blk");
3850 strcat (rat
, "blk");
3851 return creat (name
, 0, rfm
, rat
, fsz
);
3854 strcpy (rfm
, "rfm = stm");
3858 strcpy (rfm
, "rfm = stmcr");
3862 strcpy (rfm
, "rfm = stmlf");
3866 strcpy (rfm
, "rfm = udf");
3870 strcpy (rfm
, "rfm = var");
3873 strcpy (rat
, "rat = ");
3874 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3876 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3877 strcat (rat
, "ftn");
3878 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3879 strcat (rat
, "prn");
3880 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3881 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3882 strcat (rat
, ", blk");
3884 strcat (rat
, "blk");
3888 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
3889 strcpy (rat
, "rat=cr");
3891 /* Until the VAX C RTL fixes the many bugs with modes, always use
3892 mode 0 to get the user's default protection. */
3893 fd
= creat (name
, 0, rfm
, rat
);
3894 if (fd
< 0 && errno
== EEXIST
)
3896 if (unlink (name
) < 0)
3897 report_file_error ("delete", build_string (name
));
3898 fd
= creat (name
, 0, rfm
, rat
);
3904 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
3905 sys_fwrite (ptr
, size
, num
, fp
)
3906 register char * ptr
;
3909 register int tot
= num
* size
;
3916 * The VMS C library routine creat actually creates a new version of an
3917 * existing file rather than truncating the old version. There are times
3918 * when this is not the desired behavior, for instance, when writing an
3919 * auto save file (you only want one version), or when you don't have
3920 * write permission in the directory containing the file (but the file
3921 * itself is writable). Hence this routine, which is equivalent to
3922 * "close (creat (fn, 0));" on Unix if fn already exists.
3928 struct FAB xfab
= cc$rms_fab
;
3929 struct RAB xrab
= cc$rms_rab
;
3932 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
3933 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
3934 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
3935 xfab
.fab$l_fna
= fn
;
3936 xfab
.fab$b_fns
= strlen (fn
);
3937 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
3939 xrab
.rab$l_fab
= &xfab
;
3941 /* This gibberish opens the file, positions to the first record, and
3942 deletes all records from there until the end of file. */
3943 if ((SYS$
OPEN (&xfab
) & 01) == 01)
3945 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
3946 (SYS$
FIND (&xrab
) & 01) == 01 &&
3947 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
3958 /* Define this symbol to actually read SYSUAF.DAT. This requires either
3959 SYSPRV or a readable SYSUAF.DAT. */
3965 * Routine to read the VMS User Authorization File and return
3966 * a specific user's record.
3969 static struct UAF retuaf
;
3972 get_uaf_name (uname
)
3979 uaf_fab
= cc$rms_fab
;
3980 uaf_rab
= cc$rms_rab
;
3981 /* initialize fab fields */
3982 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
3983 uaf_fab
.fab$b_fns
= 21;
3984 uaf_fab
.fab$b_fac
= FAB$M_GET
;
3985 uaf_fab
.fab$b_org
= FAB$C_IDX
;
3986 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
3987 /* initialize rab fields */
3988 uaf_rab
.rab$l_fab
= &uaf_fab
;
3989 /* open the User Authorization File */
3990 status
= SYS$
OPEN (&uaf_fab
);
3994 vaxc$errno
= status
;
3997 status
= SYS$
CONNECT (&uaf_rab
);
4001 vaxc$errno
= status
;
4004 /* read the requested record - index is in uname */
4005 uaf_rab
.rab$l_kbf
= uname
;
4006 uaf_rab
.rab$b_ksz
= strlen (uname
);
4007 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4008 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4009 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4010 status
= SYS$
GET (&uaf_rab
);
4014 vaxc$errno
= status
;
4017 /* close the User Authorization File */
4018 status
= SYS$
DISCONNECT (&uaf_rab
);
4022 vaxc$errno
= status
;
4025 status
= SYS$
CLOSE (&uaf_fab
);
4029 vaxc$errno
= status
;
4043 uaf_fab
= cc$rms_fab
;
4044 uaf_rab
= cc$rms_rab
;
4045 /* initialize fab fields */
4046 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4047 uaf_fab
.fab$b_fns
= 21;
4048 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4049 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4050 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4051 /* initialize rab fields */
4052 uaf_rab
.rab$l_fab
= &uaf_fab
;
4053 /* open the User Authorization File */
4054 status
= SYS$
OPEN (&uaf_fab
);
4058 vaxc$errno
= status
;
4061 status
= SYS$
CONNECT (&uaf_rab
);
4065 vaxc$errno
= status
;
4068 /* read the requested record - index is in uic */
4069 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4070 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4071 uaf_rab
.rab$b_ksz
= sizeof uic
;
4072 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4073 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4074 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4075 status
= SYS$
GET (&uaf_rab
);
4079 vaxc$errno
= status
;
4082 /* close the User Authorization File */
4083 status
= SYS$
DISCONNECT (&uaf_rab
);
4087 vaxc$errno
= status
;
4090 status
= SYS$
CLOSE (&uaf_fab
);
4094 vaxc$errno
= status
;
4100 static struct passwd retpw
;
4108 /* copy these out first because if the username is 32 chars, the next
4109 section will overwrite the first byte of the UIC */
4110 retpw
.pw_uid
= up
->uaf$w_mem
;
4111 retpw
.pw_gid
= up
->uaf$w_grp
;
4113 /* I suppose this is not the best sytle, to possibly overwrite one
4114 byte beyond the end of the field, but what the heck... */
4115 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4116 while (ptr
[-1] == ' ')
4119 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4121 /* the rest of these are counted ascii strings */
4122 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4123 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4124 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4125 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4126 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4127 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4128 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4129 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4133 #else /* not READ_SYSUAF */
4134 static struct passwd retpw
;
4135 #endif /* not READ_SYSUAF */
4146 unsigned char * full
;
4147 #endif /* READ_SYSUAF */
4152 if ('a' <= *ptr
&& *ptr
<= 'z')
4157 if (!(up
= get_uaf_name (name
)))
4159 return cnv_uaf_pw (up
);
4161 if (strcmp (name
, getenv ("USER")) == 0)
4163 retpw
.pw_uid
= getuid ();
4164 retpw
.pw_gid
= getgid ();
4165 strcpy (retpw
.pw_name
, name
);
4166 if (full
= egetenv ("FULLNAME"))
4167 strcpy (retpw
.pw_gecos
, full
);
4169 *retpw
.pw_gecos
= '\0';
4170 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4171 *retpw
.pw_shell
= '\0';
4176 #endif /* not READ_SYSUAF */
4186 if (!(up
= get_uaf_uic (uid
)))
4188 return cnv_uaf_pw (up
);
4190 if (uid
== sys_getuid ())
4191 return getpwnam (egetenv ("USER"));
4194 #endif /* not READ_SYSUAF */
4197 /* return total address space available to the current process. This is
4198 the sum of the current p0 size, p1 size and free page table entries
4203 unsigned long free_pages
;
4204 unsigned long frep0va
;
4205 unsigned long frep1va
;
4208 item_code
= JPI$_FREPTECNT
;
4209 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4212 vaxc$errno
= status
;
4217 item_code
= JPI$_FREP0VA
;
4218 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4221 vaxc$errno
= status
;
4224 item_code
= JPI$_FREP1VA
;
4225 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4228 vaxc$errno
= status
;
4232 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4235 define_logical_name (varname
, string
)
4239 struct dsc$descriptor_s strdsc
=
4240 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4241 struct dsc$descriptor_s envdsc
=
4242 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4243 struct dsc$descriptor_s lnmdsc
=
4244 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4246 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4249 delete_logical_name (varname
)
4252 struct dsc$descriptor_s envdsc
=
4253 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4254 struct dsc$descriptor_s lnmdsc
=
4255 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4257 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4268 error ("execvp system call not implemented");
4276 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4277 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4278 char from_esn
[NAM$C_MAXRSS
];
4279 char to_esn
[NAM$C_MAXRSS
];
4281 from_fab
.fab$l_fna
= from
;
4282 from_fab
.fab$b_fns
= strlen (from
);
4283 from_fab
.fab$l_nam
= &from_nam
;
4284 from_fab
.fab$l_fop
= FAB$M_NAM
;
4286 from_nam
.nam$l_esa
= from_esn
;
4287 from_nam
.nam$b_ess
= sizeof from_esn
;
4289 to_fab
.fab$l_fna
= to
;
4290 to_fab
.fab$b_fns
= strlen (to
);
4291 to_fab
.fab$l_nam
= &to_nam
;
4292 to_fab
.fab$l_fop
= FAB$M_NAM
;
4294 to_nam
.nam$l_esa
= to_esn
;
4295 to_nam
.nam$b_ess
= sizeof to_esn
;
4297 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4303 if (status
== RMS$_DEV
)
4307 vaxc$errno
= status
;
4312 /* This function renames a file like `rename', but it strips
4313 the version number from the "to" filename, such that the "to" file is
4314 will always be a new version. It also sets the file protection once it is
4315 finished. The protection that we will use is stored in fab_final_pro,
4316 and was set when we did a creat_copy_attrs to create the file that we
4319 We could use the chmod function, but Eunichs uses 3 bits per user category
4320 to describe the protection, and VMS uses 4 (write and delete are separate
4321 bits). To maintain portability, the VMS implementation of `chmod' wires
4322 the W and D bits together. */
4325 static struct fibdef fib
; /* We need this initialized to zero */
4326 char vms_file_written
[NAM$C_MAXRSS
];
4329 rename_sans_version (from
,to
)
4336 struct FAB to_fab
= cc$rms_fab
;
4337 struct NAM to_nam
= cc$rms_nam
;
4338 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4339 struct dsc$descriptor fib_attr
[2]
4340 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4341 char to_esn
[NAM$C_MAXRSS
];
4343 $
DESCRIPTOR (disk
,to_esn
);
4345 to_fab
.fab$l_fna
= to
;
4346 to_fab
.fab$b_fns
= strlen (to
);
4347 to_fab
.fab$l_nam
= &to_nam
;
4348 to_fab
.fab$l_fop
= FAB$M_NAM
;
4350 to_nam
.nam$l_esa
= to_esn
;
4351 to_nam
.nam$b_ess
= sizeof to_esn
;
4353 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4355 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4356 *(to_nam
.nam$l_ver
) = '\0';
4358 stat
= rename (from
, to_esn
);
4362 strcpy (vms_file_written
, to_esn
);
4364 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4365 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4367 /* Now set the file protection to the correct value */
4368 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4370 /* Copy these fields into the fib */
4371 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4372 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4373 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4375 SYS$
CLOSE (&to_fab
, 0, 0);
4377 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4380 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4381 0, 0, 0, &fib_attr
, 0);
4384 stat
= SYS$
DASSGN (chan
);
4387 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4397 unsigned short fid
[3];
4398 char esa
[NAM$C_MAXRSS
];
4401 fab
.fab$l_fop
= FAB$M_OFP
;
4402 fab
.fab$l_fna
= file
;
4403 fab
.fab$b_fns
= strlen (file
);
4404 fab
.fab$l_nam
= &nam
;
4407 nam
.nam$l_esa
= esa
;
4408 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4410 status
= SYS$
PARSE (&fab
);
4411 if ((status
& 1) == 0)
4414 vaxc$errno
= status
;
4417 status
= SYS$
SEARCH (&fab
);
4418 if ((status
& 1) == 0)
4421 vaxc$errno
= status
;
4425 fid
[0] = nam
.nam$w_fid
[0];
4426 fid
[1] = nam
.nam$w_fid
[1];
4427 fid
[2] = nam
.nam$w_fid
[2];
4429 fab
.fab$l_fna
= new;
4430 fab
.fab$b_fns
= strlen (new);
4432 status
= SYS$
PARSE (&fab
);
4433 if ((status
& 1) == 0)
4436 vaxc$errno
= status
;
4440 nam
.nam$w_fid
[0] = fid
[0];
4441 nam
.nam$w_fid
[1] = fid
[1];
4442 nam
.nam$w_fid
[2] = fid
[2];
4444 nam
.nam$l_esa
= nam
.nam$l_name
;
4445 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
4447 status
= SYS$
ENTER (&fab
);
4448 if ((status
& 1) == 0)
4451 vaxc$errno
= status
;
4461 printf ("%s not yet implemented\r\n", badfunc
);
4469 /* Arrange to return a range centered on zero. */
4470 return rand () - (1 << 30);
4481 /* Called from init_sys_modes. */
4486 /* If we're not on an HFT we shouldn't do any of this. We determine
4487 if we are on an HFT by trying to get an HFT error code. If this
4488 call fails, we're not on an HFT. */
4490 if (ioctl (0, HFQERROR
, &junk
) < 0)
4492 #else /* not IBMR2AIX */
4493 if (ioctl (0, HFQEIO
, 0) < 0)
4495 #endif /* not IBMR2AIX */
4497 /* On AIX the default hft keyboard mapping uses backspace rather than delete
4498 as the rubout key's ASCII code. Here this is changed. The bug is that
4499 there's no way to determine the old mapping, so in reset_sys_modes
4500 we need to assume that the normal map had been present. Of course, this
4501 code also doesn't help if on a terminal emulator which doesn't understand
4505 struct hfkeymap keymap
;
4507 buf
.hf_bufp
= (char *)&keymap
;
4508 buf
.hf_buflen
= sizeof (keymap
);
4509 keymap
.hf_nkeys
= 2;
4510 keymap
.hfkey
[0].hf_kpos
= 15;
4511 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4513 keymap
.hfkey
[0].hf_keyidh
= '<';
4514 #else /* not IBMR2AIX */
4515 keymap
.hfkey
[0].hf_page
= '<';
4516 #endif /* not IBMR2AIX */
4517 keymap
.hfkey
[0].hf_char
= 127;
4518 keymap
.hfkey
[1].hf_kpos
= 15;
4519 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4521 keymap
.hfkey
[1].hf_keyidh
= '<';
4522 #else /* not IBMR2AIX */
4523 keymap
.hfkey
[1].hf_page
= '<';
4524 #endif /* not IBMR2AIX */
4525 keymap
.hfkey
[1].hf_char
= 127;
4526 hftctl (0, HFSKBD
, &buf
);
4528 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
4530 line_ins_del_ok
= char_ins_del_ok
= 0;
4533 /* Reset the rubout key to backspace. */
4538 struct hfkeymap keymap
;
4542 if (ioctl (0, HFQERROR
, &junk
) < 0)
4544 #else /* not IBMR2AIX */
4545 if (ioctl (0, HFQEIO
, 0) < 0)
4547 #endif /* not IBMR2AIX */
4549 buf
.hf_bufp
= (char *)&keymap
;
4550 buf
.hf_buflen
= sizeof (keymap
);
4551 keymap
.hf_nkeys
= 2;
4552 keymap
.hfkey
[0].hf_kpos
= 15;
4553 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4555 keymap
.hfkey
[0].hf_keyidh
= '<';
4556 #else /* not IBMR2AIX */
4557 keymap
.hfkey
[0].hf_page
= '<';
4558 #endif /* not IBMR2AIX */
4559 keymap
.hfkey
[0].hf_char
= 8;
4560 keymap
.hfkey
[1].hf_kpos
= 15;
4561 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4563 keymap
.hfkey
[1].hf_keyidh
= '<';
4564 #else /* not IBMR2AIX */
4565 keymap
.hfkey
[1].hf_page
= '<';
4566 #endif /* not IBMR2AIX */
4567 keymap
.hfkey
[1].hf_char
= 8;
4568 hftctl (0, HFSKBD
, &buf
);