1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
30 #include "blockinput.h"
33 #define min(x,y) ((x) > (y) ? (y) : (x))
35 /* In this file, open, read and write refer to the system calls,
36 not our sugared interfaces sys_open, sys_read and sys_write.
37 Contrariwise, for systems where we use the system calls directly,
38 define sys_read, etc. here as aliases for them. */
41 #define sys_write write
42 #endif /* `read' is not a macro */
52 #endif /* not WINDOWSNT */
55 #define sys_close close
62 #else /* `open' is a macro */
64 #endif /* `open' is a macro */
66 /* Does anyone other than VMS need this? */
68 #define sys_fwrite fwrite
78 #include <sys/types.h>
82 /* Get _POSIX_VDISABLE, if it is available. */
87 /* Get SI_SRPC_DOMAIN, if it is available. */
88 #ifdef HAVE_SYS_SYSTEMINFO_H
89 #include <sys/systeminfo.h>
92 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
96 #include <sys/param.h>
100 extern unsigned start
__asm__ ("start");
118 #include <sys/file.h>
126 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
130 #ifdef BSD_SYSTEM /* avoid writing defined (BSD_SYSTEM) || defined (USG)
131 because the vms compiler doesn't grok `defined' */
139 #endif /* not 4.1 bsd */
142 #include <sys/ioctl.h>
148 #ifdef BROKEN_TIOCGWINSZ
153 #if defined(USG) || defined(DGUX)
154 #include <sys/utsname.h>
156 #ifndef MEMORY_IN_STRING_H
159 #if defined (TIOCGWINSZ) || defined (ISC4_0)
161 #include <sys/sioctl.h>
164 #include <sys/stream.h>
165 #include <sys/ptem.h>
167 #endif /* TIOCGWINSZ or ISC4_0 */
168 #endif /* USG or DGUX */
170 extern int quit_char
;
174 #include "termhooks.h"
175 #include "termchar.h"
176 #include "termopts.h"
177 #include "dispextern.h"
182 /* In process.h which conflicts with the local copy. */
184 int _CRTAPI1
_spawnlp (int, const char *, const char *, ...);
185 int _CRTAPI1
_getpid (void);
188 #ifdef NONSYSTEM_DIR_LIBRARY
190 #endif /* NONSYSTEM_DIR_LIBRARY */
192 #include "syssignal.h"
199 #ifndef HAVE_STRUCT_UTIMBUF
200 /* We want to use utime rather than utimes, but we couldn't find the
201 structure declaration. We'll use the traditional one. */
209 #ifndef VFORK_RETURN_TYPE
210 #define VFORK_RETURN_TYPE int
213 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
219 #define LNOFLSH 0100000
222 static int baud_convert
[] =
227 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
228 1800, 2400, 4800, 9600, 19200, 38400
232 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
235 #if defined (HAVE_TERMIOS_H) && defined (LINUX)
237 /* HJL's version of libc is said to need this on the Alpha.
238 On the other hand, DEC OSF1 on the Alpha needs ospeed to be a short. */
239 extern speed_t ospeed
;
245 /* The file descriptor for Emacs's input terminal.
246 Under Unix, this is normally zero except when using X;
247 under VMS, we place the input channel number here. */
250 void croak
P_ ((char *));
258 /* Specify a different file descriptor for further input operations. */
267 /* Discard pending input on descriptor input_fd. */
273 struct emacs_tty buf
;
278 /* Discarding input is not safe when the input could contain
279 replies from the X server. So don't do it. */
280 if (read_socket_hook
)
285 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
286 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
292 ioctl (input_fd
, TIOCFLUSH
, &zero
);
294 #else /* not Apollo */
295 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
296 while (dos_keyread () != -1)
298 #else /* not MSDOS */
299 EMACS_GET_TTY (input_fd
, &buf
);
300 EMACS_SET_TTY (input_fd
, &buf
, 0);
301 #endif /* not MSDOS */
302 #endif /* not Apollo */
304 #endif /* not WINDOWSNT */
309 /* Arrange for character C to be read as the next input from
316 if (read_socket_hook
)
319 /* Should perhaps error if in batch mode */
321 ioctl (input_fd
, TIOCSTI
, &c
);
322 #else /* no TIOCSTI */
323 error ("Cannot stuff terminal input characters in this version of Unix");
324 #endif /* no TIOCSTI */
336 #ifdef INIT_BAUD_RATE
341 #else /* not DOS_NT */
345 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
346 &sg
.class, 12, 0, 0, 0, 0 );
347 ospeed
= sg
.xmit_baud
;
353 tcgetattr (input_fd
, &sg
);
354 ospeed
= cfgetospeed (&sg
);
355 #if defined (USE_GETOBAUD) && defined (getobaud)
356 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
358 ospeed
= getobaud (sg
.c_cflag
);
360 #else /* neither VMS nor TERMIOS */
366 tcgetattr (input_fd
, &sg
);
368 ioctl (input_fd
, TCGETA
, &sg
);
370 ospeed
= sg
.c_cflag
& CBAUD
;
371 #else /* neither VMS nor TERMIOS nor TERMIO */
374 sg
.sg_ospeed
= B9600
;
375 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
377 ospeed
= sg
.sg_ospeed
;
378 #endif /* not HAVE_TERMIO */
379 #endif /* not HAVE_TERMIOS */
381 #endif /* not DOS_NT */
382 #endif /* not INIT_BAUD_RATE */
385 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
386 ? baud_convert
[ospeed
] : 9600);
393 set_exclusive_use (fd
)
397 ioctl (fd
, FIOCLEX
, 0);
399 /* Ok to do nothing if this feature does not exist */
404 wait_without_blocking ()
407 wait3 (0, WNOHANG
| WUNTRACED
, 0);
409 croak ("wait_without_blocking");
411 synch_process_alive
= 0;
414 #endif /* not subprocesses */
416 int wait_debugging
; /* Set nonzero to make following function work under dbx
417 (at least for bsd). */
420 wait_for_termination_signal ()
423 /* Wait for subprocess with process id `pid' to terminate and
424 make sure it will get eliminated (not remain forever as a zombie) */
427 wait_for_termination (pid
)
436 status
= SYS$
FORCEX (&pid
, 0, 0);
439 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
440 /* Note that kill returns -1 even if the process is just a zombie now.
441 But inevitably a SIGCHLD interrupt should be generated
442 and child_sig will do wait3 and make the process go away. */
443 /* There is some indication that there is a bug involved with
444 termination of subprocesses, perhaps involving a kernel bug too,
445 but no idea what it is. Just as a hunch we signal SIGCHLD to see
446 if that causes the problem to go away or get worse. */
447 sigsetmask (sigmask (SIGCHLD
));
448 if (0 > kill (pid
, 0))
450 sigsetmask (SIGEMPTYMASK
);
451 kill (getpid (), SIGCHLD
);
457 sigpause (SIGEMPTYMASK
);
458 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
459 #if defined (UNIPLUS)
460 if (0 > kill (pid
, 0))
463 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
464 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
465 sigblock (sigmask (SIGCHLD
));
466 if (0 > kill (pid
, 0))
468 sigunblock (sigmask (SIGCHLD
));
471 sigpause (SIGEMPTYMASK
);
472 #else /* not POSIX_SIGNALS */
473 #ifdef HAVE_SYSV_SIGPAUSE
475 if (0 > kill (pid
, 0))
481 #else /* not HAVE_SYSV_SIGPAUSE */
485 #else /* not WINDOWSNT */
486 if (0 > kill (pid
, 0))
488 /* Using sleep instead of pause avoids timing error.
489 If the inferior dies just before the sleep,
490 we lose just one second. */
492 #endif /* not WINDOWSNT */
493 #endif /* not HAVE_SYSV_SIGPAUSE */
494 #endif /* not POSIX_SIGNALS */
495 #endif /* not UNIPLUS */
496 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
498 #else /* not subprocesses */
501 #else /* not __DJGPP__ > 1 */
503 if (kill (pid
, 0) < 0)
509 if (status
== pid
|| status
== -1)
512 #endif /* not __DJGPP__ > 1*/
513 #endif /* not subprocesses */
520 * flush any pending output
521 * (may flush input as well; it does not matter the way we use it)
525 flush_pending_output (channel
)
529 /* If we try this, we get hit with SIGTTIN, because
530 the child's tty belongs to the child's pgrp. */
533 ioctl (channel
, TCFLSH
, 1);
537 /* 3rd arg should be ignored
538 but some 4.2 kernels actually want the address of an int
539 and nonzero means something different. */
540 ioctl (channel
, TIOCFLUSH
, &zero
);
547 /* Set up the terminal at the other end of a pseudo-terminal that
548 we will be controlling an inferior through.
549 It should not echo or do line-editing, since that is done
550 in Emacs. No padding needed for insertion into an Emacs buffer. */
553 child_setup_tty (out
)
559 EMACS_GET_TTY (out
, &s
);
561 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
562 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
563 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
565 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
566 /* No output delays */
568 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
569 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
571 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
574 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
577 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
579 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
580 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
582 /* Said to be unnecessary: */
583 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
584 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
587 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
588 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
589 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
590 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
593 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
597 /* AIX enhanced edit loses NULs, so disable it */
600 s
.main
.c_iflag
&= ~ASCEDIT
;
602 /* Also, PTY overloads NUL and BREAK.
603 don't ignore break, but don't signal either, so it looks like NUL. */
604 s
.main
.c_iflag
&= ~IGNBRK
;
605 s
.main
.c_iflag
&= ~BRKINT
;
606 /* QUIT and INTR work better as signals, so disable character forms */
607 s
.main
.c_cc
[VINTR
] = 0377;
608 #ifdef SIGNALS_VIA_CHARACTERS
609 /* the QUIT and INTR character are used in process_send_signal
610 so set them here to something useful. */
611 if (s
.main
.c_cc
[VQUIT
] == 0377)
612 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
613 if (s
.main
.c_cc
[VINTR
] == 0377)
614 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
615 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
616 /* QUIT and INTR work better as signals, so disable character forms */
617 s
.main
.c_cc
[VQUIT
] = 0377;
618 s
.main
.c_cc
[VINTR
] = 0377;
619 s
.main
.c_lflag
&= ~ISIG
;
620 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
621 s
.main
.c_cc
[VEOL
] = 0377;
622 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
625 #else /* not HAVE_TERMIO */
627 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
629 s
.main
.sg_flags
|= LPASS8
;
630 s
.main
.sg_erase
= 0377;
631 s
.main
.sg_kill
= 0377;
632 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
634 #endif /* not HAVE_TERMIO */
636 EMACS_SET_TTY (out
, &s
, 0);
645 ioctl (out
, FIOASYNC
, &zero
);
648 #endif /* not DOS_NT */
652 #endif /* subprocesses */
654 /* Record a signal code and the handler for it. */
658 SIGTYPE (*handler
) P_ ((int));
661 static void save_signal_handlers
P_ ((struct save_signal
*));
662 static void restore_signal_handlers
P_ ((struct save_signal
*));
664 /* Suspend the Emacs process; give terminal to its superior. */
670 /* "Foster" parentage allows emacs to return to a subprocess that attached
671 to the current emacs as a cheaper than starting a whole new process. This
672 is set up by KEPTEDITOR.COM. */
673 unsigned long parent_id
, foster_parent_id
;
676 fpid_string
= getenv ("EMACS_PARENT_PID");
677 if (fpid_string
!= NULL
)
679 sscanf (fpid_string
, "%x", &foster_parent_id
);
680 if (foster_parent_id
!= 0)
681 parent_id
= foster_parent_id
;
683 parent_id
= getppid ();
686 parent_id
= getppid ();
688 xfree (fpid_string
); /* On VMS, this was malloc'd */
690 if (parent_id
&& parent_id
!= 0xffffffff)
692 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
693 int status
= LIB$
ATTACH (&parent_id
) & 1;
694 signal (SIGINT
, oldsig
);
703 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
704 d_prompt
.a
= "Emacs: "; /* Just a reminder */
705 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
710 #if defined(SIGTSTP) && !defined(MSDOS)
713 int pgrp
= EMACS_GETPGRP (0);
714 EMACS_KILLPG (pgrp
, SIGTSTP
);
717 #else /* No SIGTSTP */
718 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
719 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
720 kill (getpid (), SIGQUIT
);
722 #else /* No SIGTSTP or USG_JOBCTRL */
724 /* On a system where suspending is not implemented,
725 instead fork a subshell and let it talk directly to the terminal
729 #endif /* no USG_JOBCTRL */
730 #endif /* no SIGTSTP */
734 /* Fork a subshell. */
740 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
742 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
745 struct save_signal saved_handlers
[5];
747 unsigned char *str
= 0;
750 saved_handlers
[0].code
= SIGINT
;
751 saved_handlers
[1].code
= SIGQUIT
;
752 saved_handlers
[2].code
= SIGTERM
;
754 saved_handlers
[3].code
= SIGIO
;
755 saved_handlers
[4].code
= 0;
757 saved_handlers
[3].code
= 0;
760 /* Mentioning current_buffer->buffer would mean including buffer.h,
761 which somehow wedges the hp compiler. So instead... */
763 dir
= intern ("default-directory");
764 if (NILP (Fboundp (dir
)))
766 dir
= Fsymbol_value (dir
);
770 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
771 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
772 len
= XSTRING (dir
)->size
;
773 bcopy (XSTRING (dir
)->data
, str
, len
);
774 if (str
[len
- 1] != '/') str
[len
++] = '/';
781 save_signal_handlers (saved_handlers
);
782 synch_process_alive
= 1;
783 #endif /* __DJGPP__ > 1 */
787 error ("Can't spawn subshell");
794 #ifdef DOS_NT /* MW, Aug 1993 */
797 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
800 sh
= (char *) egetenv ("SHELL");
804 /* Use our buffer's default directory for the subshell. */
806 chdir ((char *) str
);
809 close_process_descs (); /* Close Emacs's pipes/ptys */
812 #ifdef SET_EMACS_PRIORITY
814 extern int emacs_priority
;
816 if (emacs_priority
< 0)
817 nice (-emacs_priority
);
821 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
824 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
826 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
828 #else /* not MSDOS */
830 /* Waits for process completion */
831 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
834 write (1, "Can't execute subshell", 22);
835 #else /* not WINDOWSNT */
837 write (1, "Can't execute subshell", 22);
839 #endif /* not WINDOWSNT */
840 #endif /* not MSDOS */
843 /* Do this now if we did not do it before. */
844 #if !defined (MSDOS) || __DJGPP__ == 1
845 save_signal_handlers (saved_handlers
);
846 synch_process_alive
= 1;
850 wait_for_termination (pid
);
852 restore_signal_handlers (saved_handlers
);
853 synch_process_alive
= 0;
858 save_signal_handlers (saved_handlers
)
859 struct save_signal
*saved_handlers
;
861 while (saved_handlers
->code
)
863 saved_handlers
->handler
864 = (SIGTYPE (*) P_ ((int))) signal (saved_handlers
->code
, SIG_IGN
);
870 restore_signal_handlers (saved_handlers
)
871 struct save_signal
*saved_handlers
;
873 while (saved_handlers
->code
)
875 signal (saved_handlers
->code
, saved_handlers
->handler
);
889 old_fcntl_flags
= fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
890 fcntl (fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
892 interrupts_deferred
= 0;
901 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
906 if (read_socket_hook
)
910 sigunblock (sigmask (SIGWINCH
));
912 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
914 interrupts_deferred
= 0;
920 if (read_socket_hook
)
924 sigblock (sigmask (SIGWINCH
));
926 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
927 interrupts_deferred
= 1;
930 #else /* no FASYNC */
931 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
938 if (read_socket_hook
)
941 ioctl (input_fd
, FIOASYNC
, &on
);
942 interrupts_deferred
= 0;
950 if (read_socket_hook
)
953 ioctl (input_fd
, FIOASYNC
, &off
);
954 interrupts_deferred
= 1;
957 #else /* not FASYNC, not STRIDE */
969 if (read_socket_hook
)
973 sigaddset(&st
, SIGIO
);
974 ioctl (input_fd
, FIOASYNC
, &on
);
975 interrupts_deferred
= 0;
976 sigprocmask(SIG_UNBLOCK
, &st
, (sigset_t
*)0);
984 if (read_socket_hook
)
987 ioctl (input_fd
, FIOASYNC
, &off
);
988 interrupts_deferred
= 1;
996 if (read_socket_hook
)
999 croak ("request_sigio");
1005 if (read_socket_hook
)
1008 croak ("unrequest_sigio");
1014 #endif /* F_SETFL */
1016 /* Saving and restoring the process group of Emacs's terminal. */
1020 /* The process group of which Emacs was a member when it initially
1023 If Emacs was in its own process group (i.e. inherited_pgroup ==
1024 getpid ()), then we know we're running under a shell with job
1025 control (Emacs would never be run as part of a pipeline).
1028 If Emacs was not in its own process group, then we know we're
1029 running under a shell (or a caller) that doesn't know how to
1030 separate itself from Emacs (like sh). Emacs must be in its own
1031 process group in order to receive SIGIO correctly. In this
1032 situation, we put ourselves in our own pgroup, forcibly set the
1033 tty's pgroup to our pgroup, and make sure to restore and reinstate
1034 the tty's pgroup just like any other terminal setting. If
1035 inherited_group was not the tty's pgroup, then we'll get a
1036 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1037 it goes foreground in the future, which is what should happen. */
1038 int inherited_pgroup
;
1040 /* Split off the foreground process group to Emacs alone.
1041 When we are in the foreground, but not started in our own process
1042 group, redirect the TTY to point to our own process group. We need
1043 to be in our own process group to receive SIGIO properly. */
1045 narrow_foreground_group ()
1049 setpgrp (0, inherited_pgroup
);
1050 if (inherited_pgroup
!= me
)
1051 EMACS_SET_TTY_PGRP (input_fd
, &me
);
1055 /* Set the tty to our original foreground group. */
1057 widen_foreground_group ()
1059 if (inherited_pgroup
!= getpid ())
1060 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
1061 setpgrp (0, inherited_pgroup
);
1064 #endif /* BSD_PGRPS */
1066 /* Getting and setting emacs_tty structures. */
1068 /* Set *TC to the parameters associated with the terminal FD.
1069 Return zero if all's well, or -1 if we ran into an error we
1070 couldn't deal with. */
1072 emacs_get_tty (fd
, settings
)
1074 struct emacs_tty
*settings
;
1076 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1078 /* We have those nifty POSIX tcmumbleattr functions. */
1079 bzero (&settings
->main
, sizeof (settings
->main
));
1080 if (tcgetattr (fd
, &settings
->main
) < 0)
1085 /* The SYSV-style interface? */
1086 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1091 /* Vehemently Monstrous System? :-) */
1092 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1093 &settings
->main
.class, 12, 0, 0, 0, 0)
1099 /* I give up - I hope you have the BSD ioctls. */
1100 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1102 #endif /* not DOS_NT */
1107 /* Suivant - Do we have to get struct ltchars data? */
1109 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1113 /* How about a struct tchars and a wordful of lmode bits? */
1115 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1116 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1120 /* We have survived the tempest. */
1125 /* Set the parameters of the tty on FD according to the contents of
1126 *SETTINGS. If FLUSHP is non-zero, we discard input.
1127 Return 0 if all went well, and -1 if anything failed. */
1130 emacs_set_tty (fd
, settings
, flushp
)
1132 struct emacs_tty
*settings
;
1135 /* Set the primary parameters - baud rate, character size, etcetera. */
1138 /* We have those nifty POSIX tcmumbleattr functions.
1139 William J. Smith <wjs@wiis.wang.com> writes:
1140 "POSIX 1003.1 defines tcsetattr() to return success if it was
1141 able to perform any of the requested actions, even if some
1142 of the requested actions could not be performed.
1143 We must read settings back to ensure tty setup properly.
1144 AIX requires this to keep tty from hanging occasionally." */
1145 /* This make sure that we don't loop indefinitely in here. */
1146 for (i
= 0 ; i
< 10 ; i
++)
1147 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1158 bzero (&new, sizeof (new));
1159 /* Get the current settings, and see if they're what we asked for. */
1160 tcgetattr (fd
, &new);
1161 /* We cannot use memcmp on the whole structure here because under
1162 * aix386 the termios structure has some reserved field that may
1165 if ( new.c_iflag
== settings
->main
.c_iflag
1166 && new.c_oflag
== settings
->main
.c_oflag
1167 && new.c_cflag
== settings
->main
.c_cflag
1168 && new.c_lflag
== settings
->main
.c_lflag
1169 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1177 /* The SYSV-style interface? */
1178 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1183 /* Vehemently Monstrous System? :-) */
1184 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1185 &settings
->main
.class, 12, 0, 0, 0, 0)
1191 /* I give up - I hope you have the BSD ioctls. */
1192 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1194 #endif /* not DOS_NT */
1200 /* Suivant - Do we have to get struct ltchars data? */
1202 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1206 /* How about a struct tchars and a wordful of lmode bits? */
1208 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1209 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1213 /* We have survived the tempest. */
1218 /* The initial tty mode bits */
1219 struct emacs_tty old_tty
;
1221 /* 1 if we have been through init_sys_modes. */
1224 /* 1 if outer tty status has been recorded. */
1228 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1233 #ifndef F_SETOWN_BUG
1235 int old_fcntl_owner
;
1236 #endif /* F_SETOWN */
1237 #endif /* F_SETOWN_BUG */
1239 /* This may also be defined in stdio,
1240 but if so, this does no harm,
1241 and using the same name avoids wasting the other one's space. */
1244 extern char *_sobuf
;
1246 #if defined (USG) || defined (DGUX)
1247 unsigned char _sobuf
[BUFSIZ
+8];
1249 char _sobuf
[BUFSIZ
];
1254 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1257 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1263 struct emacs_tty tty
;
1267 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1268 extern int (*interrupt_signal
) ();
1272 Vtty_erase_char
= Qnil
;
1279 input_ef
= get_kbd_event_flag ();
1280 /* LIB$GET_EF (&input_ef); */
1281 SYS$
CLREF (input_ef
);
1282 waiting_for_ast
= 0;
1284 timer_ef
= get_timer_event_flag ();
1285 /* LIB$GET_EF (&timer_ef); */
1286 SYS$
CLREF (timer_ef
);
1290 LIB$
GET_EF (&process_ef
);
1291 SYS$
CLREF (process_ef
);
1293 if (input_ef
/ 32 != process_ef
/ 32)
1294 croak ("Input and process event flags in different clusters.");
1296 if (input_ef
/ 32 != timer_ef
/ 32)
1297 croak ("Input and timer event flags in different clusters.");
1299 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1300 ((unsigned) 1 << (process_ef
% 32));
1302 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1303 ((unsigned) 1 << (timer_ef
% 32));
1305 sys_access_reinit ();
1307 #endif /* not VMS */
1310 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1311 narrow_foreground_group ();
1314 #ifdef HAVE_WINDOW_SYSTEM
1315 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1316 needs the initialization code below. */
1317 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1320 EMACS_GET_TTY (input_fd
, &old_tty
);
1326 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1327 XSETINT (Vtty_erase_char
, old_tty
.main
.c_cc
[VERASE
]);
1330 /* This allows meta to be sent on 8th bit. */
1331 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1333 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1334 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1335 #ifdef INLCR /* I'm just being cautious,
1336 since I can't check how widespread INLCR is--rms. */
1337 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1340 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1342 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1343 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1345 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1347 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1350 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1352 tty
.main
.c_iflag
&= ~IXANY
;
1356 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1357 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1359 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1363 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1364 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1367 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1368 /* Set up C-g for both SIGQUIT and SIGINT.
1369 We don't know which we will get, but we handle both alike
1370 so which one it really gives us does not matter. */
1371 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1372 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1373 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1375 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1379 #if defined (mips) || defined (HAVE_TCATTR)
1381 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1384 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1385 #endif /* V_DSUSP */
1386 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1387 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1390 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1393 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1394 #endif /* VREPRINT */
1396 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1397 #endif /* VWERASE */
1399 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1400 #endif /* VDISCARD */
1405 tty
.main
.c_cc
[VSTART
] = '\021';
1408 tty
.main
.c_cc
[VSTOP
] = '\023';
1414 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1417 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1420 #endif /* mips or HAVE_TCATTR */
1422 #ifdef SET_LINE_DISCIPLINE
1423 /* Need to explicitly request TERMIODISC line discipline or
1424 Ultrix's termios does not work correctly. */
1425 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1429 /* AIX enhanced edit loses NULs, so disable it. */
1430 tty
.main
.c_line
= 0;
1431 tty
.main
.c_iflag
&= ~ASCEDIT
;
1433 tty
.main
.c_cc
[VSTRT
] = 255;
1434 tty
.main
.c_cc
[VSTOP
] = 255;
1435 tty
.main
.c_cc
[VSUSP
] = 255;
1436 tty
.main
.c_cc
[VDSUSP
] = 255;
1437 #endif /* IBMR2AIX */
1441 tty
.main
.c_cc
[VSTART
] = '\021';
1444 tty
.main
.c_cc
[VSTOP
] = '\023';
1447 /* Also, PTY overloads NUL and BREAK.
1448 don't ignore break, but don't signal either, so it looks like NUL.
1449 This really serves a purpose only if running in an XTERM window
1450 or via TELNET or the like, but does no harm elsewhere. */
1451 tty
.main
.c_iflag
&= ~IGNBRK
;
1452 tty
.main
.c_iflag
&= ~BRKINT
;
1454 #else /* if not HAVE_TERMIO */
1456 tty
.main
.tt_char
|= TT$M_NOECHO
;
1458 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1460 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1462 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1463 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1464 #else /* not VMS (BSD, that is) */
1466 XSETINT (Vtty_erase_char
, tty
.main
.sg_erase
);
1467 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1469 tty
.main
.sg_flags
|= ANYP
;
1470 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1471 #endif /* not DOS_NT */
1472 #endif /* not VMS (BSD, that is) */
1473 #endif /* not HAVE_TERMIO */
1475 /* If going to use CBREAK mode, we must request C-g to interrupt
1476 and turn off start and stop chars, etc. If not going to use
1477 CBREAK mode, do this anyway so as to turn off local flow
1478 control for user coming over network on 4.2; in this case,
1479 only t_stopc and t_startc really matter. */
1482 /* Note: if not using CBREAK mode, it makes no difference how we
1484 tty
.tchars
= new_tchars
;
1485 tty
.tchars
.t_intrc
= quit_char
;
1488 tty
.tchars
.t_startc
= '\021';
1489 tty
.tchars
.t_stopc
= '\023';
1492 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1494 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1495 anything, and leaving it in breaks the meta key. Go figure. */
1496 tty
.lmode
&= ~LLITOUT
;
1503 #endif /* HAVE_TCHARS */
1504 #endif /* not HAVE_TERMIO */
1507 tty
.ltchars
= new_ltchars
;
1508 #endif /* HAVE_LTCHARS */
1509 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1511 internal_terminal_init ();
1515 EMACS_SET_TTY (input_fd
, &tty
, 0);
1517 /* This code added to insure that, if flow-control is not to be used,
1518 we have an unlocked terminal at the start. */
1521 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1525 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1529 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1531 if (!flow_control
) tcflow (input_fd
, TCOON
);
1539 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1540 to be only LF. This is the way that is done. */
1543 if (ioctl (1, HFTGETID
, &tty
) != -1)
1544 write (1, "\033[20l", 5);
1550 /* Appears to do nothing when in PASTHRU mode.
1551 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1552 interrupt_signal, oob_chars, 0, 0, 0, 0);
1554 queue_kbd_input (0);
1559 #ifndef F_SETOWN_BUG
1560 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1562 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1564 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1565 fcntl (input_fd
, F_SETOWN
, getpid ());
1566 init_sigio (input_fd
);
1568 #endif /* F_GETOWN */
1569 #endif /* F_SETOWN_BUG */
1570 #endif /* F_SETFL */
1573 if (interrupt_input
)
1574 init_sigio (input_fd
);
1577 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1581 /* This symbol is defined on recent USG systems.
1582 Someone says without this call USG won't really buffer the file
1583 even with a call to setbuf. */
1584 setvbuf (stdout
, (char *) _sobuf
, _IOFBF
, sizeof _sobuf
);
1586 setbuf (stdout
, (char *) _sobuf
);
1588 #ifdef HAVE_WINDOW_SYSTEM
1589 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1590 needs the initialization code below. */
1591 if (EQ (Vwindow_system
, Qnil
)
1593 /* When running in tty mode on NT/Win95, we have a read_socket
1594 hook, but still need the rest of the initialization code below. */
1595 && (! read_socket_hook
)
1599 set_terminal_modes ();
1602 && FRAMEP (Vterminal_frame
)
1603 && FRAME_TERMCAP_P (XFRAME (Vterminal_frame
)))
1604 init_frame_faces (XFRAME (Vterminal_frame
));
1606 if (term_initted
&& no_redraw_on_reenter
)
1608 if (display_completed
)
1609 direct_output_forward_char (0);
1614 if (FRAMEP (Vterminal_frame
))
1615 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1621 /* Return nonzero if safe to use tabs in output.
1622 At the time this is called, init_sys_modes has not been done yet. */
1627 struct emacs_tty tty
;
1629 EMACS_GET_TTY (input_fd
, &tty
);
1630 return EMACS_TTY_TABS_OK (&tty
);
1633 /* Get terminal size from system.
1634 Store number of lines into *HEIGHTP and width into *WIDTHP.
1635 We store 0 if there's no valid information. */
1638 get_frame_size (widthp
, heightp
)
1639 int *widthp
, *heightp
;
1645 struct winsize size
;
1647 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1648 *widthp
= *heightp
= 0;
1651 *widthp
= size
.ws_col
;
1652 *heightp
= size
.ws_row
;
1658 /* SunOS - style. */
1659 struct ttysize size
;
1661 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1662 *widthp
= *heightp
= 0;
1665 *widthp
= size
.ts_cols
;
1666 *heightp
= size
.ts_lines
;
1672 struct sensemode tty
;
1674 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1675 &tty
.class, 12, 0, 0, 0, 0);
1676 *widthp
= tty
.scr_wid
;
1677 *heightp
= tty
.scr_len
;
1681 *widthp
= ScreenCols ();
1682 *heightp
= ScreenRows ();
1683 #else /* system doesn't know size */
1688 #endif /* not VMS */
1689 #endif /* not SunOS-style */
1690 #endif /* not BSD-style */
1693 /* Set the logical window size associated with descriptor FD
1694 to HEIGHT and WIDTH. This is used mainly with ptys. */
1697 set_window_size (fd
, height
, width
)
1698 int fd
, height
, width
;
1703 struct winsize size
;
1704 size
.ws_row
= height
;
1705 size
.ws_col
= width
;
1707 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1708 return 0; /* error */
1715 /* SunOS - style. */
1716 struct ttysize size
;
1717 size
.ts_lines
= height
;
1718 size
.ts_cols
= width
;
1720 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1726 #endif /* not SunOS-style */
1727 #endif /* not BSD-style */
1731 /* Prepare the terminal for exiting Emacs; move the cursor to the
1732 bottom of the frame, turn off interrupt-driven I/O, etc. */
1743 #ifdef HAVE_WINDOW_SYSTEM
1744 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1745 needs the clean-up code below. */
1746 if (!EQ (Vwindow_system
, Qnil
)
1748 /* When running in tty mode on NT/Win95, we have a read_socket
1749 hook, but still need the rest of the clean-up code below. */
1755 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1756 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1757 /* clear_end_of_line may move the cursor */
1758 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1759 #if defined (IBMR2AIX) && defined (AIXHFT)
1761 /* HFT devices normally use ^J as a LF/CR. We forced it to
1762 do the LF only. Now, we need to reset it. */
1765 if (ioctl (1, HFTGETID
, &tty
) != -1)
1766 write (1, "\033[20h", 5);
1770 reset_terminal_modes ();
1774 /* Avoid possible loss of output when changing terminal modes. */
1775 fsync (fileno (stdout
));
1780 #ifndef F_SETOWN_BUG
1781 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1782 if (interrupt_input
)
1785 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1787 #endif /* F_SETOWN */
1788 #endif /* F_SETOWN_BUG */
1790 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1792 #endif /* F_SETFL */
1794 if (interrupt_input
)
1799 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1802 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1806 #ifdef SET_LINE_DISCIPLINE
1807 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1808 A different old line discipline is therefore not restored, yet.
1809 Restore the old line discipline by hand. */
1810 ioctl (0, TIOCSETD
, &old_tty
.main
.c_line
);
1818 widen_foreground_group ();
1824 /* Set up the proper status flags for use of a pty. */
1830 /* I'm told that TOICREMOTE does not mean control chars
1831 "can't be sent" but rather that they don't have
1832 input-editing or signaling effects.
1833 That should be good, because we have other ways
1834 to do those things in Emacs.
1835 However, telnet mode seems not to work on 4.2.
1836 So TIOCREMOTE is turned off now. */
1838 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1839 will hang. In particular, the "timeout" feature (which
1840 causes a read to return if there is no data available)
1841 does this. Also it is known that telnet mode will hang
1842 in such a way that Emacs must be stopped (perhaps this
1843 is the same problem).
1845 If TIOCREMOTE is turned off, then there is a bug in
1846 hp-ux which sometimes loses data. Apparently the
1847 code which blocks the master process when the internal
1848 buffer fills up does not work. Other than this,
1849 though, everything else seems to work fine.
1851 Since the latter lossage is more benign, we may as well
1852 lose that way. -- cph */
1857 ioctl (fd
, FIONBIO
, &on
);
1862 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1863 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1864 /* cause EMACS not to die when it should, i.e., when its own controlling */
1865 /* tty goes away. I've complained to the AIX developers, and they may */
1866 /* change this behavior, but I'm not going to hold my breath. */
1867 signal (SIGHUP
, SIG_IGN
);
1870 #endif /* HAVE_PTYS */
1874 /* Assigning an input channel is done at the start of Emacs execution.
1875 This is called each time Emacs is resumed, also, but does nothing
1876 because input_chain is no longer zero. */
1885 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1891 /* Deassigning the input channel is done before exiting. */
1896 return SYS$
DASSGN (input_fd
);
1901 /* Request reading one character into the keyboard buffer.
1902 This is done as soon as the buffer becomes empty. */
1908 extern kbd_input_ast ();
1910 waiting_for_ast
= 0;
1912 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1913 &input_iosb
, kbd_input_ast
, 1,
1914 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1919 /* Ast routine that is called when keyboard input comes in
1920 in accord with the SYS$QIO above. */
1925 register int c
= -1;
1926 int old_errno
= errno
;
1927 extern EMACS_TIME
*input_available_clear_time
;
1929 if (waiting_for_ast
)
1930 SYS$
SETEF (input_ef
);
1931 waiting_for_ast
= 0;
1934 if (input_count
== 25)
1936 printf ("Ast # %d,", input_count
);
1937 printf (" iosb = %x, %x, %x, %x",
1938 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1941 if (input_iosb
.offset
)
1945 printf (", char = 0%o", c
);
1957 struct input_event e
;
1958 e
.kind
= ascii_keystroke
;
1959 XSETINT (e
.code
, c
);
1960 XSETFRAME (e
.frame_or_window
, selected_frame
);
1961 kbd_buffer_store_event (&e
);
1963 if (input_available_clear_time
)
1964 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1968 /* Wait until there is something in kbd_buffer. */
1971 wait_for_kbd_input ()
1973 extern int have_process_input
, process_exited
;
1975 /* If already something, avoid doing system calls. */
1976 if (detect_input_pending ())
1980 /* Clear a flag, and tell ast routine above to set it. */
1981 SYS$
CLREF (input_ef
);
1982 waiting_for_ast
= 1;
1983 /* Check for timing error: ast happened while we were doing that. */
1984 if (!detect_input_pending ())
1986 /* No timing error: wait for flag to be set. */
1987 set_waiting_for_input (0);
1988 SYS$
WFLOR (input_ef
, input_eflist
);
1989 clear_waiting_for_input (0);
1990 if (!detect_input_pending ())
1991 /* Check for subprocess input availability */
1993 int dsp
= have_process_input
|| process_exited
;
1995 SYS$
CLREF (process_ef
);
1996 if (have_process_input
)
1997 process_command_input ();
2002 update_mode_lines
++;
2003 prepare_menu_bars ();
2004 redisplay_preserve_echo_area ();
2008 waiting_for_ast
= 0;
2011 /* Get rid of any pending QIO, when we are about to suspend
2012 or when we want to throw away pending input.
2013 We wait for a positive sign that the AST routine has run
2014 and therefore there is no I/O request queued when we return.
2015 SYS$SETAST is used to avoid a timing error. */
2021 printf ("At end_kbd_input.\n");
2025 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2027 SYS$
CANCEL (input_fd
);
2032 /* Clear a flag, and tell ast routine above to set it. */
2033 SYS$
CLREF (input_ef
);
2034 waiting_for_ast
= 1;
2036 SYS$
CANCEL (input_fd
);
2038 SYS$
WAITFR (input_ef
);
2039 waiting_for_ast
= 0;
2042 /* Wait for either input available or time interval expiry. */
2045 input_wait_timeout (timeval
)
2046 int timeval
; /* Time to wait, in seconds */
2049 static int zero
= 0;
2050 static int large
= -10000000;
2052 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2054 /* If already something, avoid doing system calls. */
2055 if (detect_input_pending ())
2059 /* Clear a flag, and tell ast routine above to set it. */
2060 SYS$
CLREF (input_ef
);
2061 waiting_for_ast
= 1;
2062 /* Check for timing error: ast happened while we were doing that. */
2063 if (!detect_input_pending ())
2065 /* No timing error: wait for flag to be set. */
2067 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2068 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
2070 waiting_for_ast
= 0;
2073 /* The standard `sleep' routine works some other way
2074 and it stops working if you have ever quit out of it.
2075 This one continues to work. */
2081 static int zero
= 0;
2082 static int large
= -10000000;
2084 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2087 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2088 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2106 croak ("request sigio");
2112 croak ("unrequest sigio");
2117 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2122 #ifndef SYSTEM_MALLOC
2129 /* Some systems that cannot dump also cannot implement these. */
2132 * Return the address of the start of the text segment prior to
2133 * doing an unexec. After unexec the return value is undefined.
2134 * See crt0.c for further explanation and _start.
2138 #ifndef HAVE_TEXT_START
2143 return ((char *) TEXT_START
);
2147 return ((char *) csrt
);
2148 #else /* not GOULD */
2149 extern int _start ();
2150 return ((char *) _start
);
2152 #endif /* TEXT_START */
2154 #endif /* not HAVE_TEXT_START */
2157 * Return the address of the start of the data segment prior to
2158 * doing an unexec. After unexec the return value is undefined.
2159 * See crt0.c for further information and definition of data_start.
2161 * Apparently, on BSD systems this is etext at startup. On
2162 * USG systems (swapping) this is highly mmu dependent and
2163 * is also dependent on whether or not the program is running
2164 * with shared text. Generally there is a (possibly large)
2165 * gap between end of text and start of data with shared text.
2167 * On Uniplus+ systems with shared text, data starts at a
2168 * fixed address. Each port (from a given oem) is generally
2169 * different, and the specific value of the start of data can
2170 * be obtained via the UniPlus+ specific "uvar" system call,
2171 * however the method outlined in crt0.c seems to be more portable.
2173 * Probably what will have to happen when a USG unexec is available,
2174 * at least on UniPlus, is temacs will have to be made unshared so
2175 * that text and data are contiguous. Then once loadup is complete,
2176 * unexec will produce a shared executable where the data can be
2177 * at the normal shared text boundary and the startofdata variable
2178 * will be patched by unexec to the correct value.
2186 return ((char *) DATA_START
);
2188 #ifdef ORDINARY_LINK
2190 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2191 * data_start isn't defined. We take the address of environ, which
2192 * is known to live at or near the start of the system crt0.c, and
2193 * we don't sweat the handful of bytes that might lose.
2195 extern char **environ
;
2197 return((char *) &environ
);
2199 extern int data_start
;
2200 return ((char *) &data_start
);
2201 #endif /* ORDINARY_LINK */
2202 #endif /* DATA_START */
2204 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2207 /* Some systems that cannot dump also cannot implement these. */
2210 * Return the address of the end of the text segment prior to
2211 * doing an unexec. After unexec the return value is undefined.
2218 return ((char *) TEXT_END
);
2221 return ((char *) &etext
);
2226 * Return the address of the end of the data segment prior to
2227 * doing an unexec. After unexec the return value is undefined.
2234 return ((char *) DATA_END
);
2237 return ((char *) &edata
);
2241 #endif /* not CANNOT_DUMP */
2243 /* init_system_name sets up the string for the Lisp function
2244 system-name to return. */
2250 extern Lisp_Object Vsystem_name
;
2255 #include <sys/socket.h>
2257 #endif /* HAVE_SOCKETS */
2258 #endif /* not VMS */
2259 #endif /* not BSD4_1 */
2265 Vsystem_name
= build_string (sysname
);
2269 if ((sp
= egetenv ("SYS$NODE")) == 0)
2270 Vsystem_name
= build_string ("vax-vms");
2271 else if ((end
= index (sp
, ':')) == 0)
2272 Vsystem_name
= build_string (sp
);
2274 Vsystem_name
= make_string (sp
, end
- sp
);
2276 #ifndef HAVE_GETHOSTNAME
2279 Vsystem_name
= build_string (uts
.nodename
);
2280 #else /* HAVE_GETHOSTNAME */
2281 unsigned int hostname_size
= 256;
2282 char *hostname
= (char *) alloca (hostname_size
);
2284 /* Try to get the host name; if the buffer is too short, try
2285 again. Apparently, the only indication gethostname gives of
2286 whether the buffer was large enough is the presence or absence
2287 of a '\0' in the string. Eech. */
2290 gethostname (hostname
, hostname_size
- 1);
2291 hostname
[hostname_size
- 1] = '\0';
2293 /* Was the buffer large enough for the '\0'? */
2294 if (strlen (hostname
) < hostname_size
- 1)
2297 hostname_size
<<= 1;
2298 hostname
= (char *) alloca (hostname_size
);
2301 /* Turn the hostname into the official, fully-qualified hostname.
2302 Don't do this if we're going to dump; this can confuse system
2303 libraries on some machines and make the dumped emacs core dump. */
2306 #endif /* not CANNOT_DUMP */
2307 if (! index (hostname
, '.'))
2311 for (count
= 0;; count
++)
2316 hp
= gethostbyname (hostname
);
2318 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2323 Fsleep_for (make_number (1), Qnil
);
2327 char *fqdn
= (char *) hp
->h_name
;
2330 if (!index (fqdn
, '.'))
2332 /* We still don't have a fully qualified domain name.
2333 Try to find one in the list of alternate names */
2334 char **alias
= hp
->h_aliases
;
2335 while (*alias
&& !index (*alias
, '.'))
2342 /* Convert the host name to lower case. */
2343 /* Using ctype.h here would introduce a possible locale
2344 dependence that is probably wrong for hostnames. */
2348 if (*p
>= 'A' && *p
<= 'Z')
2355 #endif /* HAVE_SOCKETS */
2356 /* We used to try using getdomainname here,
2357 but NIIBE Yutaka <gniibe@etl.go.jp> says that
2358 getdomainname gets the NIS/YP domain which often is not the same
2359 as in Internet domain name. */
2360 #if 0 /* Turned off because sysinfo is not really likely to return the
2361 correct Internet domain. */
2362 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2363 if (! index (hostname
, '.'))
2365 /* The hostname is not fully qualified. Append the domain name. */
2367 int hostlen
= strlen (hostname
);
2368 int domain_size
= 256;
2372 char *domain
= (char *) alloca (domain_size
+ 1);
2373 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2374 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2375 if (sys_domain_size
<= 0)
2377 if (domain_size
< sys_domain_size
)
2379 domain_size
= sys_domain_size
;
2382 strcpy (fqdn
, hostname
);
2383 if (domain
[0] == '.')
2384 strcpy (fqdn
+ hostlen
, domain
);
2385 else if (domain
[0] != 0)
2387 fqdn
[hostlen
] = '.';
2388 strcpy (fqdn
+ hostlen
+ 1, domain
);
2394 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2396 Vsystem_name
= build_string (hostname
);
2397 #endif /* HAVE_GETHOSTNAME */
2402 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2403 if (*p
== ' ' || *p
== '\t')
2410 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2412 #include "sysselect.h"
2415 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2416 /* Cause explanatory error message at compile time,
2417 since the select emulation is not good enough for X. */
2418 int *x
= &x_windows_lose_if_no_select_system_call
;
2421 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2422 * Only checks read descriptors.
2424 /* How long to wait between checking fds in select */
2425 #define SELECT_PAUSE 1
2428 /* For longjmp'ing back to read_input_waiting. */
2430 jmp_buf read_alarm_throw
;
2432 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2433 The read_socket_hook function sets this to 1 while it is waiting. */
2435 int read_alarm_should_throw
;
2443 #else /* not BSD4_1 */
2444 signal (SIGALRM
, SIG_IGN
);
2445 #endif /* not BSD4_1 */
2446 if (read_alarm_should_throw
)
2447 longjmp (read_alarm_throw
, 1);
2451 /* Only rfds are checked. */
2453 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2455 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2456 EMACS_TIME
*timeout
;
2458 int ravail
= 0, old_alarm
;
2462 extern int proc_buffered_char
[];
2463 #ifndef subprocesses
2464 int process_tick
= 0, update_tick
= 0;
2466 extern int process_tick
, update_tick
;
2468 SIGTYPE (*old_trap
) ();
2471 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2472 /* If we're using X, then the native select will work; we only need the
2473 emulation for non-X usage. */
2474 if (!NILP (Vwindow_system
))
2475 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2477 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2478 local_timeout
= &timeoutval
;
2490 /* If we are looking only for the terminal, with no timeout,
2491 just read it and wait -- that's more efficient. */
2492 if (*local_timeout
== 100000 && process_tick
== update_tick
2493 && FD_ISSET (0, &orfds
))
2496 for (fd
= 1; fd
< nfds
; ++fd
)
2497 if (FD_ISSET (fd
, &orfds
))
2499 if (! detect_input_pending ())
2500 read_input_waiting ();
2506 /* Once a second, till the timer expires, check all the flagged read
2507 * descriptors to see if any input is available. If there is some then
2508 * set the corresponding bit in the return copy of rfds.
2512 register int to_check
, fd
;
2516 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2518 if (FD_ISSET (fd
, &orfds
))
2520 int avail
= 0, status
= 0;
2523 avail
= detect_input_pending (); /* Special keyboard handler */
2527 status
= ioctl (fd
, FIONREAD
, &avail
);
2528 #else /* no FIONREAD */
2529 /* Hoping it will return -1 if nothing available
2530 or 0 if all 0 chars requested are read. */
2531 if (proc_buffered_char
[fd
] >= 0)
2535 avail
= read (fd
, &buf
, 1);
2537 proc_buffered_char
[fd
] = buf
;
2539 #endif /* no FIONREAD */
2541 if (status
>= 0 && avail
> 0)
2549 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2551 old_alarm
= alarm (0);
2552 old_trap
= signal (SIGALRM
, select_alarm
);
2554 alarm (SELECT_PAUSE
);
2555 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2556 while (select_alarmed
== 0 && *local_timeout
!= 0
2557 && process_tick
== update_tick
)
2559 /* If we are interested in terminal input,
2560 wait by reading the terminal.
2561 That makes instant wakeup for terminal input at least. */
2562 if (FD_ISSET (0, &orfds
))
2564 read_input_waiting ();
2565 if (detect_input_pending ())
2571 (*local_timeout
) -= SELECT_PAUSE
;
2572 /* Reset the old alarm if there was one */
2574 signal (SIGALRM
, old_trap
);
2577 /* Reset or forge an interrupt for the original handler. */
2578 old_alarm
-= SELECT_PAUSE
;
2580 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2584 if (*local_timeout
== 0) /* Stop on timer being cleared */
2589 #endif /* not WINDOWSNT */
2591 /* Read keyboard input into the standard buffer,
2592 waiting for at least one character. */
2594 /* Make all keyboard buffers much bigger when using a window system. */
2595 #ifdef HAVE_WINDOW_SYSTEM
2596 #define BUFFER_SIZE_FACTOR 16
2598 #define BUFFER_SIZE_FACTOR 1
2602 read_input_waiting ()
2604 struct input_event e
;
2606 extern int quit_char
;
2608 if (read_socket_hook
)
2610 struct input_event buf
[256];
2612 read_alarm_should_throw
= 0;
2613 if (! setjmp (read_alarm_throw
))
2614 nread
= (*read_socket_hook
) (0, buf
, 256, 1, 0);
2618 /* Scan the chars for C-g and store them in kbd_buffer. */
2619 for (i
= 0; i
< nread
; i
++)
2621 kbd_buffer_store_event (&buf
[i
]);
2622 /* Don't look at input that follows a C-g too closely.
2623 This reduces lossage due to autorepeat on C-g. */
2624 if (buf
[i
].kind
== ascii_keystroke
2625 && buf
[i
].code
== quit_char
)
2632 nread
= read (fileno (stdin
), buf
, 1);
2634 /* Scan the chars for C-g and store them in kbd_buffer. */
2635 e
.kind
= ascii_keystroke
;
2636 XSETFRAME (e
.frame_or_window
, selected_frame
);
2638 for (i
= 0; i
< nread
; i
++)
2640 /* Convert chars > 0177 to meta events if desired.
2641 We do this under the same conditions that read_avail_input does. */
2642 if (read_socket_hook
== 0)
2644 /* If the user says she has a meta key, then believe her. */
2645 if (meta_key
== 1 && (buf
[i
] & 0x80))
2646 e
.modifiers
= meta_modifier
;
2651 XSETINT (e
.code
, buf
[i
]);
2652 kbd_buffer_store_event (&e
);
2653 /* Don't look at input that follows a C-g too closely.
2654 This reduces lossage due to autorepeat on C-g. */
2655 if (buf
[i
] == quit_char
)
2661 #endif /* not HAVE_SELECT */
2662 #endif /* not VMS */
2663 #endif /* not MSDOS */
2667 * Partially emulate 4.2 open call.
2668 * open is defined as this in 4.1.
2670 * - added by Michael Bloom @ Citicorp/TTI
2675 sys_open (path
, oflag
, mode
)
2679 if (oflag
& O_CREAT
)
2680 return creat (path
, mode
);
2682 return open (path
, oflag
);
2691 lmode
= LINTRUP
| lmode
;
2692 ioctl (fd
, TIOCLSET
, &lmode
);
2700 lmode
= ~LINTRUP
& lmode
;
2701 ioctl (0, TIOCLSET
, &lmode
);
2709 interrupts_deferred
= 0;
2717 interrupts_deferred
= 1;
2720 /* still inside #ifdef BSD4_1 */
2723 int sigheld
; /* Mask of held signals */
2729 sigheld
|= sigbit (signum
);
2737 sigheld
|= sigbit (signum
);
2744 sigheld
&= ~sigbit (signum
);
2749 sigfree () /* Free all held signals */
2752 for (i
= 0; i
< NSIG
; i
++)
2753 if (sigheld
& sigbit (i
))
2761 return 1 << (i
- 1);
2763 #endif /* subprocesses */
2766 /* POSIX signals support - DJB */
2767 /* Anyone with POSIX signals should have ANSI C declarations */
2769 #ifdef POSIX_SIGNALS
2771 sigset_t empty_mask
, full_mask
;
2776 sigemptyset (&empty_mask
);
2777 sigfillset (&full_mask
);
2781 sys_signal (int signal_number
, signal_handler_t action
)
2783 struct sigaction new_action
, old_action
;
2784 sigemptyset (&new_action
.sa_mask
);
2785 new_action
.sa_handler
= action
;
2787 /* Emacs mostly works better with restartable system services. If this
2788 * flag exists, we probably want to turn it on here.
2790 new_action
.sa_flags
= SA_RESTART
;
2792 new_action
.sa_flags
= 0;
2794 sigaction (signal_number
, &new_action
, &old_action
);
2795 return (old_action
.sa_handler
);
2799 /* If we're compiling with GCC, we don't need this function, since it
2800 can be written as a macro. */
2802 sys_sigmask (int sig
)
2805 sigemptyset (&mask
);
2806 sigaddset (&mask
, sig
);
2811 /* I'd like to have these guys return pointers to the mask storage in here,
2812 but there'd be trouble if the code was saving multiple masks. I'll be
2813 safe and pass the structure. It normally won't be more than 2 bytes
2817 sys_sigblock (sigset_t new_mask
)
2820 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2825 sys_sigunblock (sigset_t new_mask
)
2828 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2833 sys_sigsetmask (sigset_t new_mask
)
2836 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2840 #endif /* POSIX_SIGNALS */
2848 /* Figure out how many bits the system's random number generator uses.
2849 `random' and `lrand48' are assumed to return 31 usable bits.
2850 BSD `rand' returns a 31 bit value but the low order bits are unusable;
2851 so we'll shift it and treat it like the 15-bit USG `rand'. */
2855 # define RAND_BITS 31
2856 # else /* !HAVE_RANDOM */
2857 # ifdef HAVE_LRAND48
2858 # define RAND_BITS 31
2859 # define random lrand48
2860 # else /* !HAVE_LRAND48 */
2861 # define RAND_BITS 15
2862 # if RAND_MAX == 32767
2863 # define random rand
2864 # else /* RAND_MAX != 32767 */
2865 # if RAND_MAX == 2147483647
2866 # define random() (rand () >> 16)
2867 # else /* RAND_MAX != 2147483647 */
2869 # define random rand
2871 # define random() (rand () >> 16)
2873 # endif /* RAND_MAX != 2147483647 */
2874 # endif /* RAND_MAX != 32767 */
2875 # endif /* !HAVE_LRAND48 */
2876 # endif /* !HAVE_RANDOM */
2877 #endif /* !RAND_BITS */
2884 srandom ((unsigned int)arg
);
2886 # ifdef HAVE_LRAND48
2889 srand ((unsigned int)arg
);
2895 * Build a full Emacs-sized word out of whatever we've got.
2896 * This suffices even for a 64-bit architecture with a 15-bit rand.
2901 long val
= random ();
2902 #if VALBITS > RAND_BITS
2903 val
= (val
<< RAND_BITS
) ^ random ();
2904 #if VALBITS > 2*RAND_BITS
2905 val
= (val
<< RAND_BITS
) ^ random ();
2906 #if VALBITS > 3*RAND_BITS
2907 val
= (val
<< RAND_BITS
) ^ random ();
2908 #if VALBITS > 4*RAND_BITS
2909 val
= (val
<< RAND_BITS
) ^ random ();
2910 #endif /* need at least 5 */
2911 #endif /* need at least 4 */
2912 #endif /* need at least 3 */
2913 #endif /* need at least 2 */
2914 return val
& ((1L << VALBITS
) - 1);
2917 #ifdef WRONG_NAME_INSQUE
2930 /* If any place else asks for the TERM variable,
2931 allow it to be overridden with the EMACS_TERM variable
2932 before attempting to translate the logical name TERM. As a last
2933 resort, ask for VAX C's special idea of the TERM variable. */
2940 static char buf
[256];
2941 static struct dsc$descriptor_s equiv
2942 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2943 static struct dsc$descriptor_s d_name
2944 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2947 if (!strcmp (name
, "TERM"))
2949 val
= (char *) getenv ("EMACS_TERM");
2954 d_name
.dsc$w_length
= strlen (name
);
2955 d_name
.dsc$a_pointer
= name
;
2956 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2958 char *str
= (char *) xmalloc (eqlen
+ 1);
2959 bcopy (buf
, str
, eqlen
);
2961 /* This is a storage leak, but a pain to fix. With luck,
2962 no one will ever notice. */
2965 return (char *) getenv (name
);
2970 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2971 to force a call on the debugger from within the image. */
2976 LIB$
SIGNAL (SS$_DEBUG
);
2982 #ifdef LINK_CRTL_SHARE
2983 #ifdef SHARABLE_LIB_BUG
2984 /* Variables declared noshare and initialized in sharable libraries
2985 cannot be shared. The VMS linker incorrectly forces you to use a private
2986 version which is uninitialized... If not for this "feature", we
2987 could use the C library definition of sys_nerr and sys_errlist. */
2989 char *sys_errlist
[] =
2993 "no such file or directory",
2995 "interrupted system call",
2997 "no such device or address",
2998 "argument list too long",
2999 "exec format error",
3002 "no more processes",
3003 "not enough memory",
3004 "permission denied",
3006 "block device required",
3007 "mount devices busy",
3009 "cross-device link",
3014 "file table overflow",
3015 "too many open files",
3019 "no space left on device",
3021 "read-only file system",
3027 "vax/vms specific error code nontranslatable error"
3029 #endif /* SHARABLE_LIB_BUG */
3030 #endif /* LINK_CRTL_SHARE */
3033 #ifndef HAVE_STRERROR
3039 extern char *sys_errlist
[];
3040 extern int sys_nerr
;
3042 if (errnum
>= 0 && errnum
< sys_nerr
)
3043 return sys_errlist
[errnum
];
3044 return (char *) "Unknown error";
3046 #endif /* not WINDOWSNT */
3047 #endif /* ! HAVE_STRERROR */
3049 #ifdef INTERRUPTIBLE_OPEN
3053 sys_open (path
, oflag
, mode
)
3057 register int rtnval
;
3059 while ((rtnval
= open (path
, oflag
, mode
)) == -1
3060 && (errno
== EINTR
));
3064 #endif /* INTERRUPTIBLE_OPEN */
3066 #ifdef INTERRUPTIBLE_CLOSE
3073 register int rtnval
;
3075 while ((rtnval
= close (fd
)) == -1
3076 && (errno
== EINTR
))
3079 /* If close is interrupted SunOS 4.1 may or may not have closed the
3080 file descriptor. If it did the second close will fail with
3081 errno = EBADF. That means we have succeeded. */
3082 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3088 #endif /* INTERRUPTIBLE_CLOSE */
3090 #ifdef INTERRUPTIBLE_IO
3093 sys_read (fildes
, buf
, nbyte
)
3098 register int rtnval
;
3100 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3101 && (errno
== EINTR
));
3106 sys_write (fildes
, buf
, nbyte
)
3111 register int rtnval
, bytes_written
;
3117 rtnval
= write (fildes
, buf
, nbyte
);
3124 return (bytes_written
? bytes_written
: -1);
3129 bytes_written
+= rtnval
;
3131 return (bytes_written
);
3134 #endif /* INTERRUPTIBLE_IO */
3139 * Substitute fork for vfork on USG flavors.
3147 #endif /* not WINDOWSNT */
3148 #endif /* not HAVE_VFORK */
3152 * All of the following are for USG.
3154 * On USG systems the system calls are INTERRUPTIBLE by signals
3155 * that the user program has elected to catch. Thus the system call
3156 * must be retried in these cases. To handle this without massive
3157 * changes in the source code, we remap the standard system call names
3158 * to names for our own functions in sysdep.c that do the system call
3159 * with retries. Actually, for portability reasons, it is good
3160 * programming practice, as this example shows, to limit all actual
3161 * system calls to a single occurrence in the source. Sure, this
3162 * adds an extra level of function call overhead but it is almost
3163 * always negligible. Fred Fish, Unisoft Systems Inc.
3166 #ifndef HAVE_SYS_SIGLIST
3167 char *sys_siglist
[NSIG
+ 1] =
3170 /* AIX has changed the signals a bit */
3171 "bogus signal", /* 0 */
3172 "hangup", /* 1 SIGHUP */
3173 "interrupt", /* 2 SIGINT */
3174 "quit", /* 3 SIGQUIT */
3175 "illegal instruction", /* 4 SIGILL */
3176 "trace trap", /* 5 SIGTRAP */
3177 "IOT instruction", /* 6 SIGIOT */
3178 "crash likely", /* 7 SIGDANGER */
3179 "floating point exception", /* 8 SIGFPE */
3180 "kill", /* 9 SIGKILL */
3181 "bus error", /* 10 SIGBUS */
3182 "segmentation violation", /* 11 SIGSEGV */
3183 "bad argument to system call", /* 12 SIGSYS */
3184 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3185 "alarm clock", /* 14 SIGALRM */
3186 "software termination signum", /* 15 SIGTERM */
3187 "user defined signal 1", /* 16 SIGUSR1 */
3188 "user defined signal 2", /* 17 SIGUSR2 */
3189 "death of a child", /* 18 SIGCLD */
3190 "power-fail restart", /* 19 SIGPWR */
3191 "bogus signal", /* 20 */
3192 "bogus signal", /* 21 */
3193 "bogus signal", /* 22 */
3194 "bogus signal", /* 23 */
3195 "bogus signal", /* 24 */
3196 "LAN I/O interrupt", /* 25 SIGAIO */
3197 "PTY I/O interrupt", /* 26 SIGPTY */
3198 "I/O intervention required", /* 27 SIGIOINT */
3200 "HFT grant", /* 28 SIGGRANT */
3201 "HFT retract", /* 29 SIGRETRACT */
3202 "HFT sound done", /* 30 SIGSOUND */
3203 "HFT input ready", /* 31 SIGMSG */
3206 "bogus signal", /* 0 */
3207 "hangup", /* 1 SIGHUP */
3208 "interrupt", /* 2 SIGINT */
3209 "quit", /* 3 SIGQUIT */
3210 "illegal instruction", /* 4 SIGILL */
3211 "trace trap", /* 5 SIGTRAP */
3212 "IOT instruction", /* 6 SIGIOT */
3213 "EMT instruction", /* 7 SIGEMT */
3214 "floating point exception", /* 8 SIGFPE */
3215 "kill", /* 9 SIGKILL */
3216 "bus error", /* 10 SIGBUS */
3217 "segmentation violation", /* 11 SIGSEGV */
3218 "bad argument to system call", /* 12 SIGSYS */
3219 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3220 "alarm clock", /* 14 SIGALRM */
3221 "software termination signum", /* 15 SIGTERM */
3222 "user defined signal 1", /* 16 SIGUSR1 */
3223 "user defined signal 2", /* 17 SIGUSR2 */
3224 "death of a child", /* 18 SIGCLD */
3225 "power-fail restart", /* 19 SIGPWR */
3227 "window size change", /* 20 SIGWINCH */
3228 "urgent socket condition", /* 21 SIGURG */
3229 "pollable event occurred", /* 22 SIGPOLL */
3230 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */
3231 "user stop requested from tty", /* 24 SIGTSTP */
3232 "stopped process has been continued", /* 25 SIGCONT */
3233 "background tty read attempted", /* 26 SIGTTIN */
3234 "background tty write attempted", /* 27 SIGTTOU */
3235 "virtual timer expired", /* 28 SIGVTALRM */
3236 "profiling timer expired", /* 29 SIGPROF */
3237 "exceeded cpu limit", /* 30 SIGXCPU */
3238 "exceeded file size limit", /* 31 SIGXFSZ */
3239 "process's lwps are blocked", /* 32 SIGWAITING */
3240 "special signal used by thread library", /* 33 SIGLWP */
3242 "Special Signal Used By CPR", /* 34 SIGFREEZE */
3245 "Special Signal Used By CPR", /* 35 SIGTHAW */
3248 #endif /* not AIX */
3251 #endif /* HAVE_SYS_SIGLIST */
3254 * Warning, this function may not duplicate 4.2 action properly
3255 * under error conditions.
3259 /* In 4.1, param.h fails to define this. */
3260 #define MAXPATHLEN 1024
3269 char *npath
, *spath
;
3270 extern char *getcwd ();
3272 BLOCK_INPUT
; /* getcwd uses malloc */
3273 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3276 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3277 up to first slash. Should be harmless on other systems. */
3278 while (*npath
&& *npath
!= '/')
3280 strcpy (pathname
, npath
);
3281 free (spath
); /* getcwd uses malloc */
3286 #endif /* HAVE_GETWD */
3289 * Emulate rename using unlink/link. Note that this is
3290 * only partially correct. Also, doesn't enforce restriction
3291 * that files be of same type (regular->regular, dir->dir, etc).
3300 if (access (from
, 0) == 0)
3303 if (link (from
, to
) == 0)
3304 if (unlink (from
) == 0)
3316 /* HPUX curses library references perror, but as far as we know
3317 it won't be called. Anyway this definition will do for now. */
3323 #endif /* not HAVE_PERROR */
3329 * Emulate BSD dup2. First close newd if it already exists.
3330 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3331 * until we are, then close the unsuccessful ones.
3338 register int fd
, ret
;
3343 fd
= fcntl (oldd
, F_DUPFD
, newd
);
3345 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, strerror (errno
));
3352 ret
= dup2 (old
,new);
3358 #endif /* not HAVE_DUP2 */
3361 * Gettimeofday. Simulate as much as possible. Only accurate
3362 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3363 * Only needed when subprocesses are defined.
3368 #ifndef HAVE_GETTIMEOFDAY
3373 gettimeofday (tp
, tzp
)
3375 struct timezone
*tzp
;
3377 extern long time ();
3379 tp
->tv_sec
= time ((long *)0);
3382 tzp
->tz_minuteswest
= -1;
3389 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3392 * This function will go away as soon as all the stubs fixed. (fnf)
3399 printf ("%s not yet implemented\r\n", badfunc
);
3408 char *sys_siglist
[NSIG
+ 1] =
3410 "null signal", /* 0 SIGNULL */
3411 "hangup", /* 1 SIGHUP */
3412 "interrupt", /* 2 SIGINT */
3413 "quit", /* 3 SIGQUIT */
3414 "illegal instruction", /* 4 SIGILL */
3415 "trace trap", /* 5 SIGTRAP */
3416 "abort termination", /* 6 SIGABRT */
3417 "SIGEMT", /* 7 SIGEMT */
3418 "floating point exception", /* 8 SIGFPE */
3419 "kill", /* 9 SIGKILL */
3420 "bus error", /* 10 SIGBUS */
3421 "segmentation violation", /* 11 SIGSEGV */
3422 "bad argument to system call", /* 12 SIGSYS */
3423 "write on a pipe with no reader", /* 13 SIGPIPE */
3424 "alarm clock", /* 14 SIGALRM */
3425 "software termination signal", /* 15 SIGTERM */
3426 "user defined signal 1", /* 16 SIGUSR1 */
3427 "user defined signal 2", /* 17 SIGUSR2 */
3428 "child stopped or terminated", /* 18 SIGCLD */
3429 "power-fail restart", /* 19 SIGPWR */
3430 "window size changed", /* 20 SIGWINCH */
3431 "undefined", /* 21 */
3432 "pollable event occurred", /* 22 SIGPOLL */
3433 "sendable stop signal not from tty", /* 23 SIGSTOP */
3434 "stop signal from tty", /* 24 SIGSTP */
3435 "continue a stopped process", /* 25 SIGCONT */
3436 "attempted background tty read", /* 26 SIGTTIN */
3437 "attempted background tty write", /* 27 SIGTTOU */
3438 "undefined", /* 28 */
3439 "undefined", /* 29 */
3440 "undefined", /* 30 */
3441 "undefined", /* 31 */
3442 "undefined", /* 32 */
3443 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
3444 "I/O is possible", /* 34 SIGIO */
3445 "exceeded cpu time limit", /* 35 SIGXCPU */
3446 "exceeded file size limit", /* 36 SIGXFSZ */
3447 "virtual time alarm", /* 37 SIGVTALRM */
3448 "profiling time alarm", /* 38 SIGPROF */
3449 "undefined", /* 39 */
3450 "file record locks revoked", /* 40 SIGLOST */
3451 "undefined", /* 41 */
3452 "undefined", /* 42 */
3453 "undefined", /* 43 */
3454 "undefined", /* 44 */
3455 "undefined", /* 45 */
3456 "undefined", /* 46 */
3457 "undefined", /* 47 */
3458 "undefined", /* 48 */
3459 "undefined", /* 49 */
3460 "undefined", /* 50 */
3461 "undefined", /* 51 */
3462 "undefined", /* 52 */
3463 "undefined", /* 53 */
3464 "undefined", /* 54 */
3465 "undefined", /* 55 */
3466 "undefined", /* 56 */
3467 "undefined", /* 57 */
3468 "undefined", /* 58 */
3469 "undefined", /* 59 */
3470 "undefined", /* 60 */
3471 "undefined", /* 61 */
3472 "undefined", /* 62 */
3473 "undefined", /* 63 */
3474 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3480 /* Directory routines for systems that don't have them. */
3482 #ifdef SYSV_SYSTEM_DIR
3486 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
3490 register DIR *dirp
; /* stream from opendir */
3494 rtnval
= sys_close (dirp
->dd_fd
);
3496 /* Some systems (like Solaris) allocate the buffer and the DIR all
3497 in one block. Why in the world are we freeing this ourselves
3499 #if ! (defined (sun) && defined (USG5_4))
3500 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3502 xfree ((char *) dirp
);
3506 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3507 #endif /* SYSV_SYSTEM_DIR */
3509 #ifdef NONSYSTEM_DIR_LIBRARY
3513 char *filename
; /* name of directory */
3515 register DIR *dirp
; /* -> malloc'ed storage */
3516 register int fd
; /* file descriptor for read */
3517 struct stat sbuf
; /* result of fstat */
3519 fd
= sys_open (filename
, 0);
3524 if (fstat (fd
, &sbuf
) < 0
3525 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3526 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
3530 return 0; /* bad luck today */
3535 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3542 register DIR *dirp
; /* stream from opendir */
3544 sys_close (dirp
->dd_fd
);
3545 xfree ((char *) dirp
);
3553 ino_t od_ino
; /* inode */
3554 char od_name
[DIRSIZ
]; /* filename */
3556 #endif /* not VMS */
3558 struct direct dir_static
; /* simulated directory contents */
3563 register DIR *dirp
; /* stream from opendir */
3566 register struct olddir
*dp
; /* -> directory data */
3568 register struct dir$_name
*dp
; /* -> directory data */
3569 register struct dir$_version
*dv
; /* -> version data */
3574 if (dirp
->dd_loc
>= dirp
->dd_size
)
3575 dirp
->dd_loc
= dirp
->dd_size
= 0;
3577 if (dirp
->dd_size
== 0 /* refill buffer */
3578 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3582 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3583 dirp
->dd_loc
+= sizeof (struct olddir
);
3585 if (dp
->od_ino
!= 0) /* not deleted entry */
3587 dir_static
.d_ino
= dp
->od_ino
;
3588 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3589 dir_static
.d_name
[DIRSIZ
] = '\0';
3590 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3591 dir_static
.d_reclen
= sizeof (struct direct
)
3593 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3594 return &dir_static
; /* -> simulated structure */
3597 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3598 if (dirp
->dd_loc
== 0)
3599 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3600 : dp
->dir$b_namecount
;
3601 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3602 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3603 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3604 dir_static
.d_reclen
= sizeof (struct direct
)
3606 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3607 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3608 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3609 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3616 /* readdirver is just like readdir except it returns all versions of a file
3617 as separate entries. */
3622 register DIR *dirp
; /* stream from opendir */
3624 register struct dir$_name
*dp
; /* -> directory data */
3625 register struct dir$_version
*dv
; /* -> version data */
3627 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3628 dirp
->dd_loc
= dirp
->dd_size
= 0;
3630 if (dirp
->dd_size
== 0 /* refill buffer */
3631 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3634 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3635 if (dirp
->dd_loc
== 0)
3636 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3637 : dp
->dir$b_namecount
;
3638 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3639 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3640 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3641 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3642 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3643 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3644 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3645 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3651 #endif /* NONSYSTEM_DIR_LIBRARY */
3655 set_file_times (filename
, atime
, mtime
)
3657 EMACS_TIME atime
, mtime
;
3660 struct timeval tv
[2];
3663 return utimes (filename
, tv
);
3664 #else /* not HAVE_UTIMES */
3666 utb
.actime
= EMACS_SECS (atime
);
3667 utb
.modtime
= EMACS_SECS (mtime
);
3668 return utime (filename
, &utb
);
3669 #endif /* not HAVE_UTIMES */
3672 /* mkdir and rmdir functions, for systems which don't have them. */
3676 * Written by Robert Rother, Mariah Corporation, August 1985.
3678 * If you want it, it's yours. All I ask in return is that if you
3679 * figure out how to do this in a Bourne Shell script you send me
3681 * sdcsvax!rmr or rmr@uscd
3683 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3684 * subroutine. 11Mar86; hoptoad!gnu
3686 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3687 * subroutine didn't return EEXIST. It does now.
3693 #ifdef MKDIR_PROTOTYPE
3697 mkdir (dpath
, dmode
)
3702 int cpid
, status
, fd
;
3703 struct stat statbuf
;
3705 if (stat (dpath
, &statbuf
) == 0)
3707 errno
= EEXIST
; /* Stat worked, so it already exists */
3711 /* If stat fails for a reason other than non-existence, return error */
3712 if (errno
!= ENOENT
)
3715 synch_process_alive
= 1;
3716 switch (cpid
= fork ())
3719 case -1: /* Error in fork */
3720 return (-1); /* Errno is set already */
3722 case 0: /* Child process */
3724 * Cheap hack to set mode of new directory. Since this
3725 * child process is going away anyway, we zap its umask.
3726 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3727 * directory. Does anybody care?
3729 status
= umask (0); /* Get current umask */
3730 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3731 fd
= sys_open("/dev/null", 2);
3738 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3739 _exit (-1); /* Can't exec /bin/mkdir */
3741 default: /* Parent process */
3742 wait_for_termination (cpid
);
3745 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3747 errno
= EIO
; /* We don't know why, but */
3748 return -1; /* /bin/mkdir failed */
3753 #endif /* not HAVE_MKDIR */
3760 int cpid
, status
, fd
;
3761 struct stat statbuf
;
3763 if (stat (dpath
, &statbuf
) != 0)
3765 /* Stat just set errno. We don't have to */
3769 synch_process_alive
= 1;
3770 switch (cpid
= fork ())
3773 case -1: /* Error in fork */
3774 return (-1); /* Errno is set already */
3776 case 0: /* Child process */
3777 fd
= sys_open("/dev/null", 2);
3784 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3785 _exit (-1); /* Can't exec /bin/rmdir */
3787 default: /* Parent process */
3788 wait_for_termination (cpid
);
3791 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3793 errno
= EIO
; /* We don't know why, but */
3794 return -1; /* /bin/rmdir failed */
3799 #endif /* !HAVE_RMDIR */
3803 /* Functions for VMS */
3805 #include "vms-pwd.h"
3810 /* Return as a string the VMS error string pertaining to STATUS.
3811 Reuses the same static buffer each time it is called. */
3815 int status
; /* VMS status code */
3819 static char buf
[257];
3821 bufadr
[0] = sizeof buf
- 1;
3822 bufadr
[1] = (int) buf
;
3823 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3824 return "untranslatable VMS error status";
3832 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3833 * not work correctly. (It also doesn't work well in version 2.3.)
3838 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3839 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3843 unsigned short s_buflen
;
3844 unsigned short s_code
;
3846 unsigned short *s_retlenadr
;
3850 #define buflen s.s_buflen
3851 #define code s.s_code
3852 #define bufadr s.s_bufadr
3853 #define retlenadr s.s_retlenadr
3855 #define R_OK 4 /* test for read permission */
3856 #define W_OK 2 /* test for write permission */
3857 #define X_OK 1 /* test for execute (search) permission */
3858 #define F_OK 0 /* test for presence of file */
3861 sys_access (path
, mode
)
3865 static char *user
= NULL
;
3868 /* translate possible directory spec into .DIR file name, so brain-dead
3869 * access can treat the directory like a file. */
3870 if (directory_file_name (path
, dir_fn
))
3874 return access (path
, mode
);
3875 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3881 unsigned short int dummy
;
3883 static int constant
= ACL$C_FILE
;
3884 DESCRIPTOR (path_desc
, path
);
3885 DESCRIPTOR (user_desc
, user
);
3889 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3892 acces
|= CHP$M_READ
;
3894 acces
|= CHP$M_WRITE
;
3895 itemlst
[0].buflen
= sizeof (int);
3896 itemlst
[0].code
= CHP$_FLAGS
;
3897 itemlst
[0].bufadr
= (char *) &flags
;
3898 itemlst
[0].retlenadr
= &dummy
;
3899 itemlst
[1].buflen
= sizeof (int);
3900 itemlst
[1].code
= CHP$_ACCESS
;
3901 itemlst
[1].bufadr
= (char *) &acces
;
3902 itemlst
[1].retlenadr
= &dummy
;
3903 itemlst
[2].end
= CHP$_END
;
3904 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3905 return stat
== SS$_NORMAL
? 0 : -1;
3909 #else /* not VMS4_4 */
3912 #define ACE$M_WRITE 2
3913 #define ACE$C_KEYID 1
3915 static unsigned short memid
, grpid
;
3916 static unsigned int uic
;
3918 /* Called from init_sys_modes, so it happens not very often
3919 but at least each time Emacs is loaded. */
3921 sys_access_reinit ()
3927 sys_access (filename
, type
)
3933 int status
, size
, i
, typecode
, acl_controlled
;
3934 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3935 union prvdef prvmask
;
3937 /* Get UIC and GRP values for protection checking. */
3940 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3943 memid
= uic
& 0xFFFF;
3947 if (type
!= 2) /* not checking write access */
3948 return access (filename
, type
);
3950 /* Check write protection. */
3952 #define CHECKPRIV(bit) (prvmask.bit)
3953 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3955 /* Find privilege bits */
3956 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3958 error ("Unable to find privileges: %s", vmserrstr (status
));
3959 if (CHECKPRIV (PRV$V_BYPASS
))
3960 return 0; /* BYPASS enabled */
3962 fab
.fab$b_fac
= FAB$M_GET
;
3963 fab
.fab$l_fna
= filename
;
3964 fab
.fab$b_fns
= strlen (filename
);
3965 fab
.fab$l_xab
= &xab
;
3966 xab
= cc$rms_xabpro
;
3967 xab
.xab$l_aclbuf
= aclbuf
;
3968 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3969 status
= SYS$
OPEN (&fab
, 0, 0);
3972 SYS$
CLOSE (&fab
, 0, 0);
3973 /* Check system access */
3974 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
3976 /* Check ACL entries, if any */
3978 if (xab
.xab$w_acllen
> 0)
3981 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3982 while (*aclptr
&& aclptr
< aclend
)
3984 size
= (*aclptr
& 0xff) / 4;
3985 typecode
= (*aclptr
>> 8) & 0xff;
3986 if (typecode
== ACE$C_KEYID
)
3987 for (i
= size
- 1; i
> 1; i
--)
3988 if (aclptr
[i
] == uic
)
3991 if (aclptr
[1] & ACE$M_WRITE
)
3992 return 0; /* Write access through ACL */
3994 aclptr
= &aclptr
[size
];
3996 if (acl_controlled
) /* ACL specified, prohibits write access */
3999 /* No ACL entries specified, check normal protection */
4000 if (WRITABLE (XAB$V_WLD
)) /* World writable */
4002 if (WRITABLE (XAB$V_GRP
) &&
4003 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
4004 return 0; /* Group writable */
4005 if (WRITABLE (XAB$V_OWN
) &&
4006 (xab
.xab$l_uic
& 0xFFFF) == memid
)
4007 return 0; /* Owner writable */
4009 return -1; /* Not writable */
4011 #endif /* not VMS4_4 */
4014 static char vtbuf
[NAM$C_MAXRSS
+1];
4016 /* translate a vms file spec to a unix path */
4018 sys_translate_vms (vfile
)
4029 /* leading device or logical name is a root directory */
4030 if (p
= strchr (vfile
, ':'))
4039 if (*p
== '[' || *p
== '<')
4041 while (*++vfile
!= *p
+ 2)
4045 if (vfile
[-1] == *p
)
4068 static char utbuf
[NAM$C_MAXRSS
+1];
4070 /* translate a unix path to a VMS file spec */
4072 sys_translate_unix (ufile
)
4095 if (index (&ufile
[1], '/'))
4102 if (index (&ufile
[1], '/'))
4109 if (strncmp (ufile
, "./", 2) == 0)
4116 ufile
++; /* skip the dot */
4117 if (index (&ufile
[1], '/'))
4122 else if (strncmp (ufile
, "../", 3) == 0)
4130 ufile
+= 2; /* skip the dots */
4131 if (index (&ufile
[1], '/'))
4156 extern char *getcwd ();
4158 #define MAXPATHLEN 1024
4160 ptr
= xmalloc (MAXPATHLEN
);
4161 val
= getcwd (ptr
, MAXPATHLEN
);
4167 strcpy (pathname
, ptr
);
4176 long item_code
= JPI$_OWNER
;
4177 unsigned long parent_id
;
4180 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4183 vaxc$errno
= status
;
4193 return (getgid () << 16) | getuid ();
4197 sys_read (fildes
, buf
, nbyte
)
4202 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4207 sys_write (fildes
, buf
, nbyte
)
4212 register int nwrote
, rtnval
= 0;
4214 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4220 return rtnval
? rtnval
: -1;
4221 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4222 return rtnval
? rtnval
: -1;
4223 return (rtnval
+ nwrote
);
4228 * VAX/VMS VAX C RTL really loses. It insists that records
4229 * end with a newline (carriage return) character, and if they
4230 * don't it adds one (nice of it isn't it!)
4232 * Thus we do this stupidity below.
4236 sys_write (fildes
, buf
, nbytes
)
4239 unsigned int nbytes
;
4246 fstat (fildes
, &st
);
4252 /* Handle fixed-length files with carriage control. */
4253 if (st
.st_fab_rfm
== FAB$C_FIX
4254 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4256 len
= st
.st_fab_mrs
;
4257 retval
= write (fildes
, p
, min (len
, nbytes
));
4260 retval
++; /* This skips the implied carriage control */
4264 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4265 while (*e
!= '\n' && e
> p
) e
--;
4266 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4267 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4269 retval
= write (fildes
, p
, len
);
4280 /* Create file NEW copying its attributes from file OLD. If
4281 OLD is 0 or does not exist, create based on the value of
4284 /* Protection value the file should ultimately have.
4285 Set by create_copy_attrs, and use by rename_sansversions. */
4286 static unsigned short int fab_final_pro
;
4289 creat_copy_attrs (old
, new)
4292 struct FAB fab
= cc$rms_fab
;
4293 struct XABPRO xabpro
;
4294 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4295 extern int vms_stmlf_recfm
;
4299 fab
.fab$b_fac
= FAB$M_GET
;
4300 fab
.fab$l_fna
= old
;
4301 fab
.fab$b_fns
= strlen (old
);
4302 fab
.fab$l_xab
= (char *) &xabpro
;
4303 xabpro
= cc$rms_xabpro
;
4304 xabpro
.xab$l_aclbuf
= aclbuf
;
4305 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4306 /* Call $OPEN to fill in the fab & xabpro fields. */
4307 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4309 SYS$
CLOSE (&fab
, 0, 0);
4310 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4311 if (xabpro
.xab$w_acllen
> 0)
4313 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4314 /* If the acl buffer was too short, redo open with longer one.
4315 Wouldn't need to do this if there were some system imposed
4316 limit on the size of an ACL, but I can't find any such. */
4318 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4319 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4320 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4321 SYS$
CLOSE (&fab
, 0, 0);
4327 xabpro
.xab$l_aclbuf
= 0;
4332 fab
.fab$l_fna
= new;
4333 fab
.fab$b_fns
= strlen (new);
4337 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4338 fab
.fab$b_rat
= FAB$M_CR
;
4341 /* Set the file protections such that we will be able to manipulate
4342 this file. Once we are done writing and renaming it, we will set
4343 the protections back. */
4345 fab_final_pro
= xabpro
.xab$w_pro
;
4347 SYS$
SETDFPROT (0, &fab_final_pro
);
4348 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4350 /* Create the new file with either default attrs or attrs copied
4352 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4354 SYS$
CLOSE (&fab
, 0, 0);
4355 /* As this is a "replacement" for creat, return a file descriptor
4356 opened for writing. */
4357 return open (new, O_WRONLY
);
4362 #include <varargs.h>
4365 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4370 sys_creat (va_alist
)
4373 va_list list_incrementer
;
4376 int rfd
; /* related file descriptor */
4377 int fd
; /* Our new file descriptor */
4384 extern int vms_stmlf_recfm
;
4387 va_start (list_incrementer
);
4388 name
= va_arg (list_incrementer
, char *);
4389 mode
= va_arg (list_incrementer
, int);
4391 rfd
= va_arg (list_incrementer
, int);
4392 va_end (list_incrementer
);
4395 /* Use information from the related file descriptor to set record
4396 format of the newly created file. */
4397 fstat (rfd
, &st_buf
);
4398 switch (st_buf
.st_fab_rfm
)
4401 strcpy (rfm
, "rfm = fix");
4402 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4403 strcpy (rat
, "rat = ");
4404 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4406 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4407 strcat (rat
, "ftn");
4408 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4409 strcat (rat
, "prn");
4410 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4411 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4412 strcat (rat
, ", blk");
4414 strcat (rat
, "blk");
4415 return creat (name
, 0, rfm
, rat
, mrs
);
4418 strcpy (rfm
, "rfm = vfc");
4419 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4420 strcpy (rat
, "rat = ");
4421 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4423 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4424 strcat (rat
, "ftn");
4425 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4426 strcat (rat
, "prn");
4427 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4428 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4429 strcat (rat
, ", blk");
4431 strcat (rat
, "blk");
4432 return creat (name
, 0, rfm
, rat
, fsz
);
4435 strcpy (rfm
, "rfm = stm");
4439 strcpy (rfm
, "rfm = stmcr");
4443 strcpy (rfm
, "rfm = stmlf");
4447 strcpy (rfm
, "rfm = udf");
4451 strcpy (rfm
, "rfm = var");
4454 strcpy (rat
, "rat = ");
4455 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4457 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4458 strcat (rat
, "ftn");
4459 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4460 strcat (rat
, "prn");
4461 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4462 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4463 strcat (rat
, ", blk");
4465 strcat (rat
, "blk");
4469 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4470 strcpy (rat
, "rat=cr");
4472 /* Until the VAX C RTL fixes the many bugs with modes, always use
4473 mode 0 to get the user's default protection. */
4474 fd
= creat (name
, 0, rfm
, rat
);
4475 if (fd
< 0 && errno
== EEXIST
)
4477 if (unlink (name
) < 0)
4478 report_file_error ("delete", build_string (name
));
4479 fd
= creat (name
, 0, rfm
, rat
);
4485 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4487 sys_fwrite (ptr
, size
, num
, fp
)
4488 register char * ptr
;
4491 register int tot
= num
* size
;
4499 * The VMS C library routine creat actually creates a new version of an
4500 * existing file rather than truncating the old version. There are times
4501 * when this is not the desired behavior, for instance, when writing an
4502 * auto save file (you only want one version), or when you don't have
4503 * write permission in the directory containing the file (but the file
4504 * itself is writable). Hence this routine, which is equivalent to
4505 * "close (creat (fn, 0));" on Unix if fn already exists.
4511 struct FAB xfab
= cc$rms_fab
;
4512 struct RAB xrab
= cc$rms_rab
;
4515 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4516 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4517 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4518 xfab
.fab$l_fna
= fn
;
4519 xfab
.fab$b_fns
= strlen (fn
);
4520 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4522 xrab
.rab$l_fab
= &xfab
;
4524 /* This gibberish opens the file, positions to the first record, and
4525 deletes all records from there until the end of file. */
4526 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4528 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4529 (SYS$
FIND (&xrab
) & 01) == 01 &&
4530 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4541 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4542 SYSPRV or a readable SYSUAF.DAT. */
4548 * Routine to read the VMS User Authorization File and return
4549 * a specific user's record.
4552 static struct UAF retuaf
;
4555 get_uaf_name (uname
)
4562 uaf_fab
= cc$rms_fab
;
4563 uaf_rab
= cc$rms_rab
;
4564 /* initialize fab fields */
4565 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4566 uaf_fab
.fab$b_fns
= 21;
4567 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4568 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4569 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4570 /* initialize rab fields */
4571 uaf_rab
.rab$l_fab
= &uaf_fab
;
4572 /* open the User Authorization File */
4573 status
= SYS$
OPEN (&uaf_fab
);
4577 vaxc$errno
= status
;
4580 status
= SYS$
CONNECT (&uaf_rab
);
4584 vaxc$errno
= status
;
4587 /* read the requested record - index is in uname */
4588 uaf_rab
.rab$l_kbf
= uname
;
4589 uaf_rab
.rab$b_ksz
= strlen (uname
);
4590 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4591 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4592 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4593 status
= SYS$
GET (&uaf_rab
);
4597 vaxc$errno
= status
;
4600 /* close the User Authorization File */
4601 status
= SYS$
DISCONNECT (&uaf_rab
);
4605 vaxc$errno
= status
;
4608 status
= SYS$
CLOSE (&uaf_fab
);
4612 vaxc$errno
= status
;
4626 uaf_fab
= cc$rms_fab
;
4627 uaf_rab
= cc$rms_rab
;
4628 /* initialize fab fields */
4629 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4630 uaf_fab
.fab$b_fns
= 21;
4631 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4632 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4633 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4634 /* initialize rab fields */
4635 uaf_rab
.rab$l_fab
= &uaf_fab
;
4636 /* open the User Authorization File */
4637 status
= SYS$
OPEN (&uaf_fab
);
4641 vaxc$errno
= status
;
4644 status
= SYS$
CONNECT (&uaf_rab
);
4648 vaxc$errno
= status
;
4651 /* read the requested record - index is in uic */
4652 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4653 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4654 uaf_rab
.rab$b_ksz
= sizeof uic
;
4655 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4656 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4657 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4658 status
= SYS$
GET (&uaf_rab
);
4662 vaxc$errno
= status
;
4665 /* close the User Authorization File */
4666 status
= SYS$
DISCONNECT (&uaf_rab
);
4670 vaxc$errno
= status
;
4673 status
= SYS$
CLOSE (&uaf_fab
);
4677 vaxc$errno
= status
;
4683 static struct passwd retpw
;
4691 /* copy these out first because if the username is 32 chars, the next
4692 section will overwrite the first byte of the UIC */
4693 retpw
.pw_uid
= up
->uaf$w_mem
;
4694 retpw
.pw_gid
= up
->uaf$w_grp
;
4696 /* I suppose this is not the best style, to possibly overwrite one
4697 byte beyond the end of the field, but what the heck... */
4698 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4699 while (ptr
[-1] == ' ')
4702 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4704 /* the rest of these are counted ascii strings */
4705 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4706 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4707 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4708 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4709 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4710 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4711 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4712 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4716 #else /* not READ_SYSUAF */
4717 static struct passwd retpw
;
4718 #endif /* not READ_SYSUAF */
4729 unsigned char * full
;
4730 #endif /* READ_SYSUAF */
4735 if ('a' <= *ptr
&& *ptr
<= 'z')
4740 if (!(up
= get_uaf_name (name
)))
4742 return cnv_uaf_pw (up
);
4744 if (strcmp (name
, getenv ("USER")) == 0)
4746 retpw
.pw_uid
= getuid ();
4747 retpw
.pw_gid
= getgid ();
4748 strcpy (retpw
.pw_name
, name
);
4749 if (full
= egetenv ("FULLNAME"))
4750 strcpy (retpw
.pw_gecos
, full
);
4752 *retpw
.pw_gecos
= '\0';
4753 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4754 *retpw
.pw_shell
= '\0';
4759 #endif /* not READ_SYSUAF */
4769 if (!(up
= get_uaf_uic (uid
)))
4771 return cnv_uaf_pw (up
);
4773 if (uid
== sys_getuid ())
4774 return getpwnam (egetenv ("USER"));
4777 #endif /* not READ_SYSUAF */
4780 /* return total address space available to the current process. This is
4781 the sum of the current p0 size, p1 size and free page table entries
4787 unsigned long free_pages
;
4788 unsigned long frep0va
;
4789 unsigned long frep1va
;
4792 item_code
= JPI$_FREPTECNT
;
4793 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4796 vaxc$errno
= status
;
4801 item_code
= JPI$_FREP0VA
;
4802 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4805 vaxc$errno
= status
;
4808 item_code
= JPI$_FREP1VA
;
4809 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4812 vaxc$errno
= status
;
4816 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4820 define_logical_name (varname
, string
)
4824 struct dsc$descriptor_s strdsc
=
4825 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4826 struct dsc$descriptor_s envdsc
=
4827 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4828 struct dsc$descriptor_s lnmdsc
=
4829 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4831 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4835 delete_logical_name (varname
)
4838 struct dsc$descriptor_s envdsc
=
4839 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4840 struct dsc$descriptor_s lnmdsc
=
4841 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4843 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4861 error ("execvp system call not implemented");
4870 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4871 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4872 char from_esn
[NAM$C_MAXRSS
];
4873 char to_esn
[NAM$C_MAXRSS
];
4875 from_fab
.fab$l_fna
= from
;
4876 from_fab
.fab$b_fns
= strlen (from
);
4877 from_fab
.fab$l_nam
= &from_nam
;
4878 from_fab
.fab$l_fop
= FAB$M_NAM
;
4880 from_nam
.nam$l_esa
= from_esn
;
4881 from_nam
.nam$b_ess
= sizeof from_esn
;
4883 to_fab
.fab$l_fna
= to
;
4884 to_fab
.fab$b_fns
= strlen (to
);
4885 to_fab
.fab$l_nam
= &to_nam
;
4886 to_fab
.fab$l_fop
= FAB$M_NAM
;
4888 to_nam
.nam$l_esa
= to_esn
;
4889 to_nam
.nam$b_ess
= sizeof to_esn
;
4891 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4897 if (status
== RMS$_DEV
)
4901 vaxc$errno
= status
;
4906 /* This function renames a file like `rename', but it strips
4907 the version number from the "to" filename, such that the "to" file is
4908 will always be a new version. It also sets the file protection once it is
4909 finished. The protection that we will use is stored in fab_final_pro,
4910 and was set when we did a creat_copy_attrs to create the file that we
4913 We could use the chmod function, but Eunichs uses 3 bits per user category
4914 to describe the protection, and VMS uses 4 (write and delete are separate
4915 bits). To maintain portability, the VMS implementation of `chmod' wires
4916 the W and D bits together. */
4919 static struct fibdef fib
; /* We need this initialized to zero */
4920 char vms_file_written
[NAM$C_MAXRSS
];
4923 rename_sans_version (from
,to
)
4930 struct FAB to_fab
= cc$rms_fab
;
4931 struct NAM to_nam
= cc$rms_nam
;
4932 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4933 struct dsc$descriptor fib_attr
[2]
4934 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4935 char to_esn
[NAM$C_MAXRSS
];
4937 $
DESCRIPTOR (disk
,to_esn
);
4939 to_fab
.fab$l_fna
= to
;
4940 to_fab
.fab$b_fns
= strlen (to
);
4941 to_fab
.fab$l_nam
= &to_nam
;
4942 to_fab
.fab$l_fop
= FAB$M_NAM
;
4944 to_nam
.nam$l_esa
= to_esn
;
4945 to_nam
.nam$b_ess
= sizeof to_esn
;
4947 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4949 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4950 *(to_nam
.nam$l_ver
) = '\0';
4952 stat
= rename (from
, to_esn
);
4956 strcpy (vms_file_written
, to_esn
);
4958 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4959 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4961 /* Now set the file protection to the correct value */
4962 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4964 /* Copy these fields into the fib */
4965 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4966 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4967 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4969 SYS$
CLOSE (&to_fab
, 0, 0);
4971 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4974 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4975 0, 0, 0, &fib_attr
, 0);
4978 stat
= SYS$
DASSGN (chan
);
4981 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4992 unsigned short fid
[3];
4993 char esa
[NAM$C_MAXRSS
];
4996 fab
.fab$l_fop
= FAB$M_OFP
;
4997 fab
.fab$l_fna
= file
;
4998 fab
.fab$b_fns
= strlen (file
);
4999 fab
.fab$l_nam
= &nam
;
5002 nam
.nam$l_esa
= esa
;
5003 nam
.nam$b_ess
= NAM$C_MAXRSS
;
5005 status
= SYS$
PARSE (&fab
);
5006 if ((status
& 1) == 0)
5009 vaxc$errno
= status
;
5012 status
= SYS$
SEARCH (&fab
);
5013 if ((status
& 1) == 0)
5016 vaxc$errno
= status
;
5020 fid
[0] = nam
.nam$w_fid
[0];
5021 fid
[1] = nam
.nam$w_fid
[1];
5022 fid
[2] = nam
.nam$w_fid
[2];
5024 fab
.fab$l_fna
= new;
5025 fab
.fab$b_fns
= strlen (new);
5027 status
= SYS$
PARSE (&fab
);
5028 if ((status
& 1) == 0)
5031 vaxc$errno
= status
;
5035 nam
.nam$w_fid
[0] = fid
[0];
5036 nam
.nam$w_fid
[1] = fid
[1];
5037 nam
.nam$w_fid
[2] = fid
[2];
5039 nam
.nam$l_esa
= nam
.nam$l_name
;
5040 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
5042 status
= SYS$
ENTER (&fab
);
5043 if ((status
& 1) == 0)
5046 vaxc$errno
= status
;
5057 printf ("%s not yet implemented\r\n", badfunc
);
5065 /* Arrange to return a range centered on zero. */
5066 return rand () - (1 << 30);
5078 /* Called from init_sys_modes. */
5084 /* If we're not on an HFT we shouldn't do any of this. We determine
5085 if we are on an HFT by trying to get an HFT error code. If this
5086 call fails, we're not on an HFT. */
5088 if (ioctl (0, HFQERROR
, &junk
) < 0)
5090 #else /* not IBMR2AIX */
5091 if (ioctl (0, HFQEIO
, 0) < 0)
5093 #endif /* not IBMR2AIX */
5095 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5096 as the rubout key's ASCII code. Here this is changed. The bug is that
5097 there's no way to determine the old mapping, so in reset_sys_modes
5098 we need to assume that the normal map had been present. Of course, this
5099 code also doesn't help if on a terminal emulator which doesn't understand
5103 struct hfkeymap keymap
;
5105 buf
.hf_bufp
= (char *)&keymap
;
5106 buf
.hf_buflen
= sizeof (keymap
);
5107 keymap
.hf_nkeys
= 2;
5108 keymap
.hfkey
[0].hf_kpos
= 15;
5109 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5111 keymap
.hfkey
[0].hf_keyidh
= '<';
5112 #else /* not IBMR2AIX */
5113 keymap
.hfkey
[0].hf_page
= '<';
5114 #endif /* not IBMR2AIX */
5115 keymap
.hfkey
[0].hf_char
= 127;
5116 keymap
.hfkey
[1].hf_kpos
= 15;
5117 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5119 keymap
.hfkey
[1].hf_keyidh
= '<';
5120 #else /* not IBMR2AIX */
5121 keymap
.hfkey
[1].hf_page
= '<';
5122 #endif /* not IBMR2AIX */
5123 keymap
.hfkey
[1].hf_char
= 127;
5124 hftctl (0, HFSKBD
, &buf
);
5126 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5128 line_ins_del_ok
= char_ins_del_ok
= 0;
5131 /* Reset the rubout key to backspace. */
5137 struct hfkeymap keymap
;
5141 if (ioctl (0, HFQERROR
, &junk
) < 0)
5143 #else /* not IBMR2AIX */
5144 if (ioctl (0, HFQEIO
, 0) < 0)
5146 #endif /* not IBMR2AIX */
5148 buf
.hf_bufp
= (char *)&keymap
;
5149 buf
.hf_buflen
= sizeof (keymap
);
5150 keymap
.hf_nkeys
= 2;
5151 keymap
.hfkey
[0].hf_kpos
= 15;
5152 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5154 keymap
.hfkey
[0].hf_keyidh
= '<';
5155 #else /* not IBMR2AIX */
5156 keymap
.hfkey
[0].hf_page
= '<';
5157 #endif /* not IBMR2AIX */
5158 keymap
.hfkey
[0].hf_char
= 8;
5159 keymap
.hfkey
[1].hf_kpos
= 15;
5160 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5162 keymap
.hfkey
[1].hf_keyidh
= '<';
5163 #else /* not IBMR2AIX */
5164 keymap
.hfkey
[1].hf_page
= '<';
5165 #endif /* not IBMR2AIX */
5166 keymap
.hfkey
[1].hf_char
= 8;
5167 hftctl (0, HFSKBD
, &buf
);
5174 /* These are included on Sunos 4.1 when we do not use shared libraries.
5175 X11 libraries may refer to these functions but (we hope) do not
5176 actually call them. */
5196 #endif /* USE_DL_STUBS */
5205 register int length
;
5209 long max_str
= 65535;
5211 while (length
> max_str
) {
5212 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5217 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5219 while (length
-- > 0)
5221 #endif /* not VMS */
5224 #endif /* no bzero */
5225 #endif /* BSTRING */
5227 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5230 /* Saying `void' requires a declaration, above, where bcopy is used
5231 and that declaration causes pain for systems where bcopy is a macro. */
5232 bcopy (b1
, b2
, length
)
5235 register int length
;
5238 long max_str
= 65535;
5240 while (length
> max_str
) {
5241 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5247 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5249 while (length
-- > 0)
5251 #endif /* not VMS */
5253 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5258 bcmp (b1
, b2
, length
) /* This could be a macro! */
5261 register int length
;
5264 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5265 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5267 return STR$
COMPARE (&src1
, &src2
);
5269 while (length
-- > 0)
5274 #endif /* not VMS */
5276 #endif /* no bcmp */
5277 #endif /* not BSTRING */