1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 86,87,88,93,94,95,1999,2000,01,2003
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
33 /* Including stdlib.h isn't necessarily enough to get srandom
34 declared, e.g. without __USE_XOPEN_EXTENDED with glibc 2. */
36 #if 0 /* It turns out that defining _OSF_SOURCE in osf5-0.h gets
37 random prototyped as returning `int'. It looks to me as
38 though the best way to DTRT is to prefer the rand48 functions
39 (per libc.info). -- fx */
40 extern long int random
P_ ((void));
42 #if 0 /* Don't prototype srandom; it takes an unsigned argument on
43 some systems, and an unsigned long on others, like FreeBSD
45 extern void srandom
P_ ((unsigned int));
49 #include "sysselect.h"
51 #include "blockinput.h"
55 /* It is essential to include stdlib.h so that this file picks up
56 the correct definitions of rand, srand, and RAND_MAX.
57 Otherwise random numbers will not work correctly. */
61 /* Nonzero means delete a process right away if it exits (process.c). */
62 static int delete_exited_processes
;
68 #define write sys_write
73 #endif /* not WINDOWSNT */
79 /* Does anyone other than VMS need this? */
81 #define sys_fwrite fwrite
86 #include <sys/types.h>
91 #if !defined (USG) || defined (BSD_PGRPS)
93 #define setpgrp setpgid
97 /* Get SI_SRPC_DOMAIN, if it is available. */
98 #ifdef HAVE_SYS_SYSTEMINFO_H
99 #include <sys/systeminfo.h>
102 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
106 #include <sys/param.h>
110 extern unsigned start
__asm__ ("start");
132 #include <sys/file.h>
140 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
144 #include <sys/file.h>
152 #include <sys/ioctl.h>
158 #ifdef BROKEN_TIOCGWINSZ
163 #if defined (USG) || defined (DGUX)
164 #include <sys/utsname.h>
165 #ifndef MEMORY_IN_STRING_H
168 #if defined (TIOCGWINSZ) || defined (ISC4_0)
170 #include <sys/sioctl.h>
173 #include <sys/stream.h>
174 #include <sys/ptem.h>
176 #endif /* TIOCGWINSZ or ISC4_0 */
177 #endif /* USG or DGUX */
179 extern int quit_char
;
181 #include "keyboard.h"
184 #include "termhooks.h"
185 #include "termchar.h"
186 #include "termopts.h"
187 #include "dispextern.h"
189 #include "cm.h" /* for reset_sys_modes */
193 /* In process.h which conflicts with the local copy. */
195 int _CRTAPI1
_spawnlp (int, const char *, const char *, ...);
196 int _CRTAPI1
_getpid (void);
199 #ifdef NONSYSTEM_DIR_LIBRARY
201 #endif /* NONSYSTEM_DIR_LIBRARY */
203 #include "syssignal.h"
210 #ifndef HAVE_STRUCT_UTIMBUF
211 /* We want to use utime rather than utimes, but we couldn't find the
212 structure declaration. We'll use the traditional one. */
220 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
226 #define LNOFLSH 0100000
229 static int baud_convert
[] =
234 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
235 1800, 2400, 4800, 9600, 19200, 38400
242 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
244 #if defined (HAVE_TERMIOS_H) && defined (GNU_LINUX)
252 void croak
P_ ((char *));
255 void hft_init
P_ ((struct tty_display_info
*));
256 void hft_reset
P_ ((struct tty_display_info
*));
259 /* Temporary used by `sigblock' when defined in terms of signprocmask. */
261 SIGMASKTYPE sigprocmask_set
;
264 /* Discard pending input on all input descriptors. */
270 struct emacs_tty buf
;
277 SYS$
QIOW (0, fileno (CURTTY()->input
), IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
278 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
283 struct tty_display_info
*tty
;
284 for (tty
= tty_list
; tty
; tty
= tty
->next
)
288 ioctl (fileno (tty
->input
), TIOCFLUSH
, &zero
);
291 #else /* not Apollo */
292 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
293 while (dos_keyread () != -1)
295 #else /* not MSDOS */
297 struct tty_display_info
*tty
;
298 for (tty
= tty_list
; tty
; tty
= tty
->next
)
300 if (tty
->input
) /* Is the device suspended? */
302 EMACS_GET_TTY (fileno (tty
->input
), &buf
);
303 EMACS_SET_TTY (fileno (tty
->input
), &buf
, 0);
307 #endif /* not MSDOS */
308 #endif /* not Apollo */
310 #endif /* not WINDOWSNT */
316 /* Arrange for character C to be read as the next input from
318 XXX What if we have multiple ttys?
324 if (! FRAME_TERMCAP_P (SELECTED_FRAME ()))
327 /* Should perhaps error if in batch mode */
329 ioctl (fileno (CURTTY()->input
), TIOCSTI
, &c
);
330 #else /* no TIOCSTI */
331 error ("Cannot stuff terminal input characters in this version of Unix");
332 #endif /* no TIOCSTI */
338 init_baud_rate (int fd
)
344 #ifdef INIT_BAUD_RATE
349 #else /* not DOS_NT */
353 SYS$
QIOW (0, fd
, IO$_SENSEMODE
, &sg
, 0, 0,
354 &sg
.class, 12, 0, 0, 0, 0 );
355 emacs_ospeed
= sg
.xmit_baud
;
362 emacs_ospeed
= cfgetospeed (&sg
);
363 #if defined (USE_GETOBAUD) && defined (getobaud)
364 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
365 if (emacs_ospeed
== 0)
366 emacs_ospeed
= getobaud (sg
.c_cflag
);
368 #else /* neither VMS nor TERMIOS */
376 ioctl (fd
, TCGETA
, &sg
);
378 emacs_ospeed
= sg
.c_cflag
& CBAUD
;
379 #else /* neither VMS nor TERMIOS nor TERMIO */
382 sg
.sg_ospeed
= B9600
;
383 if (ioctl (fd
, TIOCGETP
, &sg
) < 0)
385 emacs_ospeed
= sg
.sg_ospeed
;
386 #endif /* not HAVE_TERMIO */
387 #endif /* not HAVE_TERMIOS */
389 #endif /* not DOS_NT */
390 #endif /* not INIT_BAUD_RATE */
393 baud_rate
= (emacs_ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
394 ? baud_convert
[emacs_ospeed
] : 9600);
402 set_exclusive_use (fd
)
406 ioctl (fd
, FIOCLEX
, 0);
408 /* Ok to do nothing if this feature does not exist */
413 wait_without_blocking ()
416 wait3 (0, WNOHANG
| WUNTRACED
, 0);
418 croak ("wait_without_blocking");
420 synch_process_alive
= 0;
423 #endif /* not subprocesses */
425 int wait_debugging
; /* Set nonzero to make following function work under dbx
426 (at least for bsd). */
429 wait_for_termination_signal ()
432 /* Wait for subprocess with process id `pid' to terminate and
433 make sure it will get eliminated (not remain forever as a zombie) */
436 wait_for_termination (pid
)
445 status
= SYS$
FORCEX (&pid
, 0, 0);
448 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
449 /* Note that kill returns -1 even if the process is just a zombie now.
450 But inevitably a SIGCHLD interrupt should be generated
451 and child_sig will do wait3 and make the process go away. */
452 /* There is some indication that there is a bug involved with
453 termination of subprocesses, perhaps involving a kernel bug too,
454 but no idea what it is. Just as a hunch we signal SIGCHLD to see
455 if that causes the problem to go away or get worse. */
456 sigsetmask (sigmask (SIGCHLD
));
457 if (0 > kill (pid
, 0))
459 sigsetmask (SIGEMPTYMASK
);
460 kill (getpid (), SIGCHLD
);
466 sigpause (SIGEMPTYMASK
);
467 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
468 #if defined (UNIPLUS)
469 if (0 > kill (pid
, 0))
472 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
473 #ifdef POSIX_SIGNALS /* would this work for GNU/Linux as well? */
474 sigblock (sigmask (SIGCHLD
));
476 if (kill (pid
, 0) == -1 && errno
== ESRCH
)
478 sigunblock (sigmask (SIGCHLD
));
482 sigsuspend (&empty_mask
);
483 #else /* not POSIX_SIGNALS */
484 #ifdef HAVE_SYSV_SIGPAUSE
486 if (0 > kill (pid
, 0))
492 #else /* not HAVE_SYSV_SIGPAUSE */
496 #else /* not WINDOWSNT */
497 if (0 > kill (pid
, 0))
499 /* Using sleep instead of pause avoids timing error.
500 If the inferior dies just before the sleep,
501 we lose just one second. */
503 #endif /* not WINDOWSNT */
504 #endif /* not HAVE_SYSV_SIGPAUSE */
505 #endif /* not POSIX_SIGNALS */
506 #endif /* not UNIPLUS */
507 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
509 #else /* not subprocesses */
512 #else /* not __DJGPP__ > 1 */
514 if (kill (pid
, 0) < 0)
520 if (status
== pid
|| status
== -1)
523 #endif /* not __DJGPP__ > 1*/
524 #endif /* not subprocesses */
531 * flush any pending output
532 * (may flush input as well; it does not matter the way we use it)
536 flush_pending_output (channel
)
540 /* If we try this, we get hit with SIGTTIN, because
541 the child's tty belongs to the child's pgrp. */
544 ioctl (channel
, TCFLSH
, 1);
548 /* 3rd arg should be ignored
549 but some 4.2 kernels actually want the address of an int
550 and nonzero means something different. */
551 ioctl (channel
, TIOCFLUSH
, &zero
);
558 /* Set up the terminal at the other end of a pseudo-terminal that
559 we will be controlling an inferior through.
560 It should not echo or do line-editing, since that is done
561 in Emacs. No padding needed for insertion into an Emacs buffer. */
564 child_setup_tty (out
)
570 EMACS_GET_TTY (out
, &s
);
572 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
573 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
574 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
576 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
577 /* No output delays */
579 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
580 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
581 #if 0 /* This causes bugs in (for instance) telnet to certain sites. */
582 s
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
583 #ifdef INLCR /* Just being cautious, since I can't check how
584 widespread INLCR is--rms. */
585 s
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
589 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
592 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
595 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
597 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
598 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
600 /* Said to be unnecessary: */
601 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
602 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
605 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
606 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
607 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
608 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
611 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
615 /* AIX enhanced edit loses NULs, so disable it */
618 s
.main
.c_iflag
&= ~ASCEDIT
;
620 /* Also, PTY overloads NUL and BREAK.
621 don't ignore break, but don't signal either, so it looks like NUL. */
622 s
.main
.c_iflag
&= ~IGNBRK
;
623 s
.main
.c_iflag
&= ~BRKINT
;
624 /* QUIT and INTR work better as signals, so disable character forms */
625 s
.main
.c_cc
[VINTR
] = 0377;
626 #ifdef SIGNALS_VIA_CHARACTERS
627 /* the QUIT and INTR character are used in process_send_signal
628 so set them here to something useful. */
629 if (s
.main
.c_cc
[VQUIT
] == 0377)
630 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
631 if (s
.main
.c_cc
[VINTR
] == 0377)
632 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
633 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
634 /* QUIT and INTR work better as signals, so disable character forms */
635 s
.main
.c_cc
[VQUIT
] = 0377;
636 s
.main
.c_cc
[VINTR
] = 0377;
637 s
.main
.c_lflag
&= ~ISIG
;
638 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
639 s
.main
.c_cc
[VEOL
] = 0377;
640 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
643 #else /* not HAVE_TERMIO */
645 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
647 s
.main
.sg_flags
|= LPASS8
;
648 s
.main
.sg_erase
= 0377;
649 s
.main
.sg_kill
= 0377;
650 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
652 #endif /* not HAVE_TERMIO */
654 EMACS_SET_TTY (out
, &s
, 0);
663 ioctl (out
, FIOASYNC
, &zero
);
666 #endif /* not DOS_NT */
670 #endif /* subprocesses */
672 /* Record a signal code and the handler for it. */
676 SIGTYPE (*handler
) P_ ((int));
679 static void save_signal_handlers
P_ ((struct save_signal
*));
680 static void restore_signal_handlers
P_ ((struct save_signal
*));
682 /* Suspend the Emacs process; give terminal to its superior. */
688 /* "Foster" parentage allows emacs to return to a subprocess that attached
689 to the current emacs as a cheaper than starting a whole new process. This
690 is set up by KEPTEDITOR.COM. */
691 unsigned long parent_id
, foster_parent_id
;
694 fpid_string
= getenv ("EMACS_PARENT_PID");
695 if (fpid_string
!= NULL
)
697 sscanf (fpid_string
, "%x", &foster_parent_id
);
698 if (foster_parent_id
!= 0)
699 parent_id
= foster_parent_id
;
701 parent_id
= getppid ();
704 parent_id
= getppid ();
706 xfree (fpid_string
); /* On VMS, this was malloc'd */
708 if (parent_id
&& parent_id
!= 0xffffffff)
710 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
711 int status
= LIB$
ATTACH (&parent_id
) & 1;
712 signal (SIGINT
, oldsig
);
721 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
722 d_prompt
.a
= "Emacs: "; /* Just a reminder */
723 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
728 #if defined (SIGTSTP) && !defined (MSDOS)
731 int pgrp
= EMACS_GETPGRP (0);
732 EMACS_KILLPG (pgrp
, SIGTSTP
);
735 #else /* No SIGTSTP */
736 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
737 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
738 kill (getpid (), SIGQUIT
);
740 #else /* No SIGTSTP or USG_JOBCTRL */
742 /* On a system where suspending is not implemented,
743 instead fork a subshell and let it talk directly to the terminal
747 #endif /* no USG_JOBCTRL */
748 #endif /* no SIGTSTP */
752 /* Fork a subshell. */
759 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
761 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
764 struct save_signal saved_handlers
[5];
766 unsigned char *str
= 0;
769 saved_handlers
[0].code
= SIGINT
;
770 saved_handlers
[1].code
= SIGQUIT
;
771 saved_handlers
[2].code
= SIGTERM
;
773 saved_handlers
[3].code
= SIGIO
;
774 saved_handlers
[4].code
= 0;
776 saved_handlers
[3].code
= 0;
779 /* Mentioning current_buffer->buffer would mean including buffer.h,
780 which somehow wedges the hp compiler. So instead... */
782 dir
= intern ("default-directory");
783 if (NILP (Fboundp (dir
)))
785 dir
= Fsymbol_value (dir
);
789 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
790 str
= (unsigned char *) alloca (SCHARS (dir
) + 2);
792 bcopy (SDATA (dir
), str
, len
);
793 if (str
[len
- 1] != '/') str
[len
++] = '/';
800 save_signal_handlers (saved_handlers
);
801 synch_process_alive
= 1;
802 #endif /* __DJGPP__ > 1 */
806 error ("Can't spawn subshell");
813 #ifdef DOS_NT /* MW, Aug 1993 */
816 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
819 sh
= (char *) egetenv ("SHELL");
823 /* Use our buffer's default directory for the subshell. */
825 chdir ((char *) str
);
828 close_process_descs (); /* Close Emacs's pipes/ptys */
831 #ifdef SET_EMACS_PRIORITY
833 extern EMACS_INT emacs_priority
;
835 if (emacs_priority
< 0)
836 nice (-emacs_priority
);
840 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
842 char *epwd
= getenv ("PWD");
843 char old_pwd
[MAXPATHLEN
+1+4];
845 /* If PWD is set, pass it with corrected value. */
848 strcpy (old_pwd
, epwd
);
849 if (str
[len
- 1] == '/')
851 setenv ("PWD", str
, 1);
856 putenv (old_pwd
); /* restore previous value */
858 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
860 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
862 #else /* not MSDOS */
864 /* Waits for process completion */
865 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
868 write (1, "Can't execute subshell", 22);
869 #else /* not WINDOWSNT */
871 write (1, "Can't execute subshell", 22);
873 #endif /* not WINDOWSNT */
874 #endif /* not MSDOS */
877 /* Do this now if we did not do it before. */
878 #if !defined (MSDOS) || __DJGPP__ == 1
879 save_signal_handlers (saved_handlers
);
880 synch_process_alive
= 1;
884 wait_for_termination (pid
);
886 restore_signal_handlers (saved_handlers
);
887 synch_process_alive
= 0;
890 #endif /* !MAC_OS8 */
893 save_signal_handlers (saved_handlers
)
894 struct save_signal
*saved_handlers
;
896 while (saved_handlers
->code
)
898 saved_handlers
->handler
899 = (SIGTYPE (*) P_ ((int))) signal (saved_handlers
->code
, SIG_IGN
);
905 restore_signal_handlers (saved_handlers
)
906 struct save_signal
*saved_handlers
;
908 while (saved_handlers
->code
)
910 signal (saved_handlers
->code
, saved_handlers
->handler
);
916 /* If SIGIO is broken, don't do anything. */
933 unrequest_sigio (void)
940 int old_fcntl_flags
[MAXDESC
];
947 old_fcntl_flags
[fd
] = fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
948 fcntl (fd
, F_SETFL
, old_fcntl_flags
[fd
] | FASYNC
);
950 interrupts_deferred
= 0;
958 fcntl (fd
, F_SETFL
, old_fcntl_flags
[fd
]);
962 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
963 /* XXX Uhm, FASYNC is not used anymore here. */
968 /* XXX read_socket_hook is not global anymore. Is blocking SIGIO
971 if (read_socket_hook
)
976 sigunblock (sigmask (SIGWINCH
));
978 sigunblock (sigmask (SIGIO
));
980 interrupts_deferred
= 0;
984 unrequest_sigio (void)
986 /* XXX read_socket_hook is not global anymore. Is blocking SIGIO
989 if (read_socket_hook
)
994 sigblock (sigmask (SIGWINCH
));
996 sigblock (sigmask (SIGIO
));
997 interrupts_deferred
= 1;
1000 #else /* no FASYNC */
1001 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
1008 if (read_socket_hook
)
1011 /* XXX CURTTY() is bogus here. */
1012 ioctl (fileno (CURTTY ()->input
), FIOASYNC
, &on
);
1013 interrupts_deferred
= 0;
1021 if (read_socket_hook
)
1024 /* XXX CURTTY() is bogus here. */
1025 ioctl (fileno (CURTTY ()->input
), FIOASYNC
, &off
);
1026 interrupts_deferred
= 1;
1029 #else /* not FASYNC, not STRIDE */
1033 #include <termios.h>
1041 if (read_socket_hook
)
1045 sigaddset (&st
, SIGIO
);
1046 ioctl (0, FIOASYNC
, &on
); /* XXX This fails for multiple ttys. */
1047 interrupts_deferred
= 0;
1048 sigprocmask (SIG_UNBLOCK
, &st
, (sigset_t
*)0);
1056 if (read_socket_hook
)
1059 ioctl (0, FIOASYNC
, &off
); /* XXX This fails for multiple ttys. */
1060 interrupts_deferred
= 1;
1063 #else /* ! _CX_UX */
1069 if (read_socket_hook
)
1072 croak ("request_sigio");
1078 if (read_socket_hook
)
1081 croak ("unrequest_sigio");
1088 #endif /* F_SETFL */
1091 /* Saving and restoring the process group of Emacs's terminal. */
1095 /* The process group of which Emacs was a member when it initially
1098 If Emacs was in its own process group (i.e. inherited_pgroup ==
1099 getpid ()), then we know we're running under a shell with job
1100 control (Emacs would never be run as part of a pipeline).
1103 If Emacs was not in its own process group, then we know we're
1104 running under a shell (or a caller) that doesn't know how to
1105 separate itself from Emacs (like sh). Emacs must be in its own
1106 process group in order to receive SIGIO correctly. In this
1107 situation, we put ourselves in our own pgroup, forcibly set the
1108 tty's pgroup to our pgroup, and make sure to restore and reinstate
1109 the tty's pgroup just like any other terminal setting. If
1110 inherited_group was not the tty's pgroup, then we'll get a
1111 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1112 it goes foreground in the future, which is what should happen.
1114 This variable is initialized in emacs.c. */
1115 int inherited_pgroup
;
1117 /* Split off the foreground process group to Emacs alone. When we are
1118 in the foreground, but not started in our own process group,
1119 redirect the tty device handle FD to point to our own process
1120 group. We need to be in our own process group to receive SIGIO
1123 narrow_foreground_group (int fd
)
1127 setpgrp (0, inherited_pgroup
);
1128 if (! inherited_pgroup
)
1129 abort (); /* Should not happen. */
1130 if (inherited_pgroup
!= me
)
1131 EMACS_SET_TTY_PGRP (fd
, &me
); /* XXX This only works on the controlling tty. */
1135 /* Set the tty to our original foreground group. */
1137 widen_foreground_group (int fd
)
1139 if (inherited_pgroup
!= getpid ())
1140 EMACS_SET_TTY_PGRP (fd
, &inherited_pgroup
);
1141 setpgrp (0, inherited_pgroup
);
1144 #endif /* BSD_PGRPS */
1146 /* Getting and setting emacs_tty structures. */
1148 /* Set *TC to the parameters associated with the terminal FD.
1149 Return zero if all's well, or -1 if we ran into an error we
1150 couldn't deal with. */
1152 emacs_get_tty (fd
, settings
)
1154 struct emacs_tty
*settings
;
1156 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1158 /* We have those nifty POSIX tcmumbleattr functions. */
1159 bzero (&settings
->main
, sizeof (settings
->main
));
1160 if (tcgetattr (fd
, &settings
->main
) < 0)
1165 /* The SYSV-style interface? */
1166 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1171 /* Vehemently Monstrous System? :-) */
1172 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1173 &settings
->main
.class, 12, 0, 0, 0, 0)
1179 /* I give up - I hope you have the BSD ioctls. */
1180 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1182 #endif /* not DOS_NT */
1187 /* Suivant - Do we have to get struct ltchars data? */
1189 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1193 /* How about a struct tchars and a wordful of lmode bits? */
1195 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1196 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1200 /* We have survived the tempest. */
1205 /* Set the parameters of the tty on FD according to the contents of
1206 *SETTINGS. If FLUSHP is non-zero, we discard input.
1207 Return 0 if all went well, and -1 if anything failed. */
1210 emacs_set_tty (fd
, settings
, flushp
)
1212 struct emacs_tty
*settings
;
1215 /* Set the primary parameters - baud rate, character size, etcetera. */
1218 /* We have those nifty POSIX tcmumbleattr functions.
1219 William J. Smith <wjs@wiis.wang.com> writes:
1220 "POSIX 1003.1 defines tcsetattr to return success if it was
1221 able to perform any of the requested actions, even if some
1222 of the requested actions could not be performed.
1223 We must read settings back to ensure tty setup properly.
1224 AIX requires this to keep tty from hanging occasionally." */
1225 /* This make sure that we don't loop indefinitely in here. */
1226 for (i
= 0 ; i
< 10 ; i
++)
1227 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1238 bzero (&new, sizeof (new));
1239 /* Get the current settings, and see if they're what we asked for. */
1240 tcgetattr (fd
, &new);
1241 /* We cannot use memcmp on the whole structure here because under
1242 * aix386 the termios structure has some reserved field that may
1245 if ( new.c_iflag
== settings
->main
.c_iflag
1246 && new.c_oflag
== settings
->main
.c_oflag
1247 && new.c_cflag
== settings
->main
.c_cflag
1248 && new.c_lflag
== settings
->main
.c_lflag
1249 && memcmp (new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1257 /* The SYSV-style interface? */
1258 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1263 /* Vehemently Monstrous System? :-) */
1264 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1265 &settings
->main
.class, 12, 0, 0, 0, 0)
1271 /* I give up - I hope you have the BSD ioctls. */
1272 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1274 #endif /* not DOS_NT */
1280 /* Suivant - Do we have to get struct ltchars data? */
1282 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1286 /* How about a struct tchars and a wordful of lmode bits? */
1288 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1289 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1293 /* We have survived the tempest. */
1300 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1305 #ifndef F_SETOWN_BUG
1307 int old_fcntl_owner
[MAXDESC
];
1308 #endif /* F_SETOWN */
1309 #endif /* F_SETOWN_BUG */
1311 /* This may also be defined in stdio,
1312 but if so, this does no harm,
1313 and using the same name avoids wasting the other one's space. */
1316 extern char *_sobuf
;
1318 #if defined (USG) || defined (DGUX)
1319 unsigned char _sobuf
[BUFSIZ
+8];
1321 char _sobuf
[BUFSIZ
];
1326 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1329 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1332 /* Initialize the terminal mode on all tty devices that are currently
1336 init_all_sys_modes (void)
1338 struct tty_display_info
*tty
;
1339 for (tty
= tty_list
; tty
; tty
= tty
->next
)
1340 init_sys_modes (tty
);
1343 /* Initialize the terminal mode on the given tty device. */
1346 init_sys_modes (tty_out
)
1347 struct tty_display_info
*tty_out
;
1349 struct emacs_tty tty
;
1352 /* cus-start.el complains if delete-exited-processes is not defined */
1353 #ifndef subprocesses
1354 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes
,
1355 doc
: /* *Non-nil means delete processes immediately when they exit.
1356 nil means don't delete them until `list-processes' is run. */);
1357 delete_exited_processes
= 0;
1359 #endif /* MAC_OS8 */
1363 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1364 extern int (*interrupt_signal
) ();
1368 Vtty_erase_char
= Qnil
;
1373 if (!tty_out
->output
)
1374 return; /* The tty is suspended. */
1378 input_ef
= get_kbd_event_flag ();
1379 /* LIB$GET_EF (&input_ef); */
1380 SYS$
CLREF (input_ef
);
1381 waiting_for_ast
= 0;
1383 timer_ef
= get_timer_event_flag ();
1384 /* LIB$GET_EF (&timer_ef); */
1385 SYS$
CLREF (timer_ef
);
1389 LIB$
GET_EF (&process_ef
);
1390 SYS$
CLREF (process_ef
);
1392 if (input_ef
/ 32 != process_ef
/ 32)
1393 croak ("Input and process event flags in different clusters.");
1395 if (input_ef
/ 32 != timer_ef
/ 32)
1396 croak ("Input and timer event flags in different clusters.");
1398 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1399 ((unsigned) 1 << (process_ef
% 32));
1401 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1402 ((unsigned) 1 << (timer_ef
% 32));
1404 sys_access_reinit ();
1410 /* read_socket_hook is not global anymore. I think doing this
1411 unconditionally will not cause any problems. */
1412 if (! read_socket_hook
&& EQ (Vinitial_window_system
, Qnil
))
1414 narrow_foreground_group (fileno (tty_out
->input
));
1417 if (! tty_out
->old_tty
)
1418 tty_out
->old_tty
= (struct emacs_tty
*) xmalloc (sizeof (struct emacs_tty
));
1420 EMACS_GET_TTY (fileno (tty_out
->input
), tty_out
->old_tty
);
1422 tty
= *tty_out
->old_tty
;
1424 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1425 XSETINT (Vtty_erase_char
, tty
.main
.c_cc
[VERASE
]);
1428 /* This allows meta to be sent on 8th bit. */
1429 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1431 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1432 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1433 #ifdef INLCR /* I'm just being cautious,
1434 since I can't check how widespread INLCR is--rms. */
1435 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1438 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1440 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1441 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1443 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1445 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1446 if (tty_out
->flow_control
)
1448 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1450 tty
.main
.c_iflag
&= ~IXANY
;
1454 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1455 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1457 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1459 if (tty_out
->meta_key
)
1461 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1462 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1465 if (tty_out
->input
== stdin
)
1467 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1468 /* Set up C-g for both SIGQUIT and SIGINT.
1469 We don't know which we will get, but we handle both alike
1470 so which one it really gives us does not matter. */
1471 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1475 /* We normally don't get interrupt or quit signals from tty
1476 devices other than our controlling terminal; therefore,
1477 we must handle C-g as normal input. Unfortunately, this
1478 means that the interrupt and quit feature must be
1479 disabled on secondary ttys, or we would not even see the
1482 Note that even though emacsclient could have special code
1483 to pass SIGINT to Emacs, we should _not_ enable
1484 interrupt/quit keys for emacsclient frames. This means
1485 that we can't break out of loops in C code from a
1486 secondary tty frame, but we can always decide what
1487 display the C-g came from, which is more important from a
1488 usability point of view. (Consider the case when two
1489 people work together using the same Emacs instance.) */
1490 tty
.main
.c_cc
[VINTR
] = CDISABLE
;
1491 tty
.main
.c_cc
[VQUIT
] = CDISABLE
;
1493 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1494 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1496 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1500 #if defined (mips) || defined (HAVE_TCATTR)
1502 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1505 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1506 #endif /* V_DSUSP */
1507 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1508 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1511 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1514 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1515 #endif /* VREPRINT */
1517 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1518 #endif /* VWERASE */
1520 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1521 #endif /* VDISCARD */
1523 if (tty_out
->flow_control
)
1526 tty
.main
.c_cc
[VSTART
] = '\021';
1529 tty
.main
.c_cc
[VSTOP
] = '\023';
1535 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1538 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1541 #endif /* mips or HAVE_TCATTR */
1543 #ifdef SET_LINE_DISCIPLINE
1544 /* Need to explicitly request TERMIODISC line discipline or
1545 Ultrix's termios does not work correctly. */
1546 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1550 /* AIX enhanced edit loses NULs, so disable it. */
1551 tty
.main
.c_line
= 0;
1552 tty
.main
.c_iflag
&= ~ASCEDIT
;
1554 tty
.main
.c_cc
[VSTRT
] = 255;
1555 tty
.main
.c_cc
[VSTOP
] = 255;
1556 tty
.main
.c_cc
[VSUSP
] = 255;
1557 tty
.main
.c_cc
[VDSUSP
] = 255;
1558 #endif /* IBMR2AIX */
1559 if (tty_out
->flow_control
)
1562 tty
.main
.c_cc
[VSTART
] = '\021';
1565 tty
.main
.c_cc
[VSTOP
] = '\023';
1568 /* Also, PTY overloads NUL and BREAK.
1569 don't ignore break, but don't signal either, so it looks like NUL.
1570 This really serves a purpose only if running in an XTERM window
1571 or via TELNET or the like, but does no harm elsewhere. */
1572 tty
.main
.c_iflag
&= ~IGNBRK
;
1573 tty
.main
.c_iflag
&= ~BRKINT
;
1575 #else /* if not HAVE_TERMIO */
1577 tty
.main
.tt_char
|= TT$M_NOECHO
;
1579 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1580 if (tty_out
->flow_control
)
1581 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1583 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1584 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1585 #else /* not VMS (BSD, that is) */
1587 XSETINT (Vtty_erase_char
, tty
.main
.sg_erase
);
1588 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1590 tty
.main
.sg_flags
|= ANYP
;
1591 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1592 #endif /* not DOS_NT */
1593 #endif /* not VMS (BSD, that is) */
1594 #endif /* not HAVE_TERMIO */
1596 /* If going to use CBREAK mode, we must request C-g to interrupt
1597 and turn off start and stop chars, etc. If not going to use
1598 CBREAK mode, do this anyway so as to turn off local flow
1599 control for user coming over network on 4.2; in this case,
1600 only t_stopc and t_startc really matter. */
1603 /* Note: if not using CBREAK mode, it makes no difference how we
1605 tty
.tchars
= new_tchars
;
1606 tty
.tchars
.t_intrc
= quit_char
;
1607 if (tty_out
->flow_control
)
1609 tty
.tchars
.t_startc
= '\021';
1610 tty
.tchars
.t_stopc
= '\023';
1613 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| tty_out
->old_tty
.lmode
;
1615 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1616 anything, and leaving it in breaks the meta key. Go figure. */
1617 tty
.lmode
&= ~LLITOUT
;
1624 #endif /* HAVE_TCHARS */
1625 #endif /* not HAVE_TERMIO */
1628 tty
.ltchars
= new_ltchars
;
1629 #endif /* HAVE_LTCHARS */
1630 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1631 if (!tty_out
->term_initted
)
1632 internal_terminal_init ();
1636 EMACS_SET_TTY (fileno (tty_out
->input
), &tty
, 0);
1638 /* This code added to insure that, if flow-control is not to be used,
1639 we have an unlocked terminal at the start. */
1642 if (!tty_out
->flow_control
) ioctl (fileno (tty_out
->input
), TCXONC
, 1);
1646 if (!tty_out
->flow_control
) ioctl (fileno (tty_out
->input
), TIOCSTART
, 0);
1650 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1652 if (!tty_out
->flow_control
) tcflow (fileno (tty_out
->input
), TCOON
);
1660 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1661 to be only LF. This is the way that is done. */
1664 if (ioctl (1, HFTGETID
, &tty
) != -1)
1665 write (1, "\033[20l", 5);
1671 /* Appears to do nothing when in PASTHRU mode.
1672 SYS$QIOW (0, fileno (tty_out->input), IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1673 interrupt_signal, oob_chars, 0, 0, 0, 0);
1675 queue_kbd_input (0);
1679 #ifndef F_SETOWN_BUG
1680 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1681 if (interrupt_input
)
1683 old_fcntl_owner
[fileno (tty_out
->input
)] =
1684 fcntl (fileno (tty_out
->input
), F_GETOWN
, 0);
1685 fcntl (fileno (tty_out
->input
), F_SETOWN
, getpid ());
1686 init_sigio (fileno (tty_out
->input
));
1688 #endif /* F_GETOWN */
1689 #endif /* F_SETOWN_BUG */
1690 #endif /* F_SETFL */
1693 if (interrupt_input
)
1694 init_sigio (fileno (tty_out
->input
));
1697 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1701 /* This symbol is defined on recent USG systems.
1702 Someone says without this call USG won't really buffer the file
1703 even with a call to setbuf. */
1704 setvbuf (tty_out
->output
, (char *) _sobuf
, _IOFBF
, sizeof _sobuf
);
1706 setbuf (tty_out
->output
, (char *) _sobuf
);
1709 tty_set_terminal_modes (tty_out
->display
);
1711 if (!tty_out
->term_initted
)
1713 Lisp_Object tail
, frame
;
1714 FOR_EACH_FRAME (tail
, frame
)
1716 /* XXX This needs to be revised. */
1717 if (FRAME_TERMCAP_P (XFRAME (frame
))
1718 && FRAME_TTY (XFRAME (frame
)) == tty_out
)
1719 init_frame_faces (XFRAME (frame
));
1723 if (tty_out
->term_initted
&& no_redraw_on_reenter
)
1725 if (display_completed
)
1726 direct_output_forward_char (0);
1730 Lisp_Object tail
, frame
;
1732 FOR_EACH_FRAME (tail
, frame
)
1734 if (FRAME_TERMCAP_P (XFRAME (frame
))
1735 && FRAME_TTY (XFRAME (frame
)) == tty_out
)
1736 FRAME_GARBAGED_P (XFRAME (frame
)) = 1;
1740 tty_out
->term_initted
= 1;
1743 /* Return nonzero if safe to use tabs in output.
1744 At the time this is called, init_sys_modes has not been done yet. */
1747 tabs_safe_p (int fd
)
1749 struct emacs_tty etty
;
1751 EMACS_GET_TTY (fd
, &etty
);
1752 return EMACS_TTY_TABS_OK (&etty
);
1755 /* Get terminal size from system.
1756 Store number of lines into *HEIGHTP and width into *WIDTHP.
1757 We store 0 if there's no valid information. */
1760 get_tty_size (int fd
, int *widthp
, int *heightp
)
1766 struct winsize size
;
1768 if (ioctl (fd
, TIOCGWINSZ
, &size
) == -1)
1769 *widthp
= *heightp
= 0;
1772 *widthp
= size
.ws_col
;
1773 *heightp
= size
.ws_row
;
1779 /* SunOS - style. */
1780 struct ttysize size
;
1782 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1783 *widthp
= *heightp
= 0;
1786 *widthp
= size
.ts_cols
;
1787 *heightp
= size
.ts_lines
;
1793 struct sensemode tty
;
1795 SYS$
QIOW (0, fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1796 &tty
.class, 12, 0, 0, 0, 0);
1797 *widthp
= tty
.scr_wid
;
1798 *heightp
= tty
.scr_len
;
1802 *widthp
= ScreenCols ();
1803 *heightp
= ScreenRows ();
1804 #else /* system doesn't know size */
1808 #endif /* not VMS */
1809 #endif /* not SunOS-style */
1810 #endif /* not BSD-style */
1813 /* Set the logical window size associated with descriptor FD
1814 to HEIGHT and WIDTH. This is used mainly with ptys. */
1817 set_window_size (fd
, height
, width
)
1818 int fd
, height
, width
;
1823 struct winsize size
;
1824 size
.ws_row
= height
;
1825 size
.ws_col
= width
;
1827 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1828 return 0; /* error */
1835 /* SunOS - style. */
1836 struct ttysize size
;
1837 size
.ts_lines
= height
;
1838 size
.ts_cols
= width
;
1840 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1846 #endif /* not SunOS-style */
1847 #endif /* not BSD-style */
1852 /* Prepare all terminal devices for exiting Emacs. */
1855 reset_all_sys_modes (void)
1857 struct tty_display_info
*tty
;
1858 for (tty
= tty_list
; tty
; tty
= tty
->next
)
1859 reset_sys_modes (tty
);
1862 /* Prepare the terminal for closing it; move the cursor to the
1863 bottom of the frame, turn off interrupt-driven I/O, etc. */
1866 reset_sys_modes (tty_out
)
1867 struct tty_display_info
*tty_out
;
1874 if (!tty_out
->term_initted
)
1877 if (!tty_out
->output
)
1878 return; /* The tty is suspended. */
1880 /* Go to and clear the last line of the terminal. */
1882 cmgoto (tty_out
, FrameRows (tty_out
) - 1, 0);
1884 /* Code adapted from tty_clear_end_of_line. */
1885 if (tty_out
->TS_clr_line
)
1887 emacs_tputs (tty_out
, tty_out
->TS_clr_line
, 1, cmputc
);
1890 { /* have to do it the hard way */
1892 turn_off_insert (tty_out
);
1894 for (i
= curX (tty_out
); i
< FrameCols (tty_out
) - 1; i
++)
1896 fputc (' ', tty_out
->output
);
1900 cmgoto (tty_out
, FrameRows (tty_out
) - 1, 0);
1901 fflush (tty_out
->output
);
1903 #if defined (IBMR2AIX) && defined (AIXHFT)
1905 /* HFT devices normally use ^J as a LF/CR. We forced it to
1906 do the LF only. Now, we need to reset it. */
1909 if (ioctl (1, HFTGETID
, &tty
) != -1)
1910 write (1, "\033[20h", 5);
1914 tty_reset_terminal_modes (tty_out
->display
);
1915 fflush (tty_out
->output
);
1918 /* Avoid possible loss of output when changing terminal modes. */
1919 fsync (fileno (tty_out
->output
));
1924 #ifndef F_SETOWN_BUG
1925 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1926 if (interrupt_input
)
1928 reset_sigio (fileno (tty_out
->input
));
1929 fcntl (fileno (tty_out
->input
), F_SETOWN
,
1930 old_fcntl_owner
[fileno (tty_out
->input
)]);
1932 #endif /* F_SETOWN */
1933 #endif /* F_SETOWN_BUG */
1935 fcntl (fileno (tty_out
->input
), F_SETFL
,
1936 fcntl (fileno (tty_out
->input
), F_GETFL
, 0) & ~O_NDELAY
);
1938 #endif /* F_SETFL */
1940 if (interrupt_input
)
1941 reset_sigio (fileno (tty_out
->input
));
1944 if (tty_out
->old_tty
)
1945 while (EMACS_SET_TTY (fileno (tty_out
->input
),
1946 tty_out
->old_tty
, 0) < 0 && errno
== EINTR
)
1949 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1953 #ifdef SET_LINE_DISCIPLINE
1954 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1955 A different old line discipline is therefore not restored, yet.
1956 Restore the old line discipline by hand. */
1957 ioctl (0, TIOCSETD
, &tty_out
->old_tty
.main
.c_line
);
1965 widen_foreground_group (fileno (tty_out
->input
));
1971 /* Set up the proper status flags for use of a pty. */
1977 /* I'm told that TOICREMOTE does not mean control chars
1978 "can't be sent" but rather that they don't have
1979 input-editing or signaling effects.
1980 That should be good, because we have other ways
1981 to do those things in Emacs.
1982 However, telnet mode seems not to work on 4.2.
1983 So TIOCREMOTE is turned off now. */
1985 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1986 will hang. In particular, the "timeout" feature (which
1987 causes a read to return if there is no data available)
1988 does this. Also it is known that telnet mode will hang
1989 in such a way that Emacs must be stopped (perhaps this
1990 is the same problem).
1992 If TIOCREMOTE is turned off, then there is a bug in
1993 hp-ux which sometimes loses data. Apparently the
1994 code which blocks the master process when the internal
1995 buffer fills up does not work. Other than this,
1996 though, everything else seems to work fine.
1998 Since the latter lossage is more benign, we may as well
1999 lose that way. -- cph */
2001 #if defined(SYSV_PTYS) || defined(UNIX98_PTYS)
2004 ioctl (fd
, FIONBIO
, &on
);
2009 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
2010 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
2011 /* cause EMACS not to die when it should, i.e., when its own controlling */
2012 /* tty goes away. I've complained to the AIX developers, and they may */
2013 /* change this behavior, but I'm not going to hold my breath. */
2014 signal (SIGHUP
, SIG_IGN
);
2017 #endif /* HAVE_PTYS */
2021 /* Assigning an input channel is done at the start of Emacs execution.
2022 This is called each time Emacs is resumed, also, but does nothing
2023 because input_chain is no longer zero. */
2030 if (fileno (CURTTY ()->input
)) == 0)
2032 status
= SYS$
ASSIGN (&input_dsc
, &fileno (CURTTY ()->input
)), 0, 0);
2038 /* Deassigning the input channel is done before exiting. */
2043 return SYS$
DASSGN (fileno (CURTTY ()->input
)));
2048 /* Request reading one character into the keyboard buffer.
2049 This is done as soon as the buffer becomes empty. */
2055 extern kbd_input_ast ();
2057 waiting_for_ast
= 0;
2059 status
= SYS$
QIO (0, fileno (CURTTY()->input
), IO$_READVBLK
,
2060 &input_iosb
, kbd_input_ast
, 1,
2061 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
2066 /* Ast routine that is called when keyboard input comes in
2067 in accord with the SYS$QIO above. */
2072 register int c
= -1;
2073 int old_errno
= errno
;
2074 extern EMACS_TIME
*input_available_clear_time
;
2076 if (waiting_for_ast
)
2077 SYS$
SETEF (input_ef
);
2078 waiting_for_ast
= 0;
2081 if (input_count
== 25)
2083 printf ("Ast # %d,", input_count
);
2084 printf (" iosb = %x, %x, %x, %x",
2085 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
2088 if (input_iosb
.offset
)
2092 printf (", char = 0%o", c
);
2104 struct input_event e
;
2107 e
.kind
= ASCII_KEYSTROKE_EVENT
;
2108 XSETINT (e
.code
, c
);
2109 e
.frame_or_window
= selected_frame
;
2110 kbd_buffer_store_event (&e
);
2112 if (input_available_clear_time
)
2113 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
2117 /* Wait until there is something in kbd_buffer. */
2120 wait_for_kbd_input ()
2122 extern int have_process_input
, process_exited
;
2124 /* If already something, avoid doing system calls. */
2125 if (detect_input_pending ())
2129 /* Clear a flag, and tell ast routine above to set it. */
2130 SYS$
CLREF (input_ef
);
2131 waiting_for_ast
= 1;
2132 /* Check for timing error: ast happened while we were doing that. */
2133 if (!detect_input_pending ())
2135 /* No timing error: wait for flag to be set. */
2136 set_waiting_for_input (0);
2137 SYS$
WFLOR (input_ef
, input_eflist
);
2138 clear_waiting_for_input ();
2139 if (!detect_input_pending ())
2140 /* Check for subprocess input availability */
2142 int dsp
= have_process_input
|| process_exited
;
2144 SYS$
CLREF (process_ef
);
2145 if (have_process_input
)
2146 process_command_input ();
2151 update_mode_lines
++;
2152 prepare_menu_bars ();
2153 redisplay_preserve_echo_area (18);
2157 waiting_for_ast
= 0;
2160 /* Get rid of any pending QIO, when we are about to suspend
2161 or when we want to throw away pending input.
2162 We wait for a positive sign that the AST routine has run
2163 and therefore there is no I/O request queued when we return.
2164 SYS$SETAST is used to avoid a timing error. */
2170 printf ("At end_kbd_input.\n");
2174 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2176 SYS$
CANCEL (fileno (CURTTY()->input
));
2181 /* Clear a flag, and tell ast routine above to set it. */
2182 SYS$
CLREF (input_ef
);
2183 waiting_for_ast
= 1;
2185 SYS$
CANCEL (fileno (CURTTY()->input
));
2187 SYS$
WAITFR (input_ef
);
2188 waiting_for_ast
= 0;
2191 /* Wait for either input available or time interval expiry. */
2194 input_wait_timeout (timeval
)
2195 int timeval
; /* Time to wait, in seconds */
2198 static int zero
= 0;
2199 static int large
= -10000000;
2201 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2203 /* If already something, avoid doing system calls. */
2204 if (detect_input_pending ())
2208 /* Clear a flag, and tell ast routine above to set it. */
2209 SYS$
CLREF (input_ef
);
2210 waiting_for_ast
= 1;
2211 /* Check for timing error: ast happened while we were doing that. */
2212 if (!detect_input_pending ())
2214 /* No timing error: wait for flag to be set. */
2216 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2217 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
2219 waiting_for_ast
= 0;
2222 /* The standard `sleep' routine works some other way
2223 and it stops working if you have ever quit out of it.
2224 This one continues to work. */
2230 static int zero
= 0;
2231 static int large
= -10000000;
2233 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2236 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2237 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2256 croak ("request sigio");
2262 croak ("unrequest sigio");
2267 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2272 #ifndef SYSTEM_MALLOC
2279 /* Some systems that cannot dump also cannot implement these. */
2282 * Return the address of the start of the text segment prior to
2283 * doing an unexec. After unexec the return value is undefined.
2284 * See crt0.c for further explanation and _start.
2288 #if !(defined (__NetBSD__) && defined (__ELF__))
2289 #ifndef HAVE_TEXT_START
2294 return ((char *) TEXT_START
);
2298 return ((char *) csrt
);
2299 #else /* not GOULD */
2300 extern int _start ();
2301 return ((char *) _start
);
2303 #endif /* TEXT_START */
2305 #endif /* not HAVE_TEXT_START */
2309 * Return the address of the start of the data segment prior to
2310 * doing an unexec. After unexec the return value is undefined.
2311 * See crt0.c for further information and definition of data_start.
2313 * Apparently, on BSD systems this is etext at startup. On
2314 * USG systems (swapping) this is highly mmu dependent and
2315 * is also dependent on whether or not the program is running
2316 * with shared text. Generally there is a (possibly large)
2317 * gap between end of text and start of data with shared text.
2319 * On Uniplus+ systems with shared text, data starts at a
2320 * fixed address. Each port (from a given oem) is generally
2321 * different, and the specific value of the start of data can
2322 * be obtained via the UniPlus+ specific "uvar" system call,
2323 * however the method outlined in crt0.c seems to be more portable.
2325 * Probably what will have to happen when a USG unexec is available,
2326 * at least on UniPlus, is temacs will have to be made unshared so
2327 * that text and data are contiguous. Then once loadup is complete,
2328 * unexec will produce a shared executable where the data can be
2329 * at the normal shared text boundary and the startofdata variable
2330 * will be patched by unexec to the correct value.
2334 #ifndef start_of_data
2339 return ((char *) DATA_START
);
2341 #ifdef ORDINARY_LINK
2343 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2344 * data_start isn't defined. We take the address of environ, which
2345 * is known to live at or near the start of the system crt0.c, and
2346 * we don't sweat the handful of bytes that might lose.
2348 extern char **environ
;
2350 return ((char *) &environ
);
2352 extern int data_start
;
2353 return ((char *) &data_start
);
2354 #endif /* ORDINARY_LINK */
2355 #endif /* DATA_START */
2357 #endif /* start_of_data */
2358 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2360 /* init_system_name sets up the string for the Lisp function
2361 system-name to return. */
2367 extern Lisp_Object Vsystem_name
;
2372 #include <sys/socket.h>
2374 #endif /* HAVE_SOCKETS */
2375 #endif /* not VMS */
2376 #endif /* not BSD4_1 */
2379 #ifndef HAVE_H_ERRNO
2382 #endif /* TRY_AGAIN */
2388 Vsystem_name
= build_string (sysname
);
2392 if ((sp
= egetenv ("SYS$NODE")) == 0)
2393 Vsystem_name
= build_string ("vax-vms");
2394 else if ((end
= index (sp
, ':')) == 0)
2395 Vsystem_name
= build_string (sp
);
2397 Vsystem_name
= make_string (sp
, end
- sp
);
2399 #ifndef HAVE_GETHOSTNAME
2402 Vsystem_name
= build_string (uts
.nodename
);
2403 #else /* HAVE_GETHOSTNAME */
2404 unsigned int hostname_size
= 256;
2405 char *hostname
= (char *) alloca (hostname_size
);
2407 /* Try to get the host name; if the buffer is too short, try
2408 again. Apparently, the only indication gethostname gives of
2409 whether the buffer was large enough is the presence or absence
2410 of a '\0' in the string. Eech. */
2413 gethostname (hostname
, hostname_size
- 1);
2414 hostname
[hostname_size
- 1] = '\0';
2416 /* Was the buffer large enough for the '\0'? */
2417 if (strlen (hostname
) < hostname_size
- 1)
2420 hostname_size
<<= 1;
2421 hostname
= (char *) alloca (hostname_size
);
2424 /* Turn the hostname into the official, fully-qualified hostname.
2425 Don't do this if we're going to dump; this can confuse system
2426 libraries on some machines and make the dumped emacs core dump. */
2429 #endif /* not CANNOT_DUMP */
2430 if (! index (hostname
, '.'))
2434 for (count
= 0;; count
++)
2439 hp
= gethostbyname (hostname
);
2441 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2446 Fsleep_for (make_number (1), Qnil
);
2450 char *fqdn
= (char *) hp
->h_name
;
2455 if (!index (fqdn
, '.'))
2457 /* We still don't have a fully qualified domain name.
2458 Try to find one in the list of alternate names */
2459 char **alias
= hp
->h_aliases
;
2460 while (*alias
&& !index (*alias
, '.'))
2467 /* Convert the host name to lower case. */
2468 /* Using ctype.h here would introduce a possible locale
2469 dependence that is probably wrong for hostnames. */
2473 if (*p
>= 'A' && *p
<= 'Z')
2480 #endif /* HAVE_SOCKETS */
2481 /* We used to try using getdomainname here,
2482 but NIIBE Yutaka <gniibe@etl.go.jp> says that
2483 getdomainname gets the NIS/YP domain which often is not the same
2484 as in Internet domain name. */
2485 #if 0 /* Turned off because sysinfo is not really likely to return the
2486 correct Internet domain. */
2487 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2488 if (! index (hostname
, '.'))
2490 /* The hostname is not fully qualified. Append the domain name. */
2492 int hostlen
= strlen (hostname
);
2493 int domain_size
= 256;
2497 char *domain
= (char *) alloca (domain_size
+ 1);
2498 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2499 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2500 if (sys_domain_size
<= 0)
2502 if (domain_size
< sys_domain_size
)
2504 domain_size
= sys_domain_size
;
2507 strcpy (fqdn
, hostname
);
2508 if (domain
[0] == '.')
2509 strcpy (fqdn
+ hostlen
, domain
);
2510 else if (domain
[0] != 0)
2512 fqdn
[hostlen
] = '.';
2513 strcpy (fqdn
+ hostlen
+ 1, domain
);
2519 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2521 Vsystem_name
= build_string (hostname
);
2522 #endif /* HAVE_GETHOSTNAME */
2527 for (p
= SDATA (Vsystem_name
); *p
; p
++)
2528 if (*p
== ' ' || *p
== '\t')
2535 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2537 #include "sysselect.h"
2540 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2541 /* Cause explanatory error message at compile time,
2542 since the select emulation is not good enough for X. */
2543 int *x
= &x_windows_lose_if_no_select_system_call
;
2546 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2547 * Only checks read descriptors.
2549 /* How long to wait between checking fds in select */
2550 #define SELECT_PAUSE 1
2553 /* For longjmp'ing back to read_input_waiting. */
2555 jmp_buf read_alarm_throw
;
2557 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2558 The read_socket_hook function sets this to 1 while it is waiting. */
2560 int read_alarm_should_throw
;
2568 #else /* not BSD4_1 */
2569 signal (SIGALRM
, SIG_IGN
);
2570 #endif /* not BSD4_1 */
2571 if (read_alarm_should_throw
)
2572 longjmp (read_alarm_throw
, 1);
2576 /* Only rfds are checked. */
2578 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2580 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2581 EMACS_TIME
*timeout
;
2583 /* XXX This needs to be updated for multi-tty support. Is there
2584 anybody who needs to emulate select these days? */
2589 extern int proc_buffered_char
[];
2590 #ifndef subprocesses
2591 int process_tick
= 0, update_tick
= 0;
2593 extern int process_tick
, update_tick
;
2597 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2598 /* If we're using X, then the native select will work; we only need the
2599 emulation for non-X usage. */
2600 if (!NILP (Vinitial_window_system
))
2601 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2603 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2604 local_timeout
= &timeoutval
;
2616 /* If we are looking only for the terminal, with no timeout,
2617 just read it and wait -- that's more efficient. */
2618 if (*local_timeout
== 100000 && process_tick
== update_tick
2619 && FD_ISSET (0, &orfds
))
2622 for (fd
= 1; fd
< nfds
; ++fd
)
2623 if (FD_ISSET (fd
, &orfds
))
2625 if (! detect_input_pending ())
2626 read_input_waiting ();
2632 /* Once a second, till the timer expires, check all the flagged read
2633 * descriptors to see if any input is available. If there is some then
2634 * set the corresponding bit in the return copy of rfds.
2638 register int to_check
, fd
;
2642 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2644 if (FD_ISSET (fd
, &orfds
))
2646 int avail
= 0, status
= 0;
2649 avail
= detect_input_pending (); /* Special keyboard handler */
2653 status
= ioctl (fd
, FIONREAD
, &avail
);
2654 #else /* no FIONREAD */
2655 /* Hoping it will return -1 if nothing available
2656 or 0 if all 0 chars requested are read. */
2657 if (proc_buffered_char
[fd
] >= 0)
2661 avail
= read (fd
, &buf
, 1);
2663 proc_buffered_char
[fd
] = buf
;
2665 #endif /* no FIONREAD */
2667 if (status
>= 0 && avail
> 0)
2675 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2678 turn_on_atimers (0);
2679 signal (SIGALRM
, select_alarm
);
2681 alarm (SELECT_PAUSE
);
2683 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2684 while (select_alarmed
== 0 && *local_timeout
!= 0
2685 && process_tick
== update_tick
)
2687 /* If we are interested in terminal input,
2688 wait by reading the terminal.
2689 That makes instant wakeup for terminal input at least. */
2690 if (FD_ISSET (0, &orfds
))
2692 read_input_waiting ();
2693 if (detect_input_pending ())
2699 (*local_timeout
) -= SELECT_PAUSE
;
2701 /* Reset the old alarm if there was one. */
2702 turn_on_atimers (1);
2704 if (*local_timeout
== 0) /* Stop on timer being cleared */
2709 #endif not WINDOWSNT
2711 /* Read keyboard input into the standard buffer,
2712 waiting for at least one character. */
2714 /* Make all keyboard buffers much bigger when using a window system. */
2715 #ifdef HAVE_WINDOW_SYSTEM
2716 #define BUFFER_SIZE_FACTOR 16
2718 #define BUFFER_SIZE_FACTOR 1
2722 read_input_waiting ()
2724 /* XXX This needs to be updated for multi-tty support. Is there
2725 anybody who needs to emulate select these days? */
2727 extern int quit_char
;
2729 if (read_socket_hook
)
2731 struct input_event buf
[256];
2732 for (i
= 0; i
< 256; i
++)
2733 EVENT_INIT (buf
[i
]);
2735 read_alarm_should_throw
= 0;
2736 if (! setjmp (read_alarm_throw
))
2737 nread
= (*read_socket_hook
) (0, buf
, 256, 1);
2741 /* Scan the chars for C-g and store them in kbd_buffer. */
2742 for (i
= 0; i
< nread
; i
++)
2744 kbd_buffer_store_event (&buf
[i
]);
2745 /* Don't look at input that follows a C-g too closely.
2746 This reduces lossage due to autorepeat on C-g. */
2747 if (buf
[i
].kind
== ASCII_KEYSTROKE_EVENT
2748 && buf
[i
].code
== quit_char
)
2754 struct input_event e
;
2756 nread
= read (fileno (stdin
), buf
, 1);
2759 /* Scan the chars for C-g and store them in kbd_buffer. */
2760 e
.kind
= ASCII_KEYSTROKE_EVENT
;
2761 e
.frame_or_window
= selected_frame
;
2763 for (i
= 0; i
< nread
; i
++)
2765 /* Convert chars > 0177 to meta events if desired.
2766 We do this under the same conditions that read_avail_input does. */
2767 if (read_socket_hook
== 0)
2769 /* If the user says she has a meta key, then believe her. */
2770 if (meta_key
== 1 && (buf
[i
] & 0x80))
2771 e
.modifiers
= meta_modifier
;
2776 XSETINT (e
.code
, buf
[i
]);
2777 kbd_buffer_store_event (&e
);
2778 /* Don't look at input that follows a C-g too closely.
2779 This reduces lossage due to autorepeat on C-g. */
2780 if (buf
[i
] == quit_char
)
2786 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2787 #define select sys_select
2790 #endif /* not HAVE_SELECT */
2791 #endif /* not VMS */
2792 #endif /* not MSDOS */
2801 lmode
= LINTRUP
| lmode
;
2802 ioctl (fd
, TIOCLSET
, &lmode
);
2811 lmode
= ~LINTRUP
& lmode
;
2812 ioctl (fd
, TIOCLSET
, &lmode
);
2820 interrupts_deferred
= 0;
2828 interrupts_deferred
= 1;
2831 /* still inside #ifdef BSD4_1 */
2834 int sigheld
; /* Mask of held signals */
2840 sigheld
|= sigbit (signum
);
2848 sigheld
|= sigbit (signum
);
2855 sigheld
&= ~sigbit (signum
);
2860 sigfree () /* Free all held signals */
2863 for (i
= 0; i
< NSIG
; i
++)
2864 if (sigheld
& sigbit (i
))
2872 return 1 << (i
- 1);
2874 #endif /* subprocesses */
2877 /* POSIX signals support - DJB */
2878 /* Anyone with POSIX signals should have ANSI C declarations */
2880 #ifdef POSIX_SIGNALS
2882 sigset_t empty_mask
, full_mask
;
2885 sys_signal (int signal_number
, signal_handler_t action
)
2887 struct sigaction new_action
, old_action
;
2888 sigemptyset (&new_action
.sa_mask
);
2889 new_action
.sa_handler
= action
;
2890 #if defined (SA_RESTART) && ! defined (BROKEN_SA_RESTART)
2891 /* Emacs mostly works better with restartable system services. If this
2892 flag exists, we probably want to turn it on here.
2893 However, on some systems this resets the timeout of `select'
2894 which means that `select' never finishes if it keeps getting signals.
2895 BROKEN_SA_RESTART is defined on those systems. */
2896 new_action
.sa_flags
= SA_RESTART
;
2898 new_action
.sa_flags
= 0;
2900 sigaction (signal_number
, &new_action
, &old_action
);
2901 return (old_action
.sa_handler
);
2905 /* If we're compiling with GCC, we don't need this function, since it
2906 can be written as a macro. */
2908 sys_sigmask (int sig
)
2911 sigemptyset (&mask
);
2912 sigaddset (&mask
, sig
);
2917 /* I'd like to have these guys return pointers to the mask storage in here,
2918 but there'd be trouble if the code was saving multiple masks. I'll be
2919 safe and pass the structure. It normally won't be more than 2 bytes
2923 sys_sigblock (sigset_t new_mask
)
2926 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2931 sys_sigunblock (sigset_t new_mask
)
2934 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2939 sys_sigsetmask (sigset_t new_mask
)
2942 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2946 #endif /* POSIX_SIGNALS */
2948 #if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
2949 static char *my_sys_siglist
[NSIG
];
2953 # define sys_siglist my_sys_siglist
2959 #ifdef POSIX_SIGNALS
2960 sigemptyset (&empty_mask
);
2961 sigfillset (&full_mask
);
2964 #if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
2968 sys_siglist
[SIGABRT
] = "Aborted";
2971 sys_siglist
[SIGAIO
] = "LAN I/O interrupt";
2974 sys_siglist
[SIGALRM
] = "Alarm clock";
2977 sys_siglist
[SIGBUS
] = "Bus error";
2980 sys_siglist
[SIGCLD
] = "Child status changed";
2983 sys_siglist
[SIGCHLD
] = "Child status changed";
2986 sys_siglist
[SIGCONT
] = "Continued";
2989 sys_siglist
[SIGDANGER
] = "Swap space dangerously low";
2992 sys_siglist
[SIGDGNOTIFY
] = "Notification message in queue";
2995 sys_siglist
[SIGEMT
] = "Emulation trap";
2998 sys_siglist
[SIGFPE
] = "Arithmetic exception";
3001 sys_siglist
[SIGFREEZE
] = "SIGFREEZE";
3004 sys_siglist
[SIGGRANT
] = "Monitor mode granted";
3007 sys_siglist
[SIGHUP
] = "Hangup";
3010 sys_siglist
[SIGILL
] = "Illegal instruction";
3013 sys_siglist
[SIGINT
] = "Interrupt";
3016 sys_siglist
[SIGIO
] = "I/O possible";
3019 sys_siglist
[SIGIOINT
] = "I/O intervention required";
3022 sys_siglist
[SIGIOT
] = "IOT trap";
3025 sys_siglist
[SIGKILL
] = "Killed";
3028 sys_siglist
[SIGLOST
] = "Resource lost";
3031 sys_siglist
[SIGLWP
] = "SIGLWP";
3034 sys_siglist
[SIGMSG
] = "Monitor mode data available";
3037 sys_siglist
[SIGWIND
] = "SIGPHONE";
3040 sys_siglist
[SIGPIPE
] = "Broken pipe";
3043 sys_siglist
[SIGPOLL
] = "Pollable event occurred";
3046 sys_siglist
[SIGPROF
] = "Profiling timer expired";
3049 sys_siglist
[SIGPTY
] = "PTY I/O interrupt";
3052 sys_siglist
[SIGPWR
] = "Power-fail restart";
3055 sys_siglist
[SIGQUIT
] = "Quit";
3058 sys_siglist
[SIGRETRACT
] = "Need to relinguish monitor mode";
3061 sys_siglist
[SIGSAK
] = "Secure attention";
3064 sys_siglist
[SIGSEGV
] = "Segmentation violation";
3067 sys_siglist
[SIGSOUND
] = "Sound completed";
3070 sys_siglist
[SIGSTOP
] = "Stopped (signal)";
3073 sys_siglist
[SIGSTP
] = "Stopped (user)";
3076 sys_siglist
[SIGSYS
] = "Bad argument to system call";
3079 sys_siglist
[SIGTERM
] = "Terminated";
3082 sys_siglist
[SIGTHAW
] = "SIGTHAW";
3085 sys_siglist
[SIGTRAP
] = "Trace/breakpoint trap";
3088 sys_siglist
[SIGTSTP
] = "Stopped (user)";
3091 sys_siglist
[SIGTTIN
] = "Stopped (tty input)";
3094 sys_siglist
[SIGTTOU
] = "Stopped (tty output)";
3097 sys_siglist
[SIGURG
] = "Urgent I/O condition";
3100 sys_siglist
[SIGUSR1
] = "User defined signal 1";
3103 sys_siglist
[SIGUSR2
] = "User defined signal 2";
3106 sys_siglist
[SIGVTALRM
] = "Virtual timer expired";
3109 sys_siglist
[SIGWAITING
] = "Process's LWPs are blocked";
3112 sys_siglist
[SIGWINCH
] = "Window size changed";
3115 sys_siglist
[SIGWIND
] = "SIGWIND";
3118 sys_siglist
[SIGXCPU
] = "CPU time limit exceeded";
3121 sys_siglist
[SIGXFSZ
] = "File size limit exceeded";
3124 #endif /* !defined HAVE_STRSIGNAL && !defined HAVE_DECL_SYS_SIGLIST */
3133 /* Figure out how many bits the system's random number generator uses.
3134 `random' and `lrand48' are assumed to return 31 usable bits.
3135 BSD `rand' returns a 31 bit value but the low order bits are unusable;
3136 so we'll shift it and treat it like the 15-bit USG `rand'. */
3140 # define RAND_BITS 31
3141 # else /* !HAVE_RANDOM */
3142 # ifdef HAVE_LRAND48
3143 # define RAND_BITS 31
3144 # define random lrand48
3145 # else /* !HAVE_LRAND48 */
3146 # define RAND_BITS 15
3147 # if RAND_MAX == 32767
3148 # define random rand
3149 # else /* RAND_MAX != 32767 */
3150 # if RAND_MAX == 2147483647
3151 # define random() (rand () >> 16)
3152 # else /* RAND_MAX != 2147483647 */
3154 # define random rand
3156 # define random() (rand () >> 16)
3158 # endif /* RAND_MAX != 2147483647 */
3159 # endif /* RAND_MAX != 32767 */
3160 # endif /* !HAVE_LRAND48 */
3161 # endif /* !HAVE_RANDOM */
3162 #endif /* !RAND_BITS */
3169 srandom ((unsigned int)arg
);
3171 # ifdef HAVE_LRAND48
3174 srand ((unsigned int)arg
);
3180 * Build a full Emacs-sized word out of whatever we've got.
3181 * This suffices even for a 64-bit architecture with a 15-bit rand.
3186 long val
= random ();
3187 #if VALBITS > RAND_BITS
3188 val
= (val
<< RAND_BITS
) ^ random ();
3189 #if VALBITS > 2*RAND_BITS
3190 val
= (val
<< RAND_BITS
) ^ random ();
3191 #if VALBITS > 3*RAND_BITS
3192 val
= (val
<< RAND_BITS
) ^ random ();
3193 #if VALBITS > 4*RAND_BITS
3194 val
= (val
<< RAND_BITS
) ^ random ();
3195 #endif /* need at least 5 */
3196 #endif /* need at least 4 */
3197 #endif /* need at least 3 */
3198 #endif /* need at least 2 */
3199 return val
& ((1L << VALBITS
) - 1);
3202 #ifdef WRONG_NAME_INSQUE
3215 /* If any place else asks for the TERM variable,
3216 allow it to be overridden with the EMACS_TERM variable
3217 before attempting to translate the logical name TERM. As a last
3218 resort, ask for VAX C's special idea of the TERM variable. */
3225 static char buf
[256];
3226 static struct dsc$descriptor_s equiv
3227 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
3228 static struct dsc$descriptor_s d_name
3229 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
3232 if (!strcmp (name
, "TERM"))
3234 val
= (char *) getenv ("EMACS_TERM");
3239 d_name
.dsc$w_length
= strlen (name
);
3240 d_name
.dsc$a_pointer
= name
;
3241 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
3243 char *str
= (char *) xmalloc (eqlen
+ 1);
3244 bcopy (buf
, str
, eqlen
);
3246 /* This is a storage leak, but a pain to fix. With luck,
3247 no one will ever notice. */
3250 return (char *) getenv (name
);
3255 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
3256 to force a call on the debugger from within the image. */
3260 reset_all_sys_modes ();
3261 LIB$
SIGNAL (SS$_DEBUG
);
3267 #ifdef LINK_CRTL_SHARE
3268 #ifdef SHARABLE_LIB_BUG
3269 /* Variables declared noshare and initialized in sharable libraries
3270 cannot be shared. The VMS linker incorrectly forces you to use a private
3271 version which is uninitialized... If not for this "feature", we
3272 could use the C library definition of sys_nerr and sys_errlist. */
3274 char *sys_errlist
[] =
3278 "no such file or directory",
3280 "interrupted system call",
3282 "no such device or address",
3283 "argument list too long",
3284 "exec format error",
3287 "no more processes",
3288 "not enough memory",
3289 "permission denied",
3291 "block device required",
3292 "mount devices busy",
3294 "cross-device link",
3299 "file table overflow",
3300 "too many open files",
3304 "no space left on device",
3306 "read-only file system",
3312 "vax/vms specific error code nontranslatable error"
3314 #endif /* SHARABLE_LIB_BUG */
3315 #endif /* LINK_CRTL_SHARE */
3318 #ifndef HAVE_STRERROR
3324 extern char *sys_errlist
[];
3325 extern int sys_nerr
;
3327 if (errnum
>= 0 && errnum
< sys_nerr
)
3328 return sys_errlist
[errnum
];
3329 return (char *) "Unknown error";
3331 #endif /* not WINDOWSNT */
3332 #endif /* ! HAVE_STRERROR */
3335 emacs_open (path
, oflag
, mode
)
3339 register int rtnval
;
3342 if (oflag
& O_CREAT
)
3343 return creat (path
, mode
);
3346 while ((rtnval
= open (path
, oflag
, mode
)) == -1
3347 && (errno
== EINTR
));
3356 register int rtnval
;
3358 while ((rtnval
= close (fd
)) == -1
3359 && (errno
== EINTR
))
3362 /* If close is interrupted SunOS 4.1 may or may not have closed the
3363 file descriptor. If it did the second close will fail with
3364 errno = EBADF. That means we have succeeded. */
3365 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3372 emacs_read (fildes
, buf
, nbyte
)
3377 register int rtnval
;
3379 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3380 && (errno
== EINTR
));
3385 emacs_write (fildes
, buf
, nbyte
)
3390 register int rtnval
, bytes_written
;
3396 rtnval
= write (fildes
, buf
, nbyte
);
3403 return (bytes_written
? bytes_written
: -1);
3408 bytes_written
+= rtnval
;
3410 return (bytes_written
);
3415 * All of the following are for USG.
3417 * On USG systems the system calls are INTERRUPTIBLE by signals
3418 * that the user program has elected to catch. Thus the system call
3419 * must be retried in these cases. To handle this without massive
3420 * changes in the source code, we remap the standard system call names
3421 * to names for our own functions in sysdep.c that do the system call
3422 * with retries. Actually, for portability reasons, it is good
3423 * programming practice, as this example shows, to limit all actual
3424 * system calls to a single occurrence in the source. Sure, this
3425 * adds an extra level of function call overhead but it is almost
3426 * always negligible. Fred Fish, Unisoft Systems Inc.
3430 * Warning, this function may not duplicate 4.2 action properly
3431 * under error conditions.
3435 /* In 4.1, param.h fails to define this. */
3436 #define MAXPATHLEN 1024
3445 char *npath
, *spath
;
3446 extern char *getcwd ();
3448 BLOCK_INPUT
; /* getcwd uses malloc */
3449 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3455 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3456 up to first slash. Should be harmless on other systems. */
3457 while (*npath
&& *npath
!= '/')
3459 strcpy (pathname
, npath
);
3460 free (spath
); /* getcwd uses malloc */
3465 #endif /* HAVE_GETWD */
3468 * Emulate rename using unlink/link. Note that this is
3469 * only partially correct. Also, doesn't enforce restriction
3470 * that files be of same type (regular->regular, dir->dir, etc).
3479 if (access (from
, 0) == 0)
3482 if (link (from
, to
) == 0)
3483 if (unlink (from
) == 0)
3495 /* HPUX curses library references perror, but as far as we know
3496 it won't be called. Anyway this definition will do for now. */
3502 #endif /* not HAVE_PERROR */
3508 * Emulate BSD dup2. First close newd if it already exists.
3509 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3510 * until we are, then close the unsuccessful ones.
3517 register int fd
, ret
;
3522 return fcntl (oldd
, F_DUPFD
, newd
);
3529 ret
= dup2 (old
,new);
3535 #endif /* not HAVE_DUP2 */
3538 * Gettimeofday. Simulate as much as possible. Only accurate
3539 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3540 * Only needed when subprocesses are defined.
3545 #ifndef HAVE_GETTIMEOFDAY
3550 gettimeofday (tp
, tzp
)
3552 struct timezone
*tzp
;
3554 extern long time ();
3556 tp
->tv_sec
= time ((long *)0);
3559 tzp
->tz_minuteswest
= -1;
3566 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3569 * This function will go away as soon as all the stubs fixed. (fnf)
3576 printf ("%s not yet implemented\r\n", badfunc
);
3577 reset_all_sys_modes ();
3583 /* Directory routines for systems that don't have them. */
3585 #ifdef SYSV_SYSTEM_DIR
3589 #if defined (BROKEN_CLOSEDIR) || !defined (HAVE_CLOSEDIR)
3593 register DIR *dirp
; /* stream from opendir */
3597 rtnval
= emacs_close (dirp
->dd_fd
);
3599 /* Some systems (like Solaris) allocate the buffer and the DIR all
3600 in one block. Why in the world are we freeing this ourselves
3602 #if ! (defined (sun) && defined (USG5_4))
3603 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3605 xfree ((char *) dirp
);
3609 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3610 #endif /* SYSV_SYSTEM_DIR */
3612 #ifdef NONSYSTEM_DIR_LIBRARY
3616 char *filename
; /* name of directory */
3618 register DIR *dirp
; /* -> malloc'ed storage */
3619 register int fd
; /* file descriptor for read */
3620 struct stat sbuf
; /* result of fstat */
3622 fd
= emacs_open (filename
, O_RDONLY
, 0);
3627 if (fstat (fd
, &sbuf
) < 0
3628 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3629 || (dirp
= (DIR *) xmalloc (sizeof (DIR))) == 0)
3633 return 0; /* bad luck today */
3638 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3645 register DIR *dirp
; /* stream from opendir */
3647 emacs_close (dirp
->dd_fd
);
3648 xfree ((char *) dirp
);
3656 ino_t od_ino
; /* inode */
3657 char od_name
[DIRSIZ
]; /* filename */
3659 #endif /* not VMS */
3661 struct direct dir_static
; /* simulated directory contents */
3666 register DIR *dirp
; /* stream from opendir */
3669 register struct olddir
*dp
; /* -> directory data */
3671 register struct dir$_name
*dp
; /* -> directory data */
3672 register struct dir$_version
*dv
; /* -> version data */
3677 if (dirp
->dd_loc
>= dirp
->dd_size
)
3678 dirp
->dd_loc
= dirp
->dd_size
= 0;
3680 if (dirp
->dd_size
== 0 /* refill buffer */
3681 && (dirp
->dd_size
= emacs_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3685 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3686 dirp
->dd_loc
+= sizeof (struct olddir
);
3688 if (dp
->od_ino
!= 0) /* not deleted entry */
3690 dir_static
.d_ino
= dp
->od_ino
;
3691 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3692 dir_static
.d_name
[DIRSIZ
] = '\0';
3693 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3694 dir_static
.d_reclen
= sizeof (struct direct
)
3696 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3697 return &dir_static
; /* -> simulated structure */
3700 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3701 if (dirp
->dd_loc
== 0)
3702 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3703 : dp
->dir$b_namecount
;
3704 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3705 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3706 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3707 dir_static
.d_reclen
= sizeof (struct direct
)
3709 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3710 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3711 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3712 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3719 /* readdirver is just like readdir except it returns all versions of a file
3720 as separate entries. */
3725 register DIR *dirp
; /* stream from opendir */
3727 register struct dir$_name
*dp
; /* -> directory data */
3728 register struct dir$_version
*dv
; /* -> version data */
3730 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3731 dirp
->dd_loc
= dirp
->dd_size
= 0;
3733 if (dirp
->dd_size
== 0 /* refill buffer */
3734 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3737 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3738 if (dirp
->dd_loc
== 0)
3739 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3740 : dp
->dir$b_namecount
;
3741 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3742 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3743 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3744 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3745 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3746 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3747 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3748 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3754 #endif /* NONSYSTEM_DIR_LIBRARY */
3758 set_file_times (filename
, atime
, mtime
)
3759 const char *filename
;
3760 EMACS_TIME atime
, mtime
;
3763 struct timeval tv
[2];
3766 return utimes (filename
, tv
);
3767 #else /* not HAVE_UTIMES */
3769 utb
.actime
= EMACS_SECS (atime
);
3770 utb
.modtime
= EMACS_SECS (mtime
);
3771 return utime (filename
, &utb
);
3772 #endif /* not HAVE_UTIMES */
3775 /* mkdir and rmdir functions, for systems which don't have them. */
3779 * Written by Robert Rother, Mariah Corporation, August 1985.
3781 * If you want it, it's yours. All I ask in return is that if you
3782 * figure out how to do this in a Bourne Shell script you send me
3784 * sdcsvax!rmr or rmr@uscd
3786 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3787 * subroutine. 11Mar86; hoptoad!gnu
3789 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3790 * subroutine didn't return EEXIST. It does now.
3796 #ifdef MKDIR_PROTOTYPE
3800 mkdir (dpath
, dmode
)
3805 int cpid
, status
, fd
;
3806 struct stat statbuf
;
3808 if (stat (dpath
, &statbuf
) == 0)
3810 errno
= EEXIST
; /* Stat worked, so it already exists */
3814 /* If stat fails for a reason other than non-existence, return error */
3815 if (errno
!= ENOENT
)
3818 synch_process_alive
= 1;
3819 switch (cpid
= fork ())
3822 case -1: /* Error in fork */
3823 return (-1); /* Errno is set already */
3825 case 0: /* Child process */
3827 * Cheap hack to set mode of new directory. Since this
3828 * child process is going away anyway, we zap its umask.
3829 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3830 * directory. Does anybody care?
3832 status
= umask (0); /* Get current umask */
3833 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3834 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3841 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3842 _exit (-1); /* Can't exec /bin/mkdir */
3844 default: /* Parent process */
3845 wait_for_termination (cpid
);
3848 if (synch_process_death
!= 0 || synch_process_retcode
!= 0
3849 || synch_process_termsig
!= 0)
3851 errno
= EIO
; /* We don't know why, but */
3852 return -1; /* /bin/mkdir failed */
3857 #endif /* not HAVE_MKDIR */
3864 int cpid
, status
, fd
;
3865 struct stat statbuf
;
3867 if (stat (dpath
, &statbuf
) != 0)
3869 /* Stat just set errno. We don't have to */
3873 synch_process_alive
= 1;
3874 switch (cpid
= fork ())
3877 case -1: /* Error in fork */
3878 return (-1); /* Errno is set already */
3880 case 0: /* Child process */
3881 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3888 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3889 _exit (-1); /* Can't exec /bin/rmdir */
3891 default: /* Parent process */
3892 wait_for_termination (cpid
);
3895 if (synch_process_death
!= 0 || synch_process_retcode
!= 0
3896 || synch_process_termsig
!= 0)
3898 errno
= EIO
; /* We don't know why, but */
3899 return -1; /* /bin/rmdir failed */
3904 #endif /* !HAVE_RMDIR */
3908 /* Functions for VMS */
3910 #include "vms-pwd.h"
3915 /* Return as a string the VMS error string pertaining to STATUS.
3916 Reuses the same static buffer each time it is called. */
3920 int status
; /* VMS status code */
3924 static char buf
[257];
3926 bufadr
[0] = sizeof buf
- 1;
3927 bufadr
[1] = (int) buf
;
3928 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3929 return "untranslatable VMS error status";
3937 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3938 * not work correctly. (It also doesn't work well in version 2.3.)
3943 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3944 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3948 unsigned short s_buflen
;
3949 unsigned short s_code
;
3951 unsigned short *s_retlenadr
;
3955 #define buflen s.s_buflen
3956 #define code s.s_code
3957 #define bufadr s.s_bufadr
3958 #define retlenadr s.s_retlenadr
3960 #define R_OK 4 /* test for read permission */
3961 #define W_OK 2 /* test for write permission */
3962 #define X_OK 1 /* test for execute (search) permission */
3963 #define F_OK 0 /* test for presence of file */
3966 sys_access (path
, mode
)
3970 static char *user
= NULL
;
3973 /* translate possible directory spec into .DIR file name, so brain-dead
3974 * access can treat the directory like a file. */
3975 if (directory_file_name (path
, dir_fn
))
3979 return access (path
, mode
);
3980 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3986 unsigned short int dummy
;
3988 static int constant
= ACL$C_FILE
;
3989 DESCRIPTOR (path_desc
, path
);
3990 DESCRIPTOR (user_desc
, user
);
3994 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3997 acces
|= CHP$M_READ
;
3999 acces
|= CHP$M_WRITE
;
4000 itemlst
[0].buflen
= sizeof (int);
4001 itemlst
[0].code
= CHP$_FLAGS
;
4002 itemlst
[0].bufadr
= (char *) &flags
;
4003 itemlst
[0].retlenadr
= &dummy
;
4004 itemlst
[1].buflen
= sizeof (int);
4005 itemlst
[1].code
= CHP$_ACCESS
;
4006 itemlst
[1].bufadr
= (char *) &acces
;
4007 itemlst
[1].retlenadr
= &dummy
;
4008 itemlst
[2].end
= CHP$_END
;
4009 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
4010 return stat
== SS$_NORMAL
? 0 : -1;
4014 #else /* not VMS4_4 */
4017 #define ACE$M_WRITE 2
4018 #define ACE$C_KEYID 1
4020 static unsigned short memid
, grpid
;
4021 static unsigned int uic
;
4023 /* Called from init_sys_modes, so it happens not very often
4024 but at least each time Emacs is loaded. */
4026 sys_access_reinit ()
4032 sys_access (filename
, type
)
4038 int status
, size
, i
, typecode
, acl_controlled
;
4039 unsigned int *aclptr
, *aclend
, aclbuf
[60];
4040 union prvdef prvmask
;
4042 /* Get UIC and GRP values for protection checking. */
4045 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
4048 memid
= uic
& 0xFFFF;
4052 if (type
!= 2) /* not checking write access */
4053 return access (filename
, type
);
4055 /* Check write protection. */
4057 #define CHECKPRIV(bit) (prvmask.bit)
4058 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
4060 /* Find privilege bits */
4061 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
4063 error ("Unable to find privileges: %s", vmserrstr (status
));
4064 if (CHECKPRIV (PRV$V_BYPASS
))
4065 return 0; /* BYPASS enabled */
4067 fab
.fab$b_fac
= FAB$M_GET
;
4068 fab
.fab$l_fna
= filename
;
4069 fab
.fab$b_fns
= strlen (filename
);
4070 fab
.fab$l_xab
= &xab
;
4071 xab
= cc$rms_xabpro
;
4072 xab
.xab$l_aclbuf
= aclbuf
;
4073 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
4074 status
= SYS$
OPEN (&fab
, 0, 0);
4077 SYS$
CLOSE (&fab
, 0, 0);
4078 /* Check system access */
4079 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
4081 /* Check ACL entries, if any */
4083 if (xab
.xab$w_acllen
> 0)
4086 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
4087 while (*aclptr
&& aclptr
< aclend
)
4089 size
= (*aclptr
& 0xff) / 4;
4090 typecode
= (*aclptr
>> 8) & 0xff;
4091 if (typecode
== ACE$C_KEYID
)
4092 for (i
= size
- 1; i
> 1; i
--)
4093 if (aclptr
[i
] == uic
)
4096 if (aclptr
[1] & ACE$M_WRITE
)
4097 return 0; /* Write access through ACL */
4099 aclptr
= &aclptr
[size
];
4101 if (acl_controlled
) /* ACL specified, prohibits write access */
4104 /* No ACL entries specified, check normal protection */
4105 if (WRITABLE (XAB$V_WLD
)) /* World writable */
4107 if (WRITABLE (XAB$V_GRP
) &&
4108 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
4109 return 0; /* Group writable */
4110 if (WRITABLE (XAB$V_OWN
) &&
4111 (xab
.xab$l_uic
& 0xFFFF) == memid
)
4112 return 0; /* Owner writable */
4114 return -1; /* Not writable */
4116 #endif /* not VMS4_4 */
4119 static char vtbuf
[NAM$C_MAXRSS
+1];
4121 /* translate a vms file spec to a unix path */
4123 sys_translate_vms (vfile
)
4134 /* leading device or logical name is a root directory */
4135 if (p
= strchr (vfile
, ':'))
4144 if (*p
== '[' || *p
== '<')
4146 while (*++vfile
!= *p
+ 2)
4150 if (vfile
[-1] == *p
)
4173 static char utbuf
[NAM$C_MAXRSS
+1];
4175 /* translate a unix path to a VMS file spec */
4177 sys_translate_unix (ufile
)
4200 if (index (&ufile
[1], '/'))
4207 if (index (&ufile
[1], '/'))
4214 if (strncmp (ufile
, "./", 2) == 0)
4221 ufile
++; /* skip the dot */
4222 if (index (&ufile
[1], '/'))
4227 else if (strncmp (ufile
, "../", 3) == 0)
4235 ufile
+= 2; /* skip the dots */
4236 if (index (&ufile
[1], '/'))
4261 extern char *getcwd ();
4263 #define MAXPATHLEN 1024
4265 ptr
= xmalloc (MAXPATHLEN
);
4266 val
= getcwd (ptr
, MAXPATHLEN
);
4272 strcpy (pathname
, ptr
);
4281 long item_code
= JPI$_OWNER
;
4282 unsigned long parent_id
;
4285 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4288 vaxc$errno
= status
;
4298 return (getgid () << 16) | getuid ();
4303 sys_read (fildes
, buf
, nbyte
)
4308 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4313 sys_write (fildes
, buf
, nbyte
)
4318 register int nwrote
, rtnval
= 0;
4320 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4326 return rtnval
? rtnval
: -1;
4327 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4328 return rtnval
? rtnval
: -1;
4329 return (rtnval
+ nwrote
);
4334 * VAX/VMS VAX C RTL really loses. It insists that records
4335 * end with a newline (carriage return) character, and if they
4336 * don't it adds one (nice of it isn't it!)
4338 * Thus we do this stupidity below.
4343 sys_write (fildes
, buf
, nbytes
)
4346 unsigned int nbytes
;
4353 fstat (fildes
, &st
);
4359 /* Handle fixed-length files with carriage control. */
4360 if (st
.st_fab_rfm
== FAB$C_FIX
4361 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4363 len
= st
.st_fab_mrs
;
4364 retval
= write (fildes
, p
, min (len
, nbytes
));
4367 retval
++; /* This skips the implied carriage control */
4371 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4372 while (*e
!= '\n' && e
> p
) e
--;
4373 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4374 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4376 retval
= write (fildes
, p
, len
);
4387 /* Create file NEW copying its attributes from file OLD. If
4388 OLD is 0 or does not exist, create based on the value of
4391 /* Protection value the file should ultimately have.
4392 Set by create_copy_attrs, and use by rename_sansversions. */
4393 static unsigned short int fab_final_pro
;
4396 creat_copy_attrs (old
, new)
4399 struct FAB fab
= cc$rms_fab
;
4400 struct XABPRO xabpro
;
4401 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4402 extern int vms_stmlf_recfm
;
4406 fab
.fab$b_fac
= FAB$M_GET
;
4407 fab
.fab$l_fna
= old
;
4408 fab
.fab$b_fns
= strlen (old
);
4409 fab
.fab$l_xab
= (char *) &xabpro
;
4410 xabpro
= cc$rms_xabpro
;
4411 xabpro
.xab$l_aclbuf
= aclbuf
;
4412 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4413 /* Call $OPEN to fill in the fab & xabpro fields. */
4414 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4416 SYS$
CLOSE (&fab
, 0, 0);
4417 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4418 if (xabpro
.xab$w_acllen
> 0)
4420 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4421 /* If the acl buffer was too short, redo open with longer one.
4422 Wouldn't need to do this if there were some system imposed
4423 limit on the size of an ACL, but I can't find any such. */
4425 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4426 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4427 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4428 SYS$
CLOSE (&fab
, 0, 0);
4434 xabpro
.xab$l_aclbuf
= 0;
4439 fab
.fab$l_fna
= new;
4440 fab
.fab$b_fns
= strlen (new);
4444 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4445 fab
.fab$b_rat
= FAB$M_CR
;
4448 /* Set the file protections such that we will be able to manipulate
4449 this file. Once we are done writing and renaming it, we will set
4450 the protections back. */
4452 fab_final_pro
= xabpro
.xab$w_pro
;
4454 SYS$
SETDFPROT (0, &fab_final_pro
);
4455 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4457 /* Create the new file with either default attrs or attrs copied
4459 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4461 SYS$
CLOSE (&fab
, 0, 0);
4462 /* As this is a "replacement" for creat, return a file descriptor
4463 opened for writing. */
4464 return open (new, O_WRONLY
);
4469 #include <varargs.h>
4472 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4477 sys_creat (va_alist
)
4480 va_list list_incrementer
;
4483 int rfd
; /* related file descriptor */
4484 int fd
; /* Our new file descriptor */
4491 extern int vms_stmlf_recfm
;
4494 va_start (list_incrementer
);
4495 name
= va_arg (list_incrementer
, char *);
4496 mode
= va_arg (list_incrementer
, int);
4498 rfd
= va_arg (list_incrementer
, int);
4499 va_end (list_incrementer
);
4502 /* Use information from the related file descriptor to set record
4503 format of the newly created file. */
4504 fstat (rfd
, &st_buf
);
4505 switch (st_buf
.st_fab_rfm
)
4508 strcpy (rfm
, "rfm = fix");
4509 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
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
, mrs
);
4525 strcpy (rfm
, "rfm = vfc");
4526 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4527 strcpy (rat
, "rat = ");
4528 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4530 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4531 strcat (rat
, "ftn");
4532 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4533 strcat (rat
, "prn");
4534 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4535 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4536 strcat (rat
, ", blk");
4538 strcat (rat
, "blk");
4539 return creat (name
, 0, rfm
, rat
, fsz
);
4542 strcpy (rfm
, "rfm = stm");
4546 strcpy (rfm
, "rfm = stmcr");
4550 strcpy (rfm
, "rfm = stmlf");
4554 strcpy (rfm
, "rfm = udf");
4558 strcpy (rfm
, "rfm = var");
4561 strcpy (rat
, "rat = ");
4562 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4564 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4565 strcat (rat
, "ftn");
4566 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4567 strcat (rat
, "prn");
4568 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4569 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4570 strcat (rat
, ", blk");
4572 strcat (rat
, "blk");
4576 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4577 strcpy (rat
, "rat=cr");
4579 /* Until the VAX C RTL fixes the many bugs with modes, always use
4580 mode 0 to get the user's default protection. */
4581 fd
= creat (name
, 0, rfm
, rat
);
4582 if (fd
< 0 && errno
== EEXIST
)
4584 if (unlink (name
) < 0)
4585 report_file_error ("delete", build_string (name
));
4586 fd
= creat (name
, 0, rfm
, rat
);
4592 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4594 sys_fwrite (ptr
, size
, num
, fp
)
4595 register char * ptr
;
4598 register int tot
= num
* size
;
4606 * The VMS C library routine creat actually creates a new version of an
4607 * existing file rather than truncating the old version. There are times
4608 * when this is not the desired behavior, for instance, when writing an
4609 * auto save file (you only want one version), or when you don't have
4610 * write permission in the directory containing the file (but the file
4611 * itself is writable). Hence this routine, which is equivalent to
4612 * "close (creat (fn, 0));" on Unix if fn already exists.
4618 struct FAB xfab
= cc$rms_fab
;
4619 struct RAB xrab
= cc$rms_rab
;
4622 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4623 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4624 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4625 xfab
.fab$l_fna
= fn
;
4626 xfab
.fab$b_fns
= strlen (fn
);
4627 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4629 xrab
.rab$l_fab
= &xfab
;
4631 /* This gibberish opens the file, positions to the first record, and
4632 deletes all records from there until the end of file. */
4633 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4635 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4636 (SYS$
FIND (&xrab
) & 01) == 01 &&
4637 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4648 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4649 SYSPRV or a readable SYSUAF.DAT. */
4655 * Routine to read the VMS User Authorization File and return
4656 * a specific user's record.
4659 static struct UAF retuaf
;
4662 get_uaf_name (uname
)
4669 uaf_fab
= cc$rms_fab
;
4670 uaf_rab
= cc$rms_rab
;
4671 /* initialize fab fields */
4672 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4673 uaf_fab
.fab$b_fns
= 21;
4674 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4675 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4676 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4677 /* initialize rab fields */
4678 uaf_rab
.rab$l_fab
= &uaf_fab
;
4679 /* open the User Authorization File */
4680 status
= SYS$
OPEN (&uaf_fab
);
4684 vaxc$errno
= status
;
4687 status
= SYS$
CONNECT (&uaf_rab
);
4691 vaxc$errno
= status
;
4694 /* read the requested record - index is in uname */
4695 uaf_rab
.rab$l_kbf
= uname
;
4696 uaf_rab
.rab$b_ksz
= strlen (uname
);
4697 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4698 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4699 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4700 status
= SYS$
GET (&uaf_rab
);
4704 vaxc$errno
= status
;
4707 /* close the User Authorization File */
4708 status
= SYS$
DISCONNECT (&uaf_rab
);
4712 vaxc$errno
= status
;
4715 status
= SYS$
CLOSE (&uaf_fab
);
4719 vaxc$errno
= status
;
4733 uaf_fab
= cc$rms_fab
;
4734 uaf_rab
= cc$rms_rab
;
4735 /* initialize fab fields */
4736 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4737 uaf_fab
.fab$b_fns
= 21;
4738 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4739 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4740 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4741 /* initialize rab fields */
4742 uaf_rab
.rab$l_fab
= &uaf_fab
;
4743 /* open the User Authorization File */
4744 status
= SYS$
OPEN (&uaf_fab
);
4748 vaxc$errno
= status
;
4751 status
= SYS$
CONNECT (&uaf_rab
);
4755 vaxc$errno
= status
;
4758 /* read the requested record - index is in uic */
4759 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4760 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4761 uaf_rab
.rab$b_ksz
= sizeof uic
;
4762 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4763 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4764 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4765 status
= SYS$
GET (&uaf_rab
);
4769 vaxc$errno
= status
;
4772 /* close the User Authorization File */
4773 status
= SYS$
DISCONNECT (&uaf_rab
);
4777 vaxc$errno
= status
;
4780 status
= SYS$
CLOSE (&uaf_fab
);
4784 vaxc$errno
= status
;
4790 static struct passwd retpw
;
4798 /* copy these out first because if the username is 32 chars, the next
4799 section will overwrite the first byte of the UIC */
4800 retpw
.pw_uid
= up
->uaf$w_mem
;
4801 retpw
.pw_gid
= up
->uaf$w_grp
;
4803 /* I suppose this is not the best style, to possibly overwrite one
4804 byte beyond the end of the field, but what the heck... */
4805 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4806 while (ptr
[-1] == ' ')
4809 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4811 /* the rest of these are counted ascii strings */
4812 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4813 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4814 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4815 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4816 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4817 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4818 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4819 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4823 #else /* not READ_SYSUAF */
4824 static struct passwd retpw
;
4825 #endif /* not READ_SYSUAF */
4836 unsigned char * full
;
4837 #endif /* READ_SYSUAF */
4842 if ('a' <= *ptr
&& *ptr
<= 'z')
4847 if (!(up
= get_uaf_name (name
)))
4849 return cnv_uaf_pw (up
);
4851 if (strcmp (name
, getenv ("USER")) == 0)
4853 retpw
.pw_uid
= getuid ();
4854 retpw
.pw_gid
= getgid ();
4855 strcpy (retpw
.pw_name
, name
);
4856 if (full
= egetenv ("FULLNAME"))
4857 strcpy (retpw
.pw_gecos
, full
);
4859 *retpw
.pw_gecos
= '\0';
4860 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4861 *retpw
.pw_shell
= '\0';
4866 #endif /* not READ_SYSUAF */
4876 if (!(up
= get_uaf_uic (uid
)))
4878 return cnv_uaf_pw (up
);
4880 if (uid
== sys_getuid ())
4881 return getpwnam (egetenv ("USER"));
4884 #endif /* not READ_SYSUAF */
4887 /* return total address space available to the current process. This is
4888 the sum of the current p0 size, p1 size and free page table entries
4894 unsigned long free_pages
;
4895 unsigned long frep0va
;
4896 unsigned long frep1va
;
4899 item_code
= JPI$_FREPTECNT
;
4900 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4903 vaxc$errno
= status
;
4908 item_code
= JPI$_FREP0VA
;
4909 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4912 vaxc$errno
= status
;
4915 item_code
= JPI$_FREP1VA
;
4916 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4919 vaxc$errno
= status
;
4923 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4927 define_logical_name (varname
, string
)
4931 struct dsc$descriptor_s strdsc
=
4932 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4933 struct dsc$descriptor_s envdsc
=
4934 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4935 struct dsc$descriptor_s lnmdsc
=
4936 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4938 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4942 delete_logical_name (varname
)
4945 struct dsc$descriptor_s envdsc
=
4946 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4947 struct dsc$descriptor_s lnmdsc
=
4948 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4950 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4968 error ("execvp system call not implemented");
4977 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4978 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4979 char from_esn
[NAM$C_MAXRSS
];
4980 char to_esn
[NAM$C_MAXRSS
];
4982 from_fab
.fab$l_fna
= from
;
4983 from_fab
.fab$b_fns
= strlen (from
);
4984 from_fab
.fab$l_nam
= &from_nam
;
4985 from_fab
.fab$l_fop
= FAB$M_NAM
;
4987 from_nam
.nam$l_esa
= from_esn
;
4988 from_nam
.nam$b_ess
= sizeof from_esn
;
4990 to_fab
.fab$l_fna
= to
;
4991 to_fab
.fab$b_fns
= strlen (to
);
4992 to_fab
.fab$l_nam
= &to_nam
;
4993 to_fab
.fab$l_fop
= FAB$M_NAM
;
4995 to_nam
.nam$l_esa
= to_esn
;
4996 to_nam
.nam$b_ess
= sizeof to_esn
;
4998 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
5004 if (status
== RMS$_DEV
)
5008 vaxc$errno
= status
;
5013 /* This function renames a file like `rename', but it strips
5014 the version number from the "to" filename, such that the "to" file is
5015 will always be a new version. It also sets the file protection once it is
5016 finished. The protection that we will use is stored in fab_final_pro,
5017 and was set when we did a creat_copy_attrs to create the file that we
5020 We could use the chmod function, but Eunichs uses 3 bits per user category
5021 to describe the protection, and VMS uses 4 (write and delete are separate
5022 bits). To maintain portability, the VMS implementation of `chmod' wires
5023 the W and D bits together. */
5026 static struct fibdef fib
; /* We need this initialized to zero */
5027 char vms_file_written
[NAM$C_MAXRSS
];
5030 rename_sans_version (from
,to
)
5037 struct FAB to_fab
= cc$rms_fab
;
5038 struct NAM to_nam
= cc$rms_nam
;
5039 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
5040 struct dsc$descriptor fib_attr
[2]
5041 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
5042 char to_esn
[NAM$C_MAXRSS
];
5044 $
DESCRIPTOR (disk
,to_esn
);
5046 to_fab
.fab$l_fna
= to
;
5047 to_fab
.fab$b_fns
= strlen (to
);
5048 to_fab
.fab$l_nam
= &to_nam
;
5049 to_fab
.fab$l_fop
= FAB$M_NAM
;
5051 to_nam
.nam$l_esa
= to_esn
;
5052 to_nam
.nam$b_ess
= sizeof to_esn
;
5054 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
5056 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
5057 *(to_nam
.nam$l_ver
) = '\0';
5059 stat
= rename (from
, to_esn
);
5063 strcpy (vms_file_written
, to_esn
);
5065 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
5066 to_fab
.fab$b_fns
= strlen (vms_file_written
);
5068 /* Now set the file protection to the correct value */
5069 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
5071 /* Copy these fields into the fib */
5072 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
5073 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
5074 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
5076 SYS$
CLOSE (&to_fab
, 0, 0);
5078 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
5081 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
5082 0, 0, 0, &fib_attr
, 0);
5085 stat
= SYS$
DASSGN (chan
);
5088 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
5099 unsigned short fid
[3];
5100 char esa
[NAM$C_MAXRSS
];
5103 fab
.fab$l_fop
= FAB$M_OFP
;
5104 fab
.fab$l_fna
= file
;
5105 fab
.fab$b_fns
= strlen (file
);
5106 fab
.fab$l_nam
= &nam
;
5109 nam
.nam$l_esa
= esa
;
5110 nam
.nam$b_ess
= NAM$C_MAXRSS
;
5112 status
= SYS$
PARSE (&fab
);
5113 if ((status
& 1) == 0)
5116 vaxc$errno
= status
;
5119 status
= SYS$
SEARCH (&fab
);
5120 if ((status
& 1) == 0)
5123 vaxc$errno
= status
;
5127 fid
[0] = nam
.nam$w_fid
[0];
5128 fid
[1] = nam
.nam$w_fid
[1];
5129 fid
[2] = nam
.nam$w_fid
[2];
5131 fab
.fab$l_fna
= new;
5132 fab
.fab$b_fns
= strlen (new);
5134 status
= SYS$
PARSE (&fab
);
5135 if ((status
& 1) == 0)
5138 vaxc$errno
= status
;
5142 nam
.nam$w_fid
[0] = fid
[0];
5143 nam
.nam$w_fid
[1] = fid
[1];
5144 nam
.nam$w_fid
[2] = fid
[2];
5146 nam
.nam$l_esa
= nam
.nam$l_name
;
5147 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
5149 status
= SYS$
ENTER (&fab
);
5150 if ((status
& 1) == 0)
5153 vaxc$errno
= status
;
5164 printf ("%s not yet implemented\r\n", badfunc
);
5165 reset_all_sys_modes ();
5172 /* Arrange to return a range centered on zero. */
5173 return rand () - (1 << 30);
5185 /* Called from init_sys_modes. */
5187 hft_init (struct tty_display_info
*tty_out
)
5191 /* If we're not on an HFT we shouldn't do any of this. We determine
5192 if we are on an HFT by trying to get an HFT error code. If this
5193 call fails, we're not on an HFT. */
5195 if (ioctl (0, HFQERROR
, &junk
) < 0)
5197 #else /* not IBMR2AIX */
5198 if (ioctl (0, HFQEIO
, 0) < 0)
5200 #endif /* not IBMR2AIX */
5202 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5203 as the rubout key's ASCII code. Here this is changed. The bug is that
5204 there's no way to determine the old mapping, so in reset_sys_modes
5205 we need to assume that the normal map had been present. Of course, this
5206 code also doesn't help if on a terminal emulator which doesn't understand
5210 struct hfkeymap keymap
;
5212 buf
.hf_bufp
= (char *)&keymap
;
5213 buf
.hf_buflen
= sizeof (keymap
);
5214 keymap
.hf_nkeys
= 2;
5215 keymap
.hfkey
[0].hf_kpos
= 15;
5216 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5218 keymap
.hfkey
[0].hf_keyidh
= '<';
5219 #else /* not IBMR2AIX */
5220 keymap
.hfkey
[0].hf_page
= '<';
5221 #endif /* not IBMR2AIX */
5222 keymap
.hfkey
[0].hf_char
= 127;
5223 keymap
.hfkey
[1].hf_kpos
= 15;
5224 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5226 keymap
.hfkey
[1].hf_keyidh
= '<';
5227 #else /* not IBMR2AIX */
5228 keymap
.hfkey
[1].hf_page
= '<';
5229 #endif /* not IBMR2AIX */
5230 keymap
.hfkey
[1].hf_char
= 127;
5231 hftctl (0, HFSKBD
, &buf
);
5235 /* Reset the rubout key to backspace. */
5238 hft_reset (struct tty_display_info
*tty_out
)
5241 struct hfkeymap keymap
;
5245 if (ioctl (0, HFQERROR
, &junk
) < 0)
5247 #else /* not IBMR2AIX */
5248 if (ioctl (0, HFQEIO
, 0) < 0)
5250 #endif /* not IBMR2AIX */
5252 buf
.hf_bufp
= (char *)&keymap
;
5253 buf
.hf_buflen
= sizeof (keymap
);
5254 keymap
.hf_nkeys
= 2;
5255 keymap
.hfkey
[0].hf_kpos
= 15;
5256 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5258 keymap
.hfkey
[0].hf_keyidh
= '<';
5259 #else /* not IBMR2AIX */
5260 keymap
.hfkey
[0].hf_page
= '<';
5261 #endif /* not IBMR2AIX */
5262 keymap
.hfkey
[0].hf_char
= 8;
5263 keymap
.hfkey
[1].hf_kpos
= 15;
5264 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5266 keymap
.hfkey
[1].hf_keyidh
= '<';
5267 #else /* not IBMR2AIX */
5268 keymap
.hfkey
[1].hf_page
= '<';
5269 #endif /* not IBMR2AIX */
5270 keymap
.hfkey
[1].hf_char
= 8;
5271 hftctl (0, HFSKBD
, &buf
);
5278 /* These are included on Sunos 4.1 when we do not use shared libraries.
5279 X11 libraries may refer to these functions but (we hope) do not
5280 actually call them. */
5300 #endif /* USE_DL_STUBS */
5309 register int length
;
5313 long max_str
= 65535;
5315 while (length
> max_str
) {
5316 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5321 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5323 while (length
-- > 0)
5325 #endif /* not VMS */
5328 #endif /* no bzero */
5329 #endif /* BSTRING */
5331 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5334 /* Saying `void' requires a declaration, above, where bcopy is used
5335 and that declaration causes pain for systems where bcopy is a macro. */
5336 bcopy (b1
, b2
, length
)
5339 register int length
;
5342 long max_str
= 65535;
5344 while (length
> max_str
) {
5345 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5351 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5353 while (length
-- > 0)
5355 #endif /* not VMS */
5357 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5362 bcmp (b1
, b2
, length
) /* This could be a macro! */
5365 register int length
;
5368 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5369 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5371 return STR$
COMPARE (&src1
, &src2
);
5373 while (length
-- > 0)
5378 #endif /* not VMS */
5380 #endif /* no bcmp */
5381 #endif /* not BSTRING */
5383 #ifndef HAVE_STRSIGNAL
5390 if (0 <= code
&& code
< NSIG
)
5393 signame
= sys_errlist
[code
];
5395 /* Cast to suppress warning if the table has const char *. */
5396 signame
= (char *) sys_siglist
[code
];
5402 #endif /* HAVE_STRSIGNAL */
5404 /* arch-tag: edb43589-4e09-4544-b325-978b5b121dcf
5405 (do not change this comment) */