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 /* Specify a different file descriptor for further input operations. */
256 /* Discard pending input on descriptor input_fd. */
262 struct emacs_tty buf
;
267 /* Discarding input is not safe when the input could contain
268 replies from the X server. So don't do it. */
269 if (read_socket_hook
)
274 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
275 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
281 ioctl (input_fd
, TIOCFLUSH
, &zero
);
283 #else /* not Apollo */
284 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
285 while (dos_keyread () != -1)
287 #else /* not MSDOS */
288 EMACS_GET_TTY (input_fd
, &buf
);
289 EMACS_SET_TTY (input_fd
, &buf
, 0);
290 #endif /* not MSDOS */
291 #endif /* not Apollo */
293 #endif /* not WINDOWSNT */
298 /* Arrange for character C to be read as the next input from
305 if (read_socket_hook
)
308 /* Should perhaps error if in batch mode */
310 ioctl (input_fd
, TIOCSTI
, &c
);
311 #else /* no TIOCSTI */
312 error ("Cannot stuff terminal input characters in this version of Unix");
313 #endif /* no TIOCSTI */
325 #ifdef INIT_BAUD_RATE
330 #else /* not DOS_NT */
334 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
335 &sg
.class, 12, 0, 0, 0, 0 );
336 ospeed
= sg
.xmit_baud
;
342 tcgetattr (input_fd
, &sg
);
343 ospeed
= cfgetospeed (&sg
);
344 #if defined (USE_GETOBAUD) && defined (getobaud)
345 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
347 ospeed
= getobaud (sg
.c_cflag
);
349 #else /* neither VMS nor TERMIOS */
355 tcgetattr (input_fd
, &sg
);
357 ioctl (input_fd
, TCGETA
, &sg
);
359 ospeed
= sg
.c_cflag
& CBAUD
;
360 #else /* neither VMS nor TERMIOS nor TERMIO */
363 sg
.sg_ospeed
= B9600
;
364 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
366 ospeed
= sg
.sg_ospeed
;
367 #endif /* not HAVE_TERMIO */
368 #endif /* not HAVE_TERMIOS */
370 #endif /* not DOS_NT */
371 #endif /* not INIT_BAUD_RATE */
374 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
375 ? baud_convert
[ospeed
] : 9600);
382 set_exclusive_use (fd
)
386 ioctl (fd
, FIOCLEX
, 0);
388 /* Ok to do nothing if this feature does not exist */
393 wait_without_blocking ()
396 wait3 (0, WNOHANG
| WUNTRACED
, 0);
398 croak ("wait_without_blocking");
400 synch_process_alive
= 0;
403 #endif /* not subprocesses */
405 int wait_debugging
; /* Set nonzero to make following function work under dbx
406 (at least for bsd). */
409 wait_for_termination_signal ()
412 /* Wait for subprocess with process id `pid' to terminate and
413 make sure it will get eliminated (not remain forever as a zombie) */
416 wait_for_termination (pid
)
425 status
= SYS$
FORCEX (&pid
, 0, 0);
428 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
429 /* Note that kill returns -1 even if the process is just a zombie now.
430 But inevitably a SIGCHLD interrupt should be generated
431 and child_sig will do wait3 and make the process go away. */
432 /* There is some indication that there is a bug involved with
433 termination of subprocesses, perhaps involving a kernel bug too,
434 but no idea what it is. Just as a hunch we signal SIGCHLD to see
435 if that causes the problem to go away or get worse. */
436 sigsetmask (sigmask (SIGCHLD
));
437 if (0 > kill (pid
, 0))
439 sigsetmask (SIGEMPTYMASK
);
440 kill (getpid (), SIGCHLD
);
446 sigpause (SIGEMPTYMASK
);
447 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
448 #if defined (UNIPLUS)
449 if (0 > kill (pid
, 0))
452 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
453 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
454 sigblock (sigmask (SIGCHLD
));
455 if (0 > kill (pid
, 0))
457 sigunblock (sigmask (SIGCHLD
));
460 sigpause (SIGEMPTYMASK
);
461 #else /* not POSIX_SIGNALS */
462 #ifdef HAVE_SYSV_SIGPAUSE
464 if (0 > kill (pid
, 0))
470 #else /* not HAVE_SYSV_SIGPAUSE */
474 #else /* not WINDOWSNT */
475 if (0 > kill (pid
, 0))
477 /* Using sleep instead of pause avoids timing error.
478 If the inferior dies just before the sleep,
479 we lose just one second. */
481 #endif /* not WINDOWSNT */
482 #endif /* not HAVE_SYSV_SIGPAUSE */
483 #endif /* not POSIX_SIGNALS */
484 #endif /* not UNIPLUS */
485 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
487 #else /* not subprocesses */
490 #else /* not __DJGPP__ > 1 */
492 if (kill (pid
, 0) < 0)
498 if (status
== pid
|| status
== -1)
501 #endif /* not __DJGPP__ > 1*/
502 #endif /* not subprocesses */
509 * flush any pending output
510 * (may flush input as well; it does not matter the way we use it)
514 flush_pending_output (channel
)
518 /* If we try this, we get hit with SIGTTIN, because
519 the child's tty belongs to the child's pgrp. */
522 ioctl (channel
, TCFLSH
, 1);
526 /* 3rd arg should be ignored
527 but some 4.2 kernels actually want the address of an int
528 and nonzero means something different. */
529 ioctl (channel
, TIOCFLUSH
, &zero
);
536 /* Set up the terminal at the other end of a pseudo-terminal that
537 we will be controlling an inferior through.
538 It should not echo or do line-editing, since that is done
539 in Emacs. No padding needed for insertion into an Emacs buffer. */
542 child_setup_tty (out
)
548 EMACS_GET_TTY (out
, &s
);
550 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
551 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
552 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
554 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
555 /* No output delays */
557 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
558 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
560 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
563 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
566 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
568 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
569 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
571 /* Said to be unnecessary: */
572 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
573 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
576 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
577 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
578 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
579 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
582 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
586 /* AIX enhanced edit loses NULs, so disable it */
589 s
.main
.c_iflag
&= ~ASCEDIT
;
591 /* Also, PTY overloads NUL and BREAK.
592 don't ignore break, but don't signal either, so it looks like NUL. */
593 s
.main
.c_iflag
&= ~IGNBRK
;
594 s
.main
.c_iflag
&= ~BRKINT
;
595 /* QUIT and INTR work better as signals, so disable character forms */
596 s
.main
.c_cc
[VINTR
] = 0377;
597 #ifdef SIGNALS_VIA_CHARACTERS
598 /* the QUIT and INTR character are used in process_send_signal
599 so set them here to something useful. */
600 if (s
.main
.c_cc
[VQUIT
] == 0377)
601 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
602 if (s
.main
.c_cc
[VINTR
] == 0377)
603 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
604 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
605 /* QUIT and INTR work better as signals, so disable character forms */
606 s
.main
.c_cc
[VQUIT
] = 0377;
607 s
.main
.c_cc
[VINTR
] = 0377;
608 s
.main
.c_lflag
&= ~ISIG
;
609 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
610 s
.main
.c_cc
[VEOL
] = 0377;
611 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
614 #else /* not HAVE_TERMIO */
616 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
618 s
.main
.sg_flags
|= LPASS8
;
619 s
.main
.sg_erase
= 0377;
620 s
.main
.sg_kill
= 0377;
621 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
623 #endif /* not HAVE_TERMIO */
625 EMACS_SET_TTY (out
, &s
, 0);
634 ioctl (out
, FIOASYNC
, &zero
);
637 #endif /* not DOS_NT */
641 #endif /* subprocesses */
643 /* Record a signal code and the handler for it. */
647 SIGTYPE (*handler
) P_ ((int));
650 static void save_signal_handlers
P_ ((struct save_signal
*));
651 static void restore_signal_handlers
P_ ((struct save_signal
*));
653 /* Suspend the Emacs process; give terminal to its superior. */
659 /* "Foster" parentage allows emacs to return to a subprocess that attached
660 to the current emacs as a cheaper than starting a whole new process. This
661 is set up by KEPTEDITOR.COM. */
662 unsigned long parent_id
, foster_parent_id
;
665 fpid_string
= getenv ("EMACS_PARENT_PID");
666 if (fpid_string
!= NULL
)
668 sscanf (fpid_string
, "%x", &foster_parent_id
);
669 if (foster_parent_id
!= 0)
670 parent_id
= foster_parent_id
;
672 parent_id
= getppid ();
675 parent_id
= getppid ();
677 xfree (fpid_string
); /* On VMS, this was malloc'd */
679 if (parent_id
&& parent_id
!= 0xffffffff)
681 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
682 int status
= LIB$
ATTACH (&parent_id
) & 1;
683 signal (SIGINT
, oldsig
);
692 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
693 d_prompt
.a
= "Emacs: "; /* Just a reminder */
694 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
699 #if defined(SIGTSTP) && !defined(MSDOS)
702 int pgrp
= EMACS_GETPGRP (0);
703 EMACS_KILLPG (pgrp
, SIGTSTP
);
706 #else /* No SIGTSTP */
707 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
708 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
709 kill (getpid (), SIGQUIT
);
711 #else /* No SIGTSTP or USG_JOBCTRL */
713 /* On a system where suspending is not implemented,
714 instead fork a subshell and let it talk directly to the terminal
718 #endif /* no USG_JOBCTRL */
719 #endif /* no SIGTSTP */
723 /* Fork a subshell. */
729 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
731 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
734 struct save_signal saved_handlers
[5];
736 unsigned char *str
= 0;
739 saved_handlers
[0].code
= SIGINT
;
740 saved_handlers
[1].code
= SIGQUIT
;
741 saved_handlers
[2].code
= SIGTERM
;
743 saved_handlers
[3].code
= SIGIO
;
744 saved_handlers
[4].code
= 0;
746 saved_handlers
[3].code
= 0;
749 /* Mentioning current_buffer->buffer would mean including buffer.h,
750 which somehow wedges the hp compiler. So instead... */
752 dir
= intern ("default-directory");
753 if (NILP (Fboundp (dir
)))
755 dir
= Fsymbol_value (dir
);
759 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
760 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
761 len
= XSTRING (dir
)->size
;
762 bcopy (XSTRING (dir
)->data
, str
, len
);
763 if (str
[len
- 1] != '/') str
[len
++] = '/';
770 save_signal_handlers (saved_handlers
);
771 synch_process_alive
= 1;
772 #endif /* __DJGPP__ > 1 */
776 error ("Can't spawn subshell");
783 #ifdef DOS_NT /* MW, Aug 1993 */
786 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
789 sh
= (char *) egetenv ("SHELL");
793 /* Use our buffer's default directory for the subshell. */
798 close_process_descs (); /* Close Emacs's pipes/ptys */
801 #ifdef SET_EMACS_PRIORITY
803 extern int emacs_priority
;
805 if (emacs_priority
< 0)
806 nice (-emacs_priority
);
810 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
813 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
815 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
817 #else /* not MSDOS */
819 /* Waits for process completion */
820 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
823 write (1, "Can't execute subshell", 22);
824 #else /* not WINDOWSNT */
826 write (1, "Can't execute subshell", 22);
828 #endif /* not WINDOWSNT */
829 #endif /* not MSDOS */
832 /* Do this now if we did not do it before. */
833 #if !defined (MSDOS) || __DJGPP__ == 1
834 save_signal_handlers (saved_handlers
);
835 synch_process_alive
= 1;
839 wait_for_termination (pid
);
841 restore_signal_handlers (saved_handlers
);
842 synch_process_alive
= 0;
847 save_signal_handlers (saved_handlers
)
848 struct save_signal
*saved_handlers
;
850 while (saved_handlers
->code
)
852 saved_handlers
->handler
853 = (SIGTYPE (*) P_ ((int))) signal (saved_handlers
->code
, SIG_IGN
);
859 restore_signal_handlers (saved_handlers
)
860 struct save_signal
*saved_handlers
;
862 while (saved_handlers
->code
)
864 signal (saved_handlers
->code
, saved_handlers
->handler
);
878 old_fcntl_flags
= fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
879 fcntl (fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
881 interrupts_deferred
= 0;
890 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
895 if (read_socket_hook
)
899 sigunblock (sigmask (SIGWINCH
));
901 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
903 interrupts_deferred
= 0;
909 if (read_socket_hook
)
913 sigblock (sigmask (SIGWINCH
));
915 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
916 interrupts_deferred
= 1;
919 #else /* no FASYNC */
920 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
927 if (read_socket_hook
)
930 ioctl (input_fd
, FIOASYNC
, &on
);
931 interrupts_deferred
= 0;
939 if (read_socket_hook
)
942 ioctl (input_fd
, FIOASYNC
, &off
);
943 interrupts_deferred
= 1;
946 #else /* not FASYNC, not STRIDE */
958 if (read_socket_hook
)
962 sigaddset(&st
, SIGIO
);
963 ioctl (input_fd
, FIOASYNC
, &on
);
964 interrupts_deferred
= 0;
965 sigprocmask(SIG_UNBLOCK
, &st
, (sigset_t
*)0);
973 if (read_socket_hook
)
976 ioctl (input_fd
, FIOASYNC
, &off
);
977 interrupts_deferred
= 1;
985 if (read_socket_hook
)
988 croak ("request_sigio");
994 if (read_socket_hook
)
997 croak ("unrequest_sigio");
1003 #endif /* F_SETFL */
1005 /* Saving and restoring the process group of Emacs's terminal. */
1009 /* The process group of which Emacs was a member when it initially
1012 If Emacs was in its own process group (i.e. inherited_pgroup ==
1013 getpid ()), then we know we're running under a shell with job
1014 control (Emacs would never be run as part of a pipeline).
1017 If Emacs was not in its own process group, then we know we're
1018 running under a shell (or a caller) that doesn't know how to
1019 separate itself from Emacs (like sh). Emacs must be in its own
1020 process group in order to receive SIGIO correctly. In this
1021 situation, we put ourselves in our own pgroup, forcibly set the
1022 tty's pgroup to our pgroup, and make sure to restore and reinstate
1023 the tty's pgroup just like any other terminal setting. If
1024 inherited_group was not the tty's pgroup, then we'll get a
1025 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1026 it goes foreground in the future, which is what should happen. */
1027 int inherited_pgroup
;
1029 /* Split off the foreground process group to Emacs alone.
1030 When we are in the foreground, but not started in our own process
1031 group, redirect the TTY to point to our own process group. We need
1032 to be in our own process group to receive SIGIO properly. */
1034 narrow_foreground_group ()
1038 setpgrp (0, inherited_pgroup
);
1039 if (inherited_pgroup
!= me
)
1040 EMACS_SET_TTY_PGRP (input_fd
, &me
);
1044 /* Set the tty to our original foreground group. */
1046 widen_foreground_group ()
1048 if (inherited_pgroup
!= getpid ())
1049 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
1050 setpgrp (0, inherited_pgroup
);
1053 #endif /* BSD_PGRPS */
1055 /* Getting and setting emacs_tty structures. */
1057 /* Set *TC to the parameters associated with the terminal FD.
1058 Return zero if all's well, or -1 if we ran into an error we
1059 couldn't deal with. */
1061 emacs_get_tty (fd
, settings
)
1063 struct emacs_tty
*settings
;
1065 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1067 /* We have those nifty POSIX tcmumbleattr functions. */
1068 if (tcgetattr (fd
, &settings
->main
) < 0)
1073 /* The SYSV-style interface? */
1074 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1079 /* Vehemently Monstrous System? :-) */
1080 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1081 &settings
->main
.class, 12, 0, 0, 0, 0)
1087 /* I give up - I hope you have the BSD ioctls. */
1088 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1090 #endif /* not DOS_NT */
1095 /* Suivant - Do we have to get struct ltchars data? */
1097 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1101 /* How about a struct tchars and a wordful of lmode bits? */
1103 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1104 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1108 /* We have survived the tempest. */
1113 /* Set the parameters of the tty on FD according to the contents of
1114 *SETTINGS. If FLUSHP is non-zero, we discard input.
1115 Return 0 if all went well, and -1 if anything failed. */
1118 emacs_set_tty (fd
, settings
, flushp
)
1120 struct emacs_tty
*settings
;
1123 /* Set the primary parameters - baud rate, character size, etcetera. */
1126 /* We have those nifty POSIX tcmumbleattr functions.
1127 William J. Smith <wjs@wiis.wang.com> writes:
1128 "POSIX 1003.1 defines tcsetattr() to return success if it was
1129 able to perform any of the requested actions, even if some
1130 of the requested actions could not be performed.
1131 We must read settings back to ensure tty setup properly.
1132 AIX requires this to keep tty from hanging occasionally." */
1133 /* This make sure that we don't loop indefinitely in here. */
1134 for (i
= 0 ; i
< 10 ; i
++)
1135 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1146 /* Get the current settings, and see if they're what we asked for. */
1147 tcgetattr (fd
, &new);
1148 /* We cannot use memcmp on the whole structure here because under
1149 * aix386 the termios structure has some reserved field that may
1152 if ( new.c_iflag
== settings
->main
.c_iflag
1153 && new.c_oflag
== settings
->main
.c_oflag
1154 && new.c_cflag
== settings
->main
.c_cflag
1155 && new.c_lflag
== settings
->main
.c_lflag
1156 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1164 /* The SYSV-style interface? */
1165 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1170 /* Vehemently Monstrous System? :-) */
1171 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1172 &settings
->main
.class, 12, 0, 0, 0, 0)
1178 /* I give up - I hope you have the BSD ioctls. */
1179 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1181 #endif /* not DOS_NT */
1187 /* Suivant - Do we have to get struct ltchars data? */
1189 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1193 /* How about a struct tchars and a wordful of lmode bits? */
1195 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1196 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1200 /* We have survived the tempest. */
1205 /* The initial tty mode bits */
1206 struct emacs_tty old_tty
;
1208 /* 1 if we have been through init_sys_modes. */
1211 /* 1 if outer tty status has been recorded. */
1215 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1220 #ifndef F_SETOWN_BUG
1222 int old_fcntl_owner
;
1223 #endif /* F_SETOWN */
1224 #endif /* F_SETOWN_BUG */
1226 /* This may also be defined in stdio,
1227 but if so, this does no harm,
1228 and using the same name avoids wasting the other one's space. */
1230 #if defined (USG) || defined (DGUX)
1231 unsigned char _sobuf
[BUFSIZ
+8];
1233 char _sobuf
[BUFSIZ
];
1237 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1240 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1246 struct emacs_tty tty
;
1250 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1251 extern int (*interrupt_signal
) ();
1255 Vtty_erase_char
= Qnil
;
1262 input_ef
= get_kbd_event_flag ();
1263 /* LIB$GET_EF (&input_ef); */
1264 SYS$
CLREF (input_ef
);
1265 waiting_for_ast
= 0;
1267 timer_ef
= get_timer_event_flag ();
1268 /* LIB$GET_EF (&timer_ef); */
1269 SYS$
CLREF (timer_ef
);
1273 LIB$
GET_EF (&process_ef
);
1274 SYS$
CLREF (process_ef
);
1276 if (input_ef
/ 32 != process_ef
/ 32)
1277 croak ("Input and process event flags in different clusters.");
1279 if (input_ef
/ 32 != timer_ef
/ 32)
1280 croak ("Input and timer event flags in different clusters.");
1282 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1283 ((unsigned) 1 << (process_ef
% 32));
1285 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1286 ((unsigned) 1 << (timer_ef
% 32));
1288 sys_access_reinit ();
1290 #endif /* not VMS */
1293 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1294 narrow_foreground_group ();
1297 #ifdef HAVE_WINDOW_SYSTEM
1298 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1299 needs the initialization code below. */
1300 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1303 EMACS_GET_TTY (input_fd
, &old_tty
);
1309 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1310 XSETINT (Vtty_erase_char
, old_tty
.main
.c_cc
[VERASE
]);
1313 /* This allows meta to be sent on 8th bit. */
1314 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1316 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1317 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1318 #ifdef INLCR /* I'm just being cautious,
1319 since I can't check how widespread INLCR is--rms. */
1320 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1323 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1325 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1326 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1328 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1330 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1333 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1335 tty
.main
.c_iflag
&= ~IXANY
;
1339 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1340 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1342 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1346 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1347 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1350 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1351 /* Set up C-g for both SIGQUIT and SIGINT.
1352 We don't know which we will get, but we handle both alike
1353 so which one it really gives us does not matter. */
1354 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1355 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1356 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1358 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1362 #if defined (mips) || defined (HAVE_TCATTR)
1364 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1367 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1368 #endif /* V_DSUSP */
1369 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1370 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1373 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1376 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1377 #endif /* VREPRINT */
1379 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1380 #endif /* VWERASE */
1382 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1383 #endif /* VDISCARD */
1388 tty
.main
.c_cc
[VSTART
] = '\021';
1391 tty
.main
.c_cc
[VSTOP
] = '\023';
1397 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1400 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1403 #endif /* mips or HAVE_TCATTR */
1405 #ifdef SET_LINE_DISCIPLINE
1406 /* Need to explicitly request TERMIODISC line discipline or
1407 Ultrix's termios does not work correctly. */
1408 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1412 /* AIX enhanced edit loses NULs, so disable it. */
1413 tty
.main
.c_line
= 0;
1414 tty
.main
.c_iflag
&= ~ASCEDIT
;
1416 tty
.main
.c_cc
[VSTRT
] = 255;
1417 tty
.main
.c_cc
[VSTOP
] = 255;
1418 tty
.main
.c_cc
[VSUSP
] = 255;
1419 tty
.main
.c_cc
[VDSUSP
] = 255;
1420 #endif /* IBMR2AIX */
1424 tty
.main
.c_cc
[VSTART
] = '\021';
1427 tty
.main
.c_cc
[VSTOP
] = '\023';
1430 /* Also, PTY overloads NUL and BREAK.
1431 don't ignore break, but don't signal either, so it looks like NUL.
1432 This really serves a purpose only if running in an XTERM window
1433 or via TELNET or the like, but does no harm elsewhere. */
1434 tty
.main
.c_iflag
&= ~IGNBRK
;
1435 tty
.main
.c_iflag
&= ~BRKINT
;
1437 #else /* if not HAVE_TERMIO */
1439 tty
.main
.tt_char
|= TT$M_NOECHO
;
1441 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1443 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1445 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1446 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1447 #else /* not VMS (BSD, that is) */
1449 XSETINT (Vtty_erase_char
, tty
.main
.sg_erase
);
1450 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1452 tty
.main
.sg_flags
|= ANYP
;
1453 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1454 #endif /* not DOS_NT */
1455 #endif /* not VMS (BSD, that is) */
1456 #endif /* not HAVE_TERMIO */
1458 /* If going to use CBREAK mode, we must request C-g to interrupt
1459 and turn off start and stop chars, etc. If not going to use
1460 CBREAK mode, do this anyway so as to turn off local flow
1461 control for user coming over network on 4.2; in this case,
1462 only t_stopc and t_startc really matter. */
1465 /* Note: if not using CBREAK mode, it makes no difference how we
1467 tty
.tchars
= new_tchars
;
1468 tty
.tchars
.t_intrc
= quit_char
;
1471 tty
.tchars
.t_startc
= '\021';
1472 tty
.tchars
.t_stopc
= '\023';
1475 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1477 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1478 anything, and leaving it in breaks the meta key. Go figure. */
1479 tty
.lmode
&= ~LLITOUT
;
1486 #endif /* HAVE_TCHARS */
1487 #endif /* not HAVE_TERMIO */
1490 tty
.ltchars
= new_ltchars
;
1491 #endif /* HAVE_LTCHARS */
1492 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1494 internal_terminal_init ();
1498 EMACS_SET_TTY (input_fd
, &tty
, 0);
1500 /* This code added to insure that, if flow-control is not to be used,
1501 we have an unlocked terminal at the start. */
1504 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1508 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1512 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1514 if (!flow_control
) tcflow (input_fd
, TCOON
);
1522 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1523 to be only LF. This is the way that is done. */
1526 if (ioctl (1, HFTGETID
, &tty
) != -1)
1527 write (1, "\033[20l", 5);
1533 /* Appears to do nothing when in PASTHRU mode.
1534 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1535 interrupt_signal, oob_chars, 0, 0, 0, 0);
1537 queue_kbd_input (0);
1542 #ifndef F_SETOWN_BUG
1543 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1545 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1547 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1548 fcntl (input_fd
, F_SETOWN
, getpid ());
1549 init_sigio (input_fd
);
1551 #endif /* F_GETOWN */
1552 #endif /* F_SETOWN_BUG */
1553 #endif /* F_SETFL */
1556 if (interrupt_input
)
1557 init_sigio (input_fd
);
1560 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1564 /* This symbol is defined on recent USG systems.
1565 Someone says without this call USG won't really buffer the file
1566 even with a call to setbuf. */
1567 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
1569 setbuf (stdout
, _sobuf
);
1571 #ifdef HAVE_WINDOW_SYSTEM
1572 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1573 needs the initialization code below. */
1574 if (EQ (Vwindow_system
, Qnil
)
1576 /* When running in tty mode on NT/Win95, we have a read_socket
1577 hook, but still need the rest of the initialization code below. */
1578 && (! read_socket_hook
)
1582 set_terminal_modes ();
1584 if (term_initted
&& no_redraw_on_reenter
)
1586 if (display_completed
)
1587 direct_output_forward_char (0);
1592 if (FRAMEP (Vterminal_frame
))
1593 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1599 /* Return nonzero if safe to use tabs in output.
1600 At the time this is called, init_sys_modes has not been done yet. */
1605 struct emacs_tty tty
;
1607 EMACS_GET_TTY (input_fd
, &tty
);
1608 return EMACS_TTY_TABS_OK (&tty
);
1611 /* Get terminal size from system.
1612 Store number of lines into *HEIGHTP and width into *WIDTHP.
1613 We store 0 if there's no valid information. */
1616 get_frame_size (widthp
, heightp
)
1617 int *widthp
, *heightp
;
1623 struct winsize size
;
1625 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1626 *widthp
= *heightp
= 0;
1629 *widthp
= size
.ws_col
;
1630 *heightp
= size
.ws_row
;
1636 /* SunOS - style. */
1637 struct ttysize size
;
1639 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1640 *widthp
= *heightp
= 0;
1643 *widthp
= size
.ts_cols
;
1644 *heightp
= size
.ts_lines
;
1650 struct sensemode tty
;
1652 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1653 &tty
.class, 12, 0, 0, 0, 0);
1654 *widthp
= tty
.scr_wid
;
1655 *heightp
= tty
.scr_len
;
1659 *widthp
= ScreenCols ();
1660 *heightp
= ScreenRows ();
1661 #else /* system doesn't know size */
1666 #endif /* not VMS */
1667 #endif /* not SunOS-style */
1668 #endif /* not BSD-style */
1671 /* Set the logical window size associated with descriptor FD
1672 to HEIGHT and WIDTH. This is used mainly with ptys. */
1675 set_window_size (fd
, height
, width
)
1676 int fd
, height
, width
;
1681 struct winsize size
;
1682 size
.ws_row
= height
;
1683 size
.ws_col
= width
;
1685 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1686 return 0; /* error */
1693 /* SunOS - style. */
1694 struct ttysize size
;
1695 size
.ts_lines
= height
;
1696 size
.ts_cols
= width
;
1698 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1704 #endif /* not SunOS-style */
1705 #endif /* not BSD-style */
1709 /* Prepare the terminal for exiting Emacs; move the cursor to the
1710 bottom of the frame, turn off interrupt-driven I/O, etc. */
1721 #ifdef HAVE_WINDOW_SYSTEM
1722 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1723 needs the clean-up code below. */
1724 if (!EQ (Vwindow_system
, Qnil
)
1726 /* When running in tty mode on NT/Win95, we have a read_socket
1727 hook, but still need the rest of the clean-up code below. */
1733 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1734 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1735 /* clear_end_of_line may move the cursor */
1736 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1737 #if defined (IBMR2AIX) && defined (AIXHFT)
1739 /* HFT devices normally use ^J as a LF/CR. We forced it to
1740 do the LF only. Now, we need to reset it. */
1743 if (ioctl (1, HFTGETID
, &tty
) != -1)
1744 write (1, "\033[20h", 5);
1748 reset_terminal_modes ();
1752 /* Avoid possible loss of output when changing terminal modes. */
1753 fsync (fileno (stdout
));
1758 #ifndef F_SETOWN_BUG
1759 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1760 if (interrupt_input
)
1763 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1765 #endif /* F_SETOWN */
1766 #endif /* F_SETOWN_BUG */
1768 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1770 #endif /* F_SETFL */
1772 if (interrupt_input
)
1777 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1780 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1784 #ifdef SET_LINE_DISCIPLINE
1785 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1786 A different old line discipline is therefore not restored, yet.
1787 Restore the old line discipline by hand. */
1788 ioctl (0, TIOCSETD
, &old_tty
.main
.c_line
);
1796 widen_foreground_group ();
1802 /* Set up the proper status flags for use of a pty. */
1808 /* I'm told that TOICREMOTE does not mean control chars
1809 "can't be sent" but rather that they don't have
1810 input-editing or signaling effects.
1811 That should be good, because we have other ways
1812 to do those things in Emacs.
1813 However, telnet mode seems not to work on 4.2.
1814 So TIOCREMOTE is turned off now. */
1816 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1817 will hang. In particular, the "timeout" feature (which
1818 causes a read to return if there is no data available)
1819 does this. Also it is known that telnet mode will hang
1820 in such a way that Emacs must be stopped (perhaps this
1821 is the same problem).
1823 If TIOCREMOTE is turned off, then there is a bug in
1824 hp-ux which sometimes loses data. Apparently the
1825 code which blocks the master process when the internal
1826 buffer fills up does not work. Other than this,
1827 though, everything else seems to work fine.
1829 Since the latter lossage is more benign, we may as well
1830 lose that way. -- cph */
1835 ioctl (fd
, FIONBIO
, &on
);
1840 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1841 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1842 /* cause EMACS not to die when it should, i.e., when its own controlling */
1843 /* tty goes away. I've complained to the AIX developers, and they may */
1844 /* change this behavior, but I'm not going to hold my breath. */
1845 signal (SIGHUP
, SIG_IGN
);
1848 #endif /* HAVE_PTYS */
1852 /* Assigning an input channel is done at the start of Emacs execution.
1853 This is called each time Emacs is resumed, also, but does nothing
1854 because input_chain is no longer zero. */
1863 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1869 /* Deassigning the input channel is done before exiting. */
1874 return SYS$
DASSGN (input_fd
);
1879 /* Request reading one character into the keyboard buffer.
1880 This is done as soon as the buffer becomes empty. */
1886 extern kbd_input_ast ();
1888 waiting_for_ast
= 0;
1890 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1891 &input_iosb
, kbd_input_ast
, 1,
1892 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1897 /* Ast routine that is called when keyboard input comes in
1898 in accord with the SYS$QIO above. */
1903 register int c
= -1;
1904 int old_errno
= errno
;
1905 extern EMACS_TIME
*input_available_clear_time
;
1907 if (waiting_for_ast
)
1908 SYS$
SETEF (input_ef
);
1909 waiting_for_ast
= 0;
1912 if (input_count
== 25)
1914 printf ("Ast # %d,", input_count
);
1915 printf (" iosb = %x, %x, %x, %x",
1916 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1919 if (input_iosb
.offset
)
1923 printf (", char = 0%o", c
);
1935 struct input_event e
;
1936 e
.kind
= ascii_keystroke
;
1937 XSETINT (e
.code
, c
);
1938 XSETFRAME (e
.frame_or_window
, selected_frame
);
1939 kbd_buffer_store_event (&e
);
1941 if (input_available_clear_time
)
1942 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1946 /* Wait until there is something in kbd_buffer. */
1949 wait_for_kbd_input ()
1951 extern int have_process_input
, process_exited
;
1953 /* If already something, avoid doing system calls. */
1954 if (detect_input_pending ())
1958 /* Clear a flag, and tell ast routine above to set it. */
1959 SYS$
CLREF (input_ef
);
1960 waiting_for_ast
= 1;
1961 /* Check for timing error: ast happened while we were doing that. */
1962 if (!detect_input_pending ())
1964 /* No timing error: wait for flag to be set. */
1965 set_waiting_for_input (0);
1966 SYS$
WFLOR (input_ef
, input_eflist
);
1967 clear_waiting_for_input (0);
1968 if (!detect_input_pending ())
1969 /* Check for subprocess input availability */
1971 int dsp
= have_process_input
|| process_exited
;
1973 SYS$
CLREF (process_ef
);
1974 if (have_process_input
)
1975 process_command_input ();
1980 update_mode_lines
++;
1981 prepare_menu_bars ();
1982 redisplay_preserve_echo_area ();
1986 waiting_for_ast
= 0;
1989 /* Get rid of any pending QIO, when we are about to suspend
1990 or when we want to throw away pending input.
1991 We wait for a positive sign that the AST routine has run
1992 and therefore there is no I/O request queued when we return.
1993 SYS$SETAST is used to avoid a timing error. */
1999 printf ("At end_kbd_input.\n");
2003 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2005 SYS$
CANCEL (input_fd
);
2010 /* Clear a flag, and tell ast routine above to set it. */
2011 SYS$
CLREF (input_ef
);
2012 waiting_for_ast
= 1;
2014 SYS$
CANCEL (input_fd
);
2016 SYS$
WAITFR (input_ef
);
2017 waiting_for_ast
= 0;
2020 /* Wait for either input available or time interval expiry. */
2023 input_wait_timeout (timeval
)
2024 int timeval
; /* Time to wait, in seconds */
2027 static int zero
= 0;
2028 static int large
= -10000000;
2030 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2032 /* If already something, avoid doing system calls. */
2033 if (detect_input_pending ())
2037 /* Clear a flag, and tell ast routine above to set it. */
2038 SYS$
CLREF (input_ef
);
2039 waiting_for_ast
= 1;
2040 /* Check for timing error: ast happened while we were doing that. */
2041 if (!detect_input_pending ())
2043 /* No timing error: wait for flag to be set. */
2045 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2046 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
2048 waiting_for_ast
= 0;
2051 /* The standard `sleep' routine works some other way
2052 and it stops working if you have ever quit out of it.
2053 This one continues to work. */
2059 static int zero
= 0;
2060 static int large
= -10000000;
2062 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2065 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2066 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2084 croak ("request sigio");
2090 croak ("unrequest sigio");
2095 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2100 #ifndef SYSTEM_MALLOC
2107 /* Some systems that cannot dump also cannot implement these. */
2110 * Return the address of the start of the text segment prior to
2111 * doing an unexec. After unexec the return value is undefined.
2112 * See crt0.c for further explanation and _start.
2116 #ifndef HAVE_TEXT_START
2121 return ((char *) TEXT_START
);
2125 return ((char *) csrt
);
2126 #else /* not GOULD */
2127 extern int _start ();
2128 return ((char *) _start
);
2130 #endif /* TEXT_START */
2132 #endif /* not HAVE_TEXT_START */
2135 * Return the address of the start of the data segment prior to
2136 * doing an unexec. After unexec the return value is undefined.
2137 * See crt0.c for further information and definition of data_start.
2139 * Apparently, on BSD systems this is etext at startup. On
2140 * USG systems (swapping) this is highly mmu dependent and
2141 * is also dependent on whether or not the program is running
2142 * with shared text. Generally there is a (possibly large)
2143 * gap between end of text and start of data with shared text.
2145 * On Uniplus+ systems with shared text, data starts at a
2146 * fixed address. Each port (from a given oem) is generally
2147 * different, and the specific value of the start of data can
2148 * be obtained via the UniPlus+ specific "uvar" system call,
2149 * however the method outlined in crt0.c seems to be more portable.
2151 * Probably what will have to happen when a USG unexec is available,
2152 * at least on UniPlus, is temacs will have to be made unshared so
2153 * that text and data are contiguous. Then once loadup is complete,
2154 * unexec will produce a shared executable where the data can be
2155 * at the normal shared text boundary and the startofdata variable
2156 * will be patched by unexec to the correct value.
2164 return ((char *) DATA_START
);
2166 #ifdef ORDINARY_LINK
2168 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2169 * data_start isn't defined. We take the address of environ, which
2170 * is known to live at or near the start of the system crt0.c, and
2171 * we don't sweat the handful of bytes that might lose.
2173 extern char **environ
;
2175 return((char *) &environ
);
2177 extern int data_start
;
2178 return ((char *) &data_start
);
2179 #endif /* ORDINARY_LINK */
2180 #endif /* DATA_START */
2182 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2185 /* Some systems that cannot dump also cannot implement these. */
2188 * Return the address of the end of the text segment prior to
2189 * doing an unexec. After unexec the return value is undefined.
2196 return ((char *) TEXT_END
);
2199 return ((char *) &etext
);
2204 * Return the address of the end of the data segment prior to
2205 * doing an unexec. After unexec the return value is undefined.
2212 return ((char *) DATA_END
);
2215 return ((char *) &edata
);
2219 #endif /* not CANNOT_DUMP */
2221 /* init_system_name sets up the string for the Lisp function
2222 system-name to return. */
2228 extern Lisp_Object Vsystem_name
;
2233 #include <sys/socket.h>
2235 #endif /* HAVE_SOCKETS */
2236 #endif /* not VMS */
2237 #endif /* not BSD4_1 */
2243 Vsystem_name
= build_string (sysname
);
2247 if ((sp
= egetenv ("SYS$NODE")) == 0)
2248 Vsystem_name
= build_string ("vax-vms");
2249 else if ((end
= index (sp
, ':')) == 0)
2250 Vsystem_name
= build_string (sp
);
2252 Vsystem_name
= make_string (sp
, end
- sp
);
2254 #ifndef HAVE_GETHOSTNAME
2257 Vsystem_name
= build_string (uts
.nodename
);
2258 #else /* HAVE_GETHOSTNAME */
2259 unsigned int hostname_size
= 256;
2260 char *hostname
= (char *) alloca (hostname_size
);
2262 /* Try to get the host name; if the buffer is too short, try
2263 again. Apparently, the only indication gethostname gives of
2264 whether the buffer was large enough is the presence or absence
2265 of a '\0' in the string. Eech. */
2268 gethostname (hostname
, hostname_size
- 1);
2269 hostname
[hostname_size
- 1] = '\0';
2271 /* Was the buffer large enough for the '\0'? */
2272 if (strlen (hostname
) < hostname_size
- 1)
2275 hostname_size
<<= 1;
2276 hostname
= (char *) alloca (hostname_size
);
2279 /* Turn the hostname into the official, fully-qualified hostname.
2280 Don't do this if we're going to dump; this can confuse system
2281 libraries on some machines and make the dumped emacs core dump. */
2284 #endif /* not CANNOT_DUMP */
2285 if (! index (hostname
, '.'))
2289 for (count
= 0;; count
++)
2294 hp
= gethostbyname (hostname
);
2296 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2301 Fsleep_for (make_number (1), Qnil
);
2305 char *fqdn
= (char *) hp
->h_name
;
2308 if (!index (fqdn
, '.'))
2310 /* We still don't have a fully qualified domain name.
2311 Try to find one in the list of alternate names */
2312 char **alias
= hp
->h_aliases
;
2313 while (*alias
&& !index (*alias
, '.'))
2320 /* Convert the host name to lower case. */
2321 /* Using ctype.h here would introduce a possible locale
2322 dependence that is probably wrong for hostnames. */
2326 if (*p
>= 'A' && *p
<= 'Z')
2333 #endif /* HAVE_SOCKETS */
2334 /* We used to try using getdomainname here,
2335 but NIIBE Yutaka <gniibe@etl.go.jp> says that
2336 getdomainname gets the NIS/YP domain which often is not the same
2337 as in Internet domain name. */
2338 #if 0 /* Turned off because sysinfo is not really likely to return the
2339 correct Internet domain. */
2340 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2341 if (! index (hostname
, '.'))
2343 /* The hostname is not fully qualified. Append the domain name. */
2345 int hostlen
= strlen (hostname
);
2346 int domain_size
= 256;
2350 char *domain
= (char *) alloca (domain_size
+ 1);
2351 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2352 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2353 if (sys_domain_size
<= 0)
2355 if (domain_size
< sys_domain_size
)
2357 domain_size
= sys_domain_size
;
2360 strcpy (fqdn
, hostname
);
2361 if (domain
[0] == '.')
2362 strcpy (fqdn
+ hostlen
, domain
);
2363 else if (domain
[0] != 0)
2365 fqdn
[hostlen
] = '.';
2366 strcpy (fqdn
+ hostlen
+ 1, domain
);
2372 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2374 Vsystem_name
= build_string (hostname
);
2375 #endif /* HAVE_GETHOSTNAME */
2380 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2381 if (*p
== ' ' || *p
== '\t')
2388 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2390 #include "sysselect.h"
2393 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2394 /* Cause explanatory error message at compile time,
2395 since the select emulation is not good enough for X. */
2396 int *x
= &x_windows_lose_if_no_select_system_call
;
2399 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2400 * Only checks read descriptors.
2402 /* How long to wait between checking fds in select */
2403 #define SELECT_PAUSE 1
2406 /* For longjmp'ing back to read_input_waiting. */
2408 jmp_buf read_alarm_throw
;
2410 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2411 The read_socket_hook function sets this to 1 while it is waiting. */
2413 int read_alarm_should_throw
;
2421 #else /* not BSD4_1 */
2422 signal (SIGALRM
, SIG_IGN
);
2423 #endif /* not BSD4_1 */
2424 if (read_alarm_should_throw
)
2425 longjmp (read_alarm_throw
, 1);
2429 /* Only rfds are checked. */
2431 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2433 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2434 EMACS_TIME
*timeout
;
2436 int ravail
= 0, old_alarm
;
2440 extern int proc_buffered_char
[];
2441 #ifndef subprocesses
2442 int process_tick
= 0, update_tick
= 0;
2444 extern int process_tick
, update_tick
;
2446 SIGTYPE (*old_trap
) ();
2449 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2450 /* If we're using X, then the native select will work; we only need the
2451 emulation for non-X usage. */
2452 if (!NILP (Vwindow_system
))
2453 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2455 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2456 local_timeout
= &timeoutval
;
2468 /* If we are looking only for the terminal, with no timeout,
2469 just read it and wait -- that's more efficient. */
2470 if (*local_timeout
== 100000 && process_tick
== update_tick
2471 && FD_ISSET (0, &orfds
))
2474 for (fd
= 1; fd
< nfds
; ++fd
)
2475 if (FD_ISSET (fd
, &orfds
))
2477 if (! detect_input_pending ())
2478 read_input_waiting ();
2484 /* Once a second, till the timer expires, check all the flagged read
2485 * descriptors to see if any input is available. If there is some then
2486 * set the corresponding bit in the return copy of rfds.
2490 register int to_check
, fd
;
2494 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2496 if (FD_ISSET (fd
, &orfds
))
2498 int avail
= 0, status
= 0;
2501 avail
= detect_input_pending (); /* Special keyboard handler */
2505 status
= ioctl (fd
, FIONREAD
, &avail
);
2506 #else /* no FIONREAD */
2507 /* Hoping it will return -1 if nothing available
2508 or 0 if all 0 chars requested are read. */
2509 if (proc_buffered_char
[fd
] >= 0)
2513 avail
= read (fd
, &buf
, 1);
2515 proc_buffered_char
[fd
] = buf
;
2517 #endif /* no FIONREAD */
2519 if (status
>= 0 && avail
> 0)
2527 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2529 old_alarm
= alarm (0);
2530 old_trap
= signal (SIGALRM
, select_alarm
);
2532 alarm (SELECT_PAUSE
);
2533 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2534 while (select_alarmed
== 0 && *local_timeout
!= 0
2535 && process_tick
== update_tick
)
2537 /* If we are interested in terminal input,
2538 wait by reading the terminal.
2539 That makes instant wakeup for terminal input at least. */
2540 if (FD_ISSET (0, &orfds
))
2542 read_input_waiting ();
2543 if (detect_input_pending ())
2549 (*local_timeout
) -= SELECT_PAUSE
;
2550 /* Reset the old alarm if there was one */
2552 signal (SIGALRM
, old_trap
);
2555 /* Reset or forge an interrupt for the original handler. */
2556 old_alarm
-= SELECT_PAUSE
;
2558 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2562 if (*local_timeout
== 0) /* Stop on timer being cleared */
2567 #endif /* not WINDOWSNT */
2569 /* Read keyboard input into the standard buffer,
2570 waiting for at least one character. */
2572 /* Make all keyboard buffers much bigger when using a window system. */
2573 #ifdef HAVE_WINDOW_SYSTEM
2574 #define BUFFER_SIZE_FACTOR 16
2576 #define BUFFER_SIZE_FACTOR 1
2580 read_input_waiting ()
2582 struct input_event e
;
2584 extern int quit_char
;
2586 if (read_socket_hook
)
2588 struct input_event buf
[256];
2590 read_alarm_should_throw
= 0;
2591 if (! setjmp (read_alarm_throw
))
2592 nread
= (*read_socket_hook
) (0, buf
, 256, 1, 0);
2596 /* Scan the chars for C-g and store them in kbd_buffer. */
2597 for (i
= 0; i
< nread
; i
++)
2599 kbd_buffer_store_event (&buf
[i
]);
2600 /* Don't look at input that follows a C-g too closely.
2601 This reduces lossage due to autorepeat on C-g. */
2602 if (buf
[i
].kind
== ascii_keystroke
2603 && buf
[i
].code
== quit_char
)
2610 nread
= read (fileno (stdin
), buf
, 1);
2612 /* Scan the chars for C-g and store them in kbd_buffer. */
2613 e
.kind
= ascii_keystroke
;
2614 XSETFRAME (e
.frame_or_window
, selected_frame
);
2616 for (i
= 0; i
< nread
; i
++)
2618 /* Convert chars > 0177 to meta events if desired.
2619 We do this under the same conditions that read_avail_input does. */
2620 if (read_socket_hook
== 0)
2622 /* If the user says she has a meta key, then believe her. */
2623 if (meta_key
== 1 && (buf
[i
] & 0x80))
2624 e
.modifiers
= meta_modifier
;
2629 XSETINT (e
.code
, buf
[i
]);
2630 kbd_buffer_store_event (&e
);
2631 /* Don't look at input that follows a C-g too closely.
2632 This reduces lossage due to autorepeat on C-g. */
2633 if (buf
[i
] == quit_char
)
2639 #endif /* not HAVE_SELECT */
2640 #endif /* not VMS */
2641 #endif /* not MSDOS */
2645 * Partially emulate 4.2 open call.
2646 * open is defined as this in 4.1.
2648 * - added by Michael Bloom @ Citicorp/TTI
2653 sys_open (path
, oflag
, mode
)
2657 if (oflag
& O_CREAT
)
2658 return creat (path
, mode
);
2660 return open (path
, oflag
);
2669 lmode
= LINTRUP
| lmode
;
2670 ioctl (fd
, TIOCLSET
, &lmode
);
2678 lmode
= ~LINTRUP
& lmode
;
2679 ioctl (0, TIOCLSET
, &lmode
);
2687 interrupts_deferred
= 0;
2695 interrupts_deferred
= 1;
2698 /* still inside #ifdef BSD4_1 */
2701 int sigheld
; /* Mask of held signals */
2707 sigheld
|= sigbit (signum
);
2715 sigheld
|= sigbit (signum
);
2722 sigheld
&= ~sigbit (signum
);
2727 sigfree () /* Free all held signals */
2730 for (i
= 0; i
< NSIG
; i
++)
2731 if (sigheld
& sigbit (i
))
2739 return 1 << (i
- 1);
2741 #endif /* subprocesses */
2744 /* POSIX signals support - DJB */
2745 /* Anyone with POSIX signals should have ANSI C declarations */
2747 #ifdef POSIX_SIGNALS
2749 sigset_t empty_mask
, full_mask
;
2754 sigemptyset (&empty_mask
);
2755 sigfillset (&full_mask
);
2759 sys_signal (int signal_number
, signal_handler_t action
)
2761 struct sigaction new_action
, old_action
;
2762 sigemptyset (&new_action
.sa_mask
);
2763 new_action
.sa_handler
= action
;
2765 /* Emacs mostly works better with restartable system services. If this
2766 * flag exists, we probably want to turn it on here.
2768 new_action
.sa_flags
= SA_RESTART
;
2770 new_action
.sa_flags
= 0;
2772 sigaction (signal_number
, &new_action
, &old_action
);
2773 return (old_action
.sa_handler
);
2777 /* If we're compiling with GCC, we don't need this function, since it
2778 can be written as a macro. */
2780 sys_sigmask (int sig
)
2783 sigemptyset (&mask
);
2784 sigaddset (&mask
, sig
);
2789 /* I'd like to have these guys return pointers to the mask storage in here,
2790 but there'd be trouble if the code was saving multiple masks. I'll be
2791 safe and pass the structure. It normally won't be more than 2 bytes
2795 sys_sigblock (sigset_t new_mask
)
2798 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2803 sys_sigunblock (sigset_t new_mask
)
2806 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2811 sys_sigsetmask (sigset_t new_mask
)
2814 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2818 #endif /* POSIX_SIGNALS */
2826 /* Figure out how many bits the system's random number generator uses.
2827 `random' and `lrand48' are assumed to return 31 usable bits.
2828 BSD `rand' returns a 31 bit value but the low order bits are unusable;
2829 so we'll shift it and treat it like the 15-bit USG `rand'. */
2833 # define RAND_BITS 31
2834 # else /* !HAVE_RANDOM */
2835 # ifdef HAVE_LRAND48
2836 # define RAND_BITS 31
2837 # define random lrand48
2838 # else /* !HAVE_LRAND48 */
2839 # define RAND_BITS 15
2840 # if RAND_MAX == 32767
2841 # define random rand
2842 # else /* RAND_MAX != 32767 */
2843 # if RAND_MAX == 2147483647
2844 # define random() (rand () >> 16)
2845 # else /* RAND_MAX != 2147483647 */
2847 # define random rand
2849 # define random() (rand () >> 16)
2851 # endif /* RAND_MAX != 2147483647 */
2852 # endif /* RAND_MAX != 32767 */
2853 # endif /* !HAVE_LRAND48 */
2854 # endif /* !HAVE_RANDOM */
2855 #endif /* !RAND_BITS */
2862 srandom ((unsigned int)arg
);
2864 # ifdef HAVE_LRAND48
2867 srand ((unsigned int)arg
);
2873 * Build a full Emacs-sized word out of whatever we've got.
2874 * This suffices even for a 64-bit architecture with a 15-bit rand.
2879 long val
= random ();
2880 #if VALBITS > RAND_BITS
2881 val
= (val
<< RAND_BITS
) ^ random ();
2882 #if VALBITS > 2*RAND_BITS
2883 val
= (val
<< RAND_BITS
) ^ random ();
2884 #if VALBITS > 3*RAND_BITS
2885 val
= (val
<< RAND_BITS
) ^ random ();
2886 #if VALBITS > 4*RAND_BITS
2887 val
= (val
<< RAND_BITS
) ^ random ();
2888 #endif /* need at least 5 */
2889 #endif /* need at least 4 */
2890 #endif /* need at least 3 */
2891 #endif /* need at least 2 */
2892 return val
& ((1L << VALBITS
) - 1);
2895 #ifdef WRONG_NAME_INSQUE
2908 /* If any place else asks for the TERM variable,
2909 allow it to be overridden with the EMACS_TERM variable
2910 before attempting to translate the logical name TERM. As a last
2911 resort, ask for VAX C's special idea of the TERM variable. */
2918 static char buf
[256];
2919 static struct dsc$descriptor_s equiv
2920 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2921 static struct dsc$descriptor_s d_name
2922 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2925 if (!strcmp (name
, "TERM"))
2927 val
= (char *) getenv ("EMACS_TERM");
2932 d_name
.dsc$w_length
= strlen (name
);
2933 d_name
.dsc$a_pointer
= name
;
2934 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2936 char *str
= (char *) xmalloc (eqlen
+ 1);
2937 bcopy (buf
, str
, eqlen
);
2939 /* This is a storage leak, but a pain to fix. With luck,
2940 no one will ever notice. */
2943 return (char *) getenv (name
);
2948 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2949 to force a call on the debugger from within the image. */
2954 LIB$
SIGNAL (SS$_DEBUG
);
2960 #ifdef LINK_CRTL_SHARE
2961 #ifdef SHARABLE_LIB_BUG
2962 /* Variables declared noshare and initialized in sharable libraries
2963 cannot be shared. The VMS linker incorrectly forces you to use a private
2964 version which is uninitialized... If not for this "feature", we
2965 could use the C library definition of sys_nerr and sys_errlist. */
2967 char *sys_errlist
[] =
2971 "no such file or directory",
2973 "interrupted system call",
2975 "no such device or address",
2976 "argument list too long",
2977 "exec format error",
2980 "no more processes",
2981 "not enough memory",
2982 "permission denied",
2984 "block device required",
2985 "mount devices busy",
2987 "cross-device link",
2992 "file table overflow",
2993 "too many open files",
2997 "no space left on device",
2999 "read-only file system",
3005 "vax/vms specific error code nontranslatable error"
3007 #endif /* SHARABLE_LIB_BUG */
3008 #endif /* LINK_CRTL_SHARE */
3011 #ifndef HAVE_STRERROR
3017 extern char *sys_errlist
[];
3018 extern int sys_nerr
;
3020 if (errnum
>= 0 && errnum
< sys_nerr
)
3021 return sys_errlist
[errnum
];
3022 return (char *) "Unknown error";
3024 #endif /* not WINDOWSNT */
3025 #endif /* ! HAVE_STRERROR */
3027 #ifdef INTERRUPTIBLE_OPEN
3031 sys_open (path
, oflag
, mode
)
3035 register int rtnval
;
3037 while ((rtnval
= open (path
, oflag
, mode
)) == -1
3038 && (errno
== EINTR
));
3042 #endif /* INTERRUPTIBLE_OPEN */
3044 #ifdef INTERRUPTIBLE_CLOSE
3051 register int rtnval
;
3053 while ((rtnval
= close (fd
)) == -1
3054 && (errno
== EINTR
))
3057 /* If close is interrupted SunOS 4.1 may or may not have closed the
3058 file descriptor. If it did the second close will fail with
3059 errno = EBADF. That means we have succeeded. */
3060 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3066 #endif /* INTERRUPTIBLE_CLOSE */
3068 #ifdef INTERRUPTIBLE_IO
3071 sys_read (fildes
, buf
, nbyte
)
3076 register int rtnval
;
3078 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3079 && (errno
== EINTR
));
3084 sys_write (fildes
, buf
, nbyte
)
3089 register int rtnval
, bytes_written
;
3095 rtnval
= write (fildes
, buf
, nbyte
);
3102 return (bytes_written
? bytes_written
: -1);
3107 bytes_written
+= rtnval
;
3109 return (bytes_written
);
3112 #endif /* INTERRUPTIBLE_IO */
3117 * Substitute fork for vfork on USG flavors.
3125 #endif /* not WINDOWSNT */
3126 #endif /* not HAVE_VFORK */
3130 * All of the following are for USG.
3132 * On USG systems the system calls are INTERRUPTIBLE by signals
3133 * that the user program has elected to catch. Thus the system call
3134 * must be retried in these cases. To handle this without massive
3135 * changes in the source code, we remap the standard system call names
3136 * to names for our own functions in sysdep.c that do the system call
3137 * with retries. Actually, for portability reasons, it is good
3138 * programming practice, as this example shows, to limit all actual
3139 * system calls to a single occurrence in the source. Sure, this
3140 * adds an extra level of function call overhead but it is almost
3141 * always negligible. Fred Fish, Unisoft Systems Inc.
3144 #ifndef HAVE_SYS_SIGLIST
3145 char *sys_siglist
[NSIG
+ 1] =
3148 /* AIX has changed the signals a bit */
3149 "bogus signal", /* 0 */
3150 "hangup", /* 1 SIGHUP */
3151 "interrupt", /* 2 SIGINT */
3152 "quit", /* 3 SIGQUIT */
3153 "illegal instruction", /* 4 SIGILL */
3154 "trace trap", /* 5 SIGTRAP */
3155 "IOT instruction", /* 6 SIGIOT */
3156 "crash likely", /* 7 SIGDANGER */
3157 "floating point exception", /* 8 SIGFPE */
3158 "kill", /* 9 SIGKILL */
3159 "bus error", /* 10 SIGBUS */
3160 "segmentation violation", /* 11 SIGSEGV */
3161 "bad argument to system call", /* 12 SIGSYS */
3162 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3163 "alarm clock", /* 14 SIGALRM */
3164 "software termination signum", /* 15 SIGTERM */
3165 "user defined signal 1", /* 16 SIGUSR1 */
3166 "user defined signal 2", /* 17 SIGUSR2 */
3167 "death of a child", /* 18 SIGCLD */
3168 "power-fail restart", /* 19 SIGPWR */
3169 "bogus signal", /* 20 */
3170 "bogus signal", /* 21 */
3171 "bogus signal", /* 22 */
3172 "bogus signal", /* 23 */
3173 "bogus signal", /* 24 */
3174 "LAN I/O interrupt", /* 25 SIGAIO */
3175 "PTY I/O interrupt", /* 26 SIGPTY */
3176 "I/O intervention required", /* 27 SIGIOINT */
3178 "HFT grant", /* 28 SIGGRANT */
3179 "HFT retract", /* 29 SIGRETRACT */
3180 "HFT sound done", /* 30 SIGSOUND */
3181 "HFT input ready", /* 31 SIGMSG */
3184 "bogus signal", /* 0 */
3185 "hangup", /* 1 SIGHUP */
3186 "interrupt", /* 2 SIGINT */
3187 "quit", /* 3 SIGQUIT */
3188 "illegal instruction", /* 4 SIGILL */
3189 "trace trap", /* 5 SIGTRAP */
3190 "IOT instruction", /* 6 SIGIOT */
3191 "EMT instruction", /* 7 SIGEMT */
3192 "floating point exception", /* 8 SIGFPE */
3193 "kill", /* 9 SIGKILL */
3194 "bus error", /* 10 SIGBUS */
3195 "segmentation violation", /* 11 SIGSEGV */
3196 "bad argument to system call", /* 12 SIGSYS */
3197 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3198 "alarm clock", /* 14 SIGALRM */
3199 "software termination signum", /* 15 SIGTERM */
3200 "user defined signal 1", /* 16 SIGUSR1 */
3201 "user defined signal 2", /* 17 SIGUSR2 */
3202 "death of a child", /* 18 SIGCLD */
3203 "power-fail restart", /* 19 SIGPWR */
3205 "window size change", /* 20 SIGWINCH */
3206 "urgent socket condition", /* 21 SIGURG */
3207 "pollable event occurred", /* 22 SIGPOLL */
3208 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */
3209 "user stop requested from tty", /* 24 SIGTSTP */
3210 "stopped process has been continued", /* 25 SIGCONT */
3211 "background tty read attempted", /* 26 SIGTTIN */
3212 "background tty write attempted", /* 27 SIGTTOU */
3213 "virtual timer expired", /* 28 SIGVTALRM */
3214 "profiling timer expired", /* 29 SIGPROF */
3215 "exceeded cpu limit", /* 30 SIGXCPU */
3216 "exceeded file size limit", /* 31 SIGXFSZ */
3217 "process's lwps are blocked", /* 32 SIGWAITING */
3218 "special signal used by thread library", /* 33 SIGLWP */
3220 "Special Signal Used By CPR", /* 34 SIGFREEZE */
3223 "Special Signal Used By CPR", /* 35 SIGTHAW */
3226 #endif /* not AIX */
3229 #endif /* HAVE_SYS_SIGLIST */
3232 * Warning, this function may not duplicate 4.2 action properly
3233 * under error conditions.
3237 /* In 4.1, param.h fails to define this. */
3238 #define MAXPATHLEN 1024
3247 char *npath
, *spath
;
3248 extern char *getcwd ();
3250 BLOCK_INPUT
; /* getcwd uses malloc */
3251 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3254 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3255 up to first slash. Should be harmless on other systems. */
3256 while (*npath
&& *npath
!= '/')
3258 strcpy (pathname
, npath
);
3259 free (spath
); /* getcwd uses malloc */
3264 #endif /* HAVE_GETWD */
3267 * Emulate rename using unlink/link. Note that this is
3268 * only partially correct. Also, doesn't enforce restriction
3269 * that files be of same type (regular->regular, dir->dir, etc).
3278 if (access (from
, 0) == 0)
3281 if (link (from
, to
) == 0)
3282 if (unlink (from
) == 0)
3294 /* HPUX curses library references perror, but as far as we know
3295 it won't be called. Anyway this definition will do for now. */
3301 #endif /* not HAVE_PERROR */
3307 * Emulate BSD dup2. First close newd if it already exists.
3308 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3309 * until we are, then close the unsuccessful ones.
3316 register int fd
, ret
;
3321 fd
= fcntl (oldd
, F_DUPFD
, newd
);
3323 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, strerror (errno
));
3330 ret
= dup2 (old
,new);
3336 #endif /* not HAVE_DUP2 */
3339 * Gettimeofday. Simulate as much as possible. Only accurate
3340 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3341 * Only needed when subprocesses are defined.
3346 #ifndef HAVE_GETTIMEOFDAY
3351 gettimeofday (tp
, tzp
)
3353 struct timezone
*tzp
;
3355 extern long time ();
3357 tp
->tv_sec
= time ((long *)0);
3360 tzp
->tz_minuteswest
= -1;
3367 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3370 * This function will go away as soon as all the stubs fixed. (fnf)
3377 printf ("%s not yet implemented\r\n", badfunc
);
3386 char *sys_siglist
[NSIG
+ 1] =
3388 "null signal", /* 0 SIGNULL */
3389 "hangup", /* 1 SIGHUP */
3390 "interrupt", /* 2 SIGINT */
3391 "quit", /* 3 SIGQUIT */
3392 "illegal instruction", /* 4 SIGILL */
3393 "trace trap", /* 5 SIGTRAP */
3394 "abort termination", /* 6 SIGABRT */
3395 "SIGEMT", /* 7 SIGEMT */
3396 "floating point exception", /* 8 SIGFPE */
3397 "kill", /* 9 SIGKILL */
3398 "bus error", /* 10 SIGBUS */
3399 "segmentation violation", /* 11 SIGSEGV */
3400 "bad argument to system call", /* 12 SIGSYS */
3401 "write on a pipe with no reader", /* 13 SIGPIPE */
3402 "alarm clock", /* 14 SIGALRM */
3403 "software termination signal", /* 15 SIGTERM */
3404 "user defined signal 1", /* 16 SIGUSR1 */
3405 "user defined signal 2", /* 17 SIGUSR2 */
3406 "child stopped or terminated", /* 18 SIGCLD */
3407 "power-fail restart", /* 19 SIGPWR */
3408 "window size changed", /* 20 SIGWINCH */
3409 "undefined", /* 21 */
3410 "pollable event occurred", /* 22 SIGPOLL */
3411 "sendable stop signal not from tty", /* 23 SIGSTOP */
3412 "stop signal from tty", /* 24 SIGSTP */
3413 "continue a stopped process", /* 25 SIGCONT */
3414 "attempted background tty read", /* 26 SIGTTIN */
3415 "attempted background tty write", /* 27 SIGTTOU */
3416 "undefined", /* 28 */
3417 "undefined", /* 29 */
3418 "undefined", /* 30 */
3419 "undefined", /* 31 */
3420 "undefined", /* 32 */
3421 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
3422 "I/O is possible", /* 34 SIGIO */
3423 "exceeded cpu time limit", /* 35 SIGXCPU */
3424 "exceeded file size limit", /* 36 SIGXFSZ */
3425 "virtual time alarm", /* 37 SIGVTALRM */
3426 "profiling time alarm", /* 38 SIGPROF */
3427 "undefined", /* 39 */
3428 "file record locks revoked", /* 40 SIGLOST */
3429 "undefined", /* 41 */
3430 "undefined", /* 42 */
3431 "undefined", /* 43 */
3432 "undefined", /* 44 */
3433 "undefined", /* 45 */
3434 "undefined", /* 46 */
3435 "undefined", /* 47 */
3436 "undefined", /* 48 */
3437 "undefined", /* 49 */
3438 "undefined", /* 50 */
3439 "undefined", /* 51 */
3440 "undefined", /* 52 */
3441 "undefined", /* 53 */
3442 "undefined", /* 54 */
3443 "undefined", /* 55 */
3444 "undefined", /* 56 */
3445 "undefined", /* 57 */
3446 "undefined", /* 58 */
3447 "undefined", /* 59 */
3448 "undefined", /* 60 */
3449 "undefined", /* 61 */
3450 "undefined", /* 62 */
3451 "undefined", /* 63 */
3452 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3458 /* Directory routines for systems that don't have them. */
3460 #ifdef SYSV_SYSTEM_DIR
3464 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
3468 register DIR *dirp
; /* stream from opendir */
3472 rtnval
= sys_close (dirp
->dd_fd
);
3474 /* Some systems (like Solaris) allocate the buffer and the DIR all
3475 in one block. Why in the world are we freeing this ourselves
3477 #if ! (defined (sun) && defined (USG5_4))
3478 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3480 xfree ((char *) dirp
);
3484 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3485 #endif /* SYSV_SYSTEM_DIR */
3487 #ifdef NONSYSTEM_DIR_LIBRARY
3491 char *filename
; /* name of directory */
3493 register DIR *dirp
; /* -> malloc'ed storage */
3494 register int fd
; /* file descriptor for read */
3495 struct stat sbuf
; /* result of fstat */
3497 fd
= sys_open (filename
, 0);
3502 if (fstat (fd
, &sbuf
) < 0
3503 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3504 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
3508 return 0; /* bad luck today */
3513 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3520 register DIR *dirp
; /* stream from opendir */
3522 sys_close (dirp
->dd_fd
);
3523 xfree ((char *) dirp
);
3531 ino_t od_ino
; /* inode */
3532 char od_name
[DIRSIZ
]; /* filename */
3534 #endif /* not VMS */
3536 struct direct dir_static
; /* simulated directory contents */
3541 register DIR *dirp
; /* stream from opendir */
3544 register struct olddir
*dp
; /* -> directory data */
3546 register struct dir$_name
*dp
; /* -> directory data */
3547 register struct dir$_version
*dv
; /* -> version data */
3552 if (dirp
->dd_loc
>= dirp
->dd_size
)
3553 dirp
->dd_loc
= dirp
->dd_size
= 0;
3555 if (dirp
->dd_size
== 0 /* refill buffer */
3556 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3560 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3561 dirp
->dd_loc
+= sizeof (struct olddir
);
3563 if (dp
->od_ino
!= 0) /* not deleted entry */
3565 dir_static
.d_ino
= dp
->od_ino
;
3566 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3567 dir_static
.d_name
[DIRSIZ
] = '\0';
3568 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3569 dir_static
.d_reclen
= sizeof (struct direct
)
3571 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3572 return &dir_static
; /* -> simulated structure */
3575 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3576 if (dirp
->dd_loc
== 0)
3577 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3578 : dp
->dir$b_namecount
;
3579 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3580 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3581 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3582 dir_static
.d_reclen
= sizeof (struct direct
)
3584 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3585 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3586 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3587 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3594 /* readdirver is just like readdir except it returns all versions of a file
3595 as separate entries. */
3600 register DIR *dirp
; /* stream from opendir */
3602 register struct dir$_name
*dp
; /* -> directory data */
3603 register struct dir$_version
*dv
; /* -> version data */
3605 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3606 dirp
->dd_loc
= dirp
->dd_size
= 0;
3608 if (dirp
->dd_size
== 0 /* refill buffer */
3609 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3612 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3613 if (dirp
->dd_loc
== 0)
3614 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3615 : dp
->dir$b_namecount
;
3616 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3617 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3618 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3619 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3620 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3621 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3622 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3623 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3629 #endif /* NONSYSTEM_DIR_LIBRARY */
3633 set_file_times (filename
, atime
, mtime
)
3635 EMACS_TIME atime
, mtime
;
3638 struct timeval tv
[2];
3641 return utimes (filename
, tv
);
3642 #else /* not HAVE_UTIMES */
3644 utb
.actime
= EMACS_SECS (atime
);
3645 utb
.modtime
= EMACS_SECS (mtime
);
3646 return utime (filename
, &utb
);
3647 #endif /* not HAVE_UTIMES */
3650 /* mkdir and rmdir functions, for systems which don't have them. */
3654 * Written by Robert Rother, Mariah Corporation, August 1985.
3656 * If you want it, it's yours. All I ask in return is that if you
3657 * figure out how to do this in a Bourne Shell script you send me
3659 * sdcsvax!rmr or rmr@uscd
3661 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3662 * subroutine. 11Mar86; hoptoad!gnu
3664 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3665 * subroutine didn't return EEXIST. It does now.
3671 #ifdef MKDIR_PROTOTYPE
3675 mkdir (dpath
, dmode
)
3680 int cpid
, status
, fd
;
3681 struct stat statbuf
;
3683 if (stat (dpath
, &statbuf
) == 0)
3685 errno
= EEXIST
; /* Stat worked, so it already exists */
3689 /* If stat fails for a reason other than non-existence, return error */
3690 if (errno
!= ENOENT
)
3693 synch_process_alive
= 1;
3694 switch (cpid
= fork ())
3697 case -1: /* Error in fork */
3698 return (-1); /* Errno is set already */
3700 case 0: /* Child process */
3702 * Cheap hack to set mode of new directory. Since this
3703 * child process is going away anyway, we zap its umask.
3704 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3705 * directory. Does anybody care?
3707 status
= umask (0); /* Get current umask */
3708 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3709 fd
= sys_open("/dev/null", 2);
3716 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3717 _exit (-1); /* Can't exec /bin/mkdir */
3719 default: /* Parent process */
3720 wait_for_termination (cpid
);
3723 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3725 errno
= EIO
; /* We don't know why, but */
3726 return -1; /* /bin/mkdir failed */
3731 #endif /* not HAVE_MKDIR */
3738 int cpid
, status
, fd
;
3739 struct stat statbuf
;
3741 if (stat (dpath
, &statbuf
) != 0)
3743 /* Stat just set errno. We don't have to */
3747 synch_process_alive
= 1;
3748 switch (cpid
= fork ())
3751 case -1: /* Error in fork */
3752 return (-1); /* Errno is set already */
3754 case 0: /* Child process */
3755 fd
= sys_open("/dev/null", 2);
3762 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3763 _exit (-1); /* Can't exec /bin/rmdir */
3765 default: /* Parent process */
3766 wait_for_termination (cpid
);
3769 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3771 errno
= EIO
; /* We don't know why, but */
3772 return -1; /* /bin/rmdir failed */
3777 #endif /* !HAVE_RMDIR */
3781 /* Functions for VMS */
3783 #include "vms-pwd.h"
3788 /* Return as a string the VMS error string pertaining to STATUS.
3789 Reuses the same static buffer each time it is called. */
3793 int status
; /* VMS status code */
3797 static char buf
[257];
3799 bufadr
[0] = sizeof buf
- 1;
3800 bufadr
[1] = (int) buf
;
3801 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3802 return "untranslatable VMS error status";
3810 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3811 * not work correctly. (It also doesn't work well in version 2.3.)
3816 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3817 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3821 unsigned short s_buflen
;
3822 unsigned short s_code
;
3824 unsigned short *s_retlenadr
;
3828 #define buflen s.s_buflen
3829 #define code s.s_code
3830 #define bufadr s.s_bufadr
3831 #define retlenadr s.s_retlenadr
3833 #define R_OK 4 /* test for read permission */
3834 #define W_OK 2 /* test for write permission */
3835 #define X_OK 1 /* test for execute (search) permission */
3836 #define F_OK 0 /* test for presence of file */
3839 sys_access (path
, mode
)
3843 static char *user
= NULL
;
3846 /* translate possible directory spec into .DIR file name, so brain-dead
3847 * access can treat the directory like a file. */
3848 if (directory_file_name (path
, dir_fn
))
3852 return access (path
, mode
);
3853 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3859 unsigned short int dummy
;
3861 static int constant
= ACL$C_FILE
;
3862 DESCRIPTOR (path_desc
, path
);
3863 DESCRIPTOR (user_desc
, user
);
3867 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3870 acces
|= CHP$M_READ
;
3872 acces
|= CHP$M_WRITE
;
3873 itemlst
[0].buflen
= sizeof (int);
3874 itemlst
[0].code
= CHP$_FLAGS
;
3875 itemlst
[0].bufadr
= (char *) &flags
;
3876 itemlst
[0].retlenadr
= &dummy
;
3877 itemlst
[1].buflen
= sizeof (int);
3878 itemlst
[1].code
= CHP$_ACCESS
;
3879 itemlst
[1].bufadr
= (char *) &acces
;
3880 itemlst
[1].retlenadr
= &dummy
;
3881 itemlst
[2].end
= CHP$_END
;
3882 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3883 return stat
== SS$_NORMAL
? 0 : -1;
3887 #else /* not VMS4_4 */
3890 #define ACE$M_WRITE 2
3891 #define ACE$C_KEYID 1
3893 static unsigned short memid
, grpid
;
3894 static unsigned int uic
;
3896 /* Called from init_sys_modes, so it happens not very often
3897 but at least each time Emacs is loaded. */
3899 sys_access_reinit ()
3905 sys_access (filename
, type
)
3911 int status
, size
, i
, typecode
, acl_controlled
;
3912 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3913 union prvdef prvmask
;
3915 /* Get UIC and GRP values for protection checking. */
3918 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3921 memid
= uic
& 0xFFFF;
3925 if (type
!= 2) /* not checking write access */
3926 return access (filename
, type
);
3928 /* Check write protection. */
3930 #define CHECKPRIV(bit) (prvmask.bit)
3931 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3933 /* Find privilege bits */
3934 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3936 error ("Unable to find privileges: %s", vmserrstr (status
));
3937 if (CHECKPRIV (PRV$V_BYPASS
))
3938 return 0; /* BYPASS enabled */
3940 fab
.fab$b_fac
= FAB$M_GET
;
3941 fab
.fab$l_fna
= filename
;
3942 fab
.fab$b_fns
= strlen (filename
);
3943 fab
.fab$l_xab
= &xab
;
3944 xab
= cc$rms_xabpro
;
3945 xab
.xab$l_aclbuf
= aclbuf
;
3946 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3947 status
= SYS$
OPEN (&fab
, 0, 0);
3950 SYS$
CLOSE (&fab
, 0, 0);
3951 /* Check system access */
3952 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
3954 /* Check ACL entries, if any */
3956 if (xab
.xab$w_acllen
> 0)
3959 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3960 while (*aclptr
&& aclptr
< aclend
)
3962 size
= (*aclptr
& 0xff) / 4;
3963 typecode
= (*aclptr
>> 8) & 0xff;
3964 if (typecode
== ACE$C_KEYID
)
3965 for (i
= size
- 1; i
> 1; i
--)
3966 if (aclptr
[i
] == uic
)
3969 if (aclptr
[1] & ACE$M_WRITE
)
3970 return 0; /* Write access through ACL */
3972 aclptr
= &aclptr
[size
];
3974 if (acl_controlled
) /* ACL specified, prohibits write access */
3977 /* No ACL entries specified, check normal protection */
3978 if (WRITABLE (XAB$V_WLD
)) /* World writable */
3980 if (WRITABLE (XAB$V_GRP
) &&
3981 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3982 return 0; /* Group writable */
3983 if (WRITABLE (XAB$V_OWN
) &&
3984 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3985 return 0; /* Owner writable */
3987 return -1; /* Not writable */
3989 #endif /* not VMS4_4 */
3992 static char vtbuf
[NAM$C_MAXRSS
+1];
3994 /* translate a vms file spec to a unix path */
3996 sys_translate_vms (vfile
)
4007 /* leading device or logical name is a root directory */
4008 if (p
= strchr (vfile
, ':'))
4017 if (*p
== '[' || *p
== '<')
4019 while (*++vfile
!= *p
+ 2)
4023 if (vfile
[-1] == *p
)
4046 static char utbuf
[NAM$C_MAXRSS
+1];
4048 /* translate a unix path to a VMS file spec */
4050 sys_translate_unix (ufile
)
4073 if (index (&ufile
[1], '/'))
4080 if (index (&ufile
[1], '/'))
4087 if (strncmp (ufile
, "./", 2) == 0)
4094 ufile
++; /* skip the dot */
4095 if (index (&ufile
[1], '/'))
4100 else if (strncmp (ufile
, "../", 3) == 0)
4108 ufile
+= 2; /* skip the dots */
4109 if (index (&ufile
[1], '/'))
4134 extern char *getcwd ();
4136 #define MAXPATHLEN 1024
4138 ptr
= xmalloc (MAXPATHLEN
);
4139 val
= getcwd (ptr
, MAXPATHLEN
);
4145 strcpy (pathname
, ptr
);
4154 long item_code
= JPI$_OWNER
;
4155 unsigned long parent_id
;
4158 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4161 vaxc$errno
= status
;
4171 return (getgid () << 16) | getuid ();
4175 sys_read (fildes
, buf
, nbyte
)
4180 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4185 sys_write (fildes
, buf
, nbyte
)
4190 register int nwrote
, rtnval
= 0;
4192 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4198 return rtnval
? rtnval
: -1;
4199 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4200 return rtnval
? rtnval
: -1;
4201 return (rtnval
+ nwrote
);
4206 * VAX/VMS VAX C RTL really loses. It insists that records
4207 * end with a newline (carriage return) character, and if they
4208 * don't it adds one (nice of it isn't it!)
4210 * Thus we do this stupidity below.
4214 sys_write (fildes
, buf
, nbytes
)
4217 unsigned int nbytes
;
4224 fstat (fildes
, &st
);
4230 /* Handle fixed-length files with carriage control. */
4231 if (st
.st_fab_rfm
== FAB$C_FIX
4232 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4234 len
= st
.st_fab_mrs
;
4235 retval
= write (fildes
, p
, min (len
, nbytes
));
4238 retval
++; /* This skips the implied carriage control */
4242 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4243 while (*e
!= '\n' && e
> p
) e
--;
4244 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4245 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4247 retval
= write (fildes
, p
, len
);
4258 /* Create file NEW copying its attributes from file OLD. If
4259 OLD is 0 or does not exist, create based on the value of
4262 /* Protection value the file should ultimately have.
4263 Set by create_copy_attrs, and use by rename_sansversions. */
4264 static unsigned short int fab_final_pro
;
4267 creat_copy_attrs (old
, new)
4270 struct FAB fab
= cc$rms_fab
;
4271 struct XABPRO xabpro
;
4272 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4273 extern int vms_stmlf_recfm
;
4277 fab
.fab$b_fac
= FAB$M_GET
;
4278 fab
.fab$l_fna
= old
;
4279 fab
.fab$b_fns
= strlen (old
);
4280 fab
.fab$l_xab
= (char *) &xabpro
;
4281 xabpro
= cc$rms_xabpro
;
4282 xabpro
.xab$l_aclbuf
= aclbuf
;
4283 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4284 /* Call $OPEN to fill in the fab & xabpro fields. */
4285 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4287 SYS$
CLOSE (&fab
, 0, 0);
4288 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4289 if (xabpro
.xab$w_acllen
> 0)
4291 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4292 /* If the acl buffer was too short, redo open with longer one.
4293 Wouldn't need to do this if there were some system imposed
4294 limit on the size of an ACL, but I can't find any such. */
4296 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4297 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4298 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4299 SYS$
CLOSE (&fab
, 0, 0);
4305 xabpro
.xab$l_aclbuf
= 0;
4310 fab
.fab$l_fna
= new;
4311 fab
.fab$b_fns
= strlen (new);
4315 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4316 fab
.fab$b_rat
= FAB$M_CR
;
4319 /* Set the file protections such that we will be able to manipulate
4320 this file. Once we are done writing and renaming it, we will set
4321 the protections back. */
4323 fab_final_pro
= xabpro
.xab$w_pro
;
4325 SYS$
SETDFPROT (0, &fab_final_pro
);
4326 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4328 /* Create the new file with either default attrs or attrs copied
4330 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4332 SYS$
CLOSE (&fab
, 0, 0);
4333 /* As this is a "replacement" for creat, return a file descriptor
4334 opened for writing. */
4335 return open (new, O_WRONLY
);
4340 #include <varargs.h>
4343 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4348 sys_creat (va_alist
)
4351 va_list list_incrementer
;
4354 int rfd
; /* related file descriptor */
4355 int fd
; /* Our new file descriptor */
4362 extern int vms_stmlf_recfm
;
4365 va_start (list_incrementer
);
4366 name
= va_arg (list_incrementer
, char *);
4367 mode
= va_arg (list_incrementer
, int);
4369 rfd
= va_arg (list_incrementer
, int);
4370 va_end (list_incrementer
);
4373 /* Use information from the related file descriptor to set record
4374 format of the newly created file. */
4375 fstat (rfd
, &st_buf
);
4376 switch (st_buf
.st_fab_rfm
)
4379 strcpy (rfm
, "rfm = fix");
4380 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4381 strcpy (rat
, "rat = ");
4382 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4384 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4385 strcat (rat
, "ftn");
4386 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4387 strcat (rat
, "prn");
4388 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4389 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4390 strcat (rat
, ", blk");
4392 strcat (rat
, "blk");
4393 return creat (name
, 0, rfm
, rat
, mrs
);
4396 strcpy (rfm
, "rfm = vfc");
4397 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4398 strcpy (rat
, "rat = ");
4399 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4401 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4402 strcat (rat
, "ftn");
4403 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4404 strcat (rat
, "prn");
4405 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4406 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4407 strcat (rat
, ", blk");
4409 strcat (rat
, "blk");
4410 return creat (name
, 0, rfm
, rat
, fsz
);
4413 strcpy (rfm
, "rfm = stm");
4417 strcpy (rfm
, "rfm = stmcr");
4421 strcpy (rfm
, "rfm = stmlf");
4425 strcpy (rfm
, "rfm = udf");
4429 strcpy (rfm
, "rfm = var");
4432 strcpy (rat
, "rat = ");
4433 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4435 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4436 strcat (rat
, "ftn");
4437 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4438 strcat (rat
, "prn");
4439 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4440 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4441 strcat (rat
, ", blk");
4443 strcat (rat
, "blk");
4447 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4448 strcpy (rat
, "rat=cr");
4450 /* Until the VAX C RTL fixes the many bugs with modes, always use
4451 mode 0 to get the user's default protection. */
4452 fd
= creat (name
, 0, rfm
, rat
);
4453 if (fd
< 0 && errno
== EEXIST
)
4455 if (unlink (name
) < 0)
4456 report_file_error ("delete", build_string (name
));
4457 fd
= creat (name
, 0, rfm
, rat
);
4463 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4465 sys_fwrite (ptr
, size
, num
, fp
)
4466 register char * ptr
;
4469 register int tot
= num
* size
;
4477 * The VMS C library routine creat actually creates a new version of an
4478 * existing file rather than truncating the old version. There are times
4479 * when this is not the desired behavior, for instance, when writing an
4480 * auto save file (you only want one version), or when you don't have
4481 * write permission in the directory containing the file (but the file
4482 * itself is writable). Hence this routine, which is equivalent to
4483 * "close (creat (fn, 0));" on Unix if fn already exists.
4489 struct FAB xfab
= cc$rms_fab
;
4490 struct RAB xrab
= cc$rms_rab
;
4493 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4494 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4495 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4496 xfab
.fab$l_fna
= fn
;
4497 xfab
.fab$b_fns
= strlen (fn
);
4498 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4500 xrab
.rab$l_fab
= &xfab
;
4502 /* This gibberish opens the file, positions to the first record, and
4503 deletes all records from there until the end of file. */
4504 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4506 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4507 (SYS$
FIND (&xrab
) & 01) == 01 &&
4508 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4519 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4520 SYSPRV or a readable SYSUAF.DAT. */
4526 * Routine to read the VMS User Authorization File and return
4527 * a specific user's record.
4530 static struct UAF retuaf
;
4533 get_uaf_name (uname
)
4540 uaf_fab
= cc$rms_fab
;
4541 uaf_rab
= cc$rms_rab
;
4542 /* initialize fab fields */
4543 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4544 uaf_fab
.fab$b_fns
= 21;
4545 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4546 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4547 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4548 /* initialize rab fields */
4549 uaf_rab
.rab$l_fab
= &uaf_fab
;
4550 /* open the User Authorization File */
4551 status
= SYS$
OPEN (&uaf_fab
);
4555 vaxc$errno
= status
;
4558 status
= SYS$
CONNECT (&uaf_rab
);
4562 vaxc$errno
= status
;
4565 /* read the requested record - index is in uname */
4566 uaf_rab
.rab$l_kbf
= uname
;
4567 uaf_rab
.rab$b_ksz
= strlen (uname
);
4568 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4569 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4570 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4571 status
= SYS$
GET (&uaf_rab
);
4575 vaxc$errno
= status
;
4578 /* close the User Authorization File */
4579 status
= SYS$
DISCONNECT (&uaf_rab
);
4583 vaxc$errno
= status
;
4586 status
= SYS$
CLOSE (&uaf_fab
);
4590 vaxc$errno
= status
;
4604 uaf_fab
= cc$rms_fab
;
4605 uaf_rab
= cc$rms_rab
;
4606 /* initialize fab fields */
4607 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4608 uaf_fab
.fab$b_fns
= 21;
4609 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4610 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4611 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4612 /* initialize rab fields */
4613 uaf_rab
.rab$l_fab
= &uaf_fab
;
4614 /* open the User Authorization File */
4615 status
= SYS$
OPEN (&uaf_fab
);
4619 vaxc$errno
= status
;
4622 status
= SYS$
CONNECT (&uaf_rab
);
4626 vaxc$errno
= status
;
4629 /* read the requested record - index is in uic */
4630 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4631 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4632 uaf_rab
.rab$b_ksz
= sizeof uic
;
4633 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4634 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4635 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4636 status
= SYS$
GET (&uaf_rab
);
4640 vaxc$errno
= status
;
4643 /* close the User Authorization File */
4644 status
= SYS$
DISCONNECT (&uaf_rab
);
4648 vaxc$errno
= status
;
4651 status
= SYS$
CLOSE (&uaf_fab
);
4655 vaxc$errno
= status
;
4661 static struct passwd retpw
;
4669 /* copy these out first because if the username is 32 chars, the next
4670 section will overwrite the first byte of the UIC */
4671 retpw
.pw_uid
= up
->uaf$w_mem
;
4672 retpw
.pw_gid
= up
->uaf$w_grp
;
4674 /* I suppose this is not the best style, to possibly overwrite one
4675 byte beyond the end of the field, but what the heck... */
4676 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4677 while (ptr
[-1] == ' ')
4680 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4682 /* the rest of these are counted ascii strings */
4683 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4684 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4685 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4686 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4687 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4688 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4689 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4690 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4694 #else /* not READ_SYSUAF */
4695 static struct passwd retpw
;
4696 #endif /* not READ_SYSUAF */
4707 unsigned char * full
;
4708 #endif /* READ_SYSUAF */
4713 if ('a' <= *ptr
&& *ptr
<= 'z')
4718 if (!(up
= get_uaf_name (name
)))
4720 return cnv_uaf_pw (up
);
4722 if (strcmp (name
, getenv ("USER")) == 0)
4724 retpw
.pw_uid
= getuid ();
4725 retpw
.pw_gid
= getgid ();
4726 strcpy (retpw
.pw_name
, name
);
4727 if (full
= egetenv ("FULLNAME"))
4728 strcpy (retpw
.pw_gecos
, full
);
4730 *retpw
.pw_gecos
= '\0';
4731 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4732 *retpw
.pw_shell
= '\0';
4737 #endif /* not READ_SYSUAF */
4747 if (!(up
= get_uaf_uic (uid
)))
4749 return cnv_uaf_pw (up
);
4751 if (uid
== sys_getuid ())
4752 return getpwnam (egetenv ("USER"));
4755 #endif /* not READ_SYSUAF */
4758 /* return total address space available to the current process. This is
4759 the sum of the current p0 size, p1 size and free page table entries
4765 unsigned long free_pages
;
4766 unsigned long frep0va
;
4767 unsigned long frep1va
;
4770 item_code
= JPI$_FREPTECNT
;
4771 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4774 vaxc$errno
= status
;
4779 item_code
= JPI$_FREP0VA
;
4780 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4783 vaxc$errno
= status
;
4786 item_code
= JPI$_FREP1VA
;
4787 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4790 vaxc$errno
= status
;
4794 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4798 define_logical_name (varname
, string
)
4802 struct dsc$descriptor_s strdsc
=
4803 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4804 struct dsc$descriptor_s envdsc
=
4805 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4806 struct dsc$descriptor_s lnmdsc
=
4807 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4809 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4813 delete_logical_name (varname
)
4816 struct dsc$descriptor_s envdsc
=
4817 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4818 struct dsc$descriptor_s lnmdsc
=
4819 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4821 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4839 error ("execvp system call not implemented");
4848 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4849 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4850 char from_esn
[NAM$C_MAXRSS
];
4851 char to_esn
[NAM$C_MAXRSS
];
4853 from_fab
.fab$l_fna
= from
;
4854 from_fab
.fab$b_fns
= strlen (from
);
4855 from_fab
.fab$l_nam
= &from_nam
;
4856 from_fab
.fab$l_fop
= FAB$M_NAM
;
4858 from_nam
.nam$l_esa
= from_esn
;
4859 from_nam
.nam$b_ess
= sizeof from_esn
;
4861 to_fab
.fab$l_fna
= to
;
4862 to_fab
.fab$b_fns
= strlen (to
);
4863 to_fab
.fab$l_nam
= &to_nam
;
4864 to_fab
.fab$l_fop
= FAB$M_NAM
;
4866 to_nam
.nam$l_esa
= to_esn
;
4867 to_nam
.nam$b_ess
= sizeof to_esn
;
4869 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4875 if (status
== RMS$_DEV
)
4879 vaxc$errno
= status
;
4884 /* This function renames a file like `rename', but it strips
4885 the version number from the "to" filename, such that the "to" file is
4886 will always be a new version. It also sets the file protection once it is
4887 finished. The protection that we will use is stored in fab_final_pro,
4888 and was set when we did a creat_copy_attrs to create the file that we
4891 We could use the chmod function, but Eunichs uses 3 bits per user category
4892 to describe the protection, and VMS uses 4 (write and delete are separate
4893 bits). To maintain portability, the VMS implementation of `chmod' wires
4894 the W and D bits together. */
4897 static struct fibdef fib
; /* We need this initialized to zero */
4898 char vms_file_written
[NAM$C_MAXRSS
];
4901 rename_sans_version (from
,to
)
4908 struct FAB to_fab
= cc$rms_fab
;
4909 struct NAM to_nam
= cc$rms_nam
;
4910 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4911 struct dsc$descriptor fib_attr
[2]
4912 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4913 char to_esn
[NAM$C_MAXRSS
];
4915 $
DESCRIPTOR (disk
,to_esn
);
4917 to_fab
.fab$l_fna
= to
;
4918 to_fab
.fab$b_fns
= strlen (to
);
4919 to_fab
.fab$l_nam
= &to_nam
;
4920 to_fab
.fab$l_fop
= FAB$M_NAM
;
4922 to_nam
.nam$l_esa
= to_esn
;
4923 to_nam
.nam$b_ess
= sizeof to_esn
;
4925 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4927 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4928 *(to_nam
.nam$l_ver
) = '\0';
4930 stat
= rename (from
, to_esn
);
4934 strcpy (vms_file_written
, to_esn
);
4936 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4937 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4939 /* Now set the file protection to the correct value */
4940 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4942 /* Copy these fields into the fib */
4943 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4944 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4945 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4947 SYS$
CLOSE (&to_fab
, 0, 0);
4949 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4952 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4953 0, 0, 0, &fib_attr
, 0);
4956 stat
= SYS$
DASSGN (chan
);
4959 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4970 unsigned short fid
[3];
4971 char esa
[NAM$C_MAXRSS
];
4974 fab
.fab$l_fop
= FAB$M_OFP
;
4975 fab
.fab$l_fna
= file
;
4976 fab
.fab$b_fns
= strlen (file
);
4977 fab
.fab$l_nam
= &nam
;
4980 nam
.nam$l_esa
= esa
;
4981 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4983 status
= SYS$
PARSE (&fab
);
4984 if ((status
& 1) == 0)
4987 vaxc$errno
= status
;
4990 status
= SYS$
SEARCH (&fab
);
4991 if ((status
& 1) == 0)
4994 vaxc$errno
= status
;
4998 fid
[0] = nam
.nam$w_fid
[0];
4999 fid
[1] = nam
.nam$w_fid
[1];
5000 fid
[2] = nam
.nam$w_fid
[2];
5002 fab
.fab$l_fna
= new;
5003 fab
.fab$b_fns
= strlen (new);
5005 status
= SYS$
PARSE (&fab
);
5006 if ((status
& 1) == 0)
5009 vaxc$errno
= status
;
5013 nam
.nam$w_fid
[0] = fid
[0];
5014 nam
.nam$w_fid
[1] = fid
[1];
5015 nam
.nam$w_fid
[2] = fid
[2];
5017 nam
.nam$l_esa
= nam
.nam$l_name
;
5018 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
5020 status
= SYS$
ENTER (&fab
);
5021 if ((status
& 1) == 0)
5024 vaxc$errno
= status
;
5035 printf ("%s not yet implemented\r\n", badfunc
);
5043 /* Arrange to return a range centered on zero. */
5044 return rand () - (1 << 30);
5056 /* Called from init_sys_modes. */
5062 /* If we're not on an HFT we shouldn't do any of this. We determine
5063 if we are on an HFT by trying to get an HFT error code. If this
5064 call fails, we're not on an HFT. */
5066 if (ioctl (0, HFQERROR
, &junk
) < 0)
5068 #else /* not IBMR2AIX */
5069 if (ioctl (0, HFQEIO
, 0) < 0)
5071 #endif /* not IBMR2AIX */
5073 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5074 as the rubout key's ASCII code. Here this is changed. The bug is that
5075 there's no way to determine the old mapping, so in reset_sys_modes
5076 we need to assume that the normal map had been present. Of course, this
5077 code also doesn't help if on a terminal emulator which doesn't understand
5081 struct hfkeymap keymap
;
5083 buf
.hf_bufp
= (char *)&keymap
;
5084 buf
.hf_buflen
= sizeof (keymap
);
5085 keymap
.hf_nkeys
= 2;
5086 keymap
.hfkey
[0].hf_kpos
= 15;
5087 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5089 keymap
.hfkey
[0].hf_keyidh
= '<';
5090 #else /* not IBMR2AIX */
5091 keymap
.hfkey
[0].hf_page
= '<';
5092 #endif /* not IBMR2AIX */
5093 keymap
.hfkey
[0].hf_char
= 127;
5094 keymap
.hfkey
[1].hf_kpos
= 15;
5095 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5097 keymap
.hfkey
[1].hf_keyidh
= '<';
5098 #else /* not IBMR2AIX */
5099 keymap
.hfkey
[1].hf_page
= '<';
5100 #endif /* not IBMR2AIX */
5101 keymap
.hfkey
[1].hf_char
= 127;
5102 hftctl (0, HFSKBD
, &buf
);
5104 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5106 line_ins_del_ok
= char_ins_del_ok
= 0;
5109 /* Reset the rubout key to backspace. */
5115 struct hfkeymap keymap
;
5119 if (ioctl (0, HFQERROR
, &junk
) < 0)
5121 #else /* not IBMR2AIX */
5122 if (ioctl (0, HFQEIO
, 0) < 0)
5124 #endif /* not IBMR2AIX */
5126 buf
.hf_bufp
= (char *)&keymap
;
5127 buf
.hf_buflen
= sizeof (keymap
);
5128 keymap
.hf_nkeys
= 2;
5129 keymap
.hfkey
[0].hf_kpos
= 15;
5130 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5132 keymap
.hfkey
[0].hf_keyidh
= '<';
5133 #else /* not IBMR2AIX */
5134 keymap
.hfkey
[0].hf_page
= '<';
5135 #endif /* not IBMR2AIX */
5136 keymap
.hfkey
[0].hf_char
= 8;
5137 keymap
.hfkey
[1].hf_kpos
= 15;
5138 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5140 keymap
.hfkey
[1].hf_keyidh
= '<';
5141 #else /* not IBMR2AIX */
5142 keymap
.hfkey
[1].hf_page
= '<';
5143 #endif /* not IBMR2AIX */
5144 keymap
.hfkey
[1].hf_char
= 8;
5145 hftctl (0, HFSKBD
, &buf
);
5152 /* These are included on Sunos 4.1 when we do not use shared libraries.
5153 X11 libraries may refer to these functions but (we hope) do not
5154 actually call them. */
5174 #endif /* USE_DL_STUBS */
5183 register int length
;
5187 long max_str
= 65535;
5189 while (length
> max_str
) {
5190 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5195 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5197 while (length
-- > 0)
5199 #endif /* not VMS */
5202 #endif /* no bzero */
5203 #endif /* BSTRING */
5205 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5208 /* Saying `void' requires a declaration, above, where bcopy is used
5209 and that declaration causes pain for systems where bcopy is a macro. */
5210 bcopy (b1
, b2
, length
)
5213 register int length
;
5216 long max_str
= 65535;
5218 while (length
> max_str
) {
5219 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5225 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5227 while (length
-- > 0)
5229 #endif /* not VMS */
5231 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5236 bcmp (b1
, b2
, length
) /* This could be a macro! */
5239 register int length
;
5242 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5243 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5245 return STR$
COMPARE (&src1
, &src2
);
5247 while (length
-- > 0)
5252 #endif /* not VMS */
5254 #endif /* no bcmp */
5255 #endif /* not BSTRING */