1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 86,87,88,93,94,95, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 /* Including stdlib.h isn't necessarily enough to get srandom
31 declared, e.g. without __USE_XOPEN_EXTENDED with glibc 2. */
33 extern long int random
P_ ((void));
34 #if 0 /* Don't prototype srandom; it takes an unsigned argument on
35 some systems, and an unsigned long on others, like FreeBSD
37 extern void srandom
P_ ((unsigned int));
41 #include "blockinput.h"
45 /* It is essential to include stdlib.h so that this file picks up
46 the correct definitions of rand, srand, and RAND_MAX.
47 Otherwise random numbers will not work correctly. */
51 /* Nonzero means delete a process right away if it exits (process.c). */
52 static int delete_exited_processes
;
54 #endif /* macintosh */
56 #define min(x,y) ((x) > (y) ? (y) : (x))
60 #define write sys_write
65 #endif /* not WINDOWSNT */
67 /* Does anyone other than VMS need this? */
69 #define sys_fwrite fwrite
75 #include <sys/types.h>
79 /* Get _POSIX_VDISABLE, if it is available. */
89 #if !defined (USG) || defined (BSD_PGRPS)
91 #define setpgrp setpgid
95 /* Get SI_SRPC_DOMAIN, if it is available. */
96 #ifdef HAVE_SYS_SYSTEMINFO_H
97 #include <sys/systeminfo.h>
100 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
104 #include <sys/param.h>
108 extern unsigned start
__asm__ ("start");
130 #include <sys/file.h>
138 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
142 #ifdef BSD_SYSTEM /* avoid writing defined (BSD_SYSTEM) || defined (USG)
143 because the vms compiler doesn't grok `defined' */
151 #endif /* not 4.1 bsd */
154 #include <sys/ioctl.h>
160 #ifdef BROKEN_TIOCGWINSZ
165 #if defined (USG) || defined (DGUX)
166 #include <sys/utsname.h>
167 #ifndef MEMORY_IN_STRING_H
170 #if defined (TIOCGWINSZ) || defined (ISC4_0)
172 #include <sys/sioctl.h>
175 #include <sys/stream.h>
176 #include <sys/ptem.h>
178 #endif /* TIOCGWINSZ or ISC4_0 */
179 #endif /* USG or DGUX */
181 extern int quit_char
;
183 #include "keyboard.h"
186 #include "termhooks.h"
187 #include "termchar.h"
188 #include "termopts.h"
189 #include "dispextern.h"
194 /* In process.h which conflicts with the local copy. */
196 int _CRTAPI1
_spawnlp (int, const char *, const char *, ...);
197 int _CRTAPI1
_getpid (void);
200 #ifdef NONSYSTEM_DIR_LIBRARY
202 #endif /* NONSYSTEM_DIR_LIBRARY */
204 #include "syssignal.h"
211 #ifndef HAVE_STRUCT_UTIMBUF
212 /* We want to use utime rather than utimes, but we couldn't find the
213 structure declaration. We'll use the traditional one. */
221 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
227 #define LNOFLSH 0100000
230 static int baud_convert
[] =
235 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
236 1800, 2400, 4800, 9600, 19200, 38400
243 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
245 #if defined (HAVE_TERMIOS_H) && defined (LINUX)
253 /* The file descriptor for Emacs's input terminal.
254 Under Unix, this is normally zero except when using X;
255 under VMS, we place the input channel number here. */
258 void croak
P_ ((char *));
265 /* Temporary used by `sigblock' when defined in terms of signprocmask. */
267 SIGMASKTYPE sigprocmask_set
;
270 /* Specify a different file descriptor for further input operations. */
279 /* Discard pending input on descriptor input_fd. */
285 struct emacs_tty buf
;
290 /* Discarding input is not safe when the input could contain
291 replies from the X server. So don't do it. */
292 if (read_socket_hook
)
297 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
298 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
304 ioctl (input_fd
, TIOCFLUSH
, &zero
);
306 #else /* not Apollo */
307 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
308 while (dos_keyread () != -1)
310 #else /* not MSDOS */
311 EMACS_GET_TTY (input_fd
, &buf
);
312 EMACS_SET_TTY (input_fd
, &buf
, 0);
313 #endif /* not MSDOS */
314 #endif /* not Apollo */
316 #endif /* not WINDOWSNT */
321 /* Arrange for character C to be read as the next input from
328 if (read_socket_hook
)
331 /* Should perhaps error if in batch mode */
333 ioctl (input_fd
, TIOCSTI
, &c
);
334 #else /* no TIOCSTI */
335 error ("Cannot stuff terminal input characters in this version of Unix");
336 #endif /* no TIOCSTI */
348 #ifdef INIT_BAUD_RATE
353 #else /* not DOS_NT */
357 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
358 &sg
.class, 12, 0, 0, 0, 0 );
359 emacs_ospeed
= sg
.xmit_baud
;
365 tcgetattr (input_fd
, &sg
);
366 emacs_ospeed
= cfgetospeed (&sg
);
367 #if defined (USE_GETOBAUD) && defined (getobaud)
368 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
369 if (emacs_ospeed
== 0)
370 emacs_ospeed
= getobaud (sg
.c_cflag
);
372 #else /* neither VMS nor TERMIOS */
378 tcgetattr (input_fd
, &sg
);
380 ioctl (input_fd
, TCGETA
, &sg
);
382 emacs_ospeed
= sg
.c_cflag
& CBAUD
;
383 #else /* neither VMS nor TERMIOS nor TERMIO */
386 sg
.sg_ospeed
= B9600
;
387 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
389 emacs_ospeed
= sg
.sg_ospeed
;
390 #endif /* not HAVE_TERMIO */
391 #endif /* not HAVE_TERMIOS */
393 #endif /* not DOS_NT */
394 #endif /* not INIT_BAUD_RATE */
397 baud_rate
= (emacs_ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
398 ? baud_convert
[emacs_ospeed
] : 9600);
405 set_exclusive_use (fd
)
409 ioctl (fd
, FIOCLEX
, 0);
411 /* Ok to do nothing if this feature does not exist */
416 wait_without_blocking ()
419 wait3 (0, WNOHANG
| WUNTRACED
, 0);
421 croak ("wait_without_blocking");
423 synch_process_alive
= 0;
426 #endif /* not subprocesses */
428 int wait_debugging
; /* Set nonzero to make following function work under dbx
429 (at least for bsd). */
432 wait_for_termination_signal ()
435 /* Wait for subprocess with process id `pid' to terminate and
436 make sure it will get eliminated (not remain forever as a zombie) */
439 wait_for_termination (pid
)
448 status
= SYS$
FORCEX (&pid
, 0, 0);
451 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
452 /* Note that kill returns -1 even if the process is just a zombie now.
453 But inevitably a SIGCHLD interrupt should be generated
454 and child_sig will do wait3 and make the process go away. */
455 /* There is some indication that there is a bug involved with
456 termination of subprocesses, perhaps involving a kernel bug too,
457 but no idea what it is. Just as a hunch we signal SIGCHLD to see
458 if that causes the problem to go away or get worse. */
459 sigsetmask (sigmask (SIGCHLD
));
460 if (0 > kill (pid
, 0))
462 sigsetmask (SIGEMPTYMASK
);
463 kill (getpid (), SIGCHLD
);
469 sigpause (SIGEMPTYMASK
);
470 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
471 #if defined (UNIPLUS)
472 if (0 > kill (pid
, 0))
475 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
476 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
477 sigblock (sigmask (SIGCHLD
));
478 if (0 > kill (pid
, 0))
480 sigunblock (sigmask (SIGCHLD
));
483 sigpause (SIGEMPTYMASK
);
484 #else /* not POSIX_SIGNALS */
485 #ifdef HAVE_SYSV_SIGPAUSE
487 if (0 > kill (pid
, 0))
493 #else /* not HAVE_SYSV_SIGPAUSE */
497 #else /* not WINDOWSNT */
498 if (0 > kill (pid
, 0))
500 /* Using sleep instead of pause avoids timing error.
501 If the inferior dies just before the sleep,
502 we lose just one second. */
504 #endif /* not WINDOWSNT */
505 #endif /* not HAVE_SYSV_SIGPAUSE */
506 #endif /* not POSIX_SIGNALS */
507 #endif /* not UNIPLUS */
508 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
510 #else /* not subprocesses */
513 #else /* not __DJGPP__ > 1 */
515 if (kill (pid
, 0) < 0)
521 if (status
== pid
|| status
== -1)
524 #endif /* not __DJGPP__ > 1*/
525 #endif /* not subprocesses */
532 * flush any pending output
533 * (may flush input as well; it does not matter the way we use it)
537 flush_pending_output (channel
)
541 /* If we try this, we get hit with SIGTTIN, because
542 the child's tty belongs to the child's pgrp. */
545 ioctl (channel
, TCFLSH
, 1);
549 /* 3rd arg should be ignored
550 but some 4.2 kernels actually want the address of an int
551 and nonzero means something different. */
552 ioctl (channel
, TIOCFLUSH
, &zero
);
559 /* Set up the terminal at the other end of a pseudo-terminal that
560 we will be controlling an inferior through.
561 It should not echo or do line-editing, since that is done
562 in Emacs. No padding needed for insertion into an Emacs buffer. */
565 child_setup_tty (out
)
571 EMACS_GET_TTY (out
, &s
);
573 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
574 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
575 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
577 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
578 /* No output delays */
580 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
581 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
583 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
586 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
589 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
591 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
592 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
594 /* Said to be unnecessary: */
595 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
596 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
599 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
600 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
601 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
602 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
605 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
609 /* AIX enhanced edit loses NULs, so disable it */
612 s
.main
.c_iflag
&= ~ASCEDIT
;
614 /* Also, PTY overloads NUL and BREAK.
615 don't ignore break, but don't signal either, so it looks like NUL. */
616 s
.main
.c_iflag
&= ~IGNBRK
;
617 s
.main
.c_iflag
&= ~BRKINT
;
618 /* QUIT and INTR work better as signals, so disable character forms */
619 s
.main
.c_cc
[VINTR
] = 0377;
620 #ifdef SIGNALS_VIA_CHARACTERS
621 /* the QUIT and INTR character are used in process_send_signal
622 so set them here to something useful. */
623 if (s
.main
.c_cc
[VQUIT
] == 0377)
624 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
625 if (s
.main
.c_cc
[VINTR
] == 0377)
626 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
627 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
628 /* QUIT and INTR work better as signals, so disable character forms */
629 s
.main
.c_cc
[VQUIT
] = 0377;
630 s
.main
.c_cc
[VINTR
] = 0377;
631 s
.main
.c_lflag
&= ~ISIG
;
632 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
633 s
.main
.c_cc
[VEOL
] = 0377;
634 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
637 #else /* not HAVE_TERMIO */
639 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
641 s
.main
.sg_flags
|= LPASS8
;
642 s
.main
.sg_erase
= 0377;
643 s
.main
.sg_kill
= 0377;
644 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
646 #endif /* not HAVE_TERMIO */
648 EMACS_SET_TTY (out
, &s
, 0);
657 ioctl (out
, FIOASYNC
, &zero
);
660 #endif /* not DOS_NT */
664 #endif /* subprocesses */
666 /* Record a signal code and the handler for it. */
670 SIGTYPE (*handler
) P_ ((int));
673 static void save_signal_handlers
P_ ((struct save_signal
*));
674 static void restore_signal_handlers
P_ ((struct save_signal
*));
676 /* Suspend the Emacs process; give terminal to its superior. */
682 /* "Foster" parentage allows emacs to return to a subprocess that attached
683 to the current emacs as a cheaper than starting a whole new process. This
684 is set up by KEPTEDITOR.COM. */
685 unsigned long parent_id
, foster_parent_id
;
688 fpid_string
= getenv ("EMACS_PARENT_PID");
689 if (fpid_string
!= NULL
)
691 sscanf (fpid_string
, "%x", &foster_parent_id
);
692 if (foster_parent_id
!= 0)
693 parent_id
= foster_parent_id
;
695 parent_id
= getppid ();
698 parent_id
= getppid ();
700 xfree (fpid_string
); /* On VMS, this was malloc'd */
702 if (parent_id
&& parent_id
!= 0xffffffff)
704 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
705 int status
= LIB$
ATTACH (&parent_id
) & 1;
706 signal (SIGINT
, oldsig
);
715 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
716 d_prompt
.a
= "Emacs: "; /* Just a reminder */
717 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
722 #if defined (SIGTSTP) && !defined (MSDOS)
725 int pgrp
= EMACS_GETPGRP (0);
726 EMACS_KILLPG (pgrp
, SIGTSTP
);
729 #else /* No SIGTSTP */
730 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
731 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
732 kill (getpid (), SIGQUIT
);
734 #else /* No SIGTSTP or USG_JOBCTRL */
736 /* On a system where suspending is not implemented,
737 instead fork a subshell and let it talk directly to the terminal
741 #endif /* no USG_JOBCTRL */
742 #endif /* no SIGTSTP */
746 /* Fork a subshell. */
753 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
755 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
758 struct save_signal saved_handlers
[5];
760 unsigned char *str
= 0;
763 saved_handlers
[0].code
= SIGINT
;
764 saved_handlers
[1].code
= SIGQUIT
;
765 saved_handlers
[2].code
= SIGTERM
;
767 saved_handlers
[3].code
= SIGIO
;
768 saved_handlers
[4].code
= 0;
770 saved_handlers
[3].code
= 0;
773 /* Mentioning current_buffer->buffer would mean including buffer.h,
774 which somehow wedges the hp compiler. So instead... */
776 dir
= intern ("default-directory");
777 if (NILP (Fboundp (dir
)))
779 dir
= Fsymbol_value (dir
);
783 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
784 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
785 len
= XSTRING (dir
)->size
;
786 bcopy (XSTRING (dir
)->data
, str
, len
);
787 if (str
[len
- 1] != '/') str
[len
++] = '/';
794 save_signal_handlers (saved_handlers
);
795 synch_process_alive
= 1;
796 #endif /* __DJGPP__ > 1 */
800 error ("Can't spawn subshell");
807 #ifdef DOS_NT /* MW, Aug 1993 */
810 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
813 sh
= (char *) egetenv ("SHELL");
817 /* Use our buffer's default directory for the subshell. */
819 chdir ((char *) str
);
822 close_process_descs (); /* Close Emacs's pipes/ptys */
825 #ifdef SET_EMACS_PRIORITY
827 extern int emacs_priority
;
829 if (emacs_priority
< 0)
830 nice (-emacs_priority
);
834 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
837 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
839 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
841 #else /* not MSDOS */
843 /* Waits for process completion */
844 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
847 write (1, "Can't execute subshell", 22);
848 #else /* not WINDOWSNT */
850 write (1, "Can't execute subshell", 22);
852 #endif /* not WINDOWSNT */
853 #endif /* not MSDOS */
856 /* Do this now if we did not do it before. */
857 #if !defined (MSDOS) || __DJGPP__ == 1
858 save_signal_handlers (saved_handlers
);
859 synch_process_alive
= 1;
863 wait_for_termination (pid
);
865 restore_signal_handlers (saved_handlers
);
866 synch_process_alive
= 0;
869 #endif /* !macintosh */
872 save_signal_handlers (saved_handlers
)
873 struct save_signal
*saved_handlers
;
875 while (saved_handlers
->code
)
877 saved_handlers
->handler
878 = (SIGTYPE (*) P_ ((int))) signal (saved_handlers
->code
, SIG_IGN
);
884 restore_signal_handlers (saved_handlers
)
885 struct save_signal
*saved_handlers
;
887 while (saved_handlers
->code
)
889 signal (saved_handlers
->code
, saved_handlers
->handler
);
903 old_fcntl_flags
= fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
904 fcntl (fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
906 interrupts_deferred
= 0;
915 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
920 if (read_socket_hook
)
924 sigunblock (sigmask (SIGWINCH
));
926 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
928 interrupts_deferred
= 0;
934 if (read_socket_hook
)
938 sigblock (sigmask (SIGWINCH
));
940 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
941 interrupts_deferred
= 1;
944 #else /* no FASYNC */
945 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
952 if (read_socket_hook
)
955 ioctl (input_fd
, FIOASYNC
, &on
);
956 interrupts_deferred
= 0;
964 if (read_socket_hook
)
967 ioctl (input_fd
, FIOASYNC
, &off
);
968 interrupts_deferred
= 1;
971 #else /* not FASYNC, not STRIDE */
983 if (read_socket_hook
)
987 sigaddset (&st
, SIGIO
);
988 ioctl (input_fd
, FIOASYNC
, &on
);
989 interrupts_deferred
= 0;
990 sigprocmask (SIG_UNBLOCK
, &st
, (sigset_t
*)0);
998 if (read_socket_hook
)
1001 ioctl (input_fd
, FIOASYNC
, &off
);
1002 interrupts_deferred
= 1;
1005 #else /* ! _CX_UX */
1010 if (read_socket_hook
)
1013 croak ("request_sigio");
1019 if (read_socket_hook
)
1022 croak ("unrequest_sigio");
1028 #endif /* F_SETFL */
1030 /* Saving and restoring the process group of Emacs's terminal. */
1034 /* The process group of which Emacs was a member when it initially
1037 If Emacs was in its own process group (i.e. inherited_pgroup ==
1038 getpid ()), then we know we're running under a shell with job
1039 control (Emacs would never be run as part of a pipeline).
1042 If Emacs was not in its own process group, then we know we're
1043 running under a shell (or a caller) that doesn't know how to
1044 separate itself from Emacs (like sh). Emacs must be in its own
1045 process group in order to receive SIGIO correctly. In this
1046 situation, we put ourselves in our own pgroup, forcibly set the
1047 tty's pgroup to our pgroup, and make sure to restore and reinstate
1048 the tty's pgroup just like any other terminal setting. If
1049 inherited_group was not the tty's pgroup, then we'll get a
1050 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1051 it goes foreground in the future, which is what should happen. */
1052 int inherited_pgroup
;
1054 /* Split off the foreground process group to Emacs alone.
1055 When we are in the foreground, but not started in our own process
1056 group, redirect the TTY to point to our own process group. We need
1057 to be in our own process group to receive SIGIO properly. */
1059 narrow_foreground_group ()
1063 setpgrp (0, inherited_pgroup
);
1064 if (inherited_pgroup
!= me
)
1065 EMACS_SET_TTY_PGRP (input_fd
, &me
);
1069 /* Set the tty to our original foreground group. */
1071 widen_foreground_group ()
1073 if (inherited_pgroup
!= getpid ())
1074 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
1075 setpgrp (0, inherited_pgroup
);
1078 #endif /* BSD_PGRPS */
1080 /* Getting and setting emacs_tty structures. */
1082 /* Set *TC to the parameters associated with the terminal FD.
1083 Return zero if all's well, or -1 if we ran into an error we
1084 couldn't deal with. */
1086 emacs_get_tty (fd
, settings
)
1088 struct emacs_tty
*settings
;
1090 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1092 /* We have those nifty POSIX tcmumbleattr functions. */
1093 bzero (&settings
->main
, sizeof (settings
->main
));
1094 if (tcgetattr (fd
, &settings
->main
) < 0)
1099 /* The SYSV-style interface? */
1100 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1105 /* Vehemently Monstrous System? :-) */
1106 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1107 &settings
->main
.class, 12, 0, 0, 0, 0)
1113 /* I give up - I hope you have the BSD ioctls. */
1114 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1116 #endif /* not DOS_NT */
1121 /* Suivant - Do we have to get struct ltchars data? */
1123 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1127 /* How about a struct tchars and a wordful of lmode bits? */
1129 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1130 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1134 /* We have survived the tempest. */
1139 /* Set the parameters of the tty on FD according to the contents of
1140 *SETTINGS. If FLUSHP is non-zero, we discard input.
1141 Return 0 if all went well, and -1 if anything failed. */
1144 emacs_set_tty (fd
, settings
, flushp
)
1146 struct emacs_tty
*settings
;
1149 /* Set the primary parameters - baud rate, character size, etcetera. */
1152 /* We have those nifty POSIX tcmumbleattr functions.
1153 William J. Smith <wjs@wiis.wang.com> writes:
1154 "POSIX 1003.1 defines tcsetattr to return success if it was
1155 able to perform any of the requested actions, even if some
1156 of the requested actions could not be performed.
1157 We must read settings back to ensure tty setup properly.
1158 AIX requires this to keep tty from hanging occasionally." */
1159 /* This make sure that we don't loop indefinitely in here. */
1160 for (i
= 0 ; i
< 10 ; i
++)
1161 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1172 bzero (&new, sizeof (new));
1173 /* Get the current settings, and see if they're what we asked for. */
1174 tcgetattr (fd
, &new);
1175 /* We cannot use memcmp on the whole structure here because under
1176 * aix386 the termios structure has some reserved field that may
1179 if ( new.c_iflag
== settings
->main
.c_iflag
1180 && new.c_oflag
== settings
->main
.c_oflag
1181 && new.c_cflag
== settings
->main
.c_cflag
1182 && new.c_lflag
== settings
->main
.c_lflag
1183 && memcmp (new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1191 /* The SYSV-style interface? */
1192 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1197 /* Vehemently Monstrous System? :-) */
1198 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1199 &settings
->main
.class, 12, 0, 0, 0, 0)
1205 /* I give up - I hope you have the BSD ioctls. */
1206 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1208 #endif /* not DOS_NT */
1214 /* Suivant - Do we have to get struct ltchars data? */
1216 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1220 /* How about a struct tchars and a wordful of lmode bits? */
1222 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1223 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1227 /* We have survived the tempest. */
1232 /* The initial tty mode bits */
1233 struct emacs_tty old_tty
;
1235 /* 1 if we have been through init_sys_modes. */
1238 /* 1 if outer tty status has been recorded. */
1242 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1247 #ifndef F_SETOWN_BUG
1249 int old_fcntl_owner
;
1250 #endif /* F_SETOWN */
1251 #endif /* F_SETOWN_BUG */
1253 /* This may also be defined in stdio,
1254 but if so, this does no harm,
1255 and using the same name avoids wasting the other one's space. */
1258 extern char *_sobuf
;
1260 #if defined (USG) || defined (DGUX)
1261 unsigned char _sobuf
[BUFSIZ
+8];
1263 char _sobuf
[BUFSIZ
];
1268 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1271 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1277 struct emacs_tty tty
;
1280 /* cus-start.el complains if delete-exited-processes is not defined */
1281 #ifndef subprocesses
1282 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes
,
1283 "*Non-nil means delete processes immediately when they exit.\n\
1284 nil means don't delete them until `list-processes' is run.");
1285 delete_exited_processes
= 0;
1287 #endif /* not macintosh */
1291 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1292 extern int (*interrupt_signal
) ();
1296 Vtty_erase_char
= Qnil
;
1303 input_ef
= get_kbd_event_flag ();
1304 /* LIB$GET_EF (&input_ef); */
1305 SYS$
CLREF (input_ef
);
1306 waiting_for_ast
= 0;
1308 timer_ef
= get_timer_event_flag ();
1309 /* LIB$GET_EF (&timer_ef); */
1310 SYS$
CLREF (timer_ef
);
1314 LIB$
GET_EF (&process_ef
);
1315 SYS$
CLREF (process_ef
);
1317 if (input_ef
/ 32 != process_ef
/ 32)
1318 croak ("Input and process event flags in different clusters.");
1320 if (input_ef
/ 32 != timer_ef
/ 32)
1321 croak ("Input and timer event flags in different clusters.");
1323 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1324 ((unsigned) 1 << (process_ef
% 32));
1326 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1327 ((unsigned) 1 << (timer_ef
% 32));
1329 sys_access_reinit ();
1331 #endif /* not VMS */
1334 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1335 narrow_foreground_group ();
1338 #ifdef HAVE_WINDOW_SYSTEM
1339 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1340 needs the initialization code below. */
1341 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1344 EMACS_GET_TTY (input_fd
, &old_tty
);
1350 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1351 XSETINT (Vtty_erase_char
, old_tty
.main
.c_cc
[VERASE
]);
1354 /* This allows meta to be sent on 8th bit. */
1355 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1357 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1358 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1359 #ifdef INLCR /* I'm just being cautious,
1360 since I can't check how widespread INLCR is--rms. */
1361 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1364 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1366 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1367 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1369 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1371 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1374 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1376 tty
.main
.c_iflag
&= ~IXANY
;
1380 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1381 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1383 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1387 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1388 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1391 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1392 /* Set up C-g for both SIGQUIT and SIGINT.
1393 We don't know which we will get, but we handle both alike
1394 so which one it really gives us does not matter. */
1395 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1396 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1397 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1399 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1403 #if defined (mips) || defined (HAVE_TCATTR)
1405 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1408 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1409 #endif /* V_DSUSP */
1410 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1411 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1414 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1417 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1418 #endif /* VREPRINT */
1420 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1421 #endif /* VWERASE */
1423 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1424 #endif /* VDISCARD */
1429 tty
.main
.c_cc
[VSTART
] = '\021';
1432 tty
.main
.c_cc
[VSTOP
] = '\023';
1438 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1441 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1444 #endif /* mips or HAVE_TCATTR */
1446 #ifdef SET_LINE_DISCIPLINE
1447 /* Need to explicitly request TERMIODISC line discipline or
1448 Ultrix's termios does not work correctly. */
1449 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1453 /* AIX enhanced edit loses NULs, so disable it. */
1454 tty
.main
.c_line
= 0;
1455 tty
.main
.c_iflag
&= ~ASCEDIT
;
1457 tty
.main
.c_cc
[VSTRT
] = 255;
1458 tty
.main
.c_cc
[VSTOP
] = 255;
1459 tty
.main
.c_cc
[VSUSP
] = 255;
1460 tty
.main
.c_cc
[VDSUSP
] = 255;
1461 #endif /* IBMR2AIX */
1465 tty
.main
.c_cc
[VSTART
] = '\021';
1468 tty
.main
.c_cc
[VSTOP
] = '\023';
1471 /* Also, PTY overloads NUL and BREAK.
1472 don't ignore break, but don't signal either, so it looks like NUL.
1473 This really serves a purpose only if running in an XTERM window
1474 or via TELNET or the like, but does no harm elsewhere. */
1475 tty
.main
.c_iflag
&= ~IGNBRK
;
1476 tty
.main
.c_iflag
&= ~BRKINT
;
1478 #else /* if not HAVE_TERMIO */
1480 tty
.main
.tt_char
|= TT$M_NOECHO
;
1482 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1484 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1486 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1487 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1488 #else /* not VMS (BSD, that is) */
1490 XSETINT (Vtty_erase_char
, tty
.main
.sg_erase
);
1491 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1493 tty
.main
.sg_flags
|= ANYP
;
1494 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1495 #endif /* not DOS_NT */
1496 #endif /* not VMS (BSD, that is) */
1497 #endif /* not HAVE_TERMIO */
1499 /* If going to use CBREAK mode, we must request C-g to interrupt
1500 and turn off start and stop chars, etc. If not going to use
1501 CBREAK mode, do this anyway so as to turn off local flow
1502 control for user coming over network on 4.2; in this case,
1503 only t_stopc and t_startc really matter. */
1506 /* Note: if not using CBREAK mode, it makes no difference how we
1508 tty
.tchars
= new_tchars
;
1509 tty
.tchars
.t_intrc
= quit_char
;
1512 tty
.tchars
.t_startc
= '\021';
1513 tty
.tchars
.t_stopc
= '\023';
1516 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1518 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1519 anything, and leaving it in breaks the meta key. Go figure. */
1520 tty
.lmode
&= ~LLITOUT
;
1527 #endif /* HAVE_TCHARS */
1528 #endif /* not HAVE_TERMIO */
1531 tty
.ltchars
= new_ltchars
;
1532 #endif /* HAVE_LTCHARS */
1533 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1535 internal_terminal_init ();
1539 EMACS_SET_TTY (input_fd
, &tty
, 0);
1541 /* This code added to insure that, if flow-control is not to be used,
1542 we have an unlocked terminal at the start. */
1545 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1549 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1553 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1555 if (!flow_control
) tcflow (input_fd
, TCOON
);
1563 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1564 to be only LF. This is the way that is done. */
1567 if (ioctl (1, HFTGETID
, &tty
) != -1)
1568 write (1, "\033[20l", 5);
1574 /* Appears to do nothing when in PASTHRU mode.
1575 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1576 interrupt_signal, oob_chars, 0, 0, 0, 0);
1578 queue_kbd_input (0);
1583 #ifndef F_SETOWN_BUG
1584 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1586 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1588 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1589 fcntl (input_fd
, F_SETOWN
, getpid ());
1590 init_sigio (input_fd
);
1592 #endif /* F_GETOWN */
1593 #endif /* F_SETOWN_BUG */
1594 #endif /* F_SETFL */
1597 if (interrupt_input
)
1598 init_sigio (input_fd
);
1601 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1605 /* This symbol is defined on recent USG systems.
1606 Someone says without this call USG won't really buffer the file
1607 even with a call to setbuf. */
1608 setvbuf (stdout
, (char *) _sobuf
, _IOFBF
, sizeof _sobuf
);
1610 setbuf (stdout
, (char *) _sobuf
);
1612 #ifdef HAVE_WINDOW_SYSTEM
1613 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1614 needs the initialization code below. */
1615 if (EQ (Vwindow_system
, Qnil
)
1617 /* When running in tty mode on NT/Win95, we have a read_socket
1618 hook, but still need the rest of the initialization code below. */
1619 && (! read_socket_hook
)
1623 set_terminal_modes ();
1626 && FRAMEP (Vterminal_frame
)
1627 && FRAME_TERMCAP_P (XFRAME (Vterminal_frame
)))
1628 init_frame_faces (XFRAME (Vterminal_frame
));
1630 if (term_initted
&& no_redraw_on_reenter
)
1632 if (display_completed
)
1633 direct_output_forward_char (0);
1638 if (FRAMEP (Vterminal_frame
))
1639 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1645 /* Return nonzero if safe to use tabs in output.
1646 At the time this is called, init_sys_modes has not been done yet. */
1651 struct emacs_tty tty
;
1653 EMACS_GET_TTY (input_fd
, &tty
);
1654 return EMACS_TTY_TABS_OK (&tty
);
1657 /* Get terminal size from system.
1658 Store number of lines into *HEIGHTP and width into *WIDTHP.
1659 We store 0 if there's no valid information. */
1662 get_frame_size (widthp
, heightp
)
1663 int *widthp
, *heightp
;
1669 struct winsize size
;
1671 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1672 *widthp
= *heightp
= 0;
1675 *widthp
= size
.ws_col
;
1676 *heightp
= size
.ws_row
;
1682 /* SunOS - style. */
1683 struct ttysize size
;
1685 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1686 *widthp
= *heightp
= 0;
1689 *widthp
= size
.ts_cols
;
1690 *heightp
= size
.ts_lines
;
1696 struct sensemode tty
;
1698 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1699 &tty
.class, 12, 0, 0, 0, 0);
1700 *widthp
= tty
.scr_wid
;
1701 *heightp
= tty
.scr_len
;
1705 *widthp
= ScreenCols ();
1706 *heightp
= ScreenRows ();
1707 #else /* system doesn't know size */
1712 #endif /* not VMS */
1713 #endif /* not SunOS-style */
1714 #endif /* not BSD-style */
1717 /* Set the logical window size associated with descriptor FD
1718 to HEIGHT and WIDTH. This is used mainly with ptys. */
1721 set_window_size (fd
, height
, width
)
1722 int fd
, height
, width
;
1727 struct winsize size
;
1728 size
.ws_row
= height
;
1729 size
.ws_col
= width
;
1731 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1732 return 0; /* error */
1739 /* SunOS - style. */
1740 struct ttysize size
;
1741 size
.ts_lines
= height
;
1742 size
.ts_cols
= width
;
1744 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1750 #endif /* not SunOS-style */
1751 #endif /* not BSD-style */
1755 /* Prepare the terminal for exiting Emacs; move the cursor to the
1756 bottom of the frame, turn off interrupt-driven I/O, etc. */
1769 #ifdef HAVE_WINDOW_SYSTEM
1770 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1771 needs the clean-up code below. */
1772 if (!EQ (Vwindow_system
, Qnil
)
1774 /* When running in tty mode on NT/Win95, we have a read_socket
1775 hook, but still need the rest of the clean-up code below. */
1781 sf
= SELECTED_FRAME ();
1782 cursor_to (FRAME_HEIGHT (sf
) - 1, 0);
1783 clear_end_of_line (FRAME_WIDTH (sf
));
1784 /* clear_end_of_line may move the cursor */
1785 cursor_to (FRAME_HEIGHT (sf
) - 1, 0);
1786 #if defined (IBMR2AIX) && defined (AIXHFT)
1788 /* HFT devices normally use ^J as a LF/CR. We forced it to
1789 do the LF only. Now, we need to reset it. */
1792 if (ioctl (1, HFTGETID
, &tty
) != -1)
1793 write (1, "\033[20h", 5);
1797 reset_terminal_modes ();
1801 /* Avoid possible loss of output when changing terminal modes. */
1802 fsync (fileno (stdout
));
1807 #ifndef F_SETOWN_BUG
1808 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1809 if (interrupt_input
)
1812 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1814 #endif /* F_SETOWN */
1815 #endif /* F_SETOWN_BUG */
1817 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1819 #endif /* F_SETFL */
1821 if (interrupt_input
)
1826 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1829 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1833 #ifdef SET_LINE_DISCIPLINE
1834 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1835 A different old line discipline is therefore not restored, yet.
1836 Restore the old line discipline by hand. */
1837 ioctl (0, TIOCSETD
, &old_tty
.main
.c_line
);
1845 widen_foreground_group ();
1851 /* Set up the proper status flags for use of a pty. */
1857 /* I'm told that TOICREMOTE does not mean control chars
1858 "can't be sent" but rather that they don't have
1859 input-editing or signaling effects.
1860 That should be good, because we have other ways
1861 to do those things in Emacs.
1862 However, telnet mode seems not to work on 4.2.
1863 So TIOCREMOTE is turned off now. */
1865 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1866 will hang. In particular, the "timeout" feature (which
1867 causes a read to return if there is no data available)
1868 does this. Also it is known that telnet mode will hang
1869 in such a way that Emacs must be stopped (perhaps this
1870 is the same problem).
1872 If TIOCREMOTE is turned off, then there is a bug in
1873 hp-ux which sometimes loses data. Apparently the
1874 code which blocks the master process when the internal
1875 buffer fills up does not work. Other than this,
1876 though, everything else seems to work fine.
1878 Since the latter lossage is more benign, we may as well
1879 lose that way. -- cph */
1881 #if defined(SYSV_PTYS) || defined(UNIX98_PTYS)
1884 ioctl (fd
, FIONBIO
, &on
);
1889 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1890 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1891 /* cause EMACS not to die when it should, i.e., when its own controlling */
1892 /* tty goes away. I've complained to the AIX developers, and they may */
1893 /* change this behavior, but I'm not going to hold my breath. */
1894 signal (SIGHUP
, SIG_IGN
);
1897 #endif /* HAVE_PTYS */
1901 /* Assigning an input channel is done at the start of Emacs execution.
1902 This is called each time Emacs is resumed, also, but does nothing
1903 because input_chain is no longer zero. */
1912 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1918 /* Deassigning the input channel is done before exiting. */
1923 return SYS$
DASSGN (input_fd
);
1928 /* Request reading one character into the keyboard buffer.
1929 This is done as soon as the buffer becomes empty. */
1935 extern kbd_input_ast ();
1937 waiting_for_ast
= 0;
1939 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1940 &input_iosb
, kbd_input_ast
, 1,
1941 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1946 /* Ast routine that is called when keyboard input comes in
1947 in accord with the SYS$QIO above. */
1952 register int c
= -1;
1953 int old_errno
= errno
;
1954 extern EMACS_TIME
*input_available_clear_time
;
1956 if (waiting_for_ast
)
1957 SYS$
SETEF (input_ef
);
1958 waiting_for_ast
= 0;
1961 if (input_count
== 25)
1963 printf ("Ast # %d,", input_count
);
1964 printf (" iosb = %x, %x, %x, %x",
1965 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1968 if (input_iosb
.offset
)
1972 printf (", char = 0%o", c
);
1984 struct input_event e
;
1985 e
.kind
= ascii_keystroke
;
1986 XSETINT (e
.code
, c
);
1987 e
.frame_or_window
= selected_frame
;
1988 kbd_buffer_store_event (&e
);
1990 if (input_available_clear_time
)
1991 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1995 /* Wait until there is something in kbd_buffer. */
1998 wait_for_kbd_input ()
2000 extern int have_process_input
, process_exited
;
2002 /* If already something, avoid doing system calls. */
2003 if (detect_input_pending ())
2007 /* Clear a flag, and tell ast routine above to set it. */
2008 SYS$
CLREF (input_ef
);
2009 waiting_for_ast
= 1;
2010 /* Check for timing error: ast happened while we were doing that. */
2011 if (!detect_input_pending ())
2013 /* No timing error: wait for flag to be set. */
2014 set_waiting_for_input (0);
2015 SYS$
WFLOR (input_ef
, input_eflist
);
2016 clear_waiting_for_input (0);
2017 if (!detect_input_pending ())
2018 /* Check for subprocess input availability */
2020 int dsp
= have_process_input
|| process_exited
;
2022 SYS$
CLREF (process_ef
);
2023 if (have_process_input
)
2024 process_command_input ();
2029 update_mode_lines
++;
2030 prepare_menu_bars ();
2031 redisplay_preserve_echo_area ();
2035 waiting_for_ast
= 0;
2038 /* Get rid of any pending QIO, when we are about to suspend
2039 or when we want to throw away pending input.
2040 We wait for a positive sign that the AST routine has run
2041 and therefore there is no I/O request queued when we return.
2042 SYS$SETAST is used to avoid a timing error. */
2048 printf ("At end_kbd_input.\n");
2052 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2054 SYS$
CANCEL (input_fd
);
2059 /* Clear a flag, and tell ast routine above to set it. */
2060 SYS$
CLREF (input_ef
);
2061 waiting_for_ast
= 1;
2063 SYS$
CANCEL (input_fd
);
2065 SYS$
WAITFR (input_ef
);
2066 waiting_for_ast
= 0;
2069 /* Wait for either input available or time interval expiry. */
2072 input_wait_timeout (timeval
)
2073 int timeval
; /* Time to wait, in seconds */
2076 static int zero
= 0;
2077 static int large
= -10000000;
2079 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2081 /* If already something, avoid doing system calls. */
2082 if (detect_input_pending ())
2086 /* Clear a flag, and tell ast routine above to set it. */
2087 SYS$
CLREF (input_ef
);
2088 waiting_for_ast
= 1;
2089 /* Check for timing error: ast happened while we were doing that. */
2090 if (!detect_input_pending ())
2092 /* No timing error: wait for flag to be set. */
2094 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2095 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
2097 waiting_for_ast
= 0;
2100 /* The standard `sleep' routine works some other way
2101 and it stops working if you have ever quit out of it.
2102 This one continues to work. */
2108 static int zero
= 0;
2109 static int large
= -10000000;
2111 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2114 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2115 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2133 croak ("request sigio");
2139 croak ("unrequest sigio");
2144 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2149 #ifndef SYSTEM_MALLOC
2156 /* Some systems that cannot dump also cannot implement these. */
2159 * Return the address of the start of the text segment prior to
2160 * doing an unexec. After unexec the return value is undefined.
2161 * See crt0.c for further explanation and _start.
2165 #if !(defined (__NetBSD__) && defined (__ELF__))
2166 #ifndef HAVE_TEXT_START
2171 return ((char *) TEXT_START
);
2175 return ((char *) csrt
);
2176 #else /* not GOULD */
2177 extern int _start ();
2178 return ((char *) _start
);
2180 #endif /* TEXT_START */
2182 #endif /* not HAVE_TEXT_START */
2186 * Return the address of the start of the data segment prior to
2187 * doing an unexec. After unexec the return value is undefined.
2188 * See crt0.c for further information and definition of data_start.
2190 * Apparently, on BSD systems this is etext at startup. On
2191 * USG systems (swapping) this is highly mmu dependent and
2192 * is also dependent on whether or not the program is running
2193 * with shared text. Generally there is a (possibly large)
2194 * gap between end of text and start of data with shared text.
2196 * On Uniplus+ systems with shared text, data starts at a
2197 * fixed address. Each port (from a given oem) is generally
2198 * different, and the specific value of the start of data can
2199 * be obtained via the UniPlus+ specific "uvar" system call,
2200 * however the method outlined in crt0.c seems to be more portable.
2202 * Probably what will have to happen when a USG unexec is available,
2203 * at least on UniPlus, is temacs will have to be made unshared so
2204 * that text and data are contiguous. Then once loadup is complete,
2205 * unexec will produce a shared executable where the data can be
2206 * at the normal shared text boundary and the startofdata variable
2207 * will be patched by unexec to the correct value.
2215 return ((char *) DATA_START
);
2217 #ifdef ORDINARY_LINK
2219 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2220 * data_start isn't defined. We take the address of environ, which
2221 * is known to live at or near the start of the system crt0.c, and
2222 * we don't sweat the handful of bytes that might lose.
2224 extern char **environ
;
2226 return ((char *) &environ
);
2228 extern int data_start
;
2229 return ((char *) &data_start
);
2230 #endif /* ORDINARY_LINK */
2231 #endif /* DATA_START */
2233 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2236 /* Some systems that cannot dump also cannot implement these. */
2239 * Return the address of the end of the text segment prior to
2240 * doing an unexec. After unexec the return value is undefined.
2247 return ((char *) TEXT_END
);
2250 return ((char *) &etext
);
2255 * Return the address of the end of the data segment prior to
2256 * doing an unexec. After unexec the return value is undefined.
2263 return ((char *) DATA_END
);
2266 return ((char *) &edata
);
2270 #endif /* not CANNOT_DUMP */
2272 /* init_system_name sets up the string for the Lisp function
2273 system-name to return. */
2279 extern Lisp_Object Vsystem_name
;
2284 #include <sys/socket.h>
2286 #endif /* HAVE_SOCKETS */
2287 #endif /* not VMS */
2288 #endif /* not BSD4_1 */
2291 #ifndef HAVE_H_ERRNO
2294 #endif /* TRY_AGAIN */
2300 Vsystem_name
= build_string (sysname
);
2304 if ((sp
= egetenv ("SYS$NODE")) == 0)
2305 Vsystem_name
= build_string ("vax-vms");
2306 else if ((end
= index (sp
, ':')) == 0)
2307 Vsystem_name
= build_string (sp
);
2309 Vsystem_name
= make_string (sp
, end
- sp
);
2311 #ifndef HAVE_GETHOSTNAME
2314 Vsystem_name
= build_string (uts
.nodename
);
2315 #else /* HAVE_GETHOSTNAME */
2316 unsigned int hostname_size
= 256;
2317 char *hostname
= (char *) alloca (hostname_size
);
2319 /* Try to get the host name; if the buffer is too short, try
2320 again. Apparently, the only indication gethostname gives of
2321 whether the buffer was large enough is the presence or absence
2322 of a '\0' in the string. Eech. */
2325 gethostname (hostname
, hostname_size
- 1);
2326 hostname
[hostname_size
- 1] = '\0';
2328 /* Was the buffer large enough for the '\0'? */
2329 if (strlen (hostname
) < hostname_size
- 1)
2332 hostname_size
<<= 1;
2333 hostname
= (char *) alloca (hostname_size
);
2336 /* Turn the hostname into the official, fully-qualified hostname.
2337 Don't do this if we're going to dump; this can confuse system
2338 libraries on some machines and make the dumped emacs core dump. */
2341 #endif /* not CANNOT_DUMP */
2342 if (! index (hostname
, '.'))
2346 for (count
= 0;; count
++)
2351 hp
= gethostbyname (hostname
);
2353 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2358 Fsleep_for (make_number (1), Qnil
);
2362 char *fqdn
= (char *) hp
->h_name
;
2365 if (!index (fqdn
, '.'))
2367 /* We still don't have a fully qualified domain name.
2368 Try to find one in the list of alternate names */
2369 char **alias
= hp
->h_aliases
;
2370 while (*alias
&& !index (*alias
, '.'))
2377 /* Convert the host name to lower case. */
2378 /* Using ctype.h here would introduce a possible locale
2379 dependence that is probably wrong for hostnames. */
2383 if (*p
>= 'A' && *p
<= 'Z')
2390 #endif /* HAVE_SOCKETS */
2391 /* We used to try using getdomainname here,
2392 but NIIBE Yutaka <gniibe@etl.go.jp> says that
2393 getdomainname gets the NIS/YP domain which often is not the same
2394 as in Internet domain name. */
2395 #if 0 /* Turned off because sysinfo is not really likely to return the
2396 correct Internet domain. */
2397 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2398 if (! index (hostname
, '.'))
2400 /* The hostname is not fully qualified. Append the domain name. */
2402 int hostlen
= strlen (hostname
);
2403 int domain_size
= 256;
2407 char *domain
= (char *) alloca (domain_size
+ 1);
2408 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2409 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2410 if (sys_domain_size
<= 0)
2412 if (domain_size
< sys_domain_size
)
2414 domain_size
= sys_domain_size
;
2417 strcpy (fqdn
, hostname
);
2418 if (domain
[0] == '.')
2419 strcpy (fqdn
+ hostlen
, domain
);
2420 else if (domain
[0] != 0)
2422 fqdn
[hostlen
] = '.';
2423 strcpy (fqdn
+ hostlen
+ 1, domain
);
2429 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2431 Vsystem_name
= build_string (hostname
);
2432 #endif /* HAVE_GETHOSTNAME */
2437 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2438 if (*p
== ' ' || *p
== '\t')
2445 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2447 #include "sysselect.h"
2450 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2451 /* Cause explanatory error message at compile time,
2452 since the select emulation is not good enough for X. */
2453 int *x
= &x_windows_lose_if_no_select_system_call
;
2456 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2457 * Only checks read descriptors.
2459 /* How long to wait between checking fds in select */
2460 #define SELECT_PAUSE 1
2463 /* For longjmp'ing back to read_input_waiting. */
2465 jmp_buf read_alarm_throw
;
2467 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2468 The read_socket_hook function sets this to 1 while it is waiting. */
2470 int read_alarm_should_throw
;
2478 #else /* not BSD4_1 */
2479 signal (SIGALRM
, SIG_IGN
);
2480 #endif /* not BSD4_1 */
2481 if (read_alarm_should_throw
)
2482 longjmp (read_alarm_throw
, 1);
2486 /* Only rfds are checked. */
2488 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2490 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2491 EMACS_TIME
*timeout
;
2497 extern int proc_buffered_char
[];
2498 #ifndef subprocesses
2499 int process_tick
= 0, update_tick
= 0;
2501 extern int process_tick
, update_tick
;
2505 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2506 /* If we're using X, then the native select will work; we only need the
2507 emulation for non-X usage. */
2508 if (!NILP (Vwindow_system
))
2509 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2511 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2512 local_timeout
= &timeoutval
;
2524 /* If we are looking only for the terminal, with no timeout,
2525 just read it and wait -- that's more efficient. */
2526 if (*local_timeout
== 100000 && process_tick
== update_tick
2527 && FD_ISSET (0, &orfds
))
2530 for (fd
= 1; fd
< nfds
; ++fd
)
2531 if (FD_ISSET (fd
, &orfds
))
2533 if (! detect_input_pending ())
2534 read_input_waiting ();
2540 /* Once a second, till the timer expires, check all the flagged read
2541 * descriptors to see if any input is available. If there is some then
2542 * set the corresponding bit in the return copy of rfds.
2546 register int to_check
, fd
;
2550 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2552 if (FD_ISSET (fd
, &orfds
))
2554 int avail
= 0, status
= 0;
2557 avail
= detect_input_pending (); /* Special keyboard handler */
2561 status
= ioctl (fd
, FIONREAD
, &avail
);
2562 #else /* no FIONREAD */
2563 /* Hoping it will return -1 if nothing available
2564 or 0 if all 0 chars requested are read. */
2565 if (proc_buffered_char
[fd
] >= 0)
2569 avail
= read (fd
, &buf
, 1);
2571 proc_buffered_char
[fd
] = buf
;
2573 #endif /* no FIONREAD */
2575 if (status
>= 0 && avail
> 0)
2583 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2586 turn_on_atimers (0);
2587 signal (SIGALRM
, select_alarm
);
2589 alarm (SELECT_PAUSE
);
2591 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2592 while (select_alarmed
== 0 && *local_timeout
!= 0
2593 && process_tick
== update_tick
)
2595 /* If we are interested in terminal input,
2596 wait by reading the terminal.
2597 That makes instant wakeup for terminal input at least. */
2598 if (FD_ISSET (0, &orfds
))
2600 read_input_waiting ();
2601 if (detect_input_pending ())
2607 (*local_timeout
) -= SELECT_PAUSE
;
2609 /* Reset the old alarm if there was one. */
2610 turn_on_atimers (1);
2612 if (*local_timeout
== 0) /* Stop on timer being cleared */
2617 #endif /* not WINDOWSNT */
2619 /* Read keyboard input into the standard buffer,
2620 waiting for at least one character. */
2622 /* Make all keyboard buffers much bigger when using a window system. */
2623 #ifdef HAVE_WINDOW_SYSTEM
2624 #define BUFFER_SIZE_FACTOR 16
2626 #define BUFFER_SIZE_FACTOR 1
2630 read_input_waiting ()
2632 struct input_event e
;
2634 extern int quit_char
;
2636 if (read_socket_hook
)
2638 struct input_event buf
[256];
2640 read_alarm_should_throw
= 0;
2641 if (! setjmp (read_alarm_throw
))
2642 nread
= (*read_socket_hook
) (0, buf
, 256, 1);
2646 /* Scan the chars for C-g and store them in kbd_buffer. */
2647 for (i
= 0; i
< nread
; i
++)
2649 kbd_buffer_store_event (&buf
[i
]);
2650 /* Don't look at input that follows a C-g too closely.
2651 This reduces lossage due to autorepeat on C-g. */
2652 if (buf
[i
].kind
== ascii_keystroke
2653 && buf
[i
].code
== quit_char
)
2660 nread
= read (fileno (stdin
), buf
, 1);
2662 /* Scan the chars for C-g and store them in kbd_buffer. */
2663 e
.kind
= ascii_keystroke
;
2664 e
.frame_or_window
= selected_frame
;
2666 for (i
= 0; i
< nread
; i
++)
2668 /* Convert chars > 0177 to meta events if desired.
2669 We do this under the same conditions that read_avail_input does. */
2670 if (read_socket_hook
== 0)
2672 /* If the user says she has a meta key, then believe her. */
2673 if (meta_key
== 1 && (buf
[i
] & 0x80))
2674 e
.modifiers
= meta_modifier
;
2679 XSETINT (e
.code
, buf
[i
]);
2680 kbd_buffer_store_event (&e
);
2681 /* Don't look at input that follows a C-g too closely.
2682 This reduces lossage due to autorepeat on C-g. */
2683 if (buf
[i
] == quit_char
)
2689 #endif /* not HAVE_SELECT */
2690 #endif /* not VMS */
2691 #endif /* not MSDOS */
2700 lmode
= LINTRUP
| lmode
;
2701 ioctl (fd
, TIOCLSET
, &lmode
);
2709 lmode
= ~LINTRUP
& lmode
;
2710 ioctl (0, TIOCLSET
, &lmode
);
2718 interrupts_deferred
= 0;
2726 interrupts_deferred
= 1;
2729 /* still inside #ifdef BSD4_1 */
2732 int sigheld
; /* Mask of held signals */
2738 sigheld
|= sigbit (signum
);
2746 sigheld
|= sigbit (signum
);
2753 sigheld
&= ~sigbit (signum
);
2758 sigfree () /* Free all held signals */
2761 for (i
= 0; i
< NSIG
; i
++)
2762 if (sigheld
& sigbit (i
))
2770 return 1 << (i
- 1);
2772 #endif /* subprocesses */
2775 /* POSIX signals support - DJB */
2776 /* Anyone with POSIX signals should have ANSI C declarations */
2778 #ifdef POSIX_SIGNALS
2780 sigset_t empty_mask
, full_mask
;
2783 sys_signal (int signal_number
, signal_handler_t action
)
2785 struct sigaction new_action
, old_action
;
2786 sigemptyset (&new_action
.sa_mask
);
2787 new_action
.sa_handler
= action
;
2789 /* Emacs mostly works better with restartable system services. If this
2790 * flag exists, we probably want to turn it on here.
2792 new_action
.sa_flags
= SA_RESTART
;
2794 new_action
.sa_flags
= 0;
2796 sigaction (signal_number
, &new_action
, &old_action
);
2797 return (old_action
.sa_handler
);
2801 /* If we're compiling with GCC, we don't need this function, since it
2802 can be written as a macro. */
2804 sys_sigmask (int sig
)
2807 sigemptyset (&mask
);
2808 sigaddset (&mask
, sig
);
2813 /* I'd like to have these guys return pointers to the mask storage in here,
2814 but there'd be trouble if the code was saving multiple masks. I'll be
2815 safe and pass the structure. It normally won't be more than 2 bytes
2819 sys_sigblock (sigset_t new_mask
)
2822 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2827 sys_sigunblock (sigset_t new_mask
)
2830 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2835 sys_sigsetmask (sigset_t new_mask
)
2838 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2842 #endif /* POSIX_SIGNALS */
2844 #if !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED
2845 static char *my_sys_siglist
[NSIG
];
2849 # define sys_siglist my_sys_siglist
2855 #ifdef POSIX_SIGNALS
2856 sigemptyset (&empty_mask
);
2857 sigfillset (&full_mask
);
2860 #if !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED
2864 sys_siglist
[SIGABRT
] = "Aborted";
2867 sys_siglist
[SIGAIO
] = "LAN I/O interrupt";
2870 sys_siglist
[SIGALRM
] = "Alarm clock";
2873 sys_siglist
[SIGBUS
] = "Bus error";
2876 sys_siglist
[SIGCLD
] = "Child status changed";
2879 sys_siglist
[SIGCHLD
] = "Child status changed";
2882 sys_siglist
[SIGCONT
] = "Continued";
2885 sys_siglist
[SIGDANGER
] = "Swap space dangerously low";
2888 sys_siglist
[SIGDGNOTIFY
] = "Notification message in queue";
2891 sys_siglist
[SIGEMT
] = "Emulation trap";
2894 sys_siglist
[SIGFPE
] = "Arithmetic exception";
2897 sys_siglist
[SIGFREEZE
] = "SIGFREEZE";
2900 sys_siglist
[SIGGRANT
] = "Monitor mode granted";
2903 sys_siglist
[SIGHUP
] = "Hangup";
2906 sys_siglist
[SIGILL
] = "Illegal instruction";
2909 sys_siglist
[SIGINT
] = "Interrupt";
2912 sys_siglist
[SIGIO
] = "I/O possible";
2915 sys_siglist
[SIGIOINT
] = "I/O intervention required";
2918 sys_siglist
[SIGIOT
] = "IOT trap";
2921 sys_siglist
[SIGKILL
] = "Killed";
2924 sys_siglist
[SIGLOST
] = "Resource lost";
2927 sys_siglist
[SIGLWP
] = "SIGLWP";
2930 sys_siglist
[SIGMSG
] = "Monitor mode data available";
2933 sys_siglist
[SIGWIND
] = "SIGPHONE";
2936 sys_siglist
[SIGPIPE
] = "Broken pipe";
2939 sys_siglist
[SIGPOLL
] = "Pollable event occurred";
2942 sys_siglist
[SIGPROF
] = "Profiling timer expired";
2945 sys_siglist
[SIGPTY
] = "PTY I/O interrupt";
2948 sys_siglist
[SIGPWR
] = "Power-fail restart";
2951 sys_siglist
[SIGQUIT
] = "Quit";
2954 sys_siglist
[SIGRETRACT
] = "Need to relinguish monitor mode";
2957 sys_siglist
[SIGSAK
] = "Secure attention";
2960 sys_siglist
[SIGSEGV
] = "Segmentation violation";
2963 sys_siglist
[SIGSOUND
] = "Sound completed";
2966 sys_siglist
[SIGSTOP
] = "Stopped (signal)";
2969 sys_siglist
[SIGSTP
] = "Stopped (user)";
2972 sys_siglist
[SIGSYS
] = "Bad argument to system call";
2975 sys_siglist
[SIGTERM
] = "Terminated";
2978 sys_siglist
[SIGTHAW
] = "SIGTHAW";
2981 sys_siglist
[SIGTRAP
] = "Trace/breakpoint trap";
2984 sys_siglist
[SIGTSTP
] = "Stopped (user)";
2987 sys_siglist
[SIGTTIN
] = "Stopped (tty input)";
2990 sys_siglist
[SIGTTOU
] = "Stopped (tty output)";
2993 sys_siglist
[SIGURG
] = "Urgent I/O condition";
2996 sys_siglist
[SIGUSR1
] = "User defined signal 1";
2999 sys_siglist
[SIGUSR2
] = "User defined signal 2";
3002 sys_siglist
[SIGVTALRM
] = "Virtual timer expired";
3005 sys_siglist
[SIGWAITING
] = "Process's LWPs are blocked";
3008 sys_siglist
[SIGWINCH
] = "Window size changed";
3011 sys_siglist
[SIGWIND
] = "SIGWIND";
3014 sys_siglist
[SIGXCPU
] = "CPU time limit exceeded";
3017 sys_siglist
[SIGXFSZ
] = "File size limit exceeded";
3020 #endif /* !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED */
3029 /* Figure out how many bits the system's random number generator uses.
3030 `random' and `lrand48' are assumed to return 31 usable bits.
3031 BSD `rand' returns a 31 bit value but the low order bits are unusable;
3032 so we'll shift it and treat it like the 15-bit USG `rand'. */
3036 # define RAND_BITS 31
3037 # else /* !HAVE_RANDOM */
3038 # ifdef HAVE_LRAND48
3039 # define RAND_BITS 31
3040 # define random lrand48
3041 # else /* !HAVE_LRAND48 */
3042 # define RAND_BITS 15
3043 # if RAND_MAX == 32767
3044 # define random rand
3045 # else /* RAND_MAX != 32767 */
3046 # if RAND_MAX == 2147483647
3047 # define random() (rand () >> 16)
3048 # else /* RAND_MAX != 2147483647 */
3050 # define random rand
3052 # define random() (rand () >> 16)
3054 # endif /* RAND_MAX != 2147483647 */
3055 # endif /* RAND_MAX != 32767 */
3056 # endif /* !HAVE_LRAND48 */
3057 # endif /* !HAVE_RANDOM */
3058 #endif /* !RAND_BITS */
3065 srandom ((unsigned int)arg
);
3067 # ifdef HAVE_LRAND48
3070 srand ((unsigned int)arg
);
3076 * Build a full Emacs-sized word out of whatever we've got.
3077 * This suffices even for a 64-bit architecture with a 15-bit rand.
3082 long val
= random ();
3083 #if VALBITS > RAND_BITS
3084 val
= (val
<< RAND_BITS
) ^ random ();
3085 #if VALBITS > 2*RAND_BITS
3086 val
= (val
<< RAND_BITS
) ^ random ();
3087 #if VALBITS > 3*RAND_BITS
3088 val
= (val
<< RAND_BITS
) ^ random ();
3089 #if VALBITS > 4*RAND_BITS
3090 val
= (val
<< RAND_BITS
) ^ random ();
3091 #endif /* need at least 5 */
3092 #endif /* need at least 4 */
3093 #endif /* need at least 3 */
3094 #endif /* need at least 2 */
3095 return val
& ((1L << VALBITS
) - 1);
3098 #ifdef WRONG_NAME_INSQUE
3111 /* If any place else asks for the TERM variable,
3112 allow it to be overridden with the EMACS_TERM variable
3113 before attempting to translate the logical name TERM. As a last
3114 resort, ask for VAX C's special idea of the TERM variable. */
3121 static char buf
[256];
3122 static struct dsc$descriptor_s equiv
3123 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
3124 static struct dsc$descriptor_s d_name
3125 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
3128 if (!strcmp (name
, "TERM"))
3130 val
= (char *) getenv ("EMACS_TERM");
3135 d_name
.dsc$w_length
= strlen (name
);
3136 d_name
.dsc$a_pointer
= name
;
3137 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
3139 char *str
= (char *) xmalloc (eqlen
+ 1);
3140 bcopy (buf
, str
, eqlen
);
3142 /* This is a storage leak, but a pain to fix. With luck,
3143 no one will ever notice. */
3146 return (char *) getenv (name
);
3151 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
3152 to force a call on the debugger from within the image. */
3157 LIB$
SIGNAL (SS$_DEBUG
);
3163 #ifdef LINK_CRTL_SHARE
3164 #ifdef SHARABLE_LIB_BUG
3165 /* Variables declared noshare and initialized in sharable libraries
3166 cannot be shared. The VMS linker incorrectly forces you to use a private
3167 version which is uninitialized... If not for this "feature", we
3168 could use the C library definition of sys_nerr and sys_errlist. */
3170 char *sys_errlist
[] =
3174 "no such file or directory",
3176 "interrupted system call",
3178 "no such device or address",
3179 "argument list too long",
3180 "exec format error",
3183 "no more processes",
3184 "not enough memory",
3185 "permission denied",
3187 "block device required",
3188 "mount devices busy",
3190 "cross-device link",
3195 "file table overflow",
3196 "too many open files",
3200 "no space left on device",
3202 "read-only file system",
3208 "vax/vms specific error code nontranslatable error"
3210 #endif /* SHARABLE_LIB_BUG */
3211 #endif /* LINK_CRTL_SHARE */
3214 #ifndef HAVE_STRERROR
3220 extern char *sys_errlist
[];
3221 extern int sys_nerr
;
3223 if (errnum
>= 0 && errnum
< sys_nerr
)
3224 return sys_errlist
[errnum
];
3225 return (char *) "Unknown error";
3227 #endif /* not WINDOWSNT */
3228 #endif /* ! HAVE_STRERROR */
3231 emacs_open (path
, oflag
, mode
)
3235 register int rtnval
;
3238 if (oflag
& O_CREAT
)
3239 return creat (path
, mode
);
3242 while ((rtnval
= open (path
, oflag
, mode
)) == -1
3243 && (errno
== EINTR
));
3252 register int rtnval
;
3254 while ((rtnval
= close (fd
)) == -1
3255 && (errno
== EINTR
))
3258 /* If close is interrupted SunOS 4.1 may or may not have closed the
3259 file descriptor. If it did the second close will fail with
3260 errno = EBADF. That means we have succeeded. */
3261 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3268 emacs_read (fildes
, buf
, nbyte
)
3273 register int rtnval
;
3275 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3276 && (errno
== EINTR
));
3281 emacs_write (fildes
, buf
, nbyte
)
3286 register int rtnval
, bytes_written
;
3292 rtnval
= write (fildes
, buf
, nbyte
);
3299 return (bytes_written
? bytes_written
: -1);
3304 bytes_written
+= rtnval
;
3306 return (bytes_written
);
3311 * All of the following are for USG.
3313 * On USG systems the system calls are INTERRUPTIBLE by signals
3314 * that the user program has elected to catch. Thus the system call
3315 * must be retried in these cases. To handle this without massive
3316 * changes in the source code, we remap the standard system call names
3317 * to names for our own functions in sysdep.c that do the system call
3318 * with retries. Actually, for portability reasons, it is good
3319 * programming practice, as this example shows, to limit all actual
3320 * system calls to a single occurrence in the source. Sure, this
3321 * adds an extra level of function call overhead but it is almost
3322 * always negligible. Fred Fish, Unisoft Systems Inc.
3326 * Warning, this function may not duplicate 4.2 action properly
3327 * under error conditions.
3331 /* In 4.1, param.h fails to define this. */
3332 #define MAXPATHLEN 1024
3341 char *npath
, *spath
;
3342 extern char *getcwd ();
3344 BLOCK_INPUT
; /* getcwd uses malloc */
3345 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3348 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3349 up to first slash. Should be harmless on other systems. */
3350 while (*npath
&& *npath
!= '/')
3352 strcpy (pathname
, npath
);
3353 free (spath
); /* getcwd uses malloc */
3358 #endif /* HAVE_GETWD */
3361 * Emulate rename using unlink/link. Note that this is
3362 * only partially correct. Also, doesn't enforce restriction
3363 * that files be of same type (regular->regular, dir->dir, etc).
3372 if (access (from
, 0) == 0)
3375 if (link (from
, to
) == 0)
3376 if (unlink (from
) == 0)
3388 /* HPUX curses library references perror, but as far as we know
3389 it won't be called. Anyway this definition will do for now. */
3395 #endif /* not HAVE_PERROR */
3401 * Emulate BSD dup2. First close newd if it already exists.
3402 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3403 * until we are, then close the unsuccessful ones.
3410 register int fd
, ret
;
3415 return fcntl (oldd
, F_DUPFD
, newd
);
3422 ret
= dup2 (old
,new);
3428 #endif /* not HAVE_DUP2 */
3431 * Gettimeofday. Simulate as much as possible. Only accurate
3432 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3433 * Only needed when subprocesses are defined.
3438 #ifndef HAVE_GETTIMEOFDAY
3443 gettimeofday (tp
, tzp
)
3445 struct timezone
*tzp
;
3447 extern long time ();
3449 tp
->tv_sec
= time ((long *)0);
3452 tzp
->tz_minuteswest
= -1;
3459 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3462 * This function will go away as soon as all the stubs fixed. (fnf)
3469 printf ("%s not yet implemented\r\n", badfunc
);
3476 /* Directory routines for systems that don't have them. */
3478 #ifdef SYSV_SYSTEM_DIR
3482 #if defined (BROKEN_CLOSEDIR) || !defined (HAVE_CLOSEDIR)
3486 register DIR *dirp
; /* stream from opendir */
3490 rtnval
= emacs_close (dirp
->dd_fd
);
3492 /* Some systems (like Solaris) allocate the buffer and the DIR all
3493 in one block. Why in the world are we freeing this ourselves
3495 #if ! (defined (sun) && defined (USG5_4))
3496 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3498 xfree ((char *) dirp
);
3502 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3503 #endif /* SYSV_SYSTEM_DIR */
3505 #ifdef NONSYSTEM_DIR_LIBRARY
3509 char *filename
; /* name of directory */
3511 register DIR *dirp
; /* -> malloc'ed storage */
3512 register int fd
; /* file descriptor for read */
3513 struct stat sbuf
; /* result of fstat */
3515 fd
= emacs_open (filename
, O_RDONLY
, 0);
3520 if (fstat (fd
, &sbuf
) < 0
3521 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3522 || (dirp
= (DIR *) xmalloc (sizeof (DIR))) == 0)
3526 return 0; /* bad luck today */
3531 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3538 register DIR *dirp
; /* stream from opendir */
3540 emacs_close (dirp
->dd_fd
);
3541 xfree ((char *) dirp
);
3549 ino_t od_ino
; /* inode */
3550 char od_name
[DIRSIZ
]; /* filename */
3552 #endif /* not VMS */
3554 struct direct dir_static
; /* simulated directory contents */
3559 register DIR *dirp
; /* stream from opendir */
3562 register struct olddir
*dp
; /* -> directory data */
3564 register struct dir$_name
*dp
; /* -> directory data */
3565 register struct dir$_version
*dv
; /* -> version data */
3570 if (dirp
->dd_loc
>= dirp
->dd_size
)
3571 dirp
->dd_loc
= dirp
->dd_size
= 0;
3573 if (dirp
->dd_size
== 0 /* refill buffer */
3574 && (dirp
->dd_size
= emacs_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3578 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3579 dirp
->dd_loc
+= sizeof (struct olddir
);
3581 if (dp
->od_ino
!= 0) /* not deleted entry */
3583 dir_static
.d_ino
= dp
->od_ino
;
3584 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3585 dir_static
.d_name
[DIRSIZ
] = '\0';
3586 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3587 dir_static
.d_reclen
= sizeof (struct direct
)
3589 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3590 return &dir_static
; /* -> simulated structure */
3593 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3594 if (dirp
->dd_loc
== 0)
3595 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3596 : dp
->dir$b_namecount
;
3597 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3598 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3599 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3600 dir_static
.d_reclen
= sizeof (struct direct
)
3602 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3603 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3604 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3605 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3612 /* readdirver is just like readdir except it returns all versions of a file
3613 as separate entries. */
3618 register DIR *dirp
; /* stream from opendir */
3620 register struct dir$_name
*dp
; /* -> directory data */
3621 register struct dir$_version
*dv
; /* -> version data */
3623 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3624 dirp
->dd_loc
= dirp
->dd_size
= 0;
3626 if (dirp
->dd_size
== 0 /* refill buffer */
3627 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3630 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3631 if (dirp
->dd_loc
== 0)
3632 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3633 : dp
->dir$b_namecount
;
3634 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3635 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3636 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3637 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3638 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3639 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3640 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3641 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3647 #endif /* NONSYSTEM_DIR_LIBRARY */
3651 set_file_times (filename
, atime
, mtime
)
3653 EMACS_TIME atime
, mtime
;
3656 struct timeval tv
[2];
3659 return utimes (filename
, tv
);
3660 #else /* not HAVE_UTIMES */
3662 utb
.actime
= EMACS_SECS (atime
);
3663 utb
.modtime
= EMACS_SECS (mtime
);
3664 return utime (filename
, &utb
);
3665 #endif /* not HAVE_UTIMES */
3668 /* mkdir and rmdir functions, for systems which don't have them. */
3672 * Written by Robert Rother, Mariah Corporation, August 1985.
3674 * If you want it, it's yours. All I ask in return is that if you
3675 * figure out how to do this in a Bourne Shell script you send me
3677 * sdcsvax!rmr or rmr@uscd
3679 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3680 * subroutine. 11Mar86; hoptoad!gnu
3682 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3683 * subroutine didn't return EEXIST. It does now.
3689 #ifdef MKDIR_PROTOTYPE
3693 mkdir (dpath
, dmode
)
3698 int cpid
, status
, fd
;
3699 struct stat statbuf
;
3701 if (stat (dpath
, &statbuf
) == 0)
3703 errno
= EEXIST
; /* Stat worked, so it already exists */
3707 /* If stat fails for a reason other than non-existence, return error */
3708 if (errno
!= ENOENT
)
3711 synch_process_alive
= 1;
3712 switch (cpid
= fork ())
3715 case -1: /* Error in fork */
3716 return (-1); /* Errno is set already */
3718 case 0: /* Child process */
3720 * Cheap hack to set mode of new directory. Since this
3721 * child process is going away anyway, we zap its umask.
3722 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3723 * directory. Does anybody care?
3725 status
= umask (0); /* Get current umask */
3726 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3727 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3734 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3735 _exit (-1); /* Can't exec /bin/mkdir */
3737 default: /* Parent process */
3738 wait_for_termination (cpid
);
3741 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3743 errno
= EIO
; /* We don't know why, but */
3744 return -1; /* /bin/mkdir failed */
3749 #endif /* not HAVE_MKDIR */
3756 int cpid
, status
, fd
;
3757 struct stat statbuf
;
3759 if (stat (dpath
, &statbuf
) != 0)
3761 /* Stat just set errno. We don't have to */
3765 synch_process_alive
= 1;
3766 switch (cpid
= fork ())
3769 case -1: /* Error in fork */
3770 return (-1); /* Errno is set already */
3772 case 0: /* Child process */
3773 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3780 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3781 _exit (-1); /* Can't exec /bin/rmdir */
3783 default: /* Parent process */
3784 wait_for_termination (cpid
);
3787 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3789 errno
= EIO
; /* We don't know why, but */
3790 return -1; /* /bin/rmdir failed */
3795 #endif /* !HAVE_RMDIR */
3799 /* Functions for VMS */
3801 #include "vms-pwd.h"
3806 /* Return as a string the VMS error string pertaining to STATUS.
3807 Reuses the same static buffer each time it is called. */
3811 int status
; /* VMS status code */
3815 static char buf
[257];
3817 bufadr
[0] = sizeof buf
- 1;
3818 bufadr
[1] = (int) buf
;
3819 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3820 return "untranslatable VMS error status";
3828 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3829 * not work correctly. (It also doesn't work well in version 2.3.)
3834 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3835 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3839 unsigned short s_buflen
;
3840 unsigned short s_code
;
3842 unsigned short *s_retlenadr
;
3846 #define buflen s.s_buflen
3847 #define code s.s_code
3848 #define bufadr s.s_bufadr
3849 #define retlenadr s.s_retlenadr
3851 #define R_OK 4 /* test for read permission */
3852 #define W_OK 2 /* test for write permission */
3853 #define X_OK 1 /* test for execute (search) permission */
3854 #define F_OK 0 /* test for presence of file */
3857 sys_access (path
, mode
)
3861 static char *user
= NULL
;
3864 /* translate possible directory spec into .DIR file name, so brain-dead
3865 * access can treat the directory like a file. */
3866 if (directory_file_name (path
, dir_fn
))
3870 return access (path
, mode
);
3871 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3877 unsigned short int dummy
;
3879 static int constant
= ACL$C_FILE
;
3880 DESCRIPTOR (path_desc
, path
);
3881 DESCRIPTOR (user_desc
, user
);
3885 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3888 acces
|= CHP$M_READ
;
3890 acces
|= CHP$M_WRITE
;
3891 itemlst
[0].buflen
= sizeof (int);
3892 itemlst
[0].code
= CHP$_FLAGS
;
3893 itemlst
[0].bufadr
= (char *) &flags
;
3894 itemlst
[0].retlenadr
= &dummy
;
3895 itemlst
[1].buflen
= sizeof (int);
3896 itemlst
[1].code
= CHP$_ACCESS
;
3897 itemlst
[1].bufadr
= (char *) &acces
;
3898 itemlst
[1].retlenadr
= &dummy
;
3899 itemlst
[2].end
= CHP$_END
;
3900 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3901 return stat
== SS$_NORMAL
? 0 : -1;
3905 #else /* not VMS4_4 */
3908 #define ACE$M_WRITE 2
3909 #define ACE$C_KEYID 1
3911 static unsigned short memid
, grpid
;
3912 static unsigned int uic
;
3914 /* Called from init_sys_modes, so it happens not very often
3915 but at least each time Emacs is loaded. */
3917 sys_access_reinit ()
3923 sys_access (filename
, type
)
3929 int status
, size
, i
, typecode
, acl_controlled
;
3930 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3931 union prvdef prvmask
;
3933 /* Get UIC and GRP values for protection checking. */
3936 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3939 memid
= uic
& 0xFFFF;
3943 if (type
!= 2) /* not checking write access */
3944 return access (filename
, type
);
3946 /* Check write protection. */
3948 #define CHECKPRIV(bit) (prvmask.bit)
3949 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3951 /* Find privilege bits */
3952 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3954 error ("Unable to find privileges: %s", vmserrstr (status
));
3955 if (CHECKPRIV (PRV$V_BYPASS
))
3956 return 0; /* BYPASS enabled */
3958 fab
.fab$b_fac
= FAB$M_GET
;
3959 fab
.fab$l_fna
= filename
;
3960 fab
.fab$b_fns
= strlen (filename
);
3961 fab
.fab$l_xab
= &xab
;
3962 xab
= cc$rms_xabpro
;
3963 xab
.xab$l_aclbuf
= aclbuf
;
3964 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3965 status
= SYS$
OPEN (&fab
, 0, 0);
3968 SYS$
CLOSE (&fab
, 0, 0);
3969 /* Check system access */
3970 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
3972 /* Check ACL entries, if any */
3974 if (xab
.xab$w_acllen
> 0)
3977 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3978 while (*aclptr
&& aclptr
< aclend
)
3980 size
= (*aclptr
& 0xff) / 4;
3981 typecode
= (*aclptr
>> 8) & 0xff;
3982 if (typecode
== ACE$C_KEYID
)
3983 for (i
= size
- 1; i
> 1; i
--)
3984 if (aclptr
[i
] == uic
)
3987 if (aclptr
[1] & ACE$M_WRITE
)
3988 return 0; /* Write access through ACL */
3990 aclptr
= &aclptr
[size
];
3992 if (acl_controlled
) /* ACL specified, prohibits write access */
3995 /* No ACL entries specified, check normal protection */
3996 if (WRITABLE (XAB$V_WLD
)) /* World writable */
3998 if (WRITABLE (XAB$V_GRP
) &&
3999 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
4000 return 0; /* Group writable */
4001 if (WRITABLE (XAB$V_OWN
) &&
4002 (xab
.xab$l_uic
& 0xFFFF) == memid
)
4003 return 0; /* Owner writable */
4005 return -1; /* Not writable */
4007 #endif /* not VMS4_4 */
4010 static char vtbuf
[NAM$C_MAXRSS
+1];
4012 /* translate a vms file spec to a unix path */
4014 sys_translate_vms (vfile
)
4025 /* leading device or logical name is a root directory */
4026 if (p
= strchr (vfile
, ':'))
4035 if (*p
== '[' || *p
== '<')
4037 while (*++vfile
!= *p
+ 2)
4041 if (vfile
[-1] == *p
)
4064 static char utbuf
[NAM$C_MAXRSS
+1];
4066 /* translate a unix path to a VMS file spec */
4068 sys_translate_unix (ufile
)
4091 if (index (&ufile
[1], '/'))
4098 if (index (&ufile
[1], '/'))
4105 if (strncmp (ufile
, "./", 2) == 0)
4112 ufile
++; /* skip the dot */
4113 if (index (&ufile
[1], '/'))
4118 else if (strncmp (ufile
, "../", 3) == 0)
4126 ufile
+= 2; /* skip the dots */
4127 if (index (&ufile
[1], '/'))
4152 extern char *getcwd ();
4154 #define MAXPATHLEN 1024
4156 ptr
= xmalloc (MAXPATHLEN
);
4157 val
= getcwd (ptr
, MAXPATHLEN
);
4163 strcpy (pathname
, ptr
);
4172 long item_code
= JPI$_OWNER
;
4173 unsigned long parent_id
;
4176 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4179 vaxc$errno
= status
;
4189 return (getgid () << 16) | getuid ();
4194 sys_read (fildes
, buf
, nbyte
)
4199 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4204 sys_write (fildes
, buf
, nbyte
)
4209 register int nwrote
, rtnval
= 0;
4211 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4217 return rtnval
? rtnval
: -1;
4218 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4219 return rtnval
? rtnval
: -1;
4220 return (rtnval
+ nwrote
);
4225 * VAX/VMS VAX C RTL really loses. It insists that records
4226 * end with a newline (carriage return) character, and if they
4227 * don't it adds one (nice of it isn't it!)
4229 * Thus we do this stupidity below.
4234 sys_write (fildes
, buf
, nbytes
)
4237 unsigned int nbytes
;
4244 fstat (fildes
, &st
);
4250 /* Handle fixed-length files with carriage control. */
4251 if (st
.st_fab_rfm
== FAB$C_FIX
4252 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4254 len
= st
.st_fab_mrs
;
4255 retval
= write (fildes
, p
, min (len
, nbytes
));
4258 retval
++; /* This skips the implied carriage control */
4262 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4263 while (*e
!= '\n' && e
> p
) e
--;
4264 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4265 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4267 retval
= write (fildes
, p
, len
);
4278 /* Create file NEW copying its attributes from file OLD. If
4279 OLD is 0 or does not exist, create based on the value of
4282 /* Protection value the file should ultimately have.
4283 Set by create_copy_attrs, and use by rename_sansversions. */
4284 static unsigned short int fab_final_pro
;
4287 creat_copy_attrs (old
, new)
4290 struct FAB fab
= cc$rms_fab
;
4291 struct XABPRO xabpro
;
4292 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4293 extern int vms_stmlf_recfm
;
4297 fab
.fab$b_fac
= FAB$M_GET
;
4298 fab
.fab$l_fna
= old
;
4299 fab
.fab$b_fns
= strlen (old
);
4300 fab
.fab$l_xab
= (char *) &xabpro
;
4301 xabpro
= cc$rms_xabpro
;
4302 xabpro
.xab$l_aclbuf
= aclbuf
;
4303 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4304 /* Call $OPEN to fill in the fab & xabpro fields. */
4305 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4307 SYS$
CLOSE (&fab
, 0, 0);
4308 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4309 if (xabpro
.xab$w_acllen
> 0)
4311 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4312 /* If the acl buffer was too short, redo open with longer one.
4313 Wouldn't need to do this if there were some system imposed
4314 limit on the size of an ACL, but I can't find any such. */
4316 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4317 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4318 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4319 SYS$
CLOSE (&fab
, 0, 0);
4325 xabpro
.xab$l_aclbuf
= 0;
4330 fab
.fab$l_fna
= new;
4331 fab
.fab$b_fns
= strlen (new);
4335 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4336 fab
.fab$b_rat
= FAB$M_CR
;
4339 /* Set the file protections such that we will be able to manipulate
4340 this file. Once we are done writing and renaming it, we will set
4341 the protections back. */
4343 fab_final_pro
= xabpro
.xab$w_pro
;
4345 SYS$
SETDFPROT (0, &fab_final_pro
);
4346 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4348 /* Create the new file with either default attrs or attrs copied
4350 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4352 SYS$
CLOSE (&fab
, 0, 0);
4353 /* As this is a "replacement" for creat, return a file descriptor
4354 opened for writing. */
4355 return open (new, O_WRONLY
);
4360 #include <varargs.h>
4363 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4368 sys_creat (va_alist
)
4371 va_list list_incrementer
;
4374 int rfd
; /* related file descriptor */
4375 int fd
; /* Our new file descriptor */
4382 extern int vms_stmlf_recfm
;
4385 va_start (list_incrementer
);
4386 name
= va_arg (list_incrementer
, char *);
4387 mode
= va_arg (list_incrementer
, int);
4389 rfd
= va_arg (list_incrementer
, int);
4390 va_end (list_incrementer
);
4393 /* Use information from the related file descriptor to set record
4394 format of the newly created file. */
4395 fstat (rfd
, &st_buf
);
4396 switch (st_buf
.st_fab_rfm
)
4399 strcpy (rfm
, "rfm = fix");
4400 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4401 strcpy (rat
, "rat = ");
4402 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4404 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4405 strcat (rat
, "ftn");
4406 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4407 strcat (rat
, "prn");
4408 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4409 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4410 strcat (rat
, ", blk");
4412 strcat (rat
, "blk");
4413 return creat (name
, 0, rfm
, rat
, mrs
);
4416 strcpy (rfm
, "rfm = vfc");
4417 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4418 strcpy (rat
, "rat = ");
4419 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4421 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4422 strcat (rat
, "ftn");
4423 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4424 strcat (rat
, "prn");
4425 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4426 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4427 strcat (rat
, ", blk");
4429 strcat (rat
, "blk");
4430 return creat (name
, 0, rfm
, rat
, fsz
);
4433 strcpy (rfm
, "rfm = stm");
4437 strcpy (rfm
, "rfm = stmcr");
4441 strcpy (rfm
, "rfm = stmlf");
4445 strcpy (rfm
, "rfm = udf");
4449 strcpy (rfm
, "rfm = var");
4452 strcpy (rat
, "rat = ");
4453 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4455 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4456 strcat (rat
, "ftn");
4457 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4458 strcat (rat
, "prn");
4459 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4460 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4461 strcat (rat
, ", blk");
4463 strcat (rat
, "blk");
4467 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4468 strcpy (rat
, "rat=cr");
4470 /* Until the VAX C RTL fixes the many bugs with modes, always use
4471 mode 0 to get the user's default protection. */
4472 fd
= creat (name
, 0, rfm
, rat
);
4473 if (fd
< 0 && errno
== EEXIST
)
4475 if (unlink (name
) < 0)
4476 report_file_error ("delete", build_string (name
));
4477 fd
= creat (name
, 0, rfm
, rat
);
4483 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4485 sys_fwrite (ptr
, size
, num
, fp
)
4486 register char * ptr
;
4489 register int tot
= num
* size
;
4497 * The VMS C library routine creat actually creates a new version of an
4498 * existing file rather than truncating the old version. There are times
4499 * when this is not the desired behavior, for instance, when writing an
4500 * auto save file (you only want one version), or when you don't have
4501 * write permission in the directory containing the file (but the file
4502 * itself is writable). Hence this routine, which is equivalent to
4503 * "close (creat (fn, 0));" on Unix if fn already exists.
4509 struct FAB xfab
= cc$rms_fab
;
4510 struct RAB xrab
= cc$rms_rab
;
4513 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4514 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4515 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4516 xfab
.fab$l_fna
= fn
;
4517 xfab
.fab$b_fns
= strlen (fn
);
4518 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4520 xrab
.rab$l_fab
= &xfab
;
4522 /* This gibberish opens the file, positions to the first record, and
4523 deletes all records from there until the end of file. */
4524 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4526 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4527 (SYS$
FIND (&xrab
) & 01) == 01 &&
4528 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4539 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4540 SYSPRV or a readable SYSUAF.DAT. */
4546 * Routine to read the VMS User Authorization File and return
4547 * a specific user's record.
4550 static struct UAF retuaf
;
4553 get_uaf_name (uname
)
4560 uaf_fab
= cc$rms_fab
;
4561 uaf_rab
= cc$rms_rab
;
4562 /* initialize fab fields */
4563 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4564 uaf_fab
.fab$b_fns
= 21;
4565 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4566 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4567 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4568 /* initialize rab fields */
4569 uaf_rab
.rab$l_fab
= &uaf_fab
;
4570 /* open the User Authorization File */
4571 status
= SYS$
OPEN (&uaf_fab
);
4575 vaxc$errno
= status
;
4578 status
= SYS$
CONNECT (&uaf_rab
);
4582 vaxc$errno
= status
;
4585 /* read the requested record - index is in uname */
4586 uaf_rab
.rab$l_kbf
= uname
;
4587 uaf_rab
.rab$b_ksz
= strlen (uname
);
4588 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4589 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4590 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4591 status
= SYS$
GET (&uaf_rab
);
4595 vaxc$errno
= status
;
4598 /* close the User Authorization File */
4599 status
= SYS$
DISCONNECT (&uaf_rab
);
4603 vaxc$errno
= status
;
4606 status
= SYS$
CLOSE (&uaf_fab
);
4610 vaxc$errno
= status
;
4624 uaf_fab
= cc$rms_fab
;
4625 uaf_rab
= cc$rms_rab
;
4626 /* initialize fab fields */
4627 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4628 uaf_fab
.fab$b_fns
= 21;
4629 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4630 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4631 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4632 /* initialize rab fields */
4633 uaf_rab
.rab$l_fab
= &uaf_fab
;
4634 /* open the User Authorization File */
4635 status
= SYS$
OPEN (&uaf_fab
);
4639 vaxc$errno
= status
;
4642 status
= SYS$
CONNECT (&uaf_rab
);
4646 vaxc$errno
= status
;
4649 /* read the requested record - index is in uic */
4650 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4651 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4652 uaf_rab
.rab$b_ksz
= sizeof uic
;
4653 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4654 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4655 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4656 status
= SYS$
GET (&uaf_rab
);
4660 vaxc$errno
= status
;
4663 /* close the User Authorization File */
4664 status
= SYS$
DISCONNECT (&uaf_rab
);
4668 vaxc$errno
= status
;
4671 status
= SYS$
CLOSE (&uaf_fab
);
4675 vaxc$errno
= status
;
4681 static struct passwd retpw
;
4689 /* copy these out first because if the username is 32 chars, the next
4690 section will overwrite the first byte of the UIC */
4691 retpw
.pw_uid
= up
->uaf$w_mem
;
4692 retpw
.pw_gid
= up
->uaf$w_grp
;
4694 /* I suppose this is not the best style, to possibly overwrite one
4695 byte beyond the end of the field, but what the heck... */
4696 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4697 while (ptr
[-1] == ' ')
4700 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4702 /* the rest of these are counted ascii strings */
4703 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4704 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4705 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4706 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4707 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4708 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4709 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4710 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4714 #else /* not READ_SYSUAF */
4715 static struct passwd retpw
;
4716 #endif /* not READ_SYSUAF */
4727 unsigned char * full
;
4728 #endif /* READ_SYSUAF */
4733 if ('a' <= *ptr
&& *ptr
<= 'z')
4738 if (!(up
= get_uaf_name (name
)))
4740 return cnv_uaf_pw (up
);
4742 if (strcmp (name
, getenv ("USER")) == 0)
4744 retpw
.pw_uid
= getuid ();
4745 retpw
.pw_gid
= getgid ();
4746 strcpy (retpw
.pw_name
, name
);
4747 if (full
= egetenv ("FULLNAME"))
4748 strcpy (retpw
.pw_gecos
, full
);
4750 *retpw
.pw_gecos
= '\0';
4751 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4752 *retpw
.pw_shell
= '\0';
4757 #endif /* not READ_SYSUAF */
4767 if (!(up
= get_uaf_uic (uid
)))
4769 return cnv_uaf_pw (up
);
4771 if (uid
== sys_getuid ())
4772 return getpwnam (egetenv ("USER"));
4775 #endif /* not READ_SYSUAF */
4778 /* return total address space available to the current process. This is
4779 the sum of the current p0 size, p1 size and free page table entries
4785 unsigned long free_pages
;
4786 unsigned long frep0va
;
4787 unsigned long frep1va
;
4790 item_code
= JPI$_FREPTECNT
;
4791 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4794 vaxc$errno
= status
;
4799 item_code
= JPI$_FREP0VA
;
4800 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4803 vaxc$errno
= status
;
4806 item_code
= JPI$_FREP1VA
;
4807 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4810 vaxc$errno
= status
;
4814 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4818 define_logical_name (varname
, string
)
4822 struct dsc$descriptor_s strdsc
=
4823 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4824 struct dsc$descriptor_s envdsc
=
4825 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4826 struct dsc$descriptor_s lnmdsc
=
4827 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4829 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4833 delete_logical_name (varname
)
4836 struct dsc$descriptor_s envdsc
=
4837 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4838 struct dsc$descriptor_s lnmdsc
=
4839 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4841 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4859 error ("execvp system call not implemented");
4868 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4869 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4870 char from_esn
[NAM$C_MAXRSS
];
4871 char to_esn
[NAM$C_MAXRSS
];
4873 from_fab
.fab$l_fna
= from
;
4874 from_fab
.fab$b_fns
= strlen (from
);
4875 from_fab
.fab$l_nam
= &from_nam
;
4876 from_fab
.fab$l_fop
= FAB$M_NAM
;
4878 from_nam
.nam$l_esa
= from_esn
;
4879 from_nam
.nam$b_ess
= sizeof from_esn
;
4881 to_fab
.fab$l_fna
= to
;
4882 to_fab
.fab$b_fns
= strlen (to
);
4883 to_fab
.fab$l_nam
= &to_nam
;
4884 to_fab
.fab$l_fop
= FAB$M_NAM
;
4886 to_nam
.nam$l_esa
= to_esn
;
4887 to_nam
.nam$b_ess
= sizeof to_esn
;
4889 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4895 if (status
== RMS$_DEV
)
4899 vaxc$errno
= status
;
4904 /* This function renames a file like `rename', but it strips
4905 the version number from the "to" filename, such that the "to" file is
4906 will always be a new version. It also sets the file protection once it is
4907 finished. The protection that we will use is stored in fab_final_pro,
4908 and was set when we did a creat_copy_attrs to create the file that we
4911 We could use the chmod function, but Eunichs uses 3 bits per user category
4912 to describe the protection, and VMS uses 4 (write and delete are separate
4913 bits). To maintain portability, the VMS implementation of `chmod' wires
4914 the W and D bits together. */
4917 static struct fibdef fib
; /* We need this initialized to zero */
4918 char vms_file_written
[NAM$C_MAXRSS
];
4921 rename_sans_version (from
,to
)
4928 struct FAB to_fab
= cc$rms_fab
;
4929 struct NAM to_nam
= cc$rms_nam
;
4930 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4931 struct dsc$descriptor fib_attr
[2]
4932 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4933 char to_esn
[NAM$C_MAXRSS
];
4935 $
DESCRIPTOR (disk
,to_esn
);
4937 to_fab
.fab$l_fna
= to
;
4938 to_fab
.fab$b_fns
= strlen (to
);
4939 to_fab
.fab$l_nam
= &to_nam
;
4940 to_fab
.fab$l_fop
= FAB$M_NAM
;
4942 to_nam
.nam$l_esa
= to_esn
;
4943 to_nam
.nam$b_ess
= sizeof to_esn
;
4945 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4947 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4948 *(to_nam
.nam$l_ver
) = '\0';
4950 stat
= rename (from
, to_esn
);
4954 strcpy (vms_file_written
, to_esn
);
4956 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4957 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4959 /* Now set the file protection to the correct value */
4960 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4962 /* Copy these fields into the fib */
4963 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4964 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4965 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4967 SYS$
CLOSE (&to_fab
, 0, 0);
4969 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4972 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4973 0, 0, 0, &fib_attr
, 0);
4976 stat
= SYS$
DASSGN (chan
);
4979 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4990 unsigned short fid
[3];
4991 char esa
[NAM$C_MAXRSS
];
4994 fab
.fab$l_fop
= FAB$M_OFP
;
4995 fab
.fab$l_fna
= file
;
4996 fab
.fab$b_fns
= strlen (file
);
4997 fab
.fab$l_nam
= &nam
;
5000 nam
.nam$l_esa
= esa
;
5001 nam
.nam$b_ess
= NAM$C_MAXRSS
;
5003 status
= SYS$
PARSE (&fab
);
5004 if ((status
& 1) == 0)
5007 vaxc$errno
= status
;
5010 status
= SYS$
SEARCH (&fab
);
5011 if ((status
& 1) == 0)
5014 vaxc$errno
= status
;
5018 fid
[0] = nam
.nam$w_fid
[0];
5019 fid
[1] = nam
.nam$w_fid
[1];
5020 fid
[2] = nam
.nam$w_fid
[2];
5022 fab
.fab$l_fna
= new;
5023 fab
.fab$b_fns
= strlen (new);
5025 status
= SYS$
PARSE (&fab
);
5026 if ((status
& 1) == 0)
5029 vaxc$errno
= status
;
5033 nam
.nam$w_fid
[0] = fid
[0];
5034 nam
.nam$w_fid
[1] = fid
[1];
5035 nam
.nam$w_fid
[2] = fid
[2];
5037 nam
.nam$l_esa
= nam
.nam$l_name
;
5038 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
5040 status
= SYS$
ENTER (&fab
);
5041 if ((status
& 1) == 0)
5044 vaxc$errno
= status
;
5055 printf ("%s not yet implemented\r\n", badfunc
);
5063 /* Arrange to return a range centered on zero. */
5064 return rand () - (1 << 30);
5076 /* Called from init_sys_modes. */
5082 /* If we're not on an HFT we shouldn't do any of this. We determine
5083 if we are on an HFT by trying to get an HFT error code. If this
5084 call fails, we're not on an HFT. */
5086 if (ioctl (0, HFQERROR
, &junk
) < 0)
5088 #else /* not IBMR2AIX */
5089 if (ioctl (0, HFQEIO
, 0) < 0)
5091 #endif /* not IBMR2AIX */
5093 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5094 as the rubout key's ASCII code. Here this is changed. The bug is that
5095 there's no way to determine the old mapping, so in reset_sys_modes
5096 we need to assume that the normal map had been present. Of course, this
5097 code also doesn't help if on a terminal emulator which doesn't understand
5101 struct hfkeymap keymap
;
5103 buf
.hf_bufp
= (char *)&keymap
;
5104 buf
.hf_buflen
= sizeof (keymap
);
5105 keymap
.hf_nkeys
= 2;
5106 keymap
.hfkey
[0].hf_kpos
= 15;
5107 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5109 keymap
.hfkey
[0].hf_keyidh
= '<';
5110 #else /* not IBMR2AIX */
5111 keymap
.hfkey
[0].hf_page
= '<';
5112 #endif /* not IBMR2AIX */
5113 keymap
.hfkey
[0].hf_char
= 127;
5114 keymap
.hfkey
[1].hf_kpos
= 15;
5115 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5117 keymap
.hfkey
[1].hf_keyidh
= '<';
5118 #else /* not IBMR2AIX */
5119 keymap
.hfkey
[1].hf_page
= '<';
5120 #endif /* not IBMR2AIX */
5121 keymap
.hfkey
[1].hf_char
= 127;
5122 hftctl (0, HFSKBD
, &buf
);
5124 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5126 line_ins_del_ok
= char_ins_del_ok
= 0;
5129 /* Reset the rubout key to backspace. */
5135 struct hfkeymap keymap
;
5139 if (ioctl (0, HFQERROR
, &junk
) < 0)
5141 #else /* not IBMR2AIX */
5142 if (ioctl (0, HFQEIO
, 0) < 0)
5144 #endif /* not IBMR2AIX */
5146 buf
.hf_bufp
= (char *)&keymap
;
5147 buf
.hf_buflen
= sizeof (keymap
);
5148 keymap
.hf_nkeys
= 2;
5149 keymap
.hfkey
[0].hf_kpos
= 15;
5150 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5152 keymap
.hfkey
[0].hf_keyidh
= '<';
5153 #else /* not IBMR2AIX */
5154 keymap
.hfkey
[0].hf_page
= '<';
5155 #endif /* not IBMR2AIX */
5156 keymap
.hfkey
[0].hf_char
= 8;
5157 keymap
.hfkey
[1].hf_kpos
= 15;
5158 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5160 keymap
.hfkey
[1].hf_keyidh
= '<';
5161 #else /* not IBMR2AIX */
5162 keymap
.hfkey
[1].hf_page
= '<';
5163 #endif /* not IBMR2AIX */
5164 keymap
.hfkey
[1].hf_char
= 8;
5165 hftctl (0, HFSKBD
, &buf
);
5172 /* These are included on Sunos 4.1 when we do not use shared libraries.
5173 X11 libraries may refer to these functions but (we hope) do not
5174 actually call them. */
5194 #endif /* USE_DL_STUBS */
5203 register int length
;
5207 long max_str
= 65535;
5209 while (length
> max_str
) {
5210 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5215 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5217 while (length
-- > 0)
5219 #endif /* not VMS */
5222 #endif /* no bzero */
5223 #endif /* BSTRING */
5225 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5228 /* Saying `void' requires a declaration, above, where bcopy is used
5229 and that declaration causes pain for systems where bcopy is a macro. */
5230 bcopy (b1
, b2
, length
)
5233 register int length
;
5236 long max_str
= 65535;
5238 while (length
> max_str
) {
5239 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5245 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5247 while (length
-- > 0)
5249 #endif /* not VMS */
5251 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5256 bcmp (b1
, b2
, length
) /* This could be a macro! */
5259 register int length
;
5262 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5263 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5265 return STR$
COMPARE (&src1
, &src2
);
5267 while (length
-- > 0)
5272 #endif /* not VMS */
5274 #endif /* no bcmp */
5275 #endif /* not BSTRING */
5277 #ifndef HAVE_STRSIGNAL
5284 if (0 <= code
&& code
< NSIG
)
5287 signame
= sys_errlist
[code
];
5289 /* Cast to suppress warning if the table has const char *. */
5290 signame
= (char *) sys_siglist
[code
];
5296 #endif /* HAVE_STRSIGNAL */