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
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 */
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. */
261 struct emacs_tty buf
;
266 /* Discarding input is not safe when the input could contain
267 replies from the X server. So don't do it. */
268 if (read_socket_hook
)
273 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
274 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
280 ioctl (input_fd
, TIOCFLUSH
, &zero
);
282 #else /* not Apollo */
283 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
284 while (dos_keyread () != -1)
286 #else /* not MSDOS */
287 EMACS_GET_TTY (input_fd
, &buf
);
288 EMACS_SET_TTY (input_fd
, &buf
, 0);
289 #endif /* not MSDOS */
290 #endif /* not Apollo */
292 #endif /* not WINDOWSNT */
297 /* Arrange for character C to be read as the next input from
303 if (read_socket_hook
)
306 /* Should perhaps error if in batch mode */
308 ioctl (input_fd
, TIOCSTI
, &c
);
309 #else /* no TIOCSTI */
310 error ("Cannot stuff terminal input characters in this version of Unix");
311 #endif /* no TIOCSTI */
322 #ifdef INIT_BAUD_RATE
327 #else /* not DOS_NT */
331 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
332 &sg
.class, 12, 0, 0, 0, 0 );
333 ospeed
= sg
.xmit_baud
;
339 tcgetattr (input_fd
, &sg
);
340 ospeed
= cfgetospeed (&sg
);
341 #if defined (USE_GETOBAUD) && defined (getobaud)
342 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
344 ospeed
= getobaud (sg
.c_cflag
);
346 #else /* neither VMS nor TERMIOS */
352 tcgetattr (input_fd
, &sg
);
354 ioctl (input_fd
, TCGETA
, &sg
);
356 ospeed
= sg
.c_cflag
& CBAUD
;
357 #else /* neither VMS nor TERMIOS nor TERMIO */
360 sg
.sg_ospeed
= B9600
;
361 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
363 ospeed
= sg
.sg_ospeed
;
364 #endif /* not HAVE_TERMIO */
365 #endif /* not HAVE_TERMIOS */
367 #endif /* not DOS_NT */
368 #endif /* not INIT_BAUD_RATE */
371 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
372 ? baud_convert
[ospeed
] : 9600);
378 set_exclusive_use (fd
)
382 ioctl (fd
, FIOCLEX
, 0);
384 /* Ok to do nothing if this feature does not exist */
389 wait_without_blocking ()
392 wait3 (0, WNOHANG
| WUNTRACED
, 0);
394 croak ("wait_without_blocking");
396 synch_process_alive
= 0;
399 #endif /* not subprocesses */
401 int wait_debugging
; /* Set nonzero to make following function work under dbx
402 (at least for bsd). */
405 wait_for_termination_signal ()
408 /* Wait for subprocess with process id `pid' to terminate and
409 make sure it will get eliminated (not remain forever as a zombie) */
411 wait_for_termination (pid
)
420 status
= SYS$
FORCEX (&pid
, 0, 0);
423 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
424 /* Note that kill returns -1 even if the process is just a zombie now.
425 But inevitably a SIGCHLD interrupt should be generated
426 and child_sig will do wait3 and make the process go away. */
427 /* There is some indication that there is a bug involved with
428 termination of subprocesses, perhaps involving a kernel bug too,
429 but no idea what it is. Just as a hunch we signal SIGCHLD to see
430 if that causes the problem to go away or get worse. */
431 sigsetmask (sigmask (SIGCHLD
));
432 if (0 > kill (pid
, 0))
434 sigsetmask (SIGEMPTYMASK
);
435 kill (getpid (), SIGCHLD
);
441 sigpause (SIGEMPTYMASK
);
442 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
443 #if defined (UNIPLUS)
444 if (0 > kill (pid
, 0))
447 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
448 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
449 sigblock (sigmask (SIGCHLD
));
450 if (0 > kill (pid
, 0))
452 sigunblock (sigmask (SIGCHLD
));
455 sigpause (SIGEMPTYMASK
);
456 #else /* not POSIX_SIGNALS */
457 #ifdef HAVE_SYSV_SIGPAUSE
459 if (0 > kill (pid
, 0))
465 #else /* not HAVE_SYSV_SIGPAUSE */
469 #else /* not WINDOWSNT */
470 if (0 > kill (pid
, 0))
472 /* Using sleep instead of pause avoids timing error.
473 If the inferior dies just before the sleep,
474 we lose just one second. */
476 #endif /* not WINDOWSNT */
477 #endif /* not HAVE_SYSV_SIGPAUSE */
478 #endif /* not POSIX_SIGNALS */
479 #endif /* not UNIPLUS */
480 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
482 #else /* not subprocesses */
485 #else /* not __DJGPP__ > 1 */
487 if (kill (pid
, 0) < 0)
493 if (status
== pid
|| status
== -1)
496 #endif /* not __DJGPP__ > 1*/
497 #endif /* not subprocesses */
504 * flush any pending output
505 * (may flush input as well; it does not matter the way we use it)
508 flush_pending_output (channel
)
512 /* If we try this, we get hit with SIGTTIN, because
513 the child's tty belongs to the child's pgrp. */
516 ioctl (channel
, TCFLSH
, 1);
520 /* 3rd arg should be ignored
521 but some 4.2 kernels actually want the address of an int
522 and nonzero means something different. */
523 ioctl (channel
, TIOCFLUSH
, &zero
);
530 /* Set up the terminal at the other end of a pseudo-terminal that
531 we will be controlling an inferior through.
532 It should not echo or do line-editing, since that is done
533 in Emacs. No padding needed for insertion into an Emacs buffer. */
535 child_setup_tty (out
)
541 EMACS_GET_TTY (out
, &s
);
543 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
544 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
545 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
547 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
548 /* No output delays */
550 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
551 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
553 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
556 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
559 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
561 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
562 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
564 /* Said to be unnecessary: */
565 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
566 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
569 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
570 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
571 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
572 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
575 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
579 /* AIX enhanced edit loses NULs, so disable it */
582 s
.main
.c_iflag
&= ~ASCEDIT
;
584 /* Also, PTY overloads NUL and BREAK.
585 don't ignore break, but don't signal either, so it looks like NUL. */
586 s
.main
.c_iflag
&= ~IGNBRK
;
587 s
.main
.c_iflag
&= ~BRKINT
;
588 /* QUIT and INTR work better as signals, so disable character forms */
589 s
.main
.c_cc
[VINTR
] = 0377;
590 #ifdef SIGNALS_VIA_CHARACTERS
591 /* the QUIT and INTR character are used in process_send_signal
592 so set them here to something useful. */
593 if (s
.main
.c_cc
[VQUIT
] == 0377)
594 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
595 if (s
.main
.c_cc
[VINTR
] == 0377)
596 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
597 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
598 /* QUIT and INTR work better as signals, so disable character forms */
599 s
.main
.c_cc
[VQUIT
] = 0377;
600 s
.main
.c_cc
[VINTR
] = 0377;
601 s
.main
.c_lflag
&= ~ISIG
;
602 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
603 s
.main
.c_cc
[VEOL
] = 0377;
604 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
607 #else /* not HAVE_TERMIO */
609 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
611 s
.main
.sg_flags
|= LPASS8
;
612 s
.main
.sg_erase
= 0377;
613 s
.main
.sg_kill
= 0377;
614 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
616 #endif /* not HAVE_TERMIO */
618 EMACS_SET_TTY (out
, &s
, 0);
627 ioctl (out
, FIOASYNC
, &zero
);
630 #endif /* not DOS_NT */
634 #endif /* subprocesses */
636 /* Record a signal code and the handler for it. */
640 SIGTYPE (*handler
) ();
643 /* Suspend the Emacs process; give terminal to its superior. */
648 /* "Foster" parentage allows emacs to return to a subprocess that attached
649 to the current emacs as a cheaper than starting a whole new process. This
650 is set up by KEPTEDITOR.COM. */
651 unsigned long parent_id
, foster_parent_id
;
654 fpid_string
= getenv ("EMACS_PARENT_PID");
655 if (fpid_string
!= NULL
)
657 sscanf (fpid_string
, "%x", &foster_parent_id
);
658 if (foster_parent_id
!= 0)
659 parent_id
= foster_parent_id
;
661 parent_id
= getppid ();
664 parent_id
= getppid ();
666 xfree (fpid_string
); /* On VMS, this was malloc'd */
668 if (parent_id
&& parent_id
!= 0xffffffff)
670 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
671 int status
= LIB$
ATTACH (&parent_id
) & 1;
672 signal (SIGINT
, oldsig
);
681 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
682 d_prompt
.a
= "Emacs: "; /* Just a reminder */
683 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
688 #if defined(SIGTSTP) && !defined(MSDOS)
691 int pgrp
= EMACS_GETPGRP (0);
692 EMACS_KILLPG (pgrp
, SIGTSTP
);
695 #else /* No SIGTSTP */
696 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
697 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
698 kill (getpid (), SIGQUIT
);
700 #else /* No SIGTSTP or USG_JOBCTRL */
702 /* On a system where suspending is not implemented,
703 instead fork a subshell and let it talk directly to the terminal
707 #endif /* no USG_JOBCTRL */
708 #endif /* no SIGTSTP */
712 /* Fork a subshell. */
717 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
719 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
722 struct save_signal saved_handlers
[5];
724 unsigned char *str
= 0;
727 saved_handlers
[0].code
= SIGINT
;
728 saved_handlers
[1].code
= SIGQUIT
;
729 saved_handlers
[2].code
= SIGTERM
;
731 saved_handlers
[3].code
= SIGIO
;
732 saved_handlers
[4].code
= 0;
734 saved_handlers
[3].code
= 0;
737 /* Mentioning current_buffer->buffer would mean including buffer.h,
738 which somehow wedges the hp compiler. So instead... */
740 dir
= intern ("default-directory");
741 if (NILP (Fboundp (dir
)))
743 dir
= Fsymbol_value (dir
);
747 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
748 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
749 len
= XSTRING (dir
)->size
;
750 bcopy (XSTRING (dir
)->data
, str
, len
);
751 if (str
[len
- 1] != '/') str
[len
++] = '/';
758 save_signal_handlers (saved_handlers
);
759 synch_process_alive
= 1;
760 #endif /* __DJGPP__ > 1 */
764 error ("Can't spawn subshell");
771 #ifdef DOS_NT /* MW, Aug 1993 */
774 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
777 sh
= (char *) egetenv ("SHELL");
781 /* Use our buffer's default directory for the subshell. */
786 close_process_descs (); /* Close Emacs's pipes/ptys */
789 #ifdef SET_EMACS_PRIORITY
791 extern int emacs_priority
;
793 if (emacs_priority
< 0)
794 nice (-emacs_priority
);
798 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
801 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
803 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
805 #else /* not MSDOS */
807 /* Waits for process completion */
808 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
811 write (1, "Can't execute subshell", 22);
812 #else /* not WINDOWSNT */
814 write (1, "Can't execute subshell", 22);
816 #endif /* not WINDOWSNT */
817 #endif /* not MSDOS */
820 /* Do this now if we did not do it before. */
821 #if !defined (MSDOS) || __DJGPP__ == 1
822 save_signal_handlers (saved_handlers
);
823 synch_process_alive
= 1;
827 wait_for_termination (pid
);
829 restore_signal_handlers (saved_handlers
);
830 synch_process_alive
= 0;
834 save_signal_handlers (saved_handlers
)
835 struct save_signal
*saved_handlers
;
837 while (saved_handlers
->code
)
839 saved_handlers
->handler
840 = (SIGTYPE (*) ()) signal (saved_handlers
->code
, SIG_IGN
);
845 restore_signal_handlers (saved_handlers
)
846 struct save_signal
*saved_handlers
;
848 while (saved_handlers
->code
)
850 signal (saved_handlers
->code
, saved_handlers
->handler
);
863 old_fcntl_flags
= fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
864 fcntl (fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
866 interrupts_deferred
= 0;
874 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
878 if (read_socket_hook
)
882 sigunblock (sigmask (SIGWINCH
));
884 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
886 interrupts_deferred
= 0;
891 if (read_socket_hook
)
895 sigblock (sigmask (SIGWINCH
));
897 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
898 interrupts_deferred
= 1;
901 #else /* no FASYNC */
902 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
908 if (read_socket_hook
)
911 ioctl (input_fd
, FIOASYNC
, &on
);
912 interrupts_deferred
= 0;
919 if (read_socket_hook
)
922 ioctl (input_fd
, FIOASYNC
, &off
);
923 interrupts_deferred
= 1;
926 #else /* not FASYNC, not STRIDE */
937 if (read_socket_hook
)
941 sigaddset(&st
, SIGIO
);
942 ioctl (input_fd
, FIOASYNC
, &on
);
943 interrupts_deferred
= 0;
944 sigprocmask(SIG_UNBLOCK
, &st
, (sigset_t
*)0);
951 if (read_socket_hook
)
954 ioctl (input_fd
, FIOASYNC
, &off
);
955 interrupts_deferred
= 1;
962 if (read_socket_hook
)
965 croak ("request_sigio");
970 if (read_socket_hook
)
973 croak ("unrequest_sigio");
981 /* Saving and restoring the process group of Emacs's terminal. */
985 /* The process group of which Emacs was a member when it initially
988 If Emacs was in its own process group (i.e. inherited_pgroup ==
989 getpid ()), then we know we're running under a shell with job
990 control (Emacs would never be run as part of a pipeline).
993 If Emacs was not in its own process group, then we know we're
994 running under a shell (or a caller) that doesn't know how to
995 separate itself from Emacs (like sh). Emacs must be in its own
996 process group in order to receive SIGIO correctly. In this
997 situation, we put ourselves in our own pgroup, forcibly set the
998 tty's pgroup to our pgroup, and make sure to restore and reinstate
999 the tty's pgroup just like any other terminal setting. If
1000 inherited_group was not the tty's pgroup, then we'll get a
1001 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1002 it goes foreground in the future, which is what should happen. */
1003 int inherited_pgroup
;
1005 /* Split off the foreground process group to Emacs alone.
1006 When we are in the foreground, but not started in our own process
1007 group, redirect the TTY to point to our own process group. We need
1008 to be in our own process group to receive SIGIO properly. */
1009 narrow_foreground_group ()
1013 setpgrp (0, inherited_pgroup
);
1014 if (inherited_pgroup
!= me
)
1015 EMACS_SET_TTY_PGRP (input_fd
, &me
);
1019 /* Set the tty to our original foreground group. */
1020 widen_foreground_group ()
1022 if (inherited_pgroup
!= getpid ())
1023 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
1024 setpgrp (0, inherited_pgroup
);
1027 #endif /* BSD_PGRPS */
1029 /* Getting and setting emacs_tty structures. */
1031 /* Set *TC to the parameters associated with the terminal FD.
1032 Return zero if all's well, or -1 if we ran into an error we
1033 couldn't deal with. */
1035 emacs_get_tty (fd
, settings
)
1037 struct emacs_tty
*settings
;
1039 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1041 /* We have those nifty POSIX tcmumbleattr functions. */
1042 if (tcgetattr (fd
, &settings
->main
) < 0)
1047 /* The SYSV-style interface? */
1048 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1053 /* Vehemently Monstrous System? :-) */
1054 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1055 &settings
->main
.class, 12, 0, 0, 0, 0)
1061 /* I give up - I hope you have the BSD ioctls. */
1062 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1064 #endif /* not DOS_NT */
1069 /* Suivant - Do we have to get struct ltchars data? */
1071 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1075 /* How about a struct tchars and a wordful of lmode bits? */
1077 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1078 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1082 /* We have survived the tempest. */
1087 /* Set the parameters of the tty on FD according to the contents of
1088 *SETTINGS. If FLUSHP is non-zero, we discard input.
1089 Return 0 if all went well, and -1 if anything failed. */
1092 emacs_set_tty (fd
, settings
, flushp
)
1094 struct emacs_tty
*settings
;
1097 /* Set the primary parameters - baud rate, character size, etcetera. */
1100 /* We have those nifty POSIX tcmumbleattr functions.
1101 William J. Smith <wjs@wiis.wang.com> writes:
1102 "POSIX 1003.1 defines tcsetattr() to return success if it was
1103 able to perform any of the requested actions, even if some
1104 of the requested actions could not be performed.
1105 We must read settings back to ensure tty setup properly.
1106 AIX requires this to keep tty from hanging occasionally." */
1107 /* This make sure that we don't loop indefinitely in here. */
1108 for (i
= 0 ; i
< 10 ; i
++)
1109 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1120 /* Get the current settings, and see if they're what we asked for. */
1121 tcgetattr (fd
, &new);
1122 /* We cannot use memcmp on the whole structure here because under
1123 * aix386 the termios structure has some reserved field that may
1126 if ( new.c_iflag
== settings
->main
.c_iflag
1127 && new.c_oflag
== settings
->main
.c_oflag
1128 && new.c_cflag
== settings
->main
.c_cflag
1129 && new.c_lflag
== settings
->main
.c_lflag
1130 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1138 /* The SYSV-style interface? */
1139 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1144 /* Vehemently Monstrous System? :-) */
1145 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1146 &settings
->main
.class, 12, 0, 0, 0, 0)
1152 /* I give up - I hope you have the BSD ioctls. */
1153 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1155 #endif /* not DOS_NT */
1161 /* Suivant - Do we have to get struct ltchars data? */
1163 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1167 /* How about a struct tchars and a wordful of lmode bits? */
1169 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1170 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1174 /* We have survived the tempest. */
1179 /* The initial tty mode bits */
1180 struct emacs_tty old_tty
;
1182 /* 1 if we have been through init_sys_modes. */
1185 /* 1 if outer tty status has been recorded. */
1189 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1194 #ifndef F_SETOWN_BUG
1196 int old_fcntl_owner
;
1197 #endif /* F_SETOWN */
1198 #endif /* F_SETOWN_BUG */
1200 /* This may also be defined in stdio,
1201 but if so, this does no harm,
1202 and using the same name avoids wasting the other one's space. */
1204 #if defined (USG) || defined (DGUX)
1205 unsigned char _sobuf
[BUFSIZ
+8];
1207 char _sobuf
[BUFSIZ
];
1211 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1214 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1219 struct emacs_tty tty
;
1223 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1224 extern int (*interrupt_signal
) ();
1228 Vtty_erase_char
= Qnil
;
1235 input_ef
= get_kbd_event_flag ();
1236 /* LIB$GET_EF (&input_ef); */
1237 SYS$
CLREF (input_ef
);
1238 waiting_for_ast
= 0;
1240 timer_ef
= get_timer_event_flag ();
1241 /* LIB$GET_EF (&timer_ef); */
1242 SYS$
CLREF (timer_ef
);
1246 LIB$
GET_EF (&process_ef
);
1247 SYS$
CLREF (process_ef
);
1249 if (input_ef
/ 32 != process_ef
/ 32)
1250 croak ("Input and process event flags in different clusters.");
1252 if (input_ef
/ 32 != timer_ef
/ 32)
1253 croak ("Input and timer event flags in different clusters.");
1255 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1256 ((unsigned) 1 << (process_ef
% 32));
1258 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1259 ((unsigned) 1 << (timer_ef
% 32));
1261 sys_access_reinit ();
1263 #endif /* not VMS */
1266 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1267 narrow_foreground_group ();
1270 #ifdef HAVE_WINDOW_SYSTEM
1271 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1272 needs the initialization code below. */
1273 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1276 EMACS_GET_TTY (input_fd
, &old_tty
);
1282 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1283 XSETINT (Vtty_erase_char
, old_tty
.main
.c_cc
[VERASE
]);
1286 /* This allows meta to be sent on 8th bit. */
1287 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1289 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1290 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1291 #ifdef INLCR /* I'm just being cautious,
1292 since I can't check how widespread INLCR is--rms. */
1293 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1296 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1298 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1299 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1301 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1303 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1306 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1308 tty
.main
.c_iflag
&= ~IXANY
;
1312 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1313 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1315 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1319 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1320 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1323 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1324 /* Set up C-g for both SIGQUIT and SIGINT.
1325 We don't know which we will get, but we handle both alike
1326 so which one it really gives us does not matter. */
1327 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1328 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1329 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1331 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1335 #if defined (mips) || defined (HAVE_TCATTR)
1337 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1340 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1341 #endif /* V_DSUSP */
1342 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1343 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1346 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1349 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1350 #endif /* VREPRINT */
1352 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1353 #endif /* VWERASE */
1355 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1356 #endif /* VDISCARD */
1361 tty
.main
.c_cc
[VSTART
] = '\021';
1364 tty
.main
.c_cc
[VSTOP
] = '\023';
1370 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1373 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1376 #endif /* mips or HAVE_TCATTR */
1378 #ifdef SET_LINE_DISCIPLINE
1379 /* Need to explicitly request TERMIODISC line discipline or
1380 Ultrix's termios does not work correctly. */
1381 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1385 /* AIX enhanced edit loses NULs, so disable it. */
1386 tty
.main
.c_line
= 0;
1387 tty
.main
.c_iflag
&= ~ASCEDIT
;
1389 tty
.main
.c_cc
[VSTRT
] = 255;
1390 tty
.main
.c_cc
[VSTOP
] = 255;
1391 tty
.main
.c_cc
[VSUSP
] = 255;
1392 tty
.main
.c_cc
[VDSUSP
] = 255;
1393 #endif /* IBMR2AIX */
1397 tty
.main
.c_cc
[VSTART
] = '\021';
1400 tty
.main
.c_cc
[VSTOP
] = '\023';
1403 /* Also, PTY overloads NUL and BREAK.
1404 don't ignore break, but don't signal either, so it looks like NUL.
1405 This really serves a purpose only if running in an XTERM window
1406 or via TELNET or the like, but does no harm elsewhere. */
1407 tty
.main
.c_iflag
&= ~IGNBRK
;
1408 tty
.main
.c_iflag
&= ~BRKINT
;
1410 #else /* if not HAVE_TERMIO */
1412 tty
.main
.tt_char
|= TT$M_NOECHO
;
1414 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1416 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1418 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1419 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1420 #else /* not VMS (BSD, that is) */
1422 Vtty_erase_char
= tty
.main
.sg_erase
;
1423 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1425 tty
.main
.sg_flags
|= ANYP
;
1426 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1427 #endif /* not DOS_NT */
1428 #endif /* not VMS (BSD, that is) */
1429 #endif /* not HAVE_TERMIO */
1431 /* If going to use CBREAK mode, we must request C-g to interrupt
1432 and turn off start and stop chars, etc. If not going to use
1433 CBREAK mode, do this anyway so as to turn off local flow
1434 control for user coming over network on 4.2; in this case,
1435 only t_stopc and t_startc really matter. */
1438 /* Note: if not using CBREAK mode, it makes no difference how we
1440 tty
.tchars
= new_tchars
;
1441 tty
.tchars
.t_intrc
= quit_char
;
1444 tty
.tchars
.t_startc
= '\021';
1445 tty
.tchars
.t_stopc
= '\023';
1448 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1450 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1451 anything, and leaving it in breaks the meta key. Go figure. */
1452 tty
.lmode
&= ~LLITOUT
;
1459 #endif /* HAVE_TCHARS */
1460 #endif /* not HAVE_TERMIO */
1463 tty
.ltchars
= new_ltchars
;
1464 #endif /* HAVE_LTCHARS */
1465 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1467 internal_terminal_init ();
1471 EMACS_SET_TTY (input_fd
, &tty
, 0);
1473 /* This code added to insure that, if flow-control is not to be used,
1474 we have an unlocked terminal at the start. */
1477 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1481 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1485 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1487 if (!flow_control
) tcflow (input_fd
, TCOON
);
1495 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1496 to be only LF. This is the way that is done. */
1499 if (ioctl (1, HFTGETID
, &tty
) != -1)
1500 write (1, "\033[20l", 5);
1506 /* Appears to do nothing when in PASTHRU mode.
1507 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1508 interrupt_signal, oob_chars, 0, 0, 0, 0);
1510 queue_kbd_input (0);
1515 #ifndef F_SETOWN_BUG
1516 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1518 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1520 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1521 fcntl (input_fd
, F_SETOWN
, getpid ());
1522 init_sigio (input_fd
);
1524 #endif /* F_GETOWN */
1525 #endif /* F_SETOWN_BUG */
1526 #endif /* F_SETFL */
1529 if (interrupt_input
)
1530 init_sigio (input_fd
);
1533 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1537 /* This symbol is defined on recent USG systems.
1538 Someone says without this call USG won't really buffer the file
1539 even with a call to setbuf. */
1540 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
1542 setbuf (stdout
, _sobuf
);
1544 #ifdef HAVE_WINDOW_SYSTEM
1545 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1546 needs the initialization code below. */
1547 if (EQ (Vwindow_system
, Qnil
)
1549 /* When running in tty mode on NT/Win95, we have a read_socket
1550 hook, but still need the rest of the initialization code below. */
1551 && (! read_socket_hook
)
1555 set_terminal_modes ();
1557 if (term_initted
&& no_redraw_on_reenter
)
1559 if (display_completed
)
1560 direct_output_forward_char (0);
1565 if (FRAMEP (Vterminal_frame
))
1566 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1572 /* Return nonzero if safe to use tabs in output.
1573 At the time this is called, init_sys_modes has not been done yet. */
1577 struct emacs_tty tty
;
1579 EMACS_GET_TTY (input_fd
, &tty
);
1580 return EMACS_TTY_TABS_OK (&tty
);
1583 /* Get terminal size from system.
1584 Store number of lines into *HEIGHTP and width into *WIDTHP.
1585 We store 0 if there's no valid information. */
1587 get_frame_size (widthp
, heightp
)
1588 int *widthp
, *heightp
;
1594 struct winsize size
;
1596 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1597 *widthp
= *heightp
= 0;
1600 *widthp
= size
.ws_col
;
1601 *heightp
= size
.ws_row
;
1607 /* SunOS - style. */
1608 struct ttysize size
;
1610 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1611 *widthp
= *heightp
= 0;
1614 *widthp
= size
.ts_cols
;
1615 *heightp
= size
.ts_lines
;
1621 struct sensemode tty
;
1623 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1624 &tty
.class, 12, 0, 0, 0, 0);
1625 *widthp
= tty
.scr_wid
;
1626 *heightp
= tty
.scr_len
;
1630 *widthp
= ScreenCols ();
1631 *heightp
= ScreenRows ();
1632 #else /* system doesn't know size */
1637 #endif /* not VMS */
1638 #endif /* not SunOS-style */
1639 #endif /* not BSD-style */
1642 /* Set the logical window size associated with descriptor FD
1643 to HEIGHT and WIDTH. This is used mainly with ptys. */
1646 set_window_size (fd
, height
, width
)
1647 int fd
, height
, width
;
1652 struct winsize size
;
1653 size
.ws_row
= height
;
1654 size
.ws_col
= width
;
1656 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1657 return 0; /* error */
1664 /* SunOS - style. */
1665 struct ttysize size
;
1666 size
.ts_lines
= height
;
1667 size
.ts_cols
= width
;
1669 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1675 #endif /* not SunOS-style */
1676 #endif /* not BSD-style */
1680 /* Prepare the terminal for exiting Emacs; move the cursor to the
1681 bottom of the frame, turn off interrupt-driven I/O, etc. */
1691 #ifdef HAVE_WINDOW_SYSTEM
1692 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1693 needs the clean-up code below. */
1694 if (!EQ (Vwindow_system
, Qnil
)
1696 /* When running in tty mode on NT/Win95, we have a read_socket
1697 hook, but still need the rest of the clean-up code below. */
1703 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1704 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1705 /* clear_end_of_line may move the cursor */
1706 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1707 #if defined (IBMR2AIX) && defined (AIXHFT)
1709 /* HFT devices normally use ^J as a LF/CR. We forced it to
1710 do the LF only. Now, we need to reset it. */
1713 if (ioctl (1, HFTGETID
, &tty
) != -1)
1714 write (1, "\033[20h", 5);
1718 reset_terminal_modes ();
1722 /* Avoid possible loss of output when changing terminal modes. */
1723 fsync (fileno (stdout
));
1728 #ifndef F_SETOWN_BUG
1729 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1730 if (interrupt_input
)
1733 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1735 #endif /* F_SETOWN */
1736 #endif /* F_SETOWN_BUG */
1738 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1740 #endif /* F_SETFL */
1742 if (interrupt_input
)
1747 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1750 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1754 #ifdef SET_LINE_DISCIPLINE
1755 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1756 A different old line discipline is therefore not restored, yet.
1757 Restore the old line discipline by hand. */
1758 ioctl (0, TIOCSETD
, &old_tty
.main
.c_line
);
1766 widen_foreground_group ();
1772 /* Set up the proper status flags for use of a pty. */
1777 /* I'm told that TOICREMOTE does not mean control chars
1778 "can't be sent" but rather that they don't have
1779 input-editing or signaling effects.
1780 That should be good, because we have other ways
1781 to do those things in Emacs.
1782 However, telnet mode seems not to work on 4.2.
1783 So TIOCREMOTE is turned off now. */
1785 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1786 will hang. In particular, the "timeout" feature (which
1787 causes a read to return if there is no data available)
1788 does this. Also it is known that telnet mode will hang
1789 in such a way that Emacs must be stopped (perhaps this
1790 is the same problem).
1792 If TIOCREMOTE is turned off, then there is a bug in
1793 hp-ux which sometimes loses data. Apparently the
1794 code which blocks the master process when the internal
1795 buffer fills up does not work. Other than this,
1796 though, everything else seems to work fine.
1798 Since the latter lossage is more benign, we may as well
1799 lose that way. -- cph */
1804 ioctl (fd
, FIONBIO
, &on
);
1809 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1810 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1811 /* cause EMACS not to die when it should, i.e., when its own controlling */
1812 /* tty goes away. I've complained to the AIX developers, and they may */
1813 /* change this behavior, but I'm not going to hold my breath. */
1814 signal (SIGHUP
, SIG_IGN
);
1817 #endif /* HAVE_PTYS */
1821 /* Assigning an input channel is done at the start of Emacs execution.
1822 This is called each time Emacs is resumed, also, but does nothing
1823 because input_chain is no longer zero. */
1831 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1837 /* Deassigning the input channel is done before exiting. */
1841 return SYS$
DASSGN (input_fd
);
1846 /* Request reading one character into the keyboard buffer.
1847 This is done as soon as the buffer becomes empty. */
1852 extern kbd_input_ast ();
1854 waiting_for_ast
= 0;
1856 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1857 &input_iosb
, kbd_input_ast
, 1,
1858 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1863 /* Ast routine that is called when keyboard input comes in
1864 in accord with the SYS$QIO above. */
1868 register int c
= -1;
1869 int old_errno
= errno
;
1870 extern EMACS_TIME
*input_available_clear_time
;
1872 if (waiting_for_ast
)
1873 SYS$
SETEF (input_ef
);
1874 waiting_for_ast
= 0;
1877 if (input_count
== 25)
1879 printf ("Ast # %d,", input_count
);
1880 printf (" iosb = %x, %x, %x, %x",
1881 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1884 if (input_iosb
.offset
)
1888 printf (", char = 0%o", c
);
1900 struct input_event e
;
1901 e
.kind
= ascii_keystroke
;
1902 XSETINT (e
.code
, c
);
1903 XSETFRAME (e
.frame_or_window
, selected_frame
);
1904 kbd_buffer_store_event (&e
);
1906 if (input_available_clear_time
)
1907 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1911 /* Wait until there is something in kbd_buffer. */
1913 wait_for_kbd_input ()
1915 extern int have_process_input
, process_exited
;
1917 /* If already something, avoid doing system calls. */
1918 if (detect_input_pending ())
1922 /* Clear a flag, and tell ast routine above to set it. */
1923 SYS$
CLREF (input_ef
);
1924 waiting_for_ast
= 1;
1925 /* Check for timing error: ast happened while we were doing that. */
1926 if (!detect_input_pending ())
1928 /* No timing error: wait for flag to be set. */
1929 set_waiting_for_input (0);
1930 SYS$
WFLOR (input_ef
, input_eflist
);
1931 clear_waiting_for_input (0);
1932 if (!detect_input_pending ())
1933 /* Check for subprocess input availability */
1935 int dsp
= have_process_input
|| process_exited
;
1937 SYS$
CLREF (process_ef
);
1938 if (have_process_input
)
1939 process_command_input ();
1944 update_mode_lines
++;
1945 prepare_menu_bars ();
1946 redisplay_preserve_echo_area ();
1950 waiting_for_ast
= 0;
1953 /* Get rid of any pending QIO, when we are about to suspend
1954 or when we want to throw away pending input.
1955 We wait for a positive sign that the AST routine has run
1956 and therefore there is no I/O request queued when we return.
1957 SYS$SETAST is used to avoid a timing error. */
1962 printf ("At end_kbd_input.\n");
1966 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
1968 SYS$
CANCEL (input_fd
);
1973 /* Clear a flag, and tell ast routine above to set it. */
1974 SYS$
CLREF (input_ef
);
1975 waiting_for_ast
= 1;
1977 SYS$
CANCEL (input_fd
);
1979 SYS$
WAITFR (input_ef
);
1980 waiting_for_ast
= 0;
1983 /* Wait for either input available or time interval expiry. */
1985 input_wait_timeout (timeval
)
1986 int timeval
; /* Time to wait, in seconds */
1989 static int zero
= 0;
1990 static int large
= -10000000;
1992 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1994 /* If already something, avoid doing system calls. */
1995 if (detect_input_pending ())
1999 /* Clear a flag, and tell ast routine above to set it. */
2000 SYS$
CLREF (input_ef
);
2001 waiting_for_ast
= 1;
2002 /* Check for timing error: ast happened while we were doing that. */
2003 if (!detect_input_pending ())
2005 /* No timing error: wait for flag to be set. */
2007 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2008 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
2010 waiting_for_ast
= 0;
2013 /* The standard `sleep' routine works some other way
2014 and it stops working if you have ever quit out of it.
2015 This one continues to work. */
2021 static int zero
= 0;
2022 static int large
= -10000000;
2024 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2027 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2028 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2044 croak ("request sigio");
2049 croak ("unrequest sigio");
2054 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2059 #ifndef SYSTEM_MALLOC
2066 /* Some systems that cannot dump also cannot implement these. */
2069 * Return the address of the start of the text segment prior to
2070 * doing an unexec. After unexec the return value is undefined.
2071 * See crt0.c for further explanation and _start.
2075 #ifndef HAVE_TEXT_START
2080 return ((char *) TEXT_START
);
2084 return ((char *) csrt
);
2085 #else /* not GOULD */
2086 extern int _start ();
2087 return ((char *) _start
);
2089 #endif /* TEXT_START */
2091 #endif /* not HAVE_TEXT_START */
2094 * Return the address of the start of the data segment prior to
2095 * doing an unexec. After unexec the return value is undefined.
2096 * See crt0.c for further information and definition of data_start.
2098 * Apparently, on BSD systems this is etext at startup. On
2099 * USG systems (swapping) this is highly mmu dependent and
2100 * is also dependent on whether or not the program is running
2101 * with shared text. Generally there is a (possibly large)
2102 * gap between end of text and start of data with shared text.
2104 * On Uniplus+ systems with shared text, data starts at a
2105 * fixed address. Each port (from a given oem) is generally
2106 * different, and the specific value of the start of data can
2107 * be obtained via the UniPlus+ specific "uvar" system call,
2108 * however the method outlined in crt0.c seems to be more portable.
2110 * Probably what will have to happen when a USG unexec is available,
2111 * at least on UniPlus, is temacs will have to be made unshared so
2112 * that text and data are contiguous. Then once loadup is complete,
2113 * unexec will produce a shared executable where the data can be
2114 * at the normal shared text boundary and the startofdata variable
2115 * will be patched by unexec to the correct value.
2123 return ((char *) DATA_START
);
2125 #ifdef ORDINARY_LINK
2127 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2128 * data_start isn't defined. We take the address of environ, which
2129 * is known to live at or near the start of the system crt0.c, and
2130 * we don't sweat the handful of bytes that might lose.
2132 extern char **environ
;
2134 return((char *) &environ
);
2136 extern int data_start
;
2137 return ((char *) &data_start
);
2138 #endif /* ORDINARY_LINK */
2139 #endif /* DATA_START */
2141 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2144 /* Some systems that cannot dump also cannot implement these. */
2147 * Return the address of the end of the text segment prior to
2148 * doing an unexec. After unexec the return value is undefined.
2155 return ((char *) TEXT_END
);
2158 return ((char *) &etext
);
2163 * Return the address of the end of the data segment prior to
2164 * doing an unexec. After unexec the return value is undefined.
2171 return ((char *) DATA_END
);
2174 return ((char *) &edata
);
2178 #endif /* not CANNOT_DUMP */
2180 /* init_system_name sets up the string for the Lisp function
2181 system-name to return. */
2187 extern Lisp_Object Vsystem_name
;
2192 #include <sys/socket.h>
2194 #endif /* HAVE_SOCKETS */
2195 #endif /* not VMS */
2196 #endif /* not BSD4_1 */
2202 Vsystem_name
= build_string (sysname
);
2206 if ((sp
= egetenv ("SYS$NODE")) == 0)
2207 Vsystem_name
= build_string ("vax-vms");
2208 else if ((end
= index (sp
, ':')) == 0)
2209 Vsystem_name
= build_string (sp
);
2211 Vsystem_name
= make_string (sp
, end
- sp
);
2213 #ifndef HAVE_GETHOSTNAME
2216 Vsystem_name
= build_string (uts
.nodename
);
2217 #else /* HAVE_GETHOSTNAME */
2218 unsigned int hostname_size
= 256;
2219 char *hostname
= (char *) alloca (hostname_size
);
2221 /* Try to get the host name; if the buffer is too short, try
2222 again. Apparently, the only indication gethostname gives of
2223 whether the buffer was large enough is the presence or absence
2224 of a '\0' in the string. Eech. */
2227 gethostname (hostname
, hostname_size
- 1);
2228 hostname
[hostname_size
- 1] = '\0';
2230 /* Was the buffer large enough for the '\0'? */
2231 if (strlen (hostname
) < hostname_size
- 1)
2234 hostname_size
<<= 1;
2235 hostname
= (char *) alloca (hostname_size
);
2238 /* Turn the hostname into the official, fully-qualified hostname.
2239 Don't do this if we're going to dump; this can confuse system
2240 libraries on some machines and make the dumped emacs core dump. */
2243 #endif /* not CANNOT_DUMP */
2247 for (count
= 0;; count
++)
2252 hp
= gethostbyname (hostname
);
2254 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2259 Fsleep_for (make_number (1), Qnil
);
2263 char *fqdn
= (char *) hp
->h_name
;
2266 if (!index (fqdn
, '.'))
2268 /* We still don't have a fully qualified domain name.
2269 Try to find one in the list of alternate names */
2270 char **alias
= hp
->h_aliases
;
2271 while (*alias
&& !index (*alias
, '.'))
2278 /* Convert the host name to lower case. */
2279 /* Using ctype.h here would introduce a possible locale
2280 dependence that is probably wrong for hostnames. */
2284 if (*p
>= 'A' && *p
<= 'Z')
2291 #endif /* HAVE_SOCKETS */
2292 /* We used to try using getdomainname as an alternative
2293 to sysinfo, here, but NIIBE Yutaka <gniibe@etl.go.jp> says that
2294 getdomainname gets the NIS/YP domain which often is not the same
2295 as in Internet domain name. */
2296 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2297 if (! index (hostname
, '.'))
2299 /* The hostname is not fully qualified. Append the domain name. */
2301 int hostlen
= strlen (hostname
);
2302 int domain_size
= 256;
2306 char *domain
= (char *) alloca (domain_size
+ 1);
2307 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2308 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2309 if (sys_domain_size
<= 0)
2311 if (domain_size
< sys_domain_size
)
2313 domain_size
= sys_domain_size
;
2316 strcpy (fqdn
, hostname
);
2317 if (domain
[0] == '.')
2318 strcpy (fqdn
+ hostlen
, domain
);
2319 else if (domain
[0] != 0)
2321 fqdn
[hostlen
] = '.';
2322 strcpy (fqdn
+ hostlen
+ 1, domain
);
2328 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2329 Vsystem_name
= build_string (hostname
);
2330 #endif /* HAVE_GETHOSTNAME */
2335 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2336 if (*p
== ' ' || *p
== '\t')
2343 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2345 #include "sysselect.h"
2348 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2349 /* Cause explanatory error message at compile time,
2350 since the select emulation is not good enough for X. */
2351 int *x
= &x_windows_lose_if_no_select_system_call
;
2354 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2355 * Only checks read descriptors.
2357 /* How long to wait between checking fds in select */
2358 #define SELECT_PAUSE 1
2361 /* For longjmp'ing back to read_input_waiting. */
2363 jmp_buf read_alarm_throw
;
2365 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2366 The read_socket_hook function sets this to 1 while it is waiting. */
2368 int read_alarm_should_throw
;
2376 #else /* not BSD4_1 */
2377 signal (SIGALRM
, SIG_IGN
);
2378 #endif /* not BSD4_1 */
2379 if (read_alarm_should_throw
)
2380 longjmp (read_alarm_throw
, 1);
2384 /* Only rfds are checked. */
2386 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2388 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2389 EMACS_TIME
*timeout
;
2391 int ravail
= 0, old_alarm
;
2395 extern int proc_buffered_char
[];
2396 #ifndef subprocesses
2397 int process_tick
= 0, update_tick
= 0;
2399 extern int process_tick
, update_tick
;
2401 SIGTYPE (*old_trap
) ();
2404 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2405 /* If we're using X, then the native select will work; we only need the
2406 emulation for non-X usage. */
2407 if (!NILP (Vwindow_system
))
2408 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2410 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2411 local_timeout
= &timeoutval
;
2423 /* If we are looking only for the terminal, with no timeout,
2424 just read it and wait -- that's more efficient. */
2425 if (*local_timeout
== 100000 && process_tick
== update_tick
2426 && FD_ISSET (0, &orfds
))
2429 for (fd
= 1; fd
< nfds
; ++fd
)
2430 if (FD_ISSET (fd
, &orfds
))
2432 if (! detect_input_pending ())
2433 read_input_waiting ();
2439 /* Once a second, till the timer expires, check all the flagged read
2440 * descriptors to see if any input is available. If there is some then
2441 * set the corresponding bit in the return copy of rfds.
2445 register int to_check
, fd
;
2449 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2451 if (FD_ISSET (fd
, &orfds
))
2453 int avail
= 0, status
= 0;
2456 avail
= detect_input_pending (); /* Special keyboard handler */
2460 status
= ioctl (fd
, FIONREAD
, &avail
);
2461 #else /* no FIONREAD */
2462 /* Hoping it will return -1 if nothing available
2463 or 0 if all 0 chars requested are read. */
2464 if (proc_buffered_char
[fd
] >= 0)
2468 avail
= read (fd
, &buf
, 1);
2470 proc_buffered_char
[fd
] = buf
;
2472 #endif /* no FIONREAD */
2474 if (status
>= 0 && avail
> 0)
2482 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2484 old_alarm
= alarm (0);
2485 old_trap
= signal (SIGALRM
, select_alarm
);
2487 alarm (SELECT_PAUSE
);
2488 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2489 while (select_alarmed
== 0 && *local_timeout
!= 0
2490 && process_tick
== update_tick
)
2492 /* If we are interested in terminal input,
2493 wait by reading the terminal.
2494 That makes instant wakeup for terminal input at least. */
2495 if (FD_ISSET (0, &orfds
))
2497 read_input_waiting ();
2498 if (detect_input_pending ())
2504 (*local_timeout
) -= SELECT_PAUSE
;
2505 /* Reset the old alarm if there was one */
2507 signal (SIGALRM
, old_trap
);
2510 /* Reset or forge an interrupt for the original handler. */
2511 old_alarm
-= SELECT_PAUSE
;
2513 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2517 if (*local_timeout
== 0) /* Stop on timer being cleared */
2522 #endif /* not WINDOWSNT */
2524 /* Read keyboard input into the standard buffer,
2525 waiting for at least one character. */
2527 /* Make all keyboard buffers much bigger when using a window system. */
2528 #ifdef HAVE_WINDOW_SYSTEM
2529 #define BUFFER_SIZE_FACTOR 16
2531 #define BUFFER_SIZE_FACTOR 1
2534 read_input_waiting ()
2536 struct input_event e
;
2538 extern int quit_char
;
2540 if (read_socket_hook
)
2542 struct input_event buf
[256];
2544 read_alarm_should_throw
= 0;
2545 if (! setjmp (read_alarm_throw
))
2546 nread
= (*read_socket_hook
) (0, buf
, 256, 1, 0);
2550 /* Scan the chars for C-g and store them in kbd_buffer. */
2551 for (i
= 0; i
< nread
; i
++)
2553 kbd_buffer_store_event (&buf
[i
]);
2554 /* Don't look at input that follows a C-g too closely.
2555 This reduces lossage due to autorepeat on C-g. */
2556 if (buf
[i
].kind
== ascii_keystroke
2557 && buf
[i
].code
== quit_char
)
2564 nread
= read (fileno (stdin
), buf
, 1);
2566 /* Scan the chars for C-g and store them in kbd_buffer. */
2567 e
.kind
= ascii_keystroke
;
2568 XSETFRAME (e
.frame_or_window
, selected_frame
);
2570 for (i
= 0; i
< nread
; i
++)
2572 /* Convert chars > 0177 to meta events if desired.
2573 We do this under the same conditions that read_avail_input does. */
2574 if (read_socket_hook
== 0)
2576 /* If the user says she has a meta key, then believe her. */
2577 if (meta_key
== 1 && (buf
[i
] & 0x80))
2578 e
.modifiers
= meta_modifier
;
2583 XSETINT (e
.code
, buf
[i
]);
2584 kbd_buffer_store_event (&e
);
2585 /* Don't look at input that follows a C-g too closely.
2586 This reduces lossage due to autorepeat on C-g. */
2587 if (buf
[i
] == quit_char
)
2593 #endif /* not HAVE_SELECT */
2594 #endif /* not VMS */
2595 #endif /* not MSDOS */
2599 * Partially emulate 4.2 open call.
2600 * open is defined as this in 4.1.
2602 * - added by Michael Bloom @ Citicorp/TTI
2607 sys_open (path
, oflag
, mode
)
2611 if (oflag
& O_CREAT
)
2612 return creat (path
, mode
);
2614 return open (path
, oflag
);
2622 lmode
= LINTRUP
| lmode
;
2623 ioctl (fd
, TIOCLSET
, &lmode
);
2630 lmode
= ~LINTRUP
& lmode
;
2631 ioctl (0, TIOCLSET
, &lmode
);
2638 interrupts_deferred
= 0;
2645 interrupts_deferred
= 1;
2648 /* still inside #ifdef BSD4_1 */
2651 int sigheld
; /* Mask of held signals */
2656 sigheld
|= sigbit (signum
);
2663 sigheld
|= sigbit (signum
);
2669 sigheld
&= ~sigbit (signum
);
2673 sigfree () /* Free all held signals */
2676 for (i
= 0; i
< NSIG
; i
++)
2677 if (sigheld
& sigbit (i
))
2684 return 1 << (i
- 1);
2686 #endif /* subprocesses */
2689 /* POSIX signals support - DJB */
2690 /* Anyone with POSIX signals should have ANSI C declarations */
2692 #ifdef POSIX_SIGNALS
2694 sigset_t old_mask
, empty_mask
, full_mask
, temp_mask
;
2695 static struct sigaction new_action
, old_action
;
2699 sigemptyset (&empty_mask
);
2700 sigfillset (&full_mask
);
2704 sys_signal (int signal_number
, signal_handler_t action
)
2706 sigemptyset (&new_action
.sa_mask
);
2707 new_action
.sa_handler
= action
;
2709 /* Emacs mostly works better with restartable system services. If this
2710 * flag exists, we probably want to turn it on here.
2712 new_action
.sa_flags
= SA_RESTART
;
2714 new_action
.sa_flags
= 0;
2716 sigaction (signal_number
, &new_action
, &old_action
);
2717 return (old_action
.sa_handler
);
2721 /* If we're compiling with GCC, we don't need this function, since it
2722 can be written as a macro. */
2724 sys_sigmask (int sig
)
2727 sigemptyset (&mask
);
2728 sigaddset (&mask
, sig
);
2734 sys_sigpause (sigset_t new_mask
)
2736 /* pause emulating berk sigpause... */
2737 sigsuspend (&new_mask
);
2741 /* I'd like to have these guys return pointers to the mask storage in here,
2742 but there'd be trouble if the code was saving multiple masks. I'll be
2743 safe and pass the structure. It normally won't be more than 2 bytes
2747 sys_sigblock (sigset_t new_mask
)
2750 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2755 sys_sigunblock (sigset_t new_mask
)
2758 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2763 sys_sigsetmask (sigset_t new_mask
)
2766 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2770 #endif /* POSIX_SIGNALS */
2778 /* Figure out how many bits the system's random number generator uses.
2779 `random' and `lrand48' are assumed to return 31 usable bits.
2780 BSD `rand' returns a 31 bit value but the low order bits are unusable;
2781 so we'll shift it and treat it like the 15-bit USG `rand'. */
2785 # define RAND_BITS 31
2786 # else /* !HAVE_RANDOM */
2787 # ifdef HAVE_LRAND48
2788 # define RAND_BITS 31
2789 # define random lrand48
2790 # else /* !HAVE_LRAND48 */
2791 # define RAND_BITS 15
2792 # if RAND_MAX == 32767
2793 # define random rand
2794 # else /* RAND_MAX != 32767 */
2795 # if RAND_MAX == 2147483647
2796 # define random() (rand () >> 16)
2797 # else /* RAND_MAX != 2147483647 */
2799 # define random rand
2801 # define random() (rand () >> 16)
2803 # endif /* RAND_MAX != 2147483647 */
2804 # endif /* RAND_MAX != 32767 */
2805 # endif /* !HAVE_LRAND48 */
2806 # endif /* !HAVE_RANDOM */
2807 #endif /* !RAND_BITS */
2814 srandom ((unsigned int)arg
);
2816 # ifdef HAVE_LRAND48
2819 srand ((unsigned int)arg
);
2825 * Build a full Emacs-sized word out of whatever we've got.
2826 * This suffices even for a 64-bit architecture with a 15-bit rand.
2831 long val
= random ();
2832 #if VALBITS > RAND_BITS
2833 val
= (val
<< RAND_BITS
) ^ random ();
2834 #if VALBITS > 2*RAND_BITS
2835 val
= (val
<< RAND_BITS
) ^ random ();
2836 #if VALBITS > 3*RAND_BITS
2837 val
= (val
<< RAND_BITS
) ^ random ();
2838 #if VALBITS > 4*RAND_BITS
2839 val
= (val
<< RAND_BITS
) ^ random ();
2840 #endif /* need at least 5 */
2841 #endif /* need at least 4 */
2842 #endif /* need at least 3 */
2843 #endif /* need at least 2 */
2844 return val
& ((1L << VALBITS
) - 1);
2847 #ifdef WRONG_NAME_INSQUE
2860 /* If any place else asks for the TERM variable,
2861 allow it to be overridden with the EMACS_TERM variable
2862 before attempting to translate the logical name TERM. As a last
2863 resort, ask for VAX C's special idea of the TERM variable. */
2870 static char buf
[256];
2871 static struct dsc$descriptor_s equiv
2872 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2873 static struct dsc$descriptor_s d_name
2874 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2877 if (!strcmp (name
, "TERM"))
2879 val
= (char *) getenv ("EMACS_TERM");
2884 d_name
.dsc$w_length
= strlen (name
);
2885 d_name
.dsc$a_pointer
= name
;
2886 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2888 char *str
= (char *) xmalloc (eqlen
+ 1);
2889 bcopy (buf
, str
, eqlen
);
2891 /* This is a storage leak, but a pain to fix. With luck,
2892 no one will ever notice. */
2895 return (char *) getenv (name
);
2900 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2901 to force a call on the debugger from within the image. */
2906 LIB$
SIGNAL (SS$_DEBUG
);
2912 #ifdef LINK_CRTL_SHARE
2913 #ifdef SHARABLE_LIB_BUG
2914 /* Variables declared noshare and initialized in sharable libraries
2915 cannot be shared. The VMS linker incorrectly forces you to use a private
2916 version which is uninitialized... If not for this "feature", we
2917 could use the C library definition of sys_nerr and sys_errlist. */
2919 char *sys_errlist
[] =
2923 "no such file or directory",
2925 "interrupted system call",
2927 "no such device or address",
2928 "argument list too long",
2929 "exec format error",
2932 "no more processes",
2933 "not enough memory",
2934 "permission denied",
2936 "block device required",
2937 "mount devices busy",
2939 "cross-device link",
2944 "file table overflow",
2945 "too many open files",
2949 "no space left on device",
2951 "read-only file system",
2957 "vax/vms specific error code nontranslatable error"
2959 #endif /* SHARABLE_LIB_BUG */
2960 #endif /* LINK_CRTL_SHARE */
2963 #ifndef HAVE_STRERROR
2969 extern char *sys_errlist
[];
2970 extern int sys_nerr
;
2972 if (errnum
>= 0 && errnum
< sys_nerr
)
2973 return sys_errlist
[errnum
];
2974 return (char *) "Unknown error";
2976 #endif /* not WINDOWSNT */
2977 #endif /* ! HAVE_STRERROR */
2979 #ifdef INTERRUPTIBLE_OPEN
2983 sys_open (path
, oflag
, mode
)
2987 register int rtnval
;
2989 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2990 && (errno
== EINTR
));
2994 #endif /* INTERRUPTIBLE_OPEN */
2996 #ifdef INTERRUPTIBLE_CLOSE
3002 register int rtnval
;
3004 while ((rtnval
= close (fd
)) == -1
3005 && (errno
== EINTR
))
3008 /* If close is interrupted SunOS 4.1 may or may not have closed the
3009 file descriptor. If it did the second close will fail with
3010 errno = EBADF. That means we have succeeded. */
3011 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3017 #endif /* INTERRUPTIBLE_CLOSE */
3019 #ifdef INTERRUPTIBLE_IO
3022 sys_read (fildes
, buf
, nbyte
)
3027 register int rtnval
;
3029 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3030 && (errno
== EINTR
));
3035 sys_write (fildes
, buf
, nbyte
)
3040 register int rtnval
, bytes_written
;
3046 rtnval
= write (fildes
, buf
, nbyte
);
3053 return (bytes_written
? bytes_written
: -1);
3058 bytes_written
+= rtnval
;
3060 return (bytes_written
);
3063 #endif /* INTERRUPTIBLE_IO */
3068 * Substitute fork for vfork on USG flavors.
3076 #endif /* not WINDOWSNT */
3077 #endif /* not HAVE_VFORK */
3081 * All of the following are for USG.
3083 * On USG systems the system calls are INTERRUPTIBLE by signals
3084 * that the user program has elected to catch. Thus the system call
3085 * must be retried in these cases. To handle this without massive
3086 * changes in the source code, we remap the standard system call names
3087 * to names for our own functions in sysdep.c that do the system call
3088 * with retries. Actually, for portability reasons, it is good
3089 * programming practice, as this example shows, to limit all actual
3090 * system calls to a single occurrence in the source. Sure, this
3091 * adds an extra level of function call overhead but it is almost
3092 * always negligible. Fred Fish, Unisoft Systems Inc.
3095 #ifndef HAVE_SYS_SIGLIST
3096 char *sys_siglist
[NSIG
+ 1] =
3099 /* AIX has changed the signals a bit */
3100 "bogus signal", /* 0 */
3101 "hangup", /* 1 SIGHUP */
3102 "interrupt", /* 2 SIGINT */
3103 "quit", /* 3 SIGQUIT */
3104 "illegal instruction", /* 4 SIGILL */
3105 "trace trap", /* 5 SIGTRAP */
3106 "IOT instruction", /* 6 SIGIOT */
3107 "crash likely", /* 7 SIGDANGER */
3108 "floating point exception", /* 8 SIGFPE */
3109 "kill", /* 9 SIGKILL */
3110 "bus error", /* 10 SIGBUS */
3111 "segmentation violation", /* 11 SIGSEGV */
3112 "bad argument to system call", /* 12 SIGSYS */
3113 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3114 "alarm clock", /* 14 SIGALRM */
3115 "software termination signum", /* 15 SIGTERM */
3116 "user defined signal 1", /* 16 SIGUSR1 */
3117 "user defined signal 2", /* 17 SIGUSR2 */
3118 "death of a child", /* 18 SIGCLD */
3119 "power-fail restart", /* 19 SIGPWR */
3120 "bogus signal", /* 20 */
3121 "bogus signal", /* 21 */
3122 "bogus signal", /* 22 */
3123 "bogus signal", /* 23 */
3124 "bogus signal", /* 24 */
3125 "LAN I/O interrupt", /* 25 SIGAIO */
3126 "PTY I/O interrupt", /* 26 SIGPTY */
3127 "I/O intervention required", /* 27 SIGIOINT */
3129 "HFT grant", /* 28 SIGGRANT */
3130 "HFT retract", /* 29 SIGRETRACT */
3131 "HFT sound done", /* 30 SIGSOUND */
3132 "HFT input ready", /* 31 SIGMSG */
3135 "bogus signal", /* 0 */
3136 "hangup", /* 1 SIGHUP */
3137 "interrupt", /* 2 SIGINT */
3138 "quit", /* 3 SIGQUIT */
3139 "illegal instruction", /* 4 SIGILL */
3140 "trace trap", /* 5 SIGTRAP */
3141 "IOT instruction", /* 6 SIGIOT */
3142 "EMT instruction", /* 7 SIGEMT */
3143 "floating point exception", /* 8 SIGFPE */
3144 "kill", /* 9 SIGKILL */
3145 "bus error", /* 10 SIGBUS */
3146 "segmentation violation", /* 11 SIGSEGV */
3147 "bad argument to system call", /* 12 SIGSYS */
3148 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3149 "alarm clock", /* 14 SIGALRM */
3150 "software termination signum", /* 15 SIGTERM */
3151 "user defined signal 1", /* 16 SIGUSR1 */
3152 "user defined signal 2", /* 17 SIGUSR2 */
3153 "death of a child", /* 18 SIGCLD */
3154 "power-fail restart", /* 19 SIGPWR */
3156 "window size change", /* 20 SIGWINCH */
3157 "urgent socket condition", /* 21 SIGURG */
3158 "pollable event occurred", /* 22 SIGPOLL */
3159 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */
3160 "user stop requested from tty", /* 24 SIGTSTP */
3161 "stopped process has been continued", /* 25 SIGCONT */
3162 "background tty read attempted", /* 26 SIGTTIN */
3163 "background tty write attempted", /* 27 SIGTTOU */
3164 "virtual timer expired", /* 28 SIGVTALRM */
3165 "profiling timer expired", /* 29 SIGPROF */
3166 "exceeded cpu limit", /* 30 SIGXCPU */
3167 "exceeded file size limit", /* 31 SIGXFSZ */
3168 "process's lwps are blocked", /* 32 SIGWAITING */
3169 "special signal used by thread library", /* 33 SIGLWP */
3171 "Special Signal Used By CPR", /* 34 SIGFREEZE */
3174 "Special Signal Used By CPR", /* 35 SIGTHAW */
3177 #endif /* not AIX */
3180 #endif /* HAVE_SYS_SIGLIST */
3183 * Warning, this function may not duplicate 4.2 action properly
3184 * under error conditions.
3188 /* In 4.1, param.h fails to define this. */
3189 #define MAXPATHLEN 1024
3198 char *npath
, *spath
;
3199 extern char *getcwd ();
3201 BLOCK_INPUT
; /* getcwd uses malloc */
3202 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3205 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3206 up to first slash. Should be harmless on other systems. */
3207 while (*npath
&& *npath
!= '/')
3209 strcpy (pathname
, npath
);
3210 free (spath
); /* getcwd uses malloc */
3215 #endif /* HAVE_GETWD */
3218 * Emulate rename using unlink/link. Note that this is
3219 * only partially correct. Also, doesn't enforce restriction
3220 * that files be of same type (regular->regular, dir->dir, etc).
3229 if (access (from
, 0) == 0)
3232 if (link (from
, to
) == 0)
3233 if (unlink (from
) == 0)
3245 /* HPUX curses library references perror, but as far as we know
3246 it won't be called. Anyway this definition will do for now. */
3252 #endif /* not HAVE_PERROR */
3258 * Emulate BSD dup2. First close newd if it already exists.
3259 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3260 * until we are, then close the unsuccessful ones.
3267 register int fd
, ret
;
3272 fd
= fcntl (oldd
, F_DUPFD
, newd
);
3274 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, strerror (errno
));
3281 ret
= dup2 (old
,new);
3287 #endif /* not HAVE_DUP2 */
3290 * Gettimeofday. Simulate as much as possible. Only accurate
3291 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3292 * Only needed when subprocesses are defined.
3297 #ifndef HAVE_GETTIMEOFDAY
3301 gettimeofday (tp
, tzp
)
3303 struct timezone
*tzp
;
3305 extern long time ();
3307 tp
->tv_sec
= time ((long *)0);
3310 tzp
->tz_minuteswest
= -1;
3316 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3319 * This function will go away as soon as all the stubs fixed. (fnf)
3325 printf ("%s not yet implemented\r\n", badfunc
);
3334 char *sys_siglist
[NSIG
+ 1] =
3336 "null signal", /* 0 SIGNULL */
3337 "hangup", /* 1 SIGHUP */
3338 "interrupt", /* 2 SIGINT */
3339 "quit", /* 3 SIGQUIT */
3340 "illegal instruction", /* 4 SIGILL */
3341 "trace trap", /* 5 SIGTRAP */
3342 "abort termination", /* 6 SIGABRT */
3343 "SIGEMT", /* 7 SIGEMT */
3344 "floating point exception", /* 8 SIGFPE */
3345 "kill", /* 9 SIGKILL */
3346 "bus error", /* 10 SIGBUS */
3347 "segmentation violation", /* 11 SIGSEGV */
3348 "bad argument to system call", /* 12 SIGSYS */
3349 "write on a pipe with no reader", /* 13 SIGPIPE */
3350 "alarm clock", /* 14 SIGALRM */
3351 "software termination signal", /* 15 SIGTERM */
3352 "user defined signal 1", /* 16 SIGUSR1 */
3353 "user defined signal 2", /* 17 SIGUSR2 */
3354 "child stopped or terminated", /* 18 SIGCLD */
3355 "power-fail restart", /* 19 SIGPWR */
3356 "window size changed", /* 20 SIGWINCH */
3357 "undefined", /* 21 */
3358 "pollable event occurred", /* 22 SIGPOLL */
3359 "sendable stop signal not from tty", /* 23 SIGSTOP */
3360 "stop signal from tty", /* 24 SIGSTP */
3361 "continue a stopped process", /* 25 SIGCONT */
3362 "attempted background tty read", /* 26 SIGTTIN */
3363 "attempted background tty write", /* 27 SIGTTOU */
3364 "undefined", /* 28 */
3365 "undefined", /* 29 */
3366 "undefined", /* 30 */
3367 "undefined", /* 31 */
3368 "undefined", /* 32 */
3369 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
3370 "I/O is possible", /* 34 SIGIO */
3371 "exceeded cpu time limit", /* 35 SIGXCPU */
3372 "exceeded file size limit", /* 36 SIGXFSZ */
3373 "virtual time alarm", /* 37 SIGVTALRM */
3374 "profiling time alarm", /* 38 SIGPROF */
3375 "undefined", /* 39 */
3376 "file record locks revoked", /* 40 SIGLOST */
3377 "undefined", /* 41 */
3378 "undefined", /* 42 */
3379 "undefined", /* 43 */
3380 "undefined", /* 44 */
3381 "undefined", /* 45 */
3382 "undefined", /* 46 */
3383 "undefined", /* 47 */
3384 "undefined", /* 48 */
3385 "undefined", /* 49 */
3386 "undefined", /* 50 */
3387 "undefined", /* 51 */
3388 "undefined", /* 52 */
3389 "undefined", /* 53 */
3390 "undefined", /* 54 */
3391 "undefined", /* 55 */
3392 "undefined", /* 56 */
3393 "undefined", /* 57 */
3394 "undefined", /* 58 */
3395 "undefined", /* 59 */
3396 "undefined", /* 60 */
3397 "undefined", /* 61 */
3398 "undefined", /* 62 */
3399 "undefined", /* 63 */
3400 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3406 /* Directory routines for systems that don't have them. */
3408 #ifdef SYSV_SYSTEM_DIR
3412 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
3416 register DIR *dirp
; /* stream from opendir */
3420 rtnval
= sys_close (dirp
->dd_fd
);
3422 /* Some systems (like Solaris) allocate the buffer and the DIR all
3423 in one block. Why in the world are we freeing this ourselves
3425 #if ! (defined (sun) && defined (USG5_4))
3426 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3428 xfree ((char *) dirp
);
3432 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3433 #endif /* SYSV_SYSTEM_DIR */
3435 #ifdef NONSYSTEM_DIR_LIBRARY
3439 char *filename
; /* name of directory */
3441 register DIR *dirp
; /* -> malloc'ed storage */
3442 register int fd
; /* file descriptor for read */
3443 struct stat sbuf
; /* result of fstat */
3445 fd
= sys_open (filename
, 0);
3450 if (fstat (fd
, &sbuf
) < 0
3451 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3452 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
3456 return 0; /* bad luck today */
3461 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3468 register DIR *dirp
; /* stream from opendir */
3470 sys_close (dirp
->dd_fd
);
3471 xfree ((char *) dirp
);
3479 ino_t od_ino
; /* inode */
3480 char od_name
[DIRSIZ
]; /* filename */
3482 #endif /* not VMS */
3484 struct direct dir_static
; /* simulated directory contents */
3489 register DIR *dirp
; /* stream from opendir */
3492 register struct olddir
*dp
; /* -> directory data */
3494 register struct dir$_name
*dp
; /* -> directory data */
3495 register struct dir$_version
*dv
; /* -> version data */
3500 if (dirp
->dd_loc
>= dirp
->dd_size
)
3501 dirp
->dd_loc
= dirp
->dd_size
= 0;
3503 if (dirp
->dd_size
== 0 /* refill buffer */
3504 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3508 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3509 dirp
->dd_loc
+= sizeof (struct olddir
);
3511 if (dp
->od_ino
!= 0) /* not deleted entry */
3513 dir_static
.d_ino
= dp
->od_ino
;
3514 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3515 dir_static
.d_name
[DIRSIZ
] = '\0';
3516 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3517 dir_static
.d_reclen
= sizeof (struct direct
)
3519 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3520 return &dir_static
; /* -> simulated structure */
3523 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3524 if (dirp
->dd_loc
== 0)
3525 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3526 : dp
->dir$b_namecount
;
3527 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3528 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3529 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3530 dir_static
.d_reclen
= sizeof (struct direct
)
3532 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3533 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3534 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3535 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3542 /* readdirver is just like readdir except it returns all versions of a file
3543 as separate entries. */
3548 register DIR *dirp
; /* stream from opendir */
3550 register struct dir$_name
*dp
; /* -> directory data */
3551 register struct dir$_version
*dv
; /* -> version data */
3553 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3554 dirp
->dd_loc
= dirp
->dd_size
= 0;
3556 if (dirp
->dd_size
== 0 /* refill buffer */
3557 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3560 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3561 if (dirp
->dd_loc
== 0)
3562 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3563 : dp
->dir$b_namecount
;
3564 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3565 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3566 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3567 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3568 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3569 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3570 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3571 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3577 #endif /* NONSYSTEM_DIR_LIBRARY */
3581 set_file_times (filename
, atime
, mtime
)
3583 EMACS_TIME atime
, mtime
;
3586 struct timeval tv
[2];
3589 return utimes (filename
, tv
);
3590 #else /* not HAVE_UTIMES */
3592 utb
.actime
= EMACS_SECS (atime
);
3593 utb
.modtime
= EMACS_SECS (mtime
);
3594 return utime (filename
, &utb
);
3595 #endif /* not HAVE_UTIMES */
3598 /* mkdir and rmdir functions, for systems which don't have them. */
3602 * Written by Robert Rother, Mariah Corporation, August 1985.
3604 * If you want it, it's yours. All I ask in return is that if you
3605 * figure out how to do this in a Bourne Shell script you send me
3607 * sdcsvax!rmr or rmr@uscd
3609 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3610 * subroutine. 11Mar86; hoptoad!gnu
3612 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3613 * subroutine didn't return EEXIST. It does now.
3619 #ifdef MKDIR_PROTOTYPE
3623 mkdir (dpath
, dmode
)
3628 int cpid
, status
, fd
;
3629 struct stat statbuf
;
3631 if (stat (dpath
, &statbuf
) == 0)
3633 errno
= EEXIST
; /* Stat worked, so it already exists */
3637 /* If stat fails for a reason other than non-existence, return error */
3638 if (errno
!= ENOENT
)
3641 synch_process_alive
= 1;
3642 switch (cpid
= fork ())
3645 case -1: /* Error in fork */
3646 return (-1); /* Errno is set already */
3648 case 0: /* Child process */
3650 * Cheap hack to set mode of new directory. Since this
3651 * child process is going away anyway, we zap its umask.
3652 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3653 * directory. Does anybody care?
3655 status
= umask (0); /* Get current umask */
3656 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3657 fd
= sys_open("/dev/null", 2);
3664 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3665 _exit (-1); /* Can't exec /bin/mkdir */
3667 default: /* Parent process */
3668 wait_for_termination (cpid
);
3671 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3673 errno
= EIO
; /* We don't know why, but */
3674 return -1; /* /bin/mkdir failed */
3679 #endif /* not HAVE_MKDIR */
3686 int cpid
, status
, fd
;
3687 struct stat statbuf
;
3689 if (stat (dpath
, &statbuf
) != 0)
3691 /* Stat just set errno. We don't have to */
3695 synch_process_alive
= 1;
3696 switch (cpid
= fork ())
3699 case -1: /* Error in fork */
3700 return (-1); /* Errno is set already */
3702 case 0: /* Child process */
3703 fd
= sys_open("/dev/null", 2);
3710 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3711 _exit (-1); /* Can't exec /bin/rmdir */
3713 default: /* Parent process */
3714 wait_for_termination (cpid
);
3717 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3719 errno
= EIO
; /* We don't know why, but */
3720 return -1; /* /bin/rmdir failed */
3725 #endif /* !HAVE_RMDIR */
3729 /* Functions for VMS */
3731 #include "vms-pwd.h"
3736 /* Return as a string the VMS error string pertaining to STATUS.
3737 Reuses the same static buffer each time it is called. */
3741 int status
; /* VMS status code */
3745 static char buf
[257];
3747 bufadr
[0] = sizeof buf
- 1;
3748 bufadr
[1] = (int) buf
;
3749 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3750 return "untranslatable VMS error status";
3758 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3759 * not work correctly. (It also doesn't work well in version 2.3.)
3764 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3765 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3769 unsigned short s_buflen
;
3770 unsigned short s_code
;
3772 unsigned short *s_retlenadr
;
3776 #define buflen s.s_buflen
3777 #define code s.s_code
3778 #define bufadr s.s_bufadr
3779 #define retlenadr s.s_retlenadr
3781 #define R_OK 4 /* test for read permission */
3782 #define W_OK 2 /* test for write permission */
3783 #define X_OK 1 /* test for execute (search) permission */
3784 #define F_OK 0 /* test for presence of file */
3787 sys_access (path
, mode
)
3791 static char *user
= NULL
;
3794 /* translate possible directory spec into .DIR file name, so brain-dead
3795 * access can treat the directory like a file. */
3796 if (directory_file_name (path
, dir_fn
))
3800 return access (path
, mode
);
3801 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3807 unsigned short int dummy
;
3809 static int constant
= ACL$C_FILE
;
3810 DESCRIPTOR (path_desc
, path
);
3811 DESCRIPTOR (user_desc
, user
);
3815 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3818 acces
|= CHP$M_READ
;
3820 acces
|= CHP$M_WRITE
;
3821 itemlst
[0].buflen
= sizeof (int);
3822 itemlst
[0].code
= CHP$_FLAGS
;
3823 itemlst
[0].bufadr
= (char *) &flags
;
3824 itemlst
[0].retlenadr
= &dummy
;
3825 itemlst
[1].buflen
= sizeof (int);
3826 itemlst
[1].code
= CHP$_ACCESS
;
3827 itemlst
[1].bufadr
= (char *) &acces
;
3828 itemlst
[1].retlenadr
= &dummy
;
3829 itemlst
[2].end
= CHP$_END
;
3830 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3831 return stat
== SS$_NORMAL
? 0 : -1;
3835 #else /* not VMS4_4 */
3838 #define ACE$M_WRITE 2
3839 #define ACE$C_KEYID 1
3841 static unsigned short memid
, grpid
;
3842 static unsigned int uic
;
3844 /* Called from init_sys_modes, so it happens not very often
3845 but at least each time Emacs is loaded. */
3846 sys_access_reinit ()
3852 sys_access (filename
, type
)
3858 int status
, size
, i
, typecode
, acl_controlled
;
3859 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3860 union prvdef prvmask
;
3862 /* Get UIC and GRP values for protection checking. */
3865 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3868 memid
= uic
& 0xFFFF;
3872 if (type
!= 2) /* not checking write access */
3873 return access (filename
, type
);
3875 /* Check write protection. */
3877 #define CHECKPRIV(bit) (prvmask.bit)
3878 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3880 /* Find privilege bits */
3881 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3883 error ("Unable to find privileges: %s", vmserrstr (status
));
3884 if (CHECKPRIV (PRV$V_BYPASS
))
3885 return 0; /* BYPASS enabled */
3887 fab
.fab$b_fac
= FAB$M_GET
;
3888 fab
.fab$l_fna
= filename
;
3889 fab
.fab$b_fns
= strlen (filename
);
3890 fab
.fab$l_xab
= &xab
;
3891 xab
= cc$rms_xabpro
;
3892 xab
.xab$l_aclbuf
= aclbuf
;
3893 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3894 status
= SYS$
OPEN (&fab
, 0, 0);
3897 SYS$
CLOSE (&fab
, 0, 0);
3898 /* Check system access */
3899 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
3901 /* Check ACL entries, if any */
3903 if (xab
.xab$w_acllen
> 0)
3906 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3907 while (*aclptr
&& aclptr
< aclend
)
3909 size
= (*aclptr
& 0xff) / 4;
3910 typecode
= (*aclptr
>> 8) & 0xff;
3911 if (typecode
== ACE$C_KEYID
)
3912 for (i
= size
- 1; i
> 1; i
--)
3913 if (aclptr
[i
] == uic
)
3916 if (aclptr
[1] & ACE$M_WRITE
)
3917 return 0; /* Write access through ACL */
3919 aclptr
= &aclptr
[size
];
3921 if (acl_controlled
) /* ACL specified, prohibits write access */
3924 /* No ACL entries specified, check normal protection */
3925 if (WRITABLE (XAB$V_WLD
)) /* World writable */
3927 if (WRITABLE (XAB$V_GRP
) &&
3928 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3929 return 0; /* Group writable */
3930 if (WRITABLE (XAB$V_OWN
) &&
3931 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3932 return 0; /* Owner writable */
3934 return -1; /* Not writable */
3936 #endif /* not VMS4_4 */
3939 static char vtbuf
[NAM$C_MAXRSS
+1];
3941 /* translate a vms file spec to a unix path */
3943 sys_translate_vms (vfile
)
3954 /* leading device or logical name is a root directory */
3955 if (p
= strchr (vfile
, ':'))
3964 if (*p
== '[' || *p
== '<')
3966 while (*++vfile
!= *p
+ 2)
3970 if (vfile
[-1] == *p
)
3993 static char utbuf
[NAM$C_MAXRSS
+1];
3995 /* translate a unix path to a VMS file spec */
3997 sys_translate_unix (ufile
)
4020 if (index (&ufile
[1], '/'))
4027 if (index (&ufile
[1], '/'))
4034 if (strncmp (ufile
, "./", 2) == 0)
4041 ufile
++; /* skip the dot */
4042 if (index (&ufile
[1], '/'))
4047 else if (strncmp (ufile
, "../", 3) == 0)
4055 ufile
+= 2; /* skip the dots */
4056 if (index (&ufile
[1], '/'))
4081 extern char *getcwd ();
4083 #define MAXPATHLEN 1024
4085 ptr
= xmalloc (MAXPATHLEN
);
4086 val
= getcwd (ptr
, MAXPATHLEN
);
4092 strcpy (pathname
, ptr
);
4100 long item_code
= JPI$_OWNER
;
4101 unsigned long parent_id
;
4104 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4107 vaxc$errno
= status
;
4117 return (getgid () << 16) | getuid ();
4121 sys_read (fildes
, buf
, nbyte
)
4126 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4131 sys_write (fildes
, buf
, nbyte
)
4136 register int nwrote
, rtnval
= 0;
4138 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4144 return rtnval
? rtnval
: -1;
4145 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4146 return rtnval
? rtnval
: -1;
4147 return (rtnval
+ nwrote
);
4152 * VAX/VMS VAX C RTL really loses. It insists that records
4153 * end with a newline (carriage return) character, and if they
4154 * don't it adds one (nice of it isn't it!)
4156 * Thus we do this stupidity below.
4160 sys_write (fildes
, buf
, nbytes
)
4163 unsigned int nbytes
;
4170 fstat (fildes
, &st
);
4176 /* Handle fixed-length files with carriage control. */
4177 if (st
.st_fab_rfm
== FAB$C_FIX
4178 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4180 len
= st
.st_fab_mrs
;
4181 retval
= write (fildes
, p
, min (len
, nbytes
));
4184 retval
++; /* This skips the implied carriage control */
4188 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4189 while (*e
!= '\n' && e
> p
) e
--;
4190 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4191 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4193 retval
= write (fildes
, p
, len
);
4204 /* Create file NEW copying its attributes from file OLD. If
4205 OLD is 0 or does not exist, create based on the value of
4208 /* Protection value the file should ultimately have.
4209 Set by create_copy_attrs, and use by rename_sansversions. */
4210 static unsigned short int fab_final_pro
;
4213 creat_copy_attrs (old
, new)
4216 struct FAB fab
= cc$rms_fab
;
4217 struct XABPRO xabpro
;
4218 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4219 extern int vms_stmlf_recfm
;
4223 fab
.fab$b_fac
= FAB$M_GET
;
4224 fab
.fab$l_fna
= old
;
4225 fab
.fab$b_fns
= strlen (old
);
4226 fab
.fab$l_xab
= (char *) &xabpro
;
4227 xabpro
= cc$rms_xabpro
;
4228 xabpro
.xab$l_aclbuf
= aclbuf
;
4229 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4230 /* Call $OPEN to fill in the fab & xabpro fields. */
4231 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4233 SYS$
CLOSE (&fab
, 0, 0);
4234 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4235 if (xabpro
.xab$w_acllen
> 0)
4237 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4238 /* If the acl buffer was too short, redo open with longer one.
4239 Wouldn't need to do this if there were some system imposed
4240 limit on the size of an ACL, but I can't find any such. */
4242 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4243 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4244 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4245 SYS$
CLOSE (&fab
, 0, 0);
4251 xabpro
.xab$l_aclbuf
= 0;
4256 fab
.fab$l_fna
= new;
4257 fab
.fab$b_fns
= strlen (new);
4261 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4262 fab
.fab$b_rat
= FAB$M_CR
;
4265 /* Set the file protections such that we will be able to manipulate
4266 this file. Once we are done writing and renaming it, we will set
4267 the protections back. */
4269 fab_final_pro
= xabpro
.xab$w_pro
;
4271 SYS$
SETDFPROT (0, &fab_final_pro
);
4272 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4274 /* Create the new file with either default attrs or attrs copied
4276 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4278 SYS$
CLOSE (&fab
, 0, 0);
4279 /* As this is a "replacement" for creat, return a file descriptor
4280 opened for writing. */
4281 return open (new, O_WRONLY
);
4286 #include <varargs.h>
4289 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4293 sys_creat (va_alist
)
4296 va_list list_incrementer
;
4299 int rfd
; /* related file descriptor */
4300 int fd
; /* Our new file descriptor */
4307 extern int vms_stmlf_recfm
;
4310 va_start (list_incrementer
);
4311 name
= va_arg (list_incrementer
, char *);
4312 mode
= va_arg (list_incrementer
, int);
4314 rfd
= va_arg (list_incrementer
, int);
4315 va_end (list_incrementer
);
4318 /* Use information from the related file descriptor to set record
4319 format of the newly created file. */
4320 fstat (rfd
, &st_buf
);
4321 switch (st_buf
.st_fab_rfm
)
4324 strcpy (rfm
, "rfm = fix");
4325 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4326 strcpy (rat
, "rat = ");
4327 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4329 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4330 strcat (rat
, "ftn");
4331 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4332 strcat (rat
, "prn");
4333 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4334 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4335 strcat (rat
, ", blk");
4337 strcat (rat
, "blk");
4338 return creat (name
, 0, rfm
, rat
, mrs
);
4341 strcpy (rfm
, "rfm = vfc");
4342 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4343 strcpy (rat
, "rat = ");
4344 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4346 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4347 strcat (rat
, "ftn");
4348 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4349 strcat (rat
, "prn");
4350 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4351 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4352 strcat (rat
, ", blk");
4354 strcat (rat
, "blk");
4355 return creat (name
, 0, rfm
, rat
, fsz
);
4358 strcpy (rfm
, "rfm = stm");
4362 strcpy (rfm
, "rfm = stmcr");
4366 strcpy (rfm
, "rfm = stmlf");
4370 strcpy (rfm
, "rfm = udf");
4374 strcpy (rfm
, "rfm = var");
4377 strcpy (rat
, "rat = ");
4378 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4380 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4381 strcat (rat
, "ftn");
4382 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4383 strcat (rat
, "prn");
4384 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4385 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4386 strcat (rat
, ", blk");
4388 strcat (rat
, "blk");
4392 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4393 strcpy (rat
, "rat=cr");
4395 /* Until the VAX C RTL fixes the many bugs with modes, always use
4396 mode 0 to get the user's default protection. */
4397 fd
= creat (name
, 0, rfm
, rat
);
4398 if (fd
< 0 && errno
== EEXIST
)
4400 if (unlink (name
) < 0)
4401 report_file_error ("delete", build_string (name
));
4402 fd
= creat (name
, 0, rfm
, rat
);
4408 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4409 sys_fwrite (ptr
, size
, num
, fp
)
4410 register char * ptr
;
4413 register int tot
= num
* size
;
4420 * The VMS C library routine creat actually creates a new version of an
4421 * existing file rather than truncating the old version. There are times
4422 * when this is not the desired behavior, for instance, when writing an
4423 * auto save file (you only want one version), or when you don't have
4424 * write permission in the directory containing the file (but the file
4425 * itself is writable). Hence this routine, which is equivalent to
4426 * "close (creat (fn, 0));" on Unix if fn already exists.
4432 struct FAB xfab
= cc$rms_fab
;
4433 struct RAB xrab
= cc$rms_rab
;
4436 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4437 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4438 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4439 xfab
.fab$l_fna
= fn
;
4440 xfab
.fab$b_fns
= strlen (fn
);
4441 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4443 xrab
.rab$l_fab
= &xfab
;
4445 /* This gibberish opens the file, positions to the first record, and
4446 deletes all records from there until the end of file. */
4447 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4449 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4450 (SYS$
FIND (&xrab
) & 01) == 01 &&
4451 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4462 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4463 SYSPRV or a readable SYSUAF.DAT. */
4469 * Routine to read the VMS User Authorization File and return
4470 * a specific user's record.
4473 static struct UAF retuaf
;
4476 get_uaf_name (uname
)
4483 uaf_fab
= cc$rms_fab
;
4484 uaf_rab
= cc$rms_rab
;
4485 /* initialize fab fields */
4486 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4487 uaf_fab
.fab$b_fns
= 21;
4488 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4489 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4490 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4491 /* initialize rab fields */
4492 uaf_rab
.rab$l_fab
= &uaf_fab
;
4493 /* open the User Authorization File */
4494 status
= SYS$
OPEN (&uaf_fab
);
4498 vaxc$errno
= status
;
4501 status
= SYS$
CONNECT (&uaf_rab
);
4505 vaxc$errno
= status
;
4508 /* read the requested record - index is in uname */
4509 uaf_rab
.rab$l_kbf
= uname
;
4510 uaf_rab
.rab$b_ksz
= strlen (uname
);
4511 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4512 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4513 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4514 status
= SYS$
GET (&uaf_rab
);
4518 vaxc$errno
= status
;
4521 /* close the User Authorization File */
4522 status
= SYS$
DISCONNECT (&uaf_rab
);
4526 vaxc$errno
= status
;
4529 status
= SYS$
CLOSE (&uaf_fab
);
4533 vaxc$errno
= status
;
4547 uaf_fab
= cc$rms_fab
;
4548 uaf_rab
= cc$rms_rab
;
4549 /* initialize fab fields */
4550 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4551 uaf_fab
.fab$b_fns
= 21;
4552 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4553 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4554 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4555 /* initialize rab fields */
4556 uaf_rab
.rab$l_fab
= &uaf_fab
;
4557 /* open the User Authorization File */
4558 status
= SYS$
OPEN (&uaf_fab
);
4562 vaxc$errno
= status
;
4565 status
= SYS$
CONNECT (&uaf_rab
);
4569 vaxc$errno
= status
;
4572 /* read the requested record - index is in uic */
4573 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4574 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4575 uaf_rab
.rab$b_ksz
= sizeof uic
;
4576 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4577 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4578 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4579 status
= SYS$
GET (&uaf_rab
);
4583 vaxc$errno
= status
;
4586 /* close the User Authorization File */
4587 status
= SYS$
DISCONNECT (&uaf_rab
);
4591 vaxc$errno
= status
;
4594 status
= SYS$
CLOSE (&uaf_fab
);
4598 vaxc$errno
= status
;
4604 static struct passwd retpw
;
4612 /* copy these out first because if the username is 32 chars, the next
4613 section will overwrite the first byte of the UIC */
4614 retpw
.pw_uid
= up
->uaf$w_mem
;
4615 retpw
.pw_gid
= up
->uaf$w_grp
;
4617 /* I suppose this is not the best style, to possibly overwrite one
4618 byte beyond the end of the field, but what the heck... */
4619 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4620 while (ptr
[-1] == ' ')
4623 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4625 /* the rest of these are counted ascii strings */
4626 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4627 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4628 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4629 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4630 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4631 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4632 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4633 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4637 #else /* not READ_SYSUAF */
4638 static struct passwd retpw
;
4639 #endif /* not READ_SYSUAF */
4650 unsigned char * full
;
4651 #endif /* READ_SYSUAF */
4656 if ('a' <= *ptr
&& *ptr
<= 'z')
4661 if (!(up
= get_uaf_name (name
)))
4663 return cnv_uaf_pw (up
);
4665 if (strcmp (name
, getenv ("USER")) == 0)
4667 retpw
.pw_uid
= getuid ();
4668 retpw
.pw_gid
= getgid ();
4669 strcpy (retpw
.pw_name
, name
);
4670 if (full
= egetenv ("FULLNAME"))
4671 strcpy (retpw
.pw_gecos
, full
);
4673 *retpw
.pw_gecos
= '\0';
4674 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4675 *retpw
.pw_shell
= '\0';
4680 #endif /* not READ_SYSUAF */
4690 if (!(up
= get_uaf_uic (uid
)))
4692 return cnv_uaf_pw (up
);
4694 if (uid
== sys_getuid ())
4695 return getpwnam (egetenv ("USER"));
4698 #endif /* not READ_SYSUAF */
4701 /* return total address space available to the current process. This is
4702 the sum of the current p0 size, p1 size and free page table entries
4707 unsigned long free_pages
;
4708 unsigned long frep0va
;
4709 unsigned long frep1va
;
4712 item_code
= JPI$_FREPTECNT
;
4713 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4716 vaxc$errno
= status
;
4721 item_code
= JPI$_FREP0VA
;
4722 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4725 vaxc$errno
= status
;
4728 item_code
= JPI$_FREP1VA
;
4729 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4732 vaxc$errno
= status
;
4736 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4739 define_logical_name (varname
, string
)
4743 struct dsc$descriptor_s strdsc
=
4744 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4745 struct dsc$descriptor_s envdsc
=
4746 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4747 struct dsc$descriptor_s lnmdsc
=
4748 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4750 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4753 delete_logical_name (varname
)
4756 struct dsc$descriptor_s envdsc
=
4757 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4758 struct dsc$descriptor_s lnmdsc
=
4759 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4761 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4772 error ("execvp system call not implemented");
4780 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4781 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4782 char from_esn
[NAM$C_MAXRSS
];
4783 char to_esn
[NAM$C_MAXRSS
];
4785 from_fab
.fab$l_fna
= from
;
4786 from_fab
.fab$b_fns
= strlen (from
);
4787 from_fab
.fab$l_nam
= &from_nam
;
4788 from_fab
.fab$l_fop
= FAB$M_NAM
;
4790 from_nam
.nam$l_esa
= from_esn
;
4791 from_nam
.nam$b_ess
= sizeof from_esn
;
4793 to_fab
.fab$l_fna
= to
;
4794 to_fab
.fab$b_fns
= strlen (to
);
4795 to_fab
.fab$l_nam
= &to_nam
;
4796 to_fab
.fab$l_fop
= FAB$M_NAM
;
4798 to_nam
.nam$l_esa
= to_esn
;
4799 to_nam
.nam$b_ess
= sizeof to_esn
;
4801 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4807 if (status
== RMS$_DEV
)
4811 vaxc$errno
= status
;
4816 /* This function renames a file like `rename', but it strips
4817 the version number from the "to" filename, such that the "to" file is
4818 will always be a new version. It also sets the file protection once it is
4819 finished. The protection that we will use is stored in fab_final_pro,
4820 and was set when we did a creat_copy_attrs to create the file that we
4823 We could use the chmod function, but Eunichs uses 3 bits per user category
4824 to describe the protection, and VMS uses 4 (write and delete are separate
4825 bits). To maintain portability, the VMS implementation of `chmod' wires
4826 the W and D bits together. */
4829 static struct fibdef fib
; /* We need this initialized to zero */
4830 char vms_file_written
[NAM$C_MAXRSS
];
4833 rename_sans_version (from
,to
)
4840 struct FAB to_fab
= cc$rms_fab
;
4841 struct NAM to_nam
= cc$rms_nam
;
4842 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4843 struct dsc$descriptor fib_attr
[2]
4844 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4845 char to_esn
[NAM$C_MAXRSS
];
4847 $
DESCRIPTOR (disk
,to_esn
);
4849 to_fab
.fab$l_fna
= to
;
4850 to_fab
.fab$b_fns
= strlen (to
);
4851 to_fab
.fab$l_nam
= &to_nam
;
4852 to_fab
.fab$l_fop
= FAB$M_NAM
;
4854 to_nam
.nam$l_esa
= to_esn
;
4855 to_nam
.nam$b_ess
= sizeof to_esn
;
4857 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4859 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4860 *(to_nam
.nam$l_ver
) = '\0';
4862 stat
= rename (from
, to_esn
);
4866 strcpy (vms_file_written
, to_esn
);
4868 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4869 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4871 /* Now set the file protection to the correct value */
4872 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4874 /* Copy these fields into the fib */
4875 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4876 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4877 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4879 SYS$
CLOSE (&to_fab
, 0, 0);
4881 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4884 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4885 0, 0, 0, &fib_attr
, 0);
4888 stat
= SYS$
DASSGN (chan
);
4891 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4901 unsigned short fid
[3];
4902 char esa
[NAM$C_MAXRSS
];
4905 fab
.fab$l_fop
= FAB$M_OFP
;
4906 fab
.fab$l_fna
= file
;
4907 fab
.fab$b_fns
= strlen (file
);
4908 fab
.fab$l_nam
= &nam
;
4911 nam
.nam$l_esa
= esa
;
4912 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4914 status
= SYS$
PARSE (&fab
);
4915 if ((status
& 1) == 0)
4918 vaxc$errno
= status
;
4921 status
= SYS$
SEARCH (&fab
);
4922 if ((status
& 1) == 0)
4925 vaxc$errno
= status
;
4929 fid
[0] = nam
.nam$w_fid
[0];
4930 fid
[1] = nam
.nam$w_fid
[1];
4931 fid
[2] = nam
.nam$w_fid
[2];
4933 fab
.fab$l_fna
= new;
4934 fab
.fab$b_fns
= strlen (new);
4936 status
= SYS$
PARSE (&fab
);
4937 if ((status
& 1) == 0)
4940 vaxc$errno
= status
;
4944 nam
.nam$w_fid
[0] = fid
[0];
4945 nam
.nam$w_fid
[1] = fid
[1];
4946 nam
.nam$w_fid
[2] = fid
[2];
4948 nam
.nam$l_esa
= nam
.nam$l_name
;
4949 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
4951 status
= SYS$
ENTER (&fab
);
4952 if ((status
& 1) == 0)
4955 vaxc$errno
= status
;
4965 printf ("%s not yet implemented\r\n", badfunc
);
4973 /* Arrange to return a range centered on zero. */
4974 return rand () - (1 << 30);
4985 /* Called from init_sys_modes. */
4990 /* If we're not on an HFT we shouldn't do any of this. We determine
4991 if we are on an HFT by trying to get an HFT error code. If this
4992 call fails, we're not on an HFT. */
4994 if (ioctl (0, HFQERROR
, &junk
) < 0)
4996 #else /* not IBMR2AIX */
4997 if (ioctl (0, HFQEIO
, 0) < 0)
4999 #endif /* not IBMR2AIX */
5001 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5002 as the rubout key's ASCII code. Here this is changed. The bug is that
5003 there's no way to determine the old mapping, so in reset_sys_modes
5004 we need to assume that the normal map had been present. Of course, this
5005 code also doesn't help if on a terminal emulator which doesn't understand
5009 struct hfkeymap keymap
;
5011 buf
.hf_bufp
= (char *)&keymap
;
5012 buf
.hf_buflen
= sizeof (keymap
);
5013 keymap
.hf_nkeys
= 2;
5014 keymap
.hfkey
[0].hf_kpos
= 15;
5015 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5017 keymap
.hfkey
[0].hf_keyidh
= '<';
5018 #else /* not IBMR2AIX */
5019 keymap
.hfkey
[0].hf_page
= '<';
5020 #endif /* not IBMR2AIX */
5021 keymap
.hfkey
[0].hf_char
= 127;
5022 keymap
.hfkey
[1].hf_kpos
= 15;
5023 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5025 keymap
.hfkey
[1].hf_keyidh
= '<';
5026 #else /* not IBMR2AIX */
5027 keymap
.hfkey
[1].hf_page
= '<';
5028 #endif /* not IBMR2AIX */
5029 keymap
.hfkey
[1].hf_char
= 127;
5030 hftctl (0, HFSKBD
, &buf
);
5032 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5034 line_ins_del_ok
= char_ins_del_ok
= 0;
5037 /* Reset the rubout key to backspace. */
5042 struct hfkeymap keymap
;
5046 if (ioctl (0, HFQERROR
, &junk
) < 0)
5048 #else /* not IBMR2AIX */
5049 if (ioctl (0, HFQEIO
, 0) < 0)
5051 #endif /* not IBMR2AIX */
5053 buf
.hf_bufp
= (char *)&keymap
;
5054 buf
.hf_buflen
= sizeof (keymap
);
5055 keymap
.hf_nkeys
= 2;
5056 keymap
.hfkey
[0].hf_kpos
= 15;
5057 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5059 keymap
.hfkey
[0].hf_keyidh
= '<';
5060 #else /* not IBMR2AIX */
5061 keymap
.hfkey
[0].hf_page
= '<';
5062 #endif /* not IBMR2AIX */
5063 keymap
.hfkey
[0].hf_char
= 8;
5064 keymap
.hfkey
[1].hf_kpos
= 15;
5065 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5067 keymap
.hfkey
[1].hf_keyidh
= '<';
5068 #else /* not IBMR2AIX */
5069 keymap
.hfkey
[1].hf_page
= '<';
5070 #endif /* not IBMR2AIX */
5071 keymap
.hfkey
[1].hf_char
= 8;
5072 hftctl (0, HFSKBD
, &buf
);
5079 /* These are included on Sunos 4.1 when we do not use shared libraries.
5080 X11 libraries may refer to these functions but (we hope) do not
5081 actually call them. */
5101 #endif /* USE_DL_STUBS */
5110 register int length
;
5114 long max_str
= 65535;
5116 while (length
> max_str
) {
5117 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5122 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5124 while (length
-- > 0)
5126 #endif /* not VMS */
5129 #endif /* no bzero */
5130 #endif /* BSTRING */
5132 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5135 /* Saying `void' requires a declaration, above, where bcopy is used
5136 and that declaration causes pain for systems where bcopy is a macro. */
5137 bcopy (b1
, b2
, length
)
5140 register int length
;
5143 long max_str
= 65535;
5145 while (length
> max_str
) {
5146 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5152 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5154 while (length
-- > 0)
5156 #endif /* not VMS */
5158 #endif /* (defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5163 bcmp (b1
, b2
, length
) /* This could be a macro! */
5166 register int length
;
5169 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5170 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5172 return STR$
COMPARE (&src1
, &src2
);
5174 while (length
-- > 0)
5179 #endif /* not VMS */
5181 #endif /* no bcmp */
5182 #endif /* not BSTRING */