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 */
55 #include <sys/types.h>
61 extern char *sys_errlist
[];
84 #define MAXIOSIZE ( 32 * PAGESIZE ) /* Don't I/O more than 32 blocks at a time */
88 #ifdef BSD /* this is done this way to avoid defined (BSD) || defined (USG)
89 because the vms compiler doesn't grok `defined' */
97 #endif /* not 4.1 bsd */
99 /* Get DGUX definition for FASYNC - DJB */
101 #include <sys/file.h>
104 #include <sys/ioctl.h>
111 #include <sys/wait.h>
115 #ifdef BROKEN_TIOCGWINSZ
120 #include <sys/utsname.h>
122 #ifndef MEMORY_IN_STRING_H
127 #include <sys/sioctl.h>
130 #include <sys/stream.h>
131 #include <sys/ptem.h>
133 #endif /* TIOCGWINSZ */
136 extern int quit_char
;
140 #include "termhooks.h"
141 #include "termchar.h"
142 #include "termopts.h"
143 #include "dispextern.h"
146 #ifdef NONSYSTEM_DIR_LIBRARY
148 #endif /* NONSYSTEM_DIR_LIBRARY */
150 #include "syssignal.h"
153 static int baud_convert
[] =
158 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
159 1800, 2400, 4800, 9600, 19200, 38400
165 /* The file descriptor for Emacs's input terminal.
166 Under Unix, this is always left zero;
167 under VMS, we place the input channel number here.
168 This allows us to write more code that works for both VMS and Unix. */
180 int kbd_input_ast ();
190 static $
DESCRIPTOR (input_dsc
, "TT");
191 static int terminator_mask
[2] = { 0, 0 };
193 static struct sensemode
{
195 unsigned char xmit_baud
;
196 unsigned char rcv_baud
;
197 unsigned char crfill
;
198 unsigned char lffill
;
199 unsigned char parity
;
200 unsigned char unused
;
204 unsigned long tt_char
: 24, scr_len
: 8;
205 unsigned long tt2_char
;
211 struct emacs_tty buf
;
216 /* Discarding input is not safe when the input could contain
217 replies from the X server. So don't do it. */
218 if (read_socket_hook
)
223 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
224 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
230 ioctl (0, TIOCFLUSH
, &zero
);
232 #else /* not Apollo */
233 EMACS_GET_TTY (input_fd
, &buf
);
234 EMACS_SET_TTY (input_fd
, &buf
, 0);
235 #endif /* not Apollo */
244 /* Should perhaps error if in batch mode */
246 ioctl (0, TIOCSTI
, &c
);
247 #else /* no TIOCSTI */
248 error ("Cannot stuff terminal input characters in this version of Unix.");
249 #endif /* no TIOCSTI */
263 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
264 &sg
.class, 12, 0, 0, 0, 0 );
265 ospeed
= sg
.xmit_baud
;
270 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | B9600
;
272 ospeed
= sg
.c_cflag
& CBAUD
;
273 #else /* neither VMS nor TERMIOS */
277 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | B9600
;
281 ioctl (fd
, TIOCGETP
, &sg
);
283 ospeed
= sg
.c_cflag
& CBAUD
;
284 #else /* neither VMS nor TERMIOS nor TERMIO */
287 sg
.sg_ospeed
= B9600
;
288 ioctl (0, TIOCGETP
, &sg
);
289 ospeed
= sg
.sg_ospeed
;
290 #endif /* not HAVE_TERMIO */
291 #endif /* not HAVE_TERMIOS */
295 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
296 ? baud_convert
[ospeed
] : 9600);
302 set_exclusive_use (fd
)
306 ioctl (fd
, FIOCLEX
, 0);
308 /* Ok to do nothing if this feature does not exist */
313 wait_without_blocking ()
316 wait3 (0, WNOHANG
| WUNTRACED
, 0);
318 croak ("wait_without_blocking");
320 synch_process_alive
= 0;
323 #endif /* not subprocesses */
325 int wait_debugging
; /* Set nonzero to make following function work under dbx
326 (at least for bsd). */
329 wait_for_termination_signal ()
332 /* Wait for subprocess with process id `pid' to terminate and
333 make sure it will get eliminated (not remain forever as a zombie) */
335 wait_for_termination (pid
)
344 status
= sys$
forcex (&pid
, 0, 0);
348 /* Exit if the process has terminated. */
349 if (!synch_process_alive
)
351 /* Otherwise wait 1 second or until a signal comes in. */
352 signal (SIGALRM
, wait_for_termination_signal
);
356 signal (SIGALRM
, SIG_IGN
);
358 #else /* not subprocesses */
360 if (kill (pid
, 0) < 0)
366 if (status
== pid
|| status
== -1)
369 #endif /* not subprocesses */
376 * flush any pending output
377 * (may flush input as well; it does not matter the way we use it)
380 flush_pending_output (channel
)
384 /* If we try this, we get hit with SIGTTIN, because
385 the child's tty belongs to the child's pgrp. */
388 ioctl (channel
, TCFLSH
, 1);
392 /* 3rd arg should be ignored
393 but some 4.2 kernels actually want the address of an int
394 and nonzero means something different. */
395 ioctl (channel
, TIOCFLUSH
, &zero
);
402 /* Set up the terminal at the other end of a pseudo-terminal that
403 we will be controlling an inferior through.
404 It should not echo or do line-editing, since that is done
405 in Emacs. No padding needed for insertion into an Emacs buffer. */
407 child_setup_tty (out
)
412 EMACS_GET_TTY (out
, &s
);
415 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
416 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
417 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
418 /* No output delays */
419 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
420 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
421 s
.main
.c_iflag
&= ~IUCLC
; /* Disable map of upper case to lower on
423 s
.main
.c_oflag
&= ~OLCUC
; /* Disable map of lower case to upper on
426 /* Said to be unnecesary: */
427 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
428 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
431 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
432 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
433 s
.main
.c_cc
[VERASE
] = 0377; /* disable erase processing */
434 s
.main
.c_cc
[VKILL
] = 0377; /* disable kill processing */
437 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
441 /* AIX enhanced edit loses NULs, so disable it */
444 s
.main
.c_iflag
&= ~ASCEDIT
;
446 /* Also, PTY overloads NUL and BREAK.
447 don't ignore break, but don't signal either, so it looks like NUL. */
448 s
.main
.c_iflag
&= ~IGNBRK
;
449 s
.main
.c_iflag
&= ~BRKINT
;
450 /* QUIT and INTR work better as signals, so disable character forms */
451 s
.main
.c_cc
[VQUIT
] = 0377;
452 s
.main
.c_cc
[VINTR
] = 0377;
453 s
.main
.c_cc
[VEOL
] = 0377;
454 s
.main
.c_lflag
&= ~ISIG
;
455 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
458 #else /* not HAVE_TERMIO */
460 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
462 s
.main
.sg_erase
= 0377;
463 s
.main
.sg_kill
= 0377;
465 #endif /* not HAVE_TERMIO */
467 EMACS_SET_TTY (out
, &s
, 0);
476 ioctl (out
, FIOASYNC
, &zero
);
482 #endif /* subprocesses */
488 EMACS_SET_TTY_PGRP (input_fd
, &pid
);
491 /* Record a signal code and the handler for it. */
495 SIGTYPE (*handler
) ();
498 /* Suspend the Emacs process; give terminal to its superior. */
503 unsigned long parent_id
;
505 parent_id
= getppid ();
506 if (parent_id
&& parent_id
!= 0xffffffff)
508 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
509 int status
= LIB$
ATTACH (&parent_id
) & 1;
510 signal (SIGINT
, oldsig
);
519 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
520 d_prompt
.a
= "Emacs: "; /* Just a reminder */
521 lib$
spawn (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
528 EMACS_KILLPG (getpgrp (0), SIGTSTP
);
530 #else /* No SIGTSTP */
531 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
532 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
533 kill (getpid (), SIGQUIT
);
535 #else /* No SIGTSTP or USG_JOBCTRL */
537 /* On a system where suspending is not implemented,
538 instead fork a subshell and let it talk directly to the terminal
541 struct save_signal saved_handlers
[5];
543 saved_handlers
[0].code
= SIGINT
;
544 saved_handlers
[1].code
= SIGQUIT
;
545 saved_handlers
[2].code
= SIGTERM
;
547 saved_handlers
[3].code
= SIGIO
;
548 saved_handlers
[4].code
= 0;
550 saved_handlers
[3].code
= 0;
554 error ("Can't spawn subshell");
559 sh
= (char *) egetenv ("SHELL");
562 /* Use our buffer's default directory for the subshell. */
568 /* mentioning current_buffer->buffer would mean including buffer.h,
569 which somehow wedges the hp compiler. So instead... */
571 dir
= intern ("default-directory");
573 if (XFASTINT (Fboundp (dir
)) == XFASTINT (Qnil
))
575 dir
= Fsymbol_value (dir
);
576 if (XTYPE (dir
) != Lisp_String
)
579 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
580 len
= XSTRING (dir
)->size
;
581 bcopy (XSTRING (dir
)->data
, str
, len
);
582 if (str
[len
- 1] != '/') str
[len
++] = '/';
588 close_process_descs (); /* Close Emacs's pipes/ptys */
590 nice (-nice (0)); /* Give the new shell the default piority */
592 write (1, "Can't execute subshell", 22);
596 save_signal_handlers (saved_handlers
);
597 wait_for_termination (pid
);
598 restore_signal_handlers (saved_handlers
);
600 #endif /* no USG_JOBCTRL */
601 #endif /* no SIGTSTP */
605 save_signal_handlers (saved_handlers
)
606 struct save_signal
*saved_handlers
;
608 while (saved_handlers
->code
)
610 saved_handlers
->handler
611 = (SIGTYPE (*) ()) signal (saved_handlers
->code
, SIG_IGN
);
616 restore_signal_handlers (saved_handlers
)
617 struct save_signal
*saved_handlers
;
619 while (saved_handlers
->code
)
621 signal (saved_handlers
->code
, saved_handlers
->handler
);
633 old_fcntl_flags
= fcntl (0, F_GETFL
, 0) & ~FASYNC
;
643 #ifdef FASYNC /* F_SETFL does not imply existance of FASYNC */
648 sigunblock (sigmask (SIGWINCH
));
650 fcntl (0, F_SETFL
, old_fcntl_flags
| FASYNC
);
652 interrupts_deferred
= 0;
658 sigblock (sigmask (SIGWINCH
));
660 fcntl (0, F_SETFL
, old_fcntl_flags
);
661 interrupts_deferred
= 1;
664 #else /* no FASYNC */
665 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
670 ioctl (0, FIOASYNC
, &on
);
671 interrupts_deferred
= 0;
678 ioctl (0, FIOASYNC
, &off
);
679 interrupts_deferred
= 1;
682 #else /* not FASYNC, not STRIDE */
686 croak ("request_sigio");
691 croak ("unrequest_sigio");
698 /* The initial tty mode bits */
699 struct emacs_tty old_tty
;
701 int term_initted
; /* 1 if outer tty status has been recorded */
704 /* BSD 4.1 needs to keep track of the lmode bits in order to start
711 #endif /* F_SETOWN */
713 /* This may also be defined in stdio,
714 but if so, this does no harm,
715 and using the same name avoids wasting the other one's space. */
717 #if defined (USG) || defined (DGUX)
718 unsigned char _sobuf
[BUFSIZ
+8];
724 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
727 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
732 struct emacs_tty tty
;
736 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
737 extern int (*interrupt_signal
) ();
746 input_ef
= get_kbd_event_flag ();
747 /* LIB$GET_EF (&input_ef); */
748 SYS$
CLREF (input_ef
);
751 timer_ef
= get_timer_event_flag ();
752 /* LIB$GET_EF (&timer_ef); */
753 SYS$
CLREF (timer_ef
);
756 LIB$
GET_EF (&process_ef
);
757 SYS$
CLREF (process_ef
);
759 if (input_ef
/ 32 != process_ef
/ 32)
760 croak ("Input and process event flags in different clusters.");
761 if (input_ef
/ 32 != timer_ef
/ 32)
762 croak ("Input and process event flags in different clusters.");
763 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
764 ((unsigned) 1 << (process_ef
% 32));
765 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
766 ((unsigned) 1 << (timer_ef
% 32));
768 sys_access_reinit ();
772 EMACS_GET_TTY (input_fd
, &old_tty
);
774 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
779 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
780 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
782 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
784 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
785 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
786 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
789 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
791 tty
.main
.c_iflag
&= ~IXANY
;
795 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
796 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
798 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
802 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
803 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
806 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
807 /* Set up C-g for both SIGQUIT and SIGINT.
808 We don't know which we will get, but we handle both alike
809 so which one it really gives us does not matter. */
810 tty
.main
.c_cc
[VQUIT
] = quit_char
;
811 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
812 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
814 tty
.main
.c_cc
[VSWTCH
] = CDEL
; /* Turn off shell layering use
817 #if defined (mips) || defined (HAVE_TCATTR)
818 /* The following code looks like the right thing in general,
819 but it is said to cause a crash on USG V.4.
820 Let's play safe by turning it on only for the MIPS. */
822 tty
.main
.c_cc
[VSUSP
] = CDEL
; /* Turn off mips handling of C-z. */
825 tty
.main
.c_cc
[V_DSUSP
] = CDEL
; /* Turn off mips handling of C-y. */
827 #endif /* mips or HAVE_TCATTR */
830 /* AIX enhanced edit loses NULs, so disable it */
832 tty
.main
.c_iflag
&= ~ASCEDIT
;
834 tty
.main
.c_cc
[VSTRT
] = 255;
835 tty
.main
.c_cc
[VSTOP
] = 255;
836 tty
.main
.c_cc
[VSUSP
] = 255;
837 tty
.main
.c_cc
[VDSUSP
] = 255;
838 #endif /* IBMR2AIX */
839 /* Also, PTY overloads NUL and BREAK.
840 don't ignore break, but don't signal either, so it looks like NUL.
841 This really serves a purpose only if running in an XTERM window
842 or via TELNET or the like, but does no harm elsewhere. */
843 tty
.main
.c_iflag
&= ~IGNBRK
;
844 tty
.main
.c_iflag
&= ~BRKINT
;
846 #else /* if not HAVE_TERMIO */
848 tty
.main
.tt_char
|= TT$M_NOECHO
;
850 tty
.main
.tt_char
|= TT$M_EIGHTBIT
852 tty
.main
.tt_char
|= TT$M_TTSYNC
;
854 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
855 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
856 #else /* not VMS (BSD, that is) */
857 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
859 tty
.main
.sg_flags
|= ANYP
;
860 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
861 #endif /* not VMS (BSD, that is) */
862 #endif /* not HAVE_TERMIO */
864 /* If going to use CBREAK mode, we must request C-g to interrupt
865 and turn off start and stop chars, etc. If not going to use
866 CBREAK mode, do this anyway so as to turn off local flow
867 control for user coming over network on 4.2; in this case,
868 only t_stopc and t_startc really matter. */
871 /* Note: if not using CBREAK mode, it makes no difference how we
873 tty
.tchars
= new_tchars
;
874 tty
.tchars
.t_intrc
= quit_char
;
877 tty
.tchars
.t_startc
= '\021';
878 tty
.tchars
.t_stopc
= '\023';
881 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
887 #define LNOFLSH 0100000
890 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
896 #endif /* TIOCGETC */
897 #endif /* not HAVE_TERMIO */
900 tty
.ltchars
= new_ltchars
;
901 #endif /* TIOCGLTC */
903 EMACS_SET_TTY (input_fd
, &tty
, 0);
905 /* This code added to insure that, if flow-control is not to be used,
906 we have an unlocked terminal at the start. */
909 if (!flow_control
) ioctl (0, TCXONC
, 1);
913 if (!flow_control
) ioctl (0, TIOCSTART
, 0);
921 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
922 to be only LF. This is the way that is done. */
925 if (ioctl (1, HFTGETID
, &tty
) != -1)
926 write (1, "\033[20l", 5);
932 /* Appears to do nothing when in PASTHRU mode.
933 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
934 interrupt_signal, oob_chars, 0, 0, 0, 0);
941 #ifdef F_GETOWN /* F_SETFL does not imply existance of F_GETOWN */
944 old_fcntl_owner
= fcntl (0, F_GETOWN
, 0);
945 fcntl (0, F_SETOWN
, getpid ());
948 #endif /* F_GETOWN */
956 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
960 /* This symbol is defined on recent USG systems.
961 Someone says without this call USG won't really buffer the file
962 even with a call to setbuf. */
963 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
965 setbuf (stdout
, _sobuf
);
967 set_terminal_modes ();
968 if (term_initted
&& no_redraw_on_reenter
)
970 if (display_completed
)
971 direct_output_forward_char (0);
977 if (FRAMEP (Vterminal_frame
))
978 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
985 /* Return nonzero if safe to use tabs in output.
986 At the time this is called, init_sys_modes has not been done yet. */
990 struct emacs_tty tty
;
992 EMACS_GET_TTY (input_fd
, &tty
);
993 return EMACS_TTY_TABS_OK (&tty
);
996 /* Get terminal size from system.
997 Store number of lines into *heightp and width into *widthp.
998 If zero or a negative number is stored, the value is not valid. */
1000 get_frame_size (widthp
, heightp
)
1001 int *widthp
, *heightp
;
1007 struct winsize size
;
1009 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1010 *widthp
= *heightp
= 0;
1013 *widthp
= size
.ws_col
;
1014 *heightp
= size
.ws_row
;
1020 /* SunOS - style. */
1021 struct ttysize size
;
1023 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1024 *widthp
= *heightp
= 0;
1027 *widthp
= size
.ts_cols
;
1028 *heightp
= size
.ts_lines
;
1034 struct sensemode tty
;
1036 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1037 &tty
.class, 12, 0, 0, 0, 0);
1038 *widthp
= tty
.scr_wid
;
1039 *heightp
= tty
.scr_len
;
1041 #else /* system doesn't know size */
1046 #endif /* not VMS */
1047 #endif /* not SunOS-style */
1048 #endif /* not BSD-style */
1052 /* Prepare the terminal for exiting Emacs; move the cursor to the
1053 bottom of the frame, turn off interrupt-driven I/O, etc. */
1063 if (read_socket_hook
|| !EQ (Vwindow_system
, Qnil
))
1065 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1066 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1067 /* clear_end_of_line may move the cursor */
1068 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1071 /* HFT devices normally use ^J as a LF/CR. We forced it to
1072 do the LF only. Now, we need to reset it. */
1075 if (ioctl (1, HFTGETID
, &tty
) != -1)
1076 write (1, "\033[20h", 5);
1080 reset_terminal_modes ();
1084 /* Avoid possible loss of output when changing terminal modes. */
1085 fsync (fileno (stdout
));
1090 #ifdef F_SETOWN /* F_SETFL does not imply existance of F_SETOWN */
1091 if (interrupt_input
)
1094 fcntl (0, F_SETOWN
, old_fcntl_owner
);
1096 #endif /* F_SETOWN */
1097 #endif /* F_SETFL */
1099 if (interrupt_input
)
1103 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1113 /* Set up the proper status flags for use of a pty. */
1118 /* I'm told that TOICREMOTE does not mean control chars
1119 "can't be sent" but rather that they don't have
1120 input-editing or signaling effects.
1121 That should be good, because we have other ways
1122 to do those things in Emacs.
1123 However, telnet mode seems not to work on 4.2.
1124 So TIOCREMOTE is turned off now. */
1126 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1127 will hang. In particular, the "timeout" feature (which
1128 causes a read to return if there is no data available)
1129 does this. Also it is known that telnet mode will hang
1130 in such a way that Emacs must be stopped (perhaps this
1131 is the same problem).
1133 If TIOCREMOTE is turned off, then there is a bug in
1134 hp-ux which sometimes loses data. Apparently the
1135 code which blocks the master process when the internal
1136 buffer fills up does not work. Other than this,
1137 though, everything else seems to work fine.
1139 Since the latter lossage is more benign, we may as well
1140 lose that way. -- cph */
1145 ioctl (fd
, FIONBIO
, &on
);
1150 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1151 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1152 /* cause EMACS not to die when it should, i.e., when its own controlling */
1153 /* tty goes away. I've complained to the AIX developers, and they may */
1154 /* change this behavior, but I'm not going to hold my breath. */
1155 signal (SIGHUP
, SIG_IGN
);
1158 #endif /* HAVE_PTYS */
1162 /* Assigning an input channel is done at the start of Emacs execution.
1163 This is called each time Emacs is resumed, also, but does nothing
1164 because input_chain is no longer zero. */
1172 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1178 /* Deassigning the input channel is done before exiting. */
1182 return SYS$
DASSGN (input_fd
);
1187 /* Request reading one character into the keyboard buffer.
1188 This is done as soon as the buffer becomes empty. */
1193 waiting_for_ast
= 0;
1195 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1196 &input_iosb
, kbd_input_ast
, 1,
1197 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1202 /* Ast routine that is called when keyboard input comes in
1203 in accord with the SYS$QIO above. */
1207 register int c
= -1;
1208 int old_errno
= errno
;
1209 extern EMACS_TIME
*input_available_clear_time
;
1211 if (waiting_for_ast
)
1212 SYS$
SETEF (input_ef
);
1213 waiting_for_ast
= 0;
1216 if (input_count
== 25)
1218 printf ("Ast # %d,", input_count
);
1219 printf (" iosb = %x, %x, %x, %x",
1220 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1223 if (input_iosb
.offset
)
1227 printf (", char = 0%o", c
);
1239 struct input_event e
;
1240 e
.kind
= ascii_keystroke
;
1241 XSET (buf
[i
].code
, Lisp_Int
, cbuf
[i
]);
1242 e
.frame
= selected_frame
;
1243 kbd_buffer_store_event (&e
);
1246 if (input_available_clear_time
)
1247 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1251 /* Wait until there is something in kbd_buffer. */
1253 wait_for_kbd_input ()
1255 extern int have_process_input
, process_exited
;
1257 /* If already something, avoid doing system calls. */
1258 if (detect_input_pending ())
1262 /* Clear a flag, and tell ast routine above to set it. */
1263 SYS$
CLREF (input_ef
);
1264 waiting_for_ast
= 1;
1265 /* Check for timing error: ast happened while we were doing that. */
1266 if (!detect_input_pending ())
1268 /* No timing error: wait for flag to be set. */
1269 set_waiting_for_input (0);
1270 SYS$
WFLOR (input_ef
, input_eflist
);
1271 clear_waiting_for_input (0);
1272 if (!detect_input_pending ())
1273 /* Check for subprocess input availability */
1275 int dsp
= have_process_input
|| process_exited
;
1277 SYS$
CLREF (process_ef
);
1278 if (have_process_input
)
1279 process_command_input ();
1284 update_mode_lines
++;
1285 redisplay_preserve_echo_area ();
1289 waiting_for_ast
= 0;
1292 /* Get rid of any pending QIO, when we are about to suspend
1293 or when we want to throw away pending input.
1294 We wait for a positive sign that the AST routine has run
1295 and therefore there is no I/O request queued when we return.
1296 SYS$SETAST is used to avoid a timing error. */
1301 printf ("At end_kbd_input.\n");
1305 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
1307 SYS$
CANCEL (input_fd
);
1312 /* Clear a flag, and tell ast routine above to set it. */
1313 SYS$
CLREF (input_ef
);
1314 waiting_for_ast
= 1;
1316 SYS$
CANCEL (input_fd
);
1318 SYS$
WAITFR (input_ef
);
1319 waiting_for_ast
= 0;
1322 /* Wait for either input available or time interval expiry. */
1324 input_wait_timeout (timeval
)
1325 int timeval
; /* Time to wait, in seconds */
1328 static int zero
= 0;
1329 static int large
= -10000000;
1331 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1333 /* If already something, avoid doing system calls. */
1334 if (detect_input_pending ())
1338 /* Clear a flag, and tell ast routine above to set it. */
1339 SYS$
CLREF (input_ef
);
1340 waiting_for_ast
= 1;
1341 /* Check for timing error: ast happened while we were doing that. */
1342 if (!detect_input_pending ())
1344 /* No timing error: wait for flag to be set. */
1346 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1347 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
1349 waiting_for_ast
= 0;
1352 /* The standard `sleep' routine works some other way
1353 and it stops working if you have ever quit out of it.
1354 This one continues to work. */
1360 static int zero
= 0;
1361 static int large
= -10000000;
1363 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1366 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1367 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
1382 croak ("request sigio");
1387 croak ("unrequest sigio");
1392 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
1397 #ifndef SYSTEM_MALLOC
1404 /* Some systems that cannot dump also cannot implement these. */
1407 * Return the address of the start of the text segment prior to
1408 * doing an unexec. After unexec the return value is undefined.
1409 * See crt0.c for further explanation and _start.
1413 #ifndef CANNOT_UNEXEC
1418 return ((char *) TEXT_START
);
1422 return ((char *) csrt
);
1423 #else /* not GOULD */
1424 extern int _start ();
1425 return ((char *) _start
);
1427 #endif /* TEXT_START */
1429 #endif /* not CANNOT_UNEXEC */
1432 * Return the address of the start of the data segment prior to
1433 * doing an unexec. After unexec the return value is undefined.
1434 * See crt0.c for further information and definition of data_start.
1436 * Apparently, on BSD systems this is etext at startup. On
1437 * USG systems (swapping) this is highly mmu dependent and
1438 * is also dependent on whether or not the program is running
1439 * with shared text. Generally there is a (possibly large)
1440 * gap between end of text and start of data with shared text.
1442 * On Uniplus+ systems with shared text, data starts at a
1443 * fixed address. Each port (from a given oem) is generally
1444 * different, and the specific value of the start of data can
1445 * be obtained via the UniPlus+ specific "uvar" system call,
1446 * however the method outlined in crt0.c seems to be more portable.
1448 * Probably what will have to happen when a USG unexec is available,
1449 * at least on UniPlus, is temacs will have to be made unshared so
1450 * that text and data are contiguous. Then once loadup is complete,
1451 * unexec will produce a shared executable where the data can be
1452 * at the normal shared text boundry and the startofdata variable
1453 * will be patched by unexec to the correct value.
1461 return ((char *) DATA_START
);
1463 extern int data_start
;
1464 return ((char *) &data_start
);
1467 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
1470 /* Some systems that cannot dump also cannot implement these. */
1473 * Return the address of the end of the text segment prior to
1474 * doing an unexec. After unexec the return value is undefined.
1481 return ((char *) TEXT_END
);
1484 return ((char *) &etext
);
1489 * Return the address of the end of the data segment prior to
1490 * doing an unexec. After unexec the return value is undefined.
1497 return ((char *) DATA_END
);
1500 return ((char *) &edata
);
1504 #endif /* not CANNOT_DUMP */
1506 /* Get_system_name returns as its value
1507 a string for the Lisp function system-name to return. */
1514 /* Can't have this within the function since `static' is #defined to nothing */
1515 static struct utsname get_system_name_name
;
1522 uname (&get_system_name_name
);
1523 return (get_system_name_name
.nodename
);
1527 #else /* not USG, not 4.1 */
1528 static char system_name_saved
[32];
1531 if ((sp
= egetenv ("SYS$NODE")) == 0)
1537 if ((end
= index (sp
, ':')) != 0)
1540 strcpy (system_name_saved
, sp
);
1542 gethostname (system_name_saved
, sizeof (system_name_saved
));
1543 #endif /* not VMS */
1544 return system_name_saved
;
1545 #endif /* not USG, not 4.1 */
1546 #endif /* not USG */
1552 #ifdef HAVE_X_WINDOWS
1553 /* Cause explanatory error message at compile time,
1554 since the select emulation is not good enough for X. */
1555 int *x
= &x_windows_lose_if_no_select_system_call
;
1558 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
1559 * Only checks read descriptors.
1561 /* How long to wait between checking fds in select */
1562 #define SELECT_PAUSE 1
1565 /* For longjmp'ing back to read_input_waiting. */
1567 jmp_buf read_alarm_throw
;
1569 /* Nonzero if the alarm signal should throw back to read_input_waiting.
1570 The read_socket_hook function sets this to 1 while it is waiting. */
1572 int read_alarm_should_throw
;
1580 #else /* not BSD4_1 */
1581 signal (SIGALRM
, SIG_IGN
);
1582 #endif /* not BSD4_1 */
1583 if (read_alarm_should_throw
)
1584 longjmp (read_alarm_throw
, 1);
1587 /* Only rfds are checked. */
1589 select (nfds
, rfds
, wfds
, efds
, timeout
)
1591 int *rfds
, *wfds
, *efds
, *timeout
;
1593 int ravail
= 0, orfds
= 0, old_alarm
;
1594 int timeoutval
= timeout
? *timeout
: 100000;
1595 int *local_timeout
= &timeoutval
;
1596 extern int proc_buffered_char
[];
1597 #ifndef subprocesses
1598 int process_tick
= 0, update_tick
= 0;
1600 extern int process_tick
, update_tick
;
1602 SIGTYPE (*old_trap
) ();
1615 /* If we are looking only for the terminal, with no timeout,
1616 just read it and wait -- that's more efficient. */
1617 if (orfds
== 1 && *local_timeout
== 100000 && process_tick
== update_tick
)
1619 if (! detect_input_pending ())
1620 read_input_waiting ();
1625 /* Once a second, till the timer expires, check all the flagged read
1626 * descriptors to see if any input is available. If there is some then
1627 * set the corresponding bit in the return copy of rfds.
1631 register int to_check
, bit
, fd
;
1635 for (to_check
= nfds
, bit
= 1, fd
= 0; --to_check
>= 0; bit
<<= 1, fd
++)
1639 int avail
= 0, status
= 0;
1642 avail
= detect_input_pending (); /* Special keyboard handler */
1646 status
= ioctl (fd
, FIONREAD
, &avail
);
1647 #else /* no FIONREAD */
1648 /* Hoping it will return -1 if nothing available
1649 or 0 if all 0 chars requested are read. */
1650 if (proc_buffered_char
[fd
] >= 0)
1654 avail
= read (fd
, &buf
, 1);
1656 proc_buffered_char
[fd
] = buf
;
1658 #endif /* no FIONREAD */
1660 if (status
>= 0 && avail
> 0)
1668 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
1670 old_alarm
= alarm (0);
1671 old_trap
= signal (SIGALRM
, select_alarm
);
1673 alarm (SELECT_PAUSE
);
1674 /* Wait for a SIGALRM (or maybe a SIGTINT) */
1675 while (select_alarmed
== 0 && *local_timeout
!= 0
1676 && process_tick
== update_tick
)
1678 /* If we are interested in terminal input,
1679 wait by reading the terminal.
1680 That makes instant wakeup for terminal input at least. */
1683 read_input_waiting ();
1684 if (detect_input_pending ())
1690 (*local_timeout
) -= SELECT_PAUSE
;
1691 /* Reset the old alarm if there was one */
1693 signal (SIGALRM
, old_trap
);
1696 /* Reset or forge an interrupt for the original handler. */
1697 old_alarm
-= SELECT_PAUSE
;
1699 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
1703 if (*local_timeout
== 0) /* Stop on timer being cleared */
1709 /* Read keyboard input into the standard buffer,
1710 waiting for at least one character. */
1712 /* Make all keyboard buffers much bigger when using X windows. */
1713 #ifdef HAVE_X_WINDOWS
1714 #define BUFFER_SIZE_FACTOR 16
1716 #define BUFFER_SIZE_FACTOR 1
1719 read_input_waiting ()
1721 char buf
[256 * BUFFER_SIZE_FACTOR
];
1722 struct input_event e
;
1724 extern int quit_char
;
1726 if (read_socket_hook
)
1728 read_alarm_should_throw
= 0;
1729 if (! setjmp (read_alarm_throw
))
1730 nread
= (*read_socket_hook
) (0, buf
, 256 * BUFFER_SIZE_FACTOR
, 1, 0);
1735 nread
= read (fileno (stdin
), buf
, 1);
1737 /* Scan the chars for C-g and store them in kbd_buffer. */
1738 e
.kind
= ascii_keystroke
;
1739 e
.frame
= selected_frame
;
1740 for (i
= 0; i
< nread
; i
++)
1742 XSET (e
.code
, Lisp_Int
, buf
[i
]);
1743 kbd_buffer_store_event (&e
);
1744 /* Don't look at input that follows a C-g too closely.
1745 This reduces lossage due to autorepeat on C-g. */
1746 if (buf
[i
] == quit_char
)
1751 #endif /* not HAVE_SELECT */
1752 #endif /* not VMS */
1762 * Partially emulate 4.2 open call.
1763 * open is defined as this in 4.1.
1765 * - added by Michael Bloom @ Citicorp/TTI
1770 sys_open (path
, oflag
, mode
)
1774 if (oflag
& O_CREAT
)
1775 return creat (path
, mode
);
1777 return open (path
, oflag
);
1784 lmode
= LINTRUP
| lmode
;
1785 ioctl (0, TIOCLSET
, &lmode
);
1792 lmode
= ~LINTRUP
& lmode
;
1793 ioctl (0, TIOCLSET
, &lmode
);
1800 interrupts_deferred
= 0;
1807 interrupts_deferred
= 1;
1810 /* still inside #ifdef BSD4_1 */
1813 int sigheld
; /* Mask of held signals */
1818 sigheld
|= sigbit (signum
);
1825 sigheld
|= sigbit (signum
);
1831 sigheld
&= ~sigbit (signum
);
1835 sigfree () /* Free all held signals */
1838 for (i
= 0; i
< NSIG
; i
++)
1839 if (sigheld
& sigbit (i
))
1846 return 1 << (i
- 1);
1848 #endif /* subprocesses */
1851 /* POSIX signals support - DJB */
1852 /* Anyone with POSIX signals should have ANSI C declarations */
1854 #ifdef POSIX_SIGNALS
1856 sigset_t old_mask
, empty_mask
, full_mask
, temp_mask
;
1857 static struct sigaction new_action
, old_action
;
1861 #ifdef POSIX_SIGNALS
1862 sigemptyset (&signal_empty_mask
);
1863 sigfillset (&signal_full_mask
);
1867 int (*signal_handler_t
) ();
1870 sys_signal (int signal_number
, signal_handler_t action
)
1873 /* This gets us restartable system calls for efficiency.
1874 The "else" code will works as well. */
1875 return (berk_signal (signal_number
, action
));
1877 sigemptyset (&new_action
.sa_mask
);
1878 new_action
.sa_handler
= action
;
1879 new_action
.sa_flags
= NULL
;
1880 sigaction (signal_number
, &new_action
, &old_action
);
1881 return (old_action
.sa_handler
);
1886 /* If we're compiling with GCC, we don't need this function, since it
1887 can be written as a macro. */
1889 sys_sigmask (int sig
)
1892 sigemptyset (&mask
);
1893 sigaddset (&mask
, sig
);
1899 sys_sigpause (sigset_t new_mask
)
1901 /* pause emulating berk sigpause... */
1902 sigsuspend (&new_mask
);
1906 /* I'd like to have these guys return pointers to the mask storage in here,
1907 but there'd be trouble if the code was saving multiple masks. I'll be
1908 safe and pass the structure. It normally won't be more than 2 bytes
1912 sys_sigblock (sigset_t new_mask
)
1915 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
1920 sys_sigunblock (sigset_t new_mask
)
1923 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
1928 sys_sigsetmask (sigset_t new_mask
)
1931 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
1935 #endif /* POSIX_SIGNALS */
1942 register int length
;
1946 long max_str
= 65535;
1948 while (length
> max_str
) {
1949 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
1954 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
1956 while (length
-- > 0)
1958 #endif /* not VMS */
1961 /* Saying `void' requires a declaration, above, where bcopy is used
1962 and that declaration causes pain for systems where bcopy is a macro. */
1963 bcopy (b1
, b2
, length
)
1966 register int length
;
1969 long max_str
= 65535;
1971 while (length
> max_str
) {
1972 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
1978 (void) LIB$
MOVC3 (&length
, b1
, b2
);
1980 while (length
-- > 0)
1982 #endif /* not VMS */
1986 bcmp (b1
, b2
, length
) /* This could be a macro! */
1989 register int length
;
1992 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
1993 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
1995 return STR$
COMPARE (&src1
, &src2
);
1997 while (length
-- > 0)
2002 #endif /* not VMS */
2004 #endif /* not BSTRING */
2008 * The BSD random returns numbers in the range of
2009 * 0 to 2e31 - 1. The USG rand returns numbers in the
2010 * range of 0 to 2e15 - 1. This is probably not significant
2017 /* Arrange to return a range centered on zero. */
2018 return (rand () << 15) + rand () - (1 << 29);
2032 /* Arrange to return a range centered on zero. */
2033 return (rand () << 15) + rand () - (1 << 29);
2043 #ifdef WRONG_NAME_INSQUE
2056 /* If any place else asks for the TERM variable,
2057 allow it to be overridden with the EMACS_TERM variable
2058 before attempting to translate the logical name TERM. As a last
2059 resort, ask for VAX C's special idea of the TERM variable. */
2066 static char buf
[256];
2067 static struct dsc$descriptor_s equiv
2068 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2069 static struct dsc$descriptor_s d_name
2070 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2073 if (!strcmp (name
, "TERM"))
2075 val
= (char *) getenv ("EMACS_TERM");
2080 d_name
.dsc$w_length
= strlen (name
);
2081 d_name
.dsc$a_pointer
= name
;
2082 if (lib$
sys_trnlog (&d_name
, &eqlen
, &equiv
) == 1)
2084 char *str
= (char *) xmalloc (eqlen
+ 1);
2085 bcopy (buf
, str
, eqlen
);
2087 /* This is a storage leak, but a pain to fix. With luck,
2088 no one will ever notice. */
2091 return (char *) getenv (name
);
2096 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2097 to force a call on the debugger from within the image. */
2102 LIB$
SIGNAL (SS$_DEBUG
);
2108 #ifdef LINK_CRTL_SHARE
2109 #ifdef SHAREABLE_LIB_BUG
2110 /* Variables declared noshare and initialized in shareable libraries
2111 cannot be shared. The VMS linker incorrectly forces you to use a private
2112 version which is uninitialized... If not for this "feature", we
2113 could use the C library definition of sys_nerr and sys_errlist. */
2115 char *sys_errlist
[] =
2119 "no such file or directory",
2121 "interrupted system call",
2123 "no such device or address",
2124 "argument list too long",
2125 "exec format error",
2128 "no more processes",
2129 "not enough memory",
2130 "permission denied",
2132 "block device required",
2133 "mount devices busy",
2135 "cross-device link",
2140 "file table overflow",
2141 "too many open files",
2145 "no space left on device",
2147 "read-only file system",
2153 "vax/vms specific error code nontranslatable error"
2155 #endif /* SHAREABLE_LIB_BUG */
2156 #endif /* LINK_CRTL_SHARE */
2159 #ifdef INTERRUPTIBLE_OPEN
2163 sys_open (path
, oflag
, mode
)
2167 register int rtnval
;
2169 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2170 && (errno
== EINTR
));
2174 #endif /* INTERRUPTIBLE_OPEN */
2176 #ifdef INTERRUPTIBLE_CLOSE
2181 register int rtnval
;
2183 while ((rtnval
= close (fd
)) == -1
2184 && (errno
== EINTR
));
2188 #endif /* INTERRUPTIBLE_CLOSE */
2190 #ifdef INTERRUPTIBLE_IO
2193 sys_read (fildes
, buf
, nbyte
)
2198 register int rtnval
;
2200 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
2201 && (errno
== EINTR
));
2206 sys_write (fildes
, buf
, nbyte
)
2211 register int rtnval
;
2213 while ((rtnval
= write (fildes
, buf
, nbyte
)) == -1
2214 && (errno
== EINTR
));
2218 #endif /* INTERRUPTIBLE_IO */
2222 * All of the following are for USG.
2224 * On USG systems the system calls are INTERRUPTIBLE by signals
2225 * that the user program has elected to catch. Thus the system call
2226 * must be retried in these cases. To handle this without massive
2227 * changes in the source code, we remap the standard system call names
2228 * to names for our own functions in sysdep.c that do the system call
2229 * with retries. Actually, for portability reasons, it is good
2230 * programming practice, as this example shows, to limit all actual
2231 * system calls to a single occurance in the source. Sure, this
2232 * adds an extra level of function call overhead but it is almost
2233 * always negligible. Fred Fish, Unisoft Systems Inc.
2236 char *sys_siglist
[NSIG
+ 1] =
2239 /* AIX has changed the signals a bit */
2240 "bogus signal", /* 0 */
2241 "hangup", /* 1 SIGHUP */
2242 "interrupt", /* 2 SIGINT */
2243 "quit", /* 3 SIGQUIT */
2244 "illegal instruction", /* 4 SIGILL */
2245 "trace trap", /* 5 SIGTRAP */
2246 "IOT instruction", /* 6 SIGIOT */
2247 "crash likely", /* 7 SIGDANGER */
2248 "floating point exception", /* 8 SIGFPE */
2249 "kill", /* 9 SIGKILL */
2250 "bus error", /* 10 SIGBUS */
2251 "segmentation violation", /* 11 SIGSEGV */
2252 "bad argument to system call", /* 12 SIGSYS */
2253 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2254 "alarm clock", /* 14 SIGALRM */
2255 "software termination signum", /* 15 SIGTERM */
2256 "user defined signal 1", /* 16 SIGUSR1 */
2257 "user defined signal 2", /* 17 SIGUSR2 */
2258 "death of a child", /* 18 SIGCLD */
2259 "power-fail restart", /* 19 SIGPWR */
2260 "bogus signal", /* 20 */
2261 "bogus signal", /* 21 */
2262 "bogus signal", /* 22 */
2263 "bogus signal", /* 23 */
2264 "bogus signal", /* 24 */
2265 "LAN I/O interrupt", /* 25 SIGAIO */
2266 "PTY I/O interrupt", /* 26 SIGPTY */
2267 "I/O intervention required", /* 27 SIGIOINT */
2268 "HFT grant", /* 28 SIGGRANT */
2269 "HFT retract", /* 29 SIGRETRACT */
2270 "HFT sound done", /* 30 SIGSOUND */
2271 "HFT input ready", /* 31 SIGMSG */
2273 "bogus signal", /* 0 */
2274 "hangup", /* 1 SIGHUP */
2275 "interrupt", /* 2 SIGINT */
2276 "quit", /* 3 SIGQUIT */
2277 "illegal instruction", /* 4 SIGILL */
2278 "trace trap", /* 5 SIGTRAP */
2279 "IOT instruction", /* 6 SIGIOT */
2280 "EMT instruction", /* 7 SIGEMT */
2281 "floating point exception", /* 8 SIGFPE */
2282 "kill", /* 9 SIGKILL */
2283 "bus error", /* 10 SIGBUS */
2284 "segmentation violation", /* 11 SIGSEGV */
2285 "bad argument to system call", /* 12 SIGSYS */
2286 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2287 "alarm clock", /* 14 SIGALRM */
2288 "software termination signum", /* 15 SIGTERM */
2289 "user defined signal 1", /* 16 SIGUSR1 */
2290 "user defined signal 2", /* 17 SIGUSR2 */
2291 "death of a child", /* 18 SIGCLD */
2292 "power-fail restart", /* 19 SIGPWR */
2293 #endif /* not AIX */
2298 * Warning, this function may not duplicate 4.2 action properly
2299 * under error conditions.
2303 /* In 4.1, param.h fails to define this. */
2304 #define MAXPATHLEN 1024
2313 char *npath
, *spath
;
2314 extern char *getcwd ();
2316 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
2317 /* On Altos 3068, getcwd can return @hostname/dir, so discard
2318 up to first slash. Should be harmless on other systems. */
2319 while (*npath
&& *npath
!= '/')
2321 strcpy (pathname
, npath
);
2322 free (spath
); /* getcwd uses malloc */
2326 #endif /* HAVE_GETWD */
2329 * Emulate rename using unlink/link. Note that this is
2330 * only partially correct. Also, doesn't enforce restriction
2331 * that files be of same type (regular->regular, dir->dir, etc).
2340 if (access (from
, 0) == 0)
2343 if (link (from
, to
) == 0)
2344 if (unlink (from
) == 0)
2352 /* Set priority value to PRIO. */
2355 setpriority (which
, who
, prio
)
2356 int which
, who
, prio
;
2360 nice (prio
- nice (0));
2367 * Substitute fork for vfork on USG flavors.
2375 #endif /* not HAVE_VFORK */
2377 #ifdef MISSING_UTIMES
2379 /* HPUX (among others) sets HAVE_TIMEVAL but does not implement utimes. */
2388 /* The IRIS (3.5) has timevals, but uses sys V utime, and doesn't have the
2389 utimbuf structure defined anywhere but in the man page. */
2399 struct timeval tvp
[];
2402 utb
.actime
= tvp
[0].tv_sec
;
2403 utb
.modtime
= tvp
[1].tv_sec
;
2406 #endif /* IRIS_UTIME */
2412 /* HPUX curses library references perror, but as far as we know
2413 it won't be called. Anyway this definition will do for now. */
2419 #endif /* not HAVE_PERROR */
2425 * Emulate BSD dup2. First close newd if it already exists.
2426 * Then, attempt to dup oldd. If not successful, call dup2 recursively
2427 * until we are, then close the unsuccessful ones.
2434 register int fd
, ret
;
2439 fd
= fcntl (oldd
, F_DUPFD
, newd
);
2441 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, sys_errlist
[errno
]);
2448 ret
= dup2 (old
,new);
2454 #endif /* not HAVE_DUP2 */
2457 * Gettimeofday. Simulate as much as possible. Only accurate
2458 * to nearest second. Emacs doesn't use tzp so ignore it for now.
2459 * Only needed when subprocesses are defined.
2464 #ifndef HAVE_GETTIMEOFDAY
2468 gettimeofday (tp
, tzp
)
2470 struct timezone
*tzp
;
2472 extern long time ();
2474 tp
->tv_sec
= time ((long *)0);
2476 tzp
->tz_minuteswest
= -1;
2482 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
2485 * This function will go away as soon as all the stubs fixed. (fnf)
2491 printf ("%s not yet implemented\r\n", badfunc
);
2500 char *sys_siglist
[NSIG
+ 1] =
2502 "null signal", /* 0 SIGNULL */
2503 "hangup", /* 1 SIGHUP */
2504 "interrupt", /* 2 SIGINT */
2505 "quit", /* 3 SIGQUIT */
2506 "illegal instruction", /* 4 SIGILL */
2507 "trace trap", /* 5 SIGTRAP */
2508 "abort termination", /* 6 SIGABRT */
2509 "SIGEMT", /* 7 SIGEMT */
2510 "floating point exception", /* 8 SIGFPE */
2511 "kill", /* 9 SIGKILL */
2512 "bus error", /* 10 SIGBUS */
2513 "segmentation violation", /* 11 SIGSEGV */
2514 "bad argument to system call", /* 12 SIGSYS */
2515 "write on a pipe with no reader", /* 13 SIGPIPE */
2516 "alarm clock", /* 14 SIGALRM */
2517 "software termination signal", /* 15 SIGTERM */
2518 "user defined signal 1", /* 16 SIGUSR1 */
2519 "user defined signal 2", /* 17 SIGUSR2 */
2520 "child stopped or terminated", /* 18 SIGCLD */
2521 "power-fail restart", /* 19 SIGPWR */
2522 "window size changed", /* 20 SIGWINCH */
2523 "undefined", /* 21 */
2524 "pollable event occured", /* 22 SIGPOLL */
2525 "sendable stop signal not from tty", /* 23 SIGSTOP */
2526 "stop signal from tty", /* 24 SIGSTP */
2527 "continue a stopped process", /* 25 SIGCONT */
2528 "attempted background tty read", /* 26 SIGTTIN */
2529 "attempted background tty write", /* 27 SIGTTOU */
2530 "undefined", /* 28 */
2531 "undefined", /* 29 */
2532 "undefined", /* 30 */
2533 "undefined", /* 31 */
2534 "undefined", /* 32 */
2535 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
2536 "I/O is possible", /* 34 SIGIO */
2537 "exceeded cpu time limit", /* 35 SIGXCPU */
2538 "exceeded file size limit", /* 36 SIGXFSZ */
2539 "virtual time alarm", /* 37 SIGVTALRM */
2540 "profiling time alarm", /* 38 SIGPROF */
2541 "undefined", /* 39 */
2542 "file record locks revoked", /* 40 SIGLOST */
2543 "undefined", /* 41 */
2544 "undefined", /* 42 */
2545 "undefined", /* 43 */
2546 "undefined", /* 44 */
2547 "undefined", /* 45 */
2548 "undefined", /* 46 */
2549 "undefined", /* 47 */
2550 "undefined", /* 48 */
2551 "undefined", /* 49 */
2552 "undefined", /* 50 */
2553 "undefined", /* 51 */
2554 "undefined", /* 52 */
2555 "undefined", /* 53 */
2556 "undefined", /* 54 */
2557 "undefined", /* 55 */
2558 "undefined", /* 56 */
2559 "undefined", /* 57 */
2560 "undefined", /* 58 */
2561 "undefined", /* 59 */
2562 "undefined", /* 60 */
2563 "undefined", /* 61 */
2564 "undefined", /* 62 */
2565 "undefined", /* 63 */
2566 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
2572 /* Directory routines for systems that don't have them. */
2574 #ifdef SYSV_SYSTEM_DIR
2581 register DIR *dirp
; /* stream from opendir */
2583 sys_close (dirp
->dd_fd
);
2584 free ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
2585 free ((char *) dirp
);
2587 #endif /* not AIX */
2588 #endif /* SYSV_SYSTEM_DIR */
2590 #ifdef NONSYSTEM_DIR_LIBRARY
2594 char *filename
; /* name of directory */
2596 register DIR *dirp
; /* -> malloc'ed storage */
2597 register int fd
; /* file descriptor for read */
2598 struct stat sbuf
; /* result of fstat */
2600 fd
= sys_open (filename
, 0);
2604 if (fstat (fd
, &sbuf
) < 0
2605 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
2606 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
2609 return 0; /* bad luck today */
2613 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
2620 register DIR *dirp
; /* stream from opendir */
2622 sys_close (dirp
->dd_fd
);
2623 free ((char *) dirp
);
2631 ino_t od_ino
; /* inode */
2632 char od_name
[DIRSIZ
]; /* filename */
2634 #endif /* not VMS */
2636 struct direct dir_static
; /* simulated directory contents */
2641 register DIR *dirp
; /* stream from opendir */
2644 register struct olddir
*dp
; /* -> directory data */
2646 register struct dir$_name
*dp
; /* -> directory data */
2647 register struct dir$_version
*dv
; /* -> version data */
2652 if (dirp
->dd_loc
>= dirp
->dd_size
)
2653 dirp
->dd_loc
= dirp
->dd_size
= 0;
2655 if (dirp
->dd_size
== 0 /* refill buffer */
2656 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
2660 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
2661 dirp
->dd_loc
+= sizeof (struct olddir
);
2663 if (dp
->od_ino
!= 0) /* not deleted entry */
2665 dir_static
.d_ino
= dp
->od_ino
;
2666 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
2667 dir_static
.d_name
[DIRSIZ
] = '\0';
2668 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
2669 dir_static
.d_reclen
= sizeof (struct direct
)
2671 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
2672 return &dir_static
; /* -> simulated structure */
2675 dp
= (struct dir$_name
*) dirp
->dd_buf
;
2676 if (dirp
->dd_loc
== 0)
2677 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
2678 : dp
->dir$b_namecount
;
2679 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
2680 dir_static
.d_ino
= dv
->dir$w_fid_num
;
2681 dir_static
.d_namlen
= dp
->dir$b_namecount
;
2682 dir_static
.d_reclen
= sizeof (struct direct
)
2684 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
2685 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
2686 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
2687 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
2694 /* readdirver is just like readdir except it returns all versions of a file
2695 as separate entries. */
2700 register DIR *dirp
; /* stream from opendir */
2702 register struct dir$_name
*dp
; /* -> directory data */
2703 register struct dir$_version
*dv
; /* -> version data */
2705 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
2706 dirp
->dd_loc
= dirp
->dd_size
= 0;
2708 if (dirp
->dd_size
== 0 /* refill buffer */
2709 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
2712 dp
= (struct dir$_name
*) dirp
->dd_buf
;
2713 if (dirp
->dd_loc
== 0)
2714 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
2715 : dp
->dir$b_namecount
;
2716 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
2717 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
2718 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
2719 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
2720 dir_static
.d_ino
= dv
->dir$w_fid_num
;
2721 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
2722 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
2723 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
2729 #endif /* NONSYSTEM_DIR_LIBRARY */
2731 /* Functions for VMS */
2733 #include "vms-pwd.h"
2738 /* Return as a string the VMS error string pertaining to STATUS.
2739 Reuses the same static buffer each time it is called. */
2743 int status
; /* VMS status code */
2747 static char buf
[257];
2749 bufadr
[0] = sizeof buf
- 1;
2750 bufadr
[1] = (int) buf
;
2751 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
2752 return "untranslatable VMS error status";
2760 /* The following is necessary because 'access' emulation by VMS C (2.0) does
2761 * not work correctly. (It also doesn't work well in version 2.3.)
2766 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
2767 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
2771 unsigned short s_buflen
;
2772 unsigned short s_code
;
2774 unsigned short *s_retlenadr
;
2778 #define buflen s.s_buflen
2779 #define code s.s_code
2780 #define bufadr s.s_bufadr
2781 #define retlenadr s.s_retlenadr
2783 #define R_OK 4 /* test for read permission */
2784 #define W_OK 2 /* test for write permission */
2785 #define X_OK 1 /* test for execute (search) permission */
2786 #define F_OK 0 /* test for presence of file */
2789 sys_access (path
, mode
)
2793 static char *user
= NULL
;
2796 /* translate possible directory spec into .DIR file name, so brain-dead
2797 * access can treat the directory like a file. */
2798 if (directory_file_name (path
, dir_fn
))
2802 return access (path
, mode
);
2803 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
2809 unsigned short int dummy
;
2811 static int constant
= ACL$C_FILE
;
2812 DESCRIPTOR (path_desc
, path
);
2813 DESCRIPTOR (user_desc
, user
);
2817 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
2820 acces
|= CHP$M_READ
;
2822 acces
|= CHP$M_WRITE
;
2823 itemlst
[0].buflen
= sizeof (int);
2824 itemlst
[0].code
= CHP$_FLAGS
;
2825 itemlst
[0].bufadr
= (char *) &flags
;
2826 itemlst
[0].retlenadr
= &dummy
;
2827 itemlst
[1].buflen
= sizeof (int);
2828 itemlst
[1].code
= CHP$_ACCESS
;
2829 itemlst
[1].bufadr
= (char *) &acces
;
2830 itemlst
[1].retlenadr
= &dummy
;
2831 itemlst
[2].end
= CHP$_END
;
2832 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
2833 return stat
== SS$_NORMAL
? 0 : -1;
2837 #else /* not VMS4_4 */
2840 #define ACE$M_WRITE 2
2841 #define ACE$C_KEYID 1
2843 static unsigned short memid
, grpid
;
2844 static unsigned int uic
;
2846 /* Called from init_sys_modes, so it happens not very often
2847 but at least each time Emacs is loaded. */
2848 sys_access_reinit ()
2854 sys_access (filename
, type
)
2860 int status
, size
, i
, typecode
, acl_controlled
;
2861 unsigned int *aclptr
, *aclend
, aclbuf
[60];
2862 union prvdef prvmask
;
2864 /* Get UIC and GRP values for protection checking. */
2867 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
2870 memid
= uic
& 0xFFFF;
2874 if (type
!= 2) /* not checking write access */
2875 return access (filename
, type
);
2877 /* Check write protection. */
2879 #define CHECKPRIV(bit) (prvmask.bit)
2880 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
2882 /* Find privilege bits */
2883 status
= sys$
setprv (0, 0, 0, prvmask
);
2885 error ("Unable to find privileges: %s", vmserrstr (status
));
2886 if (CHECKPRIV (PRV$V_BYPASS
))
2887 return 0; /* BYPASS enabled */
2889 fab
.fab$b_fac
= FAB$M_GET
;
2890 fab
.fab$l_fna
= filename
;
2891 fab
.fab$b_fns
= strlen (filename
);
2892 fab
.fab$l_xab
= &xab
;
2893 xab
= cc$rms_xabpro
;
2894 xab
.xab$l_aclbuf
= aclbuf
;
2895 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
2896 status
= sys$
open (&fab
, 0, 0);
2899 sys$
close (&fab
, 0, 0);
2900 /* Check system access */
2901 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITEABLE (XAB$V_SYS
))
2903 /* Check ACL entries, if any */
2905 if (xab
.xab$w_acllen
> 0)
2908 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
2909 while (*aclptr
&& aclptr
< aclend
)
2911 size
= (*aclptr
& 0xff) / 4;
2912 typecode
= (*aclptr
>> 8) & 0xff;
2913 if (typecode
== ACE$C_KEYID
)
2914 for (i
= size
- 1; i
> 1; i
--)
2915 if (aclptr
[i
] == uic
)
2918 if (aclptr
[1] & ACE$M_WRITE
)
2919 return 0; /* Write access through ACL */
2921 aclptr
= &aclptr
[size
];
2923 if (acl_controlled
) /* ACL specified, prohibits write access */
2926 /* No ACL entries specified, check normal protection */
2927 if (WRITEABLE (XAB$V_WLD
)) /* World writeable */
2929 if (WRITEABLE (XAB$V_GRP
) &&
2930 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
2931 return 0; /* Group writeable */
2932 if (WRITEABLE (XAB$V_OWN
) &&
2933 (xab
.xab$l_uic
& 0xFFFF) == memid
)
2934 return 0; /* Owner writeable */
2936 return -1; /* Not writeable */
2938 #endif /* not VMS4_4 */
2941 static char vtbuf
[NAM$C_MAXRSS
+1];
2943 /* translate a vms file spec to a unix path */
2945 sys_translate_vms (vfile
)
2956 /* leading device or logical name is a root directory */
2957 if (p
= strchr (vfile
, ':'))
2966 if (*p
== '[' || *p
== '<')
2968 while (*++vfile
!= *p
+ 2)
2972 if (vfile
[-1] == *p
)
2995 static char utbuf
[NAM$C_MAXRSS
+1];
2997 /* translate a unix path to a VMS file spec */
2999 sys_translate_unix (ufile
)
3022 if (index (&ufile
[1], '/'))
3029 if (index (&ufile
[1], '/'))
3036 if (strncmp (ufile
, "./", 2) == 0)
3043 ufile
++; /* skip the dot */
3044 if (index (&ufile
[1], '/'))
3049 else if (strncmp (ufile
, "../", 3) == 0)
3057 ufile
+= 2; /* skip the dots */
3058 if (index (&ufile
[1], '/'))
3083 strcpy (pathname
, egetenv ("PATH"));
3088 if ('a' <= *ptr
&& *ptr
<= 'z')
3097 long item_code
= JPI$_OWNER
;
3098 unsigned long parent_id
;
3101 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
3104 vaxc$errno
= status
;
3114 return (getgid () << 16) | getuid ();
3118 sys_read (fildes
, buf
, nbyte
)
3123 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
3128 sys_write (fildes
, buf
, nbyte
)
3133 register int nwrote
, rtnval
= 0;
3135 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
3141 return rtnval
? rtnval
: -1;
3142 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
3143 return rtnval
? rtnval
: -1;
3144 return (rtnval
+ nwrote
);
3149 * VAX/VMS VAX C RTL really loses. It insists that records
3150 * end with a newline (carriage return) character, and if they
3151 * don't it adds one (nice of it isn't it!)
3153 * Thus we do this stupidity below.
3157 sys_write (fildes
, buf
, nbytes
)
3160 unsigned int nbytes
;
3167 fstat (fildes
, &st
);
3173 /* Handle fixed-length files with carriage control. */
3174 if (st
.st_fab_rfm
== FAB$C_FIX
3175 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
3177 len
= st
.st_fab_mrs
;
3178 retval
= write (fildes
, p
, min (len
, nbytes
));
3181 retval
++; /* This skips the implied carriage control */
3185 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3186 while (*e
!= '\n' && e
> p
) e
--;
3187 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
3188 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3190 retval
= write (fildes
, p
, len
);
3201 /* Create file NEW copying its attributes from file OLD. If
3202 OLD is 0 or does not exist, create based on the value of
3205 /* Protection value the file should ultimately have.
3206 Set by create_copy_attrs, and use by rename_sansversions. */
3207 static unsigned short int fab_final_pro
;
3210 creat_copy_attrs (old
, new)
3213 struct FAB fab
= cc$rms_fab
;
3214 struct XABPRO xabpro
;
3215 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
3216 extern int vms_stmlf_recfm
;
3220 fab
.fab$b_fac
= FAB$M_GET
;
3221 fab
.fab$l_fna
= old
;
3222 fab
.fab$b_fns
= strlen (old
);
3223 fab
.fab$l_xab
= (char *) &xabpro
;
3224 xabpro
= cc$rms_xabpro
;
3225 xabpro
.xab$l_aclbuf
= aclbuf
;
3226 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
3227 /* Call $OPEN to fill in the fab & xabpro fields. */
3228 if (sys$
open (&fab
, 0, 0) & 1)
3230 sys$
close (&fab
, 0, 0);
3231 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
3232 if (xabpro
.xab$w_acllen
> 0)
3234 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
3235 /* If the acl buffer was too short, redo open with longer one.
3236 Wouldn't need to do this if there were some system imposed
3237 limit on the size of an ACL, but I can't find any such. */
3239 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
3240 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
3241 if (sys$
open (&fab
, 0, 0) & 1)
3242 sys$
close (&fab
, 0, 0);
3248 xabpro
.xab$l_aclbuf
= 0;
3253 fab
.fab$l_fna
= new;
3254 fab
.fab$b_fns
= strlen (new);
3258 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
3259 fab
.fab$b_rat
= FAB$M_CR
;
3262 /* Set the file protections such that we will be able to manipulate
3263 this file. Once we are done writing and renaming it, we will set
3264 the protections back. */
3266 fab_final_pro
= xabpro
.xab$w_pro
;
3268 sys$
setdfprot (0, &fab_final_pro
);
3269 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
3271 /* Create the new file with either default attrs or attrs copied
3273 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
3275 sys$
close (&fab
, 0, 0);
3276 /* As this is a "replacement" for creat, return a file descriptor
3277 opened for writing. */
3278 return open (new, O_WRONLY
);
3283 #include <varargs.h>
3286 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
3290 sys_creat (va_alist
)
3293 va_list list_incrementor
;
3296 int rfd
; /* related file descriptor */
3297 int fd
; /* Our new file descriptor */
3304 extern int vms_stmlf_recfm
;
3307 va_start (list_incrementor
);
3308 name
= va_arg (list_incrementor
, char *);
3309 mode
= va_arg (list_incrementor
, int);
3311 rfd
= va_arg (list_incrementor
, int);
3312 va_end (list_incrementor
);
3315 /* Use information from the related file descriptor to set record
3316 format of the newly created file. */
3317 fstat (rfd
, &st_buf
);
3318 switch (st_buf
.st_fab_rfm
)
3321 strcpy (rfm
, "rfm = fix");
3322 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
3323 strcpy (rat
, "rat = ");
3324 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3326 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3327 strcat (rat
, "ftn");
3328 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3329 strcat (rat
, "prn");
3330 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3331 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3332 strcat (rat
, ", blk");
3334 strcat (rat
, "blk");
3335 return creat (name
, 0, rfm
, rat
, mrs
);
3338 strcpy (rfm
, "rfm = vfc");
3339 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
3340 strcpy (rat
, "rat = ");
3341 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3343 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3344 strcat (rat
, "ftn");
3345 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3346 strcat (rat
, "prn");
3347 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3348 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3349 strcat (rat
, ", blk");
3351 strcat (rat
, "blk");
3352 return creat (name
, 0, rfm
, rat
, fsz
);
3355 strcpy (rfm
, "rfm = stm");
3359 strcpy (rfm
, "rfm = stmcr");
3363 strcpy (rfm
, "rfm = stmlf");
3367 strcpy (rfm
, "rfm = udf");
3371 strcpy (rfm
, "rfm = var");
3374 strcpy (rat
, "rat = ");
3375 if (st_buf
.st_fab_rat
& FAB$M_CR
)
3377 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
3378 strcat (rat
, "ftn");
3379 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
3380 strcat (rat
, "prn");
3381 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
3382 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
3383 strcat (rat
, ", blk");
3385 strcat (rat
, "blk");
3389 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
3390 strcpy (rat
, "rat=cr");
3392 /* Until the VAX C RTL fixes the many bugs with modes, always use
3393 mode 0 to get the user's default protection. */
3394 fd
= creat (name
, 0, rfm
, rat
);
3395 if (fd
< 0 && errno
== EEXIST
)
3397 if (unlink (name
) < 0)
3398 report_file_error ("delete", build_string (name
));
3399 fd
= creat (name
, 0, rfm
, rat
);
3405 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
3406 sys_fwrite (ptr
, size
, num
, fp
)
3407 register char * ptr
;
3410 register int tot
= num
* size
;
3417 * The VMS C library routine creat actually creates a new version of an
3418 * existing file rather than truncating the old version. There are times
3419 * when this is not the desired behavior, for instance, when writing an
3420 * auto save file (you only want one version), or when you don't have
3421 * write permission in the directory containing the file (but the file
3422 * itself is writable). Hence this routine, which is equivalent to
3423 * "close (creat (fn, 0));" on Unix if fn already exists.
3429 struct FAB xfab
= cc$rms_fab
;
3430 struct RAB xrab
= cc$rms_rab
;
3433 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
3434 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
3435 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
3436 xfab
.fab$l_fna
= fn
;
3437 xfab
.fab$b_fns
= strlen (fn
);
3438 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
3440 xrab
.rab$l_fab
= &xfab
;
3442 /* This gibberish opens the file, positions to the first record, and
3443 deletes all records from there until the end of file. */
3444 if ((sys$
open (&xfab
) & 01) == 01)
3446 if ((sys$
connect (&xrab
) & 01) == 01 &&
3447 (sys$
find (&xrab
) & 01) == 01 &&
3448 (sys$
truncate (&xrab
) & 01) == 01)
3459 /* Define this symbol to actually read SYSUAF.DAT. This requires either
3460 SYSPRV or a readable SYSUAF.DAT. */
3466 * Routine to read the VMS User Authorization File and return
3467 * a specific user's record.
3470 static struct UAF retuaf
;
3473 get_uaf_name (uname
)
3480 uaf_fab
= cc$rms_fab
;
3481 uaf_rab
= cc$rms_rab
;
3482 /* initialize fab fields */
3483 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
3484 uaf_fab
.fab$b_fns
= 21;
3485 uaf_fab
.fab$b_fac
= FAB$M_GET
;
3486 uaf_fab
.fab$b_org
= FAB$C_IDX
;
3487 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
3488 /* initialize rab fields */
3489 uaf_rab
.rab$l_fab
= &uaf_fab
;
3490 /* open the User Authorization File */
3491 status
= sys$
open (&uaf_fab
);
3495 vaxc$errno
= status
;
3498 status
= sys$
connect (&uaf_rab
);
3502 vaxc$errno
= status
;
3505 /* read the requested record - index is in uname */
3506 uaf_rab
.rab$l_kbf
= uname
;
3507 uaf_rab
.rab$b_ksz
= strlen (uname
);
3508 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
3509 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
3510 uaf_rab
.rab$w_usz
= sizeof retuaf
;
3511 status
= sys$
get (&uaf_rab
);
3515 vaxc$errno
= status
;
3518 /* close the User Authorization File */
3519 status
= sys$
disconnect (&uaf_rab
);
3523 vaxc$errno
= status
;
3526 status
= sys$
close (&uaf_fab
);
3530 vaxc$errno
= status
;
3544 uaf_fab
= cc$rms_fab
;
3545 uaf_rab
= cc$rms_rab
;
3546 /* initialize fab fields */
3547 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
3548 uaf_fab
.fab$b_fns
= 21;
3549 uaf_fab
.fab$b_fac
= FAB$M_GET
;
3550 uaf_fab
.fab$b_org
= FAB$C_IDX
;
3551 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
3552 /* initialize rab fields */
3553 uaf_rab
.rab$l_fab
= &uaf_fab
;
3554 /* open the User Authorization File */
3555 status
= sys$
open (&uaf_fab
);
3559 vaxc$errno
= status
;
3562 status
= sys$
connect (&uaf_rab
);
3566 vaxc$errno
= status
;
3569 /* read the requested record - index is in uic */
3570 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
3571 uaf_rab
.rab$l_kbf
= (char *) &uic
;
3572 uaf_rab
.rab$b_ksz
= sizeof uic
;
3573 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
3574 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
3575 uaf_rab
.rab$w_usz
= sizeof retuaf
;
3576 status
= sys$
get (&uaf_rab
);
3580 vaxc$errno
= status
;
3583 /* close the User Authorization File */
3584 status
= sys$
disconnect (&uaf_rab
);
3588 vaxc$errno
= status
;
3591 status
= sys$
close (&uaf_fab
);
3595 vaxc$errno
= status
;
3601 static struct passwd retpw
;
3609 /* copy these out first because if the username is 32 chars, the next
3610 section will overwrite the first byte of the UIC */
3611 retpw
.pw_uid
= up
->uaf$w_mem
;
3612 retpw
.pw_gid
= up
->uaf$w_grp
;
3614 /* I suppose this is not the best sytle, to possibly overwrite one
3615 byte beyond the end of the field, but what the heck... */
3616 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
3617 while (ptr
[-1] == ' ')
3620 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
3622 /* the rest of these are counted ascii strings */
3623 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
3624 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
3625 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
3626 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
3627 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
3628 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
3629 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
3630 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
3634 #else /* not READ_SYSUAF */
3635 static struct passwd retpw
;
3636 #endif /* not READ_SYSUAF */
3647 unsigned char * full
;
3648 #endif /* READ_SYSUAF */
3653 if ('a' <= *ptr
&& *ptr
<= 'z')
3658 if (!(up
= get_uaf_name (name
)))
3660 return cnv_uaf_pw (up
);
3662 if (strcmp (name
, getenv ("USER")) == 0)
3664 retpw
.pw_uid
= getuid ();
3665 retpw
.pw_gid
= getgid ();
3666 strcpy (retpw
.pw_name
, name
);
3667 if (full
= egetenv ("FULLNAME"))
3668 strcpy (retpw
.pw_gecos
, full
);
3670 *retpw
.pw_gecos
= '\0';
3671 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
3672 *retpw
.pw_shell
= '\0';
3677 #endif /* not READ_SYSUAF */
3687 if (!(up
= get_uaf_uic (uid
)))
3689 return cnv_uaf_pw (up
);
3691 if (uid
== sys_getuid ())
3692 return getpwnam (egetenv ("USER"));
3695 #endif /* not READ_SYSUAF */
3698 /* return total address space available to the current process. This is
3699 the sum of the current p0 size, p1 size and free page table entries
3704 unsigned long free_pages
;
3705 unsigned long frep0va
;
3706 unsigned long frep1va
;
3709 item_code
= JPI$_FREPTECNT
;
3710 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
3713 vaxc$errno
= status
;
3718 item_code
= JPI$_FREP0VA
;
3719 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
3722 vaxc$errno
= status
;
3725 item_code
= JPI$_FREP1VA
;
3726 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
3729 vaxc$errno
= status
;
3733 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
3736 define_logical_name (varname
, string
)
3740 struct dsc$descriptor_s strdsc
=
3741 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
3742 struct dsc$descriptor_s envdsc
=
3743 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
3744 struct dsc$descriptor_s lnmdsc
=
3745 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
3747 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
3750 delete_logical_name (varname
)
3753 struct dsc$descriptor_s envdsc
=
3754 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
3755 struct dsc$descriptor_s lnmdsc
=
3756 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
3758 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
3772 error ("execvp system call not implemented");
3780 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
3781 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
3782 char from_esn
[NAM$C_MAXRSS
];
3783 char to_esn
[NAM$C_MAXRSS
];
3785 from_fab
.fab$l_fna
= from
;
3786 from_fab
.fab$b_fns
= strlen (from
);
3787 from_fab
.fab$l_nam
= &from_nam
;
3788 from_fab
.fab$l_fop
= FAB$M_NAM
;
3790 from_nam
.nam$l_esa
= from_esn
;
3791 from_nam
.nam$b_ess
= sizeof from_esn
;
3793 to_fab
.fab$l_fna
= to
;
3794 to_fab
.fab$b_fns
= strlen (to
);
3795 to_fab
.fab$l_nam
= &to_nam
;
3796 to_fab
.fab$l_fop
= FAB$M_NAM
;
3798 to_nam
.nam$l_esa
= to_esn
;
3799 to_nam
.nam$b_ess
= sizeof to_esn
;
3801 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
3807 if (status
== RMS$_DEV
)
3811 vaxc$errno
= status
;
3816 /* This function renames a file like `rename', but it strips
3817 the version number from the "to" filename, such that the "to" file is
3818 will always be a new version. It also sets the file protection once it is
3819 finished. The protection that we will use is stored in fab_final_pro,
3820 and was set when we did a creat_copy_attrs to create the file that we
3823 We could use the chmod function, but Eunichs uses 3 bits per user category
3824 to describe the protection, and VMS uses 4 (write and delete are seperate
3825 bits). To maintain portability, the VMS implementation of `chmod' wires
3826 the W and D bits together. */
3829 static struct fibdef fib
; /* We need this initialized to zero */
3830 char vms_file_written
[NAM$C_MAXRSS
];
3833 rename_sans_version (from
,to
)
3840 struct FAB to_fab
= cc$rms_fab
;
3841 struct NAM to_nam
= cc$rms_nam
;
3842 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
3843 struct dsc$descriptor fib_attr
[2]
3844 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
3845 char to_esn
[NAM$C_MAXRSS
];
3847 $
DESCRIPTOR (disk
,to_esn
);
3849 to_fab
.fab$l_fna
= to
;
3850 to_fab
.fab$b_fns
= strlen (to
);
3851 to_fab
.fab$l_nam
= &to_nam
;
3852 to_fab
.fab$l_fop
= FAB$M_NAM
;
3854 to_nam
.nam$l_esa
= to_esn
;
3855 to_nam
.nam$b_ess
= sizeof to_esn
;
3857 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
3859 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
3860 *(to_nam
.nam$l_ver
) = '\0';
3862 stat
= rename (from
, to_esn
);
3866 strcpy (vms_file_written
, to_esn
);
3868 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
3869 to_fab
.fab$b_fns
= strlen (vms_file_written
);
3871 /* Now set the file protection to the correct value */
3872 sys$
open (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
3874 /* Copy these fields into the fib */
3875 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
3876 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
3877 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
3879 sys$
close (&to_fab
, 0, 0);
3881 stat
= sys$
assign (&disk
, &chan
, 0, 0); /* open a channel to the disk */
3884 stat
= sys$
qiow (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
3885 0, 0, 0, &fib_attr
, 0);
3888 stat
= sys$
dassgn (chan
);
3891 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
3901 unsigned short fid
[3];
3902 char esa
[NAM$C_MAXRSS
];
3905 fab
.fab$l_fop
= FAB$M_OFP
;
3906 fab
.fab$l_fna
= file
;
3907 fab
.fab$b_fns
= strlen (file
);
3908 fab
.fab$l_nam
= &nam
;
3911 nam
.nam$l_esa
= esa
;
3912 nam
.nam$b_ess
= NAM$C_MAXRSS
;
3914 status
= SYS$
PARSE (&fab
);
3915 if ((status
& 1) == 0)
3918 vaxc$errno
= status
;
3921 status
= SYS$
SEARCH (&fab
);
3922 if ((status
& 1) == 0)
3925 vaxc$errno
= status
;
3929 fid
[0] = nam
.nam$w_fid
[0];
3930 fid
[1] = nam
.nam$w_fid
[1];
3931 fid
[2] = nam
.nam$w_fid
[2];
3933 fab
.fab$l_fna
= new;
3934 fab
.fab$b_fns
= strlen (new);
3936 status
= SYS$
PARSE (&fab
);
3937 if ((status
& 1) == 0)
3940 vaxc$errno
= status
;
3944 nam
.nam$w_fid
[0] = fid
[0];
3945 nam
.nam$w_fid
[1] = fid
[1];
3946 nam
.nam$w_fid
[2] = fid
[2];
3948 nam
.nam$l_esa
= nam
.nam$l_name
;
3949 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
3951 status
= SYS$
ENTER (&fab
);
3952 if ((status
& 1) == 0)
3955 vaxc$errno
= status
;
3965 printf ("%s not yet implemented\r\n", badfunc
);
3973 /* Arrange to return a range centered on zero. */
3974 return rand () - (1 << 30);
3985 /* Called from init_sys_modes. */
3990 /* If we're not on an HFT we shouldn't do any of this. We determine
3991 if we are on an HFT by trying to get an HFT error code. If this
3992 call fails, we're not on an HFT. */
3994 if (ioctl (0, HFQERROR
, &junk
) < 0)
3996 #else /* not IBMR2AIX */
3997 if (ioctl (0, HFQEIO
, 0) < 0)
3999 #endif /* not IBMR2AIX */
4001 /* On AIX the default hft keyboard mapping uses backspace rather than delete
4002 as the rubout key's ASCII code. Here this is changed. The bug is that
4003 there's no way to determine the old mapping, so in reset_sys_modes
4004 we need to assume that the normal map had been present. Of course, this
4005 code also doesn't help if on a terminal emulator which doesn't understand
4009 struct hfkeymap keymap
;
4011 buf
.hf_bufp
= (char *)&keymap
;
4012 buf
.hf_buflen
= sizeof (keymap
);
4013 keymap
.hf_nkeys
= 2;
4014 keymap
.hfkey
[0].hf_kpos
= 15;
4015 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4017 keymap
.hfkey
[0].hf_keyidh
= '<';
4018 #else /* not IBMR2AIX */
4019 keymap
.hfkey
[0].hf_page
= '<';
4020 #endif /* not IBMR2AIX */
4021 keymap
.hfkey
[0].hf_char
= 127;
4022 keymap
.hfkey
[1].hf_kpos
= 15;
4023 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4025 keymap
.hfkey
[1].hf_keyidh
= '<';
4026 #else /* not IBMR2AIX */
4027 keymap
.hfkey
[1].hf_page
= '<';
4028 #endif /* not IBMR2AIX */
4029 keymap
.hfkey
[1].hf_char
= 127;
4030 hftctl (0, HFSKBD
, &buf
);
4032 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
4034 line_ins_del_ok
= char_ins_del_ok
= 0;
4037 /* Reset the rubout key to backspace. */
4042 struct hfkeymap keymap
;
4046 if (ioctl (0, HFQERROR
, &junk
) < 0)
4048 #else /* not IBMR2AIX */
4049 if (ioctl (0, HFQEIO
, 0) < 0)
4051 #endif /* not IBMR2AIX */
4053 buf
.hf_bufp
= (char *)&keymap
;
4054 buf
.hf_buflen
= sizeof (keymap
);
4055 keymap
.hf_nkeys
= 2;
4056 keymap
.hfkey
[0].hf_kpos
= 15;
4057 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4059 keymap
.hfkey
[0].hf_keyidh
= '<';
4060 #else /* not IBMR2AIX */
4061 keymap
.hfkey
[0].hf_page
= '<';
4062 #endif /* not IBMR2AIX */
4063 keymap
.hfkey
[0].hf_char
= 8;
4064 keymap
.hfkey
[1].hf_kpos
= 15;
4065 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4067 keymap
.hfkey
[1].hf_keyidh
= '<';
4068 #else /* not IBMR2AIX */
4069 keymap
.hfkey
[1].hf_page
= '<';
4070 #endif /* not IBMR2AIX */
4071 keymap
.hfkey
[1].hf_char
= 8;
4072 hftctl (0, HFSKBD
, &buf
);