1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 86,87,88,93,94,95, 1999 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
30 #include "blockinput.h"
34 /* It is essential to include stdlib.h so that this file picks up
35 the correct definitions of rand, srand, and RAND_MAX.
36 Otherwise random numbers will not work correctly. */
40 /* Nonzero means delete a process right away if it exits (process.c). */
41 static int delete_exited_processes
;
43 #endif /* macintosh */
45 #define min(x,y) ((x) > (y) ? (y) : (x))
49 #define write sys_write
54 #endif /* not WINDOWSNT */
56 /* Does anyone other than VMS need this? */
58 #define sys_fwrite fwrite
67 #endif /* TRY_AGAIN */
70 #include <sys/types.h>
74 /* Get _POSIX_VDISABLE, if it is available. */
84 #if !defined (USG) || defined (BSD_PGRPS)
86 #define setpgrp setpgid
90 /* Get SI_SRPC_DOMAIN, if it is available. */
91 #ifdef HAVE_SYS_SYSTEMINFO_H
92 #include <sys/systeminfo.h>
95 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
99 #include <sys/param.h>
103 extern unsigned start
__asm__ ("start");
125 #include <sys/file.h>
133 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
137 #ifdef BSD_SYSTEM /* avoid writing defined (BSD_SYSTEM) || defined (USG)
138 because the vms compiler doesn't grok `defined' */
146 #endif /* not 4.1 bsd */
149 #include <sys/ioctl.h>
155 #ifdef BROKEN_TIOCGWINSZ
160 #if defined (USG) || defined (DGUX)
161 #include <sys/utsname.h>
162 #ifndef MEMORY_IN_STRING_H
165 #if defined (TIOCGWINSZ) || defined (ISC4_0)
167 #include <sys/sioctl.h>
170 #include <sys/stream.h>
171 #include <sys/ptem.h>
173 #endif /* TIOCGWINSZ or ISC4_0 */
174 #endif /* USG or DGUX */
176 extern int quit_char
;
178 #include "keyboard.h"
181 #include "termhooks.h"
182 #include "termchar.h"
183 #include "termopts.h"
184 #include "dispextern.h"
189 /* In process.h which conflicts with the local copy. */
191 int _CRTAPI1
_spawnlp (int, const char *, const char *, ...);
192 int _CRTAPI1
_getpid (void);
195 #ifdef NONSYSTEM_DIR_LIBRARY
197 #endif /* NONSYSTEM_DIR_LIBRARY */
199 #include "syssignal.h"
206 #ifndef HAVE_STRUCT_UTIMBUF
207 /* We want to use utime rather than utimes, but we couldn't find the
208 structure declaration. We'll use the traditional one. */
216 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
222 #define LNOFLSH 0100000
225 static int baud_convert
[] =
230 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
231 1800, 2400, 4800, 9600, 19200, 38400
237 extern speed_t ospeed
;
239 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
242 #if defined (HAVE_TERMIOS_H) && defined (LINUX)
244 /* HJL's version of libc is said to need this on the Alpha.
245 On the other hand, DEC OSF1 on the Alpha needs ospeed to be a short. */
246 extern speed_t ospeed
;
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 ospeed
= sg
.xmit_baud
;
365 tcgetattr (input_fd
, &sg
);
366 ospeed
= cfgetospeed (&sg
);
367 #if defined (USE_GETOBAUD) && defined (getobaud)
368 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
370 ospeed
= getobaud (sg
.c_cflag
);
372 #else /* neither VMS nor TERMIOS */
378 tcgetattr (input_fd
, &sg
);
380 ioctl (input_fd
, TCGETA
, &sg
);
382 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 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
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
398 ? baud_convert
[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 */
2294 Vsystem_name
= build_string (sysname
);
2298 if ((sp
= egetenv ("SYS$NODE")) == 0)
2299 Vsystem_name
= build_string ("vax-vms");
2300 else if ((end
= index (sp
, ':')) == 0)
2301 Vsystem_name
= build_string (sp
);
2303 Vsystem_name
= make_string (sp
, end
- sp
);
2305 #ifndef HAVE_GETHOSTNAME
2308 Vsystem_name
= build_string (uts
.nodename
);
2309 #else /* HAVE_GETHOSTNAME */
2310 unsigned int hostname_size
= 256;
2311 char *hostname
= (char *) alloca (hostname_size
);
2313 /* Try to get the host name; if the buffer is too short, try
2314 again. Apparently, the only indication gethostname gives of
2315 whether the buffer was large enough is the presence or absence
2316 of a '\0' in the string. Eech. */
2319 gethostname (hostname
, hostname_size
- 1);
2320 hostname
[hostname_size
- 1] = '\0';
2322 /* Was the buffer large enough for the '\0'? */
2323 if (strlen (hostname
) < hostname_size
- 1)
2326 hostname_size
<<= 1;
2327 hostname
= (char *) alloca (hostname_size
);
2330 /* Turn the hostname into the official, fully-qualified hostname.
2331 Don't do this if we're going to dump; this can confuse system
2332 libraries on some machines and make the dumped emacs core dump. */
2335 #endif /* not CANNOT_DUMP */
2336 if (! index (hostname
, '.'))
2340 for (count
= 0;; count
++)
2345 hp
= gethostbyname (hostname
);
2347 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2352 Fsleep_for (make_number (1), Qnil
);
2356 char *fqdn
= (char *) hp
->h_name
;
2359 if (!index (fqdn
, '.'))
2361 /* We still don't have a fully qualified domain name.
2362 Try to find one in the list of alternate names */
2363 char **alias
= hp
->h_aliases
;
2364 while (*alias
&& !index (*alias
, '.'))
2371 /* Convert the host name to lower case. */
2372 /* Using ctype.h here would introduce a possible locale
2373 dependence that is probably wrong for hostnames. */
2377 if (*p
>= 'A' && *p
<= 'Z')
2384 #endif /* HAVE_SOCKETS */
2385 /* We used to try using getdomainname here,
2386 but NIIBE Yutaka <gniibe@etl.go.jp> says that
2387 getdomainname gets the NIS/YP domain which often is not the same
2388 as in Internet domain name. */
2389 #if 0 /* Turned off because sysinfo is not really likely to return the
2390 correct Internet domain. */
2391 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2392 if (! index (hostname
, '.'))
2394 /* The hostname is not fully qualified. Append the domain name. */
2396 int hostlen
= strlen (hostname
);
2397 int domain_size
= 256;
2401 char *domain
= (char *) alloca (domain_size
+ 1);
2402 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2403 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2404 if (sys_domain_size
<= 0)
2406 if (domain_size
< sys_domain_size
)
2408 domain_size
= sys_domain_size
;
2411 strcpy (fqdn
, hostname
);
2412 if (domain
[0] == '.')
2413 strcpy (fqdn
+ hostlen
, domain
);
2414 else if (domain
[0] != 0)
2416 fqdn
[hostlen
] = '.';
2417 strcpy (fqdn
+ hostlen
+ 1, domain
);
2423 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2425 Vsystem_name
= build_string (hostname
);
2426 #endif /* HAVE_GETHOSTNAME */
2431 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2432 if (*p
== ' ' || *p
== '\t')
2439 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2441 #include "sysselect.h"
2444 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2445 /* Cause explanatory error message at compile time,
2446 since the select emulation is not good enough for X. */
2447 int *x
= &x_windows_lose_if_no_select_system_call
;
2450 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2451 * Only checks read descriptors.
2453 /* How long to wait between checking fds in select */
2454 #define SELECT_PAUSE 1
2457 /* For longjmp'ing back to read_input_waiting. */
2459 jmp_buf read_alarm_throw
;
2461 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2462 The read_socket_hook function sets this to 1 while it is waiting. */
2464 int read_alarm_should_throw
;
2472 #else /* not BSD4_1 */
2473 signal (SIGALRM
, SIG_IGN
);
2474 #endif /* not BSD4_1 */
2475 if (read_alarm_should_throw
)
2476 longjmp (read_alarm_throw
, 1);
2480 /* Only rfds are checked. */
2482 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2484 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2485 EMACS_TIME
*timeout
;
2491 extern int proc_buffered_char
[];
2492 #ifndef subprocesses
2493 int process_tick
= 0, update_tick
= 0;
2495 extern int process_tick
, update_tick
;
2499 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2500 /* If we're using X, then the native select will work; we only need the
2501 emulation for non-X usage. */
2502 if (!NILP (Vwindow_system
))
2503 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2505 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2506 local_timeout
= &timeoutval
;
2518 /* If we are looking only for the terminal, with no timeout,
2519 just read it and wait -- that's more efficient. */
2520 if (*local_timeout
== 100000 && process_tick
== update_tick
2521 && FD_ISSET (0, &orfds
))
2524 for (fd
= 1; fd
< nfds
; ++fd
)
2525 if (FD_ISSET (fd
, &orfds
))
2527 if (! detect_input_pending ())
2528 read_input_waiting ();
2534 /* Once a second, till the timer expires, check all the flagged read
2535 * descriptors to see if any input is available. If there is some then
2536 * set the corresponding bit in the return copy of rfds.
2540 register int to_check
, fd
;
2544 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2546 if (FD_ISSET (fd
, &orfds
))
2548 int avail
= 0, status
= 0;
2551 avail
= detect_input_pending (); /* Special keyboard handler */
2555 status
= ioctl (fd
, FIONREAD
, &avail
);
2556 #else /* no FIONREAD */
2557 /* Hoping it will return -1 if nothing available
2558 or 0 if all 0 chars requested are read. */
2559 if (proc_buffered_char
[fd
] >= 0)
2563 avail
= read (fd
, &buf
, 1);
2565 proc_buffered_char
[fd
] = buf
;
2567 #endif /* no FIONREAD */
2569 if (status
>= 0 && avail
> 0)
2577 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2580 turn_on_atimers (0);
2581 signal (SIGALRM
, select_alarm
);
2583 alarm (SELECT_PAUSE
);
2585 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2586 while (select_alarmed
== 0 && *local_timeout
!= 0
2587 && process_tick
== update_tick
)
2589 /* If we are interested in terminal input,
2590 wait by reading the terminal.
2591 That makes instant wakeup for terminal input at least. */
2592 if (FD_ISSET (0, &orfds
))
2594 read_input_waiting ();
2595 if (detect_input_pending ())
2601 (*local_timeout
) -= SELECT_PAUSE
;
2603 /* Reset the old alarm if there was one. */
2604 turn_on_atimers (1);
2606 if (*local_timeout
== 0) /* Stop on timer being cleared */
2611 #endif /* not WINDOWSNT */
2613 /* Read keyboard input into the standard buffer,
2614 waiting for at least one character. */
2616 /* Make all keyboard buffers much bigger when using a window system. */
2617 #ifdef HAVE_WINDOW_SYSTEM
2618 #define BUFFER_SIZE_FACTOR 16
2620 #define BUFFER_SIZE_FACTOR 1
2624 read_input_waiting ()
2626 struct input_event e
;
2628 extern int quit_char
;
2630 if (read_socket_hook
)
2632 struct input_event buf
[256];
2634 read_alarm_should_throw
= 0;
2635 if (! setjmp (read_alarm_throw
))
2636 nread
= (*read_socket_hook
) (0, buf
, 256, 1);
2640 /* Scan the chars for C-g and store them in kbd_buffer. */
2641 for (i
= 0; i
< nread
; i
++)
2643 kbd_buffer_store_event (&buf
[i
]);
2644 /* Don't look at input that follows a C-g too closely.
2645 This reduces lossage due to autorepeat on C-g. */
2646 if (buf
[i
].kind
== ascii_keystroke
2647 && buf
[i
].code
== quit_char
)
2654 nread
= read (fileno (stdin
), buf
, 1);
2656 /* Scan the chars for C-g and store them in kbd_buffer. */
2657 e
.kind
= ascii_keystroke
;
2658 e
.frame_or_window
= selected_frame
;
2660 for (i
= 0; i
< nread
; i
++)
2662 /* Convert chars > 0177 to meta events if desired.
2663 We do this under the same conditions that read_avail_input does. */
2664 if (read_socket_hook
== 0)
2666 /* If the user says she has a meta key, then believe her. */
2667 if (meta_key
== 1 && (buf
[i
] & 0x80))
2668 e
.modifiers
= meta_modifier
;
2673 XSETINT (e
.code
, buf
[i
]);
2674 kbd_buffer_store_event (&e
);
2675 /* Don't look at input that follows a C-g too closely.
2676 This reduces lossage due to autorepeat on C-g. */
2677 if (buf
[i
] == quit_char
)
2683 #endif /* not HAVE_SELECT */
2684 #endif /* not VMS */
2685 #endif /* not MSDOS */
2694 lmode
= LINTRUP
| lmode
;
2695 ioctl (fd
, TIOCLSET
, &lmode
);
2703 lmode
= ~LINTRUP
& lmode
;
2704 ioctl (0, TIOCLSET
, &lmode
);
2712 interrupts_deferred
= 0;
2720 interrupts_deferred
= 1;
2723 /* still inside #ifdef BSD4_1 */
2726 int sigheld
; /* Mask of held signals */
2732 sigheld
|= sigbit (signum
);
2740 sigheld
|= sigbit (signum
);
2747 sigheld
&= ~sigbit (signum
);
2752 sigfree () /* Free all held signals */
2755 for (i
= 0; i
< NSIG
; i
++)
2756 if (sigheld
& sigbit (i
))
2764 return 1 << (i
- 1);
2766 #endif /* subprocesses */
2769 /* POSIX signals support - DJB */
2770 /* Anyone with POSIX signals should have ANSI C declarations */
2772 #ifdef POSIX_SIGNALS
2774 sigset_t empty_mask
, full_mask
;
2777 sys_signal (int signal_number
, signal_handler_t action
)
2779 struct sigaction new_action
, old_action
;
2780 sigemptyset (&new_action
.sa_mask
);
2781 new_action
.sa_handler
= action
;
2783 /* Emacs mostly works better with restartable system services. If this
2784 * flag exists, we probably want to turn it on here.
2786 new_action
.sa_flags
= SA_RESTART
;
2788 new_action
.sa_flags
= 0;
2790 sigaction (signal_number
, &new_action
, &old_action
);
2791 return (old_action
.sa_handler
);
2795 /* If we're compiling with GCC, we don't need this function, since it
2796 can be written as a macro. */
2798 sys_sigmask (int sig
)
2801 sigemptyset (&mask
);
2802 sigaddset (&mask
, sig
);
2807 /* I'd like to have these guys return pointers to the mask storage in here,
2808 but there'd be trouble if the code was saving multiple masks. I'll be
2809 safe and pass the structure. It normally won't be more than 2 bytes
2813 sys_sigblock (sigset_t new_mask
)
2816 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2821 sys_sigunblock (sigset_t new_mask
)
2824 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2829 sys_sigsetmask (sigset_t new_mask
)
2832 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2836 #endif /* POSIX_SIGNALS */
2838 #if !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED
2839 static char *my_sys_siglist
[NSIG
];
2843 # define sys_siglist my_sys_siglist
2849 #ifdef POSIX_SIGNALS
2850 sigemptyset (&empty_mask
);
2851 sigfillset (&full_mask
);
2854 #if !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED
2858 sys_siglist
[SIGABRT
] = "Aborted";
2861 sys_siglist
[SIGAIO
] = "LAN I/O interrupt";
2864 sys_siglist
[SIGALRM
] = "Alarm clock";
2867 sys_siglist
[SIGBUS
] = "Bus error";
2870 sys_siglist
[SIGCLD
] = "Child status changed";
2873 sys_siglist
[SIGCHLD
] = "Child status changed";
2876 sys_siglist
[SIGCONT
] = "Continued";
2879 sys_siglist
[SIGDANGER
] = "Swap space dangerously low";
2882 sys_siglist
[SIGDGNOTIFY
] = "Notification message in queue";
2885 sys_siglist
[SIGEMT
] = "Emulation trap";
2888 sys_siglist
[SIGFPE
] = "Arithmetic exception";
2891 sys_siglist
[SIGFREEZE
] = "SIGFREEZE";
2894 sys_siglist
[SIGGRANT
] = "Monitor mode granted";
2897 sys_siglist
[SIGHUP
] = "Hangup";
2900 sys_siglist
[SIGILL
] = "Illegal instruction";
2903 sys_siglist
[SIGINT
] = "Interrupt";
2906 sys_siglist
[SIGIO
] = "I/O possible";
2909 sys_siglist
[SIGIOINT
] = "I/O intervention required";
2912 sys_siglist
[SIGIOT
] = "IOT trap";
2915 sys_siglist
[SIGKILL
] = "Killed";
2918 sys_siglist
[SIGLOST
] = "Resource lost";
2921 sys_siglist
[SIGLWP
] = "SIGLWP";
2924 sys_siglist
[SIGMSG
] = "Monitor mode data available";
2927 sys_siglist
[SIGWIND
] = "SIGPHONE";
2930 sys_siglist
[SIGPIPE
] = "Broken pipe";
2933 sys_siglist
[SIGPOLL
] = "Pollable event occurred";
2936 sys_siglist
[SIGPROF
] = "Profiling timer expired";
2939 sys_siglist
[SIGPTY
] = "PTY I/O interrupt";
2942 sys_siglist
[SIGPWR
] = "Power-fail restart";
2945 sys_siglist
[SIGQUIT
] = "Quit";
2948 sys_siglist
[SIGRETRACT
] = "Need to relinguish monitor mode";
2951 sys_siglist
[SIGSAK
] = "Secure attention";
2954 sys_siglist
[SIGSEGV
] = "Segmentation violation";
2957 sys_siglist
[SIGSOUND
] = "Sound completed";
2960 sys_siglist
[SIGSTOP
] = "Stopped (signal)";
2963 sys_siglist
[SIGSTP
] = "Stopped (user)";
2966 sys_siglist
[SIGSYS
] = "Bad argument to system call";
2969 sys_siglist
[SIGTERM
] = "Terminated";
2972 sys_siglist
[SIGTHAW
] = "SIGTHAW";
2975 sys_siglist
[SIGTRAP
] = "Trace/breakpoint trap";
2978 sys_siglist
[SIGTSTP
] = "Stopped (user)";
2981 sys_siglist
[SIGTTIN
] = "Stopped (tty input)";
2984 sys_siglist
[SIGTTOU
] = "Stopped (tty output)";
2987 sys_siglist
[SIGURG
] = "Urgent I/O condition";
2990 sys_siglist
[SIGUSR1
] = "User defined signal 1";
2993 sys_siglist
[SIGUSR2
] = "User defined signal 2";
2996 sys_siglist
[SIGVTALRM
] = "Virtual timer expired";
2999 sys_siglist
[SIGWAITING
] = "Process's LWPs are blocked";
3002 sys_siglist
[SIGWINCH
] = "Window size changed";
3005 sys_siglist
[SIGWIND
] = "SIGWIND";
3008 sys_siglist
[SIGXCPU
] = "CPU time limit exceeded";
3011 sys_siglist
[SIGXFSZ
] = "File size limit exceeded";
3014 #endif /* !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED */
3023 /* Figure out how many bits the system's random number generator uses.
3024 `random' and `lrand48' are assumed to return 31 usable bits.
3025 BSD `rand' returns a 31 bit value but the low order bits are unusable;
3026 so we'll shift it and treat it like the 15-bit USG `rand'. */
3030 # define RAND_BITS 31
3031 # else /* !HAVE_RANDOM */
3032 # ifdef HAVE_LRAND48
3033 # define RAND_BITS 31
3034 # define random lrand48
3035 # else /* !HAVE_LRAND48 */
3036 # define RAND_BITS 15
3037 # if RAND_MAX == 32767
3038 # define random rand
3039 # else /* RAND_MAX != 32767 */
3040 # if RAND_MAX == 2147483647
3041 # define random() (rand () >> 16)
3042 # else /* RAND_MAX != 2147483647 */
3044 # define random rand
3046 # define random() (rand () >> 16)
3048 # endif /* RAND_MAX != 2147483647 */
3049 # endif /* RAND_MAX != 32767 */
3050 # endif /* !HAVE_LRAND48 */
3051 # endif /* !HAVE_RANDOM */
3052 #endif /* !RAND_BITS */
3059 srandom ((unsigned int)arg
);
3061 # ifdef HAVE_LRAND48
3064 srand ((unsigned int)arg
);
3070 * Build a full Emacs-sized word out of whatever we've got.
3071 * This suffices even for a 64-bit architecture with a 15-bit rand.
3076 long val
= random ();
3077 #if VALBITS > RAND_BITS
3078 val
= (val
<< RAND_BITS
) ^ random ();
3079 #if VALBITS > 2*RAND_BITS
3080 val
= (val
<< RAND_BITS
) ^ random ();
3081 #if VALBITS > 3*RAND_BITS
3082 val
= (val
<< RAND_BITS
) ^ random ();
3083 #if VALBITS > 4*RAND_BITS
3084 val
= (val
<< RAND_BITS
) ^ random ();
3085 #endif /* need at least 5 */
3086 #endif /* need at least 4 */
3087 #endif /* need at least 3 */
3088 #endif /* need at least 2 */
3089 return val
& ((1L << VALBITS
) - 1);
3092 #ifdef WRONG_NAME_INSQUE
3105 /* If any place else asks for the TERM variable,
3106 allow it to be overridden with the EMACS_TERM variable
3107 before attempting to translate the logical name TERM. As a last
3108 resort, ask for VAX C's special idea of the TERM variable. */
3115 static char buf
[256];
3116 static struct dsc$descriptor_s equiv
3117 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
3118 static struct dsc$descriptor_s d_name
3119 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
3122 if (!strcmp (name
, "TERM"))
3124 val
= (char *) getenv ("EMACS_TERM");
3129 d_name
.dsc$w_length
= strlen (name
);
3130 d_name
.dsc$a_pointer
= name
;
3131 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
3133 char *str
= (char *) xmalloc (eqlen
+ 1);
3134 bcopy (buf
, str
, eqlen
);
3136 /* This is a storage leak, but a pain to fix. With luck,
3137 no one will ever notice. */
3140 return (char *) getenv (name
);
3145 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
3146 to force a call on the debugger from within the image. */
3151 LIB$
SIGNAL (SS$_DEBUG
);
3157 #ifdef LINK_CRTL_SHARE
3158 #ifdef SHARABLE_LIB_BUG
3159 /* Variables declared noshare and initialized in sharable libraries
3160 cannot be shared. The VMS linker incorrectly forces you to use a private
3161 version which is uninitialized... If not for this "feature", we
3162 could use the C library definition of sys_nerr and sys_errlist. */
3164 char *sys_errlist
[] =
3168 "no such file or directory",
3170 "interrupted system call",
3172 "no such device or address",
3173 "argument list too long",
3174 "exec format error",
3177 "no more processes",
3178 "not enough memory",
3179 "permission denied",
3181 "block device required",
3182 "mount devices busy",
3184 "cross-device link",
3189 "file table overflow",
3190 "too many open files",
3194 "no space left on device",
3196 "read-only file system",
3202 "vax/vms specific error code nontranslatable error"
3204 #endif /* SHARABLE_LIB_BUG */
3205 #endif /* LINK_CRTL_SHARE */
3208 #ifndef HAVE_STRERROR
3214 extern char *sys_errlist
[];
3215 extern int sys_nerr
;
3217 if (errnum
>= 0 && errnum
< sys_nerr
)
3218 return sys_errlist
[errnum
];
3219 return (char *) "Unknown error";
3221 #endif /* not WINDOWSNT */
3222 #endif /* ! HAVE_STRERROR */
3225 emacs_open (path
, oflag
, mode
)
3229 register int rtnval
;
3232 if (oflag
& O_CREAT
)
3233 return creat (path
, mode
);
3236 while ((rtnval
= open (path
, oflag
, mode
)) == -1
3237 && (errno
== EINTR
));
3246 register int rtnval
;
3248 while ((rtnval
= close (fd
)) == -1
3249 && (errno
== EINTR
))
3252 /* If close is interrupted SunOS 4.1 may or may not have closed the
3253 file descriptor. If it did the second close will fail with
3254 errno = EBADF. That means we have succeeded. */
3255 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3262 emacs_read (fildes
, buf
, nbyte
)
3267 register int rtnval
;
3269 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3270 && (errno
== EINTR
));
3275 emacs_write (fildes
, buf
, nbyte
)
3280 register int rtnval
, bytes_written
;
3286 rtnval
= write (fildes
, buf
, nbyte
);
3293 return (bytes_written
? bytes_written
: -1);
3298 bytes_written
+= rtnval
;
3300 return (bytes_written
);
3305 * All of the following are for USG.
3307 * On USG systems the system calls are INTERRUPTIBLE by signals
3308 * that the user program has elected to catch. Thus the system call
3309 * must be retried in these cases. To handle this without massive
3310 * changes in the source code, we remap the standard system call names
3311 * to names for our own functions in sysdep.c that do the system call
3312 * with retries. Actually, for portability reasons, it is good
3313 * programming practice, as this example shows, to limit all actual
3314 * system calls to a single occurrence in the source. Sure, this
3315 * adds an extra level of function call overhead but it is almost
3316 * always negligible. Fred Fish, Unisoft Systems Inc.
3320 * Warning, this function may not duplicate 4.2 action properly
3321 * under error conditions.
3325 /* In 4.1, param.h fails to define this. */
3326 #define MAXPATHLEN 1024
3335 char *npath
, *spath
;
3336 extern char *getcwd ();
3338 BLOCK_INPUT
; /* getcwd uses malloc */
3339 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3342 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3343 up to first slash. Should be harmless on other systems. */
3344 while (*npath
&& *npath
!= '/')
3346 strcpy (pathname
, npath
);
3347 free (spath
); /* getcwd uses malloc */
3352 #endif /* HAVE_GETWD */
3355 * Emulate rename using unlink/link. Note that this is
3356 * only partially correct. Also, doesn't enforce restriction
3357 * that files be of same type (regular->regular, dir->dir, etc).
3366 if (access (from
, 0) == 0)
3369 if (link (from
, to
) == 0)
3370 if (unlink (from
) == 0)
3382 /* HPUX curses library references perror, but as far as we know
3383 it won't be called. Anyway this definition will do for now. */
3389 #endif /* not HAVE_PERROR */
3395 * Emulate BSD dup2. First close newd if it already exists.
3396 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3397 * until we are, then close the unsuccessful ones.
3404 register int fd
, ret
;
3409 return fcntl (oldd
, F_DUPFD
, newd
);
3416 ret
= dup2 (old
,new);
3422 #endif /* not HAVE_DUP2 */
3425 * Gettimeofday. Simulate as much as possible. Only accurate
3426 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3427 * Only needed when subprocesses are defined.
3432 #ifndef HAVE_GETTIMEOFDAY
3437 gettimeofday (tp
, tzp
)
3439 struct timezone
*tzp
;
3441 extern long time ();
3443 tp
->tv_sec
= time ((long *)0);
3446 tzp
->tz_minuteswest
= -1;
3453 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3456 * This function will go away as soon as all the stubs fixed. (fnf)
3463 printf ("%s not yet implemented\r\n", badfunc
);
3470 /* Directory routines for systems that don't have them. */
3472 #ifdef SYSV_SYSTEM_DIR
3476 #if defined (BROKEN_CLOSEDIR) || !defined (HAVE_CLOSEDIR)
3480 register DIR *dirp
; /* stream from opendir */
3484 rtnval
= emacs_close (dirp
->dd_fd
);
3486 /* Some systems (like Solaris) allocate the buffer and the DIR all
3487 in one block. Why in the world are we freeing this ourselves
3489 #if ! (defined (sun) && defined (USG5_4))
3490 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3492 xfree ((char *) dirp
);
3496 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3497 #endif /* SYSV_SYSTEM_DIR */
3499 #ifdef NONSYSTEM_DIR_LIBRARY
3503 char *filename
; /* name of directory */
3505 register DIR *dirp
; /* -> malloc'ed storage */
3506 register int fd
; /* file descriptor for read */
3507 struct stat sbuf
; /* result of fstat */
3509 fd
= emacs_open (filename
, O_RDONLY
, 0);
3514 if (fstat (fd
, &sbuf
) < 0
3515 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3516 || (dirp
= (DIR *) xmalloc (sizeof (DIR))) == 0)
3520 return 0; /* bad luck today */
3525 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3532 register DIR *dirp
; /* stream from opendir */
3534 emacs_close (dirp
->dd_fd
);
3535 xfree ((char *) dirp
);
3543 ino_t od_ino
; /* inode */
3544 char od_name
[DIRSIZ
]; /* filename */
3546 #endif /* not VMS */
3548 struct direct dir_static
; /* simulated directory contents */
3553 register DIR *dirp
; /* stream from opendir */
3556 register struct olddir
*dp
; /* -> directory data */
3558 register struct dir$_name
*dp
; /* -> directory data */
3559 register struct dir$_version
*dv
; /* -> version data */
3564 if (dirp
->dd_loc
>= dirp
->dd_size
)
3565 dirp
->dd_loc
= dirp
->dd_size
= 0;
3567 if (dirp
->dd_size
== 0 /* refill buffer */
3568 && (dirp
->dd_size
= emacs_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3572 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3573 dirp
->dd_loc
+= sizeof (struct olddir
);
3575 if (dp
->od_ino
!= 0) /* not deleted entry */
3577 dir_static
.d_ino
= dp
->od_ino
;
3578 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3579 dir_static
.d_name
[DIRSIZ
] = '\0';
3580 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3581 dir_static
.d_reclen
= sizeof (struct direct
)
3583 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3584 return &dir_static
; /* -> simulated structure */
3587 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3588 if (dirp
->dd_loc
== 0)
3589 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3590 : dp
->dir$b_namecount
;
3591 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3592 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3593 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3594 dir_static
.d_reclen
= sizeof (struct direct
)
3596 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3597 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3598 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3599 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3606 /* readdirver is just like readdir except it returns all versions of a file
3607 as separate entries. */
3612 register DIR *dirp
; /* stream from opendir */
3614 register struct dir$_name
*dp
; /* -> directory data */
3615 register struct dir$_version
*dv
; /* -> version data */
3617 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3618 dirp
->dd_loc
= dirp
->dd_size
= 0;
3620 if (dirp
->dd_size
== 0 /* refill buffer */
3621 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3624 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3625 if (dirp
->dd_loc
== 0)
3626 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3627 : dp
->dir$b_namecount
;
3628 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3629 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3630 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3631 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3632 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3633 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3634 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3635 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3641 #endif /* NONSYSTEM_DIR_LIBRARY */
3645 set_file_times (filename
, atime
, mtime
)
3647 EMACS_TIME atime
, mtime
;
3650 struct timeval tv
[2];
3653 return utimes (filename
, tv
);
3654 #else /* not HAVE_UTIMES */
3656 utb
.actime
= EMACS_SECS (atime
);
3657 utb
.modtime
= EMACS_SECS (mtime
);
3658 return utime (filename
, &utb
);
3659 #endif /* not HAVE_UTIMES */
3662 /* mkdir and rmdir functions, for systems which don't have them. */
3666 * Written by Robert Rother, Mariah Corporation, August 1985.
3668 * If you want it, it's yours. All I ask in return is that if you
3669 * figure out how to do this in a Bourne Shell script you send me
3671 * sdcsvax!rmr or rmr@uscd
3673 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3674 * subroutine. 11Mar86; hoptoad!gnu
3676 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3677 * subroutine didn't return EEXIST. It does now.
3683 #ifdef MKDIR_PROTOTYPE
3687 mkdir (dpath
, dmode
)
3692 int cpid
, status
, fd
;
3693 struct stat statbuf
;
3695 if (stat (dpath
, &statbuf
) == 0)
3697 errno
= EEXIST
; /* Stat worked, so it already exists */
3701 /* If stat fails for a reason other than non-existence, return error */
3702 if (errno
!= ENOENT
)
3705 synch_process_alive
= 1;
3706 switch (cpid
= fork ())
3709 case -1: /* Error in fork */
3710 return (-1); /* Errno is set already */
3712 case 0: /* Child process */
3714 * Cheap hack to set mode of new directory. Since this
3715 * child process is going away anyway, we zap its umask.
3716 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3717 * directory. Does anybody care?
3719 status
= umask (0); /* Get current umask */
3720 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3721 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3728 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3729 _exit (-1); /* Can't exec /bin/mkdir */
3731 default: /* Parent process */
3732 wait_for_termination (cpid
);
3735 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3737 errno
= EIO
; /* We don't know why, but */
3738 return -1; /* /bin/mkdir failed */
3743 #endif /* not HAVE_MKDIR */
3750 int cpid
, status
, fd
;
3751 struct stat statbuf
;
3753 if (stat (dpath
, &statbuf
) != 0)
3755 /* Stat just set errno. We don't have to */
3759 synch_process_alive
= 1;
3760 switch (cpid
= fork ())
3763 case -1: /* Error in fork */
3764 return (-1); /* Errno is set already */
3766 case 0: /* Child process */
3767 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3774 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3775 _exit (-1); /* Can't exec /bin/rmdir */
3777 default: /* Parent process */
3778 wait_for_termination (cpid
);
3781 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3783 errno
= EIO
; /* We don't know why, but */
3784 return -1; /* /bin/rmdir failed */
3789 #endif /* !HAVE_RMDIR */
3793 /* Functions for VMS */
3795 #include "vms-pwd.h"
3800 /* Return as a string the VMS error string pertaining to STATUS.
3801 Reuses the same static buffer each time it is called. */
3805 int status
; /* VMS status code */
3809 static char buf
[257];
3811 bufadr
[0] = sizeof buf
- 1;
3812 bufadr
[1] = (int) buf
;
3813 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3814 return "untranslatable VMS error status";
3822 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3823 * not work correctly. (It also doesn't work well in version 2.3.)
3828 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3829 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3833 unsigned short s_buflen
;
3834 unsigned short s_code
;
3836 unsigned short *s_retlenadr
;
3840 #define buflen s.s_buflen
3841 #define code s.s_code
3842 #define bufadr s.s_bufadr
3843 #define retlenadr s.s_retlenadr
3845 #define R_OK 4 /* test for read permission */
3846 #define W_OK 2 /* test for write permission */
3847 #define X_OK 1 /* test for execute (search) permission */
3848 #define F_OK 0 /* test for presence of file */
3851 sys_access (path
, mode
)
3855 static char *user
= NULL
;
3858 /* translate possible directory spec into .DIR file name, so brain-dead
3859 * access can treat the directory like a file. */
3860 if (directory_file_name (path
, dir_fn
))
3864 return access (path
, mode
);
3865 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3871 unsigned short int dummy
;
3873 static int constant
= ACL$C_FILE
;
3874 DESCRIPTOR (path_desc
, path
);
3875 DESCRIPTOR (user_desc
, user
);
3879 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3882 acces
|= CHP$M_READ
;
3884 acces
|= CHP$M_WRITE
;
3885 itemlst
[0].buflen
= sizeof (int);
3886 itemlst
[0].code
= CHP$_FLAGS
;
3887 itemlst
[0].bufadr
= (char *) &flags
;
3888 itemlst
[0].retlenadr
= &dummy
;
3889 itemlst
[1].buflen
= sizeof (int);
3890 itemlst
[1].code
= CHP$_ACCESS
;
3891 itemlst
[1].bufadr
= (char *) &acces
;
3892 itemlst
[1].retlenadr
= &dummy
;
3893 itemlst
[2].end
= CHP$_END
;
3894 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3895 return stat
== SS$_NORMAL
? 0 : -1;
3899 #else /* not VMS4_4 */
3902 #define ACE$M_WRITE 2
3903 #define ACE$C_KEYID 1
3905 static unsigned short memid
, grpid
;
3906 static unsigned int uic
;
3908 /* Called from init_sys_modes, so it happens not very often
3909 but at least each time Emacs is loaded. */
3911 sys_access_reinit ()
3917 sys_access (filename
, type
)
3923 int status
, size
, i
, typecode
, acl_controlled
;
3924 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3925 union prvdef prvmask
;
3927 /* Get UIC and GRP values for protection checking. */
3930 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3933 memid
= uic
& 0xFFFF;
3937 if (type
!= 2) /* not checking write access */
3938 return access (filename
, type
);
3940 /* Check write protection. */
3942 #define CHECKPRIV(bit) (prvmask.bit)
3943 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3945 /* Find privilege bits */
3946 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3948 error ("Unable to find privileges: %s", vmserrstr (status
));
3949 if (CHECKPRIV (PRV$V_BYPASS
))
3950 return 0; /* BYPASS enabled */
3952 fab
.fab$b_fac
= FAB$M_GET
;
3953 fab
.fab$l_fna
= filename
;
3954 fab
.fab$b_fns
= strlen (filename
);
3955 fab
.fab$l_xab
= &xab
;
3956 xab
= cc$rms_xabpro
;
3957 xab
.xab$l_aclbuf
= aclbuf
;
3958 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3959 status
= SYS$
OPEN (&fab
, 0, 0);
3962 SYS$
CLOSE (&fab
, 0, 0);
3963 /* Check system access */
3964 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
3966 /* Check ACL entries, if any */
3968 if (xab
.xab$w_acllen
> 0)
3971 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3972 while (*aclptr
&& aclptr
< aclend
)
3974 size
= (*aclptr
& 0xff) / 4;
3975 typecode
= (*aclptr
>> 8) & 0xff;
3976 if (typecode
== ACE$C_KEYID
)
3977 for (i
= size
- 1; i
> 1; i
--)
3978 if (aclptr
[i
] == uic
)
3981 if (aclptr
[1] & ACE$M_WRITE
)
3982 return 0; /* Write access through ACL */
3984 aclptr
= &aclptr
[size
];
3986 if (acl_controlled
) /* ACL specified, prohibits write access */
3989 /* No ACL entries specified, check normal protection */
3990 if (WRITABLE (XAB$V_WLD
)) /* World writable */
3992 if (WRITABLE (XAB$V_GRP
) &&
3993 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3994 return 0; /* Group writable */
3995 if (WRITABLE (XAB$V_OWN
) &&
3996 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3997 return 0; /* Owner writable */
3999 return -1; /* Not writable */
4001 #endif /* not VMS4_4 */
4004 static char vtbuf
[NAM$C_MAXRSS
+1];
4006 /* translate a vms file spec to a unix path */
4008 sys_translate_vms (vfile
)
4019 /* leading device or logical name is a root directory */
4020 if (p
= strchr (vfile
, ':'))
4029 if (*p
== '[' || *p
== '<')
4031 while (*++vfile
!= *p
+ 2)
4035 if (vfile
[-1] == *p
)
4058 static char utbuf
[NAM$C_MAXRSS
+1];
4060 /* translate a unix path to a VMS file spec */
4062 sys_translate_unix (ufile
)
4085 if (index (&ufile
[1], '/'))
4092 if (index (&ufile
[1], '/'))
4099 if (strncmp (ufile
, "./", 2) == 0)
4106 ufile
++; /* skip the dot */
4107 if (index (&ufile
[1], '/'))
4112 else if (strncmp (ufile
, "../", 3) == 0)
4120 ufile
+= 2; /* skip the dots */
4121 if (index (&ufile
[1], '/'))
4146 extern char *getcwd ();
4148 #define MAXPATHLEN 1024
4150 ptr
= xmalloc (MAXPATHLEN
);
4151 val
= getcwd (ptr
, MAXPATHLEN
);
4157 strcpy (pathname
, ptr
);
4166 long item_code
= JPI$_OWNER
;
4167 unsigned long parent_id
;
4170 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4173 vaxc$errno
= status
;
4183 return (getgid () << 16) | getuid ();
4188 sys_read (fildes
, buf
, nbyte
)
4193 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4198 sys_write (fildes
, buf
, nbyte
)
4203 register int nwrote
, rtnval
= 0;
4205 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4211 return rtnval
? rtnval
: -1;
4212 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4213 return rtnval
? rtnval
: -1;
4214 return (rtnval
+ nwrote
);
4219 * VAX/VMS VAX C RTL really loses. It insists that records
4220 * end with a newline (carriage return) character, and if they
4221 * don't it adds one (nice of it isn't it!)
4223 * Thus we do this stupidity below.
4228 sys_write (fildes
, buf
, nbytes
)
4231 unsigned int nbytes
;
4238 fstat (fildes
, &st
);
4244 /* Handle fixed-length files with carriage control. */
4245 if (st
.st_fab_rfm
== FAB$C_FIX
4246 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4248 len
= st
.st_fab_mrs
;
4249 retval
= write (fildes
, p
, min (len
, nbytes
));
4252 retval
++; /* This skips the implied carriage control */
4256 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4257 while (*e
!= '\n' && e
> p
) e
--;
4258 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4259 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4261 retval
= write (fildes
, p
, len
);
4272 /* Create file NEW copying its attributes from file OLD. If
4273 OLD is 0 or does not exist, create based on the value of
4276 /* Protection value the file should ultimately have.
4277 Set by create_copy_attrs, and use by rename_sansversions. */
4278 static unsigned short int fab_final_pro
;
4281 creat_copy_attrs (old
, new)
4284 struct FAB fab
= cc$rms_fab
;
4285 struct XABPRO xabpro
;
4286 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4287 extern int vms_stmlf_recfm
;
4291 fab
.fab$b_fac
= FAB$M_GET
;
4292 fab
.fab$l_fna
= old
;
4293 fab
.fab$b_fns
= strlen (old
);
4294 fab
.fab$l_xab
= (char *) &xabpro
;
4295 xabpro
= cc$rms_xabpro
;
4296 xabpro
.xab$l_aclbuf
= aclbuf
;
4297 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4298 /* Call $OPEN to fill in the fab & xabpro fields. */
4299 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4301 SYS$
CLOSE (&fab
, 0, 0);
4302 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4303 if (xabpro
.xab$w_acllen
> 0)
4305 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4306 /* If the acl buffer was too short, redo open with longer one.
4307 Wouldn't need to do this if there were some system imposed
4308 limit on the size of an ACL, but I can't find any such. */
4310 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4311 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4312 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4313 SYS$
CLOSE (&fab
, 0, 0);
4319 xabpro
.xab$l_aclbuf
= 0;
4324 fab
.fab$l_fna
= new;
4325 fab
.fab$b_fns
= strlen (new);
4329 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4330 fab
.fab$b_rat
= FAB$M_CR
;
4333 /* Set the file protections such that we will be able to manipulate
4334 this file. Once we are done writing and renaming it, we will set
4335 the protections back. */
4337 fab_final_pro
= xabpro
.xab$w_pro
;
4339 SYS$
SETDFPROT (0, &fab_final_pro
);
4340 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4342 /* Create the new file with either default attrs or attrs copied
4344 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4346 SYS$
CLOSE (&fab
, 0, 0);
4347 /* As this is a "replacement" for creat, return a file descriptor
4348 opened for writing. */
4349 return open (new, O_WRONLY
);
4354 #include <varargs.h>
4357 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4362 sys_creat (va_alist
)
4365 va_list list_incrementer
;
4368 int rfd
; /* related file descriptor */
4369 int fd
; /* Our new file descriptor */
4376 extern int vms_stmlf_recfm
;
4379 va_start (list_incrementer
);
4380 name
= va_arg (list_incrementer
, char *);
4381 mode
= va_arg (list_incrementer
, int);
4383 rfd
= va_arg (list_incrementer
, int);
4384 va_end (list_incrementer
);
4387 /* Use information from the related file descriptor to set record
4388 format of the newly created file. */
4389 fstat (rfd
, &st_buf
);
4390 switch (st_buf
.st_fab_rfm
)
4393 strcpy (rfm
, "rfm = fix");
4394 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4395 strcpy (rat
, "rat = ");
4396 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4398 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4399 strcat (rat
, "ftn");
4400 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4401 strcat (rat
, "prn");
4402 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4403 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4404 strcat (rat
, ", blk");
4406 strcat (rat
, "blk");
4407 return creat (name
, 0, rfm
, rat
, mrs
);
4410 strcpy (rfm
, "rfm = vfc");
4411 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4412 strcpy (rat
, "rat = ");
4413 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4415 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4416 strcat (rat
, "ftn");
4417 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4418 strcat (rat
, "prn");
4419 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4420 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4421 strcat (rat
, ", blk");
4423 strcat (rat
, "blk");
4424 return creat (name
, 0, rfm
, rat
, fsz
);
4427 strcpy (rfm
, "rfm = stm");
4431 strcpy (rfm
, "rfm = stmcr");
4435 strcpy (rfm
, "rfm = stmlf");
4439 strcpy (rfm
, "rfm = udf");
4443 strcpy (rfm
, "rfm = var");
4446 strcpy (rat
, "rat = ");
4447 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4449 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4450 strcat (rat
, "ftn");
4451 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4452 strcat (rat
, "prn");
4453 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4454 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4455 strcat (rat
, ", blk");
4457 strcat (rat
, "blk");
4461 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4462 strcpy (rat
, "rat=cr");
4464 /* Until the VAX C RTL fixes the many bugs with modes, always use
4465 mode 0 to get the user's default protection. */
4466 fd
= creat (name
, 0, rfm
, rat
);
4467 if (fd
< 0 && errno
== EEXIST
)
4469 if (unlink (name
) < 0)
4470 report_file_error ("delete", build_string (name
));
4471 fd
= creat (name
, 0, rfm
, rat
);
4477 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4479 sys_fwrite (ptr
, size
, num
, fp
)
4480 register char * ptr
;
4483 register int tot
= num
* size
;
4491 * The VMS C library routine creat actually creates a new version of an
4492 * existing file rather than truncating the old version. There are times
4493 * when this is not the desired behavior, for instance, when writing an
4494 * auto save file (you only want one version), or when you don't have
4495 * write permission in the directory containing the file (but the file
4496 * itself is writable). Hence this routine, which is equivalent to
4497 * "close (creat (fn, 0));" on Unix if fn already exists.
4503 struct FAB xfab
= cc$rms_fab
;
4504 struct RAB xrab
= cc$rms_rab
;
4507 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4508 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4509 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4510 xfab
.fab$l_fna
= fn
;
4511 xfab
.fab$b_fns
= strlen (fn
);
4512 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4514 xrab
.rab$l_fab
= &xfab
;
4516 /* This gibberish opens the file, positions to the first record, and
4517 deletes all records from there until the end of file. */
4518 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4520 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4521 (SYS$
FIND (&xrab
) & 01) == 01 &&
4522 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4533 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4534 SYSPRV or a readable SYSUAF.DAT. */
4540 * Routine to read the VMS User Authorization File and return
4541 * a specific user's record.
4544 static struct UAF retuaf
;
4547 get_uaf_name (uname
)
4554 uaf_fab
= cc$rms_fab
;
4555 uaf_rab
= cc$rms_rab
;
4556 /* initialize fab fields */
4557 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4558 uaf_fab
.fab$b_fns
= 21;
4559 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4560 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4561 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4562 /* initialize rab fields */
4563 uaf_rab
.rab$l_fab
= &uaf_fab
;
4564 /* open the User Authorization File */
4565 status
= SYS$
OPEN (&uaf_fab
);
4569 vaxc$errno
= status
;
4572 status
= SYS$
CONNECT (&uaf_rab
);
4576 vaxc$errno
= status
;
4579 /* read the requested record - index is in uname */
4580 uaf_rab
.rab$l_kbf
= uname
;
4581 uaf_rab
.rab$b_ksz
= strlen (uname
);
4582 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4583 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4584 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4585 status
= SYS$
GET (&uaf_rab
);
4589 vaxc$errno
= status
;
4592 /* close the User Authorization File */
4593 status
= SYS$
DISCONNECT (&uaf_rab
);
4597 vaxc$errno
= status
;
4600 status
= SYS$
CLOSE (&uaf_fab
);
4604 vaxc$errno
= status
;
4618 uaf_fab
= cc$rms_fab
;
4619 uaf_rab
= cc$rms_rab
;
4620 /* initialize fab fields */
4621 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4622 uaf_fab
.fab$b_fns
= 21;
4623 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4624 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4625 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4626 /* initialize rab fields */
4627 uaf_rab
.rab$l_fab
= &uaf_fab
;
4628 /* open the User Authorization File */
4629 status
= SYS$
OPEN (&uaf_fab
);
4633 vaxc$errno
= status
;
4636 status
= SYS$
CONNECT (&uaf_rab
);
4640 vaxc$errno
= status
;
4643 /* read the requested record - index is in uic */
4644 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4645 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4646 uaf_rab
.rab$b_ksz
= sizeof uic
;
4647 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4648 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4649 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4650 status
= SYS$
GET (&uaf_rab
);
4654 vaxc$errno
= status
;
4657 /* close the User Authorization File */
4658 status
= SYS$
DISCONNECT (&uaf_rab
);
4662 vaxc$errno
= status
;
4665 status
= SYS$
CLOSE (&uaf_fab
);
4669 vaxc$errno
= status
;
4675 static struct passwd retpw
;
4683 /* copy these out first because if the username is 32 chars, the next
4684 section will overwrite the first byte of the UIC */
4685 retpw
.pw_uid
= up
->uaf$w_mem
;
4686 retpw
.pw_gid
= up
->uaf$w_grp
;
4688 /* I suppose this is not the best style, to possibly overwrite one
4689 byte beyond the end of the field, but what the heck... */
4690 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4691 while (ptr
[-1] == ' ')
4694 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4696 /* the rest of these are counted ascii strings */
4697 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4698 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4699 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4700 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4701 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4702 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4703 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4704 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4708 #else /* not READ_SYSUAF */
4709 static struct passwd retpw
;
4710 #endif /* not READ_SYSUAF */
4721 unsigned char * full
;
4722 #endif /* READ_SYSUAF */
4727 if ('a' <= *ptr
&& *ptr
<= 'z')
4732 if (!(up
= get_uaf_name (name
)))
4734 return cnv_uaf_pw (up
);
4736 if (strcmp (name
, getenv ("USER")) == 0)
4738 retpw
.pw_uid
= getuid ();
4739 retpw
.pw_gid
= getgid ();
4740 strcpy (retpw
.pw_name
, name
);
4741 if (full
= egetenv ("FULLNAME"))
4742 strcpy (retpw
.pw_gecos
, full
);
4744 *retpw
.pw_gecos
= '\0';
4745 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4746 *retpw
.pw_shell
= '\0';
4751 #endif /* not READ_SYSUAF */
4761 if (!(up
= get_uaf_uic (uid
)))
4763 return cnv_uaf_pw (up
);
4765 if (uid
== sys_getuid ())
4766 return getpwnam (egetenv ("USER"));
4769 #endif /* not READ_SYSUAF */
4772 /* return total address space available to the current process. This is
4773 the sum of the current p0 size, p1 size and free page table entries
4779 unsigned long free_pages
;
4780 unsigned long frep0va
;
4781 unsigned long frep1va
;
4784 item_code
= JPI$_FREPTECNT
;
4785 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4788 vaxc$errno
= status
;
4793 item_code
= JPI$_FREP0VA
;
4794 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4797 vaxc$errno
= status
;
4800 item_code
= JPI$_FREP1VA
;
4801 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4804 vaxc$errno
= status
;
4808 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4812 define_logical_name (varname
, string
)
4816 struct dsc$descriptor_s strdsc
=
4817 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4818 struct dsc$descriptor_s envdsc
=
4819 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4820 struct dsc$descriptor_s lnmdsc
=
4821 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4823 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4827 delete_logical_name (varname
)
4830 struct dsc$descriptor_s envdsc
=
4831 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4832 struct dsc$descriptor_s lnmdsc
=
4833 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4835 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4853 error ("execvp system call not implemented");
4862 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4863 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4864 char from_esn
[NAM$C_MAXRSS
];
4865 char to_esn
[NAM$C_MAXRSS
];
4867 from_fab
.fab$l_fna
= from
;
4868 from_fab
.fab$b_fns
= strlen (from
);
4869 from_fab
.fab$l_nam
= &from_nam
;
4870 from_fab
.fab$l_fop
= FAB$M_NAM
;
4872 from_nam
.nam$l_esa
= from_esn
;
4873 from_nam
.nam$b_ess
= sizeof from_esn
;
4875 to_fab
.fab$l_fna
= to
;
4876 to_fab
.fab$b_fns
= strlen (to
);
4877 to_fab
.fab$l_nam
= &to_nam
;
4878 to_fab
.fab$l_fop
= FAB$M_NAM
;
4880 to_nam
.nam$l_esa
= to_esn
;
4881 to_nam
.nam$b_ess
= sizeof to_esn
;
4883 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4889 if (status
== RMS$_DEV
)
4893 vaxc$errno
= status
;
4898 /* This function renames a file like `rename', but it strips
4899 the version number from the "to" filename, such that the "to" file is
4900 will always be a new version. It also sets the file protection once it is
4901 finished. The protection that we will use is stored in fab_final_pro,
4902 and was set when we did a creat_copy_attrs to create the file that we
4905 We could use the chmod function, but Eunichs uses 3 bits per user category
4906 to describe the protection, and VMS uses 4 (write and delete are separate
4907 bits). To maintain portability, the VMS implementation of `chmod' wires
4908 the W and D bits together. */
4911 static struct fibdef fib
; /* We need this initialized to zero */
4912 char vms_file_written
[NAM$C_MAXRSS
];
4915 rename_sans_version (from
,to
)
4922 struct FAB to_fab
= cc$rms_fab
;
4923 struct NAM to_nam
= cc$rms_nam
;
4924 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4925 struct dsc$descriptor fib_attr
[2]
4926 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4927 char to_esn
[NAM$C_MAXRSS
];
4929 $
DESCRIPTOR (disk
,to_esn
);
4931 to_fab
.fab$l_fna
= to
;
4932 to_fab
.fab$b_fns
= strlen (to
);
4933 to_fab
.fab$l_nam
= &to_nam
;
4934 to_fab
.fab$l_fop
= FAB$M_NAM
;
4936 to_nam
.nam$l_esa
= to_esn
;
4937 to_nam
.nam$b_ess
= sizeof to_esn
;
4939 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4941 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4942 *(to_nam
.nam$l_ver
) = '\0';
4944 stat
= rename (from
, to_esn
);
4948 strcpy (vms_file_written
, to_esn
);
4950 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4951 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4953 /* Now set the file protection to the correct value */
4954 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4956 /* Copy these fields into the fib */
4957 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4958 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4959 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4961 SYS$
CLOSE (&to_fab
, 0, 0);
4963 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4966 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4967 0, 0, 0, &fib_attr
, 0);
4970 stat
= SYS$
DASSGN (chan
);
4973 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4984 unsigned short fid
[3];
4985 char esa
[NAM$C_MAXRSS
];
4988 fab
.fab$l_fop
= FAB$M_OFP
;
4989 fab
.fab$l_fna
= file
;
4990 fab
.fab$b_fns
= strlen (file
);
4991 fab
.fab$l_nam
= &nam
;
4994 nam
.nam$l_esa
= esa
;
4995 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4997 status
= SYS$
PARSE (&fab
);
4998 if ((status
& 1) == 0)
5001 vaxc$errno
= status
;
5004 status
= SYS$
SEARCH (&fab
);
5005 if ((status
& 1) == 0)
5008 vaxc$errno
= status
;
5012 fid
[0] = nam
.nam$w_fid
[0];
5013 fid
[1] = nam
.nam$w_fid
[1];
5014 fid
[2] = nam
.nam$w_fid
[2];
5016 fab
.fab$l_fna
= new;
5017 fab
.fab$b_fns
= strlen (new);
5019 status
= SYS$
PARSE (&fab
);
5020 if ((status
& 1) == 0)
5023 vaxc$errno
= status
;
5027 nam
.nam$w_fid
[0] = fid
[0];
5028 nam
.nam$w_fid
[1] = fid
[1];
5029 nam
.nam$w_fid
[2] = fid
[2];
5031 nam
.nam$l_esa
= nam
.nam$l_name
;
5032 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
5034 status
= SYS$
ENTER (&fab
);
5035 if ((status
& 1) == 0)
5038 vaxc$errno
= status
;
5049 printf ("%s not yet implemented\r\n", badfunc
);
5057 /* Arrange to return a range centered on zero. */
5058 return rand () - (1 << 30);
5070 /* Called from init_sys_modes. */
5076 /* If we're not on an HFT we shouldn't do any of this. We determine
5077 if we are on an HFT by trying to get an HFT error code. If this
5078 call fails, we're not on an HFT. */
5080 if (ioctl (0, HFQERROR
, &junk
) < 0)
5082 #else /* not IBMR2AIX */
5083 if (ioctl (0, HFQEIO
, 0) < 0)
5085 #endif /* not IBMR2AIX */
5087 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5088 as the rubout key's ASCII code. Here this is changed. The bug is that
5089 there's no way to determine the old mapping, so in reset_sys_modes
5090 we need to assume that the normal map had been present. Of course, this
5091 code also doesn't help if on a terminal emulator which doesn't understand
5095 struct hfkeymap keymap
;
5097 buf
.hf_bufp
= (char *)&keymap
;
5098 buf
.hf_buflen
= sizeof (keymap
);
5099 keymap
.hf_nkeys
= 2;
5100 keymap
.hfkey
[0].hf_kpos
= 15;
5101 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5103 keymap
.hfkey
[0].hf_keyidh
= '<';
5104 #else /* not IBMR2AIX */
5105 keymap
.hfkey
[0].hf_page
= '<';
5106 #endif /* not IBMR2AIX */
5107 keymap
.hfkey
[0].hf_char
= 127;
5108 keymap
.hfkey
[1].hf_kpos
= 15;
5109 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5111 keymap
.hfkey
[1].hf_keyidh
= '<';
5112 #else /* not IBMR2AIX */
5113 keymap
.hfkey
[1].hf_page
= '<';
5114 #endif /* not IBMR2AIX */
5115 keymap
.hfkey
[1].hf_char
= 127;
5116 hftctl (0, HFSKBD
, &buf
);
5118 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5120 line_ins_del_ok
= char_ins_del_ok
= 0;
5123 /* Reset the rubout key to backspace. */
5129 struct hfkeymap keymap
;
5133 if (ioctl (0, HFQERROR
, &junk
) < 0)
5135 #else /* not IBMR2AIX */
5136 if (ioctl (0, HFQEIO
, 0) < 0)
5138 #endif /* not IBMR2AIX */
5140 buf
.hf_bufp
= (char *)&keymap
;
5141 buf
.hf_buflen
= sizeof (keymap
);
5142 keymap
.hf_nkeys
= 2;
5143 keymap
.hfkey
[0].hf_kpos
= 15;
5144 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5146 keymap
.hfkey
[0].hf_keyidh
= '<';
5147 #else /* not IBMR2AIX */
5148 keymap
.hfkey
[0].hf_page
= '<';
5149 #endif /* not IBMR2AIX */
5150 keymap
.hfkey
[0].hf_char
= 8;
5151 keymap
.hfkey
[1].hf_kpos
= 15;
5152 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5154 keymap
.hfkey
[1].hf_keyidh
= '<';
5155 #else /* not IBMR2AIX */
5156 keymap
.hfkey
[1].hf_page
= '<';
5157 #endif /* not IBMR2AIX */
5158 keymap
.hfkey
[1].hf_char
= 8;
5159 hftctl (0, HFSKBD
, &buf
);
5166 /* These are included on Sunos 4.1 when we do not use shared libraries.
5167 X11 libraries may refer to these functions but (we hope) do not
5168 actually call them. */
5188 #endif /* USE_DL_STUBS */
5197 register int length
;
5201 long max_str
= 65535;
5203 while (length
> max_str
) {
5204 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5209 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5211 while (length
-- > 0)
5213 #endif /* not VMS */
5216 #endif /* no bzero */
5217 #endif /* BSTRING */
5219 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5222 /* Saying `void' requires a declaration, above, where bcopy is used
5223 and that declaration causes pain for systems where bcopy is a macro. */
5224 bcopy (b1
, b2
, length
)
5227 register int length
;
5230 long max_str
= 65535;
5232 while (length
> max_str
) {
5233 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5239 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5241 while (length
-- > 0)
5243 #endif /* not VMS */
5245 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5250 bcmp (b1
, b2
, length
) /* This could be a macro! */
5253 register int length
;
5256 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5257 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5259 return STR$
COMPARE (&src1
, &src2
);
5261 while (length
-- > 0)
5266 #endif /* not VMS */
5268 #endif /* no bcmp */
5269 #endif /* not BSTRING */
5271 #ifndef HAVE_STRSIGNAL
5278 if (0 <= code
&& code
< NSIG
)
5281 signame
= sys_errlist
[code
];
5283 /* Cast to suppress warning if the table has const char *. */
5284 signame
= (char *) sys_siglist
[code
];
5290 #endif /* HAVE_STRSIGNAL */