1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
34 /* Including stdlib.h isn't necessarily enough to get srandom
35 declared, e.g. without __USE_XOPEN_EXTENDED with glibc 2. */
37 #if 0 /* It turns out that defining _OSF_SOURCE in osf5-0.h gets
38 random prototyped as returning `int'. It looks to me as
39 though the best way to DTRT is to prefer the rand48 functions
40 (per libc.info). -- fx */
41 extern long int random
P_ ((void));
43 #if 0 /* Don't prototype srandom; it takes an unsigned argument on
44 some systems, and an unsigned long on others, like FreeBSD
46 extern void srandom
P_ ((unsigned int));
50 #include "blockinput.h"
53 #include <sys/param.h>
56 /* Nonzero means delete a process right away if it exits (process.c). */
57 static int delete_exited_processes
;
63 #define write sys_write
68 #endif /* not WINDOWSNT */
70 /* Does anyone other than VMS need this? */
72 #define sys_fwrite fwrite
77 #include <sys/types.h>
82 #if !defined (USG) || defined (BSD_PGRPS)
84 #define setpgrp setpgid
88 /* Get SI_SRPC_DOMAIN, if it is available. */
89 #ifdef HAVE_SYS_SYSTEMINFO_H
90 #include <sys/systeminfo.h>
93 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
97 #include <sys/param.h>
101 extern unsigned start
__asm__ ("start");
123 #include <sys/file.h>
131 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
135 #include <sys/file.h>
143 #include <sys/ioctl.h>
149 #ifdef BROKEN_TIOCGWINSZ
154 #if defined (USG) || defined (DGUX)
155 #include <sys/utsname.h>
156 #ifndef MEMORY_IN_STRING_H
159 #if defined (TIOCGWINSZ) || defined (ISC4_0)
161 #include <sys/sioctl.h>
164 #include <sys/stream.h>
165 #include <sys/ptem.h>
167 #endif /* TIOCGWINSZ or ISC4_0 */
168 #endif /* USG or DGUX */
170 extern int quit_char
;
172 #include "keyboard.h"
175 #include "termhooks.h"
176 #include "termchar.h"
177 #include "termopts.h"
178 #include "dispextern.h"
183 /* In process.h which conflicts with the local copy. */
185 int _CRTAPI1
_spawnlp (int, const char *, const char *, ...);
186 int _CRTAPI1
_getpid (void);
187 extern char *getwd (char *);
190 #ifdef NONSYSTEM_DIR_LIBRARY
192 #endif /* NONSYSTEM_DIR_LIBRARY */
194 #include "syssignal.h"
201 #ifndef HAVE_STRUCT_UTIMBUF
202 /* We want to use utime rather than utimes, but we couldn't find the
203 structure declaration. We'll use the traditional one. */
211 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
217 #define LNOFLSH 0100000
220 static int baud_convert
[] =
225 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
226 1800, 2400, 4800, 9600, 19200, 38400
233 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
235 #if defined (HAVE_TERMIOS_H) && defined (GNU_LINUX)
243 /* The file descriptor for Emacs's input terminal.
244 Under Unix, this is normally zero except when using X;
245 under VMS, we place the input channel number here. */
248 void croak
P_ ((char *)) NO_RETURN
;
255 /* Temporary used by `sigblock' when defined in terms of signprocmask. */
257 SIGMASKTYPE sigprocmask_set
;
260 #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
262 /* Return the current working directory. Returns NULL on errors.
263 Any other returned value must be freed with free. This is used
264 only when get_current_dir_name is not defined on the system. */
266 get_current_dir_name ()
270 struct stat dotstat
, pwdstat
;
271 /* If PWD is accurate, use it instead of calling getwd. PWD is
272 sometimes a nicer name, and using it may avoid a fatal error if a
273 parent directory is searchable but not readable. */
274 if ((pwd
= getenv ("PWD")) != 0
275 && (IS_DIRECTORY_SEP (*pwd
) || (*pwd
&& IS_DEVICE_SEP (pwd
[1])))
276 && stat (pwd
, &pwdstat
) == 0
277 && stat (".", &dotstat
) == 0
278 && dotstat
.st_ino
== pwdstat
.st_ino
279 && dotstat
.st_dev
== pwdstat
.st_dev
281 && strlen (pwd
) < MAXPATHLEN
285 buf
= (char *) malloc (strlen (pwd
) + 1);
293 size_t buf_size
= 1024;
294 buf
= (char *) malloc (buf_size
);
299 if (getcwd (buf
, buf_size
) == buf
)
303 int tmp_errno
= errno
;
309 buf
= (char *) realloc (buf
, buf_size
);
317 /* We need MAXPATHLEN here. */
318 buf
= (char *) malloc (MAXPATHLEN
+ 1);
321 if (getwd (buf
) == NULL
)
323 int tmp_errno
= errno
;
335 /* Specify a different file descriptor for further input operations. */
344 /* Discard pending input on descriptor input_fd. */
350 struct emacs_tty buf
;
355 /* Discarding input is not safe when the input could contain
356 replies from the X server. So don't do it. */
357 if (read_socket_hook
)
362 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
363 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
369 ioctl (input_fd
, TIOCFLUSH
, &zero
);
371 #else /* not Apollo */
372 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
373 while (dos_keyread () != -1)
375 #else /* not MSDOS */
376 EMACS_GET_TTY (input_fd
, &buf
);
377 EMACS_SET_TTY (input_fd
, &buf
, 0);
378 #endif /* not MSDOS */
379 #endif /* not Apollo */
381 #endif /* not WINDOWSNT */
386 /* Arrange for character C to be read as the next input from
397 if (read_socket_hook
)
400 /* Should perhaps error if in batch mode */
402 ioctl (input_fd
, TIOCSTI
, &c
);
403 #else /* no TIOCSTI */
404 error ("Cannot stuff terminal input characters in this version of Unix");
405 #endif /* no TIOCSTI */
417 #ifdef INIT_BAUD_RATE
422 #else /* not DOS_NT */
426 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
427 &sg
.class, 12, 0, 0, 0, 0 );
428 emacs_ospeed
= sg
.xmit_baud
;
434 tcgetattr (input_fd
, &sg
);
435 emacs_ospeed
= cfgetospeed (&sg
);
436 #if defined (USE_GETOBAUD) && defined (getobaud)
437 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
438 if (emacs_ospeed
== 0)
439 emacs_ospeed
= getobaud (sg
.c_cflag
);
441 #else /* neither VMS nor TERMIOS */
447 tcgetattr (input_fd
, &sg
);
449 ioctl (input_fd
, TCGETA
, &sg
);
451 emacs_ospeed
= sg
.c_cflag
& CBAUD
;
452 #else /* neither VMS nor TERMIOS nor TERMIO */
455 sg
.sg_ospeed
= B9600
;
456 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
458 emacs_ospeed
= sg
.sg_ospeed
;
459 #endif /* not HAVE_TERMIO */
460 #endif /* not HAVE_TERMIOS */
462 #endif /* not DOS_NT */
463 #endif /* not INIT_BAUD_RATE */
466 baud_rate
= (emacs_ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
467 ? baud_convert
[emacs_ospeed
] : 9600);
474 set_exclusive_use (fd
)
478 ioctl (fd
, FIOCLEX
, 0);
480 /* Ok to do nothing if this feature does not exist */
485 wait_without_blocking ()
488 wait3 (0, WNOHANG
| WUNTRACED
, 0);
490 croak ("wait_without_blocking");
492 synch_process_alive
= 0;
495 #endif /* not subprocesses */
497 int wait_debugging
; /* Set nonzero to make following function work under dbx
498 (at least for bsd). */
501 wait_for_termination_signal ()
504 /* Wait for subprocess with process id `pid' to terminate and
505 make sure it will get eliminated (not remain forever as a zombie) */
508 wait_for_termination (pid
)
517 status
= SYS$
FORCEX (&pid
, 0, 0);
520 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
521 /* Note that kill returns -1 even if the process is just a zombie now.
522 But inevitably a SIGCHLD interrupt should be generated
523 and child_sig will do wait3 and make the process go away. */
524 /* There is some indication that there is a bug involved with
525 termination of subprocesses, perhaps involving a kernel bug too,
526 but no idea what it is. Just as a hunch we signal SIGCHLD to see
527 if that causes the problem to go away or get worse. */
528 sigsetmask (sigmask (SIGCHLD
));
529 if (0 > kill (pid
, 0))
531 sigsetmask (SIGEMPTYMASK
);
532 kill (getpid (), SIGCHLD
);
538 sigpause (SIGEMPTYMASK
);
539 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
540 #if defined (UNIPLUS)
541 if (0 > kill (pid
, 0))
544 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
545 #ifdef POSIX_SIGNALS /* would this work for GNU/Linux as well? */
546 sigblock (sigmask (SIGCHLD
));
548 if (kill (pid
, 0) == -1 && errno
== ESRCH
)
550 sigunblock (sigmask (SIGCHLD
));
554 sigsuspend (&empty_mask
);
555 #else /* not POSIX_SIGNALS */
556 #ifdef HAVE_SYSV_SIGPAUSE
558 if (0 > kill (pid
, 0))
564 #else /* not HAVE_SYSV_SIGPAUSE */
568 #else /* not WINDOWSNT */
569 if (0 > kill (pid
, 0))
571 /* Using sleep instead of pause avoids timing error.
572 If the inferior dies just before the sleep,
573 we lose just one second. */
575 #endif /* not WINDOWSNT */
576 #endif /* not HAVE_SYSV_SIGPAUSE */
577 #endif /* not POSIX_SIGNALS */
578 #endif /* not UNIPLUS */
579 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
581 #else /* not subprocesses */
584 #else /* not __DJGPP__ > 1 */
586 if (kill (pid
, 0) < 0)
592 if (status
== pid
|| status
== -1)
595 #endif /* not __DJGPP__ > 1*/
596 #endif /* not subprocesses */
603 * flush any pending output
604 * (may flush input as well; it does not matter the way we use it)
608 flush_pending_output (channel
)
612 /* If we try this, we get hit with SIGTTIN, because
613 the child's tty belongs to the child's pgrp. */
616 ioctl (channel
, TCFLSH
, 1);
620 /* 3rd arg should be ignored
621 but some 4.2 kernels actually want the address of an int
622 and nonzero means something different. */
623 ioctl (channel
, TIOCFLUSH
, &zero
);
630 /* Set up the terminal at the other end of a pseudo-terminal that
631 we will be controlling an inferior through.
632 It should not echo or do line-editing, since that is done
633 in Emacs. No padding needed for insertion into an Emacs buffer. */
636 child_setup_tty (out
)
642 EMACS_GET_TTY (out
, &s
);
644 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
645 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
646 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
648 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
649 /* No output delays */
651 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
652 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
653 #if 0 /* This causes bugs in (for instance) telnet to certain sites. */
654 s
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
655 #ifdef INLCR /* Just being cautious, since I can't check how
656 widespread INLCR is--rms. */
657 s
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
661 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
664 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
667 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
669 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
670 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
672 /* Said to be unnecessary: */
673 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
674 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
677 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
678 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
679 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
680 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
683 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
686 #ifdef SIGNALS_VIA_CHARACTERS
687 /* the QUIT and INTR character are used in process_send_signal
688 so set them here to something useful. */
689 if (s
.main
.c_cc
[VQUIT
] == CDISABLE
)
690 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
691 if (s
.main
.c_cc
[VINTR
] == CDISABLE
)
692 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
693 #endif /* not SIGNALS_VIA_CHARACTERS */
696 /* AIX enhanced edit loses NULs, so disable it */
699 s
.main
.c_iflag
&= ~ASCEDIT
;
701 /* Also, PTY overloads NUL and BREAK.
702 don't ignore break, but don't signal either, so it looks like NUL. */
703 s
.main
.c_iflag
&= ~IGNBRK
;
704 s
.main
.c_iflag
&= ~BRKINT
;
705 /* rms: Formerly it set s.main.c_cc[VINTR] to 0377 here
706 unconditionally. Then a SIGNALS_VIA_CHARACTERS conditional
707 would force it to 0377. That looks like duplicated code. */
708 #ifndef SIGNALS_VIA_CHARACTERS
709 /* QUIT and INTR work better as signals, so disable character forms */
710 s
.main
.c_cc
[VQUIT
] = CDISABLE
;
711 s
.main
.c_cc
[VINTR
] = CDISABLE
;
712 s
.main
.c_lflag
&= ~ISIG
;
713 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
714 s
.main
.c_cc
[VEOL
] = CDISABLE
;
715 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
718 #else /* not HAVE_TERMIO */
720 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
722 s
.main
.sg_flags
|= LPASS8
;
723 s
.main
.sg_erase
= 0377;
724 s
.main
.sg_kill
= 0377;
725 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
727 #endif /* not HAVE_TERMIO */
729 EMACS_SET_TTY (out
, &s
, 0);
738 ioctl (out
, FIOASYNC
, &zero
);
741 #endif /* not DOS_NT */
745 #endif /* subprocesses */
747 /* Record a signal code and the handler for it. */
751 SIGTYPE (*handler
) P_ ((int));
754 static void save_signal_handlers
P_ ((struct save_signal
*));
755 static void restore_signal_handlers
P_ ((struct save_signal
*));
757 /* Suspend the Emacs process; give terminal to its superior. */
763 /* "Foster" parentage allows emacs to return to a subprocess that attached
764 to the current emacs as a cheaper than starting a whole new process. This
765 is set up by KEPTEDITOR.COM. */
766 unsigned long parent_id
, foster_parent_id
;
769 fpid_string
= getenv ("EMACS_PARENT_PID");
770 if (fpid_string
!= NULL
)
772 sscanf (fpid_string
, "%x", &foster_parent_id
);
773 if (foster_parent_id
!= 0)
774 parent_id
= foster_parent_id
;
776 parent_id
= getppid ();
779 parent_id
= getppid ();
781 xfree (fpid_string
); /* On VMS, this was malloc'd */
783 if (parent_id
&& parent_id
!= 0xffffffff)
785 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
786 int status
= LIB$
ATTACH (&parent_id
) & 1;
787 signal (SIGINT
, oldsig
);
796 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
797 d_prompt
.a
= "Emacs: "; /* Just a reminder */
798 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
803 #if defined (SIGTSTP) && !defined (MSDOS)
806 int pgrp
= EMACS_GETPGRP (0);
807 EMACS_KILLPG (pgrp
, SIGTSTP
);
810 #else /* No SIGTSTP */
811 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
812 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
813 kill (getpid (), SIGQUIT
);
815 #else /* No SIGTSTP or USG_JOBCTRL */
817 /* On a system where suspending is not implemented,
818 instead fork a subshell and let it talk directly to the terminal
822 #endif /* no USG_JOBCTRL */
823 #endif /* no SIGTSTP */
827 /* Fork a subshell. */
834 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
836 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
839 struct save_signal saved_handlers
[5];
841 unsigned char *str
= 0;
844 saved_handlers
[0].code
= SIGINT
;
845 saved_handlers
[1].code
= SIGQUIT
;
846 saved_handlers
[2].code
= SIGTERM
;
848 saved_handlers
[3].code
= SIGIO
;
849 saved_handlers
[4].code
= 0;
851 saved_handlers
[3].code
= 0;
854 /* Mentioning current_buffer->buffer would mean including buffer.h,
855 which somehow wedges the hp compiler. So instead... */
857 dir
= intern ("default-directory");
858 if (NILP (Fboundp (dir
)))
860 dir
= Fsymbol_value (dir
);
864 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
865 str
= (unsigned char *) alloca (SCHARS (dir
) + 2);
867 bcopy (SDATA (dir
), str
, len
);
868 if (str
[len
- 1] != '/') str
[len
++] = '/';
875 save_signal_handlers (saved_handlers
);
876 synch_process_alive
= 1;
877 #endif /* __DJGPP__ > 1 */
881 error ("Can't spawn subshell");
888 #ifdef DOS_NT /* MW, Aug 1993 */
891 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
894 sh
= (char *) egetenv ("SHELL");
898 /* Use our buffer's default directory for the subshell. */
900 chdir ((char *) str
);
903 close_process_descs (); /* Close Emacs's pipes/ptys */
906 #ifdef SET_EMACS_PRIORITY
908 extern EMACS_INT emacs_priority
;
910 if (emacs_priority
< 0)
911 nice (-emacs_priority
);
915 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
917 char *epwd
= getenv ("PWD");
918 char old_pwd
[MAXPATHLEN
+1+4];
920 /* If PWD is set, pass it with corrected value. */
923 strcpy (old_pwd
, epwd
);
924 if (str
[len
- 1] == '/')
926 setenv ("PWD", str
, 1);
931 putenv (old_pwd
); /* restore previous value */
933 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
935 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
937 #else /* not MSDOS */
939 /* Waits for process completion */
940 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
943 write (1, "Can't execute subshell", 22);
944 #else /* not WINDOWSNT */
945 execlp (sh
, sh
, (char *) 0);
946 write (1, "Can't execute subshell", 22);
948 #endif /* not WINDOWSNT */
949 #endif /* not MSDOS */
952 /* Do this now if we did not do it before. */
953 #if !defined (MSDOS) || __DJGPP__ == 1
954 save_signal_handlers (saved_handlers
);
955 synch_process_alive
= 1;
959 wait_for_termination (pid
);
961 restore_signal_handlers (saved_handlers
);
962 synch_process_alive
= 0;
965 #endif /* !MAC_OS8 */
968 save_signal_handlers (saved_handlers
)
969 struct save_signal
*saved_handlers
;
971 while (saved_handlers
->code
)
973 saved_handlers
->handler
974 = (SIGTYPE (*) P_ ((int))) signal (saved_handlers
->code
, SIG_IGN
);
980 restore_signal_handlers (saved_handlers
)
981 struct save_signal
*saved_handlers
;
983 while (saved_handlers
->code
)
985 signal (saved_handlers
->code
, saved_handlers
->handler
);
999 old_fcntl_flags
= fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
1000 fcntl (fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
1002 interrupts_deferred
= 0;
1011 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
1016 if (noninteractive
|| read_socket_hook
)
1020 sigunblock (sigmask (SIGWINCH
));
1022 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
1024 interrupts_deferred
= 0;
1030 if (noninteractive
|| read_socket_hook
)
1034 sigblock (sigmask (SIGWINCH
));
1036 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
1037 interrupts_deferred
= 1;
1040 #else /* no FASYNC */
1041 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
1048 if (noninteractive
|| read_socket_hook
)
1051 ioctl (input_fd
, FIOASYNC
, &on
);
1052 interrupts_deferred
= 0;
1060 if (noninteractive
|| read_socket_hook
)
1063 ioctl (input_fd
, FIOASYNC
, &off
);
1064 interrupts_deferred
= 1;
1067 #else /* not FASYNC, not STRIDE */
1071 #include <termios.h>
1079 if (noninteractive
|| read_socket_hook
)
1083 sigaddset (&st
, SIGIO
);
1084 ioctl (input_fd
, FIOASYNC
, &on
);
1085 interrupts_deferred
= 0;
1086 sigprocmask (SIG_UNBLOCK
, &st
, (sigset_t
*)0);
1094 if (noninteractive
|| read_socket_hook
)
1097 ioctl (input_fd
, FIOASYNC
, &off
);
1098 interrupts_deferred
= 1;
1101 #else /* ! _CX_UX */
1107 if (noninteractive
|| read_socket_hook
)
1110 croak ("request_sigio");
1116 if (noninteractive
|| read_socket_hook
)
1119 croak ("unrequest_sigio");
1126 #endif /* F_SETFL */
1128 /* Saving and restoring the process group of Emacs's terminal. */
1132 /* The process group of which Emacs was a member when it initially
1135 If Emacs was in its own process group (i.e. inherited_pgroup ==
1136 getpid ()), then we know we're running under a shell with job
1137 control (Emacs would never be run as part of a pipeline).
1140 If Emacs was not in its own process group, then we know we're
1141 running under a shell (or a caller) that doesn't know how to
1142 separate itself from Emacs (like sh). Emacs must be in its own
1143 process group in order to receive SIGIO correctly. In this
1144 situation, we put ourselves in our own pgroup, forcibly set the
1145 tty's pgroup to our pgroup, and make sure to restore and reinstate
1146 the tty's pgroup just like any other terminal setting. If
1147 inherited_group was not the tty's pgroup, then we'll get a
1148 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1149 it goes foreground in the future, which is what should happen. */
1150 int inherited_pgroup
;
1152 /* Split off the foreground process group to Emacs alone.
1153 When we are in the foreground, but not started in our own process
1154 group, redirect the TTY to point to our own process group. We need
1155 to be in our own process group to receive SIGIO properly. */
1157 narrow_foreground_group ()
1161 setpgrp (0, inherited_pgroup
);
1162 if (inherited_pgroup
!= me
)
1163 EMACS_SET_TTY_PGRP (input_fd
, &me
);
1167 /* Set the tty to our original foreground group. */
1169 widen_foreground_group ()
1171 if (inherited_pgroup
!= getpid ())
1172 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
1173 setpgrp (0, inherited_pgroup
);
1176 #endif /* BSD_PGRPS */
1178 /* Getting and setting emacs_tty structures. */
1180 /* Set *TC to the parameters associated with the terminal FD.
1181 Return zero if all's well, or -1 if we ran into an error we
1182 couldn't deal with. */
1184 emacs_get_tty (fd
, settings
)
1186 struct emacs_tty
*settings
;
1188 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1190 /* We have those nifty POSIX tcmumbleattr functions. */
1191 bzero (&settings
->main
, sizeof (settings
->main
));
1192 if (tcgetattr (fd
, &settings
->main
) < 0)
1197 /* The SYSV-style interface? */
1198 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1203 /* Vehemently Monstrous System? :-) */
1204 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1205 &settings
->main
.class, 12, 0, 0, 0, 0)
1211 /* I give up - I hope you have the BSD ioctls. */
1212 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1214 #endif /* not DOS_NT */
1219 /* Suivant - Do we have to get struct ltchars data? */
1221 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1225 /* How about a struct tchars and a wordful of lmode bits? */
1227 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1228 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1232 /* We have survived the tempest. */
1237 /* Set the parameters of the tty on FD according to the contents of
1238 *SETTINGS. If FLUSHP is non-zero, we discard input.
1239 Return 0 if all went well, and -1 if anything failed. */
1242 emacs_set_tty (fd
, settings
, flushp
)
1244 struct emacs_tty
*settings
;
1247 /* Set the primary parameters - baud rate, character size, etcetera. */
1250 /* We have those nifty POSIX tcmumbleattr functions.
1251 William J. Smith <wjs@wiis.wang.com> writes:
1252 "POSIX 1003.1 defines tcsetattr to return success if it was
1253 able to perform any of the requested actions, even if some
1254 of the requested actions could not be performed.
1255 We must read settings back to ensure tty setup properly.
1256 AIX requires this to keep tty from hanging occasionally." */
1257 /* This make sure that we don't loop indefinitely in here. */
1258 for (i
= 0 ; i
< 10 ; i
++)
1259 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1270 bzero (&new, sizeof (new));
1271 /* Get the current settings, and see if they're what we asked for. */
1272 tcgetattr (fd
, &new);
1273 /* We cannot use memcmp on the whole structure here because under
1274 * aix386 the termios structure has some reserved field that may
1277 if ( new.c_iflag
== settings
->main
.c_iflag
1278 && new.c_oflag
== settings
->main
.c_oflag
1279 && new.c_cflag
== settings
->main
.c_cflag
1280 && new.c_lflag
== settings
->main
.c_lflag
1281 && memcmp (new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1289 /* The SYSV-style interface? */
1290 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1295 /* Vehemently Monstrous System? :-) */
1296 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1297 &settings
->main
.class, 12, 0, 0, 0, 0)
1303 /* I give up - I hope you have the BSD ioctls. */
1304 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1306 #endif /* not DOS_NT */
1312 /* Suivant - Do we have to get struct ltchars data? */
1314 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1318 /* How about a struct tchars and a wordful of lmode bits? */
1320 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1321 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1325 /* We have survived the tempest. */
1330 /* The initial tty mode bits */
1331 struct emacs_tty old_tty
;
1333 /* 1 if we have been through init_sys_modes. */
1336 /* 1 if outer tty status has been recorded. */
1340 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1345 #ifndef F_SETOWN_BUG
1347 int old_fcntl_owner
;
1348 #endif /* F_SETOWN */
1349 #endif /* F_SETOWN_BUG */
1351 /* This may also be defined in stdio,
1352 but if so, this does no harm,
1353 and using the same name avoids wasting the other one's space. */
1356 extern char *_sobuf
;
1358 #if defined (USG) || defined (DGUX)
1359 unsigned char _sobuf
[BUFSIZ
+8];
1361 char _sobuf
[BUFSIZ
];
1366 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1369 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1375 struct emacs_tty tty
;
1379 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1380 extern int (*interrupt_signal
) ();
1384 Vtty_erase_char
= Qnil
;
1391 input_ef
= get_kbd_event_flag ();
1392 /* LIB$GET_EF (&input_ef); */
1393 SYS$
CLREF (input_ef
);
1394 waiting_for_ast
= 0;
1396 timer_ef
= get_timer_event_flag ();
1397 /* LIB$GET_EF (&timer_ef); */
1398 SYS$
CLREF (timer_ef
);
1402 LIB$
GET_EF (&process_ef
);
1403 SYS$
CLREF (process_ef
);
1405 if (input_ef
/ 32 != process_ef
/ 32)
1406 croak ("Input and process event flags in different clusters.");
1408 if (input_ef
/ 32 != timer_ef
/ 32)
1409 croak ("Input and timer event flags in different clusters.");
1411 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1412 ((unsigned) 1 << (process_ef
% 32));
1414 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1415 ((unsigned) 1 << (timer_ef
% 32));
1417 sys_access_reinit ();
1419 #endif /* not VMS */
1422 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1423 narrow_foreground_group ();
1426 #ifdef HAVE_WINDOW_SYSTEM
1427 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1428 needs the initialization code below. */
1429 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1432 EMACS_GET_TTY (input_fd
, &old_tty
);
1438 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1439 XSETINT (Vtty_erase_char
, old_tty
.main
.c_cc
[VERASE
]);
1442 /* This allows meta to be sent on 8th bit. */
1443 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1445 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1446 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1447 #ifdef INLCR /* I'm just being cautious,
1448 since I can't check how widespread INLCR is--rms. */
1449 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1452 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1454 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1455 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1457 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1459 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1462 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1464 tty
.main
.c_iflag
&= ~IXANY
;
1468 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1469 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1471 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1475 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1476 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1479 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1480 /* Set up C-g for both SIGQUIT and SIGINT.
1481 We don't know which we will get, but we handle both alike
1482 so which one it really gives us does not matter. */
1483 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1484 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1485 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1487 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1491 #if defined (mips) || defined (HAVE_TCATTR)
1493 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1496 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1497 #endif /* V_DSUSP */
1498 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1499 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1502 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1505 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1506 #endif /* VREPRINT */
1508 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1509 #endif /* VWERASE */
1511 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1512 #endif /* VDISCARD */
1517 tty
.main
.c_cc
[VSTART
] = '\021';
1520 tty
.main
.c_cc
[VSTOP
] = '\023';
1526 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1529 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1532 #endif /* mips or HAVE_TCATTR */
1534 #ifdef SET_LINE_DISCIPLINE
1535 /* Need to explicitly request TERMIODISC line discipline or
1536 Ultrix's termios does not work correctly. */
1537 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1541 /* AIX enhanced edit loses NULs, so disable it. */
1542 tty
.main
.c_line
= 0;
1543 tty
.main
.c_iflag
&= ~ASCEDIT
;
1545 tty
.main
.c_cc
[VSTRT
] = CDISABLE
;
1546 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1547 tty
.main
.c_cc
[VSUSP
] = CDISABLE
;
1548 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1549 #endif /* IBMR2AIX */
1553 tty
.main
.c_cc
[VSTART
] = '\021';
1556 tty
.main
.c_cc
[VSTOP
] = '\023';
1559 /* Also, PTY overloads NUL and BREAK.
1560 don't ignore break, but don't signal either, so it looks like NUL.
1561 This really serves a purpose only if running in an XTERM window
1562 or via TELNET or the like, but does no harm elsewhere. */
1563 tty
.main
.c_iflag
&= ~IGNBRK
;
1564 tty
.main
.c_iflag
&= ~BRKINT
;
1566 #else /* if not HAVE_TERMIO */
1568 tty
.main
.tt_char
|= TT$M_NOECHO
;
1570 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1572 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1574 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1575 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1576 #else /* not VMS (BSD, that is) */
1578 XSETINT (Vtty_erase_char
, tty
.main
.sg_erase
);
1579 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1581 tty
.main
.sg_flags
|= ANYP
;
1582 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1583 #endif /* not DOS_NT */
1584 #endif /* not VMS (BSD, that is) */
1585 #endif /* not HAVE_TERMIO */
1587 /* If going to use CBREAK mode, we must request C-g to interrupt
1588 and turn off start and stop chars, etc. If not going to use
1589 CBREAK mode, do this anyway so as to turn off local flow
1590 control for user coming over network on 4.2; in this case,
1591 only t_stopc and t_startc really matter. */
1594 /* Note: if not using CBREAK mode, it makes no difference how we
1596 tty
.tchars
= new_tchars
;
1597 tty
.tchars
.t_intrc
= quit_char
;
1600 tty
.tchars
.t_startc
= '\021';
1601 tty
.tchars
.t_stopc
= '\023';
1604 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1606 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1607 anything, and leaving it in breaks the meta key. Go figure. */
1608 tty
.lmode
&= ~LLITOUT
;
1615 #endif /* HAVE_TCHARS */
1616 #endif /* not HAVE_TERMIO */
1619 tty
.ltchars
= new_ltchars
;
1620 #endif /* HAVE_LTCHARS */
1621 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1623 internal_terminal_init ();
1627 EMACS_SET_TTY (input_fd
, &tty
, 0);
1629 /* This code added to insure that, if flow-control is not to be used,
1630 we have an unlocked terminal at the start. */
1633 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1637 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1641 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1643 if (!flow_control
) tcflow (input_fd
, TCOON
);
1651 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1652 to be only LF. This is the way that is done. */
1655 if (ioctl (1, HFTGETID
, &tty
) != -1)
1656 write (1, "\033[20l", 5);
1662 /* Appears to do nothing when in PASTHRU mode.
1663 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1664 interrupt_signal, oob_chars, 0, 0, 0, 0);
1666 queue_kbd_input (0);
1671 #ifndef F_SETOWN_BUG
1672 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1674 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1676 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1677 fcntl (input_fd
, F_SETOWN
, getpid ());
1678 init_sigio (input_fd
);
1680 #endif /* F_GETOWN */
1681 #endif /* F_SETOWN_BUG */
1682 #endif /* F_SETFL */
1685 if (interrupt_input
)
1686 init_sigio (input_fd
);
1689 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1693 /* This symbol is defined on recent USG systems.
1694 Someone says without this call USG won't really buffer the file
1695 even with a call to setbuf. */
1696 setvbuf (stdout
, (char *) _sobuf
, _IOFBF
, sizeof _sobuf
);
1698 setbuf (stdout
, (char *) _sobuf
);
1700 #ifdef HAVE_WINDOW_SYSTEM
1701 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1702 needs the initialization code below. */
1703 if (EQ (Vwindow_system
, Qnil
)
1705 /* When running in tty mode on NT/Win95, we have a read_socket
1706 hook, but still need the rest of the initialization code below. */
1707 && (! read_socket_hook
)
1711 set_terminal_modes ();
1714 && FRAMEP (Vterminal_frame
)
1715 && FRAME_TERMCAP_P (XFRAME (Vterminal_frame
)))
1716 init_frame_faces (XFRAME (Vterminal_frame
));
1718 if (term_initted
&& no_redraw_on_reenter
)
1720 if (display_completed
)
1721 direct_output_forward_char (0);
1726 if (FRAMEP (Vterminal_frame
))
1727 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1733 /* Return nonzero if safe to use tabs in output.
1734 At the time this is called, init_sys_modes has not been done yet. */
1739 struct emacs_tty tty
;
1741 EMACS_GET_TTY (input_fd
, &tty
);
1742 return EMACS_TTY_TABS_OK (&tty
);
1745 /* Get terminal size from system.
1746 Store number of lines into *HEIGHTP and width into *WIDTHP.
1747 We store 0 if there's no valid information. */
1750 get_frame_size (widthp
, heightp
)
1751 int *widthp
, *heightp
;
1757 struct winsize size
;
1759 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1760 *widthp
= *heightp
= 0;
1763 *widthp
= size
.ws_col
;
1764 *heightp
= size
.ws_row
;
1770 /* SunOS - style. */
1771 struct ttysize size
;
1773 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1774 *widthp
= *heightp
= 0;
1777 *widthp
= size
.ts_cols
;
1778 *heightp
= size
.ts_lines
;
1784 /* Use a fresh channel since the current one may have stale info
1785 (for example, from prior to a suspend); and to avoid a dependency
1786 in the init sequence. */
1788 struct sensemode tty
;
1790 SYS$
ASSIGN (&input_dsc
, &chan
, 0, 0);
1791 SYS$
QIOW (0, chan
, IO$_SENSEMODE
, &tty
, 0, 0,
1792 &tty
.class, 12, 0, 0, 0, 0);
1794 *widthp
= tty
.scr_wid
;
1795 *heightp
= tty
.scr_len
;
1799 *widthp
= ScreenCols ();
1800 *heightp
= ScreenRows ();
1801 #else /* system doesn't know size */
1806 #endif /* not VMS */
1807 #endif /* not SunOS-style */
1808 #endif /* not BSD-style */
1811 /* Set the logical window size associated with descriptor FD
1812 to HEIGHT and WIDTH. This is used mainly with ptys. */
1815 set_window_size (fd
, height
, width
)
1816 int fd
, height
, width
;
1821 struct winsize size
;
1822 size
.ws_row
= height
;
1823 size
.ws_col
= width
;
1825 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1826 return 0; /* error */
1833 /* SunOS - style. */
1834 struct ttysize size
;
1835 size
.ts_lines
= height
;
1836 size
.ts_cols
= width
;
1838 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1844 #endif /* not SunOS-style */
1845 #endif /* not BSD-style */
1849 /* Prepare the terminal for exiting Emacs; move the cursor to the
1850 bottom of the frame, turn off interrupt-driven I/O, etc. */
1863 #ifdef HAVE_WINDOW_SYSTEM
1864 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1865 needs the clean-up code below. */
1866 if (!EQ (Vwindow_system
, Qnil
)
1868 /* When running in tty mode on NT/Win95, we have a read_socket
1869 hook, but still need the rest of the clean-up code below. */
1875 sf
= SELECTED_FRAME ();
1876 cursor_to (FRAME_LINES (sf
) - 1, 0);
1877 clear_end_of_line (FRAME_COLS (sf
));
1878 /* clear_end_of_line may move the cursor */
1879 cursor_to (FRAME_LINES (sf
) - 1, 0);
1880 #if defined (IBMR2AIX) && defined (AIXHFT)
1882 /* HFT devices normally use ^J as a LF/CR. We forced it to
1883 do the LF only. Now, we need to reset it. */
1886 if (ioctl (1, HFTGETID
, &tty
) != -1)
1887 write (1, "\033[20h", 5);
1891 reset_terminal_modes ();
1895 /* Avoid possible loss of output when changing terminal modes. */
1896 fsync (fileno (stdout
));
1901 #ifndef F_SETOWN_BUG
1902 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1903 if (interrupt_input
)
1906 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1908 #endif /* F_SETOWN */
1909 #endif /* F_SETOWN_BUG */
1911 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1913 #endif /* F_SETFL */
1915 if (interrupt_input
)
1920 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1923 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1927 #ifdef SET_LINE_DISCIPLINE
1928 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1929 A different old line discipline is therefore not restored, yet.
1930 Restore the old line discipline by hand. */
1931 ioctl (0, TIOCSETD
, &old_tty
.main
.c_line
);
1939 widen_foreground_group ();
1945 /* Set up the proper status flags for use of a pty. */
1951 /* I'm told that TOICREMOTE does not mean control chars
1952 "can't be sent" but rather that they don't have
1953 input-editing or signaling effects.
1954 That should be good, because we have other ways
1955 to do those things in Emacs.
1956 However, telnet mode seems not to work on 4.2.
1957 So TIOCREMOTE is turned off now. */
1959 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1960 will hang. In particular, the "timeout" feature (which
1961 causes a read to return if there is no data available)
1962 does this. Also it is known that telnet mode will hang
1963 in such a way that Emacs must be stopped (perhaps this
1964 is the same problem).
1966 If TIOCREMOTE is turned off, then there is a bug in
1967 hp-ux which sometimes loses data. Apparently the
1968 code which blocks the master process when the internal
1969 buffer fills up does not work. Other than this,
1970 though, everything else seems to work fine.
1972 Since the latter lossage is more benign, we may as well
1973 lose that way. -- cph */
1975 #if defined(SYSV_PTYS) || defined(UNIX98_PTYS)
1978 ioctl (fd
, FIONBIO
, &on
);
1983 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1984 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1985 /* cause EMACS not to die when it should, i.e., when its own controlling */
1986 /* tty goes away. I've complained to the AIX developers, and they may */
1987 /* change this behavior, but I'm not going to hold my breath. */
1988 signal (SIGHUP
, SIG_IGN
);
1991 #endif /* HAVE_PTYS */
1995 /* Assigning an input channel is done at the start of Emacs execution.
1996 This is called each time Emacs is resumed, also, but does nothing
1997 because input_chain is no longer zero. */
2006 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
2012 /* Deassigning the input channel is done before exiting. */
2017 return SYS$
DASSGN (input_fd
);
2022 /* Request reading one character into the keyboard buffer.
2023 This is done as soon as the buffer becomes empty. */
2029 extern kbd_input_ast ();
2031 waiting_for_ast
= 0;
2033 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
2034 &input_iosb
, kbd_input_ast
, 1,
2035 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
2040 /* Ast routine that is called when keyboard input comes in
2041 in accord with the SYS$QIO above. */
2046 register int c
= -1;
2047 int old_errno
= errno
;
2048 extern EMACS_TIME
*input_available_clear_time
;
2050 if (waiting_for_ast
)
2051 SYS$
SETEF (input_ef
);
2052 waiting_for_ast
= 0;
2055 if (input_count
== 25)
2057 printf ("Ast # %d,", input_count
);
2058 printf (" iosb = %x, %x, %x, %x",
2059 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
2062 if (input_iosb
.offset
)
2066 printf (", char = 0%o", c
);
2078 struct input_event e
;
2081 e
.kind
= ASCII_KEYSTROKE_EVENT
;
2082 XSETINT (e
.code
, c
);
2083 e
.frame_or_window
= selected_frame
;
2084 kbd_buffer_store_event (&e
);
2086 if (input_available_clear_time
)
2087 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
2091 /* Wait until there is something in kbd_buffer. */
2094 wait_for_kbd_input ()
2096 extern int have_process_input
, process_exited
;
2098 /* If already something, avoid doing system calls. */
2099 if (detect_input_pending ())
2103 /* Clear a flag, and tell ast routine above to set it. */
2104 SYS$
CLREF (input_ef
);
2105 waiting_for_ast
= 1;
2106 /* Check for timing error: ast happened while we were doing that. */
2107 if (!detect_input_pending ())
2109 /* No timing error: wait for flag to be set. */
2110 set_waiting_for_input (0);
2111 SYS$
WFLOR (input_ef
, input_eflist
);
2112 clear_waiting_for_input ();
2113 if (!detect_input_pending ())
2114 /* Check for subprocess input availability */
2116 int dsp
= have_process_input
|| process_exited
;
2118 SYS$
CLREF (process_ef
);
2119 if (have_process_input
)
2120 process_command_input ();
2125 update_mode_lines
++;
2126 prepare_menu_bars ();
2127 redisplay_preserve_echo_area (18);
2131 waiting_for_ast
= 0;
2134 /* Get rid of any pending QIO, when we are about to suspend
2135 or when we want to throw away pending input.
2136 We wait for a positive sign that the AST routine has run
2137 and therefore there is no I/O request queued when we return.
2138 SYS$SETAST is used to avoid a timing error. */
2144 printf ("At end_kbd_input.\n");
2148 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2150 SYS$
CANCEL (input_fd
);
2155 /* Clear a flag, and tell ast routine above to set it. */
2156 SYS$
CLREF (input_ef
);
2157 waiting_for_ast
= 1;
2159 SYS$
CANCEL (input_fd
);
2161 SYS$
WAITFR (input_ef
);
2162 waiting_for_ast
= 0;
2165 /* Wait for either input available or time interval expiry. */
2168 input_wait_timeout (timeval
)
2169 int timeval
; /* Time to wait, in seconds */
2172 static int zero
= 0;
2173 static int large
= -10000000;
2175 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2177 /* If already something, avoid doing system calls. */
2178 if (detect_input_pending ())
2182 /* Clear a flag, and tell ast routine above to set it. */
2183 SYS$
CLREF (input_ef
);
2184 waiting_for_ast
= 1;
2185 /* Check for timing error: ast happened while we were doing that. */
2186 if (!detect_input_pending ())
2188 /* No timing error: wait for flag to be set. */
2190 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2191 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
2193 waiting_for_ast
= 0;
2196 /* The standard `sleep' routine works some other way
2197 and it stops working if you have ever quit out of it.
2198 This one continues to work. */
2204 static int zero
= 0;
2205 static int large
= -10000000;
2207 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2210 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2211 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2231 croak ("request sigio");
2239 croak ("unrequest sigio");
2244 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2249 #ifndef SYSTEM_MALLOC
2256 /* Some systems that cannot dump also cannot implement these. */
2259 * Return the address of the start of the text segment prior to
2260 * doing an unexec. After unexec the return value is undefined.
2261 * See crt0.c for further explanation and _start.
2265 #if !(defined (__NetBSD__) && defined (__ELF__))
2266 #ifndef HAVE_TEXT_START
2271 return ((char *) TEXT_START
);
2275 return ((char *) csrt
);
2276 #else /* not GOULD */
2277 extern int _start ();
2278 return ((char *) _start
);
2280 #endif /* TEXT_START */
2282 #endif /* not HAVE_TEXT_START */
2286 * Return the address of the start of the data segment prior to
2287 * doing an unexec. After unexec the return value is undefined.
2288 * See crt0.c for further information and definition of data_start.
2290 * Apparently, on BSD systems this is etext at startup. On
2291 * USG systems (swapping) this is highly mmu dependent and
2292 * is also dependent on whether or not the program is running
2293 * with shared text. Generally there is a (possibly large)
2294 * gap between end of text and start of data with shared text.
2296 * On Uniplus+ systems with shared text, data starts at a
2297 * fixed address. Each port (from a given oem) is generally
2298 * different, and the specific value of the start of data can
2299 * be obtained via the UniPlus+ specific "uvar" system call,
2300 * however the method outlined in crt0.c seems to be more portable.
2302 * Probably what will have to happen when a USG unexec is available,
2303 * at least on UniPlus, is temacs will have to be made unshared so
2304 * that text and data are contiguous. Then once loadup is complete,
2305 * unexec will produce a shared executable where the data can be
2306 * at the normal shared text boundary and the startofdata variable
2307 * will be patched by unexec to the correct value.
2311 #ifndef start_of_data
2316 return ((char *) DATA_START
);
2318 #ifdef ORDINARY_LINK
2320 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2321 * data_start isn't defined. We take the address of environ, which
2322 * is known to live at or near the start of the system crt0.c, and
2323 * we don't sweat the handful of bytes that might lose.
2325 extern char **environ
;
2327 return ((char *) &environ
);
2329 extern int data_start
;
2330 return ((char *) &data_start
);
2331 #endif /* ORDINARY_LINK */
2332 #endif /* DATA_START */
2334 #endif /* start_of_data */
2335 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2337 /* init_system_name sets up the string for the Lisp function
2338 system-name to return. */
2344 extern Lisp_Object Vsystem_name
;
2349 #include <sys/socket.h>
2351 #endif /* HAVE_SOCKETS */
2352 #endif /* not VMS */
2353 #endif /* not BSD4_1 */
2356 #ifndef HAVE_H_ERRNO
2359 #endif /* TRY_AGAIN */
2365 Vsystem_name
= build_string (sysname
);
2369 if ((sp
= egetenv ("SYS$NODE")) == 0)
2370 Vsystem_name
= build_string ("vax-vms");
2371 else if ((end
= index (sp
, ':')) == 0)
2372 Vsystem_name
= build_string (sp
);
2374 Vsystem_name
= make_string (sp
, end
- sp
);
2376 #ifndef HAVE_GETHOSTNAME
2379 Vsystem_name
= build_string (uts
.nodename
);
2380 #else /* HAVE_GETHOSTNAME */
2381 unsigned int hostname_size
= 256;
2382 char *hostname
= (char *) alloca (hostname_size
);
2384 /* Try to get the host name; if the buffer is too short, try
2385 again. Apparently, the only indication gethostname gives of
2386 whether the buffer was large enough is the presence or absence
2387 of a '\0' in the string. Eech. */
2390 gethostname (hostname
, hostname_size
- 1);
2391 hostname
[hostname_size
- 1] = '\0';
2393 /* Was the buffer large enough for the '\0'? */
2394 if (strlen (hostname
) < hostname_size
- 1)
2397 hostname_size
<<= 1;
2398 hostname
= (char *) alloca (hostname_size
);
2401 /* Turn the hostname into the official, fully-qualified hostname.
2402 Don't do this if we're going to dump; this can confuse system
2403 libraries on some machines and make the dumped emacs core dump. */
2406 #endif /* not CANNOT_DUMP */
2407 if (! index (hostname
, '.'))
2411 for (count
= 0;; count
++)
2416 hp
= gethostbyname (hostname
);
2418 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2423 Fsleep_for (make_number (1), Qnil
);
2427 char *fqdn
= (char *) hp
->h_name
;
2432 if (!index (fqdn
, '.'))
2434 /* We still don't have a fully qualified domain name.
2435 Try to find one in the list of alternate names */
2436 char **alias
= hp
->h_aliases
;
2438 && (!index (*alias
, '.')
2439 || !strcmp (*alias
, "localhost.localdomain")))
2446 /* Convert the host name to lower case. */
2447 /* Using ctype.h here would introduce a possible locale
2448 dependence that is probably wrong for hostnames. */
2452 if (*p
>= 'A' && *p
<= 'Z')
2459 #endif /* HAVE_SOCKETS */
2460 /* We used to try using getdomainname here,
2461 but NIIBE Yutaka <gniibe@etl.go.jp> says that
2462 getdomainname gets the NIS/YP domain which often is not the same
2463 as in Internet domain name. */
2464 #if 0 /* Turned off because sysinfo is not really likely to return the
2465 correct Internet domain. */
2466 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2467 if (! index (hostname
, '.'))
2469 /* The hostname is not fully qualified. Append the domain name. */
2471 int hostlen
= strlen (hostname
);
2472 int domain_size
= 256;
2476 char *domain
= (char *) alloca (domain_size
+ 1);
2477 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2478 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2479 if (sys_domain_size
<= 0)
2481 if (domain_size
< sys_domain_size
)
2483 domain_size
= sys_domain_size
;
2486 strcpy (fqdn
, hostname
);
2487 if (domain
[0] == '.')
2488 strcpy (fqdn
+ hostlen
, domain
);
2489 else if (domain
[0] != 0)
2491 fqdn
[hostlen
] = '.';
2492 strcpy (fqdn
+ hostlen
+ 1, domain
);
2498 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2500 Vsystem_name
= build_string (hostname
);
2501 #endif /* HAVE_GETHOSTNAME */
2506 for (p
= SDATA (Vsystem_name
); *p
; p
++)
2507 if (*p
== ' ' || *p
== '\t')
2514 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2516 #include "sysselect.h"
2519 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2520 /* Cause explanatory error message at compile time,
2521 since the select emulation is not good enough for X. */
2522 int *x
= &x_windows_lose_if_no_select_system_call
;
2525 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2526 * Only checks read descriptors.
2528 /* How long to wait between checking fds in select */
2529 #define SELECT_PAUSE 1
2532 /* For longjmp'ing back to read_input_waiting. */
2534 jmp_buf read_alarm_throw
;
2536 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2537 The read_socket_hook function sets this to 1 while it is waiting. */
2539 int read_alarm_should_throw
;
2547 #else /* not BSD4_1 */
2548 signal (SIGALRM
, SIG_IGN
);
2549 #endif /* not BSD4_1 */
2550 SIGNAL_THREAD_CHECK (SIGALRM
);
2551 if (read_alarm_should_throw
)
2552 longjmp (read_alarm_throw
, 1);
2556 /* Only rfds are checked. */
2558 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2560 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2561 EMACS_TIME
*timeout
;
2567 extern int proc_buffered_char
[];
2568 #ifndef subprocesses
2569 int process_tick
= 0, update_tick
= 0;
2571 extern int process_tick
, update_tick
;
2575 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2576 /* If we're using X, then the native select will work; we only need the
2577 emulation for non-X usage. */
2578 if (!NILP (Vwindow_system
))
2579 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2581 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2582 local_timeout
= &timeoutval
;
2594 /* If we are looking only for the terminal, with no timeout,
2595 just read it and wait -- that's more efficient. */
2596 if (*local_timeout
== 100000 && process_tick
== update_tick
2597 && FD_ISSET (0, &orfds
))
2600 for (fd
= 1; fd
< nfds
; ++fd
)
2601 if (FD_ISSET (fd
, &orfds
))
2603 if (! detect_input_pending ())
2604 read_input_waiting ();
2610 /* Once a second, till the timer expires, check all the flagged read
2611 * descriptors to see if any input is available. If there is some then
2612 * set the corresponding bit in the return copy of rfds.
2616 register int to_check
, fd
;
2620 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2622 if (FD_ISSET (fd
, &orfds
))
2624 int avail
= 0, status
= 0;
2627 avail
= detect_input_pending (); /* Special keyboard handler */
2631 status
= ioctl (fd
, FIONREAD
, &avail
);
2632 #else /* no FIONREAD */
2633 /* Hoping it will return -1 if nothing available
2634 or 0 if all 0 chars requested are read. */
2635 if (proc_buffered_char
[fd
] >= 0)
2639 avail
= read (fd
, &buf
, 1);
2641 proc_buffered_char
[fd
] = buf
;
2643 #endif /* no FIONREAD */
2645 if (status
>= 0 && avail
> 0)
2653 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2656 turn_on_atimers (0);
2657 signal (SIGALRM
, select_alarm
);
2659 alarm (SELECT_PAUSE
);
2661 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2662 while (select_alarmed
== 0 && *local_timeout
!= 0
2663 && process_tick
== update_tick
)
2665 /* If we are interested in terminal input,
2666 wait by reading the terminal.
2667 That makes instant wakeup for terminal input at least. */
2668 if (FD_ISSET (0, &orfds
))
2670 read_input_waiting ();
2671 if (detect_input_pending ())
2677 (*local_timeout
) -= SELECT_PAUSE
;
2679 /* Reset the old alarm if there was one. */
2680 turn_on_atimers (1);
2682 if (*local_timeout
== 0) /* Stop on timer being cleared */
2687 #endif /* not WINDOWSNT */
2689 /* Read keyboard input into the standard buffer,
2690 waiting for at least one character. */
2693 read_input_waiting ()
2696 extern int quit_char
;
2698 if (read_socket_hook
)
2700 struct input_event hold_quit
;
2702 EVENT_INIT (hold_quit
);
2703 hold_quit
.kind
= NO_EVENT
;
2705 read_alarm_should_throw
= 0;
2706 if (! setjmp (read_alarm_throw
))
2707 nread
= (*read_socket_hook
) (0, 1, &hold_quit
);
2711 if (hold_quit
.kind
!= NO_EVENT
)
2712 kbd_buffer_store_event (&hold_quit
);
2716 struct input_event e
;
2718 nread
= read (fileno (stdin
), buf
, 1);
2721 /* Scan the chars for C-g and store them in kbd_buffer. */
2722 e
.kind
= ASCII_KEYSTROKE_EVENT
;
2723 e
.frame_or_window
= selected_frame
;
2725 for (i
= 0; i
< nread
; i
++)
2727 /* Convert chars > 0177 to meta events if desired.
2728 We do this under the same conditions that read_avail_input does. */
2729 if (read_socket_hook
== 0)
2731 /* If the user says she has a meta key, then believe her. */
2732 if (meta_key
== 1 && (buf
[i
] & 0x80))
2733 e
.modifiers
= meta_modifier
;
2738 XSETINT (e
.code
, buf
[i
]);
2739 kbd_buffer_store_event (&e
);
2740 /* Don't look at input that follows a C-g too closely.
2741 This reduces lossage due to autorepeat on C-g. */
2742 if (buf
[i
] == quit_char
)
2748 #endif /* not HAVE_SELECT */
2749 #endif /* not VMS */
2750 #endif /* not MSDOS */
2759 lmode
= LINTRUP
| lmode
;
2760 ioctl (fd
, TIOCLSET
, &lmode
);
2768 lmode
= ~LINTRUP
& lmode
;
2769 ioctl (0, TIOCLSET
, &lmode
);
2779 interrupts_deferred
= 0;
2789 interrupts_deferred
= 1;
2792 /* still inside #ifdef BSD4_1 */
2795 int sigheld
; /* Mask of held signals */
2801 sigheld
|= sigbit (signum
);
2809 sigheld
|= sigbit (signum
);
2816 sigheld
&= ~sigbit (signum
);
2821 sigfree () /* Free all held signals */
2824 for (i
= 0; i
< NSIG
; i
++)
2825 if (sigheld
& sigbit (i
))
2833 return 1 << (i
- 1);
2835 #endif /* subprocesses */
2838 /* POSIX signals support - DJB */
2839 /* Anyone with POSIX signals should have ANSI C declarations */
2841 #ifdef POSIX_SIGNALS
2843 sigset_t empty_mask
, full_mask
;
2846 sys_signal (int signal_number
, signal_handler_t action
)
2848 struct sigaction new_action
, old_action
;
2849 sigemptyset (&new_action
.sa_mask
);
2850 new_action
.sa_handler
= action
;
2851 #if defined (SA_RESTART) && ! defined (BROKEN_SA_RESTART) && !defined(SYNC_INPUT)
2852 /* Emacs mostly works better with restartable system services. If this
2853 flag exists, we probably want to turn it on here.
2854 However, on some systems this resets the timeout of `select'
2855 which means that `select' never finishes if it keeps getting signals.
2856 BROKEN_SA_RESTART is defined on those systems. */
2857 /* It's not clear why the comment above says "mostly works better". --Stef
2858 When SYNC_INPUT is set, we don't want SA_RESTART because we need to poll
2859 for pending input so we need long-running syscalls to be interrupted
2860 after a signal that sets the interrupt_input_pending flag. */
2861 new_action
.sa_flags
= SA_RESTART
;
2863 new_action
.sa_flags
= 0;
2865 sigaction (signal_number
, &new_action
, &old_action
);
2866 return (old_action
.sa_handler
);
2870 /* If we're compiling with GCC, we don't need this function, since it
2871 can be written as a macro. */
2873 sys_sigmask (int sig
)
2876 sigemptyset (&mask
);
2877 sigaddset (&mask
, sig
);
2882 /* I'd like to have these guys return pointers to the mask storage in here,
2883 but there'd be trouble if the code was saving multiple masks. I'll be
2884 safe and pass the structure. It normally won't be more than 2 bytes
2888 sys_sigblock (sigset_t new_mask
)
2891 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2896 sys_sigunblock (sigset_t new_mask
)
2899 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2904 sys_sigsetmask (sigset_t new_mask
)
2907 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2911 #endif /* POSIX_SIGNALS */
2913 #if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
2914 static char *my_sys_siglist
[NSIG
];
2918 # define sys_siglist my_sys_siglist
2924 #ifdef POSIX_SIGNALS
2925 sigemptyset (&empty_mask
);
2926 sigfillset (&full_mask
);
2929 #if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
2933 sys_siglist
[SIGABRT
] = "Aborted";
2936 sys_siglist
[SIGAIO
] = "LAN I/O interrupt";
2939 sys_siglist
[SIGALRM
] = "Alarm clock";
2942 sys_siglist
[SIGBUS
] = "Bus error";
2945 sys_siglist
[SIGCLD
] = "Child status changed";
2948 sys_siglist
[SIGCHLD
] = "Child status changed";
2951 sys_siglist
[SIGCONT
] = "Continued";
2954 sys_siglist
[SIGDANGER
] = "Swap space dangerously low";
2957 sys_siglist
[SIGDGNOTIFY
] = "Notification message in queue";
2960 sys_siglist
[SIGEMT
] = "Emulation trap";
2963 sys_siglist
[SIGFPE
] = "Arithmetic exception";
2966 sys_siglist
[SIGFREEZE
] = "SIGFREEZE";
2969 sys_siglist
[SIGGRANT
] = "Monitor mode granted";
2972 sys_siglist
[SIGHUP
] = "Hangup";
2975 sys_siglist
[SIGILL
] = "Illegal instruction";
2978 sys_siglist
[SIGINT
] = "Interrupt";
2981 sys_siglist
[SIGIO
] = "I/O possible";
2984 sys_siglist
[SIGIOINT
] = "I/O intervention required";
2987 sys_siglist
[SIGIOT
] = "IOT trap";
2990 sys_siglist
[SIGKILL
] = "Killed";
2993 sys_siglist
[SIGLOST
] = "Resource lost";
2996 sys_siglist
[SIGLWP
] = "SIGLWP";
2999 sys_siglist
[SIGMSG
] = "Monitor mode data available";
3002 sys_siglist
[SIGWIND
] = "SIGPHONE";
3005 sys_siglist
[SIGPIPE
] = "Broken pipe";
3008 sys_siglist
[SIGPOLL
] = "Pollable event occurred";
3011 sys_siglist
[SIGPROF
] = "Profiling timer expired";
3014 sys_siglist
[SIGPTY
] = "PTY I/O interrupt";
3017 sys_siglist
[SIGPWR
] = "Power-fail restart";
3020 sys_siglist
[SIGQUIT
] = "Quit";
3023 sys_siglist
[SIGRETRACT
] = "Need to relinguish monitor mode";
3026 sys_siglist
[SIGSAK
] = "Secure attention";
3029 sys_siglist
[SIGSEGV
] = "Segmentation violation";
3032 sys_siglist
[SIGSOUND
] = "Sound completed";
3035 sys_siglist
[SIGSTOP
] = "Stopped (signal)";
3038 sys_siglist
[SIGSTP
] = "Stopped (user)";
3041 sys_siglist
[SIGSYS
] = "Bad argument to system call";
3044 sys_siglist
[SIGTERM
] = "Terminated";
3047 sys_siglist
[SIGTHAW
] = "SIGTHAW";
3050 sys_siglist
[SIGTRAP
] = "Trace/breakpoint trap";
3053 sys_siglist
[SIGTSTP
] = "Stopped (user)";
3056 sys_siglist
[SIGTTIN
] = "Stopped (tty input)";
3059 sys_siglist
[SIGTTOU
] = "Stopped (tty output)";
3062 sys_siglist
[SIGURG
] = "Urgent I/O condition";
3065 sys_siglist
[SIGUSR1
] = "User defined signal 1";
3068 sys_siglist
[SIGUSR2
] = "User defined signal 2";
3071 sys_siglist
[SIGVTALRM
] = "Virtual timer expired";
3074 sys_siglist
[SIGWAITING
] = "Process's LWPs are blocked";
3077 sys_siglist
[SIGWINCH
] = "Window size changed";
3080 sys_siglist
[SIGWIND
] = "SIGWIND";
3083 sys_siglist
[SIGXCPU
] = "CPU time limit exceeded";
3086 sys_siglist
[SIGXFSZ
] = "File size limit exceeded";
3089 #endif /* !defined HAVE_STRSIGNAL && !defined HAVE_DECL_SYS_SIGLIST */
3098 /* Figure out how many bits the system's random number generator uses.
3099 `random' and `lrand48' are assumed to return 31 usable bits.
3100 BSD `rand' returns a 31 bit value but the low order bits are unusable;
3101 so we'll shift it and treat it like the 15-bit USG `rand'. */
3105 # define RAND_BITS 31
3106 # else /* !HAVE_RANDOM */
3107 # ifdef HAVE_LRAND48
3108 # define RAND_BITS 31
3109 # define random lrand48
3110 # else /* !HAVE_LRAND48 */
3111 # define RAND_BITS 15
3112 # if RAND_MAX == 32767
3113 # define random rand
3114 # else /* RAND_MAX != 32767 */
3115 # if RAND_MAX == 2147483647
3116 # define random() (rand () >> 16)
3117 # else /* RAND_MAX != 2147483647 */
3119 # define random rand
3121 # define random() (rand () >> 16)
3123 # endif /* RAND_MAX != 2147483647 */
3124 # endif /* RAND_MAX != 32767 */
3125 # endif /* !HAVE_LRAND48 */
3126 # endif /* !HAVE_RANDOM */
3127 #endif /* !RAND_BITS */
3134 srandom ((unsigned int)arg
);
3136 # ifdef HAVE_LRAND48
3139 srand ((unsigned int)arg
);
3145 * Build a full Emacs-sized word out of whatever we've got.
3146 * This suffices even for a 64-bit architecture with a 15-bit rand.
3151 long val
= random ();
3152 #if VALBITS > RAND_BITS
3153 val
= (val
<< RAND_BITS
) ^ random ();
3154 #if VALBITS > 2*RAND_BITS
3155 val
= (val
<< RAND_BITS
) ^ random ();
3156 #if VALBITS > 3*RAND_BITS
3157 val
= (val
<< RAND_BITS
) ^ random ();
3158 #if VALBITS > 4*RAND_BITS
3159 val
= (val
<< RAND_BITS
) ^ random ();
3160 #endif /* need at least 5 */
3161 #endif /* need at least 4 */
3162 #endif /* need at least 3 */
3163 #endif /* need at least 2 */
3164 return val
& ((1L << VALBITS
) - 1);
3167 #ifdef WRONG_NAME_INSQUE
3180 /* If any place else asks for the TERM variable,
3181 allow it to be overridden with the EMACS_TERM variable
3182 before attempting to translate the logical name TERM. As a last
3183 resort, ask for VAX C's special idea of the TERM variable. */
3190 static char buf
[256];
3191 static struct dsc$descriptor_s equiv
3192 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
3193 static struct dsc$descriptor_s d_name
3194 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
3197 if (!strcmp (name
, "TERM"))
3199 val
= (char *) getenv ("EMACS_TERM");
3204 d_name
.dsc$w_length
= strlen (name
);
3205 d_name
.dsc$a_pointer
= name
;
3206 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
3208 char *str
= (char *) xmalloc (eqlen
+ 1);
3209 bcopy (buf
, str
, eqlen
);
3211 /* This is a storage leak, but a pain to fix. With luck,
3212 no one will ever notice. */
3215 return (char *) getenv (name
);
3220 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
3221 to force a call on the debugger from within the image. */
3226 LIB$
SIGNAL (SS$_DEBUG
);
3232 #ifdef LINK_CRTL_SHARE
3233 #ifdef SHARABLE_LIB_BUG
3234 /* Variables declared noshare and initialized in sharable libraries
3235 cannot be shared. The VMS linker incorrectly forces you to use a private
3236 version which is uninitialized... If not for this "feature", we
3237 could use the C library definition of sys_nerr and sys_errlist. */
3239 char *sys_errlist
[] =
3243 "no such file or directory",
3245 "interrupted system call",
3247 "no such device or address",
3248 "argument list too long",
3249 "exec format error",
3252 "no more processes",
3253 "not enough memory",
3254 "permission denied",
3256 "block device required",
3257 "mount devices busy",
3259 "cross-device link",
3264 "file table overflow",
3265 "too many open files",
3269 "no space left on device",
3271 "read-only file system",
3277 "vax/vms specific error code nontranslatable error"
3279 #endif /* SHARABLE_LIB_BUG */
3280 #endif /* LINK_CRTL_SHARE */
3283 #ifndef HAVE_STRERROR
3289 extern char *sys_errlist
[];
3290 extern int sys_nerr
;
3292 if (errnum
>= 0 && errnum
< sys_nerr
)
3293 return sys_errlist
[errnum
];
3294 return (char *) "Unknown error";
3296 #endif /* not WINDOWSNT */
3297 #endif /* ! HAVE_STRERROR */
3300 emacs_open (path
, oflag
, mode
)
3304 register int rtnval
;
3307 if (oflag
& O_CREAT
)
3308 return creat (path
, mode
);
3311 while ((rtnval
= open (path
, oflag
, mode
)) == -1
3312 && (errno
== EINTR
))
3322 register int rtnval
;
3324 #if defined (MAC_OSX) && defined (HAVE_CARBON)
3326 extern int mac_try_close_socket
P_ ((int));
3328 if (mac_try_close_socket (fd
))
3333 while ((rtnval
= close (fd
)) == -1
3334 && (errno
== EINTR
))
3337 /* If close is interrupted SunOS 4.1 may or may not have closed the
3338 file descriptor. If it did the second close will fail with
3339 errno = EBADF. That means we have succeeded. */
3340 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3347 emacs_read (fildes
, buf
, nbyte
)
3352 register int rtnval
;
3354 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3355 && (errno
== EINTR
))
3361 emacs_write (fildes
, buf
, nbyte
)
3366 register int rtnval
, bytes_written
;
3372 rtnval
= write (fildes
, buf
, nbyte
);
3379 /* I originally used `QUIT' but that might causes files to
3380 be truncated if you hit C-g in the middle of it. --Stef */
3381 if (interrupt_input_pending
)
3382 handle_async_input ();
3387 return (bytes_written
? bytes_written
: -1);
3392 bytes_written
+= rtnval
;
3394 return (bytes_written
);
3399 * All of the following are for USG.
3401 * On USG systems the system calls are INTERRUPTIBLE by signals
3402 * that the user program has elected to catch. Thus the system call
3403 * must be retried in these cases. To handle this without massive
3404 * changes in the source code, we remap the standard system call names
3405 * to names for our own functions in sysdep.c that do the system call
3406 * with retries. Actually, for portability reasons, it is good
3407 * programming practice, as this example shows, to limit all actual
3408 * system calls to a single occurrence in the source. Sure, this
3409 * adds an extra level of function call overhead but it is almost
3410 * always negligible. Fred Fish, Unisoft Systems Inc.
3414 * Warning, this function may not duplicate 4.2 action properly
3415 * under error conditions.
3419 /* In 4.1, param.h fails to define this. */
3420 #define MAXPATHLEN 1024
3429 char *npath
, *spath
;
3430 extern char *getcwd ();
3432 BLOCK_INPUT
; /* getcwd uses malloc */
3433 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3439 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3440 up to first slash. Should be harmless on other systems. */
3441 while (*npath
&& *npath
!= '/')
3443 strcpy (pathname
, npath
);
3444 free (spath
); /* getcwd uses malloc */
3449 #endif /* HAVE_GETWD */
3452 * Emulate rename using unlink/link. Note that this is
3453 * only partially correct. Also, doesn't enforce restriction
3454 * that files be of same type (regular->regular, dir->dir, etc).
3463 if (access (from
, 0) == 0)
3466 if (link (from
, to
) == 0)
3467 if (unlink (from
) == 0)
3479 /* HPUX curses library references perror, but as far as we know
3480 it won't be called. Anyway this definition will do for now. */
3486 #endif /* not HAVE_PERROR */
3492 * Emulate BSD dup2. First close newd if it already exists.
3493 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3494 * until we are, then close the unsuccessful ones.
3501 register int fd
, ret
;
3506 return fcntl (oldd
, F_DUPFD
, newd
);
3513 ret
= dup2 (old
,new);
3519 #endif /* not HAVE_DUP2 */
3522 * Gettimeofday. Simulate as much as possible. Only accurate
3523 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3524 * Only needed when subprocesses are defined.
3529 #ifndef HAVE_GETTIMEOFDAY
3534 gettimeofday (tp
, tzp
)
3536 struct timezone
*tzp
;
3538 extern long time ();
3540 tp
->tv_sec
= time ((long *)0);
3543 tzp
->tz_minuteswest
= -1;
3550 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3553 * This function will go away as soon as all the stubs fixed. (fnf)
3560 printf ("%s not yet implemented\r\n", badfunc
);
3567 /* Directory routines for systems that don't have them. */
3569 #ifdef SYSV_SYSTEM_DIR
3573 #if defined (BROKEN_CLOSEDIR) || !defined (HAVE_CLOSEDIR)
3577 register DIR *dirp
; /* stream from opendir */
3581 rtnval
= emacs_close (dirp
->dd_fd
);
3583 /* Some systems (like Solaris) allocate the buffer and the DIR all
3584 in one block. Why in the world are we freeing this ourselves
3586 #if ! (defined (sun) && defined (USG5_4))
3587 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3589 xfree ((char *) dirp
);
3593 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3594 #endif /* SYSV_SYSTEM_DIR */
3596 #ifdef NONSYSTEM_DIR_LIBRARY
3600 char *filename
; /* name of directory */
3602 register DIR *dirp
; /* -> malloc'ed storage */
3603 register int fd
; /* file descriptor for read */
3604 struct stat sbuf
; /* result of fstat */
3606 fd
= emacs_open (filename
, O_RDONLY
, 0);
3611 if (fstat (fd
, &sbuf
) < 0
3612 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3613 || (dirp
= (DIR *) xmalloc (sizeof (DIR))) == 0)
3617 return 0; /* bad luck today */
3622 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3629 register DIR *dirp
; /* stream from opendir */
3631 emacs_close (dirp
->dd_fd
);
3632 xfree ((char *) dirp
);
3640 ino_t od_ino
; /* inode */
3641 char od_name
[DIRSIZ
]; /* filename */
3643 #endif /* not VMS */
3645 struct direct dir_static
; /* simulated directory contents */
3650 register DIR *dirp
; /* stream from opendir */
3653 register struct olddir
*dp
; /* -> directory data */
3655 register struct dir$_name
*dp
; /* -> directory data */
3656 register struct dir$_version
*dv
; /* -> version data */
3661 if (dirp
->dd_loc
>= dirp
->dd_size
)
3662 dirp
->dd_loc
= dirp
->dd_size
= 0;
3664 if (dirp
->dd_size
== 0 /* refill buffer */
3665 && (dirp
->dd_size
= emacs_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3669 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3670 dirp
->dd_loc
+= sizeof (struct olddir
);
3672 if (dp
->od_ino
!= 0) /* not deleted entry */
3674 dir_static
.d_ino
= dp
->od_ino
;
3675 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3676 dir_static
.d_name
[DIRSIZ
] = '\0';
3677 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3678 dir_static
.d_reclen
= sizeof (struct direct
)
3680 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3681 return &dir_static
; /* -> simulated structure */
3684 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3685 if (dirp
->dd_loc
== 0)
3686 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3687 : dp
->dir$b_namecount
;
3688 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3689 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3690 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3691 dir_static
.d_reclen
= sizeof (struct direct
)
3693 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3694 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3695 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3696 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3703 /* readdirver is just like readdir except it returns all versions of a file
3704 as separate entries. */
3709 register DIR *dirp
; /* stream from opendir */
3711 register struct dir$_name
*dp
; /* -> directory data */
3712 register struct dir$_version
*dv
; /* -> version data */
3714 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3715 dirp
->dd_loc
= dirp
->dd_size
= 0;
3717 if (dirp
->dd_size
== 0 /* refill buffer */
3718 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3721 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3722 if (dirp
->dd_loc
== 0)
3723 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3724 : dp
->dir$b_namecount
;
3725 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3726 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3727 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3728 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3729 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3730 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3731 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3732 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3738 #endif /* NONSYSTEM_DIR_LIBRARY */
3742 set_file_times (filename
, atime
, mtime
)
3743 const char *filename
;
3744 EMACS_TIME atime
, mtime
;
3747 struct timeval tv
[2];
3750 return utimes (filename
, tv
);
3751 #else /* not HAVE_UTIMES */
3753 utb
.actime
= EMACS_SECS (atime
);
3754 utb
.modtime
= EMACS_SECS (mtime
);
3755 return utime (filename
, &utb
);
3756 #endif /* not HAVE_UTIMES */
3759 /* mkdir and rmdir functions, for systems which don't have them. */
3763 * Written by Robert Rother, Mariah Corporation, August 1985.
3765 * If you want it, it's yours. All I ask in return is that if you
3766 * figure out how to do this in a Bourne Shell script you send me
3768 * sdcsvax!rmr or rmr@uscd
3770 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3771 * subroutine. 11Mar86; hoptoad!gnu
3773 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3774 * subroutine didn't return EEXIST. It does now.
3780 #ifdef MKDIR_PROTOTYPE
3784 mkdir (dpath
, dmode
)
3789 int cpid
, status
, fd
;
3790 struct stat statbuf
;
3792 if (stat (dpath
, &statbuf
) == 0)
3794 errno
= EEXIST
; /* Stat worked, so it already exists */
3798 /* If stat fails for a reason other than non-existence, return error */
3799 if (errno
!= ENOENT
)
3802 synch_process_alive
= 1;
3803 switch (cpid
= fork ())
3806 case -1: /* Error in fork */
3807 return (-1); /* Errno is set already */
3809 case 0: /* Child process */
3811 * Cheap hack to set mode of new directory. Since this
3812 * child process is going away anyway, we zap its umask.
3813 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3814 * directory. Does anybody care?
3816 status
= umask (0); /* Get current umask */
3817 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3818 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3825 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3826 _exit (-1); /* Can't exec /bin/mkdir */
3828 default: /* Parent process */
3829 wait_for_termination (cpid
);
3832 if (synch_process_death
!= 0 || synch_process_retcode
!= 0
3833 || synch_process_termsig
!= 0)
3835 errno
= EIO
; /* We don't know why, but */
3836 return -1; /* /bin/mkdir failed */
3841 #endif /* not HAVE_MKDIR */
3848 int cpid
, status
, fd
;
3849 struct stat statbuf
;
3851 if (stat (dpath
, &statbuf
) != 0)
3853 /* Stat just set errno. We don't have to */
3857 synch_process_alive
= 1;
3858 switch (cpid
= fork ())
3861 case -1: /* Error in fork */
3862 return (-1); /* Errno is set already */
3864 case 0: /* Child process */
3865 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3872 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3873 _exit (-1); /* Can't exec /bin/rmdir */
3875 default: /* Parent process */
3876 wait_for_termination (cpid
);
3879 if (synch_process_death
!= 0 || synch_process_retcode
!= 0
3880 || synch_process_termsig
!= 0)
3882 errno
= EIO
; /* We don't know why, but */
3883 return -1; /* /bin/rmdir failed */
3888 #endif /* !HAVE_RMDIR */
3892 /* Functions for VMS */
3898 /* Return as a string the VMS error string pertaining to STATUS.
3899 Reuses the same static buffer each time it is called. */
3903 int status
; /* VMS status code */
3907 static char buf
[257];
3909 bufadr
[0] = sizeof buf
- 1;
3910 bufadr
[1] = (int) buf
;
3911 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3912 return "untranslatable VMS error status";
3920 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3921 * not work correctly. (It also doesn't work well in version 2.3.)
3926 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3927 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3931 unsigned short s_buflen
;
3932 unsigned short s_code
;
3934 unsigned short *s_retlenadr
;
3938 #define buflen s.s_buflen
3939 #define code s.s_code
3940 #define bufadr s.s_bufadr
3941 #define retlenadr s.s_retlenadr
3943 #define R_OK 4 /* test for read permission */
3944 #define W_OK 2 /* test for write permission */
3945 #define X_OK 1 /* test for execute (search) permission */
3946 #define F_OK 0 /* test for presence of file */
3949 sys_access (path
, mode
)
3953 static char *user
= NULL
;
3956 /* translate possible directory spec into .DIR file name, so brain-dead
3957 * access can treat the directory like a file. */
3958 if (directory_file_name (path
, dir_fn
))
3962 return access (path
, mode
);
3963 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3969 unsigned short int dummy
;
3971 static int constant
= ACL$C_FILE
;
3972 DESCRIPTOR (path_desc
, path
);
3973 DESCRIPTOR (user_desc
, user
);
3977 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3980 acces
|= CHP$M_READ
;
3982 acces
|= CHP$M_WRITE
;
3983 itemlst
[0].buflen
= sizeof (int);
3984 itemlst
[0].code
= CHP$_FLAGS
;
3985 itemlst
[0].bufadr
= (char *) &flags
;
3986 itemlst
[0].retlenadr
= &dummy
;
3987 itemlst
[1].buflen
= sizeof (int);
3988 itemlst
[1].code
= CHP$_ACCESS
;
3989 itemlst
[1].bufadr
= (char *) &acces
;
3990 itemlst
[1].retlenadr
= &dummy
;
3991 itemlst
[2].end
= CHP$_END
;
3992 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3993 return stat
== SS$_NORMAL
? 0 : -1;
3997 #else /* not VMS4_4 */
4000 #define ACE$M_WRITE 2
4001 #define ACE$C_KEYID 1
4003 static unsigned short memid
, grpid
;
4004 static unsigned int uic
;
4006 /* Called from init_sys_modes, so it happens not very often
4007 but at least each time Emacs is loaded. */
4009 sys_access_reinit ()
4015 sys_access (filename
, type
)
4021 int status
, size
, i
, typecode
, acl_controlled
;
4022 unsigned int *aclptr
, *aclend
, aclbuf
[60];
4023 union prvdef prvmask
;
4025 /* Get UIC and GRP values for protection checking. */
4028 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
4031 memid
= uic
& 0xFFFF;
4035 if (type
!= 2) /* not checking write access */
4036 return access (filename
, type
);
4038 /* Check write protection. */
4040 #define CHECKPRIV(bit) (prvmask.bit)
4041 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
4043 /* Find privilege bits */
4044 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
4046 error ("Unable to find privileges: %s", vmserrstr (status
));
4047 if (CHECKPRIV (PRV$V_BYPASS
))
4048 return 0; /* BYPASS enabled */
4050 fab
.fab$b_fac
= FAB$M_GET
;
4051 fab
.fab$l_fna
= filename
;
4052 fab
.fab$b_fns
= strlen (filename
);
4053 fab
.fab$l_xab
= &xab
;
4054 xab
= cc$rms_xabpro
;
4055 xab
.xab$l_aclbuf
= aclbuf
;
4056 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
4057 status
= SYS$
OPEN (&fab
, 0, 0);
4060 SYS$
CLOSE (&fab
, 0, 0);
4061 /* Check system access */
4062 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
4064 /* Check ACL entries, if any */
4066 if (xab
.xab$w_acllen
> 0)
4069 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
4070 while (*aclptr
&& aclptr
< aclend
)
4072 size
= (*aclptr
& 0xff) / 4;
4073 typecode
= (*aclptr
>> 8) & 0xff;
4074 if (typecode
== ACE$C_KEYID
)
4075 for (i
= size
- 1; i
> 1; i
--)
4076 if (aclptr
[i
] == uic
)
4079 if (aclptr
[1] & ACE$M_WRITE
)
4080 return 0; /* Write access through ACL */
4082 aclptr
= &aclptr
[size
];
4084 if (acl_controlled
) /* ACL specified, prohibits write access */
4087 /* No ACL entries specified, check normal protection */
4088 if (WRITABLE (XAB$V_WLD
)) /* World writable */
4090 if (WRITABLE (XAB$V_GRP
) &&
4091 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
4092 return 0; /* Group writable */
4093 if (WRITABLE (XAB$V_OWN
) &&
4094 (xab
.xab$l_uic
& 0xFFFF) == memid
)
4095 return 0; /* Owner writable */
4097 return -1; /* Not writable */
4099 #endif /* not VMS4_4 */
4102 static char vtbuf
[NAM$C_MAXRSS
+1];
4104 /* translate a vms file spec to a unix path */
4106 sys_translate_vms (vfile
)
4117 /* leading device or logical name is a root directory */
4118 if (p
= strchr (vfile
, ':'))
4127 if (*p
== '[' || *p
== '<')
4129 while (*++vfile
!= *p
+ 2)
4133 if (vfile
[-1] == *p
)
4156 static char utbuf
[NAM$C_MAXRSS
+1];
4158 /* translate a unix path to a VMS file spec */
4160 sys_translate_unix (ufile
)
4183 if (index (&ufile
[1], '/'))
4190 if (index (&ufile
[1], '/'))
4197 if (strncmp (ufile
, "./", 2) == 0)
4204 ufile
++; /* skip the dot */
4205 if (index (&ufile
[1], '/'))
4210 else if (strncmp (ufile
, "../", 3) == 0)
4218 ufile
+= 2; /* skip the dots */
4219 if (index (&ufile
[1], '/'))
4244 extern char *getcwd ();
4246 #define MAXPATHLEN 1024
4248 ptr
= xmalloc (MAXPATHLEN
);
4249 val
= getcwd (ptr
, MAXPATHLEN
);
4255 strcpy (pathname
, ptr
);
4264 long item_code
= JPI$_OWNER
;
4265 unsigned long parent_id
;
4268 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4271 vaxc$errno
= status
;
4281 return (getgid () << 16) | getuid ();
4286 sys_read (fildes
, buf
, nbyte
)
4291 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4296 sys_write (fildes
, buf
, nbyte
)
4301 register int nwrote
, rtnval
= 0;
4303 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4309 return rtnval
? rtnval
: -1;
4310 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4311 return rtnval
? rtnval
: -1;
4312 return (rtnval
+ nwrote
);
4317 * VAX/VMS VAX C RTL really loses. It insists that records
4318 * end with a newline (carriage return) character, and if they
4319 * don't it adds one (nice of it isn't it!)
4321 * Thus we do this stupidity below.
4326 sys_write (fildes
, buf
, nbytes
)
4329 unsigned int nbytes
;
4336 fstat (fildes
, &st
);
4342 /* Handle fixed-length files with carriage control. */
4343 if (st
.st_fab_rfm
== FAB$C_FIX
4344 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4346 len
= st
.st_fab_mrs
;
4347 retval
= write (fildes
, p
, min (len
, nbytes
));
4350 retval
++; /* This skips the implied carriage control */
4354 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4355 while (*e
!= '\n' && e
> p
) e
--;
4356 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4357 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4359 retval
= write (fildes
, p
, len
);
4370 /* Create file NEW copying its attributes from file OLD. If
4371 OLD is 0 or does not exist, create based on the value of
4374 /* Protection value the file should ultimately have.
4375 Set by create_copy_attrs, and use by rename_sansversions. */
4376 static unsigned short int fab_final_pro
;
4379 creat_copy_attrs (old
, new)
4382 struct FAB fab
= cc$rms_fab
;
4383 struct XABPRO xabpro
;
4384 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4385 extern int vms_stmlf_recfm
;
4389 fab
.fab$b_fac
= FAB$M_GET
;
4390 fab
.fab$l_fna
= old
;
4391 fab
.fab$b_fns
= strlen (old
);
4392 fab
.fab$l_xab
= (char *) &xabpro
;
4393 xabpro
= cc$rms_xabpro
;
4394 xabpro
.xab$l_aclbuf
= aclbuf
;
4395 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4396 /* Call $OPEN to fill in the fab & xabpro fields. */
4397 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4399 SYS$
CLOSE (&fab
, 0, 0);
4400 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4401 if (xabpro
.xab$w_acllen
> 0)
4403 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4404 /* If the acl buffer was too short, redo open with longer one.
4405 Wouldn't need to do this if there were some system imposed
4406 limit on the size of an ACL, but I can't find any such. */
4408 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4409 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4410 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4411 SYS$
CLOSE (&fab
, 0, 0);
4417 xabpro
.xab$l_aclbuf
= 0;
4422 fab
.fab$l_fna
= new;
4423 fab
.fab$b_fns
= strlen (new);
4427 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4428 fab
.fab$b_rat
= FAB$M_CR
;
4431 /* Set the file protections such that we will be able to manipulate
4432 this file. Once we are done writing and renaming it, we will set
4433 the protections back. */
4435 fab_final_pro
= xabpro
.xab$w_pro
;
4437 SYS$
SETDFPROT (0, &fab_final_pro
);
4438 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4440 /* Create the new file with either default attrs or attrs copied
4442 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4444 SYS$
CLOSE (&fab
, 0, 0);
4445 /* As this is a "replacement" for creat, return a file descriptor
4446 opened for writing. */
4447 return open (new, O_WRONLY
);
4452 #include <varargs.h>
4455 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4460 sys_creat (va_alist
)
4463 va_list list_incrementer
;
4466 int rfd
; /* related file descriptor */
4467 int fd
; /* Our new file descriptor */
4474 extern int vms_stmlf_recfm
;
4477 va_start (list_incrementer
);
4478 name
= va_arg (list_incrementer
, char *);
4479 mode
= va_arg (list_incrementer
, int);
4481 rfd
= va_arg (list_incrementer
, int);
4482 va_end (list_incrementer
);
4485 /* Use information from the related file descriptor to set record
4486 format of the newly created file. */
4487 fstat (rfd
, &st_buf
);
4488 switch (st_buf
.st_fab_rfm
)
4491 strcpy (rfm
, "rfm = fix");
4492 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4493 strcpy (rat
, "rat = ");
4494 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4496 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4497 strcat (rat
, "ftn");
4498 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4499 strcat (rat
, "prn");
4500 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4501 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4502 strcat (rat
, ", blk");
4504 strcat (rat
, "blk");
4505 return creat (name
, 0, rfm
, rat
, mrs
);
4508 strcpy (rfm
, "rfm = vfc");
4509 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4510 strcpy (rat
, "rat = ");
4511 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4513 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4514 strcat (rat
, "ftn");
4515 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4516 strcat (rat
, "prn");
4517 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4518 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4519 strcat (rat
, ", blk");
4521 strcat (rat
, "blk");
4522 return creat (name
, 0, rfm
, rat
, fsz
);
4525 strcpy (rfm
, "rfm = stm");
4529 strcpy (rfm
, "rfm = stmcr");
4533 strcpy (rfm
, "rfm = stmlf");
4537 strcpy (rfm
, "rfm = udf");
4541 strcpy (rfm
, "rfm = var");
4544 strcpy (rat
, "rat = ");
4545 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4547 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4548 strcat (rat
, "ftn");
4549 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4550 strcat (rat
, "prn");
4551 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4552 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4553 strcat (rat
, ", blk");
4555 strcat (rat
, "blk");
4559 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4560 strcpy (rat
, "rat=cr");
4562 /* Until the VAX C RTL fixes the many bugs with modes, always use
4563 mode 0 to get the user's default protection. */
4564 fd
= creat (name
, 0, rfm
, rat
);
4565 if (fd
< 0 && errno
== EEXIST
)
4567 if (unlink (name
) < 0)
4568 report_file_error ("delete", build_string (name
));
4569 fd
= creat (name
, 0, rfm
, rat
);
4575 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4577 sys_fwrite (ptr
, size
, num
, fp
)
4578 register char * ptr
;
4581 register int tot
= num
* size
;
4589 * The VMS C library routine creat actually creates a new version of an
4590 * existing file rather than truncating the old version. There are times
4591 * when this is not the desired behavior, for instance, when writing an
4592 * auto save file (you only want one version), or when you don't have
4593 * write permission in the directory containing the file (but the file
4594 * itself is writable). Hence this routine, which is equivalent to
4595 * "close (creat (fn, 0));" on Unix if fn already exists.
4601 struct FAB xfab
= cc$rms_fab
;
4602 struct RAB xrab
= cc$rms_rab
;
4605 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4606 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4607 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4608 xfab
.fab$l_fna
= fn
;
4609 xfab
.fab$b_fns
= strlen (fn
);
4610 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4612 xrab
.rab$l_fab
= &xfab
;
4614 /* This gibberish opens the file, positions to the first record, and
4615 deletes all records from there until the end of file. */
4616 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4618 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4619 (SYS$
FIND (&xrab
) & 01) == 01 &&
4620 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4631 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4632 SYSPRV or a readable SYSUAF.DAT. */
4638 * Routine to read the VMS User Authorization File and return
4639 * a specific user's record.
4642 static struct UAF retuaf
;
4645 get_uaf_name (uname
)
4652 uaf_fab
= cc$rms_fab
;
4653 uaf_rab
= cc$rms_rab
;
4654 /* initialize fab fields */
4655 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4656 uaf_fab
.fab$b_fns
= 21;
4657 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4658 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4659 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4660 /* initialize rab fields */
4661 uaf_rab
.rab$l_fab
= &uaf_fab
;
4662 /* open the User Authorization File */
4663 status
= SYS$
OPEN (&uaf_fab
);
4667 vaxc$errno
= status
;
4670 status
= SYS$
CONNECT (&uaf_rab
);
4674 vaxc$errno
= status
;
4677 /* read the requested record - index is in uname */
4678 uaf_rab
.rab$l_kbf
= uname
;
4679 uaf_rab
.rab$b_ksz
= strlen (uname
);
4680 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4681 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4682 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4683 status
= SYS$
GET (&uaf_rab
);
4687 vaxc$errno
= status
;
4690 /* close the User Authorization File */
4691 status
= SYS$
DISCONNECT (&uaf_rab
);
4695 vaxc$errno
= status
;
4698 status
= SYS$
CLOSE (&uaf_fab
);
4702 vaxc$errno
= status
;
4716 uaf_fab
= cc$rms_fab
;
4717 uaf_rab
= cc$rms_rab
;
4718 /* initialize fab fields */
4719 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4720 uaf_fab
.fab$b_fns
= 21;
4721 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4722 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4723 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4724 /* initialize rab fields */
4725 uaf_rab
.rab$l_fab
= &uaf_fab
;
4726 /* open the User Authorization File */
4727 status
= SYS$
OPEN (&uaf_fab
);
4731 vaxc$errno
= status
;
4734 status
= SYS$
CONNECT (&uaf_rab
);
4738 vaxc$errno
= status
;
4741 /* read the requested record - index is in uic */
4742 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4743 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4744 uaf_rab
.rab$b_ksz
= sizeof uic
;
4745 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4746 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4747 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4748 status
= SYS$
GET (&uaf_rab
);
4752 vaxc$errno
= status
;
4755 /* close the User Authorization File */
4756 status
= SYS$
DISCONNECT (&uaf_rab
);
4760 vaxc$errno
= status
;
4763 status
= SYS$
CLOSE (&uaf_fab
);
4767 vaxc$errno
= status
;
4773 static struct passwd retpw
;
4781 /* copy these out first because if the username is 32 chars, the next
4782 section will overwrite the first byte of the UIC */
4783 retpw
.pw_uid
= up
->uaf$w_mem
;
4784 retpw
.pw_gid
= up
->uaf$w_grp
;
4786 /* I suppose this is not the best style, to possibly overwrite one
4787 byte beyond the end of the field, but what the heck... */
4788 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4789 while (ptr
[-1] == ' ')
4792 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4794 /* the rest of these are counted ascii strings */
4795 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4796 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4797 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4798 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4799 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4800 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4801 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4802 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4806 #else /* not READ_SYSUAF */
4807 static struct passwd retpw
;
4808 #endif /* not READ_SYSUAF */
4819 unsigned char * full
;
4820 #endif /* READ_SYSUAF */
4825 if ('a' <= *ptr
&& *ptr
<= 'z')
4830 if (!(up
= get_uaf_name (name
)))
4832 return cnv_uaf_pw (up
);
4834 if (strcmp (name
, getenv ("USER")) == 0)
4836 retpw
.pw_uid
= getuid ();
4837 retpw
.pw_gid
= getgid ();
4838 strcpy (retpw
.pw_name
, name
);
4839 if (full
= egetenv ("FULLNAME"))
4840 strcpy (retpw
.pw_gecos
, full
);
4842 *retpw
.pw_gecos
= '\0';
4843 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4844 *retpw
.pw_shell
= '\0';
4849 #endif /* not READ_SYSUAF */
4859 if (!(up
= get_uaf_uic (uid
)))
4861 return cnv_uaf_pw (up
);
4863 if (uid
== sys_getuid ())
4864 return getpwnam (egetenv ("USER"));
4867 #endif /* not READ_SYSUAF */
4870 /* return total address space available to the current process. This is
4871 the sum of the current p0 size, p1 size and free page table entries
4877 unsigned long free_pages
;
4878 unsigned long frep0va
;
4879 unsigned long frep1va
;
4882 item_code
= JPI$_FREPTECNT
;
4883 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4886 vaxc$errno
= status
;
4891 item_code
= JPI$_FREP0VA
;
4892 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4895 vaxc$errno
= status
;
4898 item_code
= JPI$_FREP1VA
;
4899 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4902 vaxc$errno
= status
;
4906 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4910 define_logical_name (varname
, string
)
4914 struct dsc$descriptor_s strdsc
=
4915 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4916 struct dsc$descriptor_s envdsc
=
4917 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4918 struct dsc$descriptor_s lnmdsc
=
4919 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4921 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4925 delete_logical_name (varname
)
4928 struct dsc$descriptor_s envdsc
=
4929 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4930 struct dsc$descriptor_s lnmdsc
=
4931 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4933 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4951 error ("execvp system call not implemented");
4960 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4961 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4962 char from_esn
[NAM$C_MAXRSS
];
4963 char to_esn
[NAM$C_MAXRSS
];
4965 from_fab
.fab$l_fna
= from
;
4966 from_fab
.fab$b_fns
= strlen (from
);
4967 from_fab
.fab$l_nam
= &from_nam
;
4968 from_fab
.fab$l_fop
= FAB$M_NAM
;
4970 from_nam
.nam$l_esa
= from_esn
;
4971 from_nam
.nam$b_ess
= sizeof from_esn
;
4973 to_fab
.fab$l_fna
= to
;
4974 to_fab
.fab$b_fns
= strlen (to
);
4975 to_fab
.fab$l_nam
= &to_nam
;
4976 to_fab
.fab$l_fop
= FAB$M_NAM
;
4978 to_nam
.nam$l_esa
= to_esn
;
4979 to_nam
.nam$b_ess
= sizeof to_esn
;
4981 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4987 if (status
== RMS$_DEV
)
4991 vaxc$errno
= status
;
4996 /* This function renames a file like `rename', but it strips
4997 the version number from the "to" filename, such that the "to" file is
4998 will always be a new version. It also sets the file protection once it is
4999 finished. The protection that we will use is stored in fab_final_pro,
5000 and was set when we did a creat_copy_attrs to create the file that we
5003 We could use the chmod function, but Eunichs uses 3 bits per user category
5004 to describe the protection, and VMS uses 4 (write and delete are separate
5005 bits). To maintain portability, the VMS implementation of `chmod' wires
5006 the W and D bits together. */
5009 static struct fibdef fib
; /* We need this initialized to zero */
5010 char vms_file_written
[NAM$C_MAXRSS
];
5013 rename_sans_version (from
,to
)
5020 struct FAB to_fab
= cc$rms_fab
;
5021 struct NAM to_nam
= cc$rms_nam
;
5022 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
5023 struct dsc$descriptor fib_attr
[2]
5024 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
5025 char to_esn
[NAM$C_MAXRSS
];
5027 $
DESCRIPTOR (disk
,to_esn
);
5029 to_fab
.fab$l_fna
= to
;
5030 to_fab
.fab$b_fns
= strlen (to
);
5031 to_fab
.fab$l_nam
= &to_nam
;
5032 to_fab
.fab$l_fop
= FAB$M_NAM
;
5034 to_nam
.nam$l_esa
= to_esn
;
5035 to_nam
.nam$b_ess
= sizeof to_esn
;
5037 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
5039 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
5040 *(to_nam
.nam$l_ver
) = '\0';
5042 stat
= rename (from
, to_esn
);
5046 strcpy (vms_file_written
, to_esn
);
5048 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
5049 to_fab
.fab$b_fns
= strlen (vms_file_written
);
5051 /* Now set the file protection to the correct value */
5052 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
5054 /* Copy these fields into the fib */
5055 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
5056 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
5057 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
5059 SYS$
CLOSE (&to_fab
, 0, 0);
5061 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
5064 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
5065 0, 0, 0, &fib_attr
, 0);
5068 stat
= SYS$
DASSGN (chan
);
5071 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
5082 unsigned short fid
[3];
5083 char esa
[NAM$C_MAXRSS
];
5086 fab
.fab$l_fop
= FAB$M_OFP
;
5087 fab
.fab$l_fna
= file
;
5088 fab
.fab$b_fns
= strlen (file
);
5089 fab
.fab$l_nam
= &nam
;
5092 nam
.nam$l_esa
= esa
;
5093 nam
.nam$b_ess
= NAM$C_MAXRSS
;
5095 status
= SYS$
PARSE (&fab
);
5096 if ((status
& 1) == 0)
5099 vaxc$errno
= status
;
5102 status
= SYS$
SEARCH (&fab
);
5103 if ((status
& 1) == 0)
5106 vaxc$errno
= status
;
5110 fid
[0] = nam
.nam$w_fid
[0];
5111 fid
[1] = nam
.nam$w_fid
[1];
5112 fid
[2] = nam
.nam$w_fid
[2];
5114 fab
.fab$l_fna
= new;
5115 fab
.fab$b_fns
= strlen (new);
5117 status
= SYS$
PARSE (&fab
);
5118 if ((status
& 1) == 0)
5121 vaxc$errno
= status
;
5125 nam
.nam$w_fid
[0] = fid
[0];
5126 nam
.nam$w_fid
[1] = fid
[1];
5127 nam
.nam$w_fid
[2] = fid
[2];
5129 nam
.nam$l_esa
= nam
.nam$l_name
;
5130 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
5132 status
= SYS$
ENTER (&fab
);
5133 if ((status
& 1) == 0)
5136 vaxc$errno
= status
;
5147 printf ("%s not yet implemented\r\n", badfunc
);
5155 /* Arrange to return a range centered on zero. */
5156 return rand () - (1 << 30);
5168 /* Called from init_sys_modes. */
5174 /* If we're not on an HFT we shouldn't do any of this. We determine
5175 if we are on an HFT by trying to get an HFT error code. If this
5176 call fails, we're not on an HFT. */
5178 if (ioctl (0, HFQERROR
, &junk
) < 0)
5180 #else /* not IBMR2AIX */
5181 if (ioctl (0, HFQEIO
, 0) < 0)
5183 #endif /* not IBMR2AIX */
5185 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5186 as the rubout key's ASCII code. Here this is changed. The bug is that
5187 there's no way to determine the old mapping, so in reset_sys_modes
5188 we need to assume that the normal map had been present. Of course, this
5189 code also doesn't help if on a terminal emulator which doesn't understand
5193 struct hfkeymap keymap
;
5195 buf
.hf_bufp
= (char *)&keymap
;
5196 buf
.hf_buflen
= sizeof (keymap
);
5197 keymap
.hf_nkeys
= 2;
5198 keymap
.hfkey
[0].hf_kpos
= 15;
5199 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5201 keymap
.hfkey
[0].hf_keyidh
= '<';
5202 #else /* not IBMR2AIX */
5203 keymap
.hfkey
[0].hf_page
= '<';
5204 #endif /* not IBMR2AIX */
5205 keymap
.hfkey
[0].hf_char
= 127;
5206 keymap
.hfkey
[1].hf_kpos
= 15;
5207 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5209 keymap
.hfkey
[1].hf_keyidh
= '<';
5210 #else /* not IBMR2AIX */
5211 keymap
.hfkey
[1].hf_page
= '<';
5212 #endif /* not IBMR2AIX */
5213 keymap
.hfkey
[1].hf_char
= 127;
5214 hftctl (0, HFSKBD
, &buf
);
5216 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5218 line_ins_del_ok
= char_ins_del_ok
= 0;
5221 /* Reset the rubout key to backspace. */
5227 struct hfkeymap keymap
;
5231 if (ioctl (0, HFQERROR
, &junk
) < 0)
5233 #else /* not IBMR2AIX */
5234 if (ioctl (0, HFQEIO
, 0) < 0)
5236 #endif /* not IBMR2AIX */
5238 buf
.hf_bufp
= (char *)&keymap
;
5239 buf
.hf_buflen
= sizeof (keymap
);
5240 keymap
.hf_nkeys
= 2;
5241 keymap
.hfkey
[0].hf_kpos
= 15;
5242 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5244 keymap
.hfkey
[0].hf_keyidh
= '<';
5245 #else /* not IBMR2AIX */
5246 keymap
.hfkey
[0].hf_page
= '<';
5247 #endif /* not IBMR2AIX */
5248 keymap
.hfkey
[0].hf_char
= 8;
5249 keymap
.hfkey
[1].hf_kpos
= 15;
5250 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5252 keymap
.hfkey
[1].hf_keyidh
= '<';
5253 #else /* not IBMR2AIX */
5254 keymap
.hfkey
[1].hf_page
= '<';
5255 #endif /* not IBMR2AIX */
5256 keymap
.hfkey
[1].hf_char
= 8;
5257 hftctl (0, HFSKBD
, &buf
);
5264 /* These are included on Sunos 4.1 when we do not use shared libraries.
5265 X11 libraries may refer to these functions but (we hope) do not
5266 actually call them. */
5286 #endif /* USE_DL_STUBS */
5295 register int length
;
5299 long max_str
= 65535;
5301 while (length
> max_str
) {
5302 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5307 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5309 while (length
-- > 0)
5311 #endif /* not VMS */
5314 #endif /* no bzero */
5315 #endif /* BSTRING */
5317 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5320 /* Saying `void' requires a declaration, above, where bcopy is used
5321 and that declaration causes pain for systems where bcopy is a macro. */
5322 bcopy (b1
, b2
, length
)
5325 register int length
;
5328 long max_str
= 65535;
5330 while (length
> max_str
) {
5331 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5337 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5339 while (length
-- > 0)
5341 #endif /* not VMS */
5343 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5348 bcmp (b1
, b2
, length
) /* This could be a macro! */
5351 register int length
;
5354 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5355 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5357 return STR$
COMPARE (&src1
, &src2
);
5359 while (length
-- > 0)
5364 #endif /* not VMS */
5366 #endif /* no bcmp */
5367 #endif /* not BSTRING */
5369 #ifndef HAVE_STRSIGNAL
5376 if (0 <= code
&& code
< NSIG
)
5379 signame
= sys_errlist
[code
];
5381 /* Cast to suppress warning if the table has const char *. */
5382 signame
= (char *) sys_siglist
[code
];
5388 #endif /* HAVE_STRSIGNAL */
5390 /* arch-tag: edb43589-4e09-4544-b325-978b5b121dcf
5391 (do not change this comment) */