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. */
27 #include "blockinput.h"
30 #define min(x,y) ((x) > (y) ? (y) : (x))
32 /* In this file, open, read and write refer to the system calls,
33 not our sugared interfaces sys_open, sys_read and sys_write.
34 Contrariwise, for systems where we use the system calls directly,
35 define sys_read, etc. here as aliases for them. */
38 #define sys_write write
39 #endif /* `read' is not a macro */
49 #endif /* not WINDOWSNT */
52 #define sys_close close
59 #else /* `open' is a macro */
61 #endif /* `open' is a macro */
63 /* Does anyone other than VMS need this? */
65 #define sys_fwrite fwrite
75 #include <sys/types.h>
79 /* Get _POSIX_VDISABLE, if it is available. */
84 /* Get SI_SRPC_DOMAIN, if it is available. */
85 #ifdef HAVE_SYS_SYSTEMINFO_H
86 #include <sys/systeminfo.h>
89 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
93 #include <sys/param.h>
97 extern unsigned start
__asm__ ("start");
115 #include <sys/file.h>
123 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
127 #ifdef BSD_SYSTEM /* avoid writing defined (BSD_SYSTEM) || defined (USG)
128 because the vms compiler doesn't grok `defined' */
136 #endif /* not 4.1 bsd */
139 #include <sys/ioctl.h>
145 #ifdef BROKEN_TIOCGWINSZ
150 #if defined(USG) || defined(DGUX)
151 #include <sys/utsname.h>
153 #ifndef MEMORY_IN_STRING_H
156 #if defined (TIOCGWINSZ) || defined (ISC4_0)
158 #include <sys/sioctl.h>
161 #include <sys/stream.h>
162 #include <sys/ptem.h>
164 #endif /* TIOCGWINSZ or ISC4_0 */
165 #endif /* USG or DGUX */
167 extern int quit_char
;
171 #include "termhooks.h"
172 #include "termchar.h"
173 #include "termopts.h"
174 #include "dispextern.h"
179 /* In process.h which conflicts with the local copy. */
181 int _CRTAPI1
_spawnlp (int, const char *, const char *, ...);
182 int _CRTAPI1
_getpid (void);
185 #ifdef NONSYSTEM_DIR_LIBRARY
187 #endif /* NONSYSTEM_DIR_LIBRARY */
189 #include "syssignal.h"
196 #ifndef HAVE_STRUCT_UTIMBUF
197 /* We want to use utime rather than utimes, but we couldn't find the
198 structure declaration. We'll use the traditional one. */
206 #ifndef VFORK_RETURN_TYPE
207 #define VFORK_RETURN_TYPE int
210 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
216 #define LNOFLSH 0100000
219 static int baud_convert
[] =
224 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
225 1800, 2400, 4800, 9600, 19200, 38400
229 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
232 #if defined (HAVE_TERMIOS_H) && defined (LINUX)
234 /* HJL's version of libc is said to need this on the Alpha.
235 On the other hand, DEC OSF1 on the Alpha needs ospeed to be a short. */
236 extern speed_t ospeed
;
242 /* The file descriptor for Emacs's input terminal.
243 Under Unix, this is normally zero except when using X;
244 under VMS, we place the input channel number here. */
247 void croak
P_ ((char *));
251 /* Specify a different file descriptor for further input operations. */
260 /* Discard pending input on descriptor input_fd. */
266 struct emacs_tty buf
;
271 /* Discarding input is not safe when the input could contain
272 replies from the X server. So don't do it. */
273 if (read_socket_hook
)
278 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
279 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
285 ioctl (input_fd
, TIOCFLUSH
, &zero
);
287 #else /* not Apollo */
288 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
289 while (dos_keyread () != -1)
291 #else /* not MSDOS */
292 EMACS_GET_TTY (input_fd
, &buf
);
293 EMACS_SET_TTY (input_fd
, &buf
, 0);
294 #endif /* not MSDOS */
295 #endif /* not Apollo */
297 #endif /* not WINDOWSNT */
302 /* Arrange for character C to be read as the next input from
309 if (read_socket_hook
)
312 /* Should perhaps error if in batch mode */
314 ioctl (input_fd
, TIOCSTI
, &c
);
315 #else /* no TIOCSTI */
316 error ("Cannot stuff terminal input characters in this version of Unix");
317 #endif /* no TIOCSTI */
329 #ifdef INIT_BAUD_RATE
334 #else /* not DOS_NT */
338 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
339 &sg
.class, 12, 0, 0, 0, 0 );
340 ospeed
= sg
.xmit_baud
;
346 tcgetattr (input_fd
, &sg
);
347 ospeed
= cfgetospeed (&sg
);
348 #if defined (USE_GETOBAUD) && defined (getobaud)
349 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
351 ospeed
= getobaud (sg
.c_cflag
);
353 #else /* neither VMS nor TERMIOS */
359 tcgetattr (input_fd
, &sg
);
361 ioctl (input_fd
, TCGETA
, &sg
);
363 ospeed
= sg
.c_cflag
& CBAUD
;
364 #else /* neither VMS nor TERMIOS nor TERMIO */
367 sg
.sg_ospeed
= B9600
;
368 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
370 ospeed
= sg
.sg_ospeed
;
371 #endif /* not HAVE_TERMIO */
372 #endif /* not HAVE_TERMIOS */
374 #endif /* not DOS_NT */
375 #endif /* not INIT_BAUD_RATE */
378 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
379 ? baud_convert
[ospeed
] : 9600);
386 set_exclusive_use (fd
)
390 ioctl (fd
, FIOCLEX
, 0);
392 /* Ok to do nothing if this feature does not exist */
397 wait_without_blocking ()
400 wait3 (0, WNOHANG
| WUNTRACED
, 0);
402 croak ("wait_without_blocking");
404 synch_process_alive
= 0;
407 #endif /* not subprocesses */
409 int wait_debugging
; /* Set nonzero to make following function work under dbx
410 (at least for bsd). */
413 wait_for_termination_signal ()
416 /* Wait for subprocess with process id `pid' to terminate and
417 make sure it will get eliminated (not remain forever as a zombie) */
420 wait_for_termination (pid
)
429 status
= SYS$
FORCEX (&pid
, 0, 0);
432 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
433 /* Note that kill returns -1 even if the process is just a zombie now.
434 But inevitably a SIGCHLD interrupt should be generated
435 and child_sig will do wait3 and make the process go away. */
436 /* There is some indication that there is a bug involved with
437 termination of subprocesses, perhaps involving a kernel bug too,
438 but no idea what it is. Just as a hunch we signal SIGCHLD to see
439 if that causes the problem to go away or get worse. */
440 sigsetmask (sigmask (SIGCHLD
));
441 if (0 > kill (pid
, 0))
443 sigsetmask (SIGEMPTYMASK
);
444 kill (getpid (), SIGCHLD
);
450 sigpause (SIGEMPTYMASK
);
451 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
452 #if defined (UNIPLUS)
453 if (0 > kill (pid
, 0))
456 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
457 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
458 sigblock (sigmask (SIGCHLD
));
459 if (0 > kill (pid
, 0))
461 sigunblock (sigmask (SIGCHLD
));
464 sigpause (SIGEMPTYMASK
);
465 #else /* not POSIX_SIGNALS */
466 #ifdef HAVE_SYSV_SIGPAUSE
468 if (0 > kill (pid
, 0))
474 #else /* not HAVE_SYSV_SIGPAUSE */
478 #else /* not WINDOWSNT */
479 if (0 > kill (pid
, 0))
481 /* Using sleep instead of pause avoids timing error.
482 If the inferior dies just before the sleep,
483 we lose just one second. */
485 #endif /* not WINDOWSNT */
486 #endif /* not HAVE_SYSV_SIGPAUSE */
487 #endif /* not POSIX_SIGNALS */
488 #endif /* not UNIPLUS */
489 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
491 #else /* not subprocesses */
494 #else /* not __DJGPP__ > 1 */
496 if (kill (pid
, 0) < 0)
502 if (status
== pid
|| status
== -1)
505 #endif /* not __DJGPP__ > 1*/
506 #endif /* not subprocesses */
513 * flush any pending output
514 * (may flush input as well; it does not matter the way we use it)
518 flush_pending_output (channel
)
522 /* If we try this, we get hit with SIGTTIN, because
523 the child's tty belongs to the child's pgrp. */
526 ioctl (channel
, TCFLSH
, 1);
530 /* 3rd arg should be ignored
531 but some 4.2 kernels actually want the address of an int
532 and nonzero means something different. */
533 ioctl (channel
, TIOCFLUSH
, &zero
);
540 /* Set up the terminal at the other end of a pseudo-terminal that
541 we will be controlling an inferior through.
542 It should not echo or do line-editing, since that is done
543 in Emacs. No padding needed for insertion into an Emacs buffer. */
546 child_setup_tty (out
)
552 EMACS_GET_TTY (out
, &s
);
554 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
555 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
556 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
558 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
559 /* No output delays */
561 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
562 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
564 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
567 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
570 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
572 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
573 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
575 /* Said to be unnecessary: */
576 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
577 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
580 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
581 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
582 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
583 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
586 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
590 /* AIX enhanced edit loses NULs, so disable it */
593 s
.main
.c_iflag
&= ~ASCEDIT
;
595 /* Also, PTY overloads NUL and BREAK.
596 don't ignore break, but don't signal either, so it looks like NUL. */
597 s
.main
.c_iflag
&= ~IGNBRK
;
598 s
.main
.c_iflag
&= ~BRKINT
;
599 /* QUIT and INTR work better as signals, so disable character forms */
600 s
.main
.c_cc
[VINTR
] = 0377;
601 #ifdef SIGNALS_VIA_CHARACTERS
602 /* the QUIT and INTR character are used in process_send_signal
603 so set them here to something useful. */
604 if (s
.main
.c_cc
[VQUIT
] == 0377)
605 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
606 if (s
.main
.c_cc
[VINTR
] == 0377)
607 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
608 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
609 /* QUIT and INTR work better as signals, so disable character forms */
610 s
.main
.c_cc
[VQUIT
] = 0377;
611 s
.main
.c_cc
[VINTR
] = 0377;
612 s
.main
.c_lflag
&= ~ISIG
;
613 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
614 s
.main
.c_cc
[VEOL
] = 0377;
615 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
618 #else /* not HAVE_TERMIO */
620 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
622 s
.main
.sg_flags
|= LPASS8
;
623 s
.main
.sg_erase
= 0377;
624 s
.main
.sg_kill
= 0377;
625 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
627 #endif /* not HAVE_TERMIO */
629 EMACS_SET_TTY (out
, &s
, 0);
638 ioctl (out
, FIOASYNC
, &zero
);
641 #endif /* not DOS_NT */
645 #endif /* subprocesses */
647 /* Record a signal code and the handler for it. */
651 SIGTYPE (*handler
) P_ ((int));
654 static void save_signal_handlers
P_ ((struct save_signal
*));
655 static void restore_signal_handlers
P_ ((struct save_signal
*));
657 /* Suspend the Emacs process; give terminal to its superior. */
663 /* "Foster" parentage allows emacs to return to a subprocess that attached
664 to the current emacs as a cheaper than starting a whole new process. This
665 is set up by KEPTEDITOR.COM. */
666 unsigned long parent_id
, foster_parent_id
;
669 fpid_string
= getenv ("EMACS_PARENT_PID");
670 if (fpid_string
!= NULL
)
672 sscanf (fpid_string
, "%x", &foster_parent_id
);
673 if (foster_parent_id
!= 0)
674 parent_id
= foster_parent_id
;
676 parent_id
= getppid ();
679 parent_id
= getppid ();
681 xfree (fpid_string
); /* On VMS, this was malloc'd */
683 if (parent_id
&& parent_id
!= 0xffffffff)
685 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
686 int status
= LIB$
ATTACH (&parent_id
) & 1;
687 signal (SIGINT
, oldsig
);
696 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
697 d_prompt
.a
= "Emacs: "; /* Just a reminder */
698 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
703 #if defined(SIGTSTP) && !defined(MSDOS)
706 int pgrp
= EMACS_GETPGRP (0);
707 EMACS_KILLPG (pgrp
, SIGTSTP
);
710 #else /* No SIGTSTP */
711 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
712 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
713 kill (getpid (), SIGQUIT
);
715 #else /* No SIGTSTP or USG_JOBCTRL */
717 /* On a system where suspending is not implemented,
718 instead fork a subshell and let it talk directly to the terminal
722 #endif /* no USG_JOBCTRL */
723 #endif /* no SIGTSTP */
727 /* Fork a subshell. */
733 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
735 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
738 struct save_signal saved_handlers
[5];
740 unsigned char *str
= 0;
743 saved_handlers
[0].code
= SIGINT
;
744 saved_handlers
[1].code
= SIGQUIT
;
745 saved_handlers
[2].code
= SIGTERM
;
747 saved_handlers
[3].code
= SIGIO
;
748 saved_handlers
[4].code
= 0;
750 saved_handlers
[3].code
= 0;
753 /* Mentioning current_buffer->buffer would mean including buffer.h,
754 which somehow wedges the hp compiler. So instead... */
756 dir
= intern ("default-directory");
757 if (NILP (Fboundp (dir
)))
759 dir
= Fsymbol_value (dir
);
763 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
764 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
765 len
= XSTRING (dir
)->size
;
766 bcopy (XSTRING (dir
)->data
, str
, len
);
767 if (str
[len
- 1] != '/') str
[len
++] = '/';
774 save_signal_handlers (saved_handlers
);
775 synch_process_alive
= 1;
776 #endif /* __DJGPP__ > 1 */
780 error ("Can't spawn subshell");
787 #ifdef DOS_NT /* MW, Aug 1993 */
790 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
793 sh
= (char *) egetenv ("SHELL");
797 /* Use our buffer's default directory for the subshell. */
802 close_process_descs (); /* Close Emacs's pipes/ptys */
805 #ifdef SET_EMACS_PRIORITY
807 extern int emacs_priority
;
809 if (emacs_priority
< 0)
810 nice (-emacs_priority
);
814 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
817 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
819 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
821 #else /* not MSDOS */
823 /* Waits for process completion */
824 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
827 write (1, "Can't execute subshell", 22);
828 #else /* not WINDOWSNT */
830 write (1, "Can't execute subshell", 22);
832 #endif /* not WINDOWSNT */
833 #endif /* not MSDOS */
836 /* Do this now if we did not do it before. */
837 #if !defined (MSDOS) || __DJGPP__ == 1
838 save_signal_handlers (saved_handlers
);
839 synch_process_alive
= 1;
843 wait_for_termination (pid
);
845 restore_signal_handlers (saved_handlers
);
846 synch_process_alive
= 0;
851 save_signal_handlers (saved_handlers
)
852 struct save_signal
*saved_handlers
;
854 while (saved_handlers
->code
)
856 saved_handlers
->handler
857 = (SIGTYPE (*) P_ ((int))) signal (saved_handlers
->code
, SIG_IGN
);
863 restore_signal_handlers (saved_handlers
)
864 struct save_signal
*saved_handlers
;
866 while (saved_handlers
->code
)
868 signal (saved_handlers
->code
, saved_handlers
->handler
);
882 old_fcntl_flags
= fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
883 fcntl (fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
885 interrupts_deferred
= 0;
894 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
899 if (read_socket_hook
)
903 sigunblock (sigmask (SIGWINCH
));
905 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
907 interrupts_deferred
= 0;
913 if (read_socket_hook
)
917 sigblock (sigmask (SIGWINCH
));
919 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
920 interrupts_deferred
= 1;
923 #else /* no FASYNC */
924 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
931 if (read_socket_hook
)
934 ioctl (input_fd
, FIOASYNC
, &on
);
935 interrupts_deferred
= 0;
943 if (read_socket_hook
)
946 ioctl (input_fd
, FIOASYNC
, &off
);
947 interrupts_deferred
= 1;
950 #else /* not FASYNC, not STRIDE */
962 if (read_socket_hook
)
966 sigaddset(&st
, SIGIO
);
967 ioctl (input_fd
, FIOASYNC
, &on
);
968 interrupts_deferred
= 0;
969 sigprocmask(SIG_UNBLOCK
, &st
, (sigset_t
*)0);
977 if (read_socket_hook
)
980 ioctl (input_fd
, FIOASYNC
, &off
);
981 interrupts_deferred
= 1;
989 if (read_socket_hook
)
992 croak ("request_sigio");
998 if (read_socket_hook
)
1001 croak ("unrequest_sigio");
1007 #endif /* F_SETFL */
1009 /* Saving and restoring the process group of Emacs's terminal. */
1013 /* The process group of which Emacs was a member when it initially
1016 If Emacs was in its own process group (i.e. inherited_pgroup ==
1017 getpid ()), then we know we're running under a shell with job
1018 control (Emacs would never be run as part of a pipeline).
1021 If Emacs was not in its own process group, then we know we're
1022 running under a shell (or a caller) that doesn't know how to
1023 separate itself from Emacs (like sh). Emacs must be in its own
1024 process group in order to receive SIGIO correctly. In this
1025 situation, we put ourselves in our own pgroup, forcibly set the
1026 tty's pgroup to our pgroup, and make sure to restore and reinstate
1027 the tty's pgroup just like any other terminal setting. If
1028 inherited_group was not the tty's pgroup, then we'll get a
1029 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1030 it goes foreground in the future, which is what should happen. */
1031 int inherited_pgroup
;
1033 /* Split off the foreground process group to Emacs alone.
1034 When we are in the foreground, but not started in our own process
1035 group, redirect the TTY to point to our own process group. We need
1036 to be in our own process group to receive SIGIO properly. */
1038 narrow_foreground_group ()
1042 setpgrp (0, inherited_pgroup
);
1043 if (inherited_pgroup
!= me
)
1044 EMACS_SET_TTY_PGRP (input_fd
, &me
);
1048 /* Set the tty to our original foreground group. */
1050 widen_foreground_group ()
1052 if (inherited_pgroup
!= getpid ())
1053 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
1054 setpgrp (0, inherited_pgroup
);
1057 #endif /* BSD_PGRPS */
1059 /* Getting and setting emacs_tty structures. */
1061 /* Set *TC to the parameters associated with the terminal FD.
1062 Return zero if all's well, or -1 if we ran into an error we
1063 couldn't deal with. */
1065 emacs_get_tty (fd
, settings
)
1067 struct emacs_tty
*settings
;
1069 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1071 /* We have those nifty POSIX tcmumbleattr functions. */
1072 bzero (&settings
->main
, sizeof (settings
->main
));
1073 if (tcgetattr (fd
, &settings
->main
) < 0)
1078 /* The SYSV-style interface? */
1079 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1084 /* Vehemently Monstrous System? :-) */
1085 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1086 &settings
->main
.class, 12, 0, 0, 0, 0)
1092 /* I give up - I hope you have the BSD ioctls. */
1093 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1095 #endif /* not DOS_NT */
1100 /* Suivant - Do we have to get struct ltchars data? */
1102 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1106 /* How about a struct tchars and a wordful of lmode bits? */
1108 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1109 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1113 /* We have survived the tempest. */
1118 /* Set the parameters of the tty on FD according to the contents of
1119 *SETTINGS. If FLUSHP is non-zero, we discard input.
1120 Return 0 if all went well, and -1 if anything failed. */
1123 emacs_set_tty (fd
, settings
, flushp
)
1125 struct emacs_tty
*settings
;
1128 /* Set the primary parameters - baud rate, character size, etcetera. */
1131 /* We have those nifty POSIX tcmumbleattr functions.
1132 William J. Smith <wjs@wiis.wang.com> writes:
1133 "POSIX 1003.1 defines tcsetattr() to return success if it was
1134 able to perform any of the requested actions, even if some
1135 of the requested actions could not be performed.
1136 We must read settings back to ensure tty setup properly.
1137 AIX requires this to keep tty from hanging occasionally." */
1138 /* This make sure that we don't loop indefinitely in here. */
1139 for (i
= 0 ; i
< 10 ; i
++)
1140 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1151 bzero (&new, sizeof (new));
1152 /* Get the current settings, and see if they're what we asked for. */
1153 tcgetattr (fd
, &new);
1154 /* We cannot use memcmp on the whole structure here because under
1155 * aix386 the termios structure has some reserved field that may
1158 if ( new.c_iflag
== settings
->main
.c_iflag
1159 && new.c_oflag
== settings
->main
.c_oflag
1160 && new.c_cflag
== settings
->main
.c_cflag
1161 && new.c_lflag
== settings
->main
.c_lflag
1162 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1170 /* The SYSV-style interface? */
1171 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1176 /* Vehemently Monstrous System? :-) */
1177 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1178 &settings
->main
.class, 12, 0, 0, 0, 0)
1184 /* I give up - I hope you have the BSD ioctls. */
1185 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1187 #endif /* not DOS_NT */
1193 /* Suivant - Do we have to get struct ltchars data? */
1195 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1199 /* How about a struct tchars and a wordful of lmode bits? */
1201 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1202 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1206 /* We have survived the tempest. */
1211 /* The initial tty mode bits */
1212 struct emacs_tty old_tty
;
1214 /* 1 if we have been through init_sys_modes. */
1217 /* 1 if outer tty status has been recorded. */
1221 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1226 #ifndef F_SETOWN_BUG
1228 int old_fcntl_owner
;
1229 #endif /* F_SETOWN */
1230 #endif /* F_SETOWN_BUG */
1232 /* This may also be defined in stdio,
1233 but if so, this does no harm,
1234 and using the same name avoids wasting the other one's space. */
1236 #if defined (USG) || defined (DGUX)
1237 unsigned char _sobuf
[BUFSIZ
+8];
1239 char _sobuf
[BUFSIZ
];
1243 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1246 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1252 struct emacs_tty tty
;
1256 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1257 extern int (*interrupt_signal
) ();
1261 Vtty_erase_char
= Qnil
;
1268 input_ef
= get_kbd_event_flag ();
1269 /* LIB$GET_EF (&input_ef); */
1270 SYS$
CLREF (input_ef
);
1271 waiting_for_ast
= 0;
1273 timer_ef
= get_timer_event_flag ();
1274 /* LIB$GET_EF (&timer_ef); */
1275 SYS$
CLREF (timer_ef
);
1279 LIB$
GET_EF (&process_ef
);
1280 SYS$
CLREF (process_ef
);
1282 if (input_ef
/ 32 != process_ef
/ 32)
1283 croak ("Input and process event flags in different clusters.");
1285 if (input_ef
/ 32 != timer_ef
/ 32)
1286 croak ("Input and timer event flags in different clusters.");
1288 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1289 ((unsigned) 1 << (process_ef
% 32));
1291 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1292 ((unsigned) 1 << (timer_ef
% 32));
1294 sys_access_reinit ();
1296 #endif /* not VMS */
1299 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1300 narrow_foreground_group ();
1303 #ifdef HAVE_WINDOW_SYSTEM
1304 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1305 needs the initialization code below. */
1306 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1309 EMACS_GET_TTY (input_fd
, &old_tty
);
1315 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1316 XSETINT (Vtty_erase_char
, old_tty
.main
.c_cc
[VERASE
]);
1319 /* This allows meta to be sent on 8th bit. */
1320 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1322 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1323 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1324 #ifdef INLCR /* I'm just being cautious,
1325 since I can't check how widespread INLCR is--rms. */
1326 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1329 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1331 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1332 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1334 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1336 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1339 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1341 tty
.main
.c_iflag
&= ~IXANY
;
1345 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1346 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1348 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1352 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1353 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1356 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1357 /* Set up C-g for both SIGQUIT and SIGINT.
1358 We don't know which we will get, but we handle both alike
1359 so which one it really gives us does not matter. */
1360 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1361 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1362 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1364 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1368 #if defined (mips) || defined (HAVE_TCATTR)
1370 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1373 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1374 #endif /* V_DSUSP */
1375 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1376 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1379 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1382 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1383 #endif /* VREPRINT */
1385 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1386 #endif /* VWERASE */
1388 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1389 #endif /* VDISCARD */
1394 tty
.main
.c_cc
[VSTART
] = '\021';
1397 tty
.main
.c_cc
[VSTOP
] = '\023';
1403 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1406 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1409 #endif /* mips or HAVE_TCATTR */
1411 #ifdef SET_LINE_DISCIPLINE
1412 /* Need to explicitly request TERMIODISC line discipline or
1413 Ultrix's termios does not work correctly. */
1414 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1418 /* AIX enhanced edit loses NULs, so disable it. */
1419 tty
.main
.c_line
= 0;
1420 tty
.main
.c_iflag
&= ~ASCEDIT
;
1422 tty
.main
.c_cc
[VSTRT
] = 255;
1423 tty
.main
.c_cc
[VSTOP
] = 255;
1424 tty
.main
.c_cc
[VSUSP
] = 255;
1425 tty
.main
.c_cc
[VDSUSP
] = 255;
1426 #endif /* IBMR2AIX */
1430 tty
.main
.c_cc
[VSTART
] = '\021';
1433 tty
.main
.c_cc
[VSTOP
] = '\023';
1436 /* Also, PTY overloads NUL and BREAK.
1437 don't ignore break, but don't signal either, so it looks like NUL.
1438 This really serves a purpose only if running in an XTERM window
1439 or via TELNET or the like, but does no harm elsewhere. */
1440 tty
.main
.c_iflag
&= ~IGNBRK
;
1441 tty
.main
.c_iflag
&= ~BRKINT
;
1443 #else /* if not HAVE_TERMIO */
1445 tty
.main
.tt_char
|= TT$M_NOECHO
;
1447 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1449 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1451 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1452 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1453 #else /* not VMS (BSD, that is) */
1455 XSETINT (Vtty_erase_char
, tty
.main
.sg_erase
);
1456 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1458 tty
.main
.sg_flags
|= ANYP
;
1459 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1460 #endif /* not DOS_NT */
1461 #endif /* not VMS (BSD, that is) */
1462 #endif /* not HAVE_TERMIO */
1464 /* If going to use CBREAK mode, we must request C-g to interrupt
1465 and turn off start and stop chars, etc. If not going to use
1466 CBREAK mode, do this anyway so as to turn off local flow
1467 control for user coming over network on 4.2; in this case,
1468 only t_stopc and t_startc really matter. */
1471 /* Note: if not using CBREAK mode, it makes no difference how we
1473 tty
.tchars
= new_tchars
;
1474 tty
.tchars
.t_intrc
= quit_char
;
1477 tty
.tchars
.t_startc
= '\021';
1478 tty
.tchars
.t_stopc
= '\023';
1481 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1483 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1484 anything, and leaving it in breaks the meta key. Go figure. */
1485 tty
.lmode
&= ~LLITOUT
;
1492 #endif /* HAVE_TCHARS */
1493 #endif /* not HAVE_TERMIO */
1496 tty
.ltchars
= new_ltchars
;
1497 #endif /* HAVE_LTCHARS */
1498 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1500 internal_terminal_init ();
1504 EMACS_SET_TTY (input_fd
, &tty
, 0);
1506 /* This code added to insure that, if flow-control is not to be used,
1507 we have an unlocked terminal at the start. */
1510 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1514 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1518 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1520 if (!flow_control
) tcflow (input_fd
, TCOON
);
1528 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1529 to be only LF. This is the way that is done. */
1532 if (ioctl (1, HFTGETID
, &tty
) != -1)
1533 write (1, "\033[20l", 5);
1539 /* Appears to do nothing when in PASTHRU mode.
1540 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1541 interrupt_signal, oob_chars, 0, 0, 0, 0);
1543 queue_kbd_input (0);
1548 #ifndef F_SETOWN_BUG
1549 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1551 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1553 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1554 fcntl (input_fd
, F_SETOWN
, getpid ());
1555 init_sigio (input_fd
);
1557 #endif /* F_GETOWN */
1558 #endif /* F_SETOWN_BUG */
1559 #endif /* F_SETFL */
1562 if (interrupt_input
)
1563 init_sigio (input_fd
);
1566 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1570 /* This symbol is defined on recent USG systems.
1571 Someone says without this call USG won't really buffer the file
1572 even with a call to setbuf. */
1573 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
1575 setbuf (stdout
, _sobuf
);
1577 #ifdef HAVE_WINDOW_SYSTEM
1578 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1579 needs the initialization code below. */
1580 if (EQ (Vwindow_system
, Qnil
)
1582 /* When running in tty mode on NT/Win95, we have a read_socket
1583 hook, but still need the rest of the initialization code below. */
1584 && (! read_socket_hook
)
1588 set_terminal_modes ();
1590 if (term_initted
&& no_redraw_on_reenter
)
1592 if (display_completed
)
1593 direct_output_forward_char (0);
1598 if (FRAMEP (Vterminal_frame
))
1599 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1605 /* Return nonzero if safe to use tabs in output.
1606 At the time this is called, init_sys_modes has not been done yet. */
1611 struct emacs_tty tty
;
1613 EMACS_GET_TTY (input_fd
, &tty
);
1614 return EMACS_TTY_TABS_OK (&tty
);
1617 /* Get terminal size from system.
1618 Store number of lines into *HEIGHTP and width into *WIDTHP.
1619 We store 0 if there's no valid information. */
1622 get_frame_size (widthp
, heightp
)
1623 int *widthp
, *heightp
;
1629 struct winsize size
;
1631 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1632 *widthp
= *heightp
= 0;
1635 *widthp
= size
.ws_col
;
1636 *heightp
= size
.ws_row
;
1642 /* SunOS - style. */
1643 struct ttysize size
;
1645 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1646 *widthp
= *heightp
= 0;
1649 *widthp
= size
.ts_cols
;
1650 *heightp
= size
.ts_lines
;
1656 struct sensemode tty
;
1658 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1659 &tty
.class, 12, 0, 0, 0, 0);
1660 *widthp
= tty
.scr_wid
;
1661 *heightp
= tty
.scr_len
;
1665 *widthp
= ScreenCols ();
1666 *heightp
= ScreenRows ();
1667 #else /* system doesn't know size */
1672 #endif /* not VMS */
1673 #endif /* not SunOS-style */
1674 #endif /* not BSD-style */
1677 /* Set the logical window size associated with descriptor FD
1678 to HEIGHT and WIDTH. This is used mainly with ptys. */
1681 set_window_size (fd
, height
, width
)
1682 int fd
, height
, width
;
1687 struct winsize size
;
1688 size
.ws_row
= height
;
1689 size
.ws_col
= width
;
1691 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1692 return 0; /* error */
1699 /* SunOS - style. */
1700 struct ttysize size
;
1701 size
.ts_lines
= height
;
1702 size
.ts_cols
= width
;
1704 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1710 #endif /* not SunOS-style */
1711 #endif /* not BSD-style */
1715 /* Prepare the terminal for exiting Emacs; move the cursor to the
1716 bottom of the frame, turn off interrupt-driven I/O, etc. */
1727 #ifdef HAVE_WINDOW_SYSTEM
1728 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1729 needs the clean-up code below. */
1730 if (!EQ (Vwindow_system
, Qnil
)
1732 /* When running in tty mode on NT/Win95, we have a read_socket
1733 hook, but still need the rest of the clean-up code below. */
1739 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1740 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1741 /* clear_end_of_line may move the cursor */
1742 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1743 #if defined (IBMR2AIX) && defined (AIXHFT)
1745 /* HFT devices normally use ^J as a LF/CR. We forced it to
1746 do the LF only. Now, we need to reset it. */
1749 if (ioctl (1, HFTGETID
, &tty
) != -1)
1750 write (1, "\033[20h", 5);
1754 reset_terminal_modes ();
1758 /* Avoid possible loss of output when changing terminal modes. */
1759 fsync (fileno (stdout
));
1764 #ifndef F_SETOWN_BUG
1765 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1766 if (interrupt_input
)
1769 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1771 #endif /* F_SETOWN */
1772 #endif /* F_SETOWN_BUG */
1774 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1776 #endif /* F_SETFL */
1778 if (interrupt_input
)
1783 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1786 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1790 #ifdef SET_LINE_DISCIPLINE
1791 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1792 A different old line discipline is therefore not restored, yet.
1793 Restore the old line discipline by hand. */
1794 ioctl (0, TIOCSETD
, &old_tty
.main
.c_line
);
1802 widen_foreground_group ();
1808 /* Set up the proper status flags for use of a pty. */
1814 /* I'm told that TOICREMOTE does not mean control chars
1815 "can't be sent" but rather that they don't have
1816 input-editing or signaling effects.
1817 That should be good, because we have other ways
1818 to do those things in Emacs.
1819 However, telnet mode seems not to work on 4.2.
1820 So TIOCREMOTE is turned off now. */
1822 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1823 will hang. In particular, the "timeout" feature (which
1824 causes a read to return if there is no data available)
1825 does this. Also it is known that telnet mode will hang
1826 in such a way that Emacs must be stopped (perhaps this
1827 is the same problem).
1829 If TIOCREMOTE is turned off, then there is a bug in
1830 hp-ux which sometimes loses data. Apparently the
1831 code which blocks the master process when the internal
1832 buffer fills up does not work. Other than this,
1833 though, everything else seems to work fine.
1835 Since the latter lossage is more benign, we may as well
1836 lose that way. -- cph */
1841 ioctl (fd
, FIONBIO
, &on
);
1846 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1847 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1848 /* cause EMACS not to die when it should, i.e., when its own controlling */
1849 /* tty goes away. I've complained to the AIX developers, and they may */
1850 /* change this behavior, but I'm not going to hold my breath. */
1851 signal (SIGHUP
, SIG_IGN
);
1854 #endif /* HAVE_PTYS */
1858 /* Assigning an input channel is done at the start of Emacs execution.
1859 This is called each time Emacs is resumed, also, but does nothing
1860 because input_chain is no longer zero. */
1869 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1875 /* Deassigning the input channel is done before exiting. */
1880 return SYS$
DASSGN (input_fd
);
1885 /* Request reading one character into the keyboard buffer.
1886 This is done as soon as the buffer becomes empty. */
1892 extern kbd_input_ast ();
1894 waiting_for_ast
= 0;
1896 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1897 &input_iosb
, kbd_input_ast
, 1,
1898 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1903 /* Ast routine that is called when keyboard input comes in
1904 in accord with the SYS$QIO above. */
1909 register int c
= -1;
1910 int old_errno
= errno
;
1911 extern EMACS_TIME
*input_available_clear_time
;
1913 if (waiting_for_ast
)
1914 SYS$
SETEF (input_ef
);
1915 waiting_for_ast
= 0;
1918 if (input_count
== 25)
1920 printf ("Ast # %d,", input_count
);
1921 printf (" iosb = %x, %x, %x, %x",
1922 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1925 if (input_iosb
.offset
)
1929 printf (", char = 0%o", c
);
1941 struct input_event e
;
1942 e
.kind
= ascii_keystroke
;
1943 XSETINT (e
.code
, c
);
1944 XSETFRAME (e
.frame_or_window
, selected_frame
);
1945 kbd_buffer_store_event (&e
);
1947 if (input_available_clear_time
)
1948 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1952 /* Wait until there is something in kbd_buffer. */
1955 wait_for_kbd_input ()
1957 extern int have_process_input
, process_exited
;
1959 /* If already something, avoid doing system calls. */
1960 if (detect_input_pending ())
1964 /* Clear a flag, and tell ast routine above to set it. */
1965 SYS$
CLREF (input_ef
);
1966 waiting_for_ast
= 1;
1967 /* Check for timing error: ast happened while we were doing that. */
1968 if (!detect_input_pending ())
1970 /* No timing error: wait for flag to be set. */
1971 set_waiting_for_input (0);
1972 SYS$
WFLOR (input_ef
, input_eflist
);
1973 clear_waiting_for_input (0);
1974 if (!detect_input_pending ())
1975 /* Check for subprocess input availability */
1977 int dsp
= have_process_input
|| process_exited
;
1979 SYS$
CLREF (process_ef
);
1980 if (have_process_input
)
1981 process_command_input ();
1986 update_mode_lines
++;
1987 prepare_menu_bars ();
1988 redisplay_preserve_echo_area ();
1992 waiting_for_ast
= 0;
1995 /* Get rid of any pending QIO, when we are about to suspend
1996 or when we want to throw away pending input.
1997 We wait for a positive sign that the AST routine has run
1998 and therefore there is no I/O request queued when we return.
1999 SYS$SETAST is used to avoid a timing error. */
2005 printf ("At end_kbd_input.\n");
2009 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2011 SYS$
CANCEL (input_fd
);
2016 /* Clear a flag, and tell ast routine above to set it. */
2017 SYS$
CLREF (input_ef
);
2018 waiting_for_ast
= 1;
2020 SYS$
CANCEL (input_fd
);
2022 SYS$
WAITFR (input_ef
);
2023 waiting_for_ast
= 0;
2026 /* Wait for either input available or time interval expiry. */
2029 input_wait_timeout (timeval
)
2030 int timeval
; /* Time to wait, in seconds */
2033 static int zero
= 0;
2034 static int large
= -10000000;
2036 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2038 /* If already something, avoid doing system calls. */
2039 if (detect_input_pending ())
2043 /* Clear a flag, and tell ast routine above to set it. */
2044 SYS$
CLREF (input_ef
);
2045 waiting_for_ast
= 1;
2046 /* Check for timing error: ast happened while we were doing that. */
2047 if (!detect_input_pending ())
2049 /* No timing error: wait for flag to be set. */
2051 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2052 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
2054 waiting_for_ast
= 0;
2057 /* The standard `sleep' routine works some other way
2058 and it stops working if you have ever quit out of it.
2059 This one continues to work. */
2065 static int zero
= 0;
2066 static int large
= -10000000;
2068 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2071 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2072 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2090 croak ("request sigio");
2096 croak ("unrequest sigio");
2101 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2106 #ifndef SYSTEM_MALLOC
2113 /* Some systems that cannot dump also cannot implement these. */
2116 * Return the address of the start of the text segment prior to
2117 * doing an unexec. After unexec the return value is undefined.
2118 * See crt0.c for further explanation and _start.
2122 #ifndef HAVE_TEXT_START
2127 return ((char *) TEXT_START
);
2131 return ((char *) csrt
);
2132 #else /* not GOULD */
2133 extern int _start ();
2134 return ((char *) _start
);
2136 #endif /* TEXT_START */
2138 #endif /* not HAVE_TEXT_START */
2141 * Return the address of the start of the data segment prior to
2142 * doing an unexec. After unexec the return value is undefined.
2143 * See crt0.c for further information and definition of data_start.
2145 * Apparently, on BSD systems this is etext at startup. On
2146 * USG systems (swapping) this is highly mmu dependent and
2147 * is also dependent on whether or not the program is running
2148 * with shared text. Generally there is a (possibly large)
2149 * gap between end of text and start of data with shared text.
2151 * On Uniplus+ systems with shared text, data starts at a
2152 * fixed address. Each port (from a given oem) is generally
2153 * different, and the specific value of the start of data can
2154 * be obtained via the UniPlus+ specific "uvar" system call,
2155 * however the method outlined in crt0.c seems to be more portable.
2157 * Probably what will have to happen when a USG unexec is available,
2158 * at least on UniPlus, is temacs will have to be made unshared so
2159 * that text and data are contiguous. Then once loadup is complete,
2160 * unexec will produce a shared executable where the data can be
2161 * at the normal shared text boundary and the startofdata variable
2162 * will be patched by unexec to the correct value.
2170 return ((char *) DATA_START
);
2172 #ifdef ORDINARY_LINK
2174 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2175 * data_start isn't defined. We take the address of environ, which
2176 * is known to live at or near the start of the system crt0.c, and
2177 * we don't sweat the handful of bytes that might lose.
2179 extern char **environ
;
2181 return((char *) &environ
);
2183 extern int data_start
;
2184 return ((char *) &data_start
);
2185 #endif /* ORDINARY_LINK */
2186 #endif /* DATA_START */
2188 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2191 /* Some systems that cannot dump also cannot implement these. */
2194 * Return the address of the end of the text segment prior to
2195 * doing an unexec. After unexec the return value is undefined.
2202 return ((char *) TEXT_END
);
2205 return ((char *) &etext
);
2210 * Return the address of the end of the data segment prior to
2211 * doing an unexec. After unexec the return value is undefined.
2218 return ((char *) DATA_END
);
2221 return ((char *) &edata
);
2225 #endif /* not CANNOT_DUMP */
2227 /* init_system_name sets up the string for the Lisp function
2228 system-name to return. */
2234 extern Lisp_Object Vsystem_name
;
2239 #include <sys/socket.h>
2241 #endif /* HAVE_SOCKETS */
2242 #endif /* not VMS */
2243 #endif /* not BSD4_1 */
2249 Vsystem_name
= build_string (sysname
);
2253 if ((sp
= egetenv ("SYS$NODE")) == 0)
2254 Vsystem_name
= build_string ("vax-vms");
2255 else if ((end
= index (sp
, ':')) == 0)
2256 Vsystem_name
= build_string (sp
);
2258 Vsystem_name
= make_string (sp
, end
- sp
);
2260 #ifndef HAVE_GETHOSTNAME
2263 Vsystem_name
= build_string (uts
.nodename
);
2264 #else /* HAVE_GETHOSTNAME */
2265 unsigned int hostname_size
= 256;
2266 char *hostname
= (char *) alloca (hostname_size
);
2268 /* Try to get the host name; if the buffer is too short, try
2269 again. Apparently, the only indication gethostname gives of
2270 whether the buffer was large enough is the presence or absence
2271 of a '\0' in the string. Eech. */
2274 gethostname (hostname
, hostname_size
- 1);
2275 hostname
[hostname_size
- 1] = '\0';
2277 /* Was the buffer large enough for the '\0'? */
2278 if (strlen (hostname
) < hostname_size
- 1)
2281 hostname_size
<<= 1;
2282 hostname
= (char *) alloca (hostname_size
);
2285 /* Turn the hostname into the official, fully-qualified hostname.
2286 Don't do this if we're going to dump; this can confuse system
2287 libraries on some machines and make the dumped emacs core dump. */
2290 #endif /* not CANNOT_DUMP */
2291 if (! index (hostname
, '.'))
2295 for (count
= 0;; count
++)
2300 hp
= gethostbyname (hostname
);
2302 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2307 Fsleep_for (make_number (1), Qnil
);
2311 char *fqdn
= (char *) hp
->h_name
;
2314 if (!index (fqdn
, '.'))
2316 /* We still don't have a fully qualified domain name.
2317 Try to find one in the list of alternate names */
2318 char **alias
= hp
->h_aliases
;
2319 while (*alias
&& !index (*alias
, '.'))
2326 /* Convert the host name to lower case. */
2327 /* Using ctype.h here would introduce a possible locale
2328 dependence that is probably wrong for hostnames. */
2332 if (*p
>= 'A' && *p
<= 'Z')
2339 #endif /* HAVE_SOCKETS */
2340 /* We used to try using getdomainname here,
2341 but NIIBE Yutaka <gniibe@etl.go.jp> says that
2342 getdomainname gets the NIS/YP domain which often is not the same
2343 as in Internet domain name. */
2344 #if 0 /* Turned off because sysinfo is not really likely to return the
2345 correct Internet domain. */
2346 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2347 if (! index (hostname
, '.'))
2349 /* The hostname is not fully qualified. Append the domain name. */
2351 int hostlen
= strlen (hostname
);
2352 int domain_size
= 256;
2356 char *domain
= (char *) alloca (domain_size
+ 1);
2357 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2358 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2359 if (sys_domain_size
<= 0)
2361 if (domain_size
< sys_domain_size
)
2363 domain_size
= sys_domain_size
;
2366 strcpy (fqdn
, hostname
);
2367 if (domain
[0] == '.')
2368 strcpy (fqdn
+ hostlen
, domain
);
2369 else if (domain
[0] != 0)
2371 fqdn
[hostlen
] = '.';
2372 strcpy (fqdn
+ hostlen
+ 1, domain
);
2378 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2380 Vsystem_name
= build_string (hostname
);
2381 #endif /* HAVE_GETHOSTNAME */
2386 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2387 if (*p
== ' ' || *p
== '\t')
2394 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2396 #include "sysselect.h"
2399 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2400 /* Cause explanatory error message at compile time,
2401 since the select emulation is not good enough for X. */
2402 int *x
= &x_windows_lose_if_no_select_system_call
;
2405 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2406 * Only checks read descriptors.
2408 /* How long to wait between checking fds in select */
2409 #define SELECT_PAUSE 1
2412 /* For longjmp'ing back to read_input_waiting. */
2414 jmp_buf read_alarm_throw
;
2416 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2417 The read_socket_hook function sets this to 1 while it is waiting. */
2419 int read_alarm_should_throw
;
2427 #else /* not BSD4_1 */
2428 signal (SIGALRM
, SIG_IGN
);
2429 #endif /* not BSD4_1 */
2430 if (read_alarm_should_throw
)
2431 longjmp (read_alarm_throw
, 1);
2435 /* Only rfds are checked. */
2437 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2439 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2440 EMACS_TIME
*timeout
;
2442 int ravail
= 0, old_alarm
;
2446 extern int proc_buffered_char
[];
2447 #ifndef subprocesses
2448 int process_tick
= 0, update_tick
= 0;
2450 extern int process_tick
, update_tick
;
2452 SIGTYPE (*old_trap
) ();
2455 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2456 /* If we're using X, then the native select will work; we only need the
2457 emulation for non-X usage. */
2458 if (!NILP (Vwindow_system
))
2459 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2461 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2462 local_timeout
= &timeoutval
;
2474 /* If we are looking only for the terminal, with no timeout,
2475 just read it and wait -- that's more efficient. */
2476 if (*local_timeout
== 100000 && process_tick
== update_tick
2477 && FD_ISSET (0, &orfds
))
2480 for (fd
= 1; fd
< nfds
; ++fd
)
2481 if (FD_ISSET (fd
, &orfds
))
2483 if (! detect_input_pending ())
2484 read_input_waiting ();
2490 /* Once a second, till the timer expires, check all the flagged read
2491 * descriptors to see if any input is available. If there is some then
2492 * set the corresponding bit in the return copy of rfds.
2496 register int to_check
, fd
;
2500 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2502 if (FD_ISSET (fd
, &orfds
))
2504 int avail
= 0, status
= 0;
2507 avail
= detect_input_pending (); /* Special keyboard handler */
2511 status
= ioctl (fd
, FIONREAD
, &avail
);
2512 #else /* no FIONREAD */
2513 /* Hoping it will return -1 if nothing available
2514 or 0 if all 0 chars requested are read. */
2515 if (proc_buffered_char
[fd
] >= 0)
2519 avail
= read (fd
, &buf
, 1);
2521 proc_buffered_char
[fd
] = buf
;
2523 #endif /* no FIONREAD */
2525 if (status
>= 0 && avail
> 0)
2533 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2535 old_alarm
= alarm (0);
2536 old_trap
= signal (SIGALRM
, select_alarm
);
2538 alarm (SELECT_PAUSE
);
2539 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2540 while (select_alarmed
== 0 && *local_timeout
!= 0
2541 && process_tick
== update_tick
)
2543 /* If we are interested in terminal input,
2544 wait by reading the terminal.
2545 That makes instant wakeup for terminal input at least. */
2546 if (FD_ISSET (0, &orfds
))
2548 read_input_waiting ();
2549 if (detect_input_pending ())
2555 (*local_timeout
) -= SELECT_PAUSE
;
2556 /* Reset the old alarm if there was one */
2558 signal (SIGALRM
, old_trap
);
2561 /* Reset or forge an interrupt for the original handler. */
2562 old_alarm
-= SELECT_PAUSE
;
2564 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2568 if (*local_timeout
== 0) /* Stop on timer being cleared */
2573 #endif /* not WINDOWSNT */
2575 /* Read keyboard input into the standard buffer,
2576 waiting for at least one character. */
2578 /* Make all keyboard buffers much bigger when using a window system. */
2579 #ifdef HAVE_WINDOW_SYSTEM
2580 #define BUFFER_SIZE_FACTOR 16
2582 #define BUFFER_SIZE_FACTOR 1
2586 read_input_waiting ()
2588 struct input_event e
;
2590 extern int quit_char
;
2592 if (read_socket_hook
)
2594 struct input_event buf
[256];
2596 read_alarm_should_throw
= 0;
2597 if (! setjmp (read_alarm_throw
))
2598 nread
= (*read_socket_hook
) (0, buf
, 256, 1, 0);
2602 /* Scan the chars for C-g and store them in kbd_buffer. */
2603 for (i
= 0; i
< nread
; i
++)
2605 kbd_buffer_store_event (&buf
[i
]);
2606 /* Don't look at input that follows a C-g too closely.
2607 This reduces lossage due to autorepeat on C-g. */
2608 if (buf
[i
].kind
== ascii_keystroke
2609 && buf
[i
].code
== quit_char
)
2616 nread
= read (fileno (stdin
), buf
, 1);
2618 /* Scan the chars for C-g and store them in kbd_buffer. */
2619 e
.kind
= ascii_keystroke
;
2620 XSETFRAME (e
.frame_or_window
, selected_frame
);
2622 for (i
= 0; i
< nread
; i
++)
2624 /* Convert chars > 0177 to meta events if desired.
2625 We do this under the same conditions that read_avail_input does. */
2626 if (read_socket_hook
== 0)
2628 /* If the user says she has a meta key, then believe her. */
2629 if (meta_key
== 1 && (buf
[i
] & 0x80))
2630 e
.modifiers
= meta_modifier
;
2635 XSETINT (e
.code
, buf
[i
]);
2636 kbd_buffer_store_event (&e
);
2637 /* Don't look at input that follows a C-g too closely.
2638 This reduces lossage due to autorepeat on C-g. */
2639 if (buf
[i
] == quit_char
)
2645 #endif /* not HAVE_SELECT */
2646 #endif /* not VMS */
2647 #endif /* not MSDOS */
2651 * Partially emulate 4.2 open call.
2652 * open is defined as this in 4.1.
2654 * - added by Michael Bloom @ Citicorp/TTI
2659 sys_open (path
, oflag
, mode
)
2663 if (oflag
& O_CREAT
)
2664 return creat (path
, mode
);
2666 return open (path
, oflag
);
2675 lmode
= LINTRUP
| lmode
;
2676 ioctl (fd
, TIOCLSET
, &lmode
);
2684 lmode
= ~LINTRUP
& lmode
;
2685 ioctl (0, TIOCLSET
, &lmode
);
2693 interrupts_deferred
= 0;
2701 interrupts_deferred
= 1;
2704 /* still inside #ifdef BSD4_1 */
2707 int sigheld
; /* Mask of held signals */
2713 sigheld
|= sigbit (signum
);
2721 sigheld
|= sigbit (signum
);
2728 sigheld
&= ~sigbit (signum
);
2733 sigfree () /* Free all held signals */
2736 for (i
= 0; i
< NSIG
; i
++)
2737 if (sigheld
& sigbit (i
))
2745 return 1 << (i
- 1);
2747 #endif /* subprocesses */
2750 /* POSIX signals support - DJB */
2751 /* Anyone with POSIX signals should have ANSI C declarations */
2753 #ifdef POSIX_SIGNALS
2755 sigset_t empty_mask
, full_mask
;
2760 sigemptyset (&empty_mask
);
2761 sigfillset (&full_mask
);
2765 sys_signal (int signal_number
, signal_handler_t action
)
2767 struct sigaction new_action
, old_action
;
2768 sigemptyset (&new_action
.sa_mask
);
2769 new_action
.sa_handler
= action
;
2771 /* Emacs mostly works better with restartable system services. If this
2772 * flag exists, we probably want to turn it on here.
2774 new_action
.sa_flags
= SA_RESTART
;
2776 new_action
.sa_flags
= 0;
2778 sigaction (signal_number
, &new_action
, &old_action
);
2779 return (old_action
.sa_handler
);
2783 /* If we're compiling with GCC, we don't need this function, since it
2784 can be written as a macro. */
2786 sys_sigmask (int sig
)
2789 sigemptyset (&mask
);
2790 sigaddset (&mask
, sig
);
2795 /* I'd like to have these guys return pointers to the mask storage in here,
2796 but there'd be trouble if the code was saving multiple masks. I'll be
2797 safe and pass the structure. It normally won't be more than 2 bytes
2801 sys_sigblock (sigset_t new_mask
)
2804 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2809 sys_sigunblock (sigset_t new_mask
)
2812 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2817 sys_sigsetmask (sigset_t new_mask
)
2820 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2824 #endif /* POSIX_SIGNALS */
2832 /* Figure out how many bits the system's random number generator uses.
2833 `random' and `lrand48' are assumed to return 31 usable bits.
2834 BSD `rand' returns a 31 bit value but the low order bits are unusable;
2835 so we'll shift it and treat it like the 15-bit USG `rand'. */
2839 # define RAND_BITS 31
2840 # else /* !HAVE_RANDOM */
2841 # ifdef HAVE_LRAND48
2842 # define RAND_BITS 31
2843 # define random lrand48
2844 # else /* !HAVE_LRAND48 */
2845 # define RAND_BITS 15
2846 # if RAND_MAX == 32767
2847 # define random rand
2848 # else /* RAND_MAX != 32767 */
2849 # if RAND_MAX == 2147483647
2850 # define random() (rand () >> 16)
2851 # else /* RAND_MAX != 2147483647 */
2853 # define random rand
2855 # define random() (rand () >> 16)
2857 # endif /* RAND_MAX != 2147483647 */
2858 # endif /* RAND_MAX != 32767 */
2859 # endif /* !HAVE_LRAND48 */
2860 # endif /* !HAVE_RANDOM */
2861 #endif /* !RAND_BITS */
2868 srandom ((unsigned int)arg
);
2870 # ifdef HAVE_LRAND48
2873 srand ((unsigned int)arg
);
2879 * Build a full Emacs-sized word out of whatever we've got.
2880 * This suffices even for a 64-bit architecture with a 15-bit rand.
2885 long val
= random ();
2886 #if VALBITS > RAND_BITS
2887 val
= (val
<< RAND_BITS
) ^ random ();
2888 #if VALBITS > 2*RAND_BITS
2889 val
= (val
<< RAND_BITS
) ^ random ();
2890 #if VALBITS > 3*RAND_BITS
2891 val
= (val
<< RAND_BITS
) ^ random ();
2892 #if VALBITS > 4*RAND_BITS
2893 val
= (val
<< RAND_BITS
) ^ random ();
2894 #endif /* need at least 5 */
2895 #endif /* need at least 4 */
2896 #endif /* need at least 3 */
2897 #endif /* need at least 2 */
2898 return val
& ((1L << VALBITS
) - 1);
2901 #ifdef WRONG_NAME_INSQUE
2914 /* If any place else asks for the TERM variable,
2915 allow it to be overridden with the EMACS_TERM variable
2916 before attempting to translate the logical name TERM. As a last
2917 resort, ask for VAX C's special idea of the TERM variable. */
2924 static char buf
[256];
2925 static struct dsc$descriptor_s equiv
2926 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2927 static struct dsc$descriptor_s d_name
2928 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2931 if (!strcmp (name
, "TERM"))
2933 val
= (char *) getenv ("EMACS_TERM");
2938 d_name
.dsc$w_length
= strlen (name
);
2939 d_name
.dsc$a_pointer
= name
;
2940 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2942 char *str
= (char *) xmalloc (eqlen
+ 1);
2943 bcopy (buf
, str
, eqlen
);
2945 /* This is a storage leak, but a pain to fix. With luck,
2946 no one will ever notice. */
2949 return (char *) getenv (name
);
2954 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2955 to force a call on the debugger from within the image. */
2960 LIB$
SIGNAL (SS$_DEBUG
);
2966 #ifdef LINK_CRTL_SHARE
2967 #ifdef SHARABLE_LIB_BUG
2968 /* Variables declared noshare and initialized in sharable libraries
2969 cannot be shared. The VMS linker incorrectly forces you to use a private
2970 version which is uninitialized... If not for this "feature", we
2971 could use the C library definition of sys_nerr and sys_errlist. */
2973 char *sys_errlist
[] =
2977 "no such file or directory",
2979 "interrupted system call",
2981 "no such device or address",
2982 "argument list too long",
2983 "exec format error",
2986 "no more processes",
2987 "not enough memory",
2988 "permission denied",
2990 "block device required",
2991 "mount devices busy",
2993 "cross-device link",
2998 "file table overflow",
2999 "too many open files",
3003 "no space left on device",
3005 "read-only file system",
3011 "vax/vms specific error code nontranslatable error"
3013 #endif /* SHARABLE_LIB_BUG */
3014 #endif /* LINK_CRTL_SHARE */
3017 #ifndef HAVE_STRERROR
3023 extern char *sys_errlist
[];
3024 extern int sys_nerr
;
3026 if (errnum
>= 0 && errnum
< sys_nerr
)
3027 return sys_errlist
[errnum
];
3028 return (char *) "Unknown error";
3030 #endif /* not WINDOWSNT */
3031 #endif /* ! HAVE_STRERROR */
3033 #ifdef INTERRUPTIBLE_OPEN
3037 sys_open (path
, oflag
, mode
)
3041 register int rtnval
;
3043 while ((rtnval
= open (path
, oflag
, mode
)) == -1
3044 && (errno
== EINTR
));
3048 #endif /* INTERRUPTIBLE_OPEN */
3050 #ifdef INTERRUPTIBLE_CLOSE
3057 register int rtnval
;
3059 while ((rtnval
= close (fd
)) == -1
3060 && (errno
== EINTR
))
3063 /* If close is interrupted SunOS 4.1 may or may not have closed the
3064 file descriptor. If it did the second close will fail with
3065 errno = EBADF. That means we have succeeded. */
3066 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3072 #endif /* INTERRUPTIBLE_CLOSE */
3074 #ifdef INTERRUPTIBLE_IO
3077 sys_read (fildes
, buf
, nbyte
)
3082 register int rtnval
;
3084 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3085 && (errno
== EINTR
));
3090 sys_write (fildes
, buf
, nbyte
)
3095 register int rtnval
, bytes_written
;
3101 rtnval
= write (fildes
, buf
, nbyte
);
3108 return (bytes_written
? bytes_written
: -1);
3113 bytes_written
+= rtnval
;
3115 return (bytes_written
);
3118 #endif /* INTERRUPTIBLE_IO */
3123 * Substitute fork for vfork on USG flavors.
3131 #endif /* not WINDOWSNT */
3132 #endif /* not HAVE_VFORK */
3136 * All of the following are for USG.
3138 * On USG systems the system calls are INTERRUPTIBLE by signals
3139 * that the user program has elected to catch. Thus the system call
3140 * must be retried in these cases. To handle this without massive
3141 * changes in the source code, we remap the standard system call names
3142 * to names for our own functions in sysdep.c that do the system call
3143 * with retries. Actually, for portability reasons, it is good
3144 * programming practice, as this example shows, to limit all actual
3145 * system calls to a single occurrence in the source. Sure, this
3146 * adds an extra level of function call overhead but it is almost
3147 * always negligible. Fred Fish, Unisoft Systems Inc.
3150 #ifndef HAVE_SYS_SIGLIST
3151 char *sys_siglist
[NSIG
+ 1] =
3154 /* AIX has changed the signals a bit */
3155 "bogus signal", /* 0 */
3156 "hangup", /* 1 SIGHUP */
3157 "interrupt", /* 2 SIGINT */
3158 "quit", /* 3 SIGQUIT */
3159 "illegal instruction", /* 4 SIGILL */
3160 "trace trap", /* 5 SIGTRAP */
3161 "IOT instruction", /* 6 SIGIOT */
3162 "crash likely", /* 7 SIGDANGER */
3163 "floating point exception", /* 8 SIGFPE */
3164 "kill", /* 9 SIGKILL */
3165 "bus error", /* 10 SIGBUS */
3166 "segmentation violation", /* 11 SIGSEGV */
3167 "bad argument to system call", /* 12 SIGSYS */
3168 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3169 "alarm clock", /* 14 SIGALRM */
3170 "software termination signum", /* 15 SIGTERM */
3171 "user defined signal 1", /* 16 SIGUSR1 */
3172 "user defined signal 2", /* 17 SIGUSR2 */
3173 "death of a child", /* 18 SIGCLD */
3174 "power-fail restart", /* 19 SIGPWR */
3175 "bogus signal", /* 20 */
3176 "bogus signal", /* 21 */
3177 "bogus signal", /* 22 */
3178 "bogus signal", /* 23 */
3179 "bogus signal", /* 24 */
3180 "LAN I/O interrupt", /* 25 SIGAIO */
3181 "PTY I/O interrupt", /* 26 SIGPTY */
3182 "I/O intervention required", /* 27 SIGIOINT */
3184 "HFT grant", /* 28 SIGGRANT */
3185 "HFT retract", /* 29 SIGRETRACT */
3186 "HFT sound done", /* 30 SIGSOUND */
3187 "HFT input ready", /* 31 SIGMSG */
3190 "bogus signal", /* 0 */
3191 "hangup", /* 1 SIGHUP */
3192 "interrupt", /* 2 SIGINT */
3193 "quit", /* 3 SIGQUIT */
3194 "illegal instruction", /* 4 SIGILL */
3195 "trace trap", /* 5 SIGTRAP */
3196 "IOT instruction", /* 6 SIGIOT */
3197 "EMT instruction", /* 7 SIGEMT */
3198 "floating point exception", /* 8 SIGFPE */
3199 "kill", /* 9 SIGKILL */
3200 "bus error", /* 10 SIGBUS */
3201 "segmentation violation", /* 11 SIGSEGV */
3202 "bad argument to system call", /* 12 SIGSYS */
3203 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3204 "alarm clock", /* 14 SIGALRM */
3205 "software termination signum", /* 15 SIGTERM */
3206 "user defined signal 1", /* 16 SIGUSR1 */
3207 "user defined signal 2", /* 17 SIGUSR2 */
3208 "death of a child", /* 18 SIGCLD */
3209 "power-fail restart", /* 19 SIGPWR */
3211 "window size change", /* 20 SIGWINCH */
3212 "urgent socket condition", /* 21 SIGURG */
3213 "pollable event occurred", /* 22 SIGPOLL */
3214 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */
3215 "user stop requested from tty", /* 24 SIGTSTP */
3216 "stopped process has been continued", /* 25 SIGCONT */
3217 "background tty read attempted", /* 26 SIGTTIN */
3218 "background tty write attempted", /* 27 SIGTTOU */
3219 "virtual timer expired", /* 28 SIGVTALRM */
3220 "profiling timer expired", /* 29 SIGPROF */
3221 "exceeded cpu limit", /* 30 SIGXCPU */
3222 "exceeded file size limit", /* 31 SIGXFSZ */
3223 "process's lwps are blocked", /* 32 SIGWAITING */
3224 "special signal used by thread library", /* 33 SIGLWP */
3226 "Special Signal Used By CPR", /* 34 SIGFREEZE */
3229 "Special Signal Used By CPR", /* 35 SIGTHAW */
3232 #endif /* not AIX */
3235 #endif /* HAVE_SYS_SIGLIST */
3238 * Warning, this function may not duplicate 4.2 action properly
3239 * under error conditions.
3243 /* In 4.1, param.h fails to define this. */
3244 #define MAXPATHLEN 1024
3253 char *npath
, *spath
;
3254 extern char *getcwd ();
3256 BLOCK_INPUT
; /* getcwd uses malloc */
3257 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3260 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3261 up to first slash. Should be harmless on other systems. */
3262 while (*npath
&& *npath
!= '/')
3264 strcpy (pathname
, npath
);
3265 free (spath
); /* getcwd uses malloc */
3270 #endif /* HAVE_GETWD */
3273 * Emulate rename using unlink/link. Note that this is
3274 * only partially correct. Also, doesn't enforce restriction
3275 * that files be of same type (regular->regular, dir->dir, etc).
3284 if (access (from
, 0) == 0)
3287 if (link (from
, to
) == 0)
3288 if (unlink (from
) == 0)
3300 /* HPUX curses library references perror, but as far as we know
3301 it won't be called. Anyway this definition will do for now. */
3307 #endif /* not HAVE_PERROR */
3313 * Emulate BSD dup2. First close newd if it already exists.
3314 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3315 * until we are, then close the unsuccessful ones.
3322 register int fd
, ret
;
3327 fd
= fcntl (oldd
, F_DUPFD
, newd
);
3329 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, strerror (errno
));
3336 ret
= dup2 (old
,new);
3342 #endif /* not HAVE_DUP2 */
3345 * Gettimeofday. Simulate as much as possible. Only accurate
3346 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3347 * Only needed when subprocesses are defined.
3352 #ifndef HAVE_GETTIMEOFDAY
3357 gettimeofday (tp
, tzp
)
3359 struct timezone
*tzp
;
3361 extern long time ();
3363 tp
->tv_sec
= time ((long *)0);
3366 tzp
->tz_minuteswest
= -1;
3373 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3376 * This function will go away as soon as all the stubs fixed. (fnf)
3383 printf ("%s not yet implemented\r\n", badfunc
);
3392 char *sys_siglist
[NSIG
+ 1] =
3394 "null signal", /* 0 SIGNULL */
3395 "hangup", /* 1 SIGHUP */
3396 "interrupt", /* 2 SIGINT */
3397 "quit", /* 3 SIGQUIT */
3398 "illegal instruction", /* 4 SIGILL */
3399 "trace trap", /* 5 SIGTRAP */
3400 "abort termination", /* 6 SIGABRT */
3401 "SIGEMT", /* 7 SIGEMT */
3402 "floating point exception", /* 8 SIGFPE */
3403 "kill", /* 9 SIGKILL */
3404 "bus error", /* 10 SIGBUS */
3405 "segmentation violation", /* 11 SIGSEGV */
3406 "bad argument to system call", /* 12 SIGSYS */
3407 "write on a pipe with no reader", /* 13 SIGPIPE */
3408 "alarm clock", /* 14 SIGALRM */
3409 "software termination signal", /* 15 SIGTERM */
3410 "user defined signal 1", /* 16 SIGUSR1 */
3411 "user defined signal 2", /* 17 SIGUSR2 */
3412 "child stopped or terminated", /* 18 SIGCLD */
3413 "power-fail restart", /* 19 SIGPWR */
3414 "window size changed", /* 20 SIGWINCH */
3415 "undefined", /* 21 */
3416 "pollable event occurred", /* 22 SIGPOLL */
3417 "sendable stop signal not from tty", /* 23 SIGSTOP */
3418 "stop signal from tty", /* 24 SIGSTP */
3419 "continue a stopped process", /* 25 SIGCONT */
3420 "attempted background tty read", /* 26 SIGTTIN */
3421 "attempted background tty write", /* 27 SIGTTOU */
3422 "undefined", /* 28 */
3423 "undefined", /* 29 */
3424 "undefined", /* 30 */
3425 "undefined", /* 31 */
3426 "undefined", /* 32 */
3427 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
3428 "I/O is possible", /* 34 SIGIO */
3429 "exceeded cpu time limit", /* 35 SIGXCPU */
3430 "exceeded file size limit", /* 36 SIGXFSZ */
3431 "virtual time alarm", /* 37 SIGVTALRM */
3432 "profiling time alarm", /* 38 SIGPROF */
3433 "undefined", /* 39 */
3434 "file record locks revoked", /* 40 SIGLOST */
3435 "undefined", /* 41 */
3436 "undefined", /* 42 */
3437 "undefined", /* 43 */
3438 "undefined", /* 44 */
3439 "undefined", /* 45 */
3440 "undefined", /* 46 */
3441 "undefined", /* 47 */
3442 "undefined", /* 48 */
3443 "undefined", /* 49 */
3444 "undefined", /* 50 */
3445 "undefined", /* 51 */
3446 "undefined", /* 52 */
3447 "undefined", /* 53 */
3448 "undefined", /* 54 */
3449 "undefined", /* 55 */
3450 "undefined", /* 56 */
3451 "undefined", /* 57 */
3452 "undefined", /* 58 */
3453 "undefined", /* 59 */
3454 "undefined", /* 60 */
3455 "undefined", /* 61 */
3456 "undefined", /* 62 */
3457 "undefined", /* 63 */
3458 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3464 /* Directory routines for systems that don't have them. */
3466 #ifdef SYSV_SYSTEM_DIR
3470 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
3474 register DIR *dirp
; /* stream from opendir */
3478 rtnval
= sys_close (dirp
->dd_fd
);
3480 /* Some systems (like Solaris) allocate the buffer and the DIR all
3481 in one block. Why in the world are we freeing this ourselves
3483 #if ! (defined (sun) && defined (USG5_4))
3484 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3486 xfree ((char *) dirp
);
3490 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3491 #endif /* SYSV_SYSTEM_DIR */
3493 #ifdef NONSYSTEM_DIR_LIBRARY
3497 char *filename
; /* name of directory */
3499 register DIR *dirp
; /* -> malloc'ed storage */
3500 register int fd
; /* file descriptor for read */
3501 struct stat sbuf
; /* result of fstat */
3503 fd
= sys_open (filename
, 0);
3508 if (fstat (fd
, &sbuf
) < 0
3509 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3510 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
3514 return 0; /* bad luck today */
3519 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3526 register DIR *dirp
; /* stream from opendir */
3528 sys_close (dirp
->dd_fd
);
3529 xfree ((char *) dirp
);
3537 ino_t od_ino
; /* inode */
3538 char od_name
[DIRSIZ
]; /* filename */
3540 #endif /* not VMS */
3542 struct direct dir_static
; /* simulated directory contents */
3547 register DIR *dirp
; /* stream from opendir */
3550 register struct olddir
*dp
; /* -> directory data */
3552 register struct dir$_name
*dp
; /* -> directory data */
3553 register struct dir$_version
*dv
; /* -> version data */
3558 if (dirp
->dd_loc
>= dirp
->dd_size
)
3559 dirp
->dd_loc
= dirp
->dd_size
= 0;
3561 if (dirp
->dd_size
== 0 /* refill buffer */
3562 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3566 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3567 dirp
->dd_loc
+= sizeof (struct olddir
);
3569 if (dp
->od_ino
!= 0) /* not deleted entry */
3571 dir_static
.d_ino
= dp
->od_ino
;
3572 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3573 dir_static
.d_name
[DIRSIZ
] = '\0';
3574 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3575 dir_static
.d_reclen
= sizeof (struct direct
)
3577 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3578 return &dir_static
; /* -> simulated structure */
3581 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3582 if (dirp
->dd_loc
== 0)
3583 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3584 : dp
->dir$b_namecount
;
3585 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3586 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3587 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3588 dir_static
.d_reclen
= sizeof (struct direct
)
3590 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3591 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3592 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3593 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3600 /* readdirver is just like readdir except it returns all versions of a file
3601 as separate entries. */
3606 register DIR *dirp
; /* stream from opendir */
3608 register struct dir$_name
*dp
; /* -> directory data */
3609 register struct dir$_version
*dv
; /* -> version data */
3611 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3612 dirp
->dd_loc
= dirp
->dd_size
= 0;
3614 if (dirp
->dd_size
== 0 /* refill buffer */
3615 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3618 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3619 if (dirp
->dd_loc
== 0)
3620 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3621 : dp
->dir$b_namecount
;
3622 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3623 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3624 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3625 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3626 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3627 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3628 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3629 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3635 #endif /* NONSYSTEM_DIR_LIBRARY */
3639 set_file_times (filename
, atime
, mtime
)
3641 EMACS_TIME atime
, mtime
;
3644 struct timeval tv
[2];
3647 return utimes (filename
, tv
);
3648 #else /* not HAVE_UTIMES */
3650 utb
.actime
= EMACS_SECS (atime
);
3651 utb
.modtime
= EMACS_SECS (mtime
);
3652 return utime (filename
, &utb
);
3653 #endif /* not HAVE_UTIMES */
3656 /* mkdir and rmdir functions, for systems which don't have them. */
3660 * Written by Robert Rother, Mariah Corporation, August 1985.
3662 * If you want it, it's yours. All I ask in return is that if you
3663 * figure out how to do this in a Bourne Shell script you send me
3665 * sdcsvax!rmr or rmr@uscd
3667 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3668 * subroutine. 11Mar86; hoptoad!gnu
3670 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3671 * subroutine didn't return EEXIST. It does now.
3677 #ifdef MKDIR_PROTOTYPE
3681 mkdir (dpath
, dmode
)
3686 int cpid
, status
, fd
;
3687 struct stat statbuf
;
3689 if (stat (dpath
, &statbuf
) == 0)
3691 errno
= EEXIST
; /* Stat worked, so it already exists */
3695 /* If stat fails for a reason other than non-existence, return error */
3696 if (errno
!= ENOENT
)
3699 synch_process_alive
= 1;
3700 switch (cpid
= fork ())
3703 case -1: /* Error in fork */
3704 return (-1); /* Errno is set already */
3706 case 0: /* Child process */
3708 * Cheap hack to set mode of new directory. Since this
3709 * child process is going away anyway, we zap its umask.
3710 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3711 * directory. Does anybody care?
3713 status
= umask (0); /* Get current umask */
3714 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3715 fd
= sys_open("/dev/null", 2);
3722 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3723 _exit (-1); /* Can't exec /bin/mkdir */
3725 default: /* Parent process */
3726 wait_for_termination (cpid
);
3729 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3731 errno
= EIO
; /* We don't know why, but */
3732 return -1; /* /bin/mkdir failed */
3737 #endif /* not HAVE_MKDIR */
3744 int cpid
, status
, fd
;
3745 struct stat statbuf
;
3747 if (stat (dpath
, &statbuf
) != 0)
3749 /* Stat just set errno. We don't have to */
3753 synch_process_alive
= 1;
3754 switch (cpid
= fork ())
3757 case -1: /* Error in fork */
3758 return (-1); /* Errno is set already */
3760 case 0: /* Child process */
3761 fd
= sys_open("/dev/null", 2);
3768 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3769 _exit (-1); /* Can't exec /bin/rmdir */
3771 default: /* Parent process */
3772 wait_for_termination (cpid
);
3775 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3777 errno
= EIO
; /* We don't know why, but */
3778 return -1; /* /bin/rmdir failed */
3783 #endif /* !HAVE_RMDIR */
3787 /* Functions for VMS */
3789 #include "vms-pwd.h"
3794 /* Return as a string the VMS error string pertaining to STATUS.
3795 Reuses the same static buffer each time it is called. */
3799 int status
; /* VMS status code */
3803 static char buf
[257];
3805 bufadr
[0] = sizeof buf
- 1;
3806 bufadr
[1] = (int) buf
;
3807 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3808 return "untranslatable VMS error status";
3816 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3817 * not work correctly. (It also doesn't work well in version 2.3.)
3822 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3823 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3827 unsigned short s_buflen
;
3828 unsigned short s_code
;
3830 unsigned short *s_retlenadr
;
3834 #define buflen s.s_buflen
3835 #define code s.s_code
3836 #define bufadr s.s_bufadr
3837 #define retlenadr s.s_retlenadr
3839 #define R_OK 4 /* test for read permission */
3840 #define W_OK 2 /* test for write permission */
3841 #define X_OK 1 /* test for execute (search) permission */
3842 #define F_OK 0 /* test for presence of file */
3845 sys_access (path
, mode
)
3849 static char *user
= NULL
;
3852 /* translate possible directory spec into .DIR file name, so brain-dead
3853 * access can treat the directory like a file. */
3854 if (directory_file_name (path
, dir_fn
))
3858 return access (path
, mode
);
3859 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3865 unsigned short int dummy
;
3867 static int constant
= ACL$C_FILE
;
3868 DESCRIPTOR (path_desc
, path
);
3869 DESCRIPTOR (user_desc
, user
);
3873 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3876 acces
|= CHP$M_READ
;
3878 acces
|= CHP$M_WRITE
;
3879 itemlst
[0].buflen
= sizeof (int);
3880 itemlst
[0].code
= CHP$_FLAGS
;
3881 itemlst
[0].bufadr
= (char *) &flags
;
3882 itemlst
[0].retlenadr
= &dummy
;
3883 itemlst
[1].buflen
= sizeof (int);
3884 itemlst
[1].code
= CHP$_ACCESS
;
3885 itemlst
[1].bufadr
= (char *) &acces
;
3886 itemlst
[1].retlenadr
= &dummy
;
3887 itemlst
[2].end
= CHP$_END
;
3888 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3889 return stat
== SS$_NORMAL
? 0 : -1;
3893 #else /* not VMS4_4 */
3896 #define ACE$M_WRITE 2
3897 #define ACE$C_KEYID 1
3899 static unsigned short memid
, grpid
;
3900 static unsigned int uic
;
3902 /* Called from init_sys_modes, so it happens not very often
3903 but at least each time Emacs is loaded. */
3905 sys_access_reinit ()
3911 sys_access (filename
, type
)
3917 int status
, size
, i
, typecode
, acl_controlled
;
3918 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3919 union prvdef prvmask
;
3921 /* Get UIC and GRP values for protection checking. */
3924 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3927 memid
= uic
& 0xFFFF;
3931 if (type
!= 2) /* not checking write access */
3932 return access (filename
, type
);
3934 /* Check write protection. */
3936 #define CHECKPRIV(bit) (prvmask.bit)
3937 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3939 /* Find privilege bits */
3940 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3942 error ("Unable to find privileges: %s", vmserrstr (status
));
3943 if (CHECKPRIV (PRV$V_BYPASS
))
3944 return 0; /* BYPASS enabled */
3946 fab
.fab$b_fac
= FAB$M_GET
;
3947 fab
.fab$l_fna
= filename
;
3948 fab
.fab$b_fns
= strlen (filename
);
3949 fab
.fab$l_xab
= &xab
;
3950 xab
= cc$rms_xabpro
;
3951 xab
.xab$l_aclbuf
= aclbuf
;
3952 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3953 status
= SYS$
OPEN (&fab
, 0, 0);
3956 SYS$
CLOSE (&fab
, 0, 0);
3957 /* Check system access */
3958 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
3960 /* Check ACL entries, if any */
3962 if (xab
.xab$w_acllen
> 0)
3965 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3966 while (*aclptr
&& aclptr
< aclend
)
3968 size
= (*aclptr
& 0xff) / 4;
3969 typecode
= (*aclptr
>> 8) & 0xff;
3970 if (typecode
== ACE$C_KEYID
)
3971 for (i
= size
- 1; i
> 1; i
--)
3972 if (aclptr
[i
] == uic
)
3975 if (aclptr
[1] & ACE$M_WRITE
)
3976 return 0; /* Write access through ACL */
3978 aclptr
= &aclptr
[size
];
3980 if (acl_controlled
) /* ACL specified, prohibits write access */
3983 /* No ACL entries specified, check normal protection */
3984 if (WRITABLE (XAB$V_WLD
)) /* World writable */
3986 if (WRITABLE (XAB$V_GRP
) &&
3987 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3988 return 0; /* Group writable */
3989 if (WRITABLE (XAB$V_OWN
) &&
3990 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3991 return 0; /* Owner writable */
3993 return -1; /* Not writable */
3995 #endif /* not VMS4_4 */
3998 static char vtbuf
[NAM$C_MAXRSS
+1];
4000 /* translate a vms file spec to a unix path */
4002 sys_translate_vms (vfile
)
4013 /* leading device or logical name is a root directory */
4014 if (p
= strchr (vfile
, ':'))
4023 if (*p
== '[' || *p
== '<')
4025 while (*++vfile
!= *p
+ 2)
4029 if (vfile
[-1] == *p
)
4052 static char utbuf
[NAM$C_MAXRSS
+1];
4054 /* translate a unix path to a VMS file spec */
4056 sys_translate_unix (ufile
)
4079 if (index (&ufile
[1], '/'))
4086 if (index (&ufile
[1], '/'))
4093 if (strncmp (ufile
, "./", 2) == 0)
4100 ufile
++; /* skip the dot */
4101 if (index (&ufile
[1], '/'))
4106 else if (strncmp (ufile
, "../", 3) == 0)
4114 ufile
+= 2; /* skip the dots */
4115 if (index (&ufile
[1], '/'))
4140 extern char *getcwd ();
4142 #define MAXPATHLEN 1024
4144 ptr
= xmalloc (MAXPATHLEN
);
4145 val
= getcwd (ptr
, MAXPATHLEN
);
4151 strcpy (pathname
, ptr
);
4160 long item_code
= JPI$_OWNER
;
4161 unsigned long parent_id
;
4164 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4167 vaxc$errno
= status
;
4177 return (getgid () << 16) | getuid ();
4181 sys_read (fildes
, buf
, nbyte
)
4186 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4191 sys_write (fildes
, buf
, nbyte
)
4196 register int nwrote
, rtnval
= 0;
4198 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4204 return rtnval
? rtnval
: -1;
4205 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4206 return rtnval
? rtnval
: -1;
4207 return (rtnval
+ nwrote
);
4212 * VAX/VMS VAX C RTL really loses. It insists that records
4213 * end with a newline (carriage return) character, and if they
4214 * don't it adds one (nice of it isn't it!)
4216 * Thus we do this stupidity below.
4220 sys_write (fildes
, buf
, nbytes
)
4223 unsigned int nbytes
;
4230 fstat (fildes
, &st
);
4236 /* Handle fixed-length files with carriage control. */
4237 if (st
.st_fab_rfm
== FAB$C_FIX
4238 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4240 len
= st
.st_fab_mrs
;
4241 retval
= write (fildes
, p
, min (len
, nbytes
));
4244 retval
++; /* This skips the implied carriage control */
4248 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4249 while (*e
!= '\n' && e
> p
) e
--;
4250 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4251 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4253 retval
= write (fildes
, p
, len
);
4264 /* Create file NEW copying its attributes from file OLD. If
4265 OLD is 0 or does not exist, create based on the value of
4268 /* Protection value the file should ultimately have.
4269 Set by create_copy_attrs, and use by rename_sansversions. */
4270 static unsigned short int fab_final_pro
;
4273 creat_copy_attrs (old
, new)
4276 struct FAB fab
= cc$rms_fab
;
4277 struct XABPRO xabpro
;
4278 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4279 extern int vms_stmlf_recfm
;
4283 fab
.fab$b_fac
= FAB$M_GET
;
4284 fab
.fab$l_fna
= old
;
4285 fab
.fab$b_fns
= strlen (old
);
4286 fab
.fab$l_xab
= (char *) &xabpro
;
4287 xabpro
= cc$rms_xabpro
;
4288 xabpro
.xab$l_aclbuf
= aclbuf
;
4289 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4290 /* Call $OPEN to fill in the fab & xabpro fields. */
4291 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4293 SYS$
CLOSE (&fab
, 0, 0);
4294 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4295 if (xabpro
.xab$w_acllen
> 0)
4297 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4298 /* If the acl buffer was too short, redo open with longer one.
4299 Wouldn't need to do this if there were some system imposed
4300 limit on the size of an ACL, but I can't find any such. */
4302 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4303 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4304 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4305 SYS$
CLOSE (&fab
, 0, 0);
4311 xabpro
.xab$l_aclbuf
= 0;
4316 fab
.fab$l_fna
= new;
4317 fab
.fab$b_fns
= strlen (new);
4321 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4322 fab
.fab$b_rat
= FAB$M_CR
;
4325 /* Set the file protections such that we will be able to manipulate
4326 this file. Once we are done writing and renaming it, we will set
4327 the protections back. */
4329 fab_final_pro
= xabpro
.xab$w_pro
;
4331 SYS$
SETDFPROT (0, &fab_final_pro
);
4332 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4334 /* Create the new file with either default attrs or attrs copied
4336 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4338 SYS$
CLOSE (&fab
, 0, 0);
4339 /* As this is a "replacement" for creat, return a file descriptor
4340 opened for writing. */
4341 return open (new, O_WRONLY
);
4346 #include <varargs.h>
4349 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4354 sys_creat (va_alist
)
4357 va_list list_incrementer
;
4360 int rfd
; /* related file descriptor */
4361 int fd
; /* Our new file descriptor */
4368 extern int vms_stmlf_recfm
;
4371 va_start (list_incrementer
);
4372 name
= va_arg (list_incrementer
, char *);
4373 mode
= va_arg (list_incrementer
, int);
4375 rfd
= va_arg (list_incrementer
, int);
4376 va_end (list_incrementer
);
4379 /* Use information from the related file descriptor to set record
4380 format of the newly created file. */
4381 fstat (rfd
, &st_buf
);
4382 switch (st_buf
.st_fab_rfm
)
4385 strcpy (rfm
, "rfm = fix");
4386 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4387 strcpy (rat
, "rat = ");
4388 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4390 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4391 strcat (rat
, "ftn");
4392 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4393 strcat (rat
, "prn");
4394 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4395 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4396 strcat (rat
, ", blk");
4398 strcat (rat
, "blk");
4399 return creat (name
, 0, rfm
, rat
, mrs
);
4402 strcpy (rfm
, "rfm = vfc");
4403 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4404 strcpy (rat
, "rat = ");
4405 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4407 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4408 strcat (rat
, "ftn");
4409 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4410 strcat (rat
, "prn");
4411 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4412 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4413 strcat (rat
, ", blk");
4415 strcat (rat
, "blk");
4416 return creat (name
, 0, rfm
, rat
, fsz
);
4419 strcpy (rfm
, "rfm = stm");
4423 strcpy (rfm
, "rfm = stmcr");
4427 strcpy (rfm
, "rfm = stmlf");
4431 strcpy (rfm
, "rfm = udf");
4435 strcpy (rfm
, "rfm = var");
4438 strcpy (rat
, "rat = ");
4439 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4441 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4442 strcat (rat
, "ftn");
4443 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4444 strcat (rat
, "prn");
4445 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4446 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4447 strcat (rat
, ", blk");
4449 strcat (rat
, "blk");
4453 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4454 strcpy (rat
, "rat=cr");
4456 /* Until the VAX C RTL fixes the many bugs with modes, always use
4457 mode 0 to get the user's default protection. */
4458 fd
= creat (name
, 0, rfm
, rat
);
4459 if (fd
< 0 && errno
== EEXIST
)
4461 if (unlink (name
) < 0)
4462 report_file_error ("delete", build_string (name
));
4463 fd
= creat (name
, 0, rfm
, rat
);
4469 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4471 sys_fwrite (ptr
, size
, num
, fp
)
4472 register char * ptr
;
4475 register int tot
= num
* size
;
4483 * The VMS C library routine creat actually creates a new version of an
4484 * existing file rather than truncating the old version. There are times
4485 * when this is not the desired behavior, for instance, when writing an
4486 * auto save file (you only want one version), or when you don't have
4487 * write permission in the directory containing the file (but the file
4488 * itself is writable). Hence this routine, which is equivalent to
4489 * "close (creat (fn, 0));" on Unix if fn already exists.
4495 struct FAB xfab
= cc$rms_fab
;
4496 struct RAB xrab
= cc$rms_rab
;
4499 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4500 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4501 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4502 xfab
.fab$l_fna
= fn
;
4503 xfab
.fab$b_fns
= strlen (fn
);
4504 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4506 xrab
.rab$l_fab
= &xfab
;
4508 /* This gibberish opens the file, positions to the first record, and
4509 deletes all records from there until the end of file. */
4510 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4512 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4513 (SYS$
FIND (&xrab
) & 01) == 01 &&
4514 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4525 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4526 SYSPRV or a readable SYSUAF.DAT. */
4532 * Routine to read the VMS User Authorization File and return
4533 * a specific user's record.
4536 static struct UAF retuaf
;
4539 get_uaf_name (uname
)
4546 uaf_fab
= cc$rms_fab
;
4547 uaf_rab
= cc$rms_rab
;
4548 /* initialize fab fields */
4549 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4550 uaf_fab
.fab$b_fns
= 21;
4551 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4552 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4553 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4554 /* initialize rab fields */
4555 uaf_rab
.rab$l_fab
= &uaf_fab
;
4556 /* open the User Authorization File */
4557 status
= SYS$
OPEN (&uaf_fab
);
4561 vaxc$errno
= status
;
4564 status
= SYS$
CONNECT (&uaf_rab
);
4568 vaxc$errno
= status
;
4571 /* read the requested record - index is in uname */
4572 uaf_rab
.rab$l_kbf
= uname
;
4573 uaf_rab
.rab$b_ksz
= strlen (uname
);
4574 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4575 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4576 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4577 status
= SYS$
GET (&uaf_rab
);
4581 vaxc$errno
= status
;
4584 /* close the User Authorization File */
4585 status
= SYS$
DISCONNECT (&uaf_rab
);
4589 vaxc$errno
= status
;
4592 status
= SYS$
CLOSE (&uaf_fab
);
4596 vaxc$errno
= status
;
4610 uaf_fab
= cc$rms_fab
;
4611 uaf_rab
= cc$rms_rab
;
4612 /* initialize fab fields */
4613 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4614 uaf_fab
.fab$b_fns
= 21;
4615 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4616 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4617 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4618 /* initialize rab fields */
4619 uaf_rab
.rab$l_fab
= &uaf_fab
;
4620 /* open the User Authorization File */
4621 status
= SYS$
OPEN (&uaf_fab
);
4625 vaxc$errno
= status
;
4628 status
= SYS$
CONNECT (&uaf_rab
);
4632 vaxc$errno
= status
;
4635 /* read the requested record - index is in uic */
4636 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4637 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4638 uaf_rab
.rab$b_ksz
= sizeof uic
;
4639 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4640 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4641 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4642 status
= SYS$
GET (&uaf_rab
);
4646 vaxc$errno
= status
;
4649 /* close the User Authorization File */
4650 status
= SYS$
DISCONNECT (&uaf_rab
);
4654 vaxc$errno
= status
;
4657 status
= SYS$
CLOSE (&uaf_fab
);
4661 vaxc$errno
= status
;
4667 static struct passwd retpw
;
4675 /* copy these out first because if the username is 32 chars, the next
4676 section will overwrite the first byte of the UIC */
4677 retpw
.pw_uid
= up
->uaf$w_mem
;
4678 retpw
.pw_gid
= up
->uaf$w_grp
;
4680 /* I suppose this is not the best style, to possibly overwrite one
4681 byte beyond the end of the field, but what the heck... */
4682 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4683 while (ptr
[-1] == ' ')
4686 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4688 /* the rest of these are counted ascii strings */
4689 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4690 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4691 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4692 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4693 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4694 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4695 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4696 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4700 #else /* not READ_SYSUAF */
4701 static struct passwd retpw
;
4702 #endif /* not READ_SYSUAF */
4713 unsigned char * full
;
4714 #endif /* READ_SYSUAF */
4719 if ('a' <= *ptr
&& *ptr
<= 'z')
4724 if (!(up
= get_uaf_name (name
)))
4726 return cnv_uaf_pw (up
);
4728 if (strcmp (name
, getenv ("USER")) == 0)
4730 retpw
.pw_uid
= getuid ();
4731 retpw
.pw_gid
= getgid ();
4732 strcpy (retpw
.pw_name
, name
);
4733 if (full
= egetenv ("FULLNAME"))
4734 strcpy (retpw
.pw_gecos
, full
);
4736 *retpw
.pw_gecos
= '\0';
4737 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4738 *retpw
.pw_shell
= '\0';
4743 #endif /* not READ_SYSUAF */
4753 if (!(up
= get_uaf_uic (uid
)))
4755 return cnv_uaf_pw (up
);
4757 if (uid
== sys_getuid ())
4758 return getpwnam (egetenv ("USER"));
4761 #endif /* not READ_SYSUAF */
4764 /* return total address space available to the current process. This is
4765 the sum of the current p0 size, p1 size and free page table entries
4771 unsigned long free_pages
;
4772 unsigned long frep0va
;
4773 unsigned long frep1va
;
4776 item_code
= JPI$_FREPTECNT
;
4777 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4780 vaxc$errno
= status
;
4785 item_code
= JPI$_FREP0VA
;
4786 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4789 vaxc$errno
= status
;
4792 item_code
= JPI$_FREP1VA
;
4793 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4796 vaxc$errno
= status
;
4800 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4804 define_logical_name (varname
, string
)
4808 struct dsc$descriptor_s strdsc
=
4809 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4810 struct dsc$descriptor_s envdsc
=
4811 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4812 struct dsc$descriptor_s lnmdsc
=
4813 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4815 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4819 delete_logical_name (varname
)
4822 struct dsc$descriptor_s envdsc
=
4823 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4824 struct dsc$descriptor_s lnmdsc
=
4825 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4827 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4845 error ("execvp system call not implemented");
4854 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4855 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4856 char from_esn
[NAM$C_MAXRSS
];
4857 char to_esn
[NAM$C_MAXRSS
];
4859 from_fab
.fab$l_fna
= from
;
4860 from_fab
.fab$b_fns
= strlen (from
);
4861 from_fab
.fab$l_nam
= &from_nam
;
4862 from_fab
.fab$l_fop
= FAB$M_NAM
;
4864 from_nam
.nam$l_esa
= from_esn
;
4865 from_nam
.nam$b_ess
= sizeof from_esn
;
4867 to_fab
.fab$l_fna
= to
;
4868 to_fab
.fab$b_fns
= strlen (to
);
4869 to_fab
.fab$l_nam
= &to_nam
;
4870 to_fab
.fab$l_fop
= FAB$M_NAM
;
4872 to_nam
.nam$l_esa
= to_esn
;
4873 to_nam
.nam$b_ess
= sizeof to_esn
;
4875 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4881 if (status
== RMS$_DEV
)
4885 vaxc$errno
= status
;
4890 /* This function renames a file like `rename', but it strips
4891 the version number from the "to" filename, such that the "to" file is
4892 will always be a new version. It also sets the file protection once it is
4893 finished. The protection that we will use is stored in fab_final_pro,
4894 and was set when we did a creat_copy_attrs to create the file that we
4897 We could use the chmod function, but Eunichs uses 3 bits per user category
4898 to describe the protection, and VMS uses 4 (write and delete are separate
4899 bits). To maintain portability, the VMS implementation of `chmod' wires
4900 the W and D bits together. */
4903 static struct fibdef fib
; /* We need this initialized to zero */
4904 char vms_file_written
[NAM$C_MAXRSS
];
4907 rename_sans_version (from
,to
)
4914 struct FAB to_fab
= cc$rms_fab
;
4915 struct NAM to_nam
= cc$rms_nam
;
4916 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4917 struct dsc$descriptor fib_attr
[2]
4918 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4919 char to_esn
[NAM$C_MAXRSS
];
4921 $
DESCRIPTOR (disk
,to_esn
);
4923 to_fab
.fab$l_fna
= to
;
4924 to_fab
.fab$b_fns
= strlen (to
);
4925 to_fab
.fab$l_nam
= &to_nam
;
4926 to_fab
.fab$l_fop
= FAB$M_NAM
;
4928 to_nam
.nam$l_esa
= to_esn
;
4929 to_nam
.nam$b_ess
= sizeof to_esn
;
4931 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4933 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4934 *(to_nam
.nam$l_ver
) = '\0';
4936 stat
= rename (from
, to_esn
);
4940 strcpy (vms_file_written
, to_esn
);
4942 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4943 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4945 /* Now set the file protection to the correct value */
4946 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4948 /* Copy these fields into the fib */
4949 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4950 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4951 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4953 SYS$
CLOSE (&to_fab
, 0, 0);
4955 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4958 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4959 0, 0, 0, &fib_attr
, 0);
4962 stat
= SYS$
DASSGN (chan
);
4965 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4976 unsigned short fid
[3];
4977 char esa
[NAM$C_MAXRSS
];
4980 fab
.fab$l_fop
= FAB$M_OFP
;
4981 fab
.fab$l_fna
= file
;
4982 fab
.fab$b_fns
= strlen (file
);
4983 fab
.fab$l_nam
= &nam
;
4986 nam
.nam$l_esa
= esa
;
4987 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4989 status
= SYS$
PARSE (&fab
);
4990 if ((status
& 1) == 0)
4993 vaxc$errno
= status
;
4996 status
= SYS$
SEARCH (&fab
);
4997 if ((status
& 1) == 0)
5000 vaxc$errno
= status
;
5004 fid
[0] = nam
.nam$w_fid
[0];
5005 fid
[1] = nam
.nam$w_fid
[1];
5006 fid
[2] = nam
.nam$w_fid
[2];
5008 fab
.fab$l_fna
= new;
5009 fab
.fab$b_fns
= strlen (new);
5011 status
= SYS$
PARSE (&fab
);
5012 if ((status
& 1) == 0)
5015 vaxc$errno
= status
;
5019 nam
.nam$w_fid
[0] = fid
[0];
5020 nam
.nam$w_fid
[1] = fid
[1];
5021 nam
.nam$w_fid
[2] = fid
[2];
5023 nam
.nam$l_esa
= nam
.nam$l_name
;
5024 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
5026 status
= SYS$
ENTER (&fab
);
5027 if ((status
& 1) == 0)
5030 vaxc$errno
= status
;
5041 printf ("%s not yet implemented\r\n", badfunc
);
5049 /* Arrange to return a range centered on zero. */
5050 return rand () - (1 << 30);
5062 /* Called from init_sys_modes. */
5068 /* If we're not on an HFT we shouldn't do any of this. We determine
5069 if we are on an HFT by trying to get an HFT error code. If this
5070 call fails, we're not on an HFT. */
5072 if (ioctl (0, HFQERROR
, &junk
) < 0)
5074 #else /* not IBMR2AIX */
5075 if (ioctl (0, HFQEIO
, 0) < 0)
5077 #endif /* not IBMR2AIX */
5079 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5080 as the rubout key's ASCII code. Here this is changed. The bug is that
5081 there's no way to determine the old mapping, so in reset_sys_modes
5082 we need to assume that the normal map had been present. Of course, this
5083 code also doesn't help if on a terminal emulator which doesn't understand
5087 struct hfkeymap keymap
;
5089 buf
.hf_bufp
= (char *)&keymap
;
5090 buf
.hf_buflen
= sizeof (keymap
);
5091 keymap
.hf_nkeys
= 2;
5092 keymap
.hfkey
[0].hf_kpos
= 15;
5093 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5095 keymap
.hfkey
[0].hf_keyidh
= '<';
5096 #else /* not IBMR2AIX */
5097 keymap
.hfkey
[0].hf_page
= '<';
5098 #endif /* not IBMR2AIX */
5099 keymap
.hfkey
[0].hf_char
= 127;
5100 keymap
.hfkey
[1].hf_kpos
= 15;
5101 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5103 keymap
.hfkey
[1].hf_keyidh
= '<';
5104 #else /* not IBMR2AIX */
5105 keymap
.hfkey
[1].hf_page
= '<';
5106 #endif /* not IBMR2AIX */
5107 keymap
.hfkey
[1].hf_char
= 127;
5108 hftctl (0, HFSKBD
, &buf
);
5110 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5112 line_ins_del_ok
= char_ins_del_ok
= 0;
5115 /* Reset the rubout key to backspace. */
5121 struct hfkeymap keymap
;
5125 if (ioctl (0, HFQERROR
, &junk
) < 0)
5127 #else /* not IBMR2AIX */
5128 if (ioctl (0, HFQEIO
, 0) < 0)
5130 #endif /* not IBMR2AIX */
5132 buf
.hf_bufp
= (char *)&keymap
;
5133 buf
.hf_buflen
= sizeof (keymap
);
5134 keymap
.hf_nkeys
= 2;
5135 keymap
.hfkey
[0].hf_kpos
= 15;
5136 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5138 keymap
.hfkey
[0].hf_keyidh
= '<';
5139 #else /* not IBMR2AIX */
5140 keymap
.hfkey
[0].hf_page
= '<';
5141 #endif /* not IBMR2AIX */
5142 keymap
.hfkey
[0].hf_char
= 8;
5143 keymap
.hfkey
[1].hf_kpos
= 15;
5144 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5146 keymap
.hfkey
[1].hf_keyidh
= '<';
5147 #else /* not IBMR2AIX */
5148 keymap
.hfkey
[1].hf_page
= '<';
5149 #endif /* not IBMR2AIX */
5150 keymap
.hfkey
[1].hf_char
= 8;
5151 hftctl (0, HFSKBD
, &buf
);
5158 /* These are included on Sunos 4.1 when we do not use shared libraries.
5159 X11 libraries may refer to these functions but (we hope) do not
5160 actually call them. */
5180 #endif /* USE_DL_STUBS */
5189 register int length
;
5193 long max_str
= 65535;
5195 while (length
> max_str
) {
5196 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5201 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5203 while (length
-- > 0)
5205 #endif /* not VMS */
5208 #endif /* no bzero */
5209 #endif /* BSTRING */
5211 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5214 /* Saying `void' requires a declaration, above, where bcopy is used
5215 and that declaration causes pain for systems where bcopy is a macro. */
5216 bcopy (b1
, b2
, length
)
5219 register int length
;
5222 long max_str
= 65535;
5224 while (length
> max_str
) {
5225 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5231 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5233 while (length
-- > 0)
5235 #endif /* not VMS */
5237 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5242 bcmp (b1
, b2
, length
) /* This could be a macro! */
5245 register int length
;
5248 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5249 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5251 return STR$
COMPARE (&src1
, &src2
);
5253 while (length
-- > 0)
5258 #endif /* not VMS */
5260 #endif /* no bcmp */
5261 #endif /* not BSTRING */