1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 86,87,88,93,94,95, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 /* Including stdlib.h isn't necessarily enough to get srandom
31 declared, e.g. without __USE_XOPEN_EXTENDED with glibc 2. */
33 #if 0 /* It turns out that defining _OSF_SOURCE in osf5-0.h gets
34 random prototyped as returning `int'. It looks to me as
35 though the best way to DTRT is to prefer the rand48 functions
36 (per libc.info). -- fx */
37 extern long int random
P_ ((void));
39 #if 0 /* Don't prototype srandom; it takes an unsigned argument on
40 some systems, and an unsigned long on others, like FreeBSD
42 extern void srandom
P_ ((unsigned int));
46 #include "blockinput.h"
50 /* It is essential to include stdlib.h so that this file picks up
51 the correct definitions of rand, srand, and RAND_MAX.
52 Otherwise random numbers will not work correctly. */
56 /* Nonzero means delete a process right away if it exits (process.c). */
57 static int delete_exited_processes
;
59 #endif /* macintosh */
61 #define min(x,y) ((x) > (y) ? (y) : (x))
65 #define write sys_write
70 #endif /* not WINDOWSNT */
72 /* Does anyone other than VMS need this? */
74 #define sys_fwrite fwrite
80 #include <sys/types.h>
84 /* Get _POSIX_VDISABLE, if it is available. */
94 #if !defined (USG) || defined (BSD_PGRPS)
96 #define setpgrp setpgid
100 /* Get SI_SRPC_DOMAIN, if it is available. */
101 #ifdef HAVE_SYS_SYSTEMINFO_H
102 #include <sys/systeminfo.h>
105 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
109 #include <sys/param.h>
113 extern unsigned start
__asm__ ("start");
135 #include <sys/file.h>
143 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
147 #include <sys/file.h>
151 #ifdef BSD_SYSTEM /* avoid writing defined (BSD_SYSTEM) || defined (USG)
152 because the vms compiler doesn't grok `defined' */
160 #endif /* not 4.1 bsd */
163 #include <sys/ioctl.h>
169 #ifdef BROKEN_TIOCGWINSZ
174 #if defined (USG) || defined (DGUX)
175 #include <sys/utsname.h>
176 #ifndef MEMORY_IN_STRING_H
179 #if defined (TIOCGWINSZ) || defined (ISC4_0)
181 #include <sys/sioctl.h>
184 #include <sys/stream.h>
185 #include <sys/ptem.h>
187 #endif /* TIOCGWINSZ or ISC4_0 */
188 #endif /* USG or DGUX */
190 extern int quit_char
;
192 #include "keyboard.h"
195 #include "termhooks.h"
196 #include "termchar.h"
197 #include "termopts.h"
198 #include "dispextern.h"
203 /* In process.h which conflicts with the local copy. */
205 int _CRTAPI1
_spawnlp (int, const char *, const char *, ...);
206 int _CRTAPI1
_getpid (void);
209 #ifdef NONSYSTEM_DIR_LIBRARY
211 #endif /* NONSYSTEM_DIR_LIBRARY */
213 #include "syssignal.h"
220 #ifndef HAVE_STRUCT_UTIMBUF
221 /* We want to use utime rather than utimes, but we couldn't find the
222 structure declaration. We'll use the traditional one. */
230 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
236 #define LNOFLSH 0100000
239 static int baud_convert
[] =
244 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
245 1800, 2400, 4800, 9600, 19200, 38400
252 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
254 #if defined (HAVE_TERMIOS_H) && defined (LINUX)
262 /* The file descriptor for Emacs's input terminal.
263 Under Unix, this is normally zero except when using X;
264 under VMS, we place the input channel number here. */
267 void croak
P_ ((char *));
274 /* Temporary used by `sigblock' when defined in terms of signprocmask. */
276 SIGMASKTYPE sigprocmask_set
;
279 /* Specify a different file descriptor for further input operations. */
288 /* Discard pending input on descriptor input_fd. */
294 struct emacs_tty buf
;
299 /* Discarding input is not safe when the input could contain
300 replies from the X server. So don't do it. */
301 if (read_socket_hook
)
306 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
307 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
313 ioctl (input_fd
, TIOCFLUSH
, &zero
);
315 #else /* not Apollo */
316 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
317 while (dos_keyread () != -1)
319 #else /* not MSDOS */
320 EMACS_GET_TTY (input_fd
, &buf
);
321 EMACS_SET_TTY (input_fd
, &buf
, 0);
322 #endif /* not MSDOS */
323 #endif /* not Apollo */
325 #endif /* not WINDOWSNT */
330 /* Arrange for character C to be read as the next input from
337 if (read_socket_hook
)
340 /* Should perhaps error if in batch mode */
342 ioctl (input_fd
, TIOCSTI
, &c
);
343 #else /* no TIOCSTI */
344 error ("Cannot stuff terminal input characters in this version of Unix");
345 #endif /* no TIOCSTI */
357 #ifdef INIT_BAUD_RATE
362 #else /* not DOS_NT */
366 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
367 &sg
.class, 12, 0, 0, 0, 0 );
368 emacs_ospeed
= sg
.xmit_baud
;
374 tcgetattr (input_fd
, &sg
);
375 emacs_ospeed
= cfgetospeed (&sg
);
376 #if defined (USE_GETOBAUD) && defined (getobaud)
377 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
378 if (emacs_ospeed
== 0)
379 emacs_ospeed
= getobaud (sg
.c_cflag
);
381 #else /* neither VMS nor TERMIOS */
387 tcgetattr (input_fd
, &sg
);
389 ioctl (input_fd
, TCGETA
, &sg
);
391 emacs_ospeed
= sg
.c_cflag
& CBAUD
;
392 #else /* neither VMS nor TERMIOS nor TERMIO */
395 sg
.sg_ospeed
= B9600
;
396 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
398 emacs_ospeed
= sg
.sg_ospeed
;
399 #endif /* not HAVE_TERMIO */
400 #endif /* not HAVE_TERMIOS */
402 #endif /* not DOS_NT */
403 #endif /* not INIT_BAUD_RATE */
406 baud_rate
= (emacs_ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
407 ? baud_convert
[emacs_ospeed
] : 9600);
414 set_exclusive_use (fd
)
418 ioctl (fd
, FIOCLEX
, 0);
420 /* Ok to do nothing if this feature does not exist */
425 wait_without_blocking ()
428 wait3 (0, WNOHANG
| WUNTRACED
, 0);
430 croak ("wait_without_blocking");
432 synch_process_alive
= 0;
435 #endif /* not subprocesses */
437 int wait_debugging
; /* Set nonzero to make following function work under dbx
438 (at least for bsd). */
441 wait_for_termination_signal ()
444 /* Wait for subprocess with process id `pid' to terminate and
445 make sure it will get eliminated (not remain forever as a zombie) */
448 wait_for_termination (pid
)
457 status
= SYS$
FORCEX (&pid
, 0, 0);
460 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
461 /* Note that kill returns -1 even if the process is just a zombie now.
462 But inevitably a SIGCHLD interrupt should be generated
463 and child_sig will do wait3 and make the process go away. */
464 /* There is some indication that there is a bug involved with
465 termination of subprocesses, perhaps involving a kernel bug too,
466 but no idea what it is. Just as a hunch we signal SIGCHLD to see
467 if that causes the problem to go away or get worse. */
468 sigsetmask (sigmask (SIGCHLD
));
469 if (0 > kill (pid
, 0))
471 sigsetmask (SIGEMPTYMASK
);
472 kill (getpid (), SIGCHLD
);
478 sigpause (SIGEMPTYMASK
);
479 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
480 #if defined (UNIPLUS)
481 if (0 > kill (pid
, 0))
484 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
485 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
486 sigblock (sigmask (SIGCHLD
));
488 if (kill (pid
, 0) == -1 && errno
== ESRCH
)
490 sigunblock (sigmask (SIGCHLD
));
494 /* FIXME: Since sigpause is not POSIX and its use is deprecated,
495 this should probably be `sigsuspend (&empty_mask)', which is
496 POSIX. I'm not making that change right away because the
497 release is nearing. 2001-09-20 gerd. */
498 sigpause (SIGEMPTYMASK
);
499 #else /* not POSIX_SIGNALS */
500 #ifdef HAVE_SYSV_SIGPAUSE
502 if (0 > kill (pid
, 0))
508 #else /* not HAVE_SYSV_SIGPAUSE */
512 #else /* not WINDOWSNT */
513 if (0 > kill (pid
, 0))
515 /* Using sleep instead of pause avoids timing error.
516 If the inferior dies just before the sleep,
517 we lose just one second. */
519 #endif /* not WINDOWSNT */
520 #endif /* not HAVE_SYSV_SIGPAUSE */
521 #endif /* not POSIX_SIGNALS */
522 #endif /* not UNIPLUS */
523 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
525 #else /* not subprocesses */
528 #else /* not __DJGPP__ > 1 */
530 if (kill (pid
, 0) < 0)
536 if (status
== pid
|| status
== -1)
539 #endif /* not __DJGPP__ > 1*/
540 #endif /* not subprocesses */
547 * flush any pending output
548 * (may flush input as well; it does not matter the way we use it)
552 flush_pending_output (channel
)
556 /* If we try this, we get hit with SIGTTIN, because
557 the child's tty belongs to the child's pgrp. */
560 ioctl (channel
, TCFLSH
, 1);
564 /* 3rd arg should be ignored
565 but some 4.2 kernels actually want the address of an int
566 and nonzero means something different. */
567 ioctl (channel
, TIOCFLUSH
, &zero
);
574 /* Set up the terminal at the other end of a pseudo-terminal that
575 we will be controlling an inferior through.
576 It should not echo or do line-editing, since that is done
577 in Emacs. No padding needed for insertion into an Emacs buffer. */
580 child_setup_tty (out
)
586 EMACS_GET_TTY (out
, &s
);
588 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
589 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
590 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
592 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
593 /* No output delays */
595 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
596 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
597 #if 0 /* This causes bugs in (for instance) telnet to certain sites. */
598 s
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
599 #ifdef INLCR /* Just being cautious, since I can't check how
600 widespread INLCR is--rms. */
601 s
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
605 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
608 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
611 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
613 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
614 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
616 /* Said to be unnecessary: */
617 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
618 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
621 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
622 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
623 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
624 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
627 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
631 /* AIX enhanced edit loses NULs, so disable it */
634 s
.main
.c_iflag
&= ~ASCEDIT
;
636 /* Also, PTY overloads NUL and BREAK.
637 don't ignore break, but don't signal either, so it looks like NUL. */
638 s
.main
.c_iflag
&= ~IGNBRK
;
639 s
.main
.c_iflag
&= ~BRKINT
;
640 /* QUIT and INTR work better as signals, so disable character forms */
641 s
.main
.c_cc
[VINTR
] = 0377;
642 #ifdef SIGNALS_VIA_CHARACTERS
643 /* the QUIT and INTR character are used in process_send_signal
644 so set them here to something useful. */
645 if (s
.main
.c_cc
[VQUIT
] == 0377)
646 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
647 if (s
.main
.c_cc
[VINTR
] == 0377)
648 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
649 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
650 /* QUIT and INTR work better as signals, so disable character forms */
651 s
.main
.c_cc
[VQUIT
] = 0377;
652 s
.main
.c_cc
[VINTR
] = 0377;
653 s
.main
.c_lflag
&= ~ISIG
;
654 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
655 s
.main
.c_cc
[VEOL
] = 0377;
656 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
659 #else /* not HAVE_TERMIO */
661 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
663 s
.main
.sg_flags
|= LPASS8
;
664 s
.main
.sg_erase
= 0377;
665 s
.main
.sg_kill
= 0377;
666 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
668 #endif /* not HAVE_TERMIO */
670 EMACS_SET_TTY (out
, &s
, 0);
679 ioctl (out
, FIOASYNC
, &zero
);
682 #endif /* not DOS_NT */
686 #endif /* subprocesses */
688 /* Record a signal code and the handler for it. */
692 SIGTYPE (*handler
) P_ ((int));
695 static void save_signal_handlers
P_ ((struct save_signal
*));
696 static void restore_signal_handlers
P_ ((struct save_signal
*));
698 /* Suspend the Emacs process; give terminal to its superior. */
704 /* "Foster" parentage allows emacs to return to a subprocess that attached
705 to the current emacs as a cheaper than starting a whole new process. This
706 is set up by KEPTEDITOR.COM. */
707 unsigned long parent_id
, foster_parent_id
;
710 fpid_string
= getenv ("EMACS_PARENT_PID");
711 if (fpid_string
!= NULL
)
713 sscanf (fpid_string
, "%x", &foster_parent_id
);
714 if (foster_parent_id
!= 0)
715 parent_id
= foster_parent_id
;
717 parent_id
= getppid ();
720 parent_id
= getppid ();
722 xfree (fpid_string
); /* On VMS, this was malloc'd */
724 if (parent_id
&& parent_id
!= 0xffffffff)
726 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
727 int status
= LIB$
ATTACH (&parent_id
) & 1;
728 signal (SIGINT
, oldsig
);
737 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
738 d_prompt
.a
= "Emacs: "; /* Just a reminder */
739 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
744 #if defined (SIGTSTP) && !defined (MSDOS)
747 int pgrp
= EMACS_GETPGRP (0);
748 EMACS_KILLPG (pgrp
, SIGTSTP
);
751 #else /* No SIGTSTP */
752 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
753 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
754 kill (getpid (), SIGQUIT
);
756 #else /* No SIGTSTP or USG_JOBCTRL */
758 /* On a system where suspending is not implemented,
759 instead fork a subshell and let it talk directly to the terminal
763 #endif /* no USG_JOBCTRL */
764 #endif /* no SIGTSTP */
768 /* Fork a subshell. */
775 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
777 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
780 struct save_signal saved_handlers
[5];
782 unsigned char *str
= 0;
785 saved_handlers
[0].code
= SIGINT
;
786 saved_handlers
[1].code
= SIGQUIT
;
787 saved_handlers
[2].code
= SIGTERM
;
789 saved_handlers
[3].code
= SIGIO
;
790 saved_handlers
[4].code
= 0;
792 saved_handlers
[3].code
= 0;
795 /* Mentioning current_buffer->buffer would mean including buffer.h,
796 which somehow wedges the hp compiler. So instead... */
798 dir
= intern ("default-directory");
799 if (NILP (Fboundp (dir
)))
801 dir
= Fsymbol_value (dir
);
805 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
806 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
807 len
= XSTRING (dir
)->size
;
808 bcopy (XSTRING (dir
)->data
, str
, len
);
809 if (str
[len
- 1] != '/') str
[len
++] = '/';
816 save_signal_handlers (saved_handlers
);
817 synch_process_alive
= 1;
818 #endif /* __DJGPP__ > 1 */
822 error ("Can't spawn subshell");
829 #ifdef DOS_NT /* MW, Aug 1993 */
832 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
835 sh
= (char *) egetenv ("SHELL");
839 /* Use our buffer's default directory for the subshell. */
841 chdir ((char *) str
);
844 close_process_descs (); /* Close Emacs's pipes/ptys */
847 #ifdef SET_EMACS_PRIORITY
849 extern int emacs_priority
;
851 if (emacs_priority
< 0)
852 nice (-emacs_priority
);
856 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
859 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
861 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
863 #else /* not MSDOS */
865 /* Waits for process completion */
866 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
869 write (1, "Can't execute subshell", 22);
870 #else /* not WINDOWSNT */
872 write (1, "Can't execute subshell", 22);
874 #endif /* not WINDOWSNT */
875 #endif /* not MSDOS */
878 /* Do this now if we did not do it before. */
879 #if !defined (MSDOS) || __DJGPP__ == 1
880 save_signal_handlers (saved_handlers
);
881 synch_process_alive
= 1;
885 wait_for_termination (pid
);
887 restore_signal_handlers (saved_handlers
);
888 synch_process_alive
= 0;
891 #endif /* !macintosh */
894 save_signal_handlers (saved_handlers
)
895 struct save_signal
*saved_handlers
;
897 while (saved_handlers
->code
)
899 saved_handlers
->handler
900 = (SIGTYPE (*) P_ ((int))) signal (saved_handlers
->code
, SIG_IGN
);
906 restore_signal_handlers (saved_handlers
)
907 struct save_signal
*saved_handlers
;
909 while (saved_handlers
->code
)
911 signal (saved_handlers
->code
, saved_handlers
->handler
);
925 old_fcntl_flags
= fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
926 fcntl (fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
928 interrupts_deferred
= 0;
937 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
942 if (read_socket_hook
)
946 sigunblock (sigmask (SIGWINCH
));
948 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
950 interrupts_deferred
= 0;
956 if (read_socket_hook
)
960 sigblock (sigmask (SIGWINCH
));
962 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
963 interrupts_deferred
= 1;
966 #else /* no FASYNC */
967 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
974 if (read_socket_hook
)
977 ioctl (input_fd
, FIOASYNC
, &on
);
978 interrupts_deferred
= 0;
986 if (read_socket_hook
)
989 ioctl (input_fd
, FIOASYNC
, &off
);
990 interrupts_deferred
= 1;
993 #else /* not FASYNC, not STRIDE */
1005 if (read_socket_hook
)
1009 sigaddset (&st
, SIGIO
);
1010 ioctl (input_fd
, FIOASYNC
, &on
);
1011 interrupts_deferred
= 0;
1012 sigprocmask (SIG_UNBLOCK
, &st
, (sigset_t
*)0);
1020 if (read_socket_hook
)
1023 ioctl (input_fd
, FIOASYNC
, &off
);
1024 interrupts_deferred
= 1;
1027 #else /* ! _CX_UX */
1033 if (read_socket_hook
)
1036 croak ("request_sigio");
1042 if (read_socket_hook
)
1045 croak ("unrequest_sigio");
1052 #endif /* F_SETFL */
1054 /* Saving and restoring the process group of Emacs's terminal. */
1058 /* The process group of which Emacs was a member when it initially
1061 If Emacs was in its own process group (i.e. inherited_pgroup ==
1062 getpid ()), then we know we're running under a shell with job
1063 control (Emacs would never be run as part of a pipeline).
1066 If Emacs was not in its own process group, then we know we're
1067 running under a shell (or a caller) that doesn't know how to
1068 separate itself from Emacs (like sh). Emacs must be in its own
1069 process group in order to receive SIGIO correctly. In this
1070 situation, we put ourselves in our own pgroup, forcibly set the
1071 tty's pgroup to our pgroup, and make sure to restore and reinstate
1072 the tty's pgroup just like any other terminal setting. If
1073 inherited_group was not the tty's pgroup, then we'll get a
1074 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1075 it goes foreground in the future, which is what should happen. */
1076 int inherited_pgroup
;
1078 /* Split off the foreground process group to Emacs alone.
1079 When we are in the foreground, but not started in our own process
1080 group, redirect the TTY to point to our own process group. We need
1081 to be in our own process group to receive SIGIO properly. */
1083 narrow_foreground_group ()
1087 setpgrp (0, inherited_pgroup
);
1088 if (inherited_pgroup
!= me
)
1089 EMACS_SET_TTY_PGRP (input_fd
, &me
);
1093 /* Set the tty to our original foreground group. */
1095 widen_foreground_group ()
1097 if (inherited_pgroup
!= getpid ())
1098 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
1099 setpgrp (0, inherited_pgroup
);
1102 #endif /* BSD_PGRPS */
1104 /* Getting and setting emacs_tty structures. */
1106 /* Set *TC to the parameters associated with the terminal FD.
1107 Return zero if all's well, or -1 if we ran into an error we
1108 couldn't deal with. */
1110 emacs_get_tty (fd
, settings
)
1112 struct emacs_tty
*settings
;
1114 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1116 /* We have those nifty POSIX tcmumbleattr functions. */
1117 bzero (&settings
->main
, sizeof (settings
->main
));
1118 if (tcgetattr (fd
, &settings
->main
) < 0)
1123 /* The SYSV-style interface? */
1124 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1129 /* Vehemently Monstrous System? :-) */
1130 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1131 &settings
->main
.class, 12, 0, 0, 0, 0)
1137 /* I give up - I hope you have the BSD ioctls. */
1138 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1140 #endif /* not DOS_NT */
1145 /* Suivant - Do we have to get struct ltchars data? */
1147 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1151 /* How about a struct tchars and a wordful of lmode bits? */
1153 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1154 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1158 /* We have survived the tempest. */
1163 /* Set the parameters of the tty on FD according to the contents of
1164 *SETTINGS. If FLUSHP is non-zero, we discard input.
1165 Return 0 if all went well, and -1 if anything failed. */
1168 emacs_set_tty (fd
, settings
, flushp
)
1170 struct emacs_tty
*settings
;
1173 /* Set the primary parameters - baud rate, character size, etcetera. */
1176 /* We have those nifty POSIX tcmumbleattr functions.
1177 William J. Smith <wjs@wiis.wang.com> writes:
1178 "POSIX 1003.1 defines tcsetattr to return success if it was
1179 able to perform any of the requested actions, even if some
1180 of the requested actions could not be performed.
1181 We must read settings back to ensure tty setup properly.
1182 AIX requires this to keep tty from hanging occasionally." */
1183 /* This make sure that we don't loop indefinitely in here. */
1184 for (i
= 0 ; i
< 10 ; i
++)
1185 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1196 bzero (&new, sizeof (new));
1197 /* Get the current settings, and see if they're what we asked for. */
1198 tcgetattr (fd
, &new);
1199 /* We cannot use memcmp on the whole structure here because under
1200 * aix386 the termios structure has some reserved field that may
1203 if ( new.c_iflag
== settings
->main
.c_iflag
1204 && new.c_oflag
== settings
->main
.c_oflag
1205 && new.c_cflag
== settings
->main
.c_cflag
1206 && new.c_lflag
== settings
->main
.c_lflag
1207 && memcmp (new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1215 /* The SYSV-style interface? */
1216 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1221 /* Vehemently Monstrous System? :-) */
1222 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1223 &settings
->main
.class, 12, 0, 0, 0, 0)
1229 /* I give up - I hope you have the BSD ioctls. */
1230 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1232 #endif /* not DOS_NT */
1238 /* Suivant - Do we have to get struct ltchars data? */
1240 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1244 /* How about a struct tchars and a wordful of lmode bits? */
1246 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1247 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1251 /* We have survived the tempest. */
1256 /* The initial tty mode bits */
1257 struct emacs_tty old_tty
;
1259 /* 1 if we have been through init_sys_modes. */
1262 /* 1 if outer tty status has been recorded. */
1266 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1271 #ifndef F_SETOWN_BUG
1273 int old_fcntl_owner
;
1274 #endif /* F_SETOWN */
1275 #endif /* F_SETOWN_BUG */
1277 /* This may also be defined in stdio,
1278 but if so, this does no harm,
1279 and using the same name avoids wasting the other one's space. */
1282 extern char *_sobuf
;
1284 #if defined (USG) || defined (DGUX)
1285 unsigned char _sobuf
[BUFSIZ
+8];
1287 char _sobuf
[BUFSIZ
];
1292 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1295 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1301 struct emacs_tty tty
;
1304 /* cus-start.el complains if delete-exited-processes is not defined */
1305 #ifndef subprocesses
1306 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes
,
1307 "*Non-nil means delete processes immediately when they exit.\n\
1308 nil means don't delete them until `list-processes' is run.");
1309 delete_exited_processes
= 0;
1311 #endif /* not macintosh */
1315 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1316 extern int (*interrupt_signal
) ();
1320 Vtty_erase_char
= Qnil
;
1327 input_ef
= get_kbd_event_flag ();
1328 /* LIB$GET_EF (&input_ef); */
1329 SYS$
CLREF (input_ef
);
1330 waiting_for_ast
= 0;
1332 timer_ef
= get_timer_event_flag ();
1333 /* LIB$GET_EF (&timer_ef); */
1334 SYS$
CLREF (timer_ef
);
1338 LIB$
GET_EF (&process_ef
);
1339 SYS$
CLREF (process_ef
);
1341 if (input_ef
/ 32 != process_ef
/ 32)
1342 croak ("Input and process event flags in different clusters.");
1344 if (input_ef
/ 32 != timer_ef
/ 32)
1345 croak ("Input and timer event flags in different clusters.");
1347 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1348 ((unsigned) 1 << (process_ef
% 32));
1350 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1351 ((unsigned) 1 << (timer_ef
% 32));
1353 sys_access_reinit ();
1355 #endif /* not VMS */
1358 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1359 narrow_foreground_group ();
1362 #ifdef HAVE_WINDOW_SYSTEM
1363 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1364 needs the initialization code below. */
1365 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1368 EMACS_GET_TTY (input_fd
, &old_tty
);
1374 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1375 XSETINT (Vtty_erase_char
, old_tty
.main
.c_cc
[VERASE
]);
1378 /* This allows meta to be sent on 8th bit. */
1379 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1381 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1382 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1383 #ifdef INLCR /* I'm just being cautious,
1384 since I can't check how widespread INLCR is--rms. */
1385 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1388 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1390 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1391 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1393 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1395 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1398 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1400 tty
.main
.c_iflag
&= ~IXANY
;
1404 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1405 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1407 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1411 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1412 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1415 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1416 /* Set up C-g for both SIGQUIT and SIGINT.
1417 We don't know which we will get, but we handle both alike
1418 so which one it really gives us does not matter. */
1419 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1420 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1421 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1423 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1427 #if defined (mips) || defined (HAVE_TCATTR)
1429 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1432 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1433 #endif /* V_DSUSP */
1434 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1435 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1438 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1441 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1442 #endif /* VREPRINT */
1444 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1445 #endif /* VWERASE */
1447 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1448 #endif /* VDISCARD */
1453 tty
.main
.c_cc
[VSTART
] = '\021';
1456 tty
.main
.c_cc
[VSTOP
] = '\023';
1462 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1465 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1468 #endif /* mips or HAVE_TCATTR */
1470 #ifdef SET_LINE_DISCIPLINE
1471 /* Need to explicitly request TERMIODISC line discipline or
1472 Ultrix's termios does not work correctly. */
1473 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1477 /* AIX enhanced edit loses NULs, so disable it. */
1478 tty
.main
.c_line
= 0;
1479 tty
.main
.c_iflag
&= ~ASCEDIT
;
1481 tty
.main
.c_cc
[VSTRT
] = 255;
1482 tty
.main
.c_cc
[VSTOP
] = 255;
1483 tty
.main
.c_cc
[VSUSP
] = 255;
1484 tty
.main
.c_cc
[VDSUSP
] = 255;
1485 #endif /* IBMR2AIX */
1489 tty
.main
.c_cc
[VSTART
] = '\021';
1492 tty
.main
.c_cc
[VSTOP
] = '\023';
1495 /* Also, PTY overloads NUL and BREAK.
1496 don't ignore break, but don't signal either, so it looks like NUL.
1497 This really serves a purpose only if running in an XTERM window
1498 or via TELNET or the like, but does no harm elsewhere. */
1499 tty
.main
.c_iflag
&= ~IGNBRK
;
1500 tty
.main
.c_iflag
&= ~BRKINT
;
1502 #else /* if not HAVE_TERMIO */
1504 tty
.main
.tt_char
|= TT$M_NOECHO
;
1506 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1508 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1510 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1511 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1512 #else /* not VMS (BSD, that is) */
1514 XSETINT (Vtty_erase_char
, tty
.main
.sg_erase
);
1515 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1517 tty
.main
.sg_flags
|= ANYP
;
1518 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1519 #endif /* not DOS_NT */
1520 #endif /* not VMS (BSD, that is) */
1521 #endif /* not HAVE_TERMIO */
1523 /* If going to use CBREAK mode, we must request C-g to interrupt
1524 and turn off start and stop chars, etc. If not going to use
1525 CBREAK mode, do this anyway so as to turn off local flow
1526 control for user coming over network on 4.2; in this case,
1527 only t_stopc and t_startc really matter. */
1530 /* Note: if not using CBREAK mode, it makes no difference how we
1532 tty
.tchars
= new_tchars
;
1533 tty
.tchars
.t_intrc
= quit_char
;
1536 tty
.tchars
.t_startc
= '\021';
1537 tty
.tchars
.t_stopc
= '\023';
1540 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1542 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1543 anything, and leaving it in breaks the meta key. Go figure. */
1544 tty
.lmode
&= ~LLITOUT
;
1551 #endif /* HAVE_TCHARS */
1552 #endif /* not HAVE_TERMIO */
1555 tty
.ltchars
= new_ltchars
;
1556 #endif /* HAVE_LTCHARS */
1557 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1559 internal_terminal_init ();
1563 EMACS_SET_TTY (input_fd
, &tty
, 0);
1565 /* This code added to insure that, if flow-control is not to be used,
1566 we have an unlocked terminal at the start. */
1569 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1573 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1577 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1579 if (!flow_control
) tcflow (input_fd
, TCOON
);
1587 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1588 to be only LF. This is the way that is done. */
1591 if (ioctl (1, HFTGETID
, &tty
) != -1)
1592 write (1, "\033[20l", 5);
1598 /* Appears to do nothing when in PASTHRU mode.
1599 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1600 interrupt_signal, oob_chars, 0, 0, 0, 0);
1602 queue_kbd_input (0);
1607 #ifndef F_SETOWN_BUG
1608 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1610 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1612 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1613 fcntl (input_fd
, F_SETOWN
, getpid ());
1614 init_sigio (input_fd
);
1616 #endif /* F_GETOWN */
1617 #endif /* F_SETOWN_BUG */
1618 #endif /* F_SETFL */
1621 if (interrupt_input
)
1622 init_sigio (input_fd
);
1625 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1629 /* This symbol is defined on recent USG systems.
1630 Someone says without this call USG won't really buffer the file
1631 even with a call to setbuf. */
1632 setvbuf (stdout
, (char *) _sobuf
, _IOFBF
, sizeof _sobuf
);
1634 setbuf (stdout
, (char *) _sobuf
);
1636 #ifdef HAVE_WINDOW_SYSTEM
1637 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1638 needs the initialization code below. */
1639 if (EQ (Vwindow_system
, Qnil
)
1641 /* When running in tty mode on NT/Win95, we have a read_socket
1642 hook, but still need the rest of the initialization code below. */
1643 && (! read_socket_hook
)
1647 set_terminal_modes ();
1650 && FRAMEP (Vterminal_frame
)
1651 && FRAME_TERMCAP_P (XFRAME (Vterminal_frame
)))
1652 init_frame_faces (XFRAME (Vterminal_frame
));
1654 if (term_initted
&& no_redraw_on_reenter
)
1656 if (display_completed
)
1657 direct_output_forward_char (0);
1662 if (FRAMEP (Vterminal_frame
))
1663 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1669 /* Return nonzero if safe to use tabs in output.
1670 At the time this is called, init_sys_modes has not been done yet. */
1675 struct emacs_tty tty
;
1677 EMACS_GET_TTY (input_fd
, &tty
);
1678 return EMACS_TTY_TABS_OK (&tty
);
1681 /* Get terminal size from system.
1682 Store number of lines into *HEIGHTP and width into *WIDTHP.
1683 We store 0 if there's no valid information. */
1686 get_frame_size (widthp
, heightp
)
1687 int *widthp
, *heightp
;
1693 struct winsize size
;
1695 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1696 *widthp
= *heightp
= 0;
1699 *widthp
= size
.ws_col
;
1700 *heightp
= size
.ws_row
;
1706 /* SunOS - style. */
1707 struct ttysize size
;
1709 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1710 *widthp
= *heightp
= 0;
1713 *widthp
= size
.ts_cols
;
1714 *heightp
= size
.ts_lines
;
1720 struct sensemode tty
;
1722 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1723 &tty
.class, 12, 0, 0, 0, 0);
1724 *widthp
= tty
.scr_wid
;
1725 *heightp
= tty
.scr_len
;
1729 *widthp
= ScreenCols ();
1730 *heightp
= ScreenRows ();
1731 #else /* system doesn't know size */
1736 #endif /* not VMS */
1737 #endif /* not SunOS-style */
1738 #endif /* not BSD-style */
1741 /* Set the logical window size associated with descriptor FD
1742 to HEIGHT and WIDTH. This is used mainly with ptys. */
1745 set_window_size (fd
, height
, width
)
1746 int fd
, height
, width
;
1751 struct winsize size
;
1752 size
.ws_row
= height
;
1753 size
.ws_col
= width
;
1755 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1756 return 0; /* error */
1763 /* SunOS - style. */
1764 struct ttysize size
;
1765 size
.ts_lines
= height
;
1766 size
.ts_cols
= width
;
1768 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1774 #endif /* not SunOS-style */
1775 #endif /* not BSD-style */
1779 /* Prepare the terminal for exiting Emacs; move the cursor to the
1780 bottom of the frame, turn off interrupt-driven I/O, etc. */
1793 #ifdef HAVE_WINDOW_SYSTEM
1794 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1795 needs the clean-up code below. */
1796 if (!EQ (Vwindow_system
, Qnil
)
1798 /* When running in tty mode on NT/Win95, we have a read_socket
1799 hook, but still need the rest of the clean-up code below. */
1805 sf
= SELECTED_FRAME ();
1806 cursor_to (FRAME_HEIGHT (sf
) - 1, 0);
1807 clear_end_of_line (FRAME_WIDTH (sf
));
1808 /* clear_end_of_line may move the cursor */
1809 cursor_to (FRAME_HEIGHT (sf
) - 1, 0);
1810 #if defined (IBMR2AIX) && defined (AIXHFT)
1812 /* HFT devices normally use ^J as a LF/CR. We forced it to
1813 do the LF only. Now, we need to reset it. */
1816 if (ioctl (1, HFTGETID
, &tty
) != -1)
1817 write (1, "\033[20h", 5);
1821 reset_terminal_modes ();
1825 /* Avoid possible loss of output when changing terminal modes. */
1826 fsync (fileno (stdout
));
1831 #ifndef F_SETOWN_BUG
1832 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1833 if (interrupt_input
)
1836 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1838 #endif /* F_SETOWN */
1839 #endif /* F_SETOWN_BUG */
1841 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1843 #endif /* F_SETFL */
1845 if (interrupt_input
)
1850 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1853 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1857 #ifdef SET_LINE_DISCIPLINE
1858 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1859 A different old line discipline is therefore not restored, yet.
1860 Restore the old line discipline by hand. */
1861 ioctl (0, TIOCSETD
, &old_tty
.main
.c_line
);
1869 widen_foreground_group ();
1875 /* Set up the proper status flags for use of a pty. */
1881 /* I'm told that TOICREMOTE does not mean control chars
1882 "can't be sent" but rather that they don't have
1883 input-editing or signaling effects.
1884 That should be good, because we have other ways
1885 to do those things in Emacs.
1886 However, telnet mode seems not to work on 4.2.
1887 So TIOCREMOTE is turned off now. */
1889 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1890 will hang. In particular, the "timeout" feature (which
1891 causes a read to return if there is no data available)
1892 does this. Also it is known that telnet mode will hang
1893 in such a way that Emacs must be stopped (perhaps this
1894 is the same problem).
1896 If TIOCREMOTE is turned off, then there is a bug in
1897 hp-ux which sometimes loses data. Apparently the
1898 code which blocks the master process when the internal
1899 buffer fills up does not work. Other than this,
1900 though, everything else seems to work fine.
1902 Since the latter lossage is more benign, we may as well
1903 lose that way. -- cph */
1905 #if defined(SYSV_PTYS) || defined(UNIX98_PTYS)
1908 ioctl (fd
, FIONBIO
, &on
);
1913 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1914 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1915 /* cause EMACS not to die when it should, i.e., when its own controlling */
1916 /* tty goes away. I've complained to the AIX developers, and they may */
1917 /* change this behavior, but I'm not going to hold my breath. */
1918 signal (SIGHUP
, SIG_IGN
);
1921 #endif /* HAVE_PTYS */
1925 /* Assigning an input channel is done at the start of Emacs execution.
1926 This is called each time Emacs is resumed, also, but does nothing
1927 because input_chain is no longer zero. */
1936 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1942 /* Deassigning the input channel is done before exiting. */
1947 return SYS$
DASSGN (input_fd
);
1952 /* Request reading one character into the keyboard buffer.
1953 This is done as soon as the buffer becomes empty. */
1959 extern kbd_input_ast ();
1961 waiting_for_ast
= 0;
1963 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1964 &input_iosb
, kbd_input_ast
, 1,
1965 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1970 /* Ast routine that is called when keyboard input comes in
1971 in accord with the SYS$QIO above. */
1976 register int c
= -1;
1977 int old_errno
= errno
;
1978 extern EMACS_TIME
*input_available_clear_time
;
1980 if (waiting_for_ast
)
1981 SYS$
SETEF (input_ef
);
1982 waiting_for_ast
= 0;
1985 if (input_count
== 25)
1987 printf ("Ast # %d,", input_count
);
1988 printf (" iosb = %x, %x, %x, %x",
1989 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1992 if (input_iosb
.offset
)
1996 printf (", char = 0%o", c
);
2008 struct input_event e
;
2009 e
.kind
= ascii_keystroke
;
2010 XSETINT (e
.code
, c
);
2011 e
.frame_or_window
= selected_frame
;
2012 kbd_buffer_store_event (&e
);
2014 if (input_available_clear_time
)
2015 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
2019 /* Wait until there is something in kbd_buffer. */
2022 wait_for_kbd_input ()
2024 extern int have_process_input
, process_exited
;
2026 /* If already something, avoid doing system calls. */
2027 if (detect_input_pending ())
2031 /* Clear a flag, and tell ast routine above to set it. */
2032 SYS$
CLREF (input_ef
);
2033 waiting_for_ast
= 1;
2034 /* Check for timing error: ast happened while we were doing that. */
2035 if (!detect_input_pending ())
2037 /* No timing error: wait for flag to be set. */
2038 set_waiting_for_input (0);
2039 SYS$
WFLOR (input_ef
, input_eflist
);
2040 clear_waiting_for_input (0);
2041 if (!detect_input_pending ())
2042 /* Check for subprocess input availability */
2044 int dsp
= have_process_input
|| process_exited
;
2046 SYS$
CLREF (process_ef
);
2047 if (have_process_input
)
2048 process_command_input ();
2053 update_mode_lines
++;
2054 prepare_menu_bars ();
2055 redisplay_preserve_echo_area (18);
2059 waiting_for_ast
= 0;
2062 /* Get rid of any pending QIO, when we are about to suspend
2063 or when we want to throw away pending input.
2064 We wait for a positive sign that the AST routine has run
2065 and therefore there is no I/O request queued when we return.
2066 SYS$SETAST is used to avoid a timing error. */
2072 printf ("At end_kbd_input.\n");
2076 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2078 SYS$
CANCEL (input_fd
);
2083 /* Clear a flag, and tell ast routine above to set it. */
2084 SYS$
CLREF (input_ef
);
2085 waiting_for_ast
= 1;
2087 SYS$
CANCEL (input_fd
);
2089 SYS$
WAITFR (input_ef
);
2090 waiting_for_ast
= 0;
2093 /* Wait for either input available or time interval expiry. */
2096 input_wait_timeout (timeval
)
2097 int timeval
; /* Time to wait, in seconds */
2100 static int zero
= 0;
2101 static int large
= -10000000;
2103 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2105 /* If already something, avoid doing system calls. */
2106 if (detect_input_pending ())
2110 /* Clear a flag, and tell ast routine above to set it. */
2111 SYS$
CLREF (input_ef
);
2112 waiting_for_ast
= 1;
2113 /* Check for timing error: ast happened while we were doing that. */
2114 if (!detect_input_pending ())
2116 /* No timing error: wait for flag to be set. */
2118 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2119 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
2121 waiting_for_ast
= 0;
2124 /* The standard `sleep' routine works some other way
2125 and it stops working if you have ever quit out of it.
2126 This one continues to work. */
2132 static int zero
= 0;
2133 static int large
= -10000000;
2135 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2138 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2139 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2157 croak ("request sigio");
2163 croak ("unrequest sigio");
2168 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2173 #ifndef SYSTEM_MALLOC
2180 /* Some systems that cannot dump also cannot implement these. */
2183 * Return the address of the start of the text segment prior to
2184 * doing an unexec. After unexec the return value is undefined.
2185 * See crt0.c for further explanation and _start.
2189 #if !(defined (__NetBSD__) && defined (__ELF__))
2190 #ifndef HAVE_TEXT_START
2195 return ((char *) TEXT_START
);
2199 return ((char *) csrt
);
2200 #else /* not GOULD */
2201 extern int _start ();
2202 return ((char *) _start
);
2204 #endif /* TEXT_START */
2206 #endif /* not HAVE_TEXT_START */
2210 * Return the address of the start of the data segment prior to
2211 * doing an unexec. After unexec the return value is undefined.
2212 * See crt0.c for further information and definition of data_start.
2214 * Apparently, on BSD systems this is etext at startup. On
2215 * USG systems (swapping) this is highly mmu dependent and
2216 * is also dependent on whether or not the program is running
2217 * with shared text. Generally there is a (possibly large)
2218 * gap between end of text and start of data with shared text.
2220 * On Uniplus+ systems with shared text, data starts at a
2221 * fixed address. Each port (from a given oem) is generally
2222 * different, and the specific value of the start of data can
2223 * be obtained via the UniPlus+ specific "uvar" system call,
2224 * however the method outlined in crt0.c seems to be more portable.
2226 * Probably what will have to happen when a USG unexec is available,
2227 * at least on UniPlus, is temacs will have to be made unshared so
2228 * that text and data are contiguous. Then once loadup is complete,
2229 * unexec will produce a shared executable where the data can be
2230 * at the normal shared text boundary and the startofdata variable
2231 * will be patched by unexec to the correct value.
2239 return ((char *) DATA_START
);
2241 #ifdef ORDINARY_LINK
2243 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2244 * data_start isn't defined. We take the address of environ, which
2245 * is known to live at or near the start of the system crt0.c, and
2246 * we don't sweat the handful of bytes that might lose.
2248 extern char **environ
;
2250 return ((char *) &environ
);
2252 extern int data_start
;
2253 return ((char *) &data_start
);
2254 #endif /* ORDINARY_LINK */
2255 #endif /* DATA_START */
2257 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2260 /* Some systems that cannot dump also cannot implement these. */
2263 * Return the address of the end of the text segment prior to
2264 * doing an unexec. After unexec the return value is undefined.
2271 return ((char *) TEXT_END
);
2274 return ((char *) &etext
);
2279 * Return the address of the end of the data segment prior to
2280 * doing an unexec. After unexec the return value is undefined.
2287 return ((char *) DATA_END
);
2290 return ((char *) &edata
);
2294 #endif /* not CANNOT_DUMP */
2296 /* init_system_name sets up the string for the Lisp function
2297 system-name to return. */
2303 extern Lisp_Object Vsystem_name
;
2308 #include <sys/socket.h>
2310 #endif /* HAVE_SOCKETS */
2311 #endif /* not VMS */
2312 #endif /* not BSD4_1 */
2315 #ifndef HAVE_H_ERRNO
2318 #endif /* TRY_AGAIN */
2324 Vsystem_name
= build_string (sysname
);
2328 if ((sp
= egetenv ("SYS$NODE")) == 0)
2329 Vsystem_name
= build_string ("vax-vms");
2330 else if ((end
= index (sp
, ':')) == 0)
2331 Vsystem_name
= build_string (sp
);
2333 Vsystem_name
= make_string (sp
, end
- sp
);
2335 #ifndef HAVE_GETHOSTNAME
2338 Vsystem_name
= build_string (uts
.nodename
);
2339 #else /* HAVE_GETHOSTNAME */
2340 unsigned int hostname_size
= 256;
2341 char *hostname
= (char *) alloca (hostname_size
);
2343 /* Try to get the host name; if the buffer is too short, try
2344 again. Apparently, the only indication gethostname gives of
2345 whether the buffer was large enough is the presence or absence
2346 of a '\0' in the string. Eech. */
2349 gethostname (hostname
, hostname_size
- 1);
2350 hostname
[hostname_size
- 1] = '\0';
2352 /* Was the buffer large enough for the '\0'? */
2353 if (strlen (hostname
) < hostname_size
- 1)
2356 hostname_size
<<= 1;
2357 hostname
= (char *) alloca (hostname_size
);
2360 /* Turn the hostname into the official, fully-qualified hostname.
2361 Don't do this if we're going to dump; this can confuse system
2362 libraries on some machines and make the dumped emacs core dump. */
2365 #endif /* not CANNOT_DUMP */
2366 if (! index (hostname
, '.'))
2370 for (count
= 0;; count
++)
2375 hp
= gethostbyname (hostname
);
2377 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2382 Fsleep_for (make_number (1), Qnil
);
2386 char *fqdn
= (char *) hp
->h_name
;
2389 if (!index (fqdn
, '.'))
2391 /* We still don't have a fully qualified domain name.
2392 Try to find one in the list of alternate names */
2393 char **alias
= hp
->h_aliases
;
2394 while (*alias
&& !index (*alias
, '.'))
2401 /* Convert the host name to lower case. */
2402 /* Using ctype.h here would introduce a possible locale
2403 dependence that is probably wrong for hostnames. */
2407 if (*p
>= 'A' && *p
<= 'Z')
2414 #endif /* HAVE_SOCKETS */
2415 /* We used to try using getdomainname here,
2416 but NIIBE Yutaka <gniibe@etl.go.jp> says that
2417 getdomainname gets the NIS/YP domain which often is not the same
2418 as in Internet domain name. */
2419 #if 0 /* Turned off because sysinfo is not really likely to return the
2420 correct Internet domain. */
2421 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2422 if (! index (hostname
, '.'))
2424 /* The hostname is not fully qualified. Append the domain name. */
2426 int hostlen
= strlen (hostname
);
2427 int domain_size
= 256;
2431 char *domain
= (char *) alloca (domain_size
+ 1);
2432 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2433 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2434 if (sys_domain_size
<= 0)
2436 if (domain_size
< sys_domain_size
)
2438 domain_size
= sys_domain_size
;
2441 strcpy (fqdn
, hostname
);
2442 if (domain
[0] == '.')
2443 strcpy (fqdn
+ hostlen
, domain
);
2444 else if (domain
[0] != 0)
2446 fqdn
[hostlen
] = '.';
2447 strcpy (fqdn
+ hostlen
+ 1, domain
);
2453 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2455 Vsystem_name
= build_string (hostname
);
2456 #endif /* HAVE_GETHOSTNAME */
2461 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2462 if (*p
== ' ' || *p
== '\t')
2469 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2471 #include "sysselect.h"
2474 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2475 /* Cause explanatory error message at compile time,
2476 since the select emulation is not good enough for X. */
2477 int *x
= &x_windows_lose_if_no_select_system_call
;
2480 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2481 * Only checks read descriptors.
2483 /* How long to wait between checking fds in select */
2484 #define SELECT_PAUSE 1
2487 /* For longjmp'ing back to read_input_waiting. */
2489 jmp_buf read_alarm_throw
;
2491 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2492 The read_socket_hook function sets this to 1 while it is waiting. */
2494 int read_alarm_should_throw
;
2502 #else /* not BSD4_1 */
2503 signal (SIGALRM
, SIG_IGN
);
2504 #endif /* not BSD4_1 */
2505 if (read_alarm_should_throw
)
2506 longjmp (read_alarm_throw
, 1);
2510 /* Only rfds are checked. */
2512 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2514 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2515 EMACS_TIME
*timeout
;
2521 extern int proc_buffered_char
[];
2522 #ifndef subprocesses
2523 int process_tick
= 0, update_tick
= 0;
2525 extern int process_tick
, update_tick
;
2529 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2530 /* If we're using X, then the native select will work; we only need the
2531 emulation for non-X usage. */
2532 if (!NILP (Vwindow_system
))
2533 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2535 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2536 local_timeout
= &timeoutval
;
2548 /* If we are looking only for the terminal, with no timeout,
2549 just read it and wait -- that's more efficient. */
2550 if (*local_timeout
== 100000 && process_tick
== update_tick
2551 && FD_ISSET (0, &orfds
))
2554 for (fd
= 1; fd
< nfds
; ++fd
)
2555 if (FD_ISSET (fd
, &orfds
))
2557 if (! detect_input_pending ())
2558 read_input_waiting ();
2564 /* Once a second, till the timer expires, check all the flagged read
2565 * descriptors to see if any input is available. If there is some then
2566 * set the corresponding bit in the return copy of rfds.
2570 register int to_check
, fd
;
2574 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2576 if (FD_ISSET (fd
, &orfds
))
2578 int avail
= 0, status
= 0;
2581 avail
= detect_input_pending (); /* Special keyboard handler */
2585 status
= ioctl (fd
, FIONREAD
, &avail
);
2586 #else /* no FIONREAD */
2587 /* Hoping it will return -1 if nothing available
2588 or 0 if all 0 chars requested are read. */
2589 if (proc_buffered_char
[fd
] >= 0)
2593 avail
= read (fd
, &buf
, 1);
2595 proc_buffered_char
[fd
] = buf
;
2597 #endif /* no FIONREAD */
2599 if (status
>= 0 && avail
> 0)
2607 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2610 turn_on_atimers (0);
2611 signal (SIGALRM
, select_alarm
);
2613 alarm (SELECT_PAUSE
);
2615 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2616 while (select_alarmed
== 0 && *local_timeout
!= 0
2617 && process_tick
== update_tick
)
2619 /* If we are interested in terminal input,
2620 wait by reading the terminal.
2621 That makes instant wakeup for terminal input at least. */
2622 if (FD_ISSET (0, &orfds
))
2624 read_input_waiting ();
2625 if (detect_input_pending ())
2631 (*local_timeout
) -= SELECT_PAUSE
;
2633 /* Reset the old alarm if there was one. */
2634 turn_on_atimers (1);
2636 if (*local_timeout
== 0) /* Stop on timer being cleared */
2641 #endif /* not WINDOWSNT */
2643 /* Read keyboard input into the standard buffer,
2644 waiting for at least one character. */
2646 /* Make all keyboard buffers much bigger when using a window system. */
2647 #ifdef HAVE_WINDOW_SYSTEM
2648 #define BUFFER_SIZE_FACTOR 16
2650 #define BUFFER_SIZE_FACTOR 1
2654 read_input_waiting ()
2656 struct input_event e
;
2658 extern int quit_char
;
2660 if (read_socket_hook
)
2662 struct input_event buf
[256];
2664 read_alarm_should_throw
= 0;
2665 if (! setjmp (read_alarm_throw
))
2666 nread
= (*read_socket_hook
) (0, buf
, 256, 1);
2670 /* Scan the chars for C-g and store them in kbd_buffer. */
2671 for (i
= 0; i
< nread
; i
++)
2673 kbd_buffer_store_event (&buf
[i
]);
2674 /* Don't look at input that follows a C-g too closely.
2675 This reduces lossage due to autorepeat on C-g. */
2676 if (buf
[i
].kind
== ascii_keystroke
2677 && buf
[i
].code
== quit_char
)
2684 nread
= read (fileno (stdin
), buf
, 1);
2686 /* Scan the chars for C-g and store them in kbd_buffer. */
2687 e
.kind
= ascii_keystroke
;
2688 e
.frame_or_window
= selected_frame
;
2690 for (i
= 0; i
< nread
; i
++)
2692 /* Convert chars > 0177 to meta events if desired.
2693 We do this under the same conditions that read_avail_input does. */
2694 if (read_socket_hook
== 0)
2696 /* If the user says she has a meta key, then believe her. */
2697 if (meta_key
== 1 && (buf
[i
] & 0x80))
2698 e
.modifiers
= meta_modifier
;
2703 XSETINT (e
.code
, buf
[i
]);
2704 kbd_buffer_store_event (&e
);
2705 /* Don't look at input that follows a C-g too closely.
2706 This reduces lossage due to autorepeat on C-g. */
2707 if (buf
[i
] == quit_char
)
2713 #endif /* not HAVE_SELECT */
2714 #endif /* not VMS */
2715 #endif /* not MSDOS */
2724 lmode
= LINTRUP
| lmode
;
2725 ioctl (fd
, TIOCLSET
, &lmode
);
2733 lmode
= ~LINTRUP
& lmode
;
2734 ioctl (0, TIOCLSET
, &lmode
);
2742 interrupts_deferred
= 0;
2750 interrupts_deferred
= 1;
2753 /* still inside #ifdef BSD4_1 */
2756 int sigheld
; /* Mask of held signals */
2762 sigheld
|= sigbit (signum
);
2770 sigheld
|= sigbit (signum
);
2777 sigheld
&= ~sigbit (signum
);
2782 sigfree () /* Free all held signals */
2785 for (i
= 0; i
< NSIG
; i
++)
2786 if (sigheld
& sigbit (i
))
2794 return 1 << (i
- 1);
2796 #endif /* subprocesses */
2799 /* POSIX signals support - DJB */
2800 /* Anyone with POSIX signals should have ANSI C declarations */
2802 #ifdef POSIX_SIGNALS
2804 sigset_t empty_mask
, full_mask
;
2807 sys_signal (int signal_number
, signal_handler_t action
)
2809 struct sigaction new_action
, old_action
;
2810 sigemptyset (&new_action
.sa_mask
);
2811 new_action
.sa_handler
= action
;
2812 #if defined (SA_RESTART) && ! defined (BROKEN_SA_RESTART)
2813 /* Emacs mostly works better with restartable system services. If this
2814 flag exists, we probably want to turn it on here.
2815 However, on some systems this resets the timeout of `select'
2816 which means that `select' never finishes if it keeps getting signals.
2817 BROKEN_SA_RESTART is defined on those systems. */
2818 new_action
.sa_flags
= SA_RESTART
;
2820 new_action
.sa_flags
= 0;
2822 sigaction (signal_number
, &new_action
, &old_action
);
2823 return (old_action
.sa_handler
);
2827 /* If we're compiling with GCC, we don't need this function, since it
2828 can be written as a macro. */
2830 sys_sigmask (int sig
)
2833 sigemptyset (&mask
);
2834 sigaddset (&mask
, sig
);
2839 /* I'd like to have these guys return pointers to the mask storage in here,
2840 but there'd be trouble if the code was saving multiple masks. I'll be
2841 safe and pass the structure. It normally won't be more than 2 bytes
2845 sys_sigblock (sigset_t new_mask
)
2848 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2853 sys_sigunblock (sigset_t new_mask
)
2856 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2861 sys_sigsetmask (sigset_t new_mask
)
2864 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2868 #endif /* POSIX_SIGNALS */
2870 #if !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED
2871 static char *my_sys_siglist
[NSIG
];
2875 # define sys_siglist my_sys_siglist
2881 #ifdef POSIX_SIGNALS
2882 sigemptyset (&empty_mask
);
2883 sigfillset (&full_mask
);
2886 #if !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED
2890 sys_siglist
[SIGABRT
] = "Aborted";
2893 sys_siglist
[SIGAIO
] = "LAN I/O interrupt";
2896 sys_siglist
[SIGALRM
] = "Alarm clock";
2899 sys_siglist
[SIGBUS
] = "Bus error";
2902 sys_siglist
[SIGCLD
] = "Child status changed";
2905 sys_siglist
[SIGCHLD
] = "Child status changed";
2908 sys_siglist
[SIGCONT
] = "Continued";
2911 sys_siglist
[SIGDANGER
] = "Swap space dangerously low";
2914 sys_siglist
[SIGDGNOTIFY
] = "Notification message in queue";
2917 sys_siglist
[SIGEMT
] = "Emulation trap";
2920 sys_siglist
[SIGFPE
] = "Arithmetic exception";
2923 sys_siglist
[SIGFREEZE
] = "SIGFREEZE";
2926 sys_siglist
[SIGGRANT
] = "Monitor mode granted";
2929 sys_siglist
[SIGHUP
] = "Hangup";
2932 sys_siglist
[SIGILL
] = "Illegal instruction";
2935 sys_siglist
[SIGINT
] = "Interrupt";
2938 sys_siglist
[SIGIO
] = "I/O possible";
2941 sys_siglist
[SIGIOINT
] = "I/O intervention required";
2944 sys_siglist
[SIGIOT
] = "IOT trap";
2947 sys_siglist
[SIGKILL
] = "Killed";
2950 sys_siglist
[SIGLOST
] = "Resource lost";
2953 sys_siglist
[SIGLWP
] = "SIGLWP";
2956 sys_siglist
[SIGMSG
] = "Monitor mode data available";
2959 sys_siglist
[SIGWIND
] = "SIGPHONE";
2962 sys_siglist
[SIGPIPE
] = "Broken pipe";
2965 sys_siglist
[SIGPOLL
] = "Pollable event occurred";
2968 sys_siglist
[SIGPROF
] = "Profiling timer expired";
2971 sys_siglist
[SIGPTY
] = "PTY I/O interrupt";
2974 sys_siglist
[SIGPWR
] = "Power-fail restart";
2977 sys_siglist
[SIGQUIT
] = "Quit";
2980 sys_siglist
[SIGRETRACT
] = "Need to relinguish monitor mode";
2983 sys_siglist
[SIGSAK
] = "Secure attention";
2986 sys_siglist
[SIGSEGV
] = "Segmentation violation";
2989 sys_siglist
[SIGSOUND
] = "Sound completed";
2992 sys_siglist
[SIGSTOP
] = "Stopped (signal)";
2995 sys_siglist
[SIGSTP
] = "Stopped (user)";
2998 sys_siglist
[SIGSYS
] = "Bad argument to system call";
3001 sys_siglist
[SIGTERM
] = "Terminated";
3004 sys_siglist
[SIGTHAW
] = "SIGTHAW";
3007 sys_siglist
[SIGTRAP
] = "Trace/breakpoint trap";
3010 sys_siglist
[SIGTSTP
] = "Stopped (user)";
3013 sys_siglist
[SIGTTIN
] = "Stopped (tty input)";
3016 sys_siglist
[SIGTTOU
] = "Stopped (tty output)";
3019 sys_siglist
[SIGURG
] = "Urgent I/O condition";
3022 sys_siglist
[SIGUSR1
] = "User defined signal 1";
3025 sys_siglist
[SIGUSR2
] = "User defined signal 2";
3028 sys_siglist
[SIGVTALRM
] = "Virtual timer expired";
3031 sys_siglist
[SIGWAITING
] = "Process's LWPs are blocked";
3034 sys_siglist
[SIGWINCH
] = "Window size changed";
3037 sys_siglist
[SIGWIND
] = "SIGWIND";
3040 sys_siglist
[SIGXCPU
] = "CPU time limit exceeded";
3043 sys_siglist
[SIGXFSZ
] = "File size limit exceeded";
3046 #endif /* !defined HAVE_STRSIGNAL && !defined SYS_SIGLIST_DECLARED */
3055 /* Figure out how many bits the system's random number generator uses.
3056 `random' and `lrand48' are assumed to return 31 usable bits.
3057 BSD `rand' returns a 31 bit value but the low order bits are unusable;
3058 so we'll shift it and treat it like the 15-bit USG `rand'. */
3062 # define RAND_BITS 31
3063 # else /* !HAVE_RANDOM */
3064 # ifdef HAVE_LRAND48
3065 # define RAND_BITS 31
3066 # define random lrand48
3067 # else /* !HAVE_LRAND48 */
3068 # define RAND_BITS 15
3069 # if RAND_MAX == 32767
3070 # define random rand
3071 # else /* RAND_MAX != 32767 */
3072 # if RAND_MAX == 2147483647
3073 # define random() (rand () >> 16)
3074 # else /* RAND_MAX != 2147483647 */
3076 # define random rand
3078 # define random() (rand () >> 16)
3080 # endif /* RAND_MAX != 2147483647 */
3081 # endif /* RAND_MAX != 32767 */
3082 # endif /* !HAVE_LRAND48 */
3083 # endif /* !HAVE_RANDOM */
3084 #endif /* !RAND_BITS */
3091 srandom ((unsigned int)arg
);
3093 # ifdef HAVE_LRAND48
3096 srand ((unsigned int)arg
);
3102 * Build a full Emacs-sized word out of whatever we've got.
3103 * This suffices even for a 64-bit architecture with a 15-bit rand.
3108 long val
= random ();
3109 #if VALBITS > RAND_BITS
3110 val
= (val
<< RAND_BITS
) ^ random ();
3111 #if VALBITS > 2*RAND_BITS
3112 val
= (val
<< RAND_BITS
) ^ random ();
3113 #if VALBITS > 3*RAND_BITS
3114 val
= (val
<< RAND_BITS
) ^ random ();
3115 #if VALBITS > 4*RAND_BITS
3116 val
= (val
<< RAND_BITS
) ^ random ();
3117 #endif /* need at least 5 */
3118 #endif /* need at least 4 */
3119 #endif /* need at least 3 */
3120 #endif /* need at least 2 */
3121 return val
& ((1L << VALBITS
) - 1);
3124 #ifdef WRONG_NAME_INSQUE
3137 /* If any place else asks for the TERM variable,
3138 allow it to be overridden with the EMACS_TERM variable
3139 before attempting to translate the logical name TERM. As a last
3140 resort, ask for VAX C's special idea of the TERM variable. */
3147 static char buf
[256];
3148 static struct dsc$descriptor_s equiv
3149 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
3150 static struct dsc$descriptor_s d_name
3151 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
3154 if (!strcmp (name
, "TERM"))
3156 val
= (char *) getenv ("EMACS_TERM");
3161 d_name
.dsc$w_length
= strlen (name
);
3162 d_name
.dsc$a_pointer
= name
;
3163 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
3165 char *str
= (char *) xmalloc (eqlen
+ 1);
3166 bcopy (buf
, str
, eqlen
);
3168 /* This is a storage leak, but a pain to fix. With luck,
3169 no one will ever notice. */
3172 return (char *) getenv (name
);
3177 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
3178 to force a call on the debugger from within the image. */
3183 LIB$
SIGNAL (SS$_DEBUG
);
3189 #ifdef LINK_CRTL_SHARE
3190 #ifdef SHARABLE_LIB_BUG
3191 /* Variables declared noshare and initialized in sharable libraries
3192 cannot be shared. The VMS linker incorrectly forces you to use a private
3193 version which is uninitialized... If not for this "feature", we
3194 could use the C library definition of sys_nerr and sys_errlist. */
3196 char *sys_errlist
[] =
3200 "no such file or directory",
3202 "interrupted system call",
3204 "no such device or address",
3205 "argument list too long",
3206 "exec format error",
3209 "no more processes",
3210 "not enough memory",
3211 "permission denied",
3213 "block device required",
3214 "mount devices busy",
3216 "cross-device link",
3221 "file table overflow",
3222 "too many open files",
3226 "no space left on device",
3228 "read-only file system",
3234 "vax/vms specific error code nontranslatable error"
3236 #endif /* SHARABLE_LIB_BUG */
3237 #endif /* LINK_CRTL_SHARE */
3240 #ifndef HAVE_STRERROR
3246 extern char *sys_errlist
[];
3247 extern int sys_nerr
;
3249 if (errnum
>= 0 && errnum
< sys_nerr
)
3250 return sys_errlist
[errnum
];
3251 return (char *) "Unknown error";
3253 #endif /* not WINDOWSNT */
3254 #endif /* ! HAVE_STRERROR */
3257 emacs_open (path
, oflag
, mode
)
3261 register int rtnval
;
3264 if (oflag
& O_CREAT
)
3265 return creat (path
, mode
);
3268 while ((rtnval
= open (path
, oflag
, mode
)) == -1
3269 && (errno
== EINTR
));
3278 register int rtnval
;
3280 while ((rtnval
= close (fd
)) == -1
3281 && (errno
== EINTR
))
3284 /* If close is interrupted SunOS 4.1 may or may not have closed the
3285 file descriptor. If it did the second close will fail with
3286 errno = EBADF. That means we have succeeded. */
3287 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3294 emacs_read (fildes
, buf
, nbyte
)
3299 register int rtnval
;
3301 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3302 && (errno
== EINTR
));
3307 emacs_write (fildes
, buf
, nbyte
)
3312 register int rtnval
, bytes_written
;
3318 rtnval
= write (fildes
, buf
, nbyte
);
3325 return (bytes_written
? bytes_written
: -1);
3330 bytes_written
+= rtnval
;
3332 return (bytes_written
);
3337 * All of the following are for USG.
3339 * On USG systems the system calls are INTERRUPTIBLE by signals
3340 * that the user program has elected to catch. Thus the system call
3341 * must be retried in these cases. To handle this without massive
3342 * changes in the source code, we remap the standard system call names
3343 * to names for our own functions in sysdep.c that do the system call
3344 * with retries. Actually, for portability reasons, it is good
3345 * programming practice, as this example shows, to limit all actual
3346 * system calls to a single occurrence in the source. Sure, this
3347 * adds an extra level of function call overhead but it is almost
3348 * always negligible. Fred Fish, Unisoft Systems Inc.
3352 * Warning, this function may not duplicate 4.2 action properly
3353 * under error conditions.
3357 /* In 4.1, param.h fails to define this. */
3358 #define MAXPATHLEN 1024
3367 char *npath
, *spath
;
3368 extern char *getcwd ();
3370 BLOCK_INPUT
; /* getcwd uses malloc */
3371 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3377 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3378 up to first slash. Should be harmless on other systems. */
3379 while (*npath
&& *npath
!= '/')
3381 strcpy (pathname
, npath
);
3382 free (spath
); /* getcwd uses malloc */
3387 #endif /* HAVE_GETWD */
3390 * Emulate rename using unlink/link. Note that this is
3391 * only partially correct. Also, doesn't enforce restriction
3392 * that files be of same type (regular->regular, dir->dir, etc).
3401 if (access (from
, 0) == 0)
3404 if (link (from
, to
) == 0)
3405 if (unlink (from
) == 0)
3417 /* HPUX curses library references perror, but as far as we know
3418 it won't be called. Anyway this definition will do for now. */
3424 #endif /* not HAVE_PERROR */
3430 * Emulate BSD dup2. First close newd if it already exists.
3431 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3432 * until we are, then close the unsuccessful ones.
3439 register int fd
, ret
;
3444 return fcntl (oldd
, F_DUPFD
, newd
);
3451 ret
= dup2 (old
,new);
3457 #endif /* not HAVE_DUP2 */
3460 * Gettimeofday. Simulate as much as possible. Only accurate
3461 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3462 * Only needed when subprocesses are defined.
3467 #ifndef HAVE_GETTIMEOFDAY
3472 gettimeofday (tp
, tzp
)
3474 struct timezone
*tzp
;
3476 extern long time ();
3478 tp
->tv_sec
= time ((long *)0);
3481 tzp
->tz_minuteswest
= -1;
3488 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3491 * This function will go away as soon as all the stubs fixed. (fnf)
3498 printf ("%s not yet implemented\r\n", badfunc
);
3505 /* Directory routines for systems that don't have them. */
3507 #ifdef SYSV_SYSTEM_DIR
3511 #if defined (BROKEN_CLOSEDIR) || !defined (HAVE_CLOSEDIR)
3515 register DIR *dirp
; /* stream from opendir */
3519 rtnval
= emacs_close (dirp
->dd_fd
);
3521 /* Some systems (like Solaris) allocate the buffer and the DIR all
3522 in one block. Why in the world are we freeing this ourselves
3524 #if ! (defined (sun) && defined (USG5_4))
3525 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3527 xfree ((char *) dirp
);
3531 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3532 #endif /* SYSV_SYSTEM_DIR */
3534 #ifdef NONSYSTEM_DIR_LIBRARY
3538 char *filename
; /* name of directory */
3540 register DIR *dirp
; /* -> malloc'ed storage */
3541 register int fd
; /* file descriptor for read */
3542 struct stat sbuf
; /* result of fstat */
3544 fd
= emacs_open (filename
, O_RDONLY
, 0);
3549 if (fstat (fd
, &sbuf
) < 0
3550 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3551 || (dirp
= (DIR *) xmalloc (sizeof (DIR))) == 0)
3555 return 0; /* bad luck today */
3560 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3567 register DIR *dirp
; /* stream from opendir */
3569 emacs_close (dirp
->dd_fd
);
3570 xfree ((char *) dirp
);
3578 ino_t od_ino
; /* inode */
3579 char od_name
[DIRSIZ
]; /* filename */
3581 #endif /* not VMS */
3583 struct direct dir_static
; /* simulated directory contents */
3588 register DIR *dirp
; /* stream from opendir */
3591 register struct olddir
*dp
; /* -> directory data */
3593 register struct dir$_name
*dp
; /* -> directory data */
3594 register struct dir$_version
*dv
; /* -> version data */
3599 if (dirp
->dd_loc
>= dirp
->dd_size
)
3600 dirp
->dd_loc
= dirp
->dd_size
= 0;
3602 if (dirp
->dd_size
== 0 /* refill buffer */
3603 && (dirp
->dd_size
= emacs_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3607 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3608 dirp
->dd_loc
+= sizeof (struct olddir
);
3610 if (dp
->od_ino
!= 0) /* not deleted entry */
3612 dir_static
.d_ino
= dp
->od_ino
;
3613 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3614 dir_static
.d_name
[DIRSIZ
] = '\0';
3615 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3616 dir_static
.d_reclen
= sizeof (struct direct
)
3618 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3619 return &dir_static
; /* -> simulated structure */
3622 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3623 if (dirp
->dd_loc
== 0)
3624 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3625 : dp
->dir$b_namecount
;
3626 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3627 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3628 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3629 dir_static
.d_reclen
= sizeof (struct direct
)
3631 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3632 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3633 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3634 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3641 /* readdirver is just like readdir except it returns all versions of a file
3642 as separate entries. */
3647 register DIR *dirp
; /* stream from opendir */
3649 register struct dir$_name
*dp
; /* -> directory data */
3650 register struct dir$_version
*dv
; /* -> version data */
3652 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3653 dirp
->dd_loc
= dirp
->dd_size
= 0;
3655 if (dirp
->dd_size
== 0 /* refill buffer */
3656 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3659 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3660 if (dirp
->dd_loc
== 0)
3661 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3662 : dp
->dir$b_namecount
;
3663 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3664 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3665 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3666 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3667 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3668 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3669 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3670 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3676 #endif /* NONSYSTEM_DIR_LIBRARY */
3680 set_file_times (filename
, atime
, mtime
)
3682 EMACS_TIME atime
, mtime
;
3685 struct timeval tv
[2];
3688 return utimes (filename
, tv
);
3689 #else /* not HAVE_UTIMES */
3691 utb
.actime
= EMACS_SECS (atime
);
3692 utb
.modtime
= EMACS_SECS (mtime
);
3693 return utime (filename
, &utb
);
3694 #endif /* not HAVE_UTIMES */
3697 /* mkdir and rmdir functions, for systems which don't have them. */
3701 * Written by Robert Rother, Mariah Corporation, August 1985.
3703 * If you want it, it's yours. All I ask in return is that if you
3704 * figure out how to do this in a Bourne Shell script you send me
3706 * sdcsvax!rmr or rmr@uscd
3708 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3709 * subroutine. 11Mar86; hoptoad!gnu
3711 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3712 * subroutine didn't return EEXIST. It does now.
3718 #ifdef MKDIR_PROTOTYPE
3722 mkdir (dpath
, dmode
)
3727 int cpid
, status
, fd
;
3728 struct stat statbuf
;
3730 if (stat (dpath
, &statbuf
) == 0)
3732 errno
= EEXIST
; /* Stat worked, so it already exists */
3736 /* If stat fails for a reason other than non-existence, return error */
3737 if (errno
!= ENOENT
)
3740 synch_process_alive
= 1;
3741 switch (cpid
= fork ())
3744 case -1: /* Error in fork */
3745 return (-1); /* Errno is set already */
3747 case 0: /* Child process */
3749 * Cheap hack to set mode of new directory. Since this
3750 * child process is going away anyway, we zap its umask.
3751 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3752 * directory. Does anybody care?
3754 status
= umask (0); /* Get current umask */
3755 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3756 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3763 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3764 _exit (-1); /* Can't exec /bin/mkdir */
3766 default: /* Parent process */
3767 wait_for_termination (cpid
);
3770 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3772 errno
= EIO
; /* We don't know why, but */
3773 return -1; /* /bin/mkdir failed */
3778 #endif /* not HAVE_MKDIR */
3785 int cpid
, status
, fd
;
3786 struct stat statbuf
;
3788 if (stat (dpath
, &statbuf
) != 0)
3790 /* Stat just set errno. We don't have to */
3794 synch_process_alive
= 1;
3795 switch (cpid
= fork ())
3798 case -1: /* Error in fork */
3799 return (-1); /* Errno is set already */
3801 case 0: /* Child process */
3802 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3809 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3810 _exit (-1); /* Can't exec /bin/rmdir */
3812 default: /* Parent process */
3813 wait_for_termination (cpid
);
3816 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3818 errno
= EIO
; /* We don't know why, but */
3819 return -1; /* /bin/rmdir failed */
3824 #endif /* !HAVE_RMDIR */
3828 /* Functions for VMS */
3830 #include "vms-pwd.h"
3835 /* Return as a string the VMS error string pertaining to STATUS.
3836 Reuses the same static buffer each time it is called. */
3840 int status
; /* VMS status code */
3844 static char buf
[257];
3846 bufadr
[0] = sizeof buf
- 1;
3847 bufadr
[1] = (int) buf
;
3848 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3849 return "untranslatable VMS error status";
3857 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3858 * not work correctly. (It also doesn't work well in version 2.3.)
3863 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3864 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3868 unsigned short s_buflen
;
3869 unsigned short s_code
;
3871 unsigned short *s_retlenadr
;
3875 #define buflen s.s_buflen
3876 #define code s.s_code
3877 #define bufadr s.s_bufadr
3878 #define retlenadr s.s_retlenadr
3880 #define R_OK 4 /* test for read permission */
3881 #define W_OK 2 /* test for write permission */
3882 #define X_OK 1 /* test for execute (search) permission */
3883 #define F_OK 0 /* test for presence of file */
3886 sys_access (path
, mode
)
3890 static char *user
= NULL
;
3893 /* translate possible directory spec into .DIR file name, so brain-dead
3894 * access can treat the directory like a file. */
3895 if (directory_file_name (path
, dir_fn
))
3899 return access (path
, mode
);
3900 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3906 unsigned short int dummy
;
3908 static int constant
= ACL$C_FILE
;
3909 DESCRIPTOR (path_desc
, path
);
3910 DESCRIPTOR (user_desc
, user
);
3914 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3917 acces
|= CHP$M_READ
;
3919 acces
|= CHP$M_WRITE
;
3920 itemlst
[0].buflen
= sizeof (int);
3921 itemlst
[0].code
= CHP$_FLAGS
;
3922 itemlst
[0].bufadr
= (char *) &flags
;
3923 itemlst
[0].retlenadr
= &dummy
;
3924 itemlst
[1].buflen
= sizeof (int);
3925 itemlst
[1].code
= CHP$_ACCESS
;
3926 itemlst
[1].bufadr
= (char *) &acces
;
3927 itemlst
[1].retlenadr
= &dummy
;
3928 itemlst
[2].end
= CHP$_END
;
3929 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3930 return stat
== SS$_NORMAL
? 0 : -1;
3934 #else /* not VMS4_4 */
3937 #define ACE$M_WRITE 2
3938 #define ACE$C_KEYID 1
3940 static unsigned short memid
, grpid
;
3941 static unsigned int uic
;
3943 /* Called from init_sys_modes, so it happens not very often
3944 but at least each time Emacs is loaded. */
3946 sys_access_reinit ()
3952 sys_access (filename
, type
)
3958 int status
, size
, i
, typecode
, acl_controlled
;
3959 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3960 union prvdef prvmask
;
3962 /* Get UIC and GRP values for protection checking. */
3965 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3968 memid
= uic
& 0xFFFF;
3972 if (type
!= 2) /* not checking write access */
3973 return access (filename
, type
);
3975 /* Check write protection. */
3977 #define CHECKPRIV(bit) (prvmask.bit)
3978 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3980 /* Find privilege bits */
3981 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3983 error ("Unable to find privileges: %s", vmserrstr (status
));
3984 if (CHECKPRIV (PRV$V_BYPASS
))
3985 return 0; /* BYPASS enabled */
3987 fab
.fab$b_fac
= FAB$M_GET
;
3988 fab
.fab$l_fna
= filename
;
3989 fab
.fab$b_fns
= strlen (filename
);
3990 fab
.fab$l_xab
= &xab
;
3991 xab
= cc$rms_xabpro
;
3992 xab
.xab$l_aclbuf
= aclbuf
;
3993 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3994 status
= SYS$
OPEN (&fab
, 0, 0);
3997 SYS$
CLOSE (&fab
, 0, 0);
3998 /* Check system access */
3999 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
4001 /* Check ACL entries, if any */
4003 if (xab
.xab$w_acllen
> 0)
4006 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
4007 while (*aclptr
&& aclptr
< aclend
)
4009 size
= (*aclptr
& 0xff) / 4;
4010 typecode
= (*aclptr
>> 8) & 0xff;
4011 if (typecode
== ACE$C_KEYID
)
4012 for (i
= size
- 1; i
> 1; i
--)
4013 if (aclptr
[i
] == uic
)
4016 if (aclptr
[1] & ACE$M_WRITE
)
4017 return 0; /* Write access through ACL */
4019 aclptr
= &aclptr
[size
];
4021 if (acl_controlled
) /* ACL specified, prohibits write access */
4024 /* No ACL entries specified, check normal protection */
4025 if (WRITABLE (XAB$V_WLD
)) /* World writable */
4027 if (WRITABLE (XAB$V_GRP
) &&
4028 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
4029 return 0; /* Group writable */
4030 if (WRITABLE (XAB$V_OWN
) &&
4031 (xab
.xab$l_uic
& 0xFFFF) == memid
)
4032 return 0; /* Owner writable */
4034 return -1; /* Not writable */
4036 #endif /* not VMS4_4 */
4039 static char vtbuf
[NAM$C_MAXRSS
+1];
4041 /* translate a vms file spec to a unix path */
4043 sys_translate_vms (vfile
)
4054 /* leading device or logical name is a root directory */
4055 if (p
= strchr (vfile
, ':'))
4064 if (*p
== '[' || *p
== '<')
4066 while (*++vfile
!= *p
+ 2)
4070 if (vfile
[-1] == *p
)
4093 static char utbuf
[NAM$C_MAXRSS
+1];
4095 /* translate a unix path to a VMS file spec */
4097 sys_translate_unix (ufile
)
4120 if (index (&ufile
[1], '/'))
4127 if (index (&ufile
[1], '/'))
4134 if (strncmp (ufile
, "./", 2) == 0)
4141 ufile
++; /* skip the dot */
4142 if (index (&ufile
[1], '/'))
4147 else if (strncmp (ufile
, "../", 3) == 0)
4155 ufile
+= 2; /* skip the dots */
4156 if (index (&ufile
[1], '/'))
4181 extern char *getcwd ();
4183 #define MAXPATHLEN 1024
4185 ptr
= xmalloc (MAXPATHLEN
);
4186 val
= getcwd (ptr
, MAXPATHLEN
);
4192 strcpy (pathname
, ptr
);
4201 long item_code
= JPI$_OWNER
;
4202 unsigned long parent_id
;
4205 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4208 vaxc$errno
= status
;
4218 return (getgid () << 16) | getuid ();
4223 sys_read (fildes
, buf
, nbyte
)
4228 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4233 sys_write (fildes
, buf
, nbyte
)
4238 register int nwrote
, rtnval
= 0;
4240 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4246 return rtnval
? rtnval
: -1;
4247 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4248 return rtnval
? rtnval
: -1;
4249 return (rtnval
+ nwrote
);
4254 * VAX/VMS VAX C RTL really loses. It insists that records
4255 * end with a newline (carriage return) character, and if they
4256 * don't it adds one (nice of it isn't it!)
4258 * Thus we do this stupidity below.
4263 sys_write (fildes
, buf
, nbytes
)
4266 unsigned int nbytes
;
4273 fstat (fildes
, &st
);
4279 /* Handle fixed-length files with carriage control. */
4280 if (st
.st_fab_rfm
== FAB$C_FIX
4281 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4283 len
= st
.st_fab_mrs
;
4284 retval
= write (fildes
, p
, min (len
, nbytes
));
4287 retval
++; /* This skips the implied carriage control */
4291 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4292 while (*e
!= '\n' && e
> p
) e
--;
4293 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4294 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4296 retval
= write (fildes
, p
, len
);
4307 /* Create file NEW copying its attributes from file OLD. If
4308 OLD is 0 or does not exist, create based on the value of
4311 /* Protection value the file should ultimately have.
4312 Set by create_copy_attrs, and use by rename_sansversions. */
4313 static unsigned short int fab_final_pro
;
4316 creat_copy_attrs (old
, new)
4319 struct FAB fab
= cc$rms_fab
;
4320 struct XABPRO xabpro
;
4321 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4322 extern int vms_stmlf_recfm
;
4326 fab
.fab$b_fac
= FAB$M_GET
;
4327 fab
.fab$l_fna
= old
;
4328 fab
.fab$b_fns
= strlen (old
);
4329 fab
.fab$l_xab
= (char *) &xabpro
;
4330 xabpro
= cc$rms_xabpro
;
4331 xabpro
.xab$l_aclbuf
= aclbuf
;
4332 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4333 /* Call $OPEN to fill in the fab & xabpro fields. */
4334 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4336 SYS$
CLOSE (&fab
, 0, 0);
4337 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4338 if (xabpro
.xab$w_acllen
> 0)
4340 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4341 /* If the acl buffer was too short, redo open with longer one.
4342 Wouldn't need to do this if there were some system imposed
4343 limit on the size of an ACL, but I can't find any such. */
4345 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4346 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4347 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4348 SYS$
CLOSE (&fab
, 0, 0);
4354 xabpro
.xab$l_aclbuf
= 0;
4359 fab
.fab$l_fna
= new;
4360 fab
.fab$b_fns
= strlen (new);
4364 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4365 fab
.fab$b_rat
= FAB$M_CR
;
4368 /* Set the file protections such that we will be able to manipulate
4369 this file. Once we are done writing and renaming it, we will set
4370 the protections back. */
4372 fab_final_pro
= xabpro
.xab$w_pro
;
4374 SYS$
SETDFPROT (0, &fab_final_pro
);
4375 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4377 /* Create the new file with either default attrs or attrs copied
4379 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4381 SYS$
CLOSE (&fab
, 0, 0);
4382 /* As this is a "replacement" for creat, return a file descriptor
4383 opened for writing. */
4384 return open (new, O_WRONLY
);
4389 #include <varargs.h>
4392 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4397 sys_creat (va_alist
)
4400 va_list list_incrementer
;
4403 int rfd
; /* related file descriptor */
4404 int fd
; /* Our new file descriptor */
4411 extern int vms_stmlf_recfm
;
4414 va_start (list_incrementer
);
4415 name
= va_arg (list_incrementer
, char *);
4416 mode
= va_arg (list_incrementer
, int);
4418 rfd
= va_arg (list_incrementer
, int);
4419 va_end (list_incrementer
);
4422 /* Use information from the related file descriptor to set record
4423 format of the newly created file. */
4424 fstat (rfd
, &st_buf
);
4425 switch (st_buf
.st_fab_rfm
)
4428 strcpy (rfm
, "rfm = fix");
4429 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4430 strcpy (rat
, "rat = ");
4431 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4433 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4434 strcat (rat
, "ftn");
4435 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4436 strcat (rat
, "prn");
4437 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4438 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4439 strcat (rat
, ", blk");
4441 strcat (rat
, "blk");
4442 return creat (name
, 0, rfm
, rat
, mrs
);
4445 strcpy (rfm
, "rfm = vfc");
4446 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4447 strcpy (rat
, "rat = ");
4448 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4450 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4451 strcat (rat
, "ftn");
4452 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4453 strcat (rat
, "prn");
4454 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4455 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4456 strcat (rat
, ", blk");
4458 strcat (rat
, "blk");
4459 return creat (name
, 0, rfm
, rat
, fsz
);
4462 strcpy (rfm
, "rfm = stm");
4466 strcpy (rfm
, "rfm = stmcr");
4470 strcpy (rfm
, "rfm = stmlf");
4474 strcpy (rfm
, "rfm = udf");
4478 strcpy (rfm
, "rfm = var");
4481 strcpy (rat
, "rat = ");
4482 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4484 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4485 strcat (rat
, "ftn");
4486 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4487 strcat (rat
, "prn");
4488 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4489 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4490 strcat (rat
, ", blk");
4492 strcat (rat
, "blk");
4496 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4497 strcpy (rat
, "rat=cr");
4499 /* Until the VAX C RTL fixes the many bugs with modes, always use
4500 mode 0 to get the user's default protection. */
4501 fd
= creat (name
, 0, rfm
, rat
);
4502 if (fd
< 0 && errno
== EEXIST
)
4504 if (unlink (name
) < 0)
4505 report_file_error ("delete", build_string (name
));
4506 fd
= creat (name
, 0, rfm
, rat
);
4512 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4514 sys_fwrite (ptr
, size
, num
, fp
)
4515 register char * ptr
;
4518 register int tot
= num
* size
;
4526 * The VMS C library routine creat actually creates a new version of an
4527 * existing file rather than truncating the old version. There are times
4528 * when this is not the desired behavior, for instance, when writing an
4529 * auto save file (you only want one version), or when you don't have
4530 * write permission in the directory containing the file (but the file
4531 * itself is writable). Hence this routine, which is equivalent to
4532 * "close (creat (fn, 0));" on Unix if fn already exists.
4538 struct FAB xfab
= cc$rms_fab
;
4539 struct RAB xrab
= cc$rms_rab
;
4542 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4543 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4544 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4545 xfab
.fab$l_fna
= fn
;
4546 xfab
.fab$b_fns
= strlen (fn
);
4547 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4549 xrab
.rab$l_fab
= &xfab
;
4551 /* This gibberish opens the file, positions to the first record, and
4552 deletes all records from there until the end of file. */
4553 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4555 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4556 (SYS$
FIND (&xrab
) & 01) == 01 &&
4557 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4568 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4569 SYSPRV or a readable SYSUAF.DAT. */
4575 * Routine to read the VMS User Authorization File and return
4576 * a specific user's record.
4579 static struct UAF retuaf
;
4582 get_uaf_name (uname
)
4589 uaf_fab
= cc$rms_fab
;
4590 uaf_rab
= cc$rms_rab
;
4591 /* initialize fab fields */
4592 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4593 uaf_fab
.fab$b_fns
= 21;
4594 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4595 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4596 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4597 /* initialize rab fields */
4598 uaf_rab
.rab$l_fab
= &uaf_fab
;
4599 /* open the User Authorization File */
4600 status
= SYS$
OPEN (&uaf_fab
);
4604 vaxc$errno
= status
;
4607 status
= SYS$
CONNECT (&uaf_rab
);
4611 vaxc$errno
= status
;
4614 /* read the requested record - index is in uname */
4615 uaf_rab
.rab$l_kbf
= uname
;
4616 uaf_rab
.rab$b_ksz
= strlen (uname
);
4617 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4618 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4619 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4620 status
= SYS$
GET (&uaf_rab
);
4624 vaxc$errno
= status
;
4627 /* close the User Authorization File */
4628 status
= SYS$
DISCONNECT (&uaf_rab
);
4632 vaxc$errno
= status
;
4635 status
= SYS$
CLOSE (&uaf_fab
);
4639 vaxc$errno
= status
;
4653 uaf_fab
= cc$rms_fab
;
4654 uaf_rab
= cc$rms_rab
;
4655 /* initialize fab fields */
4656 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4657 uaf_fab
.fab$b_fns
= 21;
4658 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4659 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4660 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4661 /* initialize rab fields */
4662 uaf_rab
.rab$l_fab
= &uaf_fab
;
4663 /* open the User Authorization File */
4664 status
= SYS$
OPEN (&uaf_fab
);
4668 vaxc$errno
= status
;
4671 status
= SYS$
CONNECT (&uaf_rab
);
4675 vaxc$errno
= status
;
4678 /* read the requested record - index is in uic */
4679 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4680 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4681 uaf_rab
.rab$b_ksz
= sizeof uic
;
4682 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4683 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4684 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4685 status
= SYS$
GET (&uaf_rab
);
4689 vaxc$errno
= status
;
4692 /* close the User Authorization File */
4693 status
= SYS$
DISCONNECT (&uaf_rab
);
4697 vaxc$errno
= status
;
4700 status
= SYS$
CLOSE (&uaf_fab
);
4704 vaxc$errno
= status
;
4710 static struct passwd retpw
;
4718 /* copy these out first because if the username is 32 chars, the next
4719 section will overwrite the first byte of the UIC */
4720 retpw
.pw_uid
= up
->uaf$w_mem
;
4721 retpw
.pw_gid
= up
->uaf$w_grp
;
4723 /* I suppose this is not the best style, to possibly overwrite one
4724 byte beyond the end of the field, but what the heck... */
4725 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4726 while (ptr
[-1] == ' ')
4729 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4731 /* the rest of these are counted ascii strings */
4732 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4733 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4734 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4735 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4736 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4737 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4738 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4739 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4743 #else /* not READ_SYSUAF */
4744 static struct passwd retpw
;
4745 #endif /* not READ_SYSUAF */
4756 unsigned char * full
;
4757 #endif /* READ_SYSUAF */
4762 if ('a' <= *ptr
&& *ptr
<= 'z')
4767 if (!(up
= get_uaf_name (name
)))
4769 return cnv_uaf_pw (up
);
4771 if (strcmp (name
, getenv ("USER")) == 0)
4773 retpw
.pw_uid
= getuid ();
4774 retpw
.pw_gid
= getgid ();
4775 strcpy (retpw
.pw_name
, name
);
4776 if (full
= egetenv ("FULLNAME"))
4777 strcpy (retpw
.pw_gecos
, full
);
4779 *retpw
.pw_gecos
= '\0';
4780 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4781 *retpw
.pw_shell
= '\0';
4786 #endif /* not READ_SYSUAF */
4796 if (!(up
= get_uaf_uic (uid
)))
4798 return cnv_uaf_pw (up
);
4800 if (uid
== sys_getuid ())
4801 return getpwnam (egetenv ("USER"));
4804 #endif /* not READ_SYSUAF */
4807 /* return total address space available to the current process. This is
4808 the sum of the current p0 size, p1 size and free page table entries
4814 unsigned long free_pages
;
4815 unsigned long frep0va
;
4816 unsigned long frep1va
;
4819 item_code
= JPI$_FREPTECNT
;
4820 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4823 vaxc$errno
= status
;
4828 item_code
= JPI$_FREP0VA
;
4829 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4832 vaxc$errno
= status
;
4835 item_code
= JPI$_FREP1VA
;
4836 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4839 vaxc$errno
= status
;
4843 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4847 define_logical_name (varname
, string
)
4851 struct dsc$descriptor_s strdsc
=
4852 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4853 struct dsc$descriptor_s envdsc
=
4854 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4855 struct dsc$descriptor_s lnmdsc
=
4856 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4858 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4862 delete_logical_name (varname
)
4865 struct dsc$descriptor_s envdsc
=
4866 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4867 struct dsc$descriptor_s lnmdsc
=
4868 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4870 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4888 error ("execvp system call not implemented");
4897 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4898 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4899 char from_esn
[NAM$C_MAXRSS
];
4900 char to_esn
[NAM$C_MAXRSS
];
4902 from_fab
.fab$l_fna
= from
;
4903 from_fab
.fab$b_fns
= strlen (from
);
4904 from_fab
.fab$l_nam
= &from_nam
;
4905 from_fab
.fab$l_fop
= FAB$M_NAM
;
4907 from_nam
.nam$l_esa
= from_esn
;
4908 from_nam
.nam$b_ess
= sizeof from_esn
;
4910 to_fab
.fab$l_fna
= to
;
4911 to_fab
.fab$b_fns
= strlen (to
);
4912 to_fab
.fab$l_nam
= &to_nam
;
4913 to_fab
.fab$l_fop
= FAB$M_NAM
;
4915 to_nam
.nam$l_esa
= to_esn
;
4916 to_nam
.nam$b_ess
= sizeof to_esn
;
4918 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4924 if (status
== RMS$_DEV
)
4928 vaxc$errno
= status
;
4933 /* This function renames a file like `rename', but it strips
4934 the version number from the "to" filename, such that the "to" file is
4935 will always be a new version. It also sets the file protection once it is
4936 finished. The protection that we will use is stored in fab_final_pro,
4937 and was set when we did a creat_copy_attrs to create the file that we
4940 We could use the chmod function, but Eunichs uses 3 bits per user category
4941 to describe the protection, and VMS uses 4 (write and delete are separate
4942 bits). To maintain portability, the VMS implementation of `chmod' wires
4943 the W and D bits together. */
4946 static struct fibdef fib
; /* We need this initialized to zero */
4947 char vms_file_written
[NAM$C_MAXRSS
];
4950 rename_sans_version (from
,to
)
4957 struct FAB to_fab
= cc$rms_fab
;
4958 struct NAM to_nam
= cc$rms_nam
;
4959 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4960 struct dsc$descriptor fib_attr
[2]
4961 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4962 char to_esn
[NAM$C_MAXRSS
];
4964 $
DESCRIPTOR (disk
,to_esn
);
4966 to_fab
.fab$l_fna
= to
;
4967 to_fab
.fab$b_fns
= strlen (to
);
4968 to_fab
.fab$l_nam
= &to_nam
;
4969 to_fab
.fab$l_fop
= FAB$M_NAM
;
4971 to_nam
.nam$l_esa
= to_esn
;
4972 to_nam
.nam$b_ess
= sizeof to_esn
;
4974 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4976 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4977 *(to_nam
.nam$l_ver
) = '\0';
4979 stat
= rename (from
, to_esn
);
4983 strcpy (vms_file_written
, to_esn
);
4985 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4986 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4988 /* Now set the file protection to the correct value */
4989 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4991 /* Copy these fields into the fib */
4992 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4993 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4994 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4996 SYS$
CLOSE (&to_fab
, 0, 0);
4998 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
5001 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
5002 0, 0, 0, &fib_attr
, 0);
5005 stat
= SYS$
DASSGN (chan
);
5008 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
5019 unsigned short fid
[3];
5020 char esa
[NAM$C_MAXRSS
];
5023 fab
.fab$l_fop
= FAB$M_OFP
;
5024 fab
.fab$l_fna
= file
;
5025 fab
.fab$b_fns
= strlen (file
);
5026 fab
.fab$l_nam
= &nam
;
5029 nam
.nam$l_esa
= esa
;
5030 nam
.nam$b_ess
= NAM$C_MAXRSS
;
5032 status
= SYS$
PARSE (&fab
);
5033 if ((status
& 1) == 0)
5036 vaxc$errno
= status
;
5039 status
= SYS$
SEARCH (&fab
);
5040 if ((status
& 1) == 0)
5043 vaxc$errno
= status
;
5047 fid
[0] = nam
.nam$w_fid
[0];
5048 fid
[1] = nam
.nam$w_fid
[1];
5049 fid
[2] = nam
.nam$w_fid
[2];
5051 fab
.fab$l_fna
= new;
5052 fab
.fab$b_fns
= strlen (new);
5054 status
= SYS$
PARSE (&fab
);
5055 if ((status
& 1) == 0)
5058 vaxc$errno
= status
;
5062 nam
.nam$w_fid
[0] = fid
[0];
5063 nam
.nam$w_fid
[1] = fid
[1];
5064 nam
.nam$w_fid
[2] = fid
[2];
5066 nam
.nam$l_esa
= nam
.nam$l_name
;
5067 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
5069 status
= SYS$
ENTER (&fab
);
5070 if ((status
& 1) == 0)
5073 vaxc$errno
= status
;
5084 printf ("%s not yet implemented\r\n", badfunc
);
5092 /* Arrange to return a range centered on zero. */
5093 return rand () - (1 << 30);
5105 /* Called from init_sys_modes. */
5111 /* If we're not on an HFT we shouldn't do any of this. We determine
5112 if we are on an HFT by trying to get an HFT error code. If this
5113 call fails, we're not on an HFT. */
5115 if (ioctl (0, HFQERROR
, &junk
) < 0)
5117 #else /* not IBMR2AIX */
5118 if (ioctl (0, HFQEIO
, 0) < 0)
5120 #endif /* not IBMR2AIX */
5122 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5123 as the rubout key's ASCII code. Here this is changed. The bug is that
5124 there's no way to determine the old mapping, so in reset_sys_modes
5125 we need to assume that the normal map had been present. Of course, this
5126 code also doesn't help if on a terminal emulator which doesn't understand
5130 struct hfkeymap keymap
;
5132 buf
.hf_bufp
= (char *)&keymap
;
5133 buf
.hf_buflen
= sizeof (keymap
);
5134 keymap
.hf_nkeys
= 2;
5135 keymap
.hfkey
[0].hf_kpos
= 15;
5136 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5138 keymap
.hfkey
[0].hf_keyidh
= '<';
5139 #else /* not IBMR2AIX */
5140 keymap
.hfkey
[0].hf_page
= '<';
5141 #endif /* not IBMR2AIX */
5142 keymap
.hfkey
[0].hf_char
= 127;
5143 keymap
.hfkey
[1].hf_kpos
= 15;
5144 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5146 keymap
.hfkey
[1].hf_keyidh
= '<';
5147 #else /* not IBMR2AIX */
5148 keymap
.hfkey
[1].hf_page
= '<';
5149 #endif /* not IBMR2AIX */
5150 keymap
.hfkey
[1].hf_char
= 127;
5151 hftctl (0, HFSKBD
, &buf
);
5153 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5155 line_ins_del_ok
= char_ins_del_ok
= 0;
5158 /* Reset the rubout key to backspace. */
5164 struct hfkeymap keymap
;
5168 if (ioctl (0, HFQERROR
, &junk
) < 0)
5170 #else /* not IBMR2AIX */
5171 if (ioctl (0, HFQEIO
, 0) < 0)
5173 #endif /* not IBMR2AIX */
5175 buf
.hf_bufp
= (char *)&keymap
;
5176 buf
.hf_buflen
= sizeof (keymap
);
5177 keymap
.hf_nkeys
= 2;
5178 keymap
.hfkey
[0].hf_kpos
= 15;
5179 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5181 keymap
.hfkey
[0].hf_keyidh
= '<';
5182 #else /* not IBMR2AIX */
5183 keymap
.hfkey
[0].hf_page
= '<';
5184 #endif /* not IBMR2AIX */
5185 keymap
.hfkey
[0].hf_char
= 8;
5186 keymap
.hfkey
[1].hf_kpos
= 15;
5187 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5189 keymap
.hfkey
[1].hf_keyidh
= '<';
5190 #else /* not IBMR2AIX */
5191 keymap
.hfkey
[1].hf_page
= '<';
5192 #endif /* not IBMR2AIX */
5193 keymap
.hfkey
[1].hf_char
= 8;
5194 hftctl (0, HFSKBD
, &buf
);
5201 /* These are included on Sunos 4.1 when we do not use shared libraries.
5202 X11 libraries may refer to these functions but (we hope) do not
5203 actually call them. */
5223 #endif /* USE_DL_STUBS */
5232 register int length
;
5236 long max_str
= 65535;
5238 while (length
> max_str
) {
5239 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5244 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5246 while (length
-- > 0)
5248 #endif /* not VMS */
5251 #endif /* no bzero */
5252 #endif /* BSTRING */
5254 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5257 /* Saying `void' requires a declaration, above, where bcopy is used
5258 and that declaration causes pain for systems where bcopy is a macro. */
5259 bcopy (b1
, b2
, length
)
5262 register int length
;
5265 long max_str
= 65535;
5267 while (length
> max_str
) {
5268 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5274 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5276 while (length
-- > 0)
5278 #endif /* not VMS */
5280 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5285 bcmp (b1
, b2
, length
) /* This could be a macro! */
5288 register int length
;
5291 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5292 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5294 return STR$
COMPARE (&src1
, &src2
);
5296 while (length
-- > 0)
5301 #endif /* not VMS */
5303 #endif /* no bcmp */
5304 #endif /* not BSTRING */
5306 #ifndef HAVE_STRSIGNAL
5313 if (0 <= code
&& code
< NSIG
)
5316 signame
= sys_errlist
[code
];
5318 /* Cast to suppress warning if the table has const char *. */
5319 signame
= (char *) sys_siglist
[code
];
5325 #endif /* HAVE_STRSIGNAL */