1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 1986, 1987, 1988, 1992 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 1, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #define min(x,y) ((x) > (y) ? (y) : (x))
30 /* In this file, open, read and write refer to the system calls,
31 not our sugared interfaces sys_open, sys_read and sys_write.
32 Contrariwise, for systems where we use the system calls directly,
33 define sys_read, etc. here as aliases for them. */
36 #define sys_write write
37 #endif /* `read' is not a macro */
43 #define sys_close close
50 #else /* `open' is a macro */
52 #endif /* `open' is a macro */
54 /* Does anyone other than VMS need this? */
56 #define sys_fwrite fwrite
62 #include <sys/types.h>
68 extern char *sys_errlist
[];
91 #define MAXIOSIZE ( 32 * PAGESIZE ) /* Don't I/O more than 32 blocks at a time */
95 #ifdef BSD /* this is done this way to avoid defined (BSD) || defined (USG)
96 because the vms compiler doesn't grok `defined' */
104 #endif /* not 4.1 bsd */
106 /* Get DGUX definition for FASYNC - DJB */
108 #include <sys/file.h>
111 #include <sys/ioctl.h>
118 #include <sys/wait.h>
122 #ifdef BROKEN_TIOCGWINSZ
127 #include <sys/utsname.h>
129 #ifndef MEMORY_IN_STRING_H
134 #include <sys/sioctl.h>
137 #include <sys/stream.h>
138 #include <sys/ptem.h>
140 #endif /* TIOCGWINSZ */
143 extern int quit_char
;
147 #include "termhooks.h"
148 #include "termchar.h"
149 #include "termopts.h"
150 #include "dispextern.h"
153 #ifdef NONSYSTEM_DIR_LIBRARY
155 #endif /* NONSYSTEM_DIR_LIBRARY */
157 #include "syssignal.h"
160 static int baud_convert
[] =
165 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
166 1800, 2400, 4800, 9600, 19200, 38400
172 /* The file descriptor for Emacs's input terminal.
173 Under Unix, this is always left zero;
174 under VMS, we place the input channel number here.
175 This allows us to write more code that works for both VMS and Unix. */
180 struct emacs_tty buf
;
185 /* Discarding input is not safe when the input could contain
186 replies from the X server. So don't do it. */
187 if (read_socket_hook
)
192 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
193 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
199 ioctl (0, TIOCFLUSH
, &zero
);
201 #else /* not Apollo */
202 EMACS_GET_TTY (input_fd
, &buf
);
203 EMACS_SET_TTY (input_fd
, &buf
, 0);
204 #endif /* not Apollo */
213 /* Should perhaps error if in batch mode */
215 ioctl (0, TIOCSTI
, &c
);
216 #else /* no TIOCSTI */
217 error ("Cannot stuff terminal input characters in this version of Unix.");
218 #endif /* no TIOCSTI */
232 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
233 &sg
.class, 12, 0, 0, 0, 0 );
234 ospeed
= sg
.xmit_baud
;
239 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | B9600
;
241 ospeed
= sg
.c_cflag
& CBAUD
;
242 #else /* neither VMS nor TERMIOS */
246 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | B9600
;
250 ioctl (input_fd
, TCGETA
, &sg
);
252 ospeed
= sg
.c_cflag
& CBAUD
;
253 #else /* neither VMS nor TERMIOS nor TERMIO */
256 sg
.sg_ospeed
= B9600
;
257 ioctl (0, TIOCGETP
, &sg
);
258 ospeed
= sg
.sg_ospeed
;
259 #endif /* not HAVE_TERMIO */
260 #endif /* not HAVE_TERMIOS */
264 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
265 ? baud_convert
[ospeed
] : 9600);
271 set_exclusive_use (fd
)
275 ioctl (fd
, FIOCLEX
, 0);
277 /* Ok to do nothing if this feature does not exist */
282 wait_without_blocking ()
285 wait3 (0, WNOHANG
| WUNTRACED
, 0);
287 croak ("wait_without_blocking");
289 synch_process_alive
= 0;
292 #endif /* not subprocesses */
294 int wait_debugging
; /* Set nonzero to make following function work under dbx
295 (at least for bsd). */
298 wait_for_termination_signal ()
301 /* Wait for subprocess with process id `pid' to terminate and
302 make sure it will get eliminated (not remain forever as a zombie) */
304 wait_for_termination (pid
)
313 status
= SYS$
FORCEX (&pid
, 0, 0);
317 /* Exit if the process has terminated. */
318 if (!synch_process_alive
)
320 /* Otherwise wait 1 second or until a signal comes in. */
321 signal (SIGALRM
, wait_for_termination_signal
);
325 signal (SIGALRM
, SIG_IGN
);
327 #else /* not subprocesses */
329 if (kill (pid
, 0) < 0)
335 if (status
== pid
|| status
== -1)
338 #endif /* not subprocesses */
345 * flush any pending output
346 * (may flush input as well; it does not matter the way we use it)
349 flush_pending_output (channel
)
353 /* If we try this, we get hit with SIGTTIN, because
354 the child's tty belongs to the child's pgrp. */
357 ioctl (channel
, TCFLSH
, 1);
361 /* 3rd arg should be ignored
362 but some 4.2 kernels actually want the address of an int
363 and nonzero means something different. */
364 ioctl (channel
, TIOCFLUSH
, &zero
);
371 /* Set up the terminal at the other end of a pseudo-terminal that
372 we will be controlling an inferior through.
373 It should not echo or do line-editing, since that is done
374 in Emacs. No padding needed for insertion into an Emacs buffer. */
376 child_setup_tty (out
)
381 EMACS_GET_TTY (out
, &s
);
383 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
384 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
385 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
386 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
387 /* No output delays */
388 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
389 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
390 s
.main
.c_iflag
&= ~IUCLC
; /* Disable map of upper case to lower on
392 s
.main
.c_oflag
&= ~OLCUC
; /* Disable map of lower case to upper on
395 /* Said to be unnecesary: */
396 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
397 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
400 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
401 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
402 s
.main
.c_cc
[VERASE
] = 0377; /* disable erase processing */
403 s
.main
.c_cc
[VKILL
] = 0377; /* disable kill processing */
406 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
410 /* AIX enhanced edit loses NULs, so disable it */
413 s
.main
.c_iflag
&= ~ASCEDIT
;
415 /* Also, PTY overloads NUL and BREAK.
416 don't ignore break, but don't signal either, so it looks like NUL. */
417 s
.main
.c_iflag
&= ~IGNBRK
;
418 s
.main
.c_iflag
&= ~BRKINT
;
419 /* QUIT and INTR work better as signals, so disable character forms */
420 s
.main
.c_cc
[VQUIT
] = 0377;
421 s
.main
.c_cc
[VINTR
] = 0377;
422 s
.main
.c_cc
[VEOL
] = 0377;
423 s
.main
.c_lflag
&= ~ISIG
;
424 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
427 #else /* not HAVE_TERMIO */
429 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
431 s
.main
.sg_erase
= 0377;
432 s
.main
.sg_kill
= 0377;
434 #endif /* not HAVE_TERMIO */
436 EMACS_SET_TTY (out
, &s
, 0);
445 ioctl (out
, FIOASYNC
, &zero
);
451 #endif /* subprocesses */
457 EMACS_SET_TTY_PGRP (input_fd
, &pid
);
460 /* Record a signal code and the handler for it. */
464 SIGTYPE (*handler
) ();
467 /* Suspend the Emacs process; give terminal to its superior. */
472 /* "Foster" parentage allows emacs to return to a subprocess that attached
473 to the current emacs as a cheaper than starting a whole new process. This
474 is set up by KEPTEDITOR.COM. */
475 unsigned long parent_id
, foster_parent_id
;
478 fpid_string
= getenv ("EMACS_PARENT_PID");
479 if (fpid_string
!= NULL
)
481 sscanf (fpid_string
, "%x", &foster_parent_id
);
482 if (foster_parent_id
!= 0)
483 parent_id
= foster_parent_id
;
485 parent_id
= getppid ();
488 parent_id
= getppid ();
490 free (fpid_string
); /* On VMS, this was malloc'd */
492 if (parent_id
&& parent_id
!= 0xffffffff)
494 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
495 int status
= LIB$
ATTACH (&parent_id
) & 1;
496 signal (SIGINT
, oldsig
);
505 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
506 d_prompt
.a
= "Emacs: "; /* Just a reminder */
507 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
514 EMACS_KILLPG (getpgrp (0), SIGTSTP
);
516 #else /* No SIGTSTP */
517 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
518 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
519 kill (getpid (), SIGQUIT
);
521 #else /* No SIGTSTP or USG_JOBCTRL */
523 /* On a system where suspending is not implemented,
524 instead fork a subshell and let it talk directly to the terminal
527 struct save_signal saved_handlers
[5];
529 saved_handlers
[0].code
= SIGINT
;
530 saved_handlers
[1].code
= SIGQUIT
;
531 saved_handlers
[2].code
= SIGTERM
;
533 saved_handlers
[3].code
= SIGIO
;
534 saved_handlers
[4].code
= 0;
536 saved_handlers
[3].code
= 0;
540 error ("Can't spawn subshell");
545 sh
= (char *) egetenv ("SHELL");
548 /* Use our buffer's default directory for the subshell. */
554 /* mentioning current_buffer->buffer would mean including buffer.h,
555 which somehow wedges the hp compiler. So instead... */
557 dir
= intern ("default-directory");
559 if (XFASTINT (Fboundp (dir
)) == XFASTINT (Qnil
))
561 dir
= Fsymbol_value (dir
);
562 if (XTYPE (dir
) != Lisp_String
)
565 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
566 len
= XSTRING (dir
)->size
;
567 bcopy (XSTRING (dir
)->data
, str
, len
);
568 if (str
[len
- 1] != '/') str
[len
++] = '/';
574 close_process_descs (); /* Close Emacs's pipes/ptys */
579 extern int emacs_priority
;
582 nice (-emacs_priority
);
587 write (1, "Can't execute subshell", 22);
591 save_signal_handlers (saved_handlers
);
592 wait_for_termination (pid
);
593 restore_signal_handlers (saved_handlers
);
595 #endif /* no USG_JOBCTRL */
596 #endif /* no SIGTSTP */
600 save_signal_handlers (saved_handlers
)
601 struct save_signal
*saved_handlers
;
603 while (saved_handlers
->code
)
605 saved_handlers
->handler
606 = (SIGTYPE (*) ()) signal (saved_handlers
->code
, SIG_IGN
);
611 restore_signal_handlers (saved_handlers
)
612 struct save_signal
*saved_handlers
;
614 while (saved_handlers
->code
)
616 signal (saved_handlers
->code
, saved_handlers
->handler
);
628 old_fcntl_flags
= fcntl (0, F_GETFL
, 0) & ~FASYNC
;
638 #ifdef FASYNC /* F_SETFL does not imply existance of FASYNC */
643 sigunblock (sigmask (SIGWINCH
));
645 fcntl (0, F_SETFL
, old_fcntl_flags
| FASYNC
);
647 interrupts_deferred
= 0;
653 sigblock (sigmask (SIGWINCH
));
655 fcntl (0, F_SETFL
, old_fcntl_flags
);
656 interrupts_deferred
= 1;
659 #else /* no FASYNC */
660 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
665 ioctl (0, FIOASYNC
, &on
);
666 interrupts_deferred
= 0;
673 ioctl (0, FIOASYNC
, &off
);
674 interrupts_deferred
= 1;
677 #else /* not FASYNC, not STRIDE */
681 croak ("request_sigio");
686 croak ("unrequest_sigio");
693 /* The initial tty mode bits */
694 struct emacs_tty old_tty
;
696 int term_initted
; /* 1 if outer tty status has been recorded */
699 /* BSD 4.1 needs to keep track of the lmode bits in order to start
706 #endif /* F_SETOWN */
708 /* This may also be defined in stdio,
709 but if so, this does no harm,
710 and using the same name avoids wasting the other one's space. */
712 #if defined (USG) || defined (DGUX)
713 unsigned char _sobuf
[BUFSIZ
+8];
719 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
722 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
727 struct emacs_tty tty
;
731 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
732 extern int (*interrupt_signal
) ();
741 input_ef
= get_kbd_event_flag ();
742 /* LIB$GET_EF (&input_ef); */
743 SYS$
CLREF (input_ef
);
746 timer_ef
= get_timer_event_flag ();
747 /* LIB$GET_EF (&timer_ef); */
748 SYS$
CLREF (timer_ef
);
752 LIB$
GET_EF (&process_ef
);
753 SYS$
CLREF (process_ef
);
755 if (input_ef
/ 32 != process_ef
/ 32)
756 croak ("Input and process event flags in different clusters.");
758 if (input_ef
/ 32 != timer_ef
/ 32)
759 croak ("Input and timer event flags in different clusters.");
761 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
762 ((unsigned) 1 << (process_ef
% 32));
764 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
765 ((unsigned) 1 << (timer_ef
% 32));
767 sys_access_reinit ();
771 EMACS_GET_TTY (input_fd
, &old_tty
);
773 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
777 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
778 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
779 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
781 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
783 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
784 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
786 tty
.main
.c_iflag
&= ~IEXTEN
; /* Disable other editing characters. */
788 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
791 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
793 tty
.main
.c_iflag
&= ~IXANY
;
797 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
798 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
800 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
804 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
805 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
808 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
809 /* Set up C-g for both SIGQUIT and SIGINT.
810 We don't know which we will get, but we handle both alike
811 so which one it really gives us does not matter. */
812 tty
.main
.c_cc
[VQUIT
] = quit_char
;
813 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
814 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
816 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
819 #if defined (mips) || defined (HAVE_TCATTR)
821 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
824 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
826 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
827 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
829 #endif /* mips or HAVE_TCATTR */
832 /* AIX enhanced edit loses NULs, so disable it */
834 tty
.main
.c_iflag
&= ~ASCEDIT
;
836 tty
.main
.c_cc
[VSTRT
] = 255;
837 tty
.main
.c_cc
[VSTOP
] = 255;
838 tty
.main
.c_cc
[VSUSP
] = 255;
839 tty
.main
.c_cc
[VDSUSP
] = 255;
840 #endif /* IBMR2AIX */
841 /* Also, PTY overloads NUL and BREAK.
842 don't ignore break, but don't signal either, so it looks like NUL.
843 This really serves a purpose only if running in an XTERM window
844 or via TELNET or the like, but does no harm elsewhere. */
845 tty
.main
.c_iflag
&= ~IGNBRK
;
846 tty
.main
.c_iflag
&= ~BRKINT
;
848 #else /* if not HAVE_TERMIO */
850 tty
.main
.tt_char
|= TT$M_NOECHO
;
852 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
854 tty
.main
.tt_char
|= TT$M_TTSYNC
;
856 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
857 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
858 #else /* not VMS (BSD, that is) */
859 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
861 tty
.main
.sg_flags
|= ANYP
;
862 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
863 #endif /* not VMS (BSD, that is) */
864 #endif /* not HAVE_TERMIO */
866 /* If going to use CBREAK mode, we must request C-g to interrupt
867 and turn off start and stop chars, etc. If not going to use
868 CBREAK mode, do this anyway so as to turn off local flow
869 control for user coming over network on 4.2; in this case,
870 only t_stopc and t_startc really matter. */
873 /* Note: if not using CBREAK mode, it makes no difference how we
875 tty
.tchars
= new_tchars
;
876 tty
.tchars
.t_intrc
= quit_char
;
879 tty
.tchars
.t_startc
= '\021';
880 tty
.tchars
.t_stopc
= '\023';
883 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
889 #define LNOFLSH 0100000
892 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
898 #endif /* TIOCGETC */
899 #endif /* not HAVE_TERMIO */
902 tty
.ltchars
= new_ltchars
;
903 #endif /* TIOCGLTC */
905 EMACS_SET_TTY (input_fd
, &tty
, 0);
907 /* This code added to insure that, if flow-control is not to be used,
908 we have an unlocked terminal at the start. */
911 if (!flow_control
) ioctl (0, TCXONC
, 1);
915 if (!flow_control
) ioctl (0, TIOCSTART
, 0);
923 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
924 to be only LF. This is the way that is done. */
927 if (ioctl (1, HFTGETID
, &tty
) != -1)
928 write (1, "\033[20l", 5);
934 /* Appears to do nothing when in PASTHRU mode.
935 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
936 interrupt_signal, oob_chars, 0, 0, 0, 0);
943 #ifdef F_GETOWN /* F_SETFL does not imply existance of F_GETOWN */
946 old_fcntl_owner
= fcntl (0, F_GETOWN
, 0);
947 fcntl (0, F_SETOWN
, getpid ());
950 #endif /* F_GETOWN */
958 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
962 /* This symbol is defined on recent USG systems.
963 Someone says without this call USG won't really buffer the file
964 even with a call to setbuf. */
965 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
967 setbuf (stdout
, _sobuf
);
969 set_terminal_modes ();
970 if (term_initted
&& no_redraw_on_reenter
)
972 if (display_completed
)
973 direct_output_forward_char (0);
979 if (FRAMEP (Vterminal_frame
))
980 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
987 /* Return nonzero if safe to use tabs in output.
988 At the time this is called, init_sys_modes has not been done yet. */
992 struct emacs_tty tty
;
994 EMACS_GET_TTY (input_fd
, &tty
);
995 return EMACS_TTY_TABS_OK (&tty
);
998 /* Get terminal size from system.
999 Store number of lines into *heightp and width into *widthp.
1000 If zero or a negative number is stored, the value is not valid. */
1002 get_frame_size (widthp
, heightp
)
1003 int *widthp
, *heightp
;
1009 struct winsize size
;
1011 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1012 *widthp
= *heightp
= 0;
1015 *widthp
= size
.ws_col
;
1016 *heightp
= size
.ws_row
;
1022 /* SunOS - style. */
1023 struct ttysize size
;
1025 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1026 *widthp
= *heightp
= 0;
1029 *widthp
= size
.ts_cols
;
1030 *heightp
= size
.ts_lines
;
1036 struct sensemode tty
;
1038 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1039 &tty
.class, 12, 0, 0, 0, 0);
1040 *widthp
= tty
.scr_wid
;
1041 *heightp
= tty
.scr_len
;
1043 #else /* system doesn't know size */
1048 #endif /* not VMS */
1049 #endif /* not SunOS-style */
1050 #endif /* not BSD-style */
1054 /* Prepare the terminal for exiting Emacs; move the cursor to the
1055 bottom of the frame, turn off interrupt-driven I/O, etc. */
1065 if (read_socket_hook
|| !EQ (Vwindow_system
, Qnil
))
1067 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1068 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1069 /* clear_end_of_line may move the cursor */
1070 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1073 /* HFT devices normally use ^J as a LF/CR. We forced it to
1074 do the LF only. Now, we need to reset it. */
1077 if (ioctl (1, HFTGETID
, &tty
) != -1)
1078 write (1, "\033[20h", 5);
1082 reset_terminal_modes ();
1086 /* Avoid possible loss of output when changing terminal modes. */
1087 fsync (fileno (stdout
));
1092 #ifdef F_SETOWN /* F_SETFL does not imply existance of F_SETOWN */
1093 if (interrupt_input
)
1096 fcntl (0, F_SETOWN
, old_fcntl_owner
);
1098 #endif /* F_SETOWN */
1099 #endif /* F_SETFL */
1101 if (interrupt_input
)
1105 while (! EMACS_SET_TTY (input_fd
, &old_tty
, 0) && errno
== EINTR
)
1115 /* Set up the proper status flags for use of a pty. */
1120 /* I'm told that TOICREMOTE does not mean control chars
1121 "can't be sent" but rather that they don't have
1122 input-editing or signaling effects.
1123 That should be good, because we have other ways
1124 to do those things in Emacs.
1125 However, telnet mode seems not to work on 4.2.
1126 So TIOCREMOTE is turned off now. */
1128 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1129 will hang. In particular, the "timeout" feature (which
1130 causes a read to return if there is no data available)
1131 does this. Also it is known that telnet mode will hang
1132 in such a way that Emacs must be stopped (perhaps this
1133 is the same problem).
1135 If TIOCREMOTE is turned off, then there is a bug in
1136 hp-ux which sometimes loses data. Apparently the
1137 code which blocks the master process when the internal
1138 buffer fills up does not work. Other than this,
1139 though, everything else seems to work fine.
1141 Since the latter lossage is more benign, we may as well
1142 lose that way. -- cph */
1147 ioctl (fd
, FIONBIO
, &on
);
1152 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1153 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1154 /* cause EMACS not to die when it should, i.e., when its own controlling */
1155 /* tty goes away. I've complained to the AIX developers, and they may */
1156 /* change this behavior, but I'm not going to hold my breath. */
1157 signal (SIGHUP
, SIG_IGN
);
1160 #endif /* HAVE_PTYS */
1164 /* Assigning an input channel is done at the start of Emacs execution.
1165 This is called each time Emacs is resumed, also, but does nothing
1166 because input_chain is no longer zero. */
1174 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1180 /* Deassigning the input channel is done before exiting. */
1184 return SYS$
DASSGN (input_fd
);
1189 /* Request reading one character into the keyboard buffer.
1190 This is done as soon as the buffer becomes empty. */
1195 extern kbd_input_ast ();
1197 waiting_for_ast
= 0;
1199 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1200 &input_iosb
, kbd_input_ast
, 1,
1201 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1206 /* Ast routine that is called when keyboard input comes in
1207 in accord with the SYS$QIO above. */
1211 register int c
= -1;
1212 int old_errno
= errno
;
1213 extern EMACS_TIME
*input_available_clear_time
;
1215 if (waiting_for_ast
)
1216 SYS$
SETEF (input_ef
);
1217 waiting_for_ast
= 0;
1220 if (input_count
== 25)
1222 printf ("Ast # %d,", input_count
);
1223 printf (" iosb = %x, %x, %x, %x",
1224 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1227 if (input_iosb
.offset
)
1231 printf (", char = 0%o", c
);
1243 struct input_event e
;
1244 e
.kind
= ascii_keystroke
;
1245 XSET (e
.code
, Lisp_Int
, c
);
1247 XSET(e
.frame_or_window
, Lisp_Frame
, selected_frame
);
1249 e
.frame_or_window
= Qnil
;
1251 kbd_buffer_store_event (&e
);
1253 if (input_available_clear_time
)
1254 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1258 /* Wait until there is something in kbd_buffer. */
1260 wait_for_kbd_input ()
1262 extern int have_process_input
, process_exited
;
1264 /* If already something, avoid doing system calls. */
1265 if (detect_input_pending ())
1269 /* Clear a flag, and tell ast routine above to set it. */
1270 SYS$
CLREF (input_ef
);
1271 waiting_for_ast
= 1;
1272 /* Check for timing error: ast happened while we were doing that. */
1273 if (!detect_input_pending ())
1275 /* No timing error: wait for flag to be set. */
1276 set_waiting_for_input (0);
1277 SYS$
WFLOR (input_ef
, input_eflist
);
1278 clear_waiting_for_input (0);
1279 if (!detect_input_pending ())
1280 /* Check for subprocess input availability */
1282 int dsp
= have_process_input
|| process_exited
;
1284 SYS$
CLREF (process_ef
);
1285 if (have_process_input
)
1286 process_command_input ();
1291 update_mode_lines
++;
1292 redisplay_preserve_echo_area ();
1296 waiting_for_ast
= 0;
1299 /* Get rid of any pending QIO, when we are about to suspend
1300 or when we want to throw away pending input.
1301 We wait for a positive sign that the AST routine has run
1302 and therefore there is no I/O request queued when we return.
1303 SYS$SETAST is used to avoid a timing error. */
1308 printf ("At end_kbd_input.\n");
1312 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
1314 SYS$
CANCEL (input_fd
);
1319 /* Clear a flag, and tell ast routine above to set it. */
1320 SYS$
CLREF (input_ef
);
1321 waiting_for_ast
= 1;
1323 SYS$
CANCEL (input_fd
);
1325 SYS$
WAITFR (input_ef
);
1326 waiting_for_ast
= 0;
1329 /* Wait for either input available or time interval expiry. */
1331 input_wait_timeout (timeval
)
1332 int timeval
; /* Time to wait, in seconds */
1335 static int zero
= 0;
1336 static int large
= -10000000;
1338 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1340 /* If already something, avoid doing system calls. */
1341 if (detect_input_pending ())
1345 /* Clear a flag, and tell ast routine above to set it. */
1346 SYS$
CLREF (input_ef
);
1347 waiting_for_ast
= 1;
1348 /* Check for timing error: ast happened while we were doing that. */
1349 if (!detect_input_pending ())
1351 /* No timing error: wait for flag to be set. */
1353 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1354 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
1356 waiting_for_ast
= 0;
1359 /* The standard `sleep' routine works some other way
1360 and it stops working if you have ever quit out of it.
1361 This one continues to work. */
1367 static int zero
= 0;
1368 static int large
= -10000000;
1370 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1373 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1374 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
1389 croak ("request sigio");
1394 croak ("unrequest sigio");
1399 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
1404 #ifndef SYSTEM_MALLOC
1411 /* Some systems that cannot dump also cannot implement these. */
1414 * Return the address of the start of the text segment prior to
1415 * doing an unexec. After unexec the return value is undefined.
1416 * See crt0.c for further explanation and _start.
1420 #ifndef CANNOT_UNEXEC
1425 return ((char *) TEXT_START
);
1429 return ((char *) csrt
);
1430 #else /* not GOULD */
1431 extern int _start ();
1432 return ((char *) _start
);
1434 #endif /* TEXT_START */
1436 #endif /* not CANNOT_UNEXEC */
1439 * Return the address of the start of the data segment prior to
1440 * doing an unexec. After unexec the return value is undefined.
1441 * See crt0.c for further information and definition of data_start.
1443 * Apparently, on BSD systems this is etext at startup. On
1444 * USG systems (swapping) this is highly mmu dependent and
1445 * is also dependent on whether or not the program is running
1446 * with shared text. Generally there is a (possibly large)
1447 * gap between end of text and start of data with shared text.
1449 * On Uniplus+ systems with shared text, data starts at a
1450 * fixed address. Each port (from a given oem) is generally
1451 * different, and the specific value of the start of data can
1452 * be obtained via the UniPlus+ specific "uvar" system call,
1453 * however the method outlined in crt0.c seems to be more portable.
1455 * Probably what will have to happen when a USG unexec is available,
1456 * at least on UniPlus, is temacs will have to be made unshared so
1457 * that text and data are contiguous. Then once loadup is complete,
1458 * unexec will produce a shared executable where the data can be
1459 * at the normal shared text boundry and the startofdata variable
1460 * will be patched by unexec to the correct value.
1468 return ((char *) DATA_START
);
1470 #ifdef ORDINARY_LINK
1472 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
1473 * data_start isn't defined. We take the address of environ, which
1474 * is known to live at or near the start of the system crt0.c, and
1475 * we don't sweat the handful of bytes that might lose.
1477 extern char **environ
;
1479 return((char *) &environ
);
1481 extern int data_start
;
1482 return ((char *) &data_start
);
1483 #endif /* ORDINARY_LINK */
1484 #endif /* DATA_START */
1486 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
1489 /* Some systems that cannot dump also cannot implement these. */
1492 * Return the address of the end of the text segment prior to
1493 * doing an unexec. After unexec the return value is undefined.
1500 return ((char *) TEXT_END
);
1503 return ((char *) &etext
);
1508 * Return the address of the end of the data segment prior to
1509 * doing an unexec. After unexec the return value is undefined.
1516 return ((char *) DATA_END
);
1519 return ((char *) &edata
);
1523 #endif /* not CANNOT_DUMP */
1525 /* Get_system_name returns as its value
1526 a string for the Lisp function system-name to return. */
1532 /* Can't have this within the function since `static' is #defined to
1533 nothing for some USG systems. */
1535 #ifdef HAVE_GETHOSTNAME
1536 static char get_system_name_name
[256];
1537 #else /* not HAVE_GETHOSTNAME */
1538 static struct utsname get_system_name_name
;
1539 #endif /* not HAVE_GETHOSTNAME */
1546 #ifdef HAVE_GETHOSTNAME
1547 gethostname (get_system_name_name
, sizeof (get_system_name_name
));
1548 return get_system_name_name
;
1549 #else /* not HAVE_GETHOSTNAME */
1550 uname (&get_system_name_name
);
1551 return (get_system_name_name
.nodename
);
1552 #endif /* not HAVE_GETHOSTNAME */
1556 #else /* not USG, not 4.1 */
1557 static char system_name_saved
[32];
1560 if ((sp
= egetenv ("SYS$NODE")) == 0)
1566 if ((end
= index (sp
, ':')) != 0)
1569 strcpy (system_name_saved
, sp
);
1571 gethostname (system_name_saved
, sizeof (system_name_saved
));
1572 #endif /* not VMS */
1573 return system_name_saved
;
1574 #endif /* not USG, not 4.1 */
1575 #endif /* not USG */
1579 #ifndef HAVE_GETHOSTNAME
1580 void gethostname(buf
, len
)
1585 s
= getenv ("SYS$NODE");
1589 strncpy (buf
, s
, len
- 2);
1590 buf
[len
- 1] = '\0';
1592 } /* static void gethostname */
1593 #endif /* ! HAVE_GETHOSTNAME */
1600 #ifdef HAVE_X_WINDOWS
1601 /* Cause explanatory error message at compile time,
1602 since the select emulation is not good enough for X. */
1603 int *x
= &x_windows_lose_if_no_select_system_call
;
1606 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
1607 * Only checks read descriptors.
1609 /* How long to wait between checking fds in select */
1610 #define SELECT_PAUSE 1
1613 /* For longjmp'ing back to read_input_waiting. */
1615 jmp_buf read_alarm_throw
;
1617 /* Nonzero if the alarm signal should throw back to read_input_waiting.
1618 The read_socket_hook function sets this to 1 while it is waiting. */
1620 int read_alarm_should_throw
;
1628 #else /* not BSD4_1 */
1629 signal (SIGALRM
, SIG_IGN
);
1630 #endif /* not BSD4_1 */
1631 if (read_alarm_should_throw
)
1632 longjmp (read_alarm_throw
, 1);
1635 /* Only rfds are checked. */
1637 select (nfds
, rfds
, wfds
, efds
, timeout
)
1639 int *rfds
, *wfds
, *efds
, *timeout
;
1641 int ravail
= 0, orfds
= 0, old_alarm
;
1642 int timeoutval
= timeout
? *timeout
: 100000;
1643 int *local_timeout
= &timeoutval
;
1644 extern int proc_buffered_char
[];
1645 #ifndef subprocesses
1646 int process_tick
= 0, update_tick
= 0;
1648 extern int process_tick
, update_tick
;
1650 SIGTYPE (*old_trap
) ();
1663 /* If we are looking only for the terminal, with no timeout,
1664 just read it and wait -- that's more efficient. */
1665 if (orfds
== 1 && *local_timeout
== 100000 && process_tick
== update_tick
)
1667 if (! detect_input_pending ())
1668 read_input_waiting ();
1673 /* Once a second, till the timer expires, check all the flagged read
1674 * descriptors to see if any input is available. If there is some then
1675 * set the corresponding bit in the return copy of rfds.
1679 register int to_check
, bit
, fd
;
1683 for (to_check
= nfds
, bit
= 1, fd
= 0; --to_check
>= 0; bit
<<= 1, fd
++)
1687 int avail
= 0, status
= 0;
1690 avail
= detect_input_pending (); /* Special keyboard handler */
1694 status
= ioctl (fd
, FIONREAD
, &avail
);
1695 #else /* no FIONREAD */
1696 /* Hoping it will return -1 if nothing available
1697 or 0 if all 0 chars requested are read. */
1698 if (proc_buffered_char
[fd
] >= 0)
1702 avail
= read (fd
, &buf
, 1);
1704 proc_buffered_char
[fd
] = buf
;
1706 #endif /* no FIONREAD */
1708 if (status
>= 0 && avail
> 0)
1716 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
1718 old_alarm
= alarm (0);
1719 old_trap
= signal (SIGALRM
, select_alarm
);
1721 alarm (SELECT_PAUSE
);
1722 /* Wait for a SIGALRM (or maybe a SIGTINT) */
1723 while (select_alarmed
== 0 && *local_timeout
!= 0
1724 && process_tick
== update_tick
)
1726 /* If we are interested in terminal input,
1727 wait by reading the terminal.
1728 That makes instant wakeup for terminal input at least. */
1731 read_input_waiting ();
1732 if (detect_input_pending ())
1738 (*local_timeout
) -= SELECT_PAUSE
;
1739 /* Reset the old alarm if there was one */
1741 signal (SIGALRM
, old_trap
);
1744 /* Reset or forge an interrupt for the original handler. */
1745 old_alarm
-= SELECT_PAUSE
;
1747 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
1751 if (*local_timeout
== 0) /* Stop on timer being cleared */
1757 /* Read keyboard input into the standard buffer,
1758 waiting for at least one character. */
1760 /* Make all keyboard buffers much bigger when using X windows. */
1761 #ifdef HAVE_X_WINDOWS
1762 #define BUFFER_SIZE_FACTOR 16
1764 #define BUFFER_SIZE_FACTOR 1
1767 read_input_waiting ()
1769 char buf
[256 * BUFFER_SIZE_FACTOR
];
1770 struct input_event e
;
1772 extern int quit_char
;
1774 if (read_socket_hook
)
1776 read_alarm_should_throw
= 0;
1777 if (! setjmp (read_alarm_throw
))
1778 nread
= (*read_socket_hook
) (0, buf
, 256 * BUFFER_SIZE_FACTOR
, 1, 0);
1783 nread
= read (fileno (stdin
), buf
, 1);
1785 /* Scan the chars for C-g and store them in kbd_buffer. */
1786 e
.kind
= ascii_keystroke
;
1787 e
.frame_or_window
= selected_frame
;
1788 for (i
= 0; i
< nread
; i
++)
1790 XSET (e
.code
, Lisp_Int
, buf
[i
]);
1791 kbd_buffer_store_event (&e
);
1792 /* Don't look at input that follows a C-g too closely.
1793 This reduces lossage due to autorepeat on C-g. */
1794 if (buf
[i
] == quit_char
)
1799 #endif /* not HAVE_SELECT */
1800 #endif /* not VMS */
1804 * Partially emulate 4.2 open call.
1805 * open is defined as this in 4.1.
1807 * - added by Michael Bloom @ Citicorp/TTI
1812 sys_open (path
, oflag
, mode
)
1816 if (oflag
& O_CREAT
)
1817 return creat (path
, mode
);
1819 return open (path
, oflag
);
1826 lmode
= LINTRUP
| lmode
;
1827 ioctl (0, TIOCLSET
, &lmode
);
1834 lmode
= ~LINTRUP
& lmode
;
1835 ioctl (0, TIOCLSET
, &lmode
);
1842 interrupts_deferred
= 0;
1849 interrupts_deferred
= 1;
1852 /* still inside #ifdef BSD4_1 */
1855 int sigheld
; /* Mask of held signals */
1860 sigheld
|= sigbit (signum
);
1867 sigheld
|= sigbit (signum
);
1873 sigheld
&= ~sigbit (signum
);
1877 sigfree () /* Free all held signals */
1880 for (i
= 0; i
< NSIG
; i
++)
1881 if (sigheld
& sigbit (i
))
1888 return 1 << (i
- 1);
1890 #endif /* subprocesses */
1893 /* POSIX signals support - DJB */
1894 /* Anyone with POSIX signals should have ANSI C declarations */
1896 #ifdef POSIX_SIGNALS
1898 sigset_t old_mask
, empty_mask
, full_mask
, temp_mask
;
1899 static struct sigaction new_action
, old_action
;
1903 #ifdef POSIX_SIGNALS
1904 sigemptyset (&signal_empty_mask
);
1905 sigfillset (&signal_full_mask
);
1909 int (*signal_handler_t
) ();
1912 sys_signal (int signal_number
, signal_handler_t action
)
1915 /* This gets us restartable system calls for efficiency.
1916 The "else" code will works as well. */
1917 return (berk_signal (signal_number
, action
));
1919 sigemptyset (&new_action
.sa_mask
);
1920 new_action
.sa_handler
= action
;
1921 new_action
.sa_flags
= NULL
;
1922 sigaction (signal_number
, &new_action
, &old_action
);
1923 return (old_action
.sa_handler
);
1928 /* If we're compiling with GCC, we don't need this function, since it
1929 can be written as a macro. */
1931 sys_sigmask (int sig
)
1934 sigemptyset (&mask
);
1935 sigaddset (&mask
, sig
);
1941 sys_sigpause (sigset_t new_mask
)
1943 /* pause emulating berk sigpause... */
1944 sigsuspend (&new_mask
);
1948 /* I'd like to have these guys return pointers to the mask storage in here,
1949 but there'd be trouble if the code was saving multiple masks. I'll be
1950 safe and pass the structure. It normally won't be more than 2 bytes
1954 sys_sigblock (sigset_t new_mask
)
1957 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
1962 sys_sigunblock (sigset_t new_mask
)
1965 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
1970 sys_sigsetmask (sigset_t new_mask
)
1973 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
1977 #endif /* POSIX_SIGNALS */
1984 register int length
;
1988 long max_str
= 65535;
1990 while (length
> max_str
) {
1991 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
1996 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
1998 while (length
-- > 0)
2000 #endif /* not VMS */
2003 /* Saying `void' requires a declaration, above, where bcopy is used
2004 and that declaration causes pain for systems where bcopy is a macro. */
2005 bcopy (b1
, b2
, length
)
2008 register int length
;
2011 long max_str
= 65535;
2013 while (length
> max_str
) {
2014 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
2020 (void) LIB$
MOVC3 (&length
, b1
, b2
);
2022 while (length
-- > 0)
2024 #endif /* not VMS */
2028 bcmp (b1
, b2
, length
) /* This could be a macro! */
2031 register int length
;
2034 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
2035 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
2037 return STR$
COMPARE (&src1
, &src2
);
2039 while (length
-- > 0)
2044 #endif /* not VMS */
2046 #endif /* not BSTRING */
2051 * The BSD random returns numbers in the range of
2052 * 0 to 2e31 - 1. The USG rand returns numbers in the
2053 * range of 0 to 2e15 - 1. This is probably not significant
2060 /* Arrange to return a range centered on zero. */
2061 return (rand () << 15) + rand () - (1 << 29);
2075 /* Arrange to return a range centered on zero. */
2076 return (rand () << 15) + rand () - (1 << 29);
2087 #ifdef WRONG_NAME_INSQUE
2100 /* If any place else asks for the TERM variable,
2101 allow it to be overridden with the EMACS_TERM variable
2102 before attempting to translate the logical name TERM. As a last
2103 resort, ask for VAX C's special idea of the TERM variable. */
2110 static char buf
[256];
2111 static struct dsc$descriptor_s equiv
2112 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2113 static struct dsc$descriptor_s d_name
2114 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2117 if (!strcmp (name
, "TERM"))
2119 val
= (char *) getenv ("EMACS_TERM");
2124 d_name
.dsc$w_length
= strlen (name
);
2125 d_name
.dsc$a_pointer
= name
;
2126 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2128 char *str
= (char *) xmalloc (eqlen
+ 1);
2129 bcopy (buf
, str
, eqlen
);
2131 /* This is a storage leak, but a pain to fix. With luck,
2132 no one will ever notice. */
2135 return (char *) getenv (name
);
2140 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2141 to force a call on the debugger from within the image. */
2146 LIB$
SIGNAL (SS$_DEBUG
);
2152 #ifdef LINK_CRTL_SHARE
2153 #ifdef SHAREABLE_LIB_BUG
2154 /* Variables declared noshare and initialized in shareable libraries
2155 cannot be shared. The VMS linker incorrectly forces you to use a private
2156 version which is uninitialized... If not for this "feature", we
2157 could use the C library definition of sys_nerr and sys_errlist. */
2159 char *sys_errlist
[] =
2163 "no such file or directory",
2165 "interrupted system call",
2167 "no such device or address",
2168 "argument list too long",
2169 "exec format error",
2172 "no more processes",
2173 "not enough memory",
2174 "permission denied",
2176 "block device required",
2177 "mount devices busy",
2179 "cross-device link",
2184 "file table overflow",
2185 "too many open files",
2189 "no space left on device",
2191 "read-only file system",
2197 "vax/vms specific error code nontranslatable error"
2199 #endif /* SHAREABLE_LIB_BUG */
2200 #endif /* LINK_CRTL_SHARE */
2203 #ifdef INTERRUPTIBLE_OPEN
2207 sys_open (path
, oflag
, mode
)
2211 register int rtnval
;
2213 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2214 && (errno
== EINTR
));
2218 #endif /* INTERRUPTIBLE_OPEN */
2220 #ifdef INTERRUPTIBLE_CLOSE
2225 register int rtnval
;
2227 while ((rtnval
= close (fd
)) == -1
2228 && (errno
== EINTR
));
2232 #endif /* INTERRUPTIBLE_CLOSE */
2234 #ifdef INTERRUPTIBLE_IO
2237 sys_read (fildes
, buf
, nbyte
)
2242 register int rtnval
;
2244 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
2245 && (errno
== EINTR
));
2250 sys_write (fildes
, buf
, nbyte
)
2255 register int rtnval
;
2257 while ((rtnval
= write (fildes
, buf
, nbyte
)) == -1
2258 && (errno
== EINTR
));
2262 #endif /* INTERRUPTIBLE_IO */
2266 * All of the following are for USG.
2268 * On USG systems the system calls are INTERRUPTIBLE by signals
2269 * that the user program has elected to catch. Thus the system call
2270 * must be retried in these cases. To handle this without massive
2271 * changes in the source code, we remap the standard system call names
2272 * to names for our own functions in sysdep.c that do the system call
2273 * with retries. Actually, for portability reasons, it is good
2274 * programming practice, as this example shows, to limit all actual
2275 * system calls to a single occurance in the source. Sure, this
2276 * adds an extra level of function call overhead but it is almost
2277 * always negligible. Fred Fish, Unisoft Systems Inc.
2280 char *sys_siglist
[NSIG
+ 1] =
2283 /* AIX has changed the signals a bit */
2284 "bogus signal", /* 0 */
2285 "hangup", /* 1 SIGHUP */
2286 "interrupt", /* 2 SIGINT */
2287 "quit", /* 3 SIGQUIT */
2288 "illegal instruction", /* 4 SIGILL */
2289 "trace trap", /* 5 SIGTRAP */
2290 "IOT instruction", /* 6 SIGIOT */
2291 "crash likely", /* 7 SIGDANGER */
2292 "floating point exception", /* 8 SIGFPE */
2293 "kill", /* 9 SIGKILL */
2294 "bus error", /* 10 SIGBUS */
2295 "segmentation violation", /* 11 SIGSEGV */
2296 "bad argument to system call", /* 12 SIGSYS */
2297 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2298 "alarm clock", /* 14 SIGALRM */
2299 "software termination signum", /* 15 SIGTERM */
2300 "user defined signal 1", /* 16 SIGUSR1 */
2301 "user defined signal 2", /* 17 SIGUSR2 */
2302 "death of a child", /* 18 SIGCLD */
2303 "power-fail restart", /* 19 SIGPWR */
2304 "bogus signal", /* 20 */
2305 "bogus signal", /* 21 */
2306 "bogus signal", /* 22 */
2307 "bogus signal", /* 23 */
2308 "bogus signal", /* 24 */
2309 "LAN I/O interrupt", /* 25 SIGAIO */
2310 "PTY I/O interrupt", /* 26 SIGPTY */
2311 "I/O intervention required", /* 27 SIGIOINT */
2312 "HFT grant", /* 28 SIGGRANT */
2313 "HFT retract", /* 29 SIGRETRACT */
2314 "HFT sound done", /* 30 SIGSOUND */
2315 "HFT input ready", /* 31 SIGMSG */
2317 "bogus signal", /* 0 */
2318 "hangup", /* 1 SIGHUP */
2319 "interrupt", /* 2 SIGINT */
2320 "quit", /* 3 SIGQUIT */
2321 "illegal instruction", /* 4 SIGILL */
2322 "trace trap", /* 5 SIGTRAP */
2323 "IOT instruction", /* 6 SIGIOT */
2324 "EMT instruction", /* 7 SIGEMT */
2325 "floating point exception", /* 8 SIGFPE */
2326 "kill", /* 9 SIGKILL */
2327 "bus error", /* 10 SIGBUS */
2328 "segmentation violation", /* 11 SIGSEGV */
2329 "bad argument to system call", /* 12 SIGSYS */
2330 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2331 "alarm clock", /* 14 SIGALRM */
2332 "software termination signum", /* 15 SIGTERM */
2333 "user defined signal 1", /* 16 SIGUSR1 */
2334 "user defined signal 2", /* 17 SIGUSR2 */
2335 "death of a child", /* 18 SIGCLD */
2336 "power-fail restart", /* 19 SIGPWR */
2337 #endif /* not AIX */
2342 * Warning, this function may not duplicate 4.2 action properly
2343 * under error conditions.
2347 /* In 4.1, param.h fails to define this. */
2348 #define MAXPATHLEN 1024
2357 char *npath
, *spath
;
2358 extern char *getcwd ();
2360 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
2361 /* On Altos 3068, getcwd can return @hostname/dir, so discard
2362 up to first slash. Should be harmless on other systems. */
2363 while (*npath
&& *npath
!= '/')
2365 strcpy (pathname
, npath
);
2366 free (spath
); /* getcwd uses malloc */
2370 #endif /* HAVE_GETWD */
2373 * Emulate rename using unlink/link. Note that this is
2374 * only partially correct. Also, doesn't enforce restriction
2375 * that files be of same type (regular->regular, dir->dir, etc).
2384 if (access (from
, 0) == 0)
2387 if (link (from
, to
) == 0)
2388 if (unlink (from
) == 0)
2399 * Substitute fork for vfork on USG flavors.
2407 #endif /* not HAVE_VFORK */
2409 #ifdef MISSING_UTIMES
2411 /* HPUX (among others) sets HAVE_TIMEVAL but does not implement utimes. */
2420 /* The IRIS (3.5) has timevals, but uses sys V utime, and doesn't have the
2421 utimbuf structure defined anywhere but in the man page. */
2431 struct timeval tvp
[];
2434 utb
.actime
= tvp
[0].tv_sec
;
2435 utb
.modtime
= tvp
[1].tv_sec
;
2438 #endif /* IRIS_UTIME */
2444 /* HPUX curses library references perror, but as far as we know
2445 it won't be called. Anyway this definition will do for now. */
2451 #endif /* not HAVE_PERROR */
2457 * Emulate BSD dup2. First close newd if it already exists.
2458 * Then, attempt to dup oldd. If not successful, call dup2 recursively
2459 * until we are, then close the unsuccessful ones.
2466 register int fd
, ret
;
2471 fd
= fcntl (oldd
, F_DUPFD
, newd
);
2473 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, sys_errlist
[errno
]);
2480 ret
= dup2 (old
,new);
2486 #endif /* not HAVE_DUP2 */
2489 * Gettimeofday. Simulate as much as possible. Only accurate
2490 * to nearest second. Emacs doesn't use tzp so ignore it for now.
2491 * Only needed when subprocesses are defined.
2496 #ifndef HAVE_GETTIMEOFDAY
2500 gettimeofday (tp
, tzp
)
2502 struct timezone
*tzp
;
2504 extern long time ();
2506 tp
->tv_sec
= time ((long *)0);
2508 tzp
->tz_minuteswest
= -1;
2514 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
2517 * This function will go away as soon as all the stubs fixed. (fnf)
2523 printf ("%s not yet implemented\r\n", badfunc
);
2532 char *sys_siglist
[NSIG
+ 1] =
2534 "null signal", /* 0 SIGNULL */
2535 "hangup", /* 1 SIGHUP */
2536 "interrupt", /* 2 SIGINT */
2537 "quit", /* 3 SIGQUIT */
2538 "illegal instruction", /* 4 SIGILL */
2539 "trace trap", /* 5 SIGTRAP */
2540 "abort termination", /* 6 SIGABRT */
2541 "SIGEMT", /* 7 SIGEMT */
2542 "floating point exception", /* 8 SIGFPE */
2543 "kill", /* 9 SIGKILL */
2544 "bus error", /* 10 SIGBUS */
2545 "segmentation violation", /* 11 SIGSEGV */
2546 "bad argument to system call", /* 12 SIGSYS */
2547 "write on a pipe with no reader", /* 13 SIGPIPE */
2548 "alarm clock", /* 14 SIGALRM */
2549 "software termination signal", /* 15 SIGTERM */
2550 "user defined signal 1", /* 16 SIGUSR1 */
2551 "user defined signal 2", /* 17 SIGUSR2 */
2552 "child stopped or terminated", /* 18 SIGCLD */
2553 "power-fail restart", /* 19 SIGPWR */
2554 "window size changed", /* 20 SIGWINCH */
2555 "undefined", /* 21 */
2556 "pollable event occured", /* 22 SIGPOLL */
2557 "sendable stop signal not from tty", /* 23 SIGSTOP */
2558 "stop signal from tty", /* 24 SIGSTP */
2559 "continue a stopped process", /* 25 SIGCONT */
2560 "attempted background tty read", /* 26 SIGTTIN */
2561 "attempted background tty write", /* 27 SIGTTOU */
2562 "undefined", /* 28 */
2563 "undefined", /* 29 */
2564 "undefined", /* 30 */
2565 "undefined", /* 31 */
2566 "undefined", /* 32 */
2567 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
2568 "I/O is possible", /* 34 SIGIO */
2569 "exceeded cpu time limit", /* 35 SIGXCPU */
2570 "exceeded file size limit", /* 36 SIGXFSZ */
2571 "virtual time alarm", /* 37 SIGVTALRM */
2572 "profiling time alarm", /* 38 SIGPROF */
2573 "undefined", /* 39 */
2574 "file record locks revoked", /* 40 SIGLOST */
2575 "undefined", /* 41 */
2576 "undefined", /* 42 */
2577 "undefined", /* 43 */
2578 "undefined", /* 44 */
2579 "undefined", /* 45 */
2580 "undefined", /* 46 */
2581 "undefined", /* 47 */
2582 "undefined", /* 48 */
2583 "undefined", /* 49 */
2584 "undefined", /* 50 */
2585 "undefined", /* 51 */
2586 "undefined", /* 52 */
2587 "undefined", /* 53 */
2588 "undefined", /* 54 */
2589 "undefined", /* 55 */
2590 "undefined", /* 56 */
2591 "undefined", /* 57 */
2592 "undefined", /* 58 */
2593 "undefined", /* 59 */
2594 "undefined", /* 60 */
2595 "undefined", /* 61 */
2596 "undefined", /* 62 */
2597 "undefined", /* 63 */
2598 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
2604 /* Directory routines for systems that don't have them. */
2606 #ifdef SYSV_SYSTEM_DIR
2613 register DIR *dirp
; /* stream from opendir */
2615 sys_close (dirp
->dd_fd
);
2616 free ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
2617 free ((char *) dirp
);
2619 #endif /* not AIX */
2620 #endif /* SYSV_SYSTEM_DIR */
2622 #ifdef NONSYSTEM_DIR_LIBRARY
2626 char *filename
; /* name of directory */
2628 register DIR *dirp
; /* -> malloc'ed storage */
2629 register int fd
; /* file descriptor for read */
2630 struct stat sbuf
; /* result of fstat */
2632 fd
= sys_open (filename
, 0);
2636 if (fstat (fd
, &sbuf
) < 0
2637 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
2638 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
2641 return 0; /* bad luck today */
2645 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
2652 register DIR *dirp
; /* stream from opendir */
2654 sys_close (dirp
->dd_fd
);
2655 free ((char *) dirp
);
2663 ino_t od_ino
; /* inode */
2664 char od_name
[DIRSIZ
]; /* filename */
2666 #endif /* not VMS */
2668 struct direct dir_static
; /* simulated directory contents */
2673 register DIR *dirp
; /* stream from opendir */
2676 register struct olddir
*dp
; /* -> directory data */
2678 register struct dir$_name
*dp
; /* -> directory data */
2679 register struct dir$_version
*dv
; /* -> version data */
2684 if (dirp
->dd_loc
>= dirp
->dd_size
)
2685 dirp
->dd_loc
= dirp
->dd_size
= 0;
2687 if (dirp
->dd_size
== 0 /* refill buffer */
2688 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
2692 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
2693 dirp
->dd_loc
+= sizeof (struct olddir
);
2695 if (dp
->od_ino
!= 0) /* not deleted entry */
2697 dir_static
.d_ino
= dp
->od_ino
;
2698 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
2699 dir_static
.d_name
[DIRSIZ
] = '\0';
2700 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
2701 dir_static
.d_reclen
= sizeof (struct direct
)
2703 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
2704 return &dir_static
; /* -> simulated structure */
2707 dp
= (struct dir$_name
*) dirp
->dd_buf
;
2708 if (dirp
->dd_loc
== 0)
2709 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
2710 : dp
->dir$b_namecount
;
2711 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
2712 dir_static
.d_ino
= dv
->dir$w_fid_num
;
2713 dir_static
.d_namlen
= dp
->dir$b_namecount
;
2714 dir_static
.d_reclen
= sizeof (struct direct
)
2716 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
2717 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
2718 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
2719 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
2726 /* readdirver is just like readdir except it returns all versions of a file
2727 as separate entries. */
2732 register DIR *dirp
; /* stream from opendir */
2734 register struct dir$_name
*dp
; /* -> directory data */
2735 register struct dir$_version
*dv
; /* -> version data */
2737 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
2738 dirp
->dd_loc
= dirp
->dd_size
= 0;
2740 if (dirp
->dd_size
== 0 /* refill buffer */
2741 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
2744 dp
= (struct dir$_name
*) dirp
->dd_buf
;
2745 if (dirp
->dd_loc
== 0)
2746 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
2747 : dp
->dir$b_namecount
;
2748 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
2749 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
2750 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
2751 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
2752 dir_static
.d_ino
= dv
->dir$w_fid_num
;
2753 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
2754 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
2755 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
2761 #endif /* NONSYSTEM_DIR_LIBRARY */
2763 /* Functions for VMS */
2765 #include "vms-pwd.h"
2770 /* Return as a string the VMS error string pertaining to STATUS.
2771 Reuses the same static buffer each time it is called. */
2775 int status
; /* VMS status code */
2779 static char buf
[257];
2781 bufadr
[0] = sizeof buf
- 1;
2782 bufadr
[1] = (int) buf
;
2783 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
2784 return "untranslatable VMS error status";
2792 /* The following is necessary because 'access' emulation by VMS C (2.0) does
2793 * not work correctly. (It also doesn't work well in version 2.3.)
2798 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
2799 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
2803 unsigned short s_buflen
;
2804 unsigned short s_code
;
2806 unsigned short *s_retlenadr
;
2810 #define buflen s.s_buflen
2811 #define code s.s_code
2812 #define bufadr s.s_bufadr
2813 #define retlenadr s.s_retlenadr
2815 #define R_OK 4 /* test for read permission */
2816 #define W_OK 2 /* test for write permission */
2817 #define X_OK 1 /* test for execute (search) permission */
2818 #define F_OK 0 /* test for presence of file */
2821 sys_access (path
, mode
)
2825 static char *user
= NULL
;
2828 /* translate possible directory spec into .DIR file name, so brain-dead
2829 * access can treat the directory like a file. */
2830 if (directory_file_name (path
, dir_fn
))
2834 return access (path
, mode
);
2835 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
2841 unsigned short int dummy
;
2843 static int constant
= ACL$C_FILE
;
2844 DESCRIPTOR (path_desc
, path
);
2845 DESCRIPTOR (user_desc
, user
);
2849 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
2852 acces
|= CHP$M_READ
;
2854 acces
|= CHP$M_WRITE
;
2855 itemlst
[0].buflen
= sizeof (int);
2856 itemlst
[0].code
= CHP$_FLAGS
;
2857 itemlst
[0].bufadr
= (char *) &flags
;
2858 itemlst
[0].retlenadr
= &dummy
;
2859 itemlst
[1].buflen
= sizeof (int);
2860 itemlst
[1].code
= CHP$_ACCESS
;
2861 itemlst
[1].bufadr
= (char *) &acces
;
2862 itemlst
[1].retlenadr
= &dummy
;
2863 itemlst
[2].end
= CHP$_END
;
2864 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
2865 return stat
== SS$_NORMAL
? 0 : -1;
2869 #else /* not VMS4_4 */
2872 #define ACE$M_WRITE 2
2873 #define ACE$C_KEYID 1
2875 static unsigned short memid
, grpid
;
2876 static unsigned int uic
;
2878 /* Called from init_sys_modes, so it happens not very often
2879 but at least each time Emacs is loaded. */
2880 sys_access_reinit ()
2886 sys_access (filename
, type
)
2892 int status
, size
, i
, typecode
, acl_controlled
;
2893 unsigned int *aclptr
, *aclend
, aclbuf
[60];
2894 union prvdef prvmask
;
2896 /* Get UIC and GRP values for protection checking. */
2899 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
2902 memid
= uic
& 0xFFFF;
2906 if (type
!= 2) /* not checking write access */
2907 return access (filename
, type
);
2909 /* Check write protection. */
2911 #define CHECKPRIV(bit) (prvmask.bit)
2912 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
2914 /* Find privilege bits */
2915 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
2917 error ("Unable to find privileges: %s", vmserrstr (status
));
2918 if (CHECKPRIV (PRV$V_BYPASS
))
2919 return 0; /* BYPASS enabled */
2921 fab
.fab$b_fac
= FAB$M_GET
;
2922 fab
.fab$l_fna
= filename
;
2923 fab
.fab$b_fns
= strlen (filename
);
2924 fab
.fab$l_xab
= &xab
;
2925 xab
= cc$rms_xabpro
;
2926 xab
.xab$l_aclbuf
= aclbuf
;
2927 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
2928 status
= SYS$
OPEN (&fab
, 0, 0);
2931 SYS$
CLOSE (&fab
, 0, 0);
2932 /* Check system access */
2933 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITEABLE (XAB$V_SYS
))
2935 /* Check ACL entries, if any */
2937 if (xab
.xab$w_acllen
> 0)
2940 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
2941 while (*aclptr
&& aclptr
< aclend
)
2943 size
= (*aclptr
& 0xff) / 4;
2944 typecode
= (*aclptr
>> 8) & 0xff;
2945 if (typecode
== ACE$C_KEYID
)
2946 for (i
= size
- 1; i
> 1; i
--)
2947 if (aclptr
[i
] == uic
)
2950 if (aclptr
[1] & ACE$M_WRITE
)
2951 return 0; /* Write access through ACL */
2953 aclptr
= &aclptr
[size
];
2955 if (acl_controlled
) /* ACL specified, prohibits write access */
2958 /* No ACL entries specified, check normal protection */
2959 if (WRITEABLE (XAB$V_WLD
)) /* World writeable */
2961 if (WRITEABLE (XAB$V_GRP
) &&
2962 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
2963 return 0; /* Group writeable */
2964 if (WRITEABLE (XAB$V_OWN
) &&
2965 (xab
.xab$l_uic
& 0xFFFF) == memid
)
2966 return 0; /* Owner writeable */
2968 return -1; /* Not writeable */
2970 #endif /* not VMS4_4 */
2973 static char vtbuf
[NAM$C_MAXRSS
+1];
2975 /* translate a vms file spec to a unix path */
2977 sys_translate_vms (vfile
)
2988 /* leading device or logical name is a root directory */
2989 if (p
= strchr (vfile
, ':'))
2998 if (*p
== '[' || *p
== '<')
3000 while (*++vfile
!= *p
+ 2)
3004 if (vfile
[-1] == *p
)
3027 static char utbuf
[NAM$C_MAXRSS
+1];
3029 /* translate a unix path to a VMS file spec */
3031 sys_translate_unix (ufile
)
3054 if (index (&ufile
[1], '/'))
3061 if (index (&ufile
[1], '/'))
3068 if (strncmp (ufile
, "./", 2) == 0)
3075 ufile
++; /* skip the dot */
3076 if (index (&ufile
[1], '/'))
3081 else if (strncmp (ufile
, "../", 3) == 0)
3089 ufile
+= 2; /* skip the dots */
3090 if (index (&ufile
[1], '/'))
3115 extern char *getcwd ();
3117 #define MAXPATHLEN 1024
3119 ptr
= malloc (MAXPATHLEN
);
3120 getcwd (ptr
, MAXPATHLEN
);
3121 strcpy (pathname
, ptr
);
3129 long item_code
= JPI$_OWNER
;
3130 unsigned long parent_id
;
3133 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
3136 vaxc$errno
= status
;
3146 return (getgid () << 16) | getuid ();
3150 sys_read (fildes
, buf
, nbyte
)
3155 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
3160 sys_write (fildes
, buf
, nbyte
)
3165 register int nwrote
, rtnval
= 0;
3167 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
3173 return rtnval
? rtnval
: -1;
3174 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
3175 return rtnval
? rtnval
: -1;
3176 return (rtnval
+ nwrote
);
3181 * VAX/VMS VAX C RTL really loses. It insists that records
3182 * end with a newline (carriage return) character, and if they
3183 * don't it adds one (nice of it isn't it!)
3185 * Thus we do this stupidity below.
3189 sys_write (fildes
, buf
, nbytes
)
3192 unsigned int nbytes
;
3199 fstat (fildes
, &st
);
3205 /* Handle fixed-length files with carriage control. */
3206 if (st
.st_fab_rfm
== FAB$C_FIX
3207 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
3209 len
= st
.st_fab_mrs
;
3210 retval
= write (fildes
, p
, min (len
, nbytes
));
3213 retval
++; /* This skips the implied carriage control */
3217 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3218 while (*e
!= '\n' && e
> p
) e
--;
3219 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
3220 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3222 retval
= write (fildes
, p
, len
);
3233 /* Create file NEW copying its attributes from file OLD. If
3234 OLD is 0 or does not exist, create based on the value of
3237 /* Protection value the file should ultimately have.
3238 Set by create_copy_attrs, and use by rename_sansversions. */
3239 static unsigned short int fab_final_pro
;
3242 creat_copy_attrs (old
, new)
3245 struct FAB fab
= cc$rms_fab
;
3246 struct XABPRO xabpro
;
3247 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
3248 extern int vms_stmlf_recfm
;
3252 fab
.fab$b_fac
= FAB$M_GET
;
3253 fab
.fab$l_fna
= old
;
3254 fab
.fab$b_fns
= strlen (old
);
3255 fab
.fab$l_xab
= (char *) &xabpro
;
3256 xabpro
= cc$rms_xabpro
;
3257 xabpro
.xab$l_aclbuf
= aclbuf
;
3258 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
3259 /* Call $OPEN to fill in the fab & xabpro fields. */
3260 if (SYS$
OPEN (&fab
, 0, 0) & 1)
3262 SYS$
CLOSE (&fab
, 0, 0);
3263 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
3264 if (xabpro
.xab$w_acllen
> 0)
3266 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
3267 /* If the acl buffer was too short, redo open with longer one.
3268 Wouldn't need to do this if there were some system imposed
3269 limit on the size of an ACL, but I can't find any such. */
3271 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
3272 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
3273 if (SYS$
OPEN (&fab
, 0, 0) & 1)
3274 SYS$
CLOSE (&fab
, 0, 0);
3280 xabpro
.xab$l_aclbuf
= 0;
3285 fab
.fab$l_fna
= new;
3286 fab
.fab$b_fns
= strlen (new);
3290 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
3291 fab
.fab$b_rat
= FAB$M_CR
;
3294 /* Set the file protections such that we will be able to manipulate
3295 this file. Once we are done writing and renaming it, we will set
3296 the protections back. */
3298 fab_final_pro
= xabpro
.xab$w_pro
;
3300 SYS$
SETDFPROT (0, &fab_final_pro
);
3301 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
3303 /* Create the new file with either default attrs or attrs copied
3305 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
3307 SYS$
CLOSE (&fab
, 0, 0);
3308 /* As this is a "replacement" for creat, return a file descriptor
3309 opened for writing. */
3310 return open (new, O_WRONLY
);
3315 #include <varargs.h>
3318 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
3322 sys_creat (va_alist
)
3325 va_list list_incrementor
;
3328 int rfd
; /* related file descriptor */
3329 int fd
; /* Our new file descriptor */
3336 extern int vms_stmlf_recfm
;
3339 va_start (list_incrementor
);
3340 name
= va_arg (list_incrementor
, char *);
3341 mode
= va_arg (list_incrementor
, int);
3343 rfd
= va_arg (list_incrementor
, int);
3344 va_end (list_incrementor
);
3347 /* Use information from the related file descriptor to set record
3348 format of the newly created file. */
3349 fstat (rfd
, &st_buf
);
3350 switch (st_buf
.st_fab_rfm
)
3353 strcpy (rfm
, "rfm = fix");
3354 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
3355 strcpy (rat
, "rat = ");
3356 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3358 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3359 strcat (rat
, "ftn");
3360 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3361 strcat (rat
, "prn");
3362 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3363 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3364 strcat (rat
, ", blk");
3366 strcat (rat
, "blk");
3367 return creat (name
, 0, rfm
, rat
, mrs
);
3370 strcpy (rfm
, "rfm = vfc");
3371 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
3372 strcpy (rat
, "rat = ");
3373 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3375 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3376 strcat (rat
, "ftn");
3377 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3378 strcat (rat
, "prn");
3379 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3380 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3381 strcat (rat
, ", blk");
3383 strcat (rat
, "blk");
3384 return creat (name
, 0, rfm
, rat
, fsz
);
3387 strcpy (rfm
, "rfm = stm");
3391 strcpy (rfm
, "rfm = stmcr");
3395 strcpy (rfm
, "rfm = stmlf");
3399 strcpy (rfm
, "rfm = udf");
3403 strcpy (rfm
, "rfm = var");
3406 strcpy (rat
, "rat = ");
3407 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3409 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3410 strcat (rat
, "ftn");
3411 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3412 strcat (rat
, "prn");
3413 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3414 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3415 strcat (rat
, ", blk");
3417 strcat (rat
, "blk");
3421 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
3422 strcpy (rat
, "rat=cr");
3424 /* Until the VAX C RTL fixes the many bugs with modes, always use
3425 mode 0 to get the user's default protection. */
3426 fd
= creat (name
, 0, rfm
, rat
);
3427 if (fd
< 0 && errno
== EEXIST
)
3429 if (unlink (name
) < 0)
3430 report_file_error ("delete", build_string (name
));
3431 fd
= creat (name
, 0, rfm
, rat
);
3437 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
3438 sys_fwrite (ptr
, size
, num
, fp
)
3439 register char * ptr
;
3442 register int tot
= num
* size
;
3449 * The VMS C library routine creat actually creates a new version of an
3450 * existing file rather than truncating the old version. There are times
3451 * when this is not the desired behavior, for instance, when writing an
3452 * auto save file (you only want one version), or when you don't have
3453 * write permission in the directory containing the file (but the file
3454 * itself is writable). Hence this routine, which is equivalent to
3455 * "close (creat (fn, 0));" on Unix if fn already exists.
3461 struct FAB xfab
= cc$rms_fab
;
3462 struct RAB xrab
= cc$rms_rab
;
3465 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
3466 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
3467 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
3468 xfab
.fab$l_fna
= fn
;
3469 xfab
.fab$b_fns
= strlen (fn
);
3470 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
3472 xrab
.rab$l_fab
= &xfab
;
3474 /* This gibberish opens the file, positions to the first record, and
3475 deletes all records from there until the end of file. */
3476 if ((SYS$
OPEN (&xfab
) & 01) == 01)
3478 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
3479 (SYS$
FIND (&xrab
) & 01) == 01 &&
3480 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
3491 /* Define this symbol to actually read SYSUAF.DAT. This requires either
3492 SYSPRV or a readable SYSUAF.DAT. */
3498 * Routine to read the VMS User Authorization File and return
3499 * a specific user's record.
3502 static struct UAF retuaf
;
3505 get_uaf_name (uname
)
3512 uaf_fab
= cc$rms_fab
;
3513 uaf_rab
= cc$rms_rab
;
3514 /* initialize fab fields */
3515 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
3516 uaf_fab
.fab$b_fns
= 21;
3517 uaf_fab
.fab$b_fac
= FAB$M_GET
;
3518 uaf_fab
.fab$b_org
= FAB$C_IDX
;
3519 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
3520 /* initialize rab fields */
3521 uaf_rab
.rab$l_fab
= &uaf_fab
;
3522 /* open the User Authorization File */
3523 status
= SYS$
OPEN (&uaf_fab
);
3527 vaxc$errno
= status
;
3530 status
= SYS$
CONNECT (&uaf_rab
);
3534 vaxc$errno
= status
;
3537 /* read the requested record - index is in uname */
3538 uaf_rab
.rab$l_kbf
= uname
;
3539 uaf_rab
.rab$b_ksz
= strlen (uname
);
3540 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
3541 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
3542 uaf_rab
.rab$w_usz
= sizeof retuaf
;
3543 status
= SYS$
GET (&uaf_rab
);
3547 vaxc$errno
= status
;
3550 /* close the User Authorization File */
3551 status
= SYS$
DISCONNECT (&uaf_rab
);
3555 vaxc$errno
= status
;
3558 status
= SYS$
CLOSE (&uaf_fab
);
3562 vaxc$errno
= status
;
3576 uaf_fab
= cc$rms_fab
;
3577 uaf_rab
= cc$rms_rab
;
3578 /* initialize fab fields */
3579 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
3580 uaf_fab
.fab$b_fns
= 21;
3581 uaf_fab
.fab$b_fac
= FAB$M_GET
;
3582 uaf_fab
.fab$b_org
= FAB$C_IDX
;
3583 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
3584 /* initialize rab fields */
3585 uaf_rab
.rab$l_fab
= &uaf_fab
;
3586 /* open the User Authorization File */
3587 status
= SYS$
OPEN (&uaf_fab
);
3591 vaxc$errno
= status
;
3594 status
= SYS$
CONNECT (&uaf_rab
);
3598 vaxc$errno
= status
;
3601 /* read the requested record - index is in uic */
3602 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
3603 uaf_rab
.rab$l_kbf
= (char *) &uic
;
3604 uaf_rab
.rab$b_ksz
= sizeof uic
;
3605 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
3606 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
3607 uaf_rab
.rab$w_usz
= sizeof retuaf
;
3608 status
= SYS$
GET (&uaf_rab
);
3612 vaxc$errno
= status
;
3615 /* close the User Authorization File */
3616 status
= SYS$
DISCONNECT (&uaf_rab
);
3620 vaxc$errno
= status
;
3623 status
= SYS$
CLOSE (&uaf_fab
);
3627 vaxc$errno
= status
;
3633 static struct passwd retpw
;
3641 /* copy these out first because if the username is 32 chars, the next
3642 section will overwrite the first byte of the UIC */
3643 retpw
.pw_uid
= up
->uaf$w_mem
;
3644 retpw
.pw_gid
= up
->uaf$w_grp
;
3646 /* I suppose this is not the best sytle, to possibly overwrite one
3647 byte beyond the end of the field, but what the heck... */
3648 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
3649 while (ptr
[-1] == ' ')
3652 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
3654 /* the rest of these are counted ascii strings */
3655 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
3656 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
3657 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
3658 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
3659 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
3660 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
3661 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
3662 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
3666 #else /* not READ_SYSUAF */
3667 static struct passwd retpw
;
3668 #endif /* not READ_SYSUAF */
3679 unsigned char * full
;
3680 #endif /* READ_SYSUAF */
3685 if ('a' <= *ptr
&& *ptr
<= 'z')
3690 if (!(up
= get_uaf_name (name
)))
3692 return cnv_uaf_pw (up
);
3694 if (strcmp (name
, getenv ("USER")) == 0)
3696 retpw
.pw_uid
= getuid ();
3697 retpw
.pw_gid
= getgid ();
3698 strcpy (retpw
.pw_name
, name
);
3699 if (full
= egetenv ("FULLNAME"))
3700 strcpy (retpw
.pw_gecos
, full
);
3702 *retpw
.pw_gecos
= '\0';
3703 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
3704 *retpw
.pw_shell
= '\0';
3709 #endif /* not READ_SYSUAF */
3719 if (!(up
= get_uaf_uic (uid
)))
3721 return cnv_uaf_pw (up
);
3723 if (uid
== sys_getuid ())
3724 return getpwnam (egetenv ("USER"));
3727 #endif /* not READ_SYSUAF */
3730 /* return total address space available to the current process. This is
3731 the sum of the current p0 size, p1 size and free page table entries
3736 unsigned long free_pages
;
3737 unsigned long frep0va
;
3738 unsigned long frep1va
;
3741 item_code
= JPI$_FREPTECNT
;
3742 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
3745 vaxc$errno
= status
;
3750 item_code
= JPI$_FREP0VA
;
3751 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
3754 vaxc$errno
= status
;
3757 item_code
= JPI$_FREP1VA
;
3758 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
3761 vaxc$errno
= status
;
3765 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
3768 define_logical_name (varname
, string
)
3772 struct dsc$descriptor_s strdsc
=
3773 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
3774 struct dsc$descriptor_s envdsc
=
3775 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
3776 struct dsc$descriptor_s lnmdsc
=
3777 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
3779 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
3782 delete_logical_name (varname
)
3785 struct dsc$descriptor_s envdsc
=
3786 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
3787 struct dsc$descriptor_s lnmdsc
=
3788 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
3790 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
3801 error ("execvp system call not implemented");
3809 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
3810 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
3811 char from_esn
[NAM$C_MAXRSS
];
3812 char to_esn
[NAM$C_MAXRSS
];
3814 from_fab
.fab$l_fna
= from
;
3815 from_fab
.fab$b_fns
= strlen (from
);
3816 from_fab
.fab$l_nam
= &from_nam
;
3817 from_fab
.fab$l_fop
= FAB$M_NAM
;
3819 from_nam
.nam$l_esa
= from_esn
;
3820 from_nam
.nam$b_ess
= sizeof from_esn
;
3822 to_fab
.fab$l_fna
= to
;
3823 to_fab
.fab$b_fns
= strlen (to
);
3824 to_fab
.fab$l_nam
= &to_nam
;
3825 to_fab
.fab$l_fop
= FAB$M_NAM
;
3827 to_nam
.nam$l_esa
= to_esn
;
3828 to_nam
.nam$b_ess
= sizeof to_esn
;
3830 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
3836 if (status
== RMS$_DEV
)
3840 vaxc$errno
= status
;
3845 /* This function renames a file like `rename', but it strips
3846 the version number from the "to" filename, such that the "to" file is
3847 will always be a new version. It also sets the file protection once it is
3848 finished. The protection that we will use is stored in fab_final_pro,
3849 and was set when we did a creat_copy_attrs to create the file that we
3852 We could use the chmod function, but Eunichs uses 3 bits per user category
3853 to describe the protection, and VMS uses 4 (write and delete are seperate
3854 bits). To maintain portability, the VMS implementation of `chmod' wires
3855 the W and D bits together. */
3858 static struct fibdef fib
; /* We need this initialized to zero */
3859 char vms_file_written
[NAM$C_MAXRSS
];
3862 rename_sans_version (from
,to
)
3869 struct FAB to_fab
= cc$rms_fab
;
3870 struct NAM to_nam
= cc$rms_nam
;
3871 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
3872 struct dsc$descriptor fib_attr
[2]
3873 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
3874 char to_esn
[NAM$C_MAXRSS
];
3876 $
DESCRIPTOR (disk
,to_esn
);
3878 to_fab
.fab$l_fna
= to
;
3879 to_fab
.fab$b_fns
= strlen (to
);
3880 to_fab
.fab$l_nam
= &to_nam
;
3881 to_fab
.fab$l_fop
= FAB$M_NAM
;
3883 to_nam
.nam$l_esa
= to_esn
;
3884 to_nam
.nam$b_ess
= sizeof to_esn
;
3886 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
3888 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
3889 *(to_nam
.nam$l_ver
) = '\0';
3891 stat
= rename (from
, to_esn
);
3895 strcpy (vms_file_written
, to_esn
);
3897 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
3898 to_fab
.fab$b_fns
= strlen (vms_file_written
);
3900 /* Now set the file protection to the correct value */
3901 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
3903 /* Copy these fields into the fib */
3904 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
3905 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
3906 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
3908 SYS$
CLOSE (&to_fab
, 0, 0);
3910 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
3913 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
3914 0, 0, 0, &fib_attr
, 0);
3917 stat
= SYS$
DASSGN (chan
);
3920 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
3930 unsigned short fid
[3];
3931 char esa
[NAM$C_MAXRSS
];
3934 fab
.fab$l_fop
= FAB$M_OFP
;
3935 fab
.fab$l_fna
= file
;
3936 fab
.fab$b_fns
= strlen (file
);
3937 fab
.fab$l_nam
= &nam
;
3940 nam
.nam$l_esa
= esa
;
3941 nam
.nam$b_ess
= NAM$C_MAXRSS
;
3943 status
= SYS$
PARSE (&fab
);
3944 if ((status
& 1) == 0)
3947 vaxc$errno
= status
;
3950 status
= SYS$
SEARCH (&fab
);
3951 if ((status
& 1) == 0)
3954 vaxc$errno
= status
;
3958 fid
[0] = nam
.nam$w_fid
[0];
3959 fid
[1] = nam
.nam$w_fid
[1];
3960 fid
[2] = nam
.nam$w_fid
[2];
3962 fab
.fab$l_fna
= new;
3963 fab
.fab$b_fns
= strlen (new);
3965 status
= SYS$
PARSE (&fab
);
3966 if ((status
& 1) == 0)
3969 vaxc$errno
= status
;
3973 nam
.nam$w_fid
[0] = fid
[0];
3974 nam
.nam$w_fid
[1] = fid
[1];
3975 nam
.nam$w_fid
[2] = fid
[2];
3977 nam
.nam$l_esa
= nam
.nam$l_name
;
3978 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
3980 status
= SYS$
ENTER (&fab
);
3981 if ((status
& 1) == 0)
3984 vaxc$errno
= status
;
3994 printf ("%s not yet implemented\r\n", badfunc
);
4002 /* Arrange to return a range centered on zero. */
4003 return rand () - (1 << 30);
4014 /* Called from init_sys_modes. */
4019 /* If we're not on an HFT we shouldn't do any of this. We determine
4020 if we are on an HFT by trying to get an HFT error code. If this
4021 call fails, we're not on an HFT. */
4023 if (ioctl (0, HFQERROR
, &junk
) < 0)
4025 #else /* not IBMR2AIX */
4026 if (ioctl (0, HFQEIO
, 0) < 0)
4028 #endif /* not IBMR2AIX */
4030 /* On AIX the default hft keyboard mapping uses backspace rather than delete
4031 as the rubout key's ASCII code. Here this is changed. The bug is that
4032 there's no way to determine the old mapping, so in reset_sys_modes
4033 we need to assume that the normal map had been present. Of course, this
4034 code also doesn't help if on a terminal emulator which doesn't understand
4038 struct hfkeymap keymap
;
4040 buf
.hf_bufp
= (char *)&keymap
;
4041 buf
.hf_buflen
= sizeof (keymap
);
4042 keymap
.hf_nkeys
= 2;
4043 keymap
.hfkey
[0].hf_kpos
= 15;
4044 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4046 keymap
.hfkey
[0].hf_keyidh
= '<';
4047 #else /* not IBMR2AIX */
4048 keymap
.hfkey
[0].hf_page
= '<';
4049 #endif /* not IBMR2AIX */
4050 keymap
.hfkey
[0].hf_char
= 127;
4051 keymap
.hfkey
[1].hf_kpos
= 15;
4052 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4054 keymap
.hfkey
[1].hf_keyidh
= '<';
4055 #else /* not IBMR2AIX */
4056 keymap
.hfkey
[1].hf_page
= '<';
4057 #endif /* not IBMR2AIX */
4058 keymap
.hfkey
[1].hf_char
= 127;
4059 hftctl (0, HFSKBD
, &buf
);
4061 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
4063 line_ins_del_ok
= char_ins_del_ok
= 0;
4066 /* Reset the rubout key to backspace. */
4071 struct hfkeymap keymap
;
4075 if (ioctl (0, HFQERROR
, &junk
) < 0)
4077 #else /* not IBMR2AIX */
4078 if (ioctl (0, HFQEIO
, 0) < 0)
4080 #endif /* not IBMR2AIX */
4082 buf
.hf_bufp
= (char *)&keymap
;
4083 buf
.hf_buflen
= sizeof (keymap
);
4084 keymap
.hf_nkeys
= 2;
4085 keymap
.hfkey
[0].hf_kpos
= 15;
4086 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4088 keymap
.hfkey
[0].hf_keyidh
= '<';
4089 #else /* not IBMR2AIX */
4090 keymap
.hfkey
[0].hf_page
= '<';
4091 #endif /* not IBMR2AIX */
4092 keymap
.hfkey
[0].hf_char
= 8;
4093 keymap
.hfkey
[1].hf_kpos
= 15;
4094 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4096 keymap
.hfkey
[1].hf_keyidh
= '<';
4097 #else /* not IBMR2AIX */
4098 keymap
.hfkey
[1].hf_page
= '<';
4099 #endif /* not IBMR2AIX */
4100 keymap
.hfkey
[1].hf_char
= 8;
4101 hftctl (0, HFSKBD
, &buf
);