1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994 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 2, 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>
67 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
71 #include <sys/param.h>
78 /* On some systems (DGUX comes to mind real fast) FASYNC causes
79 background writes to the terminal to stop all processes in the
80 process group when invoked under the csh (and probably any shell
81 with job control). This stops Emacs dead in its tracks when coming
87 #include <sys/ioctl.h>
92 #ifdef BROKEN_TIOCGWINSZ
97 #include <sys/utsname.h>
99 #ifndef MEMORY_IN_STRING_H
104 #include <sys/sioctl.h>
107 #include <sys/stream.h>
108 #include <sys/ptem.h>
110 #endif /* TIOCGWINSZ */
113 extern int quit_char
;
117 #include "termhooks.h"
118 #include "termchar.h"
119 #include "termopts.h"
120 #include "dispextern.h"
123 #ifdef NONSYSTEM_DIR_LIBRARY
125 #endif /* NONSYSTEM_DIR_LIBRARY */
127 #include "syssignal.h"
130 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
136 #define LNOFLSH 0100000
139 static int baud_convert
[] =
144 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
145 1800, 2400, 4800, 9600, 19200, 38400
151 /* The file descriptor for Emacs's input terminal.
152 Under Unix, this is normaly zero except when using X;
153 under VMS, we place the input channel number here.
154 This allows us to write more code that works for both VMS and Unix. */
157 /* Specify a different file descriptor for further input operations. */
166 /* Discard pending input on descriptor input_fd. */
170 struct emacs_tty buf
;
175 /* Discarding input is not safe when the input could contain
176 replies from the X server. So don't do it. */
177 if (read_socket_hook
)
182 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
183 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
189 ioctl (input_fd
, TIOCFLUSH
, &zero
);
191 #else /* not Apollo */
192 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
193 while (dos_keyread () != -1)
195 #else /* not MSDOS */
196 EMACS_GET_TTY (input_fd
, &buf
);
197 EMACS_SET_TTY (input_fd
, &buf
, 0);
198 #endif /* not MSDOS */
199 #endif /* not Apollo */
205 /* Arrange for character C to be read as the next input from
211 /* Should perhaps error if in batch mode */
213 ioctl (input_fd
, TIOCSTI
, &c
);
214 #else /* no TIOCSTI */
215 error ("Cannot stuff terminal input characters in this version of Unix");
216 #endif /* no TIOCSTI */
233 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
234 &sg
.class, 12, 0, 0, 0, 0 );
235 ospeed
= sg
.xmit_baud
;
241 tcgetattr (input_fd
, &sg
);
242 ospeed
= cfgetospeed (&sg
);
243 #else /* neither VMS nor TERMIOS */
249 tcgetattr (input_fd
, &sg
);
251 ioctl (input_fd
, TCGETA
, &sg
);
253 ospeed
= sg
.c_cflag
& CBAUD
;
254 #else /* neither VMS nor TERMIOS nor TERMIO */
257 sg
.sg_ospeed
= B9600
;
258 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
260 ospeed
= sg
.sg_ospeed
;
261 #endif /* not HAVE_TERMIO */
262 #endif /* not HAVE_TERMIOS */
264 #endif /* not MSDOS */
267 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
268 ? baud_convert
[ospeed
] : 9600);
274 set_exclusive_use (fd
)
278 ioctl (fd
, FIOCLEX
, 0);
280 /* Ok to do nothing if this feature does not exist */
285 wait_without_blocking ()
288 wait3 (0, WNOHANG
| WUNTRACED
, 0);
290 croak ("wait_without_blocking");
292 synch_process_alive
= 0;
295 #endif /* not subprocesses */
297 int wait_debugging
; /* Set nonzero to make following function work under dbx
298 (at least for bsd). */
301 wait_for_termination_signal ()
304 /* Wait for subprocess with process id `pid' to terminate and
305 make sure it will get eliminated (not remain forever as a zombie) */
307 wait_for_termination (pid
)
316 status
= SYS$
FORCEX (&pid
, 0, 0);
319 #if defined (BSD) || (defined (HPUX) && !defined (HPUX_5))
320 /* Note that kill returns -1 even if the process is just a zombie now.
321 But inevitably a SIGCHLD interrupt should be generated
322 and child_sig will do wait3 and make the process go away. */
323 /* There is some indication that there is a bug involved with
324 termination of subprocesses, perhaps involving a kernel bug too,
325 but no idea what it is. Just as a hunch we signal SIGCHLD to see
326 if that causes the problem to go away or get worse. */
327 sigsetmask (sigmask (SIGCHLD
));
328 if (0 > kill (pid
, 0))
330 sigsetmask (SIGEMPTYMASK
);
331 kill (getpid (), SIGCHLD
);
337 sigpause (SIGEMPTYMASK
);
338 #else /* not BSD, and not HPUX version >= 6 */
339 #if defined (UNIPLUS)
340 if (0 > kill (pid
, 0))
343 #else /* neither BSD nor UNIPLUS: random sysV */
344 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
345 sigblock (sigmask (SIGCHLD
));
346 if (0 > kill (pid
, 0))
348 sigunblock (sigmask (SIGCHLD
));
351 sigpause (SIGEMPTYMASK
);
352 #else /* not POSIX_SIGNALS */
353 #ifdef HAVE_SYSV_SIGPAUSE
355 if (0 > kill (pid
, 0))
361 #else /* not HAVE_SYSV_SIGPAUSE */
362 if (0 > kill (pid
, 0))
364 /* Using sleep instead of pause avoids timing error.
365 If the inferior dies just before the sleep,
366 we lose just one second. */
368 #endif /* not HAVE_SYSV_SIGPAUSE */
369 #endif /* not POSIX_SIGNALS */
370 #endif /* not UNIPLUS */
371 #endif /* not BSD, and not HPUX version >= 6 */
373 #else /* not subprocesses */
375 if (kill (pid
, 0) < 0)
381 if (status
== pid
|| status
== -1)
384 #endif /* not subprocesses */
391 * flush any pending output
392 * (may flush input as well; it does not matter the way we use it)
395 flush_pending_output (channel
)
399 /* If we try this, we get hit with SIGTTIN, because
400 the child's tty belongs to the child's pgrp. */
403 ioctl (channel
, TCFLSH
, 1);
407 /* 3rd arg should be ignored
408 but some 4.2 kernels actually want the address of an int
409 and nonzero means something different. */
410 ioctl (channel
, TIOCFLUSH
, &zero
);
417 /* Set up the terminal at the other end of a pseudo-terminal that
418 we will be controlling an inferior through.
419 It should not echo or do line-editing, since that is done
420 in Emacs. No padding needed for insertion into an Emacs buffer. */
422 child_setup_tty (out
)
428 EMACS_GET_TTY (out
, &s
);
430 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
431 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
432 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
433 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
434 /* No output delays */
435 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
436 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
437 s
.main
.c_iflag
&= ~IUCLC
; /* Disable map of upper case to lower on
439 s
.main
.c_oflag
&= ~OLCUC
; /* Disable map of lower case to upper on
441 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
443 /* Said to be unnecessary: */
444 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
445 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
448 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
449 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
450 s
.main
.c_cc
[VERASE
] = 0377; /* disable erase processing */
451 s
.main
.c_cc
[VKILL
] = 0377; /* disable kill processing */
454 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
458 /* AIX enhanced edit loses NULs, so disable it */
461 s
.main
.c_iflag
&= ~ASCEDIT
;
463 /* Also, PTY overloads NUL and BREAK.
464 don't ignore break, but don't signal either, so it looks like NUL. */
465 s
.main
.c_iflag
&= ~IGNBRK
;
466 s
.main
.c_iflag
&= ~BRKINT
;
467 /* QUIT and INTR work better as signals, so disable character forms */
468 s
.main
.c_cc
[VINTR
] = 0377;
469 #ifdef SIGNALS_VIA_CHARACTERS
470 /* the QUIT and INTR character are used in process_send_signal
471 so set them here to something useful. */
472 if (s
.main
.c_cc
[VQUIT
] == 0377)
473 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
474 if (s
.main
.c_cc
[VINTR
] == 0377)
475 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
476 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
477 /* QUIT and INTR work better as signals, so disable character forms */
478 s
.main
.c_cc
[VQUIT
] = 0377;
479 s
.main
.c_cc
[VINTR
] = 0377;
480 s
.main
.c_lflag
&= ~ISIG
;
481 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
482 s
.main
.c_cc
[VEOL
] = 0377;
483 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
486 #else /* not HAVE_TERMIO */
488 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
490 s
.main
.sg_flags
|= LPASS8
;
491 s
.main
.sg_erase
= 0377;
492 s
.main
.sg_kill
= 0377;
493 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
495 #endif /* not HAVE_TERMIO */
497 EMACS_SET_TTY (out
, &s
, 0);
506 ioctl (out
, FIOASYNC
, &zero
);
509 #endif /* not MSDOS */
513 #endif /* subprocesses */
519 EMACS_SET_TTY_PGRP (input_fd
, &pid
);
522 /* Record a signal code and the handler for it. */
526 SIGTYPE (*handler
) ();
529 /* Suspend the Emacs process; give terminal to its superior. */
533 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
535 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
538 /* "Foster" parentage allows emacs to return to a subprocess that attached
539 to the current emacs as a cheaper than starting a whole new process. This
540 is set up by KEPTEDITOR.COM. */
541 unsigned long parent_id
, foster_parent_id
;
544 fpid_string
= getenv ("EMACS_PARENT_PID");
545 if (fpid_string
!= NULL
)
547 sscanf (fpid_string
, "%x", &foster_parent_id
);
548 if (foster_parent_id
!= 0)
549 parent_id
= foster_parent_id
;
551 parent_id
= getppid ();
554 parent_id
= getppid ();
556 xfree (fpid_string
); /* On VMS, this was malloc'd */
558 if (parent_id
&& parent_id
!= 0xffffffff)
560 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
561 int status
= LIB$
ATTACH (&parent_id
) & 1;
562 signal (SIGINT
, oldsig
);
571 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
572 d_prompt
.a
= "Emacs: "; /* Just a reminder */
573 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
578 #if defined(SIGTSTP) && !defined(MSDOS)
581 int pgrp
= EMACS_GETPGRP (0);
582 EMACS_KILLPG (pgrp
, SIGTSTP
);
585 #else /* No SIGTSTP */
586 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
587 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
588 kill (getpid (), SIGQUIT
);
590 #else /* No SIGTSTP or USG_JOBCTRL */
592 /* On a system where suspending is not implemented,
593 instead fork a subshell and let it talk directly to the terminal
596 struct save_signal saved_handlers
[5];
598 saved_handlers
[0].code
= SIGINT
;
599 saved_handlers
[1].code
= SIGQUIT
;
600 saved_handlers
[2].code
= SIGTERM
;
602 saved_handlers
[3].code
= SIGIO
;
603 saved_handlers
[4].code
= 0;
605 saved_handlers
[3].code
= 0;
609 error ("Can't spawn subshell");
614 #ifdef MSDOS /* MW, Aug 1993 */
617 sh
= (char *) egetenv ("SHELL");
621 /* Use our buffer's default directory for the subshell. */
627 /* mentioning current_buffer->buffer would mean including buffer.h,
628 which somehow wedges the hp compiler. So instead... */
630 dir
= intern ("default-directory");
632 if (XFASTINT (Fboundp (dir
)) == XFASTINT (Qnil
))
634 dir
= Fsymbol_value (dir
);
635 if (XTYPE (dir
) != Lisp_String
)
638 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
639 len
= XSTRING (dir
)->size
;
640 bcopy (XSTRING (dir
)->data
, str
, len
);
641 if (str
[len
- 1] != '/') str
[len
++] = '/';
647 close_process_descs (); /* Close Emacs's pipes/ptys */
652 extern int emacs_priority
;
655 nice (-emacs_priority
);
659 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
663 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
664 #else /* not MSDOS */
666 write (1, "Can't execute subshell", 22);
668 #endif /* not MSDOS */
671 save_signal_handlers (saved_handlers
);
672 synch_process_alive
= 1;
673 wait_for_termination (pid
);
674 restore_signal_handlers (saved_handlers
);
676 #endif /* no USG_JOBCTRL */
677 #endif /* no SIGTSTP */
681 save_signal_handlers (saved_handlers
)
682 struct save_signal
*saved_handlers
;
684 while (saved_handlers
->code
)
686 saved_handlers
->handler
687 = (SIGTYPE (*) ()) signal (saved_handlers
->code
, SIG_IGN
);
692 restore_signal_handlers (saved_handlers
)
693 struct save_signal
*saved_handlers
;
695 while (saved_handlers
->code
)
697 signal (saved_handlers
->code
, saved_handlers
->handler
);
709 old_fcntl_flags
= fcntl (input_fd
, F_GETFL
, 0) & ~FASYNC
;
719 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
724 sigunblock (sigmask (SIGWINCH
));
726 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
728 interrupts_deferred
= 0;
734 sigblock (sigmask (SIGWINCH
));
736 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
737 interrupts_deferred
= 1;
740 #else /* no FASYNC */
741 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
746 ioctl (input_fd
, FIOASYNC
, &on
);
747 interrupts_deferred
= 0;
754 ioctl (input_fd
, FIOASYNC
, &off
);
755 interrupts_deferred
= 1;
758 #else /* not FASYNC, not STRIDE */
762 croak ("request_sigio");
767 croak ("unrequest_sigio");
774 /* Saving and restoring the process group of Emacs's terminal. */
778 /* The process group of which Emacs was a member when it initially
781 If Emacs was in its own process group (i.e. inherited_pgroup ==
782 getpid ()), then we know we're running under a shell with job
783 control (Emacs would never be run as part of a pipeline).
786 If Emacs was not in its own process group, then we know we're
787 running under a shell (or a caller) that doesn't know how to
788 separate itself from Emacs (like sh). Emacs must be in its own
789 process group in order to receive SIGIO correctly. In this
790 situation, we put ourselves in our own pgroup, forcibly set the
791 tty's pgroup to our pgroup, and make sure to restore and reinstate
792 the tty's pgroup just like any other terminal setting. If
793 inherited_group was not the tty's pgroup, then we'll get a
794 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
795 it goes foreground in the future, which is what should happen. */
796 int inherited_pgroup
;
798 /* Split off the foreground process group to Emacs alone.
799 When we are in the foreground, but not started in our own process
800 group, redirect the TTY to point to our own process group. We need
801 to be in our own process group to receive SIGIO properly. */
802 narrow_foreground_group ()
806 setpgrp (0, inherited_pgroup
);
807 if (inherited_pgroup
!= me
)
808 EMACS_SET_TTY_PGRP (input_fd
, &me
);
812 /* Set the tty to our original foreground group. */
813 widen_foreground_group ()
815 if (inherited_pgroup
!= getpid ())
816 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
817 setpgrp (0, inherited_pgroup
);
822 /* Getting and setting emacs_tty structures. */
824 /* Set *TC to the parameters associated with the terminal FD.
825 Return zero if all's well, or -1 if we ran into an error we
826 couldn't deal with. */
828 emacs_get_tty (fd
, settings
)
830 struct emacs_tty
*settings
;
832 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
834 /* We have those nifty POSIX tcmumbleattr functions. */
835 if (tcgetattr (fd
, &settings
->main
) < 0)
840 /* The SYSV-style interface? */
841 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
846 /* Vehemently Monstrous System? :-) */
847 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
848 &settings
->main
.class, 12, 0, 0, 0, 0)
854 /* I give up - I hope you have the BSD ioctls. */
855 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
857 #endif /* not MSDOS */
862 /* Suivant - Do we have to get struct ltchars data? */
864 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
868 /* How about a struct tchars and a wordful of lmode bits? */
870 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
871 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
875 /* We have survived the tempest. */
880 /* Set the parameters of the tty on FD according to the contents of
881 *SETTINGS. If WAITP is non-zero, we wait for all queued output to
882 be written before making the change; otherwise, we forget any
883 queued input and make the change immediately.
884 Return 0 if all went well, and -1 if anything failed. */
886 emacs_set_tty (fd
, settings
, waitp
)
888 struct emacs_tty
*settings
;
891 /* Set the primary parameters - baud rate, character size, etcetera. */
894 /* We have those nifty POSIX tcmumbleattr functions.
895 William J. Smith <wjs@wiis.wang.com> writes:
896 "POSIX 1003.1 defines tcsetattr() to return success if it was
897 able to perform any of the requested actions, even if some
898 of the requested actions could not be performed.
899 We must read settings back to ensure tty setup properly.
900 AIX requires this to keep tty from hanging occasionally." */
901 /* This make sure that we don't loop indefinitely in here. */
902 for (i
= 0 ; i
< 10 ; i
++)
903 if (tcsetattr (fd
, waitp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
914 /* Get the current settings, and see if they're what we asked for. */
915 tcgetattr (fd
, &new);
916 /* We cannot use memcmp on the whole structure here because under
917 * aix386 the termios structure has some reserved field that may
920 if ( new.c_iflag
== settings
->main
.c_iflag
921 && new.c_oflag
== settings
->main
.c_oflag
922 && new.c_cflag
== settings
->main
.c_cflag
923 && new.c_lflag
== settings
->main
.c_lflag
924 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
932 /* The SYSV-style interface? */
933 if (ioctl (fd
, waitp
? TCSETAW
: TCSETAF
, &settings
->main
) < 0)
938 /* Vehemently Monstrous System? :-) */
939 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
940 &settings
->main
.class, 12, 0, 0, 0, 0)
946 /* I give up - I hope you have the BSD ioctls. */
947 if (ioctl (fd
, (waitp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
949 #endif /* not MSDOS */
955 /* Suivant - Do we have to get struct ltchars data? */
957 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
961 /* How about a struct tchars and a wordful of lmode bits? */
963 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
964 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
968 /* We have survived the tempest. */
973 /* The initial tty mode bits */
974 struct emacs_tty old_tty
;
976 int term_initted
; /* 1 if outer tty status has been recorded */
979 /* BSD 4.1 needs to keep track of the lmode bits in order to start
987 #endif /* F_SETOWN */
988 #endif /* F_SETOWN_BUG */
990 /* This may also be defined in stdio,
991 but if so, this does no harm,
992 and using the same name avoids wasting the other one's space. */
994 #if defined (USG) || defined (DGUX)
995 unsigned char _sobuf
[BUFSIZ
+8];
1001 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1004 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1009 struct emacs_tty tty
;
1013 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1014 extern int (*interrupt_signal
) ();
1023 input_ef
= get_kbd_event_flag ();
1024 /* LIB$GET_EF (&input_ef); */
1025 SYS$
CLREF (input_ef
);
1026 waiting_for_ast
= 0;
1028 timer_ef
= get_timer_event_flag ();
1029 /* LIB$GET_EF (&timer_ef); */
1030 SYS$
CLREF (timer_ef
);
1034 LIB$
GET_EF (&process_ef
);
1035 SYS$
CLREF (process_ef
);
1037 if (input_ef
/ 32 != process_ef
/ 32)
1038 croak ("Input and process event flags in different clusters.");
1040 if (input_ef
/ 32 != timer_ef
/ 32)
1041 croak ("Input and timer event flags in different clusters.");
1043 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1044 ((unsigned) 1 << (process_ef
% 32));
1046 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1047 ((unsigned) 1 << (timer_ef
% 32));
1049 sys_access_reinit ();
1051 #endif /* not VMS */
1054 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1055 narrow_foreground_group ();
1058 EMACS_GET_TTY (input_fd
, &old_tty
);
1060 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1064 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1065 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1066 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1068 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1070 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1071 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1073 tty
.main
.c_iflag
&= ~IEXTEN
; /* Disable other editing characters. */
1075 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1078 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1080 tty
.main
.c_iflag
&= ~IXANY
;
1084 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1085 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1087 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1091 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1092 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1095 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1096 /* Set up C-g for both SIGQUIT and SIGINT.
1097 We don't know which we will get, but we handle both alike
1098 so which one it really gives us does not matter. */
1099 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1100 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1101 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1103 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1106 #if defined (mips) || defined (HAVE_TCATTR)
1108 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1111 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1112 #endif /* V_DSUSP */
1113 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1114 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1117 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1120 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1121 #endif /* VREPRINT */
1123 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1124 #endif /* VWERASE */
1126 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1127 #endif /* VDISCARD */
1128 #endif /* mips or HAVE_TCATTR */
1131 /* AIX enhanced edit loses NULs, so disable it */
1132 tty
.main
.c_line
= 0;
1133 tty
.main
.c_iflag
&= ~ASCEDIT
;
1135 tty
.main
.c_cc
[VSTRT
] = 255;
1136 tty
.main
.c_cc
[VSTOP
] = 255;
1137 tty
.main
.c_cc
[VSUSP
] = 255;
1138 tty
.main
.c_cc
[VDSUSP
] = 255;
1139 #endif /* IBMR2AIX */
1140 /* Also, PTY overloads NUL and BREAK.
1141 don't ignore break, but don't signal either, so it looks like NUL.
1142 This really serves a purpose only if running in an XTERM window
1143 or via TELNET or the like, but does no harm elsewhere. */
1144 tty
.main
.c_iflag
&= ~IGNBRK
;
1145 tty
.main
.c_iflag
&= ~BRKINT
;
1147 #else /* if not HAVE_TERMIO */
1149 tty
.main
.tt_char
|= TT$M_NOECHO
;
1151 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1153 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1155 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1156 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1157 #else /* not VMS (BSD, that is) */
1159 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1161 tty
.main
.sg_flags
|= ANYP
;
1162 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1164 #endif /* not VMS (BSD, that is) */
1165 #endif /* not HAVE_TERMIO */
1167 /* If going to use CBREAK mode, we must request C-g to interrupt
1168 and turn off start and stop chars, etc. If not going to use
1169 CBREAK mode, do this anyway so as to turn off local flow
1170 control for user coming over network on 4.2; in this case,
1171 only t_stopc and t_startc really matter. */
1174 /* Note: if not using CBREAK mode, it makes no difference how we
1176 tty
.tchars
= new_tchars
;
1177 tty
.tchars
.t_intrc
= quit_char
;
1180 tty
.tchars
.t_startc
= '\021';
1181 tty
.tchars
.t_stopc
= '\023';
1184 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1186 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1187 anything, and leaving it in breaks the meta key. Go figure. */
1188 tty
.lmode
&= ~LLITOUT
;
1195 #endif /* HAVE_TCHARS */
1196 #endif /* not HAVE_TERMIO */
1199 tty
.ltchars
= new_ltchars
;
1200 #endif /* HAVE_LTCHARS */
1201 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1202 internal_terminal_init ();
1206 EMACS_SET_TTY (input_fd
, &tty
, 0);
1208 /* This code added to insure that, if flow-control is not to be used,
1209 we have an unlocked terminal at the start. */
1212 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1216 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1224 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1225 to be only LF. This is the way that is done. */
1228 if (ioctl (1, HFTGETID
, &tty
) != -1)
1229 write (1, "\033[20l", 5);
1235 /* Appears to do nothing when in PASTHRU mode.
1236 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1237 interrupt_signal, oob_chars, 0, 0, 0, 0);
1239 queue_kbd_input (0);
1244 #ifndef F_SETOWN_BUG
1245 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1246 if (interrupt_input
)
1248 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1249 fcntl (input_fd
, F_SETOWN
, getpid ());
1252 #endif /* F_GETOWN */
1253 #endif /* F_SETOWN_BUG */
1254 #endif /* F_SETFL */
1257 if (interrupt_input
)
1261 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1265 /* This symbol is defined on recent USG systems.
1266 Someone says without this call USG won't really buffer the file
1267 even with a call to setbuf. */
1268 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
1270 setbuf (stdout
, _sobuf
);
1272 set_terminal_modes ();
1273 if (term_initted
&& no_redraw_on_reenter
)
1275 if (display_completed
)
1276 direct_output_forward_char (0);
1282 if (FRAMEP (Vterminal_frame
))
1283 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1290 /* Return nonzero if safe to use tabs in output.
1291 At the time this is called, init_sys_modes has not been done yet. */
1295 struct emacs_tty tty
;
1297 EMACS_GET_TTY (input_fd
, &tty
);
1298 return EMACS_TTY_TABS_OK (&tty
);
1301 /* Get terminal size from system.
1302 Store number of lines into *heightp and width into *widthp.
1303 If zero or a negative number is stored, the value is not valid. */
1305 get_frame_size (widthp
, heightp
)
1306 int *widthp
, *heightp
;
1312 struct winsize size
;
1314 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1315 *widthp
= *heightp
= 0;
1318 *widthp
= size
.ws_col
;
1319 *heightp
= size
.ws_row
;
1325 /* SunOS - style. */
1326 struct ttysize size
;
1328 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1329 *widthp
= *heightp
= 0;
1332 *widthp
= size
.ts_cols
;
1333 *heightp
= size
.ts_lines
;
1339 struct sensemode tty
;
1341 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1342 &tty
.class, 12, 0, 0, 0, 0);
1343 *widthp
= tty
.scr_wid
;
1344 *heightp
= tty
.scr_len
;
1348 *widthp
= ScreenCols ();
1349 *heightp
= ScreenRows ();
1350 #else /* system doesn't know size */
1355 #endif /* not VMS */
1356 #endif /* not SunOS-style */
1357 #endif /* not BSD-style */
1361 /* Prepare the terminal for exiting Emacs; move the cursor to the
1362 bottom of the frame, turn off interrupt-driven I/O, etc. */
1372 if (read_socket_hook
|| !EQ (Vwindow_system
, Qnil
))
1374 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1375 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1376 /* clear_end_of_line may move the cursor */
1377 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1380 /* HFT devices normally use ^J as a LF/CR. We forced it to
1381 do the LF only. Now, we need to reset it. */
1384 if (ioctl (1, HFTGETID
, &tty
) != -1)
1385 write (1, "\033[20h", 5);
1389 reset_terminal_modes ();
1393 /* Avoid possible loss of output when changing terminal modes. */
1394 fsync (fileno (stdout
));
1399 #ifndef F_SETOWN_BUG
1400 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1401 if (interrupt_input
)
1404 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1406 #endif /* F_SETOWN */
1407 #endif /* F_SETOWN_BUG */
1408 #endif /* F_SETFL */
1410 if (interrupt_input
)
1414 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1417 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1426 widen_foreground_group ();
1432 /* Set up the proper status flags for use of a pty. */
1437 /* I'm told that TOICREMOTE does not mean control chars
1438 "can't be sent" but rather that they don't have
1439 input-editing or signaling effects.
1440 That should be good, because we have other ways
1441 to do those things in Emacs.
1442 However, telnet mode seems not to work on 4.2.
1443 So TIOCREMOTE is turned off now. */
1445 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1446 will hang. In particular, the "timeout" feature (which
1447 causes a read to return if there is no data available)
1448 does this. Also it is known that telnet mode will hang
1449 in such a way that Emacs must be stopped (perhaps this
1450 is the same problem).
1452 If TIOCREMOTE is turned off, then there is a bug in
1453 hp-ux which sometimes loses data. Apparently the
1454 code which blocks the master process when the internal
1455 buffer fills up does not work. Other than this,
1456 though, everything else seems to work fine.
1458 Since the latter lossage is more benign, we may as well
1459 lose that way. -- cph */
1464 ioctl (fd
, FIONBIO
, &on
);
1469 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1470 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1471 /* cause EMACS not to die when it should, i.e., when its own controlling */
1472 /* tty goes away. I've complained to the AIX developers, and they may */
1473 /* change this behavior, but I'm not going to hold my breath. */
1474 signal (SIGHUP
, SIG_IGN
);
1477 #endif /* HAVE_PTYS */
1481 /* Assigning an input channel is done at the start of Emacs execution.
1482 This is called each time Emacs is resumed, also, but does nothing
1483 because input_chain is no longer zero. */
1491 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1497 /* Deassigning the input channel is done before exiting. */
1501 return SYS$
DASSGN (input_fd
);
1506 /* Request reading one character into the keyboard buffer.
1507 This is done as soon as the buffer becomes empty. */
1512 extern kbd_input_ast ();
1514 waiting_for_ast
= 0;
1516 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1517 &input_iosb
, kbd_input_ast
, 1,
1518 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1523 /* Ast routine that is called when keyboard input comes in
1524 in accord with the SYS$QIO above. */
1528 register int c
= -1;
1529 int old_errno
= errno
;
1530 extern EMACS_TIME
*input_available_clear_time
;
1532 if (waiting_for_ast
)
1533 SYS$
SETEF (input_ef
);
1534 waiting_for_ast
= 0;
1537 if (input_count
== 25)
1539 printf ("Ast # %d,", input_count
);
1540 printf (" iosb = %x, %x, %x, %x",
1541 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1544 if (input_iosb
.offset
)
1548 printf (", char = 0%o", c
);
1560 struct input_event e
;
1561 e
.kind
= ascii_keystroke
;
1562 XSET (e
.code
, Lisp_Int
, c
);
1564 XSET(e
.frame_or_window
, Lisp_Frame
, selected_frame
);
1566 e
.frame_or_window
= Qnil
;
1568 kbd_buffer_store_event (&e
);
1570 if (input_available_clear_time
)
1571 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1575 /* Wait until there is something in kbd_buffer. */
1577 wait_for_kbd_input ()
1579 extern int have_process_input
, process_exited
;
1581 /* If already something, avoid doing system calls. */
1582 if (detect_input_pending ())
1586 /* Clear a flag, and tell ast routine above to set it. */
1587 SYS$
CLREF (input_ef
);
1588 waiting_for_ast
= 1;
1589 /* Check for timing error: ast happened while we were doing that. */
1590 if (!detect_input_pending ())
1592 /* No timing error: wait for flag to be set. */
1593 set_waiting_for_input (0);
1594 SYS$
WFLOR (input_ef
, input_eflist
);
1595 clear_waiting_for_input (0);
1596 if (!detect_input_pending ())
1597 /* Check for subprocess input availability */
1599 int dsp
= have_process_input
|| process_exited
;
1601 SYS$
CLREF (process_ef
);
1602 if (have_process_input
)
1603 process_command_input ();
1608 update_mode_lines
++;
1609 prepare_menu_bars ();
1610 redisplay_preserve_echo_area ();
1614 waiting_for_ast
= 0;
1617 /* Get rid of any pending QIO, when we are about to suspend
1618 or when we want to throw away pending input.
1619 We wait for a positive sign that the AST routine has run
1620 and therefore there is no I/O request queued when we return.
1621 SYS$SETAST is used to avoid a timing error. */
1626 printf ("At end_kbd_input.\n");
1630 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
1632 SYS$
CANCEL (input_fd
);
1637 /* Clear a flag, and tell ast routine above to set it. */
1638 SYS$
CLREF (input_ef
);
1639 waiting_for_ast
= 1;
1641 SYS$
CANCEL (input_fd
);
1643 SYS$
WAITFR (input_ef
);
1644 waiting_for_ast
= 0;
1647 /* Wait for either input available or time interval expiry. */
1649 input_wait_timeout (timeval
)
1650 int timeval
; /* Time to wait, in seconds */
1653 static int zero
= 0;
1654 static int large
= -10000000;
1656 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1658 /* If already something, avoid doing system calls. */
1659 if (detect_input_pending ())
1663 /* Clear a flag, and tell ast routine above to set it. */
1664 SYS$
CLREF (input_ef
);
1665 waiting_for_ast
= 1;
1666 /* Check for timing error: ast happened while we were doing that. */
1667 if (!detect_input_pending ())
1669 /* No timing error: wait for flag to be set. */
1671 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1672 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
1674 waiting_for_ast
= 0;
1677 /* The standard `sleep' routine works some other way
1678 and it stops working if you have ever quit out of it.
1679 This one continues to work. */
1685 static int zero
= 0;
1686 static int large
= -10000000;
1688 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1691 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1692 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
1707 croak ("request sigio");
1712 croak ("unrequest sigio");
1717 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
1722 #ifndef SYSTEM_MALLOC
1729 /* Some systems that cannot dump also cannot implement these. */
1732 * Return the address of the start of the text segment prior to
1733 * doing an unexec. After unexec the return value is undefined.
1734 * See crt0.c for further explanation and _start.
1738 #ifndef CANNOT_UNEXEC
1743 return ((char *) TEXT_START
);
1747 return ((char *) csrt
);
1748 #else /* not GOULD */
1749 extern int _start ();
1750 return ((char *) _start
);
1752 #endif /* TEXT_START */
1754 #endif /* not CANNOT_UNEXEC */
1757 * Return the address of the start of the data segment prior to
1758 * doing an unexec. After unexec the return value is undefined.
1759 * See crt0.c for further information and definition of data_start.
1761 * Apparently, on BSD systems this is etext at startup. On
1762 * USG systems (swapping) this is highly mmu dependent and
1763 * is also dependent on whether or not the program is running
1764 * with shared text. Generally there is a (possibly large)
1765 * gap between end of text and start of data with shared text.
1767 * On Uniplus+ systems with shared text, data starts at a
1768 * fixed address. Each port (from a given oem) is generally
1769 * different, and the specific value of the start of data can
1770 * be obtained via the UniPlus+ specific "uvar" system call,
1771 * however the method outlined in crt0.c seems to be more portable.
1773 * Probably what will have to happen when a USG unexec is available,
1774 * at least on UniPlus, is temacs will have to be made unshared so
1775 * that text and data are contiguous. Then once loadup is complete,
1776 * unexec will produce a shared executable where the data can be
1777 * at the normal shared text boundry and the startofdata variable
1778 * will be patched by unexec to the correct value.
1786 return ((char *) DATA_START
);
1788 #ifdef ORDINARY_LINK
1790 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
1791 * data_start isn't defined. We take the address of environ, which
1792 * is known to live at or near the start of the system crt0.c, and
1793 * we don't sweat the handful of bytes that might lose.
1795 extern char **environ
;
1797 return((char *) &environ
);
1799 extern int data_start
;
1800 return ((char *) &data_start
);
1801 #endif /* ORDINARY_LINK */
1802 #endif /* DATA_START */
1804 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
1807 /* Some systems that cannot dump also cannot implement these. */
1810 * Return the address of the end of the text segment prior to
1811 * doing an unexec. After unexec the return value is undefined.
1818 return ((char *) TEXT_END
);
1821 return ((char *) &etext
);
1826 * Return the address of the end of the data segment prior to
1827 * doing an unexec. After unexec the return value is undefined.
1834 return ((char *) DATA_END
);
1837 return ((char *) &edata
);
1841 #endif /* not CANNOT_DUMP */
1843 /* Get_system_name returns as its value
1844 a string for the Lisp function system-name to return. */
1850 /* Can't have this within the function since `static' is #defined to
1851 nothing for some USG systems. */
1853 #ifdef HAVE_GETHOSTNAME
1854 static char get_system_name_name
[256];
1855 #else /* not HAVE_GETHOSTNAME */
1856 static struct utsname get_system_name_name
;
1857 #endif /* not HAVE_GETHOSTNAME */
1864 #include <sys/socket.h>
1866 #endif /* HAVE_SOCKETS */
1867 #endif /* not VMS */
1868 #endif /* not USG */
1869 #endif /* not BSD4_1 */
1875 #ifdef HAVE_GETHOSTNAME
1876 gethostname (get_system_name_name
, sizeof (get_system_name_name
));
1877 return get_system_name_name
;
1878 #else /* not HAVE_GETHOSTNAME */
1879 uname (&get_system_name_name
);
1880 return (get_system_name_name
.nodename
);
1881 #endif /* not HAVE_GETHOSTNAME */
1885 #else /* not USG, not 4.1 */
1886 static char system_name_saved
[32];
1889 if ((sp
= egetenv ("SYS$NODE")) == 0)
1895 if ((end
= index (sp
, ':')) != 0)
1898 strcpy (system_name_saved
, sp
);
1900 gethostname (system_name_saved
, sizeof (system_name_saved
));
1902 /* Turn the hostname into the official, fully-qualified hostname.
1903 Don't do this if we're going to dump; this can confuse system
1904 libraries on some machines and make the dumped emacs core dump. */
1907 #endif /* not CANNOT_DUMP */
1910 hp
= gethostbyname (system_name_saved
);
1911 if (hp
&& strlen (hp
->h_name
) < sizeof(system_name_saved
))
1912 strcpy (system_name_saved
, hp
->h_name
);
1913 if (hp
&& !index (system_name_saved
, '.'))
1915 /* We still don't have a fully qualified domain name.
1916 Try to find one in the list of alternate names */
1917 char **alias
= hp
->h_aliases
;
1918 while (*alias
&& !index (*alias
, '.'))
1920 if (*alias
&& strlen (*alias
) < sizeof (system_name_saved
))
1921 strcpy (system_name_saved
, *alias
);
1924 #endif /* HAVE_SOCKETS */
1925 #endif /* not VMS */
1926 return system_name_saved
;
1927 #endif /* not USG, not 4.1 */
1928 #endif /* not USG */
1932 #ifndef HAVE_GETHOSTNAME
1933 void gethostname(buf
, len
)
1938 s
= getenv ("SYS$NODE");
1942 strncpy (buf
, s
, len
- 2);
1943 buf
[len
- 1] = '\0';
1945 } /* static void gethostname */
1946 #endif /* ! HAVE_GETHOSTNAME */
1953 #ifdef HAVE_X_WINDOWS
1954 /* Cause explanatory error message at compile time,
1955 since the select emulation is not good enough for X. */
1956 int *x
= &x_windows_lose_if_no_select_system_call
;
1959 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
1960 * Only checks read descriptors.
1962 /* How long to wait between checking fds in select */
1963 #define SELECT_PAUSE 1
1966 /* For longjmp'ing back to read_input_waiting. */
1968 jmp_buf read_alarm_throw
;
1970 /* Nonzero if the alarm signal should throw back to read_input_waiting.
1971 The read_socket_hook function sets this to 1 while it is waiting. */
1973 int read_alarm_should_throw
;
1981 #else /* not BSD4_1 */
1982 signal (SIGALRM
, SIG_IGN
);
1983 #endif /* not BSD4_1 */
1984 if (read_alarm_should_throw
)
1985 longjmp (read_alarm_throw
, 1);
1988 /* Only rfds are checked. */
1990 select (nfds
, rfds
, wfds
, efds
, timeout
)
1992 int *rfds
, *wfds
, *efds
, *timeout
;
1994 int ravail
= 0, orfds
= 0, old_alarm
;
1995 int timeoutval
= timeout
? *timeout
: 100000;
1996 int *local_timeout
= &timeoutval
;
1997 extern int proc_buffered_char
[];
1998 #ifndef subprocesses
1999 int process_tick
= 0, update_tick
= 0;
2001 extern int process_tick
, update_tick
;
2003 SIGTYPE (*old_trap
) ();
2016 /* If we are looking only for the terminal, with no timeout,
2017 just read it and wait -- that's more efficient. */
2018 if (orfds
== 1 && *local_timeout
== 100000 && process_tick
== update_tick
)
2020 if (! detect_input_pending ())
2021 read_input_waiting ();
2026 /* Once a second, till the timer expires, check all the flagged read
2027 * descriptors to see if any input is available. If there is some then
2028 * set the corresponding bit in the return copy of rfds.
2032 register int to_check
, bit
, fd
;
2036 for (to_check
= nfds
, bit
= 1, fd
= 0; --to_check
>= 0; bit
<<= 1, fd
++)
2040 int avail
= 0, status
= 0;
2043 avail
= detect_input_pending (); /* Special keyboard handler */
2047 status
= ioctl (fd
, FIONREAD
, &avail
);
2048 #else /* no FIONREAD */
2050 abort (); /* I don't think we need it. */
2051 #else /* not MSDOS */
2052 /* Hoping it will return -1 if nothing available
2053 or 0 if all 0 chars requested are read. */
2054 if (proc_buffered_char
[fd
] >= 0)
2058 avail
= read (fd
, &buf
, 1);
2060 proc_buffered_char
[fd
] = buf
;
2062 #endif /* not MSDOS */
2063 #endif /* no FIONREAD */
2065 if (status
>= 0 && avail
> 0)
2073 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2075 old_alarm
= alarm (0);
2076 old_trap
= signal (SIGALRM
, select_alarm
);
2078 alarm (SELECT_PAUSE
);
2079 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2080 while (select_alarmed
== 0 && *local_timeout
!= 0
2081 && process_tick
== update_tick
)
2084 sleep_or_kbd_hit (SELECT_PAUSE
, (orfds
& 1) != 0);
2086 #else /* not MSDOS */
2087 /* If we are interested in terminal input,
2088 wait by reading the terminal.
2089 That makes instant wakeup for terminal input at least. */
2092 read_input_waiting ();
2093 if (detect_input_pending ())
2098 #endif /* not MSDOS */
2100 (*local_timeout
) -= SELECT_PAUSE
;
2101 /* Reset the old alarm if there was one */
2103 signal (SIGALRM
, old_trap
);
2106 /* Reset or forge an interrupt for the original handler. */
2107 old_alarm
-= SELECT_PAUSE
;
2109 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2113 if (*local_timeout
== 0) /* Stop on timer being cleared */
2119 /* Read keyboard input into the standard buffer,
2120 waiting for at least one character. */
2122 /* Make all keyboard buffers much bigger when using X windows. */
2123 #ifdef HAVE_X_WINDOWS
2124 #define BUFFER_SIZE_FACTOR 16
2126 #define BUFFER_SIZE_FACTOR 1
2129 read_input_waiting ()
2131 struct input_event e
;
2133 extern int quit_char
;
2135 if (read_socket_hook
)
2137 struct input_event buf
[256];
2139 read_alarm_should_throw
= 0;
2140 if (! setjmp (read_alarm_throw
))
2141 nread
= (*read_socket_hook
) (0, buf
, 256, 1, 0);
2145 /* Scan the chars for C-g and store them in kbd_buffer. */
2146 for (i
= 0; i
< nread
; i
++)
2148 kbd_buffer_store_event (&buf
[i
]);
2149 /* Don't look at input that follows a C-g too closely.
2150 This reduces lossage due to autorepeat on C-g. */
2151 if (buf
[i
].kind
== ascii_keystroke
2152 && XINT(buf
[i
].code
) == quit_char
)
2159 nread
= read (fileno (stdin
), buf
, 1);
2161 /* Scan the chars for C-g and store them in kbd_buffer. */
2162 e
.kind
= ascii_keystroke
;
2163 e
.frame_or_window
= selected_frame
;
2165 for (i
= 0; i
< nread
; i
++)
2167 /* Convert chars > 0177 to meta events if desired.
2168 We do this under the same conditions that read_avail_input does. */
2169 if (read_socket_hook
== 0)
2171 /* If the user says she has a meta key, then believe her. */
2172 if (meta_key
== 1 && (buf
[i
] & 0x80))
2173 e
.modifiers
= meta_modifier
;
2178 XSET (e
.code
, Lisp_Int
, buf
[i
]);
2179 kbd_buffer_store_event (&e
);
2180 /* Don't look at input that follows a C-g too closely.
2181 This reduces lossage due to autorepeat on C-g. */
2182 if (buf
[i
] == quit_char
)
2188 #endif /* not HAVE_SELECT */
2189 #endif /* not VMS */
2193 * Partially emulate 4.2 open call.
2194 * open is defined as this in 4.1.
2196 * - added by Michael Bloom @ Citicorp/TTI
2201 sys_open (path
, oflag
, mode
)
2205 if (oflag
& O_CREAT
)
2206 return creat (path
, mode
);
2208 return open (path
, oflag
);
2215 lmode
= LINTRUP
| lmode
;
2216 ioctl (0, TIOCLSET
, &lmode
);
2223 lmode
= ~LINTRUP
& lmode
;
2224 ioctl (0, TIOCLSET
, &lmode
);
2231 interrupts_deferred
= 0;
2238 interrupts_deferred
= 1;
2241 /* still inside #ifdef BSD4_1 */
2244 int sigheld
; /* Mask of held signals */
2249 sigheld
|= sigbit (signum
);
2256 sigheld
|= sigbit (signum
);
2262 sigheld
&= ~sigbit (signum
);
2266 sigfree () /* Free all held signals */
2269 for (i
= 0; i
< NSIG
; i
++)
2270 if (sigheld
& sigbit (i
))
2277 return 1 << (i
- 1);
2279 #endif /* subprocesses */
2282 /* POSIX signals support - DJB */
2283 /* Anyone with POSIX signals should have ANSI C declarations */
2285 #ifdef POSIX_SIGNALS
2287 sigset_t old_mask
, empty_mask
, full_mask
, temp_mask
;
2288 static struct sigaction new_action
, old_action
;
2292 sigemptyset (&empty_mask
);
2293 sigfillset (&full_mask
);
2297 sys_signal (int signal_number
, signal_handler_t action
)
2300 /* This gets us restartable system calls for efficiency.
2301 The "else" code will works as well. */
2302 return (berk_signal (signal_number
, action
));
2304 sigemptyset (&new_action
.sa_mask
);
2305 new_action
.sa_handler
= action
;
2306 new_action
.sa_flags
= 0;
2307 sigaction (signal_number
, &new_action
, &old_action
);
2308 return (old_action
.sa_handler
);
2313 /* If we're compiling with GCC, we don't need this function, since it
2314 can be written as a macro. */
2316 sys_sigmask (int sig
)
2319 sigemptyset (&mask
);
2320 sigaddset (&mask
, sig
);
2326 sys_sigpause (sigset_t new_mask
)
2328 /* pause emulating berk sigpause... */
2329 sigsuspend (&new_mask
);
2333 /* I'd like to have these guys return pointers to the mask storage in here,
2334 but there'd be trouble if the code was saving multiple masks. I'll be
2335 safe and pass the structure. It normally won't be more than 2 bytes
2339 sys_sigblock (sigset_t new_mask
)
2342 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2347 sys_sigunblock (sigset_t new_mask
)
2350 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2355 sys_sigsetmask (sigset_t new_mask
)
2358 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2362 #endif /* POSIX_SIGNALS */
2371 register int length
;
2375 long max_str
= 65535;
2377 while (length
> max_str
) {
2378 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
2383 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
2385 while (length
-- > 0)
2387 #endif /* not VMS */
2390 #endif /* no bzero */
2393 /* Saying `void' requires a declaration, above, where bcopy is used
2394 and that declaration causes pain for systems where bcopy is a macro. */
2395 bcopy (b1
, b2
, length
)
2398 register int length
;
2401 long max_str
= 65535;
2403 while (length
> max_str
) {
2404 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
2410 (void) LIB$
MOVC3 (&length
, b1
, b2
);
2412 while (length
-- > 0)
2414 #endif /* not VMS */
2416 #endif /* no bcopy */
2420 bcmp (b1
, b2
, length
) /* This could be a macro! */
2423 register int length
;
2426 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
2427 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
2429 return STR$
COMPARE (&src1
, &src2
);
2431 while (length
-- > 0)
2436 #endif /* not VMS */
2438 #endif /* no bcmp */
2440 #endif /* not BSTRING */
2445 * The BSD random returns numbers in the range of
2446 * 0 to 2e31 - 1. The USG rand returns numbers in the
2447 * range of 0 to 2e15 - 1. This is probably not significant
2454 /* Arrange to return a range centered on zero. */
2455 return (rand () << 15) + rand () - (1 << 29);
2469 /* Arrange to return a range centered on zero. */
2470 return (rand () << 15) + rand () - (1 << 29);
2481 #ifdef WRONG_NAME_INSQUE
2494 /* If any place else asks for the TERM variable,
2495 allow it to be overridden with the EMACS_TERM variable
2496 before attempting to translate the logical name TERM. As a last
2497 resort, ask for VAX C's special idea of the TERM variable. */
2504 static char buf
[256];
2505 static struct dsc$descriptor_s equiv
2506 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2507 static struct dsc$descriptor_s d_name
2508 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2511 if (!strcmp (name
, "TERM"))
2513 val
= (char *) getenv ("EMACS_TERM");
2518 d_name
.dsc$w_length
= strlen (name
);
2519 d_name
.dsc$a_pointer
= name
;
2520 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2522 char *str
= (char *) xmalloc (eqlen
+ 1);
2523 bcopy (buf
, str
, eqlen
);
2525 /* This is a storage leak, but a pain to fix. With luck,
2526 no one will ever notice. */
2529 return (char *) getenv (name
);
2534 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2535 to force a call on the debugger from within the image. */
2540 LIB$
SIGNAL (SS$_DEBUG
);
2546 #ifdef LINK_CRTL_SHARE
2547 #ifdef SHAREABLE_LIB_BUG
2548 /* Variables declared noshare and initialized in sharable libraries
2549 cannot be shared. The VMS linker incorrectly forces you to use a private
2550 version which is uninitialized... If not for this "feature", we
2551 could use the C library definition of sys_nerr and sys_errlist. */
2553 char *sys_errlist
[] =
2557 "no such file or directory",
2559 "interrupted system call",
2561 "no such device or address",
2562 "argument list too long",
2563 "exec format error",
2566 "no more processes",
2567 "not enough memory",
2568 "permission denied",
2570 "block device required",
2571 "mount devices busy",
2573 "cross-device link",
2578 "file table overflow",
2579 "too many open files",
2583 "no space left on device",
2585 "read-only file system",
2591 "vax/vms specific error code nontranslatable error"
2593 #endif /* SHAREABLE_LIB_BUG */
2594 #endif /* LINK_CRTL_SHARE */
2597 #ifndef HAVE_STRERROR
2602 extern char *sys_errlist
[];
2603 extern int sys_nerr
;
2605 if (errnum
>= 0 && errnum
< sys_nerr
)
2606 return sys_errlist
[errnum
];
2607 return (char *) "Unknown error";
2610 #endif /* ! HAVE_STRERROR */
2612 #ifdef INTERRUPTIBLE_OPEN
2616 sys_open (path
, oflag
, mode
)
2620 register int rtnval
;
2622 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2623 && (errno
== EINTR
));
2627 #endif /* INTERRUPTIBLE_OPEN */
2629 #ifdef INTERRUPTIBLE_CLOSE
2634 register int rtnval
;
2636 while ((rtnval
= close (fd
)) == -1
2637 && (errno
== EINTR
));
2641 #endif /* INTERRUPTIBLE_CLOSE */
2643 #ifdef INTERRUPTIBLE_IO
2646 sys_read (fildes
, buf
, nbyte
)
2651 register int rtnval
;
2653 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
2654 && (errno
== EINTR
));
2659 sys_write (fildes
, buf
, nbyte
)
2664 register int rtnval
, bytes_written
;
2670 rtnval
= write (fildes
, buf
, nbyte
);
2682 bytes_written
+= rtnval
;
2684 return (bytes_written
);
2687 #endif /* INTERRUPTIBLE_IO */
2692 * Substitute fork for vfork on USG flavors.
2700 #endif /* not HAVE_VFORK */
2704 * All of the following are for USG.
2706 * On USG systems the system calls are INTERRUPTIBLE by signals
2707 * that the user program has elected to catch. Thus the system call
2708 * must be retried in these cases. To handle this without massive
2709 * changes in the source code, we remap the standard system call names
2710 * to names for our own functions in sysdep.c that do the system call
2711 * with retries. Actually, for portability reasons, it is good
2712 * programming practice, as this example shows, to limit all actual
2713 * system calls to a single occurrence in the source. Sure, this
2714 * adds an extra level of function call overhead but it is almost
2715 * always negligible. Fred Fish, Unisoft Systems Inc.
2718 #ifndef HAVE_SYS_SIGLIST
2719 char *sys_siglist
[NSIG
+ 1] =
2722 /* AIX has changed the signals a bit */
2723 "bogus signal", /* 0 */
2724 "hangup", /* 1 SIGHUP */
2725 "interrupt", /* 2 SIGINT */
2726 "quit", /* 3 SIGQUIT */
2727 "illegal instruction", /* 4 SIGILL */
2728 "trace trap", /* 5 SIGTRAP */
2729 "IOT instruction", /* 6 SIGIOT */
2730 "crash likely", /* 7 SIGDANGER */
2731 "floating point exception", /* 8 SIGFPE */
2732 "kill", /* 9 SIGKILL */
2733 "bus error", /* 10 SIGBUS */
2734 "segmentation violation", /* 11 SIGSEGV */
2735 "bad argument to system call", /* 12 SIGSYS */
2736 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2737 "alarm clock", /* 14 SIGALRM */
2738 "software termination signum", /* 15 SIGTERM */
2739 "user defined signal 1", /* 16 SIGUSR1 */
2740 "user defined signal 2", /* 17 SIGUSR2 */
2741 "death of a child", /* 18 SIGCLD */
2742 "power-fail restart", /* 19 SIGPWR */
2743 "bogus signal", /* 20 */
2744 "bogus signal", /* 21 */
2745 "bogus signal", /* 22 */
2746 "bogus signal", /* 23 */
2747 "bogus signal", /* 24 */
2748 "LAN I/O interrupt", /* 25 SIGAIO */
2749 "PTY I/O interrupt", /* 26 SIGPTY */
2750 "I/O intervention required", /* 27 SIGIOINT */
2751 "HFT grant", /* 28 SIGGRANT */
2752 "HFT retract", /* 29 SIGRETRACT */
2753 "HFT sound done", /* 30 SIGSOUND */
2754 "HFT input ready", /* 31 SIGMSG */
2756 "bogus signal", /* 0 */
2757 "hangup", /* 1 SIGHUP */
2758 "interrupt", /* 2 SIGINT */
2759 "quit", /* 3 SIGQUIT */
2760 "illegal instruction", /* 4 SIGILL */
2761 "trace trap", /* 5 SIGTRAP */
2762 "IOT instruction", /* 6 SIGIOT */
2763 "EMT instruction", /* 7 SIGEMT */
2764 "floating point exception", /* 8 SIGFPE */
2765 "kill", /* 9 SIGKILL */
2766 "bus error", /* 10 SIGBUS */
2767 "segmentation violation", /* 11 SIGSEGV */
2768 "bad argument to system call", /* 12 SIGSYS */
2769 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2770 "alarm clock", /* 14 SIGALRM */
2771 "software termination signum", /* 15 SIGTERM */
2772 "user defined signal 1", /* 16 SIGUSR1 */
2773 "user defined signal 2", /* 17 SIGUSR2 */
2774 "death of a child", /* 18 SIGCLD */
2775 "power-fail restart", /* 19 SIGPWR */
2776 #endif /* not AIX */
2779 #endif /* HAVE_SYS_SIGLIST */
2782 * Warning, this function may not duplicate 4.2 action properly
2783 * under error conditions.
2787 /* In 4.1, param.h fails to define this. */
2788 #define MAXPATHLEN 1024
2797 char *npath
, *spath
;
2798 extern char *getcwd ();
2800 BLOCK_INPUT
; /* getcwd uses malloc */
2801 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
2804 /* On Altos 3068, getcwd can return @hostname/dir, so discard
2805 up to first slash. Should be harmless on other systems. */
2806 while (*npath
&& *npath
!= '/')
2808 strcpy (pathname
, npath
);
2809 free (spath
); /* getcwd uses malloc */
2814 #endif /* HAVE_GETWD */
2817 * Emulate rename using unlink/link. Note that this is
2818 * only partially correct. Also, doesn't enforce restriction
2819 * that files be of same type (regular->regular, dir->dir, etc).
2828 if (access (from
, 0) == 0)
2831 if (link (from
, to
) == 0)
2832 if (unlink (from
) == 0)
2840 #ifdef MISSING_UTIMES
2842 /* HPUX (among others) sets HAVE_TIMEVAL but does not implement utimes. */
2851 /* The IRIS (3.5) has timevals, but uses sys V utime, and doesn't have the
2852 utimbuf structure defined anywhere but in the man page. */
2862 struct timeval tvp
[];
2865 utb
.actime
= tvp
[0].tv_sec
;
2866 utb
.modtime
= tvp
[1].tv_sec
;
2869 #endif /* IRIS_UTIME */
2875 /* HPUX curses library references perror, but as far as we know
2876 it won't be called. Anyway this definition will do for now. */
2882 #endif /* not HAVE_PERROR */
2888 * Emulate BSD dup2. First close newd if it already exists.
2889 * Then, attempt to dup oldd. If not successful, call dup2 recursively
2890 * until we are, then close the unsuccessful ones.
2897 register int fd
, ret
;
2902 fd
= fcntl (oldd
, F_DUPFD
, newd
);
2904 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, strerror (errno
));
2911 ret
= dup2 (old
,new);
2917 #endif /* not HAVE_DUP2 */
2920 * Gettimeofday. Simulate as much as possible. Only accurate
2921 * to nearest second. Emacs doesn't use tzp so ignore it for now.
2922 * Only needed when subprocesses are defined.
2927 #ifndef HAVE_GETTIMEOFDAY
2931 gettimeofday (tp
, tzp
)
2933 struct timezone
*tzp
;
2935 extern long time ();
2937 tp
->tv_sec
= time ((long *)0);
2940 tzp
->tz_minuteswest
= -1;
2946 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
2949 * This function will go away as soon as all the stubs fixed. (fnf)
2955 printf ("%s not yet implemented\r\n", badfunc
);
2964 char *sys_siglist
[NSIG
+ 1] =
2966 "null signal", /* 0 SIGNULL */
2967 "hangup", /* 1 SIGHUP */
2968 "interrupt", /* 2 SIGINT */
2969 "quit", /* 3 SIGQUIT */
2970 "illegal instruction", /* 4 SIGILL */
2971 "trace trap", /* 5 SIGTRAP */
2972 "abort termination", /* 6 SIGABRT */
2973 "SIGEMT", /* 7 SIGEMT */
2974 "floating point exception", /* 8 SIGFPE */
2975 "kill", /* 9 SIGKILL */
2976 "bus error", /* 10 SIGBUS */
2977 "segmentation violation", /* 11 SIGSEGV */
2978 "bad argument to system call", /* 12 SIGSYS */
2979 "write on a pipe with no reader", /* 13 SIGPIPE */
2980 "alarm clock", /* 14 SIGALRM */
2981 "software termination signal", /* 15 SIGTERM */
2982 "user defined signal 1", /* 16 SIGUSR1 */
2983 "user defined signal 2", /* 17 SIGUSR2 */
2984 "child stopped or terminated", /* 18 SIGCLD */
2985 "power-fail restart", /* 19 SIGPWR */
2986 "window size changed", /* 20 SIGWINCH */
2987 "undefined", /* 21 */
2988 "pollable event occurred", /* 22 SIGPOLL */
2989 "sendable stop signal not from tty", /* 23 SIGSTOP */
2990 "stop signal from tty", /* 24 SIGSTP */
2991 "continue a stopped process", /* 25 SIGCONT */
2992 "attempted background tty read", /* 26 SIGTTIN */
2993 "attempted background tty write", /* 27 SIGTTOU */
2994 "undefined", /* 28 */
2995 "undefined", /* 29 */
2996 "undefined", /* 30 */
2997 "undefined", /* 31 */
2998 "undefined", /* 32 */
2999 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
3000 "I/O is possible", /* 34 SIGIO */
3001 "exceeded cpu time limit", /* 35 SIGXCPU */
3002 "exceeded file size limit", /* 36 SIGXFSZ */
3003 "virtual time alarm", /* 37 SIGVTALRM */
3004 "profiling time alarm", /* 38 SIGPROF */
3005 "undefined", /* 39 */
3006 "file record locks revoked", /* 40 SIGLOST */
3007 "undefined", /* 41 */
3008 "undefined", /* 42 */
3009 "undefined", /* 43 */
3010 "undefined", /* 44 */
3011 "undefined", /* 45 */
3012 "undefined", /* 46 */
3013 "undefined", /* 47 */
3014 "undefined", /* 48 */
3015 "undefined", /* 49 */
3016 "undefined", /* 50 */
3017 "undefined", /* 51 */
3018 "undefined", /* 52 */
3019 "undefined", /* 53 */
3020 "undefined", /* 54 */
3021 "undefined", /* 55 */
3022 "undefined", /* 56 */
3023 "undefined", /* 57 */
3024 "undefined", /* 58 */
3025 "undefined", /* 59 */
3026 "undefined", /* 60 */
3027 "undefined", /* 61 */
3028 "undefined", /* 62 */
3029 "undefined", /* 63 */
3030 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3036 /* Directory routines for systems that don't have them. */
3038 #ifdef SYSV_SYSTEM_DIR
3042 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
3046 register DIR *dirp
; /* stream from opendir */
3050 rtnval
= sys_close (dirp
->dd_fd
);
3052 /* Some systems (like Solaris) allocate the buffer and the DIR all
3053 in one block. Why in the world are we freeing this ourselves
3055 #if ! (defined (sun) && defined (USG5_4))
3056 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3058 xfree ((char *) dirp
);
3062 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3063 #endif /* SYSV_SYSTEM_DIR */
3065 #ifdef NONSYSTEM_DIR_LIBRARY
3069 char *filename
; /* name of directory */
3071 register DIR *dirp
; /* -> malloc'ed storage */
3072 register int fd
; /* file descriptor for read */
3073 struct stat sbuf
; /* result of fstat */
3075 fd
= sys_open (filename
, 0);
3080 if (fstat (fd
, &sbuf
) < 0
3081 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3082 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
3086 return 0; /* bad luck today */
3091 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3098 register DIR *dirp
; /* stream from opendir */
3100 sys_close (dirp
->dd_fd
);
3101 xfree ((char *) dirp
);
3109 ino_t od_ino
; /* inode */
3110 char od_name
[DIRSIZ
]; /* filename */
3112 #endif /* not VMS */
3114 struct direct dir_static
; /* simulated directory contents */
3119 register DIR *dirp
; /* stream from opendir */
3122 register struct olddir
*dp
; /* -> directory data */
3124 register struct dir$_name
*dp
; /* -> directory data */
3125 register struct dir$_version
*dv
; /* -> version data */
3130 if (dirp
->dd_loc
>= dirp
->dd_size
)
3131 dirp
->dd_loc
= dirp
->dd_size
= 0;
3133 if (dirp
->dd_size
== 0 /* refill buffer */
3134 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3138 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3139 dirp
->dd_loc
+= sizeof (struct olddir
);
3141 if (dp
->od_ino
!= 0) /* not deleted entry */
3143 dir_static
.d_ino
= dp
->od_ino
;
3144 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3145 dir_static
.d_name
[DIRSIZ
] = '\0';
3146 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3147 dir_static
.d_reclen
= sizeof (struct direct
)
3149 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3150 return &dir_static
; /* -> simulated structure */
3153 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3154 if (dirp
->dd_loc
== 0)
3155 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3156 : dp
->dir$b_namecount
;
3157 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3158 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3159 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3160 dir_static
.d_reclen
= sizeof (struct direct
)
3162 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3163 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3164 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3165 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3172 /* readdirver is just like readdir except it returns all versions of a file
3173 as separate entries. */
3178 register DIR *dirp
; /* stream from opendir */
3180 register struct dir$_name
*dp
; /* -> directory data */
3181 register struct dir$_version
*dv
; /* -> version data */
3183 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3184 dirp
->dd_loc
= dirp
->dd_size
= 0;
3186 if (dirp
->dd_size
== 0 /* refill buffer */
3187 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3190 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3191 if (dirp
->dd_loc
== 0)
3192 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3193 : dp
->dir$b_namecount
;
3194 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3195 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3196 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3197 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3198 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3199 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3200 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3201 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3207 #endif /* NONSYSTEM_DIR_LIBRARY */
3210 /* mkdir and rmdir functions, for systems which don't have them. */
3214 * Written by Robert Rother, Mariah Corporation, August 1985.
3216 * If you want it, it's yours. All I ask in return is that if you
3217 * figure out how to do this in a Bourne Shell script you send me
3219 * sdcsvax!rmr or rmr@uscd
3221 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3222 * subroutine. 11Mar86; hoptoad!gnu
3224 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3225 * subroutine didn't return EEXIST. It does now.
3232 mkdir (dpath
, dmode
)
3236 int cpid
, status
, fd
;
3237 struct stat statbuf
;
3239 if (stat (dpath
, &statbuf
) == 0)
3241 errno
= EEXIST
; /* Stat worked, so it already exists */
3245 /* If stat fails for a reason other than non-existence, return error */
3246 if (errno
!= ENOENT
)
3249 synch_process_alive
= 1;
3250 switch (cpid
= fork ())
3253 case -1: /* Error in fork */
3254 return (-1); /* Errno is set already */
3256 case 0: /* Child process */
3258 * Cheap hack to set mode of new directory. Since this
3259 * child process is going away anyway, we zap its umask.
3260 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3261 * directory. Does anybody care?
3263 status
= umask (0); /* Get current umask */
3264 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3265 fd
= sys_open("/dev/null", 2);
3272 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3273 _exit (-1); /* Can't exec /bin/mkdir */
3275 default: /* Parent process */
3276 wait_for_termination (cpid
);
3279 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3281 errno
= EIO
; /* We don't know why, but */
3282 return -1; /* /bin/mkdir failed */
3287 #endif /* not HAVE_MKDIR */
3294 int cpid
, status
, fd
;
3295 struct stat statbuf
;
3297 if (stat (dpath
, &statbuf
) != 0)
3299 /* Stat just set errno. We don't have to */
3303 synch_process_alive
= 1;
3304 switch (cpid
= fork ())
3307 case -1: /* Error in fork */
3308 return (-1); /* Errno is set already */
3310 case 0: /* Child process */
3311 fd
= sys_open("/dev/null", 2);
3318 wait_for_termination (cpid
);
3319 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3320 return -1; /* /bin/rmdir failed */
3321 default: /* Parent process */
3322 while (cpid
!= wait (&status
)); /* Wait for kid to finish */
3325 if (WIFSIGNALED (status
) || WEXITSTATUS (status
) != 0)
3327 errno
= EIO
; /* We don't know why, but */
3328 return -1; /* /bin/mkdir failed */
3333 #endif /* !HAVE_RMDIR */
3337 /* Functions for VMS */
3339 #include "vms-pwd.h"
3344 /* Return as a string the VMS error string pertaining to STATUS.
3345 Reuses the same static buffer each time it is called. */
3349 int status
; /* VMS status code */
3353 static char buf
[257];
3355 bufadr
[0] = sizeof buf
- 1;
3356 bufadr
[1] = (int) buf
;
3357 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3358 return "untranslatable VMS error status";
3366 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3367 * not work correctly. (It also doesn't work well in version 2.3.)
3372 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3373 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3377 unsigned short s_buflen
;
3378 unsigned short s_code
;
3380 unsigned short *s_retlenadr
;
3384 #define buflen s.s_buflen
3385 #define code s.s_code
3386 #define bufadr s.s_bufadr
3387 #define retlenadr s.s_retlenadr
3389 #define R_OK 4 /* test for read permission */
3390 #define W_OK 2 /* test for write permission */
3391 #define X_OK 1 /* test for execute (search) permission */
3392 #define F_OK 0 /* test for presence of file */
3395 sys_access (path
, mode
)
3399 static char *user
= NULL
;
3402 /* translate possible directory spec into .DIR file name, so brain-dead
3403 * access can treat the directory like a file. */
3404 if (directory_file_name (path
, dir_fn
))
3408 return access (path
, mode
);
3409 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3415 unsigned short int dummy
;
3417 static int constant
= ACL$C_FILE
;
3418 DESCRIPTOR (path_desc
, path
);
3419 DESCRIPTOR (user_desc
, user
);
3423 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3426 acces
|= CHP$M_READ
;
3428 acces
|= CHP$M_WRITE
;
3429 itemlst
[0].buflen
= sizeof (int);
3430 itemlst
[0].code
= CHP$_FLAGS
;
3431 itemlst
[0].bufadr
= (char *) &flags
;
3432 itemlst
[0].retlenadr
= &dummy
;
3433 itemlst
[1].buflen
= sizeof (int);
3434 itemlst
[1].code
= CHP$_ACCESS
;
3435 itemlst
[1].bufadr
= (char *) &acces
;
3436 itemlst
[1].retlenadr
= &dummy
;
3437 itemlst
[2].end
= CHP$_END
;
3438 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3439 return stat
== SS$_NORMAL
? 0 : -1;
3443 #else /* not VMS4_4 */
3446 #define ACE$M_WRITE 2
3447 #define ACE$C_KEYID 1
3449 static unsigned short memid
, grpid
;
3450 static unsigned int uic
;
3452 /* Called from init_sys_modes, so it happens not very often
3453 but at least each time Emacs is loaded. */
3454 sys_access_reinit ()
3460 sys_access (filename
, type
)
3466 int status
, size
, i
, typecode
, acl_controlled
;
3467 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3468 union prvdef prvmask
;
3470 /* Get UIC and GRP values for protection checking. */
3473 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3476 memid
= uic
& 0xFFFF;
3480 if (type
!= 2) /* not checking write access */
3481 return access (filename
, type
);
3483 /* Check write protection. */
3485 #define CHECKPRIV(bit) (prvmask.bit)
3486 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3488 /* Find privilege bits */
3489 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3491 error ("Unable to find privileges: %s", vmserrstr (status
));
3492 if (CHECKPRIV (PRV$V_BYPASS
))
3493 return 0; /* BYPASS enabled */
3495 fab
.fab$b_fac
= FAB$M_GET
;
3496 fab
.fab$l_fna
= filename
;
3497 fab
.fab$b_fns
= strlen (filename
);
3498 fab
.fab$l_xab
= &xab
;
3499 xab
= cc$rms_xabpro
;
3500 xab
.xab$l_aclbuf
= aclbuf
;
3501 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3502 status
= SYS$
OPEN (&fab
, 0, 0);
3505 SYS$
CLOSE (&fab
, 0, 0);
3506 /* Check system access */
3507 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITEABLE (XAB$V_SYS
))
3509 /* Check ACL entries, if any */
3511 if (xab
.xab$w_acllen
> 0)
3514 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3515 while (*aclptr
&& aclptr
< aclend
)
3517 size
= (*aclptr
& 0xff) / 4;
3518 typecode
= (*aclptr
>> 8) & 0xff;
3519 if (typecode
== ACE$C_KEYID
)
3520 for (i
= size
- 1; i
> 1; i
--)
3521 if (aclptr
[i
] == uic
)
3524 if (aclptr
[1] & ACE$M_WRITE
)
3525 return 0; /* Write access through ACL */
3527 aclptr
= &aclptr
[size
];
3529 if (acl_controlled
) /* ACL specified, prohibits write access */
3532 /* No ACL entries specified, check normal protection */
3533 if (WRITEABLE (XAB$V_WLD
)) /* World writeable */
3535 if (WRITEABLE (XAB$V_GRP
) &&
3536 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3537 return 0; /* Group writeable */
3538 if (WRITEABLE (XAB$V_OWN
) &&
3539 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3540 return 0; /* Owner writeable */
3542 return -1; /* Not writeable */
3544 #endif /* not VMS4_4 */
3547 static char vtbuf
[NAM$C_MAXRSS
+1];
3549 /* translate a vms file spec to a unix path */
3551 sys_translate_vms (vfile
)
3562 /* leading device or logical name is a root directory */
3563 if (p
= strchr (vfile
, ':'))
3572 if (*p
== '[' || *p
== '<')
3574 while (*++vfile
!= *p
+ 2)
3578 if (vfile
[-1] == *p
)
3601 static char utbuf
[NAM$C_MAXRSS
+1];
3603 /* translate a unix path to a VMS file spec */
3605 sys_translate_unix (ufile
)
3628 if (index (&ufile
[1], '/'))
3635 if (index (&ufile
[1], '/'))
3642 if (strncmp (ufile
, "./", 2) == 0)
3649 ufile
++; /* skip the dot */
3650 if (index (&ufile
[1], '/'))
3655 else if (strncmp (ufile
, "../", 3) == 0)
3663 ufile
+= 2; /* skip the dots */
3664 if (index (&ufile
[1], '/'))
3689 extern char *getcwd ();
3691 #define MAXPATHLEN 1024
3693 ptr
= xmalloc (MAXPATHLEN
);
3694 val
= getcwd (ptr
, MAXPATHLEN
);
3700 strcpy (pathname
, ptr
);
3708 long item_code
= JPI$_OWNER
;
3709 unsigned long parent_id
;
3712 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
3715 vaxc$errno
= status
;
3725 return (getgid () << 16) | getuid ();
3729 sys_read (fildes
, buf
, nbyte
)
3734 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
3739 sys_write (fildes
, buf
, nbyte
)
3744 register int nwrote
, rtnval
= 0;
3746 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
3752 return rtnval
? rtnval
: -1;
3753 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
3754 return rtnval
? rtnval
: -1;
3755 return (rtnval
+ nwrote
);
3760 * VAX/VMS VAX C RTL really loses. It insists that records
3761 * end with a newline (carriage return) character, and if they
3762 * don't it adds one (nice of it isn't it!)
3764 * Thus we do this stupidity below.
3768 sys_write (fildes
, buf
, nbytes
)
3771 unsigned int nbytes
;
3778 fstat (fildes
, &st
);
3784 /* Handle fixed-length files with carriage control. */
3785 if (st
.st_fab_rfm
== FAB$C_FIX
3786 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
3788 len
= st
.st_fab_mrs
;
3789 retval
= write (fildes
, p
, min (len
, nbytes
));
3792 retval
++; /* This skips the implied carriage control */
3796 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3797 while (*e
!= '\n' && e
> p
) e
--;
3798 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
3799 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3801 retval
= write (fildes
, p
, len
);
3812 /* Create file NEW copying its attributes from file OLD. If
3813 OLD is 0 or does not exist, create based on the value of
3816 /* Protection value the file should ultimately have.
3817 Set by create_copy_attrs, and use by rename_sansversions. */
3818 static unsigned short int fab_final_pro
;
3821 creat_copy_attrs (old
, new)
3824 struct FAB fab
= cc$rms_fab
;
3825 struct XABPRO xabpro
;
3826 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
3827 extern int vms_stmlf_recfm
;
3831 fab
.fab$b_fac
= FAB$M_GET
;
3832 fab
.fab$l_fna
= old
;
3833 fab
.fab$b_fns
= strlen (old
);
3834 fab
.fab$l_xab
= (char *) &xabpro
;
3835 xabpro
= cc$rms_xabpro
;
3836 xabpro
.xab$l_aclbuf
= aclbuf
;
3837 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
3838 /* Call $OPEN to fill in the fab & xabpro fields. */
3839 if (SYS$
OPEN (&fab
, 0, 0) & 1)
3841 SYS$
CLOSE (&fab
, 0, 0);
3842 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
3843 if (xabpro
.xab$w_acllen
> 0)
3845 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
3846 /* If the acl buffer was too short, redo open with longer one.
3847 Wouldn't need to do this if there were some system imposed
3848 limit on the size of an ACL, but I can't find any such. */
3850 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
3851 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
3852 if (SYS$
OPEN (&fab
, 0, 0) & 1)
3853 SYS$
CLOSE (&fab
, 0, 0);
3859 xabpro
.xab$l_aclbuf
= 0;
3864 fab
.fab$l_fna
= new;
3865 fab
.fab$b_fns
= strlen (new);
3869 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
3870 fab
.fab$b_rat
= FAB$M_CR
;
3873 /* Set the file protections such that we will be able to manipulate
3874 this file. Once we are done writing and renaming it, we will set
3875 the protections back. */
3877 fab_final_pro
= xabpro
.xab$w_pro
;
3879 SYS$
SETDFPROT (0, &fab_final_pro
);
3880 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
3882 /* Create the new file with either default attrs or attrs copied
3884 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
3886 SYS$
CLOSE (&fab
, 0, 0);
3887 /* As this is a "replacement" for creat, return a file descriptor
3888 opened for writing. */
3889 return open (new, O_WRONLY
);
3894 #include <varargs.h>
3897 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
3901 sys_creat (va_alist
)
3904 va_list list_incrementer
;
3907 int rfd
; /* related file descriptor */
3908 int fd
; /* Our new file descriptor */
3915 extern int vms_stmlf_recfm
;
3918 va_start (list_incrementer
);
3919 name
= va_arg (list_incrementer
, char *);
3920 mode
= va_arg (list_incrementer
, int);
3922 rfd
= va_arg (list_incrementer
, int);
3923 va_end (list_incrementer
);
3926 /* Use information from the related file descriptor to set record
3927 format of the newly created file. */
3928 fstat (rfd
, &st_buf
);
3929 switch (st_buf
.st_fab_rfm
)
3932 strcpy (rfm
, "rfm = fix");
3933 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
3934 strcpy (rat
, "rat = ");
3935 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3937 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3938 strcat (rat
, "ftn");
3939 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3940 strcat (rat
, "prn");
3941 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3942 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3943 strcat (rat
, ", blk");
3945 strcat (rat
, "blk");
3946 return creat (name
, 0, rfm
, rat
, mrs
);
3949 strcpy (rfm
, "rfm = vfc");
3950 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
3951 strcpy (rat
, "rat = ");
3952 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3954 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3955 strcat (rat
, "ftn");
3956 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3957 strcat (rat
, "prn");
3958 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3959 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3960 strcat (rat
, ", blk");
3962 strcat (rat
, "blk");
3963 return creat (name
, 0, rfm
, rat
, fsz
);
3966 strcpy (rfm
, "rfm = stm");
3970 strcpy (rfm
, "rfm = stmcr");
3974 strcpy (rfm
, "rfm = stmlf");
3978 strcpy (rfm
, "rfm = udf");
3982 strcpy (rfm
, "rfm = var");
3985 strcpy (rat
, "rat = ");
3986 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3988 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3989 strcat (rat
, "ftn");
3990 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3991 strcat (rat
, "prn");
3992 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3993 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3994 strcat (rat
, ", blk");
3996 strcat (rat
, "blk");
4000 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4001 strcpy (rat
, "rat=cr");
4003 /* Until the VAX C RTL fixes the many bugs with modes, always use
4004 mode 0 to get the user's default protection. */
4005 fd
= creat (name
, 0, rfm
, rat
);
4006 if (fd
< 0 && errno
== EEXIST
)
4008 if (unlink (name
) < 0)
4009 report_file_error ("delete", build_string (name
));
4010 fd
= creat (name
, 0, rfm
, rat
);
4016 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4017 sys_fwrite (ptr
, size
, num
, fp
)
4018 register char * ptr
;
4021 register int tot
= num
* size
;
4028 * The VMS C library routine creat actually creates a new version of an
4029 * existing file rather than truncating the old version. There are times
4030 * when this is not the desired behavior, for instance, when writing an
4031 * auto save file (you only want one version), or when you don't have
4032 * write permission in the directory containing the file (but the file
4033 * itself is writable). Hence this routine, which is equivalent to
4034 * "close (creat (fn, 0));" on Unix if fn already exists.
4040 struct FAB xfab
= cc$rms_fab
;
4041 struct RAB xrab
= cc$rms_rab
;
4044 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4045 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4046 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4047 xfab
.fab$l_fna
= fn
;
4048 xfab
.fab$b_fns
= strlen (fn
);
4049 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4051 xrab
.rab$l_fab
= &xfab
;
4053 /* This gibberish opens the file, positions to the first record, and
4054 deletes all records from there until the end of file. */
4055 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4057 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4058 (SYS$
FIND (&xrab
) & 01) == 01 &&
4059 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4070 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4071 SYSPRV or a readable SYSUAF.DAT. */
4077 * Routine to read the VMS User Authorization File and return
4078 * a specific user's record.
4081 static struct UAF retuaf
;
4084 get_uaf_name (uname
)
4091 uaf_fab
= cc$rms_fab
;
4092 uaf_rab
= cc$rms_rab
;
4093 /* initialize fab fields */
4094 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4095 uaf_fab
.fab$b_fns
= 21;
4096 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4097 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4098 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4099 /* initialize rab fields */
4100 uaf_rab
.rab$l_fab
= &uaf_fab
;
4101 /* open the User Authorization File */
4102 status
= SYS$
OPEN (&uaf_fab
);
4106 vaxc$errno
= status
;
4109 status
= SYS$
CONNECT (&uaf_rab
);
4113 vaxc$errno
= status
;
4116 /* read the requested record - index is in uname */
4117 uaf_rab
.rab$l_kbf
= uname
;
4118 uaf_rab
.rab$b_ksz
= strlen (uname
);
4119 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4120 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4121 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4122 status
= SYS$
GET (&uaf_rab
);
4126 vaxc$errno
= status
;
4129 /* close the User Authorization File */
4130 status
= SYS$
DISCONNECT (&uaf_rab
);
4134 vaxc$errno
= status
;
4137 status
= SYS$
CLOSE (&uaf_fab
);
4141 vaxc$errno
= status
;
4155 uaf_fab
= cc$rms_fab
;
4156 uaf_rab
= cc$rms_rab
;
4157 /* initialize fab fields */
4158 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4159 uaf_fab
.fab$b_fns
= 21;
4160 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4161 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4162 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4163 /* initialize rab fields */
4164 uaf_rab
.rab$l_fab
= &uaf_fab
;
4165 /* open the User Authorization File */
4166 status
= SYS$
OPEN (&uaf_fab
);
4170 vaxc$errno
= status
;
4173 status
= SYS$
CONNECT (&uaf_rab
);
4177 vaxc$errno
= status
;
4180 /* read the requested record - index is in uic */
4181 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4182 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4183 uaf_rab
.rab$b_ksz
= sizeof uic
;
4184 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4185 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4186 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4187 status
= SYS$
GET (&uaf_rab
);
4191 vaxc$errno
= status
;
4194 /* close the User Authorization File */
4195 status
= SYS$
DISCONNECT (&uaf_rab
);
4199 vaxc$errno
= status
;
4202 status
= SYS$
CLOSE (&uaf_fab
);
4206 vaxc$errno
= status
;
4212 static struct passwd retpw
;
4220 /* copy these out first because if the username is 32 chars, the next
4221 section will overwrite the first byte of the UIC */
4222 retpw
.pw_uid
= up
->uaf$w_mem
;
4223 retpw
.pw_gid
= up
->uaf$w_grp
;
4225 /* I suppose this is not the best sytle, to possibly overwrite one
4226 byte beyond the end of the field, but what the heck... */
4227 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4228 while (ptr
[-1] == ' ')
4231 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4233 /* the rest of these are counted ascii strings */
4234 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4235 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4236 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4237 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4238 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4239 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4240 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4241 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4245 #else /* not READ_SYSUAF */
4246 static struct passwd retpw
;
4247 #endif /* not READ_SYSUAF */
4258 unsigned char * full
;
4259 #endif /* READ_SYSUAF */
4264 if ('a' <= *ptr
&& *ptr
<= 'z')
4269 if (!(up
= get_uaf_name (name
)))
4271 return cnv_uaf_pw (up
);
4273 if (strcmp (name
, getenv ("USER")) == 0)
4275 retpw
.pw_uid
= getuid ();
4276 retpw
.pw_gid
= getgid ();
4277 strcpy (retpw
.pw_name
, name
);
4278 if (full
= egetenv ("FULLNAME"))
4279 strcpy (retpw
.pw_gecos
, full
);
4281 *retpw
.pw_gecos
= '\0';
4282 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4283 *retpw
.pw_shell
= '\0';
4288 #endif /* not READ_SYSUAF */
4298 if (!(up
= get_uaf_uic (uid
)))
4300 return cnv_uaf_pw (up
);
4302 if (uid
== sys_getuid ())
4303 return getpwnam (egetenv ("USER"));
4306 #endif /* not READ_SYSUAF */
4309 /* return total address space available to the current process. This is
4310 the sum of the current p0 size, p1 size and free page table entries
4315 unsigned long free_pages
;
4316 unsigned long frep0va
;
4317 unsigned long frep1va
;
4320 item_code
= JPI$_FREPTECNT
;
4321 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4324 vaxc$errno
= status
;
4329 item_code
= JPI$_FREP0VA
;
4330 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4333 vaxc$errno
= status
;
4336 item_code
= JPI$_FREP1VA
;
4337 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4340 vaxc$errno
= status
;
4344 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4347 define_logical_name (varname
, string
)
4351 struct dsc$descriptor_s strdsc
=
4352 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4353 struct dsc$descriptor_s envdsc
=
4354 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4355 struct dsc$descriptor_s lnmdsc
=
4356 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4358 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4361 delete_logical_name (varname
)
4364 struct dsc$descriptor_s envdsc
=
4365 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4366 struct dsc$descriptor_s lnmdsc
=
4367 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4369 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4380 error ("execvp system call not implemented");
4388 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4389 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4390 char from_esn
[NAM$C_MAXRSS
];
4391 char to_esn
[NAM$C_MAXRSS
];
4393 from_fab
.fab$l_fna
= from
;
4394 from_fab
.fab$b_fns
= strlen (from
);
4395 from_fab
.fab$l_nam
= &from_nam
;
4396 from_fab
.fab$l_fop
= FAB$M_NAM
;
4398 from_nam
.nam$l_esa
= from_esn
;
4399 from_nam
.nam$b_ess
= sizeof from_esn
;
4401 to_fab
.fab$l_fna
= to
;
4402 to_fab
.fab$b_fns
= strlen (to
);
4403 to_fab
.fab$l_nam
= &to_nam
;
4404 to_fab
.fab$l_fop
= FAB$M_NAM
;
4406 to_nam
.nam$l_esa
= to_esn
;
4407 to_nam
.nam$b_ess
= sizeof to_esn
;
4409 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4415 if (status
== RMS$_DEV
)
4419 vaxc$errno
= status
;
4424 /* This function renames a file like `rename', but it strips
4425 the version number from the "to" filename, such that the "to" file is
4426 will always be a new version. It also sets the file protection once it is
4427 finished. The protection that we will use is stored in fab_final_pro,
4428 and was set when we did a creat_copy_attrs to create the file that we
4431 We could use the chmod function, but Eunichs uses 3 bits per user category
4432 to describe the protection, and VMS uses 4 (write and delete are separate
4433 bits). To maintain portability, the VMS implementation of `chmod' wires
4434 the W and D bits together. */
4437 static struct fibdef fib
; /* We need this initialized to zero */
4438 char vms_file_written
[NAM$C_MAXRSS
];
4441 rename_sans_version (from
,to
)
4448 struct FAB to_fab
= cc$rms_fab
;
4449 struct NAM to_nam
= cc$rms_nam
;
4450 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4451 struct dsc$descriptor fib_attr
[2]
4452 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4453 char to_esn
[NAM$C_MAXRSS
];
4455 $
DESCRIPTOR (disk
,to_esn
);
4457 to_fab
.fab$l_fna
= to
;
4458 to_fab
.fab$b_fns
= strlen (to
);
4459 to_fab
.fab$l_nam
= &to_nam
;
4460 to_fab
.fab$l_fop
= FAB$M_NAM
;
4462 to_nam
.nam$l_esa
= to_esn
;
4463 to_nam
.nam$b_ess
= sizeof to_esn
;
4465 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4467 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4468 *(to_nam
.nam$l_ver
) = '\0';
4470 stat
= rename (from
, to_esn
);
4474 strcpy (vms_file_written
, to_esn
);
4476 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4477 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4479 /* Now set the file protection to the correct value */
4480 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4482 /* Copy these fields into the fib */
4483 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4484 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4485 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4487 SYS$
CLOSE (&to_fab
, 0, 0);
4489 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4492 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4493 0, 0, 0, &fib_attr
, 0);
4496 stat
= SYS$
DASSGN (chan
);
4499 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4509 unsigned short fid
[3];
4510 char esa
[NAM$C_MAXRSS
];
4513 fab
.fab$l_fop
= FAB$M_OFP
;
4514 fab
.fab$l_fna
= file
;
4515 fab
.fab$b_fns
= strlen (file
);
4516 fab
.fab$l_nam
= &nam
;
4519 nam
.nam$l_esa
= esa
;
4520 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4522 status
= SYS$
PARSE (&fab
);
4523 if ((status
& 1) == 0)
4526 vaxc$errno
= status
;
4529 status
= SYS$
SEARCH (&fab
);
4530 if ((status
& 1) == 0)
4533 vaxc$errno
= status
;
4537 fid
[0] = nam
.nam$w_fid
[0];
4538 fid
[1] = nam
.nam$w_fid
[1];
4539 fid
[2] = nam
.nam$w_fid
[2];
4541 fab
.fab$l_fna
= new;
4542 fab
.fab$b_fns
= strlen (new);
4544 status
= SYS$
PARSE (&fab
);
4545 if ((status
& 1) == 0)
4548 vaxc$errno
= status
;
4552 nam
.nam$w_fid
[0] = fid
[0];
4553 nam
.nam$w_fid
[1] = fid
[1];
4554 nam
.nam$w_fid
[2] = fid
[2];
4556 nam
.nam$l_esa
= nam
.nam$l_name
;
4557 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
4559 status
= SYS$
ENTER (&fab
);
4560 if ((status
& 1) == 0)
4563 vaxc$errno
= status
;
4573 printf ("%s not yet implemented\r\n", badfunc
);
4581 /* Arrange to return a range centered on zero. */
4582 return rand () - (1 << 30);
4593 /* Called from init_sys_modes. */
4598 /* If we're not on an HFT we shouldn't do any of this. We determine
4599 if we are on an HFT by trying to get an HFT error code. If this
4600 call fails, we're not on an HFT. */
4602 if (ioctl (0, HFQERROR
, &junk
) < 0)
4604 #else /* not IBMR2AIX */
4605 if (ioctl (0, HFQEIO
, 0) < 0)
4607 #endif /* not IBMR2AIX */
4609 /* On AIX the default hft keyboard mapping uses backspace rather than delete
4610 as the rubout key's ASCII code. Here this is changed. The bug is that
4611 there's no way to determine the old mapping, so in reset_sys_modes
4612 we need to assume that the normal map had been present. Of course, this
4613 code also doesn't help if on a terminal emulator which doesn't understand
4617 struct hfkeymap keymap
;
4619 buf
.hf_bufp
= (char *)&keymap
;
4620 buf
.hf_buflen
= sizeof (keymap
);
4621 keymap
.hf_nkeys
= 2;
4622 keymap
.hfkey
[0].hf_kpos
= 15;
4623 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4625 keymap
.hfkey
[0].hf_keyidh
= '<';
4626 #else /* not IBMR2AIX */
4627 keymap
.hfkey
[0].hf_page
= '<';
4628 #endif /* not IBMR2AIX */
4629 keymap
.hfkey
[0].hf_char
= 127;
4630 keymap
.hfkey
[1].hf_kpos
= 15;
4631 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4633 keymap
.hfkey
[1].hf_keyidh
= '<';
4634 #else /* not IBMR2AIX */
4635 keymap
.hfkey
[1].hf_page
= '<';
4636 #endif /* not IBMR2AIX */
4637 keymap
.hfkey
[1].hf_char
= 127;
4638 hftctl (0, HFSKBD
, &buf
);
4640 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
4642 line_ins_del_ok
= char_ins_del_ok
= 0;
4645 /* Reset the rubout key to backspace. */
4650 struct hfkeymap keymap
;
4654 if (ioctl (0, HFQERROR
, &junk
) < 0)
4656 #else /* not IBMR2AIX */
4657 if (ioctl (0, HFQEIO
, 0) < 0)
4659 #endif /* not IBMR2AIX */
4661 buf
.hf_bufp
= (char *)&keymap
;
4662 buf
.hf_buflen
= sizeof (keymap
);
4663 keymap
.hf_nkeys
= 2;
4664 keymap
.hfkey
[0].hf_kpos
= 15;
4665 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4667 keymap
.hfkey
[0].hf_keyidh
= '<';
4668 #else /* not IBMR2AIX */
4669 keymap
.hfkey
[0].hf_page
= '<';
4670 #endif /* not IBMR2AIX */
4671 keymap
.hfkey
[0].hf_char
= 8;
4672 keymap
.hfkey
[1].hf_kpos
= 15;
4673 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4675 keymap
.hfkey
[1].hf_keyidh
= '<';
4676 #else /* not IBMR2AIX */
4677 keymap
.hfkey
[1].hf_page
= '<';
4678 #endif /* not IBMR2AIX */
4679 keymap
.hfkey
[1].hf_char
= 8;
4680 hftctl (0, HFSKBD
, &buf
);