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_TERMIOS_H) && defined (LINUX)
231 /* HJL's version of libc is said to need this on the Alpha.
232 On the other hand, DEC OSF1 on the Alpha needs ospeed to be a short. */
233 extern speed_t ospeed
;
238 /* The file descriptor for Emacs's input terminal.
239 Under Unix, this is normally zero except when using X;
240 under VMS, we place the input channel number here. */
243 /* Specify a different file descriptor for further input operations. */
252 /* Discard pending input on descriptor input_fd. */
257 struct emacs_tty buf
;
262 /* Discarding input is not safe when the input could contain
263 replies from the X server. So don't do it. */
264 if (read_socket_hook
)
269 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
270 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
276 ioctl (input_fd
, TIOCFLUSH
, &zero
);
278 #else /* not Apollo */
279 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
280 while (dos_keyread () != -1)
282 #else /* not MSDOS */
283 EMACS_GET_TTY (input_fd
, &buf
);
284 EMACS_SET_TTY (input_fd
, &buf
, 0);
285 #endif /* not MSDOS */
286 #endif /* not Apollo */
288 #endif /* not WINDOWSNT */
293 /* Arrange for character C to be read as the next input from
299 if (read_socket_hook
)
302 /* Should perhaps error if in batch mode */
304 ioctl (input_fd
, TIOCSTI
, &c
);
305 #else /* no TIOCSTI */
306 error ("Cannot stuff terminal input characters in this version of Unix");
307 #endif /* no TIOCSTI */
318 #ifdef INIT_BAUD_RATE
323 #else /* not DOS_NT */
327 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
328 &sg
.class, 12, 0, 0, 0, 0 );
329 ospeed
= sg
.xmit_baud
;
335 tcgetattr (input_fd
, &sg
);
336 ospeed
= cfgetospeed (&sg
);
337 #if defined (USE_GETOBAUD) && defined (getobaud)
338 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
340 ospeed
= getobaud (sg
.c_cflag
);
342 #else /* neither VMS nor TERMIOS */
348 tcgetattr (input_fd
, &sg
);
350 ioctl (input_fd
, TCGETA
, &sg
);
352 ospeed
= sg
.c_cflag
& CBAUD
;
353 #else /* neither VMS nor TERMIOS nor TERMIO */
356 sg
.sg_ospeed
= B9600
;
357 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
359 ospeed
= sg
.sg_ospeed
;
360 #endif /* not HAVE_TERMIO */
361 #endif /* not HAVE_TERMIOS */
363 #endif /* not DOS_NT */
364 #endif /* not INIT_BAUD_RATE */
367 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
368 ? baud_convert
[ospeed
] : 9600);
374 set_exclusive_use (fd
)
378 ioctl (fd
, FIOCLEX
, 0);
380 /* Ok to do nothing if this feature does not exist */
385 wait_without_blocking ()
388 wait3 (0, WNOHANG
| WUNTRACED
, 0);
390 croak ("wait_without_blocking");
392 synch_process_alive
= 0;
395 #endif /* not subprocesses */
397 int wait_debugging
; /* Set nonzero to make following function work under dbx
398 (at least for bsd). */
401 wait_for_termination_signal ()
404 /* Wait for subprocess with process id `pid' to terminate and
405 make sure it will get eliminated (not remain forever as a zombie) */
407 wait_for_termination (pid
)
416 status
= SYS$
FORCEX (&pid
, 0, 0);
419 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
420 /* Note that kill returns -1 even if the process is just a zombie now.
421 But inevitably a SIGCHLD interrupt should be generated
422 and child_sig will do wait3 and make the process go away. */
423 /* There is some indication that there is a bug involved with
424 termination of subprocesses, perhaps involving a kernel bug too,
425 but no idea what it is. Just as a hunch we signal SIGCHLD to see
426 if that causes the problem to go away or get worse. */
427 sigsetmask (sigmask (SIGCHLD
));
428 if (0 > kill (pid
, 0))
430 sigsetmask (SIGEMPTYMASK
);
431 kill (getpid (), SIGCHLD
);
437 sigpause (SIGEMPTYMASK
);
438 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
439 #if defined (UNIPLUS)
440 if (0 > kill (pid
, 0))
443 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
444 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
445 sigblock (sigmask (SIGCHLD
));
446 if (0 > kill (pid
, 0))
448 sigunblock (sigmask (SIGCHLD
));
451 sigpause (SIGEMPTYMASK
);
452 #else /* not POSIX_SIGNALS */
453 #ifdef HAVE_SYSV_SIGPAUSE
455 if (0 > kill (pid
, 0))
461 #else /* not HAVE_SYSV_SIGPAUSE */
465 #else /* not WINDOWSNT */
466 if (0 > kill (pid
, 0))
468 /* Using sleep instead of pause avoids timing error.
469 If the inferior dies just before the sleep,
470 we lose just one second. */
472 #endif /* not WINDOWSNT */
473 #endif /* not HAVE_SYSV_SIGPAUSE */
474 #endif /* not POSIX_SIGNALS */
475 #endif /* not UNIPLUS */
476 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
478 #else /* not subprocesses */
481 #else /* not __DJGPP__ > 1 */
483 if (kill (pid
, 0) < 0)
489 if (status
== pid
|| status
== -1)
492 #endif /* not __DJGPP__ > 1*/
493 #endif /* not subprocesses */
500 * flush any pending output
501 * (may flush input as well; it does not matter the way we use it)
504 flush_pending_output (channel
)
508 /* If we try this, we get hit with SIGTTIN, because
509 the child's tty belongs to the child's pgrp. */
512 ioctl (channel
, TCFLSH
, 1);
516 /* 3rd arg should be ignored
517 but some 4.2 kernels actually want the address of an int
518 and nonzero means something different. */
519 ioctl (channel
, TIOCFLUSH
, &zero
);
526 /* Set up the terminal at the other end of a pseudo-terminal that
527 we will be controlling an inferior through.
528 It should not echo or do line-editing, since that is done
529 in Emacs. No padding needed for insertion into an Emacs buffer. */
531 child_setup_tty (out
)
537 EMACS_GET_TTY (out
, &s
);
539 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
540 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
541 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
543 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
544 /* No output delays */
546 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
547 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
549 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
552 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
555 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
557 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
558 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
560 /* Said to be unnecessary: */
561 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
562 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
565 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
566 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
567 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
568 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
571 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
575 /* AIX enhanced edit loses NULs, so disable it */
578 s
.main
.c_iflag
&= ~ASCEDIT
;
580 /* Also, PTY overloads NUL and BREAK.
581 don't ignore break, but don't signal either, so it looks like NUL. */
582 s
.main
.c_iflag
&= ~IGNBRK
;
583 s
.main
.c_iflag
&= ~BRKINT
;
584 /* QUIT and INTR work better as signals, so disable character forms */
585 s
.main
.c_cc
[VINTR
] = 0377;
586 #ifdef SIGNALS_VIA_CHARACTERS
587 /* the QUIT and INTR character are used in process_send_signal
588 so set them here to something useful. */
589 if (s
.main
.c_cc
[VQUIT
] == 0377)
590 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
591 if (s
.main
.c_cc
[VINTR
] == 0377)
592 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
593 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
594 /* QUIT and INTR work better as signals, so disable character forms */
595 s
.main
.c_cc
[VQUIT
] = 0377;
596 s
.main
.c_cc
[VINTR
] = 0377;
597 s
.main
.c_lflag
&= ~ISIG
;
598 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
599 s
.main
.c_cc
[VEOL
] = 0377;
600 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
603 #else /* not HAVE_TERMIO */
605 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
607 s
.main
.sg_flags
|= LPASS8
;
608 s
.main
.sg_erase
= 0377;
609 s
.main
.sg_kill
= 0377;
610 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
612 #endif /* not HAVE_TERMIO */
614 EMACS_SET_TTY (out
, &s
, 0);
623 ioctl (out
, FIOASYNC
, &zero
);
626 #endif /* not DOS_NT */
630 #endif /* subprocesses */
632 /* Record a signal code and the handler for it. */
636 SIGTYPE (*handler
) ();
639 /* Suspend the Emacs process; give terminal to its superior. */
644 /* "Foster" parentage allows emacs to return to a subprocess that attached
645 to the current emacs as a cheaper than starting a whole new process. This
646 is set up by KEPTEDITOR.COM. */
647 unsigned long parent_id
, foster_parent_id
;
650 fpid_string
= getenv ("EMACS_PARENT_PID");
651 if (fpid_string
!= NULL
)
653 sscanf (fpid_string
, "%x", &foster_parent_id
);
654 if (foster_parent_id
!= 0)
655 parent_id
= foster_parent_id
;
657 parent_id
= getppid ();
660 parent_id
= getppid ();
662 xfree (fpid_string
); /* On VMS, this was malloc'd */
664 if (parent_id
&& parent_id
!= 0xffffffff)
666 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
667 int status
= LIB$
ATTACH (&parent_id
) & 1;
668 signal (SIGINT
, oldsig
);
677 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
678 d_prompt
.a
= "Emacs: "; /* Just a reminder */
679 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
684 #if defined(SIGTSTP) && !defined(MSDOS)
687 int pgrp
= EMACS_GETPGRP (0);
688 EMACS_KILLPG (pgrp
, SIGTSTP
);
691 #else /* No SIGTSTP */
692 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
693 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
694 kill (getpid (), SIGQUIT
);
696 #else /* No SIGTSTP or USG_JOBCTRL */
698 /* On a system where suspending is not implemented,
699 instead fork a subshell and let it talk directly to the terminal
703 #endif /* no USG_JOBCTRL */
704 #endif /* no SIGTSTP */
708 /* Fork a subshell. */
713 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
715 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
718 struct save_signal saved_handlers
[5];
720 unsigned char *str
= 0;
723 saved_handlers
[0].code
= SIGINT
;
724 saved_handlers
[1].code
= SIGQUIT
;
725 saved_handlers
[2].code
= SIGTERM
;
727 saved_handlers
[3].code
= SIGIO
;
728 saved_handlers
[4].code
= 0;
730 saved_handlers
[3].code
= 0;
733 /* Mentioning current_buffer->buffer would mean including buffer.h,
734 which somehow wedges the hp compiler. So instead... */
736 dir
= intern ("default-directory");
737 if (NILP (Fboundp (dir
)))
739 dir
= Fsymbol_value (dir
);
743 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
744 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
745 len
= XSTRING (dir
)->size
;
746 bcopy (XSTRING (dir
)->data
, str
, len
);
747 if (str
[len
- 1] != '/') str
[len
++] = '/';
753 #else /* not WINDOWSNT */
758 save_signal_handlers (saved_handlers
);
759 synch_process_alive
= 1;
760 #endif /* __DJGPP__ > 1 */
764 error ("Can't spawn subshell");
768 #endif /* not WINDOWSNT */
772 #ifdef MSDOS /* MW, Aug 1993 */
775 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
778 sh
= (char *) egetenv ("SHELL");
782 /* Use our buffer's default directory for the subshell. */
787 close_process_descs (); /* Close Emacs's pipes/ptys */
790 #ifdef SET_EMACS_PRIORITY
792 extern int emacs_priority
;
794 if (emacs_priority
< 0)
795 nice (-emacs_priority
);
799 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
802 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
804 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
806 #else /* not MSDOS */
808 /* Waits for process completion */
809 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
811 write (1, "Can't execute subshell", 22);
814 #else /* not WINDOWSNT */
816 write (1, "Can't execute subshell", 22);
818 #endif /* not WINDOWSNT */
819 #endif /* not MSDOS */
822 /* Do this now if we did not do it before. */
823 #if !defined (MSDOS) || __DJGPP__ == 1
824 save_signal_handlers (saved_handlers
);
825 synch_process_alive
= 1;
829 wait_for_termination (pid
);
831 restore_signal_handlers (saved_handlers
);
832 synch_process_alive
= 0;
836 save_signal_handlers (saved_handlers
)
837 struct save_signal
*saved_handlers
;
839 while (saved_handlers
->code
)
841 saved_handlers
->handler
842 = (SIGTYPE (*) ()) signal (saved_handlers
->code
, SIG_IGN
);
847 restore_signal_handlers (saved_handlers
)
848 struct save_signal
*saved_handlers
;
850 while (saved_handlers
->code
)
852 signal (saved_handlers
->code
, saved_handlers
->handler
);
865 old_fcntl_flags
= fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
866 fcntl (fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
868 interrupts_deferred
= 0;
876 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
880 if (read_socket_hook
)
884 sigunblock (sigmask (SIGWINCH
));
886 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
888 interrupts_deferred
= 0;
893 if (read_socket_hook
)
897 sigblock (sigmask (SIGWINCH
));
899 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
900 interrupts_deferred
= 1;
903 #else /* no FASYNC */
904 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
910 if (read_socket_hook
)
913 ioctl (input_fd
, FIOASYNC
, &on
);
914 interrupts_deferred
= 0;
921 if (read_socket_hook
)
924 ioctl (input_fd
, FIOASYNC
, &off
);
925 interrupts_deferred
= 1;
928 #else /* not FASYNC, not STRIDE */
939 if (read_socket_hook
)
943 sigaddset(&st
, SIGIO
);
944 ioctl (input_fd
, FIOASYNC
, &on
);
945 interrupts_deferred
= 0;
946 sigprocmask(SIG_UNBLOCK
, &st
, (sigset_t
*)0);
953 if (read_socket_hook
)
956 ioctl (input_fd
, FIOASYNC
, &off
);
957 interrupts_deferred
= 1;
964 if (read_socket_hook
)
967 croak ("request_sigio");
972 if (read_socket_hook
)
975 croak ("unrequest_sigio");
983 /* Saving and restoring the process group of Emacs's terminal. */
987 /* The process group of which Emacs was a member when it initially
990 If Emacs was in its own process group (i.e. inherited_pgroup ==
991 getpid ()), then we know we're running under a shell with job
992 control (Emacs would never be run as part of a pipeline).
995 If Emacs was not in its own process group, then we know we're
996 running under a shell (or a caller) that doesn't know how to
997 separate itself from Emacs (like sh). Emacs must be in its own
998 process group in order to receive SIGIO correctly. In this
999 situation, we put ourselves in our own pgroup, forcibly set the
1000 tty's pgroup to our pgroup, and make sure to restore and reinstate
1001 the tty's pgroup just like any other terminal setting. If
1002 inherited_group was not the tty's pgroup, then we'll get a
1003 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1004 it goes foreground in the future, which is what should happen. */
1005 int inherited_pgroup
;
1007 /* Split off the foreground process group to Emacs alone.
1008 When we are in the foreground, but not started in our own process
1009 group, redirect the TTY to point to our own process group. We need
1010 to be in our own process group to receive SIGIO properly. */
1011 narrow_foreground_group ()
1015 setpgrp (0, inherited_pgroup
);
1016 if (inherited_pgroup
!= me
)
1017 EMACS_SET_TTY_PGRP (input_fd
, &me
);
1021 /* Set the tty to our original foreground group. */
1022 widen_foreground_group ()
1024 if (inherited_pgroup
!= getpid ())
1025 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
1026 setpgrp (0, inherited_pgroup
);
1029 #endif /* BSD_PGRPS */
1031 /* Getting and setting emacs_tty structures. */
1033 /* Set *TC to the parameters associated with the terminal FD.
1034 Return zero if all's well, or -1 if we ran into an error we
1035 couldn't deal with. */
1037 emacs_get_tty (fd
, settings
)
1039 struct emacs_tty
*settings
;
1041 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1043 /* We have those nifty POSIX tcmumbleattr functions. */
1044 if (tcgetattr (fd
, &settings
->main
) < 0)
1049 /* The SYSV-style interface? */
1050 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1055 /* Vehemently Monstrous System? :-) */
1056 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1057 &settings
->main
.class, 12, 0, 0, 0, 0)
1063 /* I give up - I hope you have the BSD ioctls. */
1064 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1066 #endif /* not DOS_NT */
1071 /* Suivant - Do we have to get struct ltchars data? */
1073 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1077 /* How about a struct tchars and a wordful of lmode bits? */
1079 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1080 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1084 /* We have survived the tempest. */
1089 /* Set the parameters of the tty on FD according to the contents of
1090 *SETTINGS. If FLUSHP is non-zero, we discard input.
1091 Return 0 if all went well, and -1 if anything failed. */
1094 emacs_set_tty (fd
, settings
, flushp
)
1096 struct emacs_tty
*settings
;
1099 /* Set the primary parameters - baud rate, character size, etcetera. */
1102 /* We have those nifty POSIX tcmumbleattr functions.
1103 William J. Smith <wjs@wiis.wang.com> writes:
1104 "POSIX 1003.1 defines tcsetattr() to return success if it was
1105 able to perform any of the requested actions, even if some
1106 of the requested actions could not be performed.
1107 We must read settings back to ensure tty setup properly.
1108 AIX requires this to keep tty from hanging occasionally." */
1109 /* This make sure that we don't loop indefinitely in here. */
1110 for (i
= 0 ; i
< 10 ; i
++)
1111 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1122 /* Get the current settings, and see if they're what we asked for. */
1123 tcgetattr (fd
, &new);
1124 /* We cannot use memcmp on the whole structure here because under
1125 * aix386 the termios structure has some reserved field that may
1128 if ( new.c_iflag
== settings
->main
.c_iflag
1129 && new.c_oflag
== settings
->main
.c_oflag
1130 && new.c_cflag
== settings
->main
.c_cflag
1131 && new.c_lflag
== settings
->main
.c_lflag
1132 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1140 /* The SYSV-style interface? */
1141 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1146 /* Vehemently Monstrous System? :-) */
1147 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1148 &settings
->main
.class, 12, 0, 0, 0, 0)
1154 /* I give up - I hope you have the BSD ioctls. */
1155 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1157 #endif /* not DOS_NT */
1163 /* Suivant - Do we have to get struct ltchars data? */
1165 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1169 /* How about a struct tchars and a wordful of lmode bits? */
1171 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1172 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1176 /* We have survived the tempest. */
1181 /* The initial tty mode bits */
1182 struct emacs_tty old_tty
;
1184 /* 1 if we have been through init_sys_modes. */
1187 /* 1 if outer tty status has been recorded. */
1191 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1196 #ifndef F_SETOWN_BUG
1198 int old_fcntl_owner
;
1199 #endif /* F_SETOWN */
1200 #endif /* F_SETOWN_BUG */
1202 /* This may also be defined in stdio,
1203 but if so, this does no harm,
1204 and using the same name avoids wasting the other one's space. */
1206 #if defined (USG) || defined (DGUX)
1207 unsigned char _sobuf
[BUFSIZ
+8];
1209 char _sobuf
[BUFSIZ
];
1213 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1216 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1221 struct emacs_tty tty
;
1225 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1226 extern int (*interrupt_signal
) ();
1230 Vtty_erase_char
= Qnil
;
1237 input_ef
= get_kbd_event_flag ();
1238 /* LIB$GET_EF (&input_ef); */
1239 SYS$
CLREF (input_ef
);
1240 waiting_for_ast
= 0;
1242 timer_ef
= get_timer_event_flag ();
1243 /* LIB$GET_EF (&timer_ef); */
1244 SYS$
CLREF (timer_ef
);
1248 LIB$
GET_EF (&process_ef
);
1249 SYS$
CLREF (process_ef
);
1251 if (input_ef
/ 32 != process_ef
/ 32)
1252 croak ("Input and process event flags in different clusters.");
1254 if (input_ef
/ 32 != timer_ef
/ 32)
1255 croak ("Input and timer event flags in different clusters.");
1257 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1258 ((unsigned) 1 << (process_ef
% 32));
1260 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1261 ((unsigned) 1 << (timer_ef
% 32));
1263 sys_access_reinit ();
1265 #endif /* not VMS */
1268 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1269 narrow_foreground_group ();
1272 #ifdef HAVE_WINDOW_SYSTEM
1273 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1274 needs the initialization code below. */
1275 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1278 EMACS_GET_TTY (input_fd
, &old_tty
);
1284 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1285 XSETINT (Vtty_erase_char
, old_tty
.main
.c_cc
[VERASE
]);
1288 /* This allows meta to be sent on 8th bit. */
1289 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1291 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1292 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1293 #ifdef INLCR /* I'm just being cautious,
1294 since I can't check how widespread INLCR is--rms. */
1295 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1298 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1300 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1301 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1303 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1305 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1308 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1310 tty
.main
.c_iflag
&= ~IXANY
;
1314 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1315 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1317 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1321 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1322 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1325 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1326 /* Set up C-g for both SIGQUIT and SIGINT.
1327 We don't know which we will get, but we handle both alike
1328 so which one it really gives us does not matter. */
1329 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1330 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1331 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1333 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1336 #if defined (mips) || defined (HAVE_TCATTR)
1338 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1341 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1342 #endif /* V_DSUSP */
1343 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1344 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1347 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1350 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1351 #endif /* VREPRINT */
1353 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1354 #endif /* VWERASE */
1356 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1357 #endif /* VDISCARD */
1359 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1362 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1364 #endif /* mips or HAVE_TCATTR */
1365 #ifdef SET_LINE_DISCIPLINE
1366 /* Need to explicitly request TERMIODISC line discipline or
1367 Ultrix's termios does not work correctly. */
1368 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1372 /* AIX enhanced edit loses NULs, so disable it. */
1373 tty
.main
.c_line
= 0;
1374 tty
.main
.c_iflag
&= ~ASCEDIT
;
1376 tty
.main
.c_cc
[VSTRT
] = 255;
1377 tty
.main
.c_cc
[VSTOP
] = 255;
1378 tty
.main
.c_cc
[VSUSP
] = 255;
1379 tty
.main
.c_cc
[VDSUSP
] = 255;
1380 #endif /* IBMR2AIX */
1384 tty
.main
.c_cc
[VSTART
] = '\021';
1387 tty
.main
.c_cc
[VSTOP
] = '\023';
1390 /* Also, PTY overloads NUL and BREAK.
1391 don't ignore break, but don't signal either, so it looks like NUL.
1392 This really serves a purpose only if running in an XTERM window
1393 or via TELNET or the like, but does no harm elsewhere. */
1394 tty
.main
.c_iflag
&= ~IGNBRK
;
1395 tty
.main
.c_iflag
&= ~BRKINT
;
1397 #else /* if not HAVE_TERMIO */
1399 tty
.main
.tt_char
|= TT$M_NOECHO
;
1401 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1403 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1405 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1406 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1407 #else /* not VMS (BSD, that is) */
1409 Vtty_erase_char
= tty
.main
.sg_erase
;
1410 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1412 tty
.main
.sg_flags
|= ANYP
;
1413 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1414 #endif /* not DOS_NT */
1415 #endif /* not VMS (BSD, that is) */
1416 #endif /* not HAVE_TERMIO */
1418 /* If going to use CBREAK mode, we must request C-g to interrupt
1419 and turn off start and stop chars, etc. If not going to use
1420 CBREAK mode, do this anyway so as to turn off local flow
1421 control for user coming over network on 4.2; in this case,
1422 only t_stopc and t_startc really matter. */
1425 /* Note: if not using CBREAK mode, it makes no difference how we
1427 tty
.tchars
= new_tchars
;
1428 tty
.tchars
.t_intrc
= quit_char
;
1431 tty
.tchars
.t_startc
= '\021';
1432 tty
.tchars
.t_stopc
= '\023';
1435 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1437 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1438 anything, and leaving it in breaks the meta key. Go figure. */
1439 tty
.lmode
&= ~LLITOUT
;
1446 #endif /* HAVE_TCHARS */
1447 #endif /* not HAVE_TERMIO */
1450 tty
.ltchars
= new_ltchars
;
1451 #endif /* HAVE_LTCHARS */
1452 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1454 internal_terminal_init ();
1458 EMACS_SET_TTY (input_fd
, &tty
, 0);
1460 /* This code added to insure that, if flow-control is not to be used,
1461 we have an unlocked terminal at the start. */
1464 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1468 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1472 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1474 if (!flow_control
) tcflow (input_fd
, TCOON
);
1482 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1483 to be only LF. This is the way that is done. */
1486 if (ioctl (1, HFTGETID
, &tty
) != -1)
1487 write (1, "\033[20l", 5);
1493 /* Appears to do nothing when in PASTHRU mode.
1494 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1495 interrupt_signal, oob_chars, 0, 0, 0, 0);
1497 queue_kbd_input (0);
1502 #ifndef F_SETOWN_BUG
1503 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1505 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1507 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1508 fcntl (input_fd
, F_SETOWN
, getpid ());
1509 init_sigio (input_fd
);
1511 #endif /* F_GETOWN */
1512 #endif /* F_SETOWN_BUG */
1513 #endif /* F_SETFL */
1516 if (interrupt_input
)
1517 init_sigio (input_fd
);
1520 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1524 /* This symbol is defined on recent USG systems.
1525 Someone says without this call USG won't really buffer the file
1526 even with a call to setbuf. */
1527 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
1529 setbuf (stdout
, _sobuf
);
1531 #ifdef HAVE_WINDOW_SYSTEM
1532 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1533 needs the initialization code below. */
1534 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1536 set_terminal_modes ();
1538 if (term_initted
&& no_redraw_on_reenter
)
1540 if (display_completed
)
1541 direct_output_forward_char (0);
1546 if (FRAMEP (Vterminal_frame
))
1547 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1553 /* Return nonzero if safe to use tabs in output.
1554 At the time this is called, init_sys_modes has not been done yet. */
1558 struct emacs_tty tty
;
1560 EMACS_GET_TTY (input_fd
, &tty
);
1561 return EMACS_TTY_TABS_OK (&tty
);
1564 /* Get terminal size from system.
1565 Store number of lines into *HEIGHTP and width into *WIDTHP.
1566 We store 0 if there's no valid information. */
1568 get_frame_size (widthp
, heightp
)
1569 int *widthp
, *heightp
;
1575 struct winsize size
;
1577 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1578 *widthp
= *heightp
= 0;
1581 *widthp
= size
.ws_col
;
1582 *heightp
= size
.ws_row
;
1588 /* SunOS - style. */
1589 struct ttysize size
;
1591 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1592 *widthp
= *heightp
= 0;
1595 *widthp
= size
.ts_cols
;
1596 *heightp
= size
.ts_lines
;
1602 struct sensemode tty
;
1604 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1605 &tty
.class, 12, 0, 0, 0, 0);
1606 *widthp
= tty
.scr_wid
;
1607 *heightp
= tty
.scr_len
;
1611 *widthp
= ScreenCols ();
1612 *heightp
= ScreenRows ();
1613 #else /* system doesn't know size */
1618 #endif /* not VMS */
1619 #endif /* not SunOS-style */
1620 #endif /* not BSD-style */
1623 /* Set the logical window size associated with descriptor FD
1624 to HEIGHT and WIDTH. This is used mainly with ptys. */
1627 set_window_size (fd
, height
, width
)
1628 int fd
, height
, width
;
1633 struct winsize size
;
1634 size
.ws_row
= height
;
1635 size
.ws_col
= width
;
1637 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1638 return 0; /* error */
1645 /* SunOS - style. */
1646 struct ttysize size
;
1647 size
.ts_lines
= height
;
1648 size
.ts_cols
= width
;
1650 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1656 #endif /* not SunOS-style */
1657 #endif /* not BSD-style */
1661 /* Prepare the terminal for exiting Emacs; move the cursor to the
1662 bottom of the frame, turn off interrupt-driven I/O, etc. */
1672 #ifdef HAVE_WINDOW_SYSTEM
1673 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1674 needs the clean-up code below. */
1675 if (read_socket_hook
|| !EQ (Vwindow_system
, Qnil
))
1678 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1679 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1680 /* clear_end_of_line may move the cursor */
1681 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1682 #if defined (IBMR2AIX) && defined (AIXHFT)
1684 /* HFT devices normally use ^J as a LF/CR. We forced it to
1685 do the LF only. Now, we need to reset it. */
1688 if (ioctl (1, HFTGETID
, &tty
) != -1)
1689 write (1, "\033[20h", 5);
1693 reset_terminal_modes ();
1697 /* Avoid possible loss of output when changing terminal modes. */
1698 fsync (fileno (stdout
));
1703 #ifndef F_SETOWN_BUG
1704 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1705 if (interrupt_input
)
1708 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1710 #endif /* F_SETOWN */
1711 #endif /* F_SETOWN_BUG */
1713 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1715 #endif /* F_SETFL */
1717 if (interrupt_input
)
1722 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1725 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1729 #ifdef SET_LINE_DISCIPLINE
1730 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1731 A different old line discipline is therefore not restored, yet.
1732 Restore the old line discipline by hand. */
1733 ioctl (0, TIOCSETD
, &old_tty
.main
.c_line
);
1741 widen_foreground_group ();
1747 /* Set up the proper status flags for use of a pty. */
1752 /* I'm told that TOICREMOTE does not mean control chars
1753 "can't be sent" but rather that they don't have
1754 input-editing or signaling effects.
1755 That should be good, because we have other ways
1756 to do those things in Emacs.
1757 However, telnet mode seems not to work on 4.2.
1758 So TIOCREMOTE is turned off now. */
1760 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1761 will hang. In particular, the "timeout" feature (which
1762 causes a read to return if there is no data available)
1763 does this. Also it is known that telnet mode will hang
1764 in such a way that Emacs must be stopped (perhaps this
1765 is the same problem).
1767 If TIOCREMOTE is turned off, then there is a bug in
1768 hp-ux which sometimes loses data. Apparently the
1769 code which blocks the master process when the internal
1770 buffer fills up does not work. Other than this,
1771 though, everything else seems to work fine.
1773 Since the latter lossage is more benign, we may as well
1774 lose that way. -- cph */
1779 ioctl (fd
, FIONBIO
, &on
);
1784 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1785 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1786 /* cause EMACS not to die when it should, i.e., when its own controlling */
1787 /* tty goes away. I've complained to the AIX developers, and they may */
1788 /* change this behavior, but I'm not going to hold my breath. */
1789 signal (SIGHUP
, SIG_IGN
);
1792 #endif /* HAVE_PTYS */
1796 /* Assigning an input channel is done at the start of Emacs execution.
1797 This is called each time Emacs is resumed, also, but does nothing
1798 because input_chain is no longer zero. */
1806 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1812 /* Deassigning the input channel is done before exiting. */
1816 return SYS$
DASSGN (input_fd
);
1821 /* Request reading one character into the keyboard buffer.
1822 This is done as soon as the buffer becomes empty. */
1827 extern kbd_input_ast ();
1829 waiting_for_ast
= 0;
1831 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1832 &input_iosb
, kbd_input_ast
, 1,
1833 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1838 /* Ast routine that is called when keyboard input comes in
1839 in accord with the SYS$QIO above. */
1843 register int c
= -1;
1844 int old_errno
= errno
;
1845 extern EMACS_TIME
*input_available_clear_time
;
1847 if (waiting_for_ast
)
1848 SYS$
SETEF (input_ef
);
1849 waiting_for_ast
= 0;
1852 if (input_count
== 25)
1854 printf ("Ast # %d,", input_count
);
1855 printf (" iosb = %x, %x, %x, %x",
1856 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1859 if (input_iosb
.offset
)
1863 printf (", char = 0%o", c
);
1875 struct input_event e
;
1876 e
.kind
= ascii_keystroke
;
1877 XSETINT (e
.code
, c
);
1878 XSETFRAME (e
.frame_or_window
, selected_frame
);
1879 kbd_buffer_store_event (&e
);
1881 if (input_available_clear_time
)
1882 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1886 /* Wait until there is something in kbd_buffer. */
1888 wait_for_kbd_input ()
1890 extern int have_process_input
, process_exited
;
1892 /* If already something, avoid doing system calls. */
1893 if (detect_input_pending ())
1897 /* Clear a flag, and tell ast routine above to set it. */
1898 SYS$
CLREF (input_ef
);
1899 waiting_for_ast
= 1;
1900 /* Check for timing error: ast happened while we were doing that. */
1901 if (!detect_input_pending ())
1903 /* No timing error: wait for flag to be set. */
1904 set_waiting_for_input (0);
1905 SYS$
WFLOR (input_ef
, input_eflist
);
1906 clear_waiting_for_input (0);
1907 if (!detect_input_pending ())
1908 /* Check for subprocess input availability */
1910 int dsp
= have_process_input
|| process_exited
;
1912 SYS$
CLREF (process_ef
);
1913 if (have_process_input
)
1914 process_command_input ();
1919 update_mode_lines
++;
1920 prepare_menu_bars ();
1921 redisplay_preserve_echo_area ();
1925 waiting_for_ast
= 0;
1928 /* Get rid of any pending QIO, when we are about to suspend
1929 or when we want to throw away pending input.
1930 We wait for a positive sign that the AST routine has run
1931 and therefore there is no I/O request queued when we return.
1932 SYS$SETAST is used to avoid a timing error. */
1937 printf ("At end_kbd_input.\n");
1941 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
1943 SYS$
CANCEL (input_fd
);
1948 /* Clear a flag, and tell ast routine above to set it. */
1949 SYS$
CLREF (input_ef
);
1950 waiting_for_ast
= 1;
1952 SYS$
CANCEL (input_fd
);
1954 SYS$
WAITFR (input_ef
);
1955 waiting_for_ast
= 0;
1958 /* Wait for either input available or time interval expiry. */
1960 input_wait_timeout (timeval
)
1961 int timeval
; /* Time to wait, in seconds */
1964 static int zero
= 0;
1965 static int large
= -10000000;
1967 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1969 /* If already something, avoid doing system calls. */
1970 if (detect_input_pending ())
1974 /* Clear a flag, and tell ast routine above to set it. */
1975 SYS$
CLREF (input_ef
);
1976 waiting_for_ast
= 1;
1977 /* Check for timing error: ast happened while we were doing that. */
1978 if (!detect_input_pending ())
1980 /* No timing error: wait for flag to be set. */
1982 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1983 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
1985 waiting_for_ast
= 0;
1988 /* The standard `sleep' routine works some other way
1989 and it stops working if you have ever quit out of it.
1990 This one continues to work. */
1996 static int zero
= 0;
1997 static int large
= -10000000;
1999 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2002 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2003 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2019 croak ("request sigio");
2024 croak ("unrequest sigio");
2029 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2034 #ifndef SYSTEM_MALLOC
2041 /* Some systems that cannot dump also cannot implement these. */
2044 * Return the address of the start of the text segment prior to
2045 * doing an unexec. After unexec the return value is undefined.
2046 * See crt0.c for further explanation and _start.
2050 #ifndef HAVE_TEXT_START
2055 return ((char *) TEXT_START
);
2059 return ((char *) csrt
);
2060 #else /* not GOULD */
2061 extern int _start ();
2062 return ((char *) _start
);
2064 #endif /* TEXT_START */
2066 #endif /* not HAVE_TEXT_START */
2069 * Return the address of the start of the data segment prior to
2070 * doing an unexec. After unexec the return value is undefined.
2071 * See crt0.c for further information and definition of data_start.
2073 * Apparently, on BSD systems this is etext at startup. On
2074 * USG systems (swapping) this is highly mmu dependent and
2075 * is also dependent on whether or not the program is running
2076 * with shared text. Generally there is a (possibly large)
2077 * gap between end of text and start of data with shared text.
2079 * On Uniplus+ systems with shared text, data starts at a
2080 * fixed address. Each port (from a given oem) is generally
2081 * different, and the specific value of the start of data can
2082 * be obtained via the UniPlus+ specific "uvar" system call,
2083 * however the method outlined in crt0.c seems to be more portable.
2085 * Probably what will have to happen when a USG unexec is available,
2086 * at least on UniPlus, is temacs will have to be made unshared so
2087 * that text and data are contiguous. Then once loadup is complete,
2088 * unexec will produce a shared executable where the data can be
2089 * at the normal shared text boundary and the startofdata variable
2090 * will be patched by unexec to the correct value.
2098 return ((char *) DATA_START
);
2100 #ifdef ORDINARY_LINK
2102 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2103 * data_start isn't defined. We take the address of environ, which
2104 * is known to live at or near the start of the system crt0.c, and
2105 * we don't sweat the handful of bytes that might lose.
2107 extern char **environ
;
2109 return((char *) &environ
);
2111 extern int data_start
;
2112 return ((char *) &data_start
);
2113 #endif /* ORDINARY_LINK */
2114 #endif /* DATA_START */
2116 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2119 /* Some systems that cannot dump also cannot implement these. */
2122 * Return the address of the end of the text segment prior to
2123 * doing an unexec. After unexec the return value is undefined.
2130 return ((char *) TEXT_END
);
2133 return ((char *) &etext
);
2138 * Return the address of the end of the data segment prior to
2139 * doing an unexec. After unexec the return value is undefined.
2146 return ((char *) DATA_END
);
2149 return ((char *) &edata
);
2153 #endif /* not CANNOT_DUMP */
2155 /* init_system_name sets up the string for the Lisp function
2156 system-name to return. */
2162 extern Lisp_Object Vsystem_name
;
2167 #include <sys/socket.h>
2169 #endif /* HAVE_SOCKETS */
2170 #endif /* not VMS */
2171 #endif /* not BSD4_1 */
2177 Vsystem_name
= build_string (sysname
);
2181 if ((sp
= egetenv ("SYS$NODE")) == 0)
2182 Vsystem_name
= build_string ("vax-vms");
2183 else if ((end
= index (sp
, ':')) == 0)
2184 Vsystem_name
= build_string (sp
);
2186 Vsystem_name
= make_string (sp
, end
- sp
);
2188 #ifndef HAVE_GETHOSTNAME
2191 Vsystem_name
= build_string (uts
.nodename
);
2192 #else /* HAVE_GETHOSTNAME */
2193 unsigned int hostname_size
= 256;
2194 char *hostname
= (char *) alloca (hostname_size
);
2196 /* Try to get the host name; if the buffer is too short, try
2197 again. Apparently, the only indication gethostname gives of
2198 whether the buffer was large enough is the presence or absence
2199 of a '\0' in the string. Eech. */
2202 gethostname (hostname
, hostname_size
- 1);
2203 hostname
[hostname_size
- 1] = '\0';
2205 /* Was the buffer large enough for the '\0'? */
2206 if (strlen (hostname
) < hostname_size
- 1)
2209 hostname_size
<<= 1;
2210 hostname
= (char *) alloca (hostname_size
);
2213 /* Turn the hostname into the official, fully-qualified hostname.
2214 Don't do this if we're going to dump; this can confuse system
2215 libraries on some machines and make the dumped emacs core dump. */
2218 #endif /* not CANNOT_DUMP */
2222 for (count
= 0;; count
++)
2227 hp
= gethostbyname (hostname
);
2229 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2234 Fsleep_for (make_number (1), Qnil
);
2238 char *fqdn
= (char *) hp
->h_name
;
2241 if (!index (fqdn
, '.'))
2243 /* We still don't have a fully qualified domain name.
2244 Try to find one in the list of alternate names */
2245 char **alias
= hp
->h_aliases
;
2246 while (*alias
&& !index (*alias
, '.'))
2253 /* Convert the host name to lower case. */
2254 /* Using ctype.h here would introduce a possible locale
2255 dependence that is probably wrong for hostnames. */
2259 if (*p
>= 'A' && *p
<= 'Z')
2266 #endif /* HAVE_SOCKETS */
2267 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN)) || HAVE_GETDOMAINNAME
2268 if (! index (hostname
, '.'))
2270 /* The hostname is not fully qualified. Append the domain name. */
2272 int hostlen
= strlen (hostname
);
2273 int domain_size
= 256;
2277 char *domain
= (char *) alloca (domain_size
+ 1);
2278 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2279 #if HAVE_SYSINFO && defined (SI_SRPC_DOMAIN)
2280 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2281 if (sys_domain_size
<= 0)
2283 if (domain_size
< sys_domain_size
)
2285 domain_size
= sys_domain_size
;
2288 #else /* HAVE_GETDOMAINNAME */
2289 if (getdomainname (domain
, domain_size
- 1) != 0 || ! *domain
)
2291 domain
[domain_size
- 1] = '\0';
2292 if (strlen (domain
) == domain_size
- 1)
2297 /* If we get an answer which means "domain unknown",
2298 don't use a domain. */
2299 if (!strcmp (domain
, "(none)"))
2304 #endif /* HAVE_GETDOMAINNAME */
2305 strcpy (fqdn
, hostname
);
2306 if (domain
[0] == '.')
2307 strcpy (fqdn
+ hostlen
, domain
);
2310 fqdn
[hostlen
] = '.';
2311 strcpy (fqdn
+ hostlen
+ 1, domain
);
2317 #endif /*! ((HAVE_SYSINFO && defined (SI_SRPC_DOMAIN)) || HAVE_GETDOMAINNAME)*/
2318 Vsystem_name
= build_string (hostname
);
2319 #endif /* HAVE_GETHOSTNAME */
2324 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2325 if (*p
== ' ' || *p
== '\t')
2332 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2334 #include "sysselect.h"
2337 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2338 /* Cause explanatory error message at compile time,
2339 since the select emulation is not good enough for X. */
2340 int *x
= &x_windows_lose_if_no_select_system_call
;
2343 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2344 * Only checks read descriptors.
2346 /* How long to wait between checking fds in select */
2347 #define SELECT_PAUSE 1
2350 /* For longjmp'ing back to read_input_waiting. */
2352 jmp_buf read_alarm_throw
;
2354 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2355 The read_socket_hook function sets this to 1 while it is waiting. */
2357 int read_alarm_should_throw
;
2365 #else /* not BSD4_1 */
2366 signal (SIGALRM
, SIG_IGN
);
2367 #endif /* not BSD4_1 */
2368 if (read_alarm_should_throw
)
2369 longjmp (read_alarm_throw
, 1);
2373 /* Only rfds are checked. */
2375 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2377 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2378 EMACS_TIME
*timeout
;
2380 int ravail
= 0, old_alarm
;
2384 extern int proc_buffered_char
[];
2385 #ifndef subprocesses
2386 int process_tick
= 0, update_tick
= 0;
2388 extern int process_tick
, update_tick
;
2390 SIGTYPE (*old_trap
) ();
2393 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2394 /* If we're using X, then the native select will work; we only need the
2395 emulation for non-X usage. */
2396 if (!NILP (Vwindow_system
))
2397 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2399 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2400 local_timeout
= &timeoutval
;
2412 /* If we are looking only for the terminal, with no timeout,
2413 just read it and wait -- that's more efficient. */
2414 if (*local_timeout
== 100000 && process_tick
== update_tick
2415 && FD_ISSET (0, &orfds
))
2418 for (fd
= 1; fd
< nfds
; ++fd
)
2419 if (FD_ISSET (fd
, &orfds
))
2421 if (! detect_input_pending ())
2422 read_input_waiting ();
2428 /* Once a second, till the timer expires, check all the flagged read
2429 * descriptors to see if any input is available. If there is some then
2430 * set the corresponding bit in the return copy of rfds.
2434 register int to_check
, fd
;
2438 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2440 if (FD_ISSET (fd
, &orfds
))
2442 int avail
= 0, status
= 0;
2445 avail
= detect_input_pending (); /* Special keyboard handler */
2449 status
= ioctl (fd
, FIONREAD
, &avail
);
2450 #else /* no FIONREAD */
2451 /* Hoping it will return -1 if nothing available
2452 or 0 if all 0 chars requested are read. */
2453 if (proc_buffered_char
[fd
] >= 0)
2457 avail
= read (fd
, &buf
, 1);
2459 proc_buffered_char
[fd
] = buf
;
2461 #endif /* no FIONREAD */
2463 if (status
>= 0 && avail
> 0)
2471 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2473 old_alarm
= alarm (0);
2474 old_trap
= signal (SIGALRM
, select_alarm
);
2476 alarm (SELECT_PAUSE
);
2477 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2478 while (select_alarmed
== 0 && *local_timeout
!= 0
2479 && process_tick
== update_tick
)
2481 /* If we are interested in terminal input,
2482 wait by reading the terminal.
2483 That makes instant wakeup for terminal input at least. */
2484 if (FD_ISSET (0, &orfds
))
2486 read_input_waiting ();
2487 if (detect_input_pending ())
2493 (*local_timeout
) -= SELECT_PAUSE
;
2494 /* Reset the old alarm if there was one */
2496 signal (SIGALRM
, old_trap
);
2499 /* Reset or forge an interrupt for the original handler. */
2500 old_alarm
-= SELECT_PAUSE
;
2502 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2506 if (*local_timeout
== 0) /* Stop on timer being cleared */
2511 #endif /* not WINDOWSNT */
2513 /* Read keyboard input into the standard buffer,
2514 waiting for at least one character. */
2516 /* Make all keyboard buffers much bigger when using a window system. */
2517 #ifdef HAVE_WINDOW_SYSTEM
2518 #define BUFFER_SIZE_FACTOR 16
2520 #define BUFFER_SIZE_FACTOR 1
2523 read_input_waiting ()
2525 struct input_event e
;
2527 extern int quit_char
;
2529 if (read_socket_hook
)
2531 struct input_event buf
[256];
2533 read_alarm_should_throw
= 0;
2534 if (! setjmp (read_alarm_throw
))
2535 nread
= (*read_socket_hook
) (0, buf
, 256, 1, 0);
2539 /* Scan the chars for C-g and store them in kbd_buffer. */
2540 for (i
= 0; i
< nread
; i
++)
2542 kbd_buffer_store_event (&buf
[i
]);
2543 /* Don't look at input that follows a C-g too closely.
2544 This reduces lossage due to autorepeat on C-g. */
2545 if (buf
[i
].kind
== ascii_keystroke
2546 && buf
[i
].code
== quit_char
)
2553 nread
= read (fileno (stdin
), buf
, 1);
2555 /* Scan the chars for C-g and store them in kbd_buffer. */
2556 e
.kind
= ascii_keystroke
;
2557 XSETFRAME (e
.frame_or_window
, selected_frame
);
2559 for (i
= 0; i
< nread
; i
++)
2561 /* Convert chars > 0177 to meta events if desired.
2562 We do this under the same conditions that read_avail_input does. */
2563 if (read_socket_hook
== 0)
2565 /* If the user says she has a meta key, then believe her. */
2566 if (meta_key
== 1 && (buf
[i
] & 0x80))
2567 e
.modifiers
= meta_modifier
;
2572 XSETINT (e
.code
, buf
[i
]);
2573 kbd_buffer_store_event (&e
);
2574 /* Don't look at input that follows a C-g too closely.
2575 This reduces lossage due to autorepeat on C-g. */
2576 if (buf
[i
] == quit_char
)
2582 #endif /* not HAVE_SELECT */
2583 #endif /* not VMS */
2584 #endif /* not MSDOS */
2588 * Partially emulate 4.2 open call.
2589 * open is defined as this in 4.1.
2591 * - added by Michael Bloom @ Citicorp/TTI
2596 sys_open (path
, oflag
, mode
)
2600 if (oflag
& O_CREAT
)
2601 return creat (path
, mode
);
2603 return open (path
, oflag
);
2611 lmode
= LINTRUP
| lmode
;
2612 ioctl (fd
, TIOCLSET
, &lmode
);
2619 lmode
= ~LINTRUP
& lmode
;
2620 ioctl (0, TIOCLSET
, &lmode
);
2627 interrupts_deferred
= 0;
2634 interrupts_deferred
= 1;
2637 /* still inside #ifdef BSD4_1 */
2640 int sigheld
; /* Mask of held signals */
2645 sigheld
|= sigbit (signum
);
2652 sigheld
|= sigbit (signum
);
2658 sigheld
&= ~sigbit (signum
);
2662 sigfree () /* Free all held signals */
2665 for (i
= 0; i
< NSIG
; i
++)
2666 if (sigheld
& sigbit (i
))
2673 return 1 << (i
- 1);
2675 #endif /* subprocesses */
2678 /* POSIX signals support - DJB */
2679 /* Anyone with POSIX signals should have ANSI C declarations */
2681 #ifdef POSIX_SIGNALS
2683 sigset_t old_mask
, empty_mask
, full_mask
, temp_mask
;
2684 static struct sigaction new_action
, old_action
;
2688 sigemptyset (&empty_mask
);
2689 sigfillset (&full_mask
);
2693 sys_signal (int signal_number
, signal_handler_t action
)
2695 sigemptyset (&new_action
.sa_mask
);
2696 new_action
.sa_handler
= action
;
2698 /* Emacs mostly works better with restartable system services. If this
2699 * flag exists, we probably want to turn it on here.
2701 new_action
.sa_flags
= SA_RESTART
;
2703 new_action
.sa_flags
= 0;
2705 sigaction (signal_number
, &new_action
, &old_action
);
2706 return (old_action
.sa_handler
);
2710 /* If we're compiling with GCC, we don't need this function, since it
2711 can be written as a macro. */
2713 sys_sigmask (int sig
)
2716 sigemptyset (&mask
);
2717 sigaddset (&mask
, sig
);
2723 sys_sigpause (sigset_t new_mask
)
2725 /* pause emulating berk sigpause... */
2726 sigsuspend (&new_mask
);
2730 /* I'd like to have these guys return pointers to the mask storage in here,
2731 but there'd be trouble if the code was saving multiple masks. I'll be
2732 safe and pass the structure. It normally won't be more than 2 bytes
2736 sys_sigblock (sigset_t new_mask
)
2739 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2744 sys_sigunblock (sigset_t new_mask
)
2747 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2752 sys_sigsetmask (sigset_t new_mask
)
2755 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2759 #endif /* POSIX_SIGNALS */
2767 /* Figure out how many bits the system's random number generator uses.
2768 `random' and `lrand48' are assumed to return 31 usable bits.
2769 BSD `rand' returns a 31 bit value but the low order bits are unusable;
2770 so we'll shift it and treat it like the 15-bit USG `rand'. */
2774 # define RAND_BITS 31
2775 # else /* !HAVE_RANDOM */
2776 # ifdef HAVE_LRAND48
2777 # define RAND_BITS 31
2778 # define random lrand48
2779 # else /* !HAVE_LRAND48 */
2780 # define RAND_BITS 15
2781 # if RAND_MAX == 32767
2782 # define random rand
2783 # else /* RAND_MAX != 32767 */
2784 # if RAND_MAX == 2147483647
2785 # define random() (rand () >> 16)
2786 # else /* RAND_MAX != 2147483647 */
2788 # define random rand
2790 # define random() (rand () >> 16)
2792 # endif /* RAND_MAX != 2147483647 */
2793 # endif /* RAND_MAX != 32767 */
2794 # endif /* !HAVE_LRAND48 */
2795 # endif /* !HAVE_RANDOM */
2796 #endif /* !RAND_BITS */
2803 srandom ((unsigned int)arg
);
2805 # ifdef HAVE_LRAND48
2808 srand ((unsigned int)arg
);
2814 * Build a full Emacs-sized word out of whatever we've got.
2815 * This suffices even for a 64-bit architecture with a 15-bit rand.
2820 long val
= random ();
2821 #if VALBITS > RAND_BITS
2822 val
= (val
<< RAND_BITS
) ^ random ();
2823 #if VALBITS > 2*RAND_BITS
2824 val
= (val
<< RAND_BITS
) ^ random ();
2825 #if VALBITS > 3*RAND_BITS
2826 val
= (val
<< RAND_BITS
) ^ random ();
2827 #if VALBITS > 4*RAND_BITS
2828 val
= (val
<< RAND_BITS
) ^ random ();
2829 #endif /* need at least 5 */
2830 #endif /* need at least 4 */
2831 #endif /* need at least 3 */
2832 #endif /* need at least 2 */
2833 return val
& ((1L << VALBITS
) - 1);
2836 #ifdef WRONG_NAME_INSQUE
2849 /* If any place else asks for the TERM variable,
2850 allow it to be overridden with the EMACS_TERM variable
2851 before attempting to translate the logical name TERM. As a last
2852 resort, ask for VAX C's special idea of the TERM variable. */
2859 static char buf
[256];
2860 static struct dsc$descriptor_s equiv
2861 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2862 static struct dsc$descriptor_s d_name
2863 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2866 if (!strcmp (name
, "TERM"))
2868 val
= (char *) getenv ("EMACS_TERM");
2873 d_name
.dsc$w_length
= strlen (name
);
2874 d_name
.dsc$a_pointer
= name
;
2875 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2877 char *str
= (char *) xmalloc (eqlen
+ 1);
2878 bcopy (buf
, str
, eqlen
);
2880 /* This is a storage leak, but a pain to fix. With luck,
2881 no one will ever notice. */
2884 return (char *) getenv (name
);
2889 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2890 to force a call on the debugger from within the image. */
2895 LIB$
SIGNAL (SS$_DEBUG
);
2901 #ifdef LINK_CRTL_SHARE
2902 #ifdef SHARABLE_LIB_BUG
2903 /* Variables declared noshare and initialized in sharable libraries
2904 cannot be shared. The VMS linker incorrectly forces you to use a private
2905 version which is uninitialized... If not for this "feature", we
2906 could use the C library definition of sys_nerr and sys_errlist. */
2908 char *sys_errlist
[] =
2912 "no such file or directory",
2914 "interrupted system call",
2916 "no such device or address",
2917 "argument list too long",
2918 "exec format error",
2921 "no more processes",
2922 "not enough memory",
2923 "permission denied",
2925 "block device required",
2926 "mount devices busy",
2928 "cross-device link",
2933 "file table overflow",
2934 "too many open files",
2938 "no space left on device",
2940 "read-only file system",
2946 "vax/vms specific error code nontranslatable error"
2948 #endif /* SHARABLE_LIB_BUG */
2949 #endif /* LINK_CRTL_SHARE */
2952 #ifndef HAVE_STRERROR
2958 extern char *sys_errlist
[];
2959 extern int sys_nerr
;
2961 if (errnum
>= 0 && errnum
< sys_nerr
)
2962 return sys_errlist
[errnum
];
2963 return (char *) "Unknown error";
2965 #endif /* not WINDOWSNT */
2966 #endif /* ! HAVE_STRERROR */
2968 #ifdef INTERRUPTIBLE_OPEN
2972 sys_open (path
, oflag
, mode
)
2976 register int rtnval
;
2978 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2979 && (errno
== EINTR
));
2983 #endif /* INTERRUPTIBLE_OPEN */
2985 #ifdef INTERRUPTIBLE_CLOSE
2991 register int rtnval
;
2993 while ((rtnval
= close (fd
)) == -1
2994 && (errno
== EINTR
))
2997 /* If close is interrupted SunOS 4.1 may or may not have closed the
2998 file descriptor. If it did the second close will fail with
2999 errno = EBADF. That means we have succeeded. */
3000 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3006 #endif /* INTERRUPTIBLE_CLOSE */
3008 #ifdef INTERRUPTIBLE_IO
3011 sys_read (fildes
, buf
, nbyte
)
3016 register int rtnval
;
3018 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3019 && (errno
== EINTR
));
3024 sys_write (fildes
, buf
, nbyte
)
3029 register int rtnval
, bytes_written
;
3035 rtnval
= write (fildes
, buf
, nbyte
);
3042 return (bytes_written
? bytes_written
: -1);
3047 bytes_written
+= rtnval
;
3049 return (bytes_written
);
3052 #endif /* INTERRUPTIBLE_IO */
3057 * Substitute fork for vfork on USG flavors.
3065 #endif /* not WINDOWSNT */
3066 #endif /* not HAVE_VFORK */
3070 * All of the following are for USG.
3072 * On USG systems the system calls are INTERRUPTIBLE by signals
3073 * that the user program has elected to catch. Thus the system call
3074 * must be retried in these cases. To handle this without massive
3075 * changes in the source code, we remap the standard system call names
3076 * to names for our own functions in sysdep.c that do the system call
3077 * with retries. Actually, for portability reasons, it is good
3078 * programming practice, as this example shows, to limit all actual
3079 * system calls to a single occurrence in the source. Sure, this
3080 * adds an extra level of function call overhead but it is almost
3081 * always negligible. Fred Fish, Unisoft Systems Inc.
3084 #ifndef HAVE_SYS_SIGLIST
3085 char *sys_siglist
[NSIG
+ 1] =
3088 /* AIX has changed the signals a bit */
3089 "bogus signal", /* 0 */
3090 "hangup", /* 1 SIGHUP */
3091 "interrupt", /* 2 SIGINT */
3092 "quit", /* 3 SIGQUIT */
3093 "illegal instruction", /* 4 SIGILL */
3094 "trace trap", /* 5 SIGTRAP */
3095 "IOT instruction", /* 6 SIGIOT */
3096 "crash likely", /* 7 SIGDANGER */
3097 "floating point exception", /* 8 SIGFPE */
3098 "kill", /* 9 SIGKILL */
3099 "bus error", /* 10 SIGBUS */
3100 "segmentation violation", /* 11 SIGSEGV */
3101 "bad argument to system call", /* 12 SIGSYS */
3102 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3103 "alarm clock", /* 14 SIGALRM */
3104 "software termination signum", /* 15 SIGTERM */
3105 "user defined signal 1", /* 16 SIGUSR1 */
3106 "user defined signal 2", /* 17 SIGUSR2 */
3107 "death of a child", /* 18 SIGCLD */
3108 "power-fail restart", /* 19 SIGPWR */
3109 "bogus signal", /* 20 */
3110 "bogus signal", /* 21 */
3111 "bogus signal", /* 22 */
3112 "bogus signal", /* 23 */
3113 "bogus signal", /* 24 */
3114 "LAN I/O interrupt", /* 25 SIGAIO */
3115 "PTY I/O interrupt", /* 26 SIGPTY */
3116 "I/O intervention required", /* 27 SIGIOINT */
3118 "HFT grant", /* 28 SIGGRANT */
3119 "HFT retract", /* 29 SIGRETRACT */
3120 "HFT sound done", /* 30 SIGSOUND */
3121 "HFT input ready", /* 31 SIGMSG */
3124 "bogus signal", /* 0 */
3125 "hangup", /* 1 SIGHUP */
3126 "interrupt", /* 2 SIGINT */
3127 "quit", /* 3 SIGQUIT */
3128 "illegal instruction", /* 4 SIGILL */
3129 "trace trap", /* 5 SIGTRAP */
3130 "IOT instruction", /* 6 SIGIOT */
3131 "EMT instruction", /* 7 SIGEMT */
3132 "floating point exception", /* 8 SIGFPE */
3133 "kill", /* 9 SIGKILL */
3134 "bus error", /* 10 SIGBUS */
3135 "segmentation violation", /* 11 SIGSEGV */
3136 "bad argument to system call", /* 12 SIGSYS */
3137 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3138 "alarm clock", /* 14 SIGALRM */
3139 "software termination signum", /* 15 SIGTERM */
3140 "user defined signal 1", /* 16 SIGUSR1 */
3141 "user defined signal 2", /* 17 SIGUSR2 */
3142 "death of a child", /* 18 SIGCLD */
3143 "power-fail restart", /* 19 SIGPWR */
3145 "window size change", /* 20 SIGWINCH */
3146 "urgent socket condition", /* 21 SIGURG */
3147 "pollable event occurred", /* 22 SIGPOLL */
3148 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */
3149 "user stop requested from tty", /* 24 SIGTSTP */
3150 "stopped process has been continued", /* 25 SIGCONT */
3151 "background tty read attempted", /* 26 SIGTTIN */
3152 "background tty write attempted", /* 27 SIGTTOU */
3153 "virtual timer expired", /* 28 SIGVTALRM */
3154 "profiling timer expired", /* 29 SIGPROF */
3155 "exceeded cpu limit", /* 30 SIGXCPU */
3156 "exceeded file size limit", /* 31 SIGXFSZ */
3157 "process's lwps are blocked", /* 32 SIGWAITING */
3158 "special signal used by thread library", /* 33 SIGLWP */
3160 "Special Signal Used By CPR", /* 34 SIGFREEZE */
3163 "Special Signal Used By CPR", /* 35 SIGTHAW */
3166 #endif /* not AIX */
3169 #endif /* HAVE_SYS_SIGLIST */
3172 * Warning, this function may not duplicate 4.2 action properly
3173 * under error conditions.
3177 /* In 4.1, param.h fails to define this. */
3178 #define MAXPATHLEN 1024
3187 char *npath
, *spath
;
3188 extern char *getcwd ();
3190 BLOCK_INPUT
; /* getcwd uses malloc */
3191 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3194 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3195 up to first slash. Should be harmless on other systems. */
3196 while (*npath
&& *npath
!= '/')
3198 strcpy (pathname
, npath
);
3199 free (spath
); /* getcwd uses malloc */
3204 #endif /* HAVE_GETWD */
3207 * Emulate rename using unlink/link. Note that this is
3208 * only partially correct. Also, doesn't enforce restriction
3209 * that files be of same type (regular->regular, dir->dir, etc).
3218 if (access (from
, 0) == 0)
3221 if (link (from
, to
) == 0)
3222 if (unlink (from
) == 0)
3234 /* HPUX curses library references perror, but as far as we know
3235 it won't be called. Anyway this definition will do for now. */
3241 #endif /* not HAVE_PERROR */
3247 * Emulate BSD dup2. First close newd if it already exists.
3248 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3249 * until we are, then close the unsuccessful ones.
3256 register int fd
, ret
;
3261 fd
= fcntl (oldd
, F_DUPFD
, newd
);
3263 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, strerror (errno
));
3270 ret
= dup2 (old
,new);
3276 #endif /* not HAVE_DUP2 */
3279 * Gettimeofday. Simulate as much as possible. Only accurate
3280 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3281 * Only needed when subprocesses are defined.
3286 #ifndef HAVE_GETTIMEOFDAY
3290 gettimeofday (tp
, tzp
)
3292 struct timezone
*tzp
;
3294 extern long time ();
3296 tp
->tv_sec
= time ((long *)0);
3299 tzp
->tz_minuteswest
= -1;
3305 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3308 * This function will go away as soon as all the stubs fixed. (fnf)
3314 printf ("%s not yet implemented\r\n", badfunc
);
3323 char *sys_siglist
[NSIG
+ 1] =
3325 "null signal", /* 0 SIGNULL */
3326 "hangup", /* 1 SIGHUP */
3327 "interrupt", /* 2 SIGINT */
3328 "quit", /* 3 SIGQUIT */
3329 "illegal instruction", /* 4 SIGILL */
3330 "trace trap", /* 5 SIGTRAP */
3331 "abort termination", /* 6 SIGABRT */
3332 "SIGEMT", /* 7 SIGEMT */
3333 "floating point exception", /* 8 SIGFPE */
3334 "kill", /* 9 SIGKILL */
3335 "bus error", /* 10 SIGBUS */
3336 "segmentation violation", /* 11 SIGSEGV */
3337 "bad argument to system call", /* 12 SIGSYS */
3338 "write on a pipe with no reader", /* 13 SIGPIPE */
3339 "alarm clock", /* 14 SIGALRM */
3340 "software termination signal", /* 15 SIGTERM */
3341 "user defined signal 1", /* 16 SIGUSR1 */
3342 "user defined signal 2", /* 17 SIGUSR2 */
3343 "child stopped or terminated", /* 18 SIGCLD */
3344 "power-fail restart", /* 19 SIGPWR */
3345 "window size changed", /* 20 SIGWINCH */
3346 "undefined", /* 21 */
3347 "pollable event occurred", /* 22 SIGPOLL */
3348 "sendable stop signal not from tty", /* 23 SIGSTOP */
3349 "stop signal from tty", /* 24 SIGSTP */
3350 "continue a stopped process", /* 25 SIGCONT */
3351 "attempted background tty read", /* 26 SIGTTIN */
3352 "attempted background tty write", /* 27 SIGTTOU */
3353 "undefined", /* 28 */
3354 "undefined", /* 29 */
3355 "undefined", /* 30 */
3356 "undefined", /* 31 */
3357 "undefined", /* 32 */
3358 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
3359 "I/O is possible", /* 34 SIGIO */
3360 "exceeded cpu time limit", /* 35 SIGXCPU */
3361 "exceeded file size limit", /* 36 SIGXFSZ */
3362 "virtual time alarm", /* 37 SIGVTALRM */
3363 "profiling time alarm", /* 38 SIGPROF */
3364 "undefined", /* 39 */
3365 "file record locks revoked", /* 40 SIGLOST */
3366 "undefined", /* 41 */
3367 "undefined", /* 42 */
3368 "undefined", /* 43 */
3369 "undefined", /* 44 */
3370 "undefined", /* 45 */
3371 "undefined", /* 46 */
3372 "undefined", /* 47 */
3373 "undefined", /* 48 */
3374 "undefined", /* 49 */
3375 "undefined", /* 50 */
3376 "undefined", /* 51 */
3377 "undefined", /* 52 */
3378 "undefined", /* 53 */
3379 "undefined", /* 54 */
3380 "undefined", /* 55 */
3381 "undefined", /* 56 */
3382 "undefined", /* 57 */
3383 "undefined", /* 58 */
3384 "undefined", /* 59 */
3385 "undefined", /* 60 */
3386 "undefined", /* 61 */
3387 "undefined", /* 62 */
3388 "undefined", /* 63 */
3389 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3395 /* Directory routines for systems that don't have them. */
3397 #ifdef SYSV_SYSTEM_DIR
3401 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
3405 register DIR *dirp
; /* stream from opendir */
3409 rtnval
= sys_close (dirp
->dd_fd
);
3411 /* Some systems (like Solaris) allocate the buffer and the DIR all
3412 in one block. Why in the world are we freeing this ourselves
3414 #if ! (defined (sun) && defined (USG5_4))
3415 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3417 xfree ((char *) dirp
);
3421 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3422 #endif /* SYSV_SYSTEM_DIR */
3424 #ifdef NONSYSTEM_DIR_LIBRARY
3428 char *filename
; /* name of directory */
3430 register DIR *dirp
; /* -> malloc'ed storage */
3431 register int fd
; /* file descriptor for read */
3432 struct stat sbuf
; /* result of fstat */
3434 fd
= sys_open (filename
, 0);
3439 if (fstat (fd
, &sbuf
) < 0
3440 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3441 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
3445 return 0; /* bad luck today */
3450 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3457 register DIR *dirp
; /* stream from opendir */
3459 sys_close (dirp
->dd_fd
);
3460 xfree ((char *) dirp
);
3468 ino_t od_ino
; /* inode */
3469 char od_name
[DIRSIZ
]; /* filename */
3471 #endif /* not VMS */
3473 struct direct dir_static
; /* simulated directory contents */
3478 register DIR *dirp
; /* stream from opendir */
3481 register struct olddir
*dp
; /* -> directory data */
3483 register struct dir$_name
*dp
; /* -> directory data */
3484 register struct dir$_version
*dv
; /* -> version data */
3489 if (dirp
->dd_loc
>= dirp
->dd_size
)
3490 dirp
->dd_loc
= dirp
->dd_size
= 0;
3492 if (dirp
->dd_size
== 0 /* refill buffer */
3493 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3497 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3498 dirp
->dd_loc
+= sizeof (struct olddir
);
3500 if (dp
->od_ino
!= 0) /* not deleted entry */
3502 dir_static
.d_ino
= dp
->od_ino
;
3503 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3504 dir_static
.d_name
[DIRSIZ
] = '\0';
3505 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3506 dir_static
.d_reclen
= sizeof (struct direct
)
3508 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3509 return &dir_static
; /* -> simulated structure */
3512 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3513 if (dirp
->dd_loc
== 0)
3514 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3515 : dp
->dir$b_namecount
;
3516 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3517 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3518 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3519 dir_static
.d_reclen
= sizeof (struct direct
)
3521 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3522 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3523 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3524 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3531 /* readdirver is just like readdir except it returns all versions of a file
3532 as separate entries. */
3537 register DIR *dirp
; /* stream from opendir */
3539 register struct dir$_name
*dp
; /* -> directory data */
3540 register struct dir$_version
*dv
; /* -> version data */
3542 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3543 dirp
->dd_loc
= dirp
->dd_size
= 0;
3545 if (dirp
->dd_size
== 0 /* refill buffer */
3546 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3549 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3550 if (dirp
->dd_loc
== 0)
3551 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3552 : dp
->dir$b_namecount
;
3553 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3554 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3555 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3556 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3557 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3558 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3559 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3560 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3566 #endif /* NONSYSTEM_DIR_LIBRARY */
3570 set_file_times (filename
, atime
, mtime
)
3572 EMACS_TIME atime
, mtime
;
3575 struct timeval tv
[2];
3578 return utimes (filename
, tv
);
3579 #else /* not HAVE_UTIMES */
3581 utb
.actime
= EMACS_SECS (atime
);
3582 utb
.modtime
= EMACS_SECS (mtime
);
3583 return utime (filename
, &utb
);
3584 #endif /* not HAVE_UTIMES */
3587 /* mkdir and rmdir functions, for systems which don't have them. */
3591 * Written by Robert Rother, Mariah Corporation, August 1985.
3593 * If you want it, it's yours. All I ask in return is that if you
3594 * figure out how to do this in a Bourne Shell script you send me
3596 * sdcsvax!rmr or rmr@uscd
3598 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3599 * subroutine. 11Mar86; hoptoad!gnu
3601 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3602 * subroutine didn't return EEXIST. It does now.
3608 #ifdef MKDIR_PROTOTYPE
3612 mkdir (dpath
, dmode
)
3617 int cpid
, status
, fd
;
3618 struct stat statbuf
;
3620 if (stat (dpath
, &statbuf
) == 0)
3622 errno
= EEXIST
; /* Stat worked, so it already exists */
3626 /* If stat fails for a reason other than non-existence, return error */
3627 if (errno
!= ENOENT
)
3630 synch_process_alive
= 1;
3631 switch (cpid
= fork ())
3634 case -1: /* Error in fork */
3635 return (-1); /* Errno is set already */
3637 case 0: /* Child process */
3639 * Cheap hack to set mode of new directory. Since this
3640 * child process is going away anyway, we zap its umask.
3641 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3642 * directory. Does anybody care?
3644 status
= umask (0); /* Get current umask */
3645 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3646 fd
= sys_open("/dev/null", 2);
3653 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3654 _exit (-1); /* Can't exec /bin/mkdir */
3656 default: /* Parent process */
3657 wait_for_termination (cpid
);
3660 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3662 errno
= EIO
; /* We don't know why, but */
3663 return -1; /* /bin/mkdir failed */
3668 #endif /* not HAVE_MKDIR */
3675 int cpid
, status
, fd
;
3676 struct stat statbuf
;
3678 if (stat (dpath
, &statbuf
) != 0)
3680 /* Stat just set errno. We don't have to */
3684 synch_process_alive
= 1;
3685 switch (cpid
= fork ())
3688 case -1: /* Error in fork */
3689 return (-1); /* Errno is set already */
3691 case 0: /* Child process */
3692 fd
= sys_open("/dev/null", 2);
3699 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3700 _exit (-1); /* Can't exec /bin/rmdir */
3702 default: /* Parent process */
3703 wait_for_termination (cpid
);
3706 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3708 errno
= EIO
; /* We don't know why, but */
3709 return -1; /* /bin/rmdir failed */
3714 #endif /* !HAVE_RMDIR */
3718 /* Functions for VMS */
3720 #include "vms-pwd.h"
3725 /* Return as a string the VMS error string pertaining to STATUS.
3726 Reuses the same static buffer each time it is called. */
3730 int status
; /* VMS status code */
3734 static char buf
[257];
3736 bufadr
[0] = sizeof buf
- 1;
3737 bufadr
[1] = (int) buf
;
3738 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3739 return "untranslatable VMS error status";
3747 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3748 * not work correctly. (It also doesn't work well in version 2.3.)
3753 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3754 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3758 unsigned short s_buflen
;
3759 unsigned short s_code
;
3761 unsigned short *s_retlenadr
;
3765 #define buflen s.s_buflen
3766 #define code s.s_code
3767 #define bufadr s.s_bufadr
3768 #define retlenadr s.s_retlenadr
3770 #define R_OK 4 /* test for read permission */
3771 #define W_OK 2 /* test for write permission */
3772 #define X_OK 1 /* test for execute (search) permission */
3773 #define F_OK 0 /* test for presence of file */
3776 sys_access (path
, mode
)
3780 static char *user
= NULL
;
3783 /* translate possible directory spec into .DIR file name, so brain-dead
3784 * access can treat the directory like a file. */
3785 if (directory_file_name (path
, dir_fn
))
3789 return access (path
, mode
);
3790 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3796 unsigned short int dummy
;
3798 static int constant
= ACL$C_FILE
;
3799 DESCRIPTOR (path_desc
, path
);
3800 DESCRIPTOR (user_desc
, user
);
3804 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3807 acces
|= CHP$M_READ
;
3809 acces
|= CHP$M_WRITE
;
3810 itemlst
[0].buflen
= sizeof (int);
3811 itemlst
[0].code
= CHP$_FLAGS
;
3812 itemlst
[0].bufadr
= (char *) &flags
;
3813 itemlst
[0].retlenadr
= &dummy
;
3814 itemlst
[1].buflen
= sizeof (int);
3815 itemlst
[1].code
= CHP$_ACCESS
;
3816 itemlst
[1].bufadr
= (char *) &acces
;
3817 itemlst
[1].retlenadr
= &dummy
;
3818 itemlst
[2].end
= CHP$_END
;
3819 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3820 return stat
== SS$_NORMAL
? 0 : -1;
3824 #else /* not VMS4_4 */
3827 #define ACE$M_WRITE 2
3828 #define ACE$C_KEYID 1
3830 static unsigned short memid
, grpid
;
3831 static unsigned int uic
;
3833 /* Called from init_sys_modes, so it happens not very often
3834 but at least each time Emacs is loaded. */
3835 sys_access_reinit ()
3841 sys_access (filename
, type
)
3847 int status
, size
, i
, typecode
, acl_controlled
;
3848 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3849 union prvdef prvmask
;
3851 /* Get UIC and GRP values for protection checking. */
3854 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3857 memid
= uic
& 0xFFFF;
3861 if (type
!= 2) /* not checking write access */
3862 return access (filename
, type
);
3864 /* Check write protection. */
3866 #define CHECKPRIV(bit) (prvmask.bit)
3867 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3869 /* Find privilege bits */
3870 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3872 error ("Unable to find privileges: %s", vmserrstr (status
));
3873 if (CHECKPRIV (PRV$V_BYPASS
))
3874 return 0; /* BYPASS enabled */
3876 fab
.fab$b_fac
= FAB$M_GET
;
3877 fab
.fab$l_fna
= filename
;
3878 fab
.fab$b_fns
= strlen (filename
);
3879 fab
.fab$l_xab
= &xab
;
3880 xab
= cc$rms_xabpro
;
3881 xab
.xab$l_aclbuf
= aclbuf
;
3882 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3883 status
= SYS$
OPEN (&fab
, 0, 0);
3886 SYS$
CLOSE (&fab
, 0, 0);
3887 /* Check system access */
3888 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
3890 /* Check ACL entries, if any */
3892 if (xab
.xab$w_acllen
> 0)
3895 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3896 while (*aclptr
&& aclptr
< aclend
)
3898 size
= (*aclptr
& 0xff) / 4;
3899 typecode
= (*aclptr
>> 8) & 0xff;
3900 if (typecode
== ACE$C_KEYID
)
3901 for (i
= size
- 1; i
> 1; i
--)
3902 if (aclptr
[i
] == uic
)
3905 if (aclptr
[1] & ACE$M_WRITE
)
3906 return 0; /* Write access through ACL */
3908 aclptr
= &aclptr
[size
];
3910 if (acl_controlled
) /* ACL specified, prohibits write access */
3913 /* No ACL entries specified, check normal protection */
3914 if (WRITABLE (XAB$V_WLD
)) /* World writable */
3916 if (WRITABLE (XAB$V_GRP
) &&
3917 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3918 return 0; /* Group writable */
3919 if (WRITABLE (XAB$V_OWN
) &&
3920 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3921 return 0; /* Owner writable */
3923 return -1; /* Not writable */
3925 #endif /* not VMS4_4 */
3928 static char vtbuf
[NAM$C_MAXRSS
+1];
3930 /* translate a vms file spec to a unix path */
3932 sys_translate_vms (vfile
)
3943 /* leading device or logical name is a root directory */
3944 if (p
= strchr (vfile
, ':'))
3953 if (*p
== '[' || *p
== '<')
3955 while (*++vfile
!= *p
+ 2)
3959 if (vfile
[-1] == *p
)
3982 static char utbuf
[NAM$C_MAXRSS
+1];
3984 /* translate a unix path to a VMS file spec */
3986 sys_translate_unix (ufile
)
4009 if (index (&ufile
[1], '/'))
4016 if (index (&ufile
[1], '/'))
4023 if (strncmp (ufile
, "./", 2) == 0)
4030 ufile
++; /* skip the dot */
4031 if (index (&ufile
[1], '/'))
4036 else if (strncmp (ufile
, "../", 3) == 0)
4044 ufile
+= 2; /* skip the dots */
4045 if (index (&ufile
[1], '/'))
4070 extern char *getcwd ();
4072 #define MAXPATHLEN 1024
4074 ptr
= xmalloc (MAXPATHLEN
);
4075 val
= getcwd (ptr
, MAXPATHLEN
);
4081 strcpy (pathname
, ptr
);
4089 long item_code
= JPI$_OWNER
;
4090 unsigned long parent_id
;
4093 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4096 vaxc$errno
= status
;
4106 return (getgid () << 16) | getuid ();
4110 sys_read (fildes
, buf
, nbyte
)
4115 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4120 sys_write (fildes
, buf
, nbyte
)
4125 register int nwrote
, rtnval
= 0;
4127 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4133 return rtnval
? rtnval
: -1;
4134 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4135 return rtnval
? rtnval
: -1;
4136 return (rtnval
+ nwrote
);
4141 * VAX/VMS VAX C RTL really loses. It insists that records
4142 * end with a newline (carriage return) character, and if they
4143 * don't it adds one (nice of it isn't it!)
4145 * Thus we do this stupidity below.
4149 sys_write (fildes
, buf
, nbytes
)
4152 unsigned int nbytes
;
4159 fstat (fildes
, &st
);
4165 /* Handle fixed-length files with carriage control. */
4166 if (st
.st_fab_rfm
== FAB$C_FIX
4167 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4169 len
= st
.st_fab_mrs
;
4170 retval
= write (fildes
, p
, min (len
, nbytes
));
4173 retval
++; /* This skips the implied carriage control */
4177 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4178 while (*e
!= '\n' && e
> p
) e
--;
4179 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4180 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4182 retval
= write (fildes
, p
, len
);
4193 /* Create file NEW copying its attributes from file OLD. If
4194 OLD is 0 or does not exist, create based on the value of
4197 /* Protection value the file should ultimately have.
4198 Set by create_copy_attrs, and use by rename_sansversions. */
4199 static unsigned short int fab_final_pro
;
4202 creat_copy_attrs (old
, new)
4205 struct FAB fab
= cc$rms_fab
;
4206 struct XABPRO xabpro
;
4207 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4208 extern int vms_stmlf_recfm
;
4212 fab
.fab$b_fac
= FAB$M_GET
;
4213 fab
.fab$l_fna
= old
;
4214 fab
.fab$b_fns
= strlen (old
);
4215 fab
.fab$l_xab
= (char *) &xabpro
;
4216 xabpro
= cc$rms_xabpro
;
4217 xabpro
.xab$l_aclbuf
= aclbuf
;
4218 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4219 /* Call $OPEN to fill in the fab & xabpro fields. */
4220 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4222 SYS$
CLOSE (&fab
, 0, 0);
4223 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4224 if (xabpro
.xab$w_acllen
> 0)
4226 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4227 /* If the acl buffer was too short, redo open with longer one.
4228 Wouldn't need to do this if there were some system imposed
4229 limit on the size of an ACL, but I can't find any such. */
4231 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4232 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4233 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4234 SYS$
CLOSE (&fab
, 0, 0);
4240 xabpro
.xab$l_aclbuf
= 0;
4245 fab
.fab$l_fna
= new;
4246 fab
.fab$b_fns
= strlen (new);
4250 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4251 fab
.fab$b_rat
= FAB$M_CR
;
4254 /* Set the file protections such that we will be able to manipulate
4255 this file. Once we are done writing and renaming it, we will set
4256 the protections back. */
4258 fab_final_pro
= xabpro
.xab$w_pro
;
4260 SYS$
SETDFPROT (0, &fab_final_pro
);
4261 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4263 /* Create the new file with either default attrs or attrs copied
4265 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4267 SYS$
CLOSE (&fab
, 0, 0);
4268 /* As this is a "replacement" for creat, return a file descriptor
4269 opened for writing. */
4270 return open (new, O_WRONLY
);
4275 #include <varargs.h>
4278 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4282 sys_creat (va_alist
)
4285 va_list list_incrementer
;
4288 int rfd
; /* related file descriptor */
4289 int fd
; /* Our new file descriptor */
4296 extern int vms_stmlf_recfm
;
4299 va_start (list_incrementer
);
4300 name
= va_arg (list_incrementer
, char *);
4301 mode
= va_arg (list_incrementer
, int);
4303 rfd
= va_arg (list_incrementer
, int);
4304 va_end (list_incrementer
);
4307 /* Use information from the related file descriptor to set record
4308 format of the newly created file. */
4309 fstat (rfd
, &st_buf
);
4310 switch (st_buf
.st_fab_rfm
)
4313 strcpy (rfm
, "rfm = fix");
4314 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4315 strcpy (rat
, "rat = ");
4316 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4318 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4319 strcat (rat
, "ftn");
4320 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4321 strcat (rat
, "prn");
4322 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4323 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4324 strcat (rat
, ", blk");
4326 strcat (rat
, "blk");
4327 return creat (name
, 0, rfm
, rat
, mrs
);
4330 strcpy (rfm
, "rfm = vfc");
4331 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4332 strcpy (rat
, "rat = ");
4333 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4335 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4336 strcat (rat
, "ftn");
4337 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4338 strcat (rat
, "prn");
4339 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4340 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4341 strcat (rat
, ", blk");
4343 strcat (rat
, "blk");
4344 return creat (name
, 0, rfm
, rat
, fsz
);
4347 strcpy (rfm
, "rfm = stm");
4351 strcpy (rfm
, "rfm = stmcr");
4355 strcpy (rfm
, "rfm = stmlf");
4359 strcpy (rfm
, "rfm = udf");
4363 strcpy (rfm
, "rfm = var");
4366 strcpy (rat
, "rat = ");
4367 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4369 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4370 strcat (rat
, "ftn");
4371 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4372 strcat (rat
, "prn");
4373 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4374 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4375 strcat (rat
, ", blk");
4377 strcat (rat
, "blk");
4381 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4382 strcpy (rat
, "rat=cr");
4384 /* Until the VAX C RTL fixes the many bugs with modes, always use
4385 mode 0 to get the user's default protection. */
4386 fd
= creat (name
, 0, rfm
, rat
);
4387 if (fd
< 0 && errno
== EEXIST
)
4389 if (unlink (name
) < 0)
4390 report_file_error ("delete", build_string (name
));
4391 fd
= creat (name
, 0, rfm
, rat
);
4397 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4398 sys_fwrite (ptr
, size
, num
, fp
)
4399 register char * ptr
;
4402 register int tot
= num
* size
;
4409 * The VMS C library routine creat actually creates a new version of an
4410 * existing file rather than truncating the old version. There are times
4411 * when this is not the desired behavior, for instance, when writing an
4412 * auto save file (you only want one version), or when you don't have
4413 * write permission in the directory containing the file (but the file
4414 * itself is writable). Hence this routine, which is equivalent to
4415 * "close (creat (fn, 0));" on Unix if fn already exists.
4421 struct FAB xfab
= cc$rms_fab
;
4422 struct RAB xrab
= cc$rms_rab
;
4425 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4426 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4427 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4428 xfab
.fab$l_fna
= fn
;
4429 xfab
.fab$b_fns
= strlen (fn
);
4430 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4432 xrab
.rab$l_fab
= &xfab
;
4434 /* This gibberish opens the file, positions to the first record, and
4435 deletes all records from there until the end of file. */
4436 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4438 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4439 (SYS$
FIND (&xrab
) & 01) == 01 &&
4440 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4451 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4452 SYSPRV or a readable SYSUAF.DAT. */
4458 * Routine to read the VMS User Authorization File and return
4459 * a specific user's record.
4462 static struct UAF retuaf
;
4465 get_uaf_name (uname
)
4472 uaf_fab
= cc$rms_fab
;
4473 uaf_rab
= cc$rms_rab
;
4474 /* initialize fab fields */
4475 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4476 uaf_fab
.fab$b_fns
= 21;
4477 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4478 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4479 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4480 /* initialize rab fields */
4481 uaf_rab
.rab$l_fab
= &uaf_fab
;
4482 /* open the User Authorization File */
4483 status
= SYS$
OPEN (&uaf_fab
);
4487 vaxc$errno
= status
;
4490 status
= SYS$
CONNECT (&uaf_rab
);
4494 vaxc$errno
= status
;
4497 /* read the requested record - index is in uname */
4498 uaf_rab
.rab$l_kbf
= uname
;
4499 uaf_rab
.rab$b_ksz
= strlen (uname
);
4500 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4501 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4502 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4503 status
= SYS$
GET (&uaf_rab
);
4507 vaxc$errno
= status
;
4510 /* close the User Authorization File */
4511 status
= SYS$
DISCONNECT (&uaf_rab
);
4515 vaxc$errno
= status
;
4518 status
= SYS$
CLOSE (&uaf_fab
);
4522 vaxc$errno
= status
;
4536 uaf_fab
= cc$rms_fab
;
4537 uaf_rab
= cc$rms_rab
;
4538 /* initialize fab fields */
4539 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4540 uaf_fab
.fab$b_fns
= 21;
4541 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4542 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4543 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4544 /* initialize rab fields */
4545 uaf_rab
.rab$l_fab
= &uaf_fab
;
4546 /* open the User Authorization File */
4547 status
= SYS$
OPEN (&uaf_fab
);
4551 vaxc$errno
= status
;
4554 status
= SYS$
CONNECT (&uaf_rab
);
4558 vaxc$errno
= status
;
4561 /* read the requested record - index is in uic */
4562 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4563 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4564 uaf_rab
.rab$b_ksz
= sizeof uic
;
4565 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4566 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4567 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4568 status
= SYS$
GET (&uaf_rab
);
4572 vaxc$errno
= status
;
4575 /* close the User Authorization File */
4576 status
= SYS$
DISCONNECT (&uaf_rab
);
4580 vaxc$errno
= status
;
4583 status
= SYS$
CLOSE (&uaf_fab
);
4587 vaxc$errno
= status
;
4593 static struct passwd retpw
;
4601 /* copy these out first because if the username is 32 chars, the next
4602 section will overwrite the first byte of the UIC */
4603 retpw
.pw_uid
= up
->uaf$w_mem
;
4604 retpw
.pw_gid
= up
->uaf$w_grp
;
4606 /* I suppose this is not the best style, to possibly overwrite one
4607 byte beyond the end of the field, but what the heck... */
4608 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4609 while (ptr
[-1] == ' ')
4612 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4614 /* the rest of these are counted ascii strings */
4615 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4616 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4617 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4618 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4619 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4620 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4621 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4622 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4626 #else /* not READ_SYSUAF */
4627 static struct passwd retpw
;
4628 #endif /* not READ_SYSUAF */
4639 unsigned char * full
;
4640 #endif /* READ_SYSUAF */
4645 if ('a' <= *ptr
&& *ptr
<= 'z')
4650 if (!(up
= get_uaf_name (name
)))
4652 return cnv_uaf_pw (up
);
4654 if (strcmp (name
, getenv ("USER")) == 0)
4656 retpw
.pw_uid
= getuid ();
4657 retpw
.pw_gid
= getgid ();
4658 strcpy (retpw
.pw_name
, name
);
4659 if (full
= egetenv ("FULLNAME"))
4660 strcpy (retpw
.pw_gecos
, full
);
4662 *retpw
.pw_gecos
= '\0';
4663 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4664 *retpw
.pw_shell
= '\0';
4669 #endif /* not READ_SYSUAF */
4679 if (!(up
= get_uaf_uic (uid
)))
4681 return cnv_uaf_pw (up
);
4683 if (uid
== sys_getuid ())
4684 return getpwnam (egetenv ("USER"));
4687 #endif /* not READ_SYSUAF */
4690 /* return total address space available to the current process. This is
4691 the sum of the current p0 size, p1 size and free page table entries
4696 unsigned long free_pages
;
4697 unsigned long frep0va
;
4698 unsigned long frep1va
;
4701 item_code
= JPI$_FREPTECNT
;
4702 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4705 vaxc$errno
= status
;
4710 item_code
= JPI$_FREP0VA
;
4711 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4714 vaxc$errno
= status
;
4717 item_code
= JPI$_FREP1VA
;
4718 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4721 vaxc$errno
= status
;
4725 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4728 define_logical_name (varname
, string
)
4732 struct dsc$descriptor_s strdsc
=
4733 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4734 struct dsc$descriptor_s envdsc
=
4735 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4736 struct dsc$descriptor_s lnmdsc
=
4737 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4739 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4742 delete_logical_name (varname
)
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$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4761 error ("execvp system call not implemented");
4769 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4770 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4771 char from_esn
[NAM$C_MAXRSS
];
4772 char to_esn
[NAM$C_MAXRSS
];
4774 from_fab
.fab$l_fna
= from
;
4775 from_fab
.fab$b_fns
= strlen (from
);
4776 from_fab
.fab$l_nam
= &from_nam
;
4777 from_fab
.fab$l_fop
= FAB$M_NAM
;
4779 from_nam
.nam$l_esa
= from_esn
;
4780 from_nam
.nam$b_ess
= sizeof from_esn
;
4782 to_fab
.fab$l_fna
= to
;
4783 to_fab
.fab$b_fns
= strlen (to
);
4784 to_fab
.fab$l_nam
= &to_nam
;
4785 to_fab
.fab$l_fop
= FAB$M_NAM
;
4787 to_nam
.nam$l_esa
= to_esn
;
4788 to_nam
.nam$b_ess
= sizeof to_esn
;
4790 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4796 if (status
== RMS$_DEV
)
4800 vaxc$errno
= status
;
4805 /* This function renames a file like `rename', but it strips
4806 the version number from the "to" filename, such that the "to" file is
4807 will always be a new version. It also sets the file protection once it is
4808 finished. The protection that we will use is stored in fab_final_pro,
4809 and was set when we did a creat_copy_attrs to create the file that we
4812 We could use the chmod function, but Eunichs uses 3 bits per user category
4813 to describe the protection, and VMS uses 4 (write and delete are separate
4814 bits). To maintain portability, the VMS implementation of `chmod' wires
4815 the W and D bits together. */
4818 static struct fibdef fib
; /* We need this initialized to zero */
4819 char vms_file_written
[NAM$C_MAXRSS
];
4822 rename_sans_version (from
,to
)
4829 struct FAB to_fab
= cc$rms_fab
;
4830 struct NAM to_nam
= cc$rms_nam
;
4831 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4832 struct dsc$descriptor fib_attr
[2]
4833 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4834 char to_esn
[NAM$C_MAXRSS
];
4836 $
DESCRIPTOR (disk
,to_esn
);
4838 to_fab
.fab$l_fna
= to
;
4839 to_fab
.fab$b_fns
= strlen (to
);
4840 to_fab
.fab$l_nam
= &to_nam
;
4841 to_fab
.fab$l_fop
= FAB$M_NAM
;
4843 to_nam
.nam$l_esa
= to_esn
;
4844 to_nam
.nam$b_ess
= sizeof to_esn
;
4846 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4848 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4849 *(to_nam
.nam$l_ver
) = '\0';
4851 stat
= rename (from
, to_esn
);
4855 strcpy (vms_file_written
, to_esn
);
4857 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4858 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4860 /* Now set the file protection to the correct value */
4861 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4863 /* Copy these fields into the fib */
4864 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4865 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4866 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4868 SYS$
CLOSE (&to_fab
, 0, 0);
4870 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4873 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4874 0, 0, 0, &fib_attr
, 0);
4877 stat
= SYS$
DASSGN (chan
);
4880 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4890 unsigned short fid
[3];
4891 char esa
[NAM$C_MAXRSS
];
4894 fab
.fab$l_fop
= FAB$M_OFP
;
4895 fab
.fab$l_fna
= file
;
4896 fab
.fab$b_fns
= strlen (file
);
4897 fab
.fab$l_nam
= &nam
;
4900 nam
.nam$l_esa
= esa
;
4901 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4903 status
= SYS$
PARSE (&fab
);
4904 if ((status
& 1) == 0)
4907 vaxc$errno
= status
;
4910 status
= SYS$
SEARCH (&fab
);
4911 if ((status
& 1) == 0)
4914 vaxc$errno
= status
;
4918 fid
[0] = nam
.nam$w_fid
[0];
4919 fid
[1] = nam
.nam$w_fid
[1];
4920 fid
[2] = nam
.nam$w_fid
[2];
4922 fab
.fab$l_fna
= new;
4923 fab
.fab$b_fns
= strlen (new);
4925 status
= SYS$
PARSE (&fab
);
4926 if ((status
& 1) == 0)
4929 vaxc$errno
= status
;
4933 nam
.nam$w_fid
[0] = fid
[0];
4934 nam
.nam$w_fid
[1] = fid
[1];
4935 nam
.nam$w_fid
[2] = fid
[2];
4937 nam
.nam$l_esa
= nam
.nam$l_name
;
4938 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
4940 status
= SYS$
ENTER (&fab
);
4941 if ((status
& 1) == 0)
4944 vaxc$errno
= status
;
4954 printf ("%s not yet implemented\r\n", badfunc
);
4962 /* Arrange to return a range centered on zero. */
4963 return rand () - (1 << 30);
4974 /* Called from init_sys_modes. */
4979 /* If we're not on an HFT we shouldn't do any of this. We determine
4980 if we are on an HFT by trying to get an HFT error code. If this
4981 call fails, we're not on an HFT. */
4983 if (ioctl (0, HFQERROR
, &junk
) < 0)
4985 #else /* not IBMR2AIX */
4986 if (ioctl (0, HFQEIO
, 0) < 0)
4988 #endif /* not IBMR2AIX */
4990 /* On AIX the default hft keyboard mapping uses backspace rather than delete
4991 as the rubout key's ASCII code. Here this is changed. The bug is that
4992 there's no way to determine the old mapping, so in reset_sys_modes
4993 we need to assume that the normal map had been present. Of course, this
4994 code also doesn't help if on a terminal emulator which doesn't understand
4998 struct hfkeymap keymap
;
5000 buf
.hf_bufp
= (char *)&keymap
;
5001 buf
.hf_buflen
= sizeof (keymap
);
5002 keymap
.hf_nkeys
= 2;
5003 keymap
.hfkey
[0].hf_kpos
= 15;
5004 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5006 keymap
.hfkey
[0].hf_keyidh
= '<';
5007 #else /* not IBMR2AIX */
5008 keymap
.hfkey
[0].hf_page
= '<';
5009 #endif /* not IBMR2AIX */
5010 keymap
.hfkey
[0].hf_char
= 127;
5011 keymap
.hfkey
[1].hf_kpos
= 15;
5012 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5014 keymap
.hfkey
[1].hf_keyidh
= '<';
5015 #else /* not IBMR2AIX */
5016 keymap
.hfkey
[1].hf_page
= '<';
5017 #endif /* not IBMR2AIX */
5018 keymap
.hfkey
[1].hf_char
= 127;
5019 hftctl (0, HFSKBD
, &buf
);
5021 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5023 line_ins_del_ok
= char_ins_del_ok
= 0;
5026 /* Reset the rubout key to backspace. */
5031 struct hfkeymap keymap
;
5035 if (ioctl (0, HFQERROR
, &junk
) < 0)
5037 #else /* not IBMR2AIX */
5038 if (ioctl (0, HFQEIO
, 0) < 0)
5040 #endif /* not IBMR2AIX */
5042 buf
.hf_bufp
= (char *)&keymap
;
5043 buf
.hf_buflen
= sizeof (keymap
);
5044 keymap
.hf_nkeys
= 2;
5045 keymap
.hfkey
[0].hf_kpos
= 15;
5046 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5048 keymap
.hfkey
[0].hf_keyidh
= '<';
5049 #else /* not IBMR2AIX */
5050 keymap
.hfkey
[0].hf_page
= '<';
5051 #endif /* not IBMR2AIX */
5052 keymap
.hfkey
[0].hf_char
= 8;
5053 keymap
.hfkey
[1].hf_kpos
= 15;
5054 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5056 keymap
.hfkey
[1].hf_keyidh
= '<';
5057 #else /* not IBMR2AIX */
5058 keymap
.hfkey
[1].hf_page
= '<';
5059 #endif /* not IBMR2AIX */
5060 keymap
.hfkey
[1].hf_char
= 8;
5061 hftctl (0, HFSKBD
, &buf
);
5068 /* These are included on Sunos 4.1 when we do not use shared libraries.
5069 X11 libraries may refer to these functions but (we hope) do not
5070 actually call them. */
5090 #endif /* USE_DL_STUBS */
5099 register int length
;
5103 long max_str
= 65535;
5105 while (length
> max_str
) {
5106 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5111 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5113 while (length
-- > 0)
5115 #endif /* not VMS */
5118 #endif /* no bzero */
5119 #endif /* BSTRING */
5121 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5124 /* Saying `void' requires a declaration, above, where bcopy is used
5125 and that declaration causes pain for systems where bcopy is a macro. */
5126 bcopy (b1
, b2
, length
)
5129 register int length
;
5132 long max_str
= 65535;
5134 while (length
> max_str
) {
5135 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5141 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5143 while (length
-- > 0)
5145 #endif /* not VMS */
5147 #endif /* (defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5152 bcmp (b1
, b2
, length
) /* This could be a macro! */
5155 register int length
;
5158 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5159 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5161 return STR$
COMPARE (&src1
, &src2
);
5163 while (length
-- > 0)
5168 #endif /* not VMS */
5170 #endif /* no bcmp */
5171 #endif /* not BSTRING */