1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 86, 87, 88, 93, 94 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "blockinput.h"
29 #define min(x,y) ((x) > (y) ? (y) : (x))
31 /* In this file, open, read and write refer to the system calls,
32 not our sugared interfaces sys_open, sys_read and sys_write.
33 Contrariwise, for systems where we use the system calls directly,
34 define sys_read, etc. here as aliases for them. */
37 #define sys_write write
38 #endif /* `read' is not a macro */
44 #define sys_close close
51 #else /* `open' is a macro */
53 #endif /* `open' is a macro */
55 /* Does anyone other than VMS need this? */
57 #define sys_fwrite fwrite
67 #include <sys/types.h>
71 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
75 #include <sys/param.h>
100 #define MAXIOSIZE ( 32 * PAGESIZE ) /* Don't I/O more than 32 blocks at a time */
104 #ifdef BSD /* this is done this way to avoid defined (BSD) || defined (USG)
105 because the vms compiler doesn't grok `defined' */
113 #endif /* not 4.1 bsd */
116 #include <sys/ioctl.h>
121 #ifdef BROKEN_TIOCGWINSZ
127 #include <sys/utsname.h>
129 #ifndef MEMORY_IN_STRING_H
132 #if defined (TIOCGWINSZ) || defined (ISC4_0)
134 #include <sys/sioctl.h>
137 #include <sys/stream.h>
138 #include <sys/ptem.h>
140 #endif /* TIOCGWINSZ or ISC4_0 */
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"
164 #ifndef HAVE_STRUCT_UTIMBUF
165 /* We want to use utime rather than utimes, but we couldn't find the
166 structure declaration. We'll use the traditional one. */
174 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
180 #define LNOFLSH 0100000
183 static int baud_convert
[] =
188 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
189 1800, 2400, 4800, 9600, 19200, 38400
195 /* The file descriptor for Emacs's input terminal.
196 Under Unix, this is normally zero except when using X;
197 under VMS, we place the input channel number here. */
200 /* Specify a different file descriptor for further input operations. */
209 /* Discard pending input on descriptor input_fd. */
213 struct emacs_tty buf
;
218 /* Discarding input is not safe when the input could contain
219 replies from the X server. So don't do it. */
220 if (read_socket_hook
)
225 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
226 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
232 ioctl (input_fd
, TIOCFLUSH
, &zero
);
234 #else /* not Apollo */
235 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
236 while (dos_keyread () != -1)
238 #else /* not MSDOS */
239 EMACS_GET_TTY (input_fd
, &buf
);
240 EMACS_SET_TTY (input_fd
, &buf
, 0);
241 #endif /* not MSDOS */
242 #endif /* not Apollo */
248 /* Arrange for character C to be read as the next input from
254 /* Should perhaps error if in batch mode */
256 ioctl (input_fd
, TIOCSTI
, &c
);
257 #else /* no TIOCSTI */
258 error ("Cannot stuff terminal input characters in this version of Unix");
259 #endif /* no TIOCSTI */
276 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
277 &sg
.class, 12, 0, 0, 0, 0 );
278 ospeed
= sg
.xmit_baud
;
284 tcgetattr (input_fd
, &sg
);
285 ospeed
= cfgetospeed (&sg
);
286 #if defined (USE_GETOBAUD) && defined (getobaud)
287 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
289 ospeed
= getobaud (sg
.c_cflag
);
291 #else /* neither VMS nor TERMIOS */
297 tcgetattr (input_fd
, &sg
);
299 ioctl (input_fd
, TCGETA
, &sg
);
301 ospeed
= sg
.c_cflag
& CBAUD
;
302 #else /* neither VMS nor TERMIOS nor TERMIO */
305 sg
.sg_ospeed
= B9600
;
306 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
308 ospeed
= sg
.sg_ospeed
;
309 #endif /* not HAVE_TERMIO */
310 #endif /* not HAVE_TERMIOS */
312 #endif /* not MSDOS */
315 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
316 ? baud_convert
[ospeed
] : 9600);
322 set_exclusive_use (fd
)
326 ioctl (fd
, FIOCLEX
, 0);
328 /* Ok to do nothing if this feature does not exist */
333 wait_without_blocking ()
336 wait3 (0, WNOHANG
| WUNTRACED
, 0);
338 croak ("wait_without_blocking");
340 synch_process_alive
= 0;
343 #endif /* not subprocesses */
345 int wait_debugging
; /* Set nonzero to make following function work under dbx
346 (at least for bsd). */
349 wait_for_termination_signal ()
352 /* Wait for subprocess with process id `pid' to terminate and
353 make sure it will get eliminated (not remain forever as a zombie) */
355 wait_for_termination (pid
)
364 status
= SYS$
FORCEX (&pid
, 0, 0);
367 #if defined (BSD) || (defined (HPUX) && !defined (HPUX_5))
368 /* Note that kill returns -1 even if the process is just a zombie now.
369 But inevitably a SIGCHLD interrupt should be generated
370 and child_sig will do wait3 and make the process go away. */
371 /* There is some indication that there is a bug involved with
372 termination of subprocesses, perhaps involving a kernel bug too,
373 but no idea what it is. Just as a hunch we signal SIGCHLD to see
374 if that causes the problem to go away or get worse. */
375 sigsetmask (sigmask (SIGCHLD
));
376 if (0 > kill (pid
, 0))
378 sigsetmask (SIGEMPTYMASK
);
379 kill (getpid (), SIGCHLD
);
385 sigpause (SIGEMPTYMASK
);
386 #else /* not BSD, and not HPUX version >= 6 */
387 #if defined (UNIPLUS)
388 if (0 > kill (pid
, 0))
391 #else /* neither BSD nor UNIPLUS: random sysV */
392 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
393 sigblock (sigmask (SIGCHLD
));
394 if (0 > kill (pid
, 0))
396 sigunblock (sigmask (SIGCHLD
));
399 sigpause (SIGEMPTYMASK
);
400 #else /* not POSIX_SIGNALS */
401 #ifdef HAVE_SYSV_SIGPAUSE
403 if (0 > kill (pid
, 0))
409 #else /* not HAVE_SYSV_SIGPAUSE */
410 if (0 > kill (pid
, 0))
412 /* Using sleep instead of pause avoids timing error.
413 If the inferior dies just before the sleep,
414 we lose just one second. */
416 #endif /* not HAVE_SYSV_SIGPAUSE */
417 #endif /* not POSIX_SIGNALS */
418 #endif /* not UNIPLUS */
419 #endif /* not BSD, and not HPUX version >= 6 */
421 #else /* not subprocesses */
423 if (kill (pid
, 0) < 0)
429 if (status
== pid
|| status
== -1)
432 #endif /* not subprocesses */
439 * flush any pending output
440 * (may flush input as well; it does not matter the way we use it)
443 flush_pending_output (channel
)
447 /* If we try this, we get hit with SIGTTIN, because
448 the child's tty belongs to the child's pgrp. */
451 ioctl (channel
, TCFLSH
, 1);
455 /* 3rd arg should be ignored
456 but some 4.2 kernels actually want the address of an int
457 and nonzero means something different. */
458 ioctl (channel
, TIOCFLUSH
, &zero
);
465 /* Set up the terminal at the other end of a pseudo-terminal that
466 we will be controlling an inferior through.
467 It should not echo or do line-editing, since that is done
468 in Emacs. No padding needed for insertion into an Emacs buffer. */
470 child_setup_tty (out
)
476 EMACS_GET_TTY (out
, &s
);
478 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
479 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
480 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
482 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
483 /* No output delays */
485 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
486 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
488 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
491 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
493 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
495 /* Said to be unnecessary: */
496 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
497 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
500 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
501 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
502 s
.main
.c_cc
[VERASE
] = 0377; /* disable erase processing */
503 s
.main
.c_cc
[VKILL
] = 0377; /* disable kill processing */
506 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
510 /* AIX enhanced edit loses NULs, so disable it */
513 s
.main
.c_iflag
&= ~ASCEDIT
;
515 /* Also, PTY overloads NUL and BREAK.
516 don't ignore break, but don't signal either, so it looks like NUL. */
517 s
.main
.c_iflag
&= ~IGNBRK
;
518 s
.main
.c_iflag
&= ~BRKINT
;
519 /* QUIT and INTR work better as signals, so disable character forms */
520 s
.main
.c_cc
[VINTR
] = 0377;
521 #ifdef SIGNALS_VIA_CHARACTERS
522 /* the QUIT and INTR character are used in process_send_signal
523 so set them here to something useful. */
524 if (s
.main
.c_cc
[VQUIT
] == 0377)
525 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
526 if (s
.main
.c_cc
[VINTR
] == 0377)
527 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
528 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
529 /* QUIT and INTR work better as signals, so disable character forms */
530 s
.main
.c_cc
[VQUIT
] = 0377;
531 s
.main
.c_cc
[VINTR
] = 0377;
532 s
.main
.c_lflag
&= ~ISIG
;
533 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
534 s
.main
.c_cc
[VEOL
] = 0377;
535 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
538 #else /* not HAVE_TERMIO */
540 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
542 s
.main
.sg_flags
|= LPASS8
;
543 s
.main
.sg_erase
= 0377;
544 s
.main
.sg_kill
= 0377;
545 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
547 #endif /* not HAVE_TERMIO */
549 EMACS_SET_TTY (out
, &s
, 0);
558 ioctl (out
, FIOASYNC
, &zero
);
561 #endif /* not MSDOS */
565 #endif /* subprocesses */
571 EMACS_SET_TTY_PGRP (input_fd
, &pid
);
574 /* Record a signal code and the handler for it. */
578 SIGTYPE (*handler
) ();
581 /* Suspend the Emacs process; give terminal to its superior. */
586 /* "Foster" parentage allows emacs to return to a subprocess that attached
587 to the current emacs as a cheaper than starting a whole new process. This
588 is set up by KEPTEDITOR.COM. */
589 unsigned long parent_id
, foster_parent_id
;
592 fpid_string
= getenv ("EMACS_PARENT_PID");
593 if (fpid_string
!= NULL
)
595 sscanf (fpid_string
, "%x", &foster_parent_id
);
596 if (foster_parent_id
!= 0)
597 parent_id
= foster_parent_id
;
599 parent_id
= getppid ();
602 parent_id
= getppid ();
604 xfree (fpid_string
); /* On VMS, this was malloc'd */
606 if (parent_id
&& parent_id
!= 0xffffffff)
608 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
609 int status
= LIB$
ATTACH (&parent_id
) & 1;
610 signal (SIGINT
, oldsig
);
619 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
620 d_prompt
.a
= "Emacs: "; /* Just a reminder */
621 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
626 #if defined(SIGTSTP) && !defined(MSDOS)
629 int pgrp
= EMACS_GETPGRP (0);
630 EMACS_KILLPG (pgrp
, SIGTSTP
);
633 #else /* No SIGTSTP */
634 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
635 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
636 kill (getpid (), SIGQUIT
);
638 #else /* No SIGTSTP or USG_JOBCTRL */
640 /* On a system where suspending is not implemented,
641 instead fork a subshell and let it talk directly to the terminal
645 #endif /* no USG_JOBCTRL */
646 #endif /* no SIGTSTP */
650 /* Fork a subshell. */
655 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
657 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
660 struct save_signal saved_handlers
[5];
662 unsigned char *str
= 0;
665 saved_handlers
[0].code
= SIGINT
;
666 saved_handlers
[1].code
= SIGQUIT
;
667 saved_handlers
[2].code
= SIGTERM
;
669 saved_handlers
[3].code
= SIGIO
;
670 saved_handlers
[4].code
= 0;
672 saved_handlers
[3].code
= 0;
675 /* Mentioning current_buffer->buffer would mean including buffer.h,
676 which somehow wedges the hp compiler. So instead... */
678 dir
= intern ("default-directory");
679 if (NILP (Fboundp (dir
)))
681 dir
= Fsymbol_value (dir
);
685 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
686 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
687 len
= XSTRING (dir
)->size
;
688 bcopy (XSTRING (dir
)->data
, str
, len
);
689 if (str
[len
- 1] != '/') str
[len
++] = '/';
696 error ("Can't spawn subshell");
701 #ifdef MSDOS /* MW, Aug 1993 */
704 sh
= (char *) egetenv ("SHELL");
708 /* Use our buffer's default directory for the subshell. */
713 close_process_descs (); /* Close Emacs's pipes/ptys */
716 #ifdef SET_EMACS_PRIORITY
718 extern int emacs_priority
;
720 if (emacs_priority
< 0)
721 nice (-emacs_priority
);
725 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
729 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
730 #else /* not MSDOS */
732 write (1, "Can't execute subshell", 22);
734 #endif /* not MSDOS */
737 save_signal_handlers (saved_handlers
);
738 synch_process_alive
= 1;
739 wait_for_termination (pid
);
740 restore_signal_handlers (saved_handlers
);
744 save_signal_handlers (saved_handlers
)
745 struct save_signal
*saved_handlers
;
747 while (saved_handlers
->code
)
749 saved_handlers
->handler
750 = (SIGTYPE (*) ()) signal (saved_handlers
->code
, SIG_IGN
);
755 restore_signal_handlers (saved_handlers
)
756 struct save_signal
*saved_handlers
;
758 while (saved_handlers
->code
)
760 signal (saved_handlers
->code
, saved_handlers
->handler
);
772 old_fcntl_flags
= fcntl (input_fd
, F_GETFL
, 0) & ~FASYNC
;
782 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
787 sigunblock (sigmask (SIGWINCH
));
789 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
791 interrupts_deferred
= 0;
797 sigblock (sigmask (SIGWINCH
));
799 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
800 interrupts_deferred
= 1;
803 #else /* no FASYNC */
804 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
809 ioctl (input_fd
, FIOASYNC
, &on
);
810 interrupts_deferred
= 0;
817 ioctl (input_fd
, FIOASYNC
, &off
);
818 interrupts_deferred
= 1;
821 #else /* not FASYNC, not STRIDE */
833 sigaddset(&st
, SIGIO
);
834 ioctl (input_fd
, FIOASYNC
, &on
);
835 interrupts_deferred
= 0;
836 sigprocmask(SIG_UNBLOCK
, &st
, (sigset_t
*)0);
843 ioctl (input_fd
, FIOASYNC
, &off
);
844 interrupts_deferred
= 1;
851 croak ("request_sigio");
856 croak ("unrequest_sigio");
864 /* Saving and restoring the process group of Emacs's terminal. */
868 /* The process group of which Emacs was a member when it initially
871 If Emacs was in its own process group (i.e. inherited_pgroup ==
872 getpid ()), then we know we're running under a shell with job
873 control (Emacs would never be run as part of a pipeline).
876 If Emacs was not in its own process group, then we know we're
877 running under a shell (or a caller) that doesn't know how to
878 separate itself from Emacs (like sh). Emacs must be in its own
879 process group in order to receive SIGIO correctly. In this
880 situation, we put ourselves in our own pgroup, forcibly set the
881 tty's pgroup to our pgroup, and make sure to restore and reinstate
882 the tty's pgroup just like any other terminal setting. If
883 inherited_group was not the tty's pgroup, then we'll get a
884 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
885 it goes foreground in the future, which is what should happen. */
886 int inherited_pgroup
;
888 /* Split off the foreground process group to Emacs alone.
889 When we are in the foreground, but not started in our own process
890 group, redirect the TTY to point to our own process group. We need
891 to be in our own process group to receive SIGIO properly. */
892 narrow_foreground_group ()
896 setpgrp (0, inherited_pgroup
);
897 if (inherited_pgroup
!= me
)
898 EMACS_SET_TTY_PGRP (input_fd
, &me
);
902 /* Set the tty to our original foreground group. */
903 widen_foreground_group ()
905 if (inherited_pgroup
!= getpid ())
906 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
907 setpgrp (0, inherited_pgroup
);
910 #endif /* BSD_PGRPS */
912 /* Getting and setting emacs_tty structures. */
914 /* Set *TC to the parameters associated with the terminal FD.
915 Return zero if all's well, or -1 if we ran into an error we
916 couldn't deal with. */
918 emacs_get_tty (fd
, settings
)
920 struct emacs_tty
*settings
;
922 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
924 /* We have those nifty POSIX tcmumbleattr functions. */
925 if (tcgetattr (fd
, &settings
->main
) < 0)
930 /* The SYSV-style interface? */
931 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
936 /* Vehemently Monstrous System? :-) */
937 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
938 &settings
->main
.class, 12, 0, 0, 0, 0)
944 /* I give up - I hope you have the BSD ioctls. */
945 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
947 #endif /* not MSDOS */
952 /* Suivant - Do we have to get struct ltchars data? */
954 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
958 /* How about a struct tchars and a wordful of lmode bits? */
960 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
961 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
965 /* We have survived the tempest. */
970 /* Set the parameters of the tty on FD according to the contents of
971 *SETTINGS. If WAITP is non-zero, we wait for all queued output to
972 be written before making the change; otherwise, we forget any
973 queued input and make the change immediately.
974 Return 0 if all went well, and -1 if anything failed. */
976 emacs_set_tty (fd
, settings
, waitp
)
978 struct emacs_tty
*settings
;
981 /* Set the primary parameters - baud rate, character size, etcetera. */
984 /* We have those nifty POSIX tcmumbleattr functions.
985 William J. Smith <wjs@wiis.wang.com> writes:
986 "POSIX 1003.1 defines tcsetattr() to return success if it was
987 able to perform any of the requested actions, even if some
988 of the requested actions could not be performed.
989 We must read settings back to ensure tty setup properly.
990 AIX requires this to keep tty from hanging occasionally." */
991 /* This make sure that we don't loop indefinitely in here. */
992 for (i
= 0 ; i
< 10 ; i
++)
993 if (tcsetattr (fd
, waitp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1004 /* Get the current settings, and see if they're what we asked for. */
1005 tcgetattr (fd
, &new);
1006 /* We cannot use memcmp on the whole structure here because under
1007 * aix386 the termios structure has some reserved field that may
1010 if ( new.c_iflag
== settings
->main
.c_iflag
1011 && new.c_oflag
== settings
->main
.c_oflag
1012 && new.c_cflag
== settings
->main
.c_cflag
1013 && new.c_lflag
== settings
->main
.c_lflag
1014 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1022 /* The SYSV-style interface? */
1023 if (ioctl (fd
, waitp
? TCSETAW
: TCSETAF
, &settings
->main
) < 0)
1028 /* Vehemently Monstrous System? :-) */
1029 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1030 &settings
->main
.class, 12, 0, 0, 0, 0)
1036 /* I give up - I hope you have the BSD ioctls. */
1037 if (ioctl (fd
, (waitp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1039 #endif /* not MSDOS */
1045 /* Suivant - Do we have to get struct ltchars data? */
1047 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1051 /* How about a struct tchars and a wordful of lmode bits? */
1053 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1054 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1058 /* We have survived the tempest. */
1063 /* The initial tty mode bits */
1064 struct emacs_tty old_tty
;
1066 int term_initted
; /* 1 if outer tty status has been recorded */
1069 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1074 #ifndef F_SETOWN_BUG
1076 int old_fcntl_owner
;
1077 #endif /* F_SETOWN */
1078 #endif /* F_SETOWN_BUG */
1080 /* This may also be defined in stdio,
1081 but if so, this does no harm,
1082 and using the same name avoids wasting the other one's space. */
1084 #if defined (USG) || defined (DGUX)
1085 unsigned char _sobuf
[BUFSIZ
+8];
1087 char _sobuf
[BUFSIZ
];
1091 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1094 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1099 struct emacs_tty tty
;
1103 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1104 extern int (*interrupt_signal
) ();
1113 input_ef
= get_kbd_event_flag ();
1114 /* LIB$GET_EF (&input_ef); */
1115 SYS$
CLREF (input_ef
);
1116 waiting_for_ast
= 0;
1118 timer_ef
= get_timer_event_flag ();
1119 /* LIB$GET_EF (&timer_ef); */
1120 SYS$
CLREF (timer_ef
);
1124 LIB$
GET_EF (&process_ef
);
1125 SYS$
CLREF (process_ef
);
1127 if (input_ef
/ 32 != process_ef
/ 32)
1128 croak ("Input and process event flags in different clusters.");
1130 if (input_ef
/ 32 != timer_ef
/ 32)
1131 croak ("Input and timer event flags in different clusters.");
1133 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1134 ((unsigned) 1 << (process_ef
% 32));
1136 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1137 ((unsigned) 1 << (timer_ef
% 32));
1139 sys_access_reinit ();
1141 #endif /* not VMS */
1144 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1145 narrow_foreground_group ();
1148 EMACS_GET_TTY (input_fd
, &old_tty
);
1150 #ifdef HAVE_X_WINDOWS
1151 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1152 needs the initialization code below. */
1153 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1158 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1160 /* This allows meta to be sent on 8th bit. */
1161 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1163 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1164 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1166 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1168 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1169 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1171 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1173 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1176 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1178 tty
.main
.c_iflag
&= ~IXANY
;
1182 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1183 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1185 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1189 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1190 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1193 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1194 /* Set up C-g for both SIGQUIT and SIGINT.
1195 We don't know which we will get, but we handle both alike
1196 so which one it really gives us does not matter. */
1197 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1198 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1199 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1201 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1204 #if defined (mips) || defined (HAVE_TCATTR)
1206 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1209 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1210 #endif /* V_DSUSP */
1211 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1212 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1215 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1218 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1219 #endif /* VREPRINT */
1221 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1222 #endif /* VWERASE */
1224 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1225 #endif /* VDISCARD */
1227 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1230 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1232 #endif /* mips or HAVE_TCATTR */
1235 /* AIX enhanced edit loses NULs, so disable it */
1236 tty
.main
.c_line
= 0;
1237 tty
.main
.c_iflag
&= ~ASCEDIT
;
1239 tty
.main
.c_cc
[VSTRT
] = 255;
1240 tty
.main
.c_cc
[VSTOP
] = 255;
1241 tty
.main
.c_cc
[VSUSP
] = 255;
1242 tty
.main
.c_cc
[VDSUSP
] = 255;
1243 #endif /* IBMR2AIX */
1244 /* Also, PTY overloads NUL and BREAK.
1245 don't ignore break, but don't signal either, so it looks like NUL.
1246 This really serves a purpose only if running in an XTERM window
1247 or via TELNET or the like, but does no harm elsewhere. */
1248 tty
.main
.c_iflag
&= ~IGNBRK
;
1249 tty
.main
.c_iflag
&= ~BRKINT
;
1251 #else /* if not HAVE_TERMIO */
1253 tty
.main
.tt_char
|= TT$M_NOECHO
;
1255 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1257 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1259 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1260 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1261 #else /* not VMS (BSD, that is) */
1263 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1265 tty
.main
.sg_flags
|= ANYP
;
1266 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1268 #endif /* not VMS (BSD, that is) */
1269 #endif /* not HAVE_TERMIO */
1271 /* If going to use CBREAK mode, we must request C-g to interrupt
1272 and turn off start and stop chars, etc. If not going to use
1273 CBREAK mode, do this anyway so as to turn off local flow
1274 control for user coming over network on 4.2; in this case,
1275 only t_stopc and t_startc really matter. */
1278 /* Note: if not using CBREAK mode, it makes no difference how we
1280 tty
.tchars
= new_tchars
;
1281 tty
.tchars
.t_intrc
= quit_char
;
1284 tty
.tchars
.t_startc
= '\021';
1285 tty
.tchars
.t_stopc
= '\023';
1288 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1290 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1291 anything, and leaving it in breaks the meta key. Go figure. */
1292 tty
.lmode
&= ~LLITOUT
;
1299 #endif /* HAVE_TCHARS */
1300 #endif /* not HAVE_TERMIO */
1303 tty
.ltchars
= new_ltchars
;
1304 #endif /* HAVE_LTCHARS */
1305 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1307 internal_terminal_init ();
1311 EMACS_SET_TTY (input_fd
, &tty
, 0);
1313 /* This code added to insure that, if flow-control is not to be used,
1314 we have an unlocked terminal at the start. */
1317 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1321 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1329 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1330 to be only LF. This is the way that is done. */
1333 if (ioctl (1, HFTGETID
, &tty
) != -1)
1334 write (1, "\033[20l", 5);
1340 /* Appears to do nothing when in PASTHRU mode.
1341 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1342 interrupt_signal, oob_chars, 0, 0, 0, 0);
1344 queue_kbd_input (0);
1349 #ifndef F_SETOWN_BUG
1350 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1352 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1354 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1355 fcntl (input_fd
, F_SETOWN
, getpid ());
1358 #endif /* F_GETOWN */
1359 #endif /* F_SETOWN_BUG */
1360 #endif /* F_SETFL */
1363 if (interrupt_input
)
1367 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1371 /* This symbol is defined on recent USG systems.
1372 Someone says without this call USG won't really buffer the file
1373 even with a call to setbuf. */
1374 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
1376 setbuf (stdout
, _sobuf
);
1378 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1379 set_terminal_modes ();
1381 if (term_initted
&& no_redraw_on_reenter
)
1383 if (display_completed
)
1384 direct_output_forward_char (0);
1390 if (FRAMEP (Vterminal_frame
))
1391 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1398 /* Return nonzero if safe to use tabs in output.
1399 At the time this is called, init_sys_modes has not been done yet. */
1403 struct emacs_tty tty
;
1405 EMACS_GET_TTY (input_fd
, &tty
);
1406 return EMACS_TTY_TABS_OK (&tty
);
1409 /* Get terminal size from system.
1410 Store number of lines into *HEIGHTP and width into *WIDTHP.
1411 We store 0 if there's no valid information. */
1413 get_frame_size (widthp
, heightp
)
1414 int *widthp
, *heightp
;
1420 struct winsize size
;
1422 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1423 *widthp
= *heightp
= 0;
1426 *widthp
= size
.ws_col
;
1427 *heightp
= size
.ws_row
;
1433 /* SunOS - style. */
1434 struct ttysize size
;
1436 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1437 *widthp
= *heightp
= 0;
1440 *widthp
= size
.ts_cols
;
1441 *heightp
= size
.ts_lines
;
1447 struct sensemode tty
;
1449 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1450 &tty
.class, 12, 0, 0, 0, 0);
1451 *widthp
= tty
.scr_wid
;
1452 *heightp
= tty
.scr_len
;
1456 *widthp
= ScreenCols ();
1457 *heightp
= ScreenRows ();
1458 #else /* system doesn't know size */
1463 #endif /* not VMS */
1464 #endif /* not SunOS-style */
1465 #endif /* not BSD-style */
1468 /* Set the logical window size associated with descriptor FD
1469 to HEIGHT and WIDTH. This is used mainly with ptys. */
1472 set_window_size (fd
, height
, width
)
1473 int fd
, height
, width
;
1478 struct winsize size
;
1479 size
.ws_row
= height
;
1480 size
.ws_col
= width
;
1482 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1483 return 0; /* error */
1490 /* SunOS - style. */
1491 struct ttysize size
;
1492 size
.ts_lines
= height
;
1493 size
.ts_cols
= width
;
1495 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1501 #endif /* not SunOS-style */
1502 #endif /* not BSD-style */
1506 /* Prepare the terminal for exiting Emacs; move the cursor to the
1507 bottom of the frame, turn off interrupt-driven I/O, etc. */
1517 #ifdef HAVE_X_WINDOWS
1518 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1519 needs the clean-up code below. */
1520 if (read_socket_hook
|| !EQ (Vwindow_system
, Qnil
))
1523 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1525 if (!EQ (Vwindow_system
, Qnil
))
1527 /* Change to grey on white. */
1533 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1534 /* clear_end_of_line may move the cursor */
1535 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1538 /* HFT devices normally use ^J as a LF/CR. We forced it to
1539 do the LF only. Now, we need to reset it. */
1542 if (ioctl (1, HFTGETID
, &tty
) != -1)
1543 write (1, "\033[20h", 5);
1547 reset_terminal_modes ();
1551 /* Avoid possible loss of output when changing terminal modes. */
1552 fsync (fileno (stdout
));
1557 #ifndef F_SETOWN_BUG
1558 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1559 if (interrupt_input
)
1562 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1564 #endif /* F_SETOWN */
1565 #endif /* F_SETOWN_BUG */
1567 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1569 #endif /* F_SETFL */
1571 if (interrupt_input
)
1575 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1578 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1587 widen_foreground_group ();
1593 /* Set up the proper status flags for use of a pty. */
1598 /* I'm told that TOICREMOTE does not mean control chars
1599 "can't be sent" but rather that they don't have
1600 input-editing or signaling effects.
1601 That should be good, because we have other ways
1602 to do those things in Emacs.
1603 However, telnet mode seems not to work on 4.2.
1604 So TIOCREMOTE is turned off now. */
1606 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1607 will hang. In particular, the "timeout" feature (which
1608 causes a read to return if there is no data available)
1609 does this. Also it is known that telnet mode will hang
1610 in such a way that Emacs must be stopped (perhaps this
1611 is the same problem).
1613 If TIOCREMOTE is turned off, then there is a bug in
1614 hp-ux which sometimes loses data. Apparently the
1615 code which blocks the master process when the internal
1616 buffer fills up does not work. Other than this,
1617 though, everything else seems to work fine.
1619 Since the latter lossage is more benign, we may as well
1620 lose that way. -- cph */
1625 ioctl (fd
, FIONBIO
, &on
);
1630 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1631 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1632 /* cause EMACS not to die when it should, i.e., when its own controlling */
1633 /* tty goes away. I've complained to the AIX developers, and they may */
1634 /* change this behavior, but I'm not going to hold my breath. */
1635 signal (SIGHUP
, SIG_IGN
);
1638 #endif /* HAVE_PTYS */
1642 /* Assigning an input channel is done at the start of Emacs execution.
1643 This is called each time Emacs is resumed, also, but does nothing
1644 because input_chain is no longer zero. */
1652 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1658 /* Deassigning the input channel is done before exiting. */
1662 return SYS$
DASSGN (input_fd
);
1667 /* Request reading one character into the keyboard buffer.
1668 This is done as soon as the buffer becomes empty. */
1673 extern kbd_input_ast ();
1675 waiting_for_ast
= 0;
1677 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1678 &input_iosb
, kbd_input_ast
, 1,
1679 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1684 /* Ast routine that is called when keyboard input comes in
1685 in accord with the SYS$QIO above. */
1689 register int c
= -1;
1690 int old_errno
= errno
;
1691 extern EMACS_TIME
*input_available_clear_time
;
1693 if (waiting_for_ast
)
1694 SYS$
SETEF (input_ef
);
1695 waiting_for_ast
= 0;
1698 if (input_count
== 25)
1700 printf ("Ast # %d,", input_count
);
1701 printf (" iosb = %x, %x, %x, %x",
1702 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1705 if (input_iosb
.offset
)
1709 printf (", char = 0%o", c
);
1721 struct input_event e
;
1722 e
.kind
= ascii_keystroke
;
1723 XSETINT (e
.code
, c
);
1724 XSETFRAME (e
.frame_or_window
, selected_frame
);
1725 kbd_buffer_store_event (&e
);
1727 if (input_available_clear_time
)
1728 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1732 /* Wait until there is something in kbd_buffer. */
1734 wait_for_kbd_input ()
1736 extern int have_process_input
, process_exited
;
1738 /* If already something, avoid doing system calls. */
1739 if (detect_input_pending ())
1743 /* Clear a flag, and tell ast routine above to set it. */
1744 SYS$
CLREF (input_ef
);
1745 waiting_for_ast
= 1;
1746 /* Check for timing error: ast happened while we were doing that. */
1747 if (!detect_input_pending ())
1749 /* No timing error: wait for flag to be set. */
1750 set_waiting_for_input (0);
1751 SYS$
WFLOR (input_ef
, input_eflist
);
1752 clear_waiting_for_input (0);
1753 if (!detect_input_pending ())
1754 /* Check for subprocess input availability */
1756 int dsp
= have_process_input
|| process_exited
;
1758 SYS$
CLREF (process_ef
);
1759 if (have_process_input
)
1760 process_command_input ();
1765 update_mode_lines
++;
1766 prepare_menu_bars ();
1767 redisplay_preserve_echo_area ();
1771 waiting_for_ast
= 0;
1774 /* Get rid of any pending QIO, when we are about to suspend
1775 or when we want to throw away pending input.
1776 We wait for a positive sign that the AST routine has run
1777 and therefore there is no I/O request queued when we return.
1778 SYS$SETAST is used to avoid a timing error. */
1783 printf ("At end_kbd_input.\n");
1787 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
1789 SYS$
CANCEL (input_fd
);
1794 /* Clear a flag, and tell ast routine above to set it. */
1795 SYS$
CLREF (input_ef
);
1796 waiting_for_ast
= 1;
1798 SYS$
CANCEL (input_fd
);
1800 SYS$
WAITFR (input_ef
);
1801 waiting_for_ast
= 0;
1804 /* Wait for either input available or time interval expiry. */
1806 input_wait_timeout (timeval
)
1807 int timeval
; /* Time to wait, in seconds */
1810 static int zero
= 0;
1811 static int large
= -10000000;
1813 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1815 /* If already something, avoid doing system calls. */
1816 if (detect_input_pending ())
1820 /* Clear a flag, and tell ast routine above to set it. */
1821 SYS$
CLREF (input_ef
);
1822 waiting_for_ast
= 1;
1823 /* Check for timing error: ast happened while we were doing that. */
1824 if (!detect_input_pending ())
1826 /* No timing error: wait for flag to be set. */
1828 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1829 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
1831 waiting_for_ast
= 0;
1834 /* The standard `sleep' routine works some other way
1835 and it stops working if you have ever quit out of it.
1836 This one continues to work. */
1842 static int zero
= 0;
1843 static int large
= -10000000;
1845 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1848 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1849 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
1864 croak ("request sigio");
1869 croak ("unrequest sigio");
1874 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
1879 #ifndef SYSTEM_MALLOC
1886 /* Some systems that cannot dump also cannot implement these. */
1889 * Return the address of the start of the text segment prior to
1890 * doing an unexec. After unexec the return value is undefined.
1891 * See crt0.c for further explanation and _start.
1895 #ifndef HAVE_TEXT_START
1900 return ((char *) TEXT_START
);
1904 return ((char *) csrt
);
1905 #else /* not GOULD */
1906 extern int _start ();
1907 return ((char *) _start
);
1909 #endif /* TEXT_START */
1911 #endif /* not HAVE_TEXT_START */
1914 * Return the address of the start of the data segment prior to
1915 * doing an unexec. After unexec the return value is undefined.
1916 * See crt0.c for further information and definition of data_start.
1918 * Apparently, on BSD systems this is etext at startup. On
1919 * USG systems (swapping) this is highly mmu dependent and
1920 * is also dependent on whether or not the program is running
1921 * with shared text. Generally there is a (possibly large)
1922 * gap between end of text and start of data with shared text.
1924 * On Uniplus+ systems with shared text, data starts at a
1925 * fixed address. Each port (from a given oem) is generally
1926 * different, and the specific value of the start of data can
1927 * be obtained via the UniPlus+ specific "uvar" system call,
1928 * however the method outlined in crt0.c seems to be more portable.
1930 * Probably what will have to happen when a USG unexec is available,
1931 * at least on UniPlus, is temacs will have to be made unshared so
1932 * that text and data are contiguous. Then once loadup is complete,
1933 * unexec will produce a shared executable where the data can be
1934 * at the normal shared text boundry and the startofdata variable
1935 * will be patched by unexec to the correct value.
1943 return ((char *) DATA_START
);
1945 #ifdef ORDINARY_LINK
1947 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
1948 * data_start isn't defined. We take the address of environ, which
1949 * is known to live at or near the start of the system crt0.c, and
1950 * we don't sweat the handful of bytes that might lose.
1952 extern char **environ
;
1954 return((char *) &environ
);
1956 extern int data_start
;
1957 return ((char *) &data_start
);
1958 #endif /* ORDINARY_LINK */
1959 #endif /* DATA_START */
1961 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
1964 /* Some systems that cannot dump also cannot implement these. */
1967 * Return the address of the end of the text segment prior to
1968 * doing an unexec. After unexec the return value is undefined.
1975 return ((char *) TEXT_END
);
1978 return ((char *) &etext
);
1983 * Return the address of the end of the data segment prior to
1984 * doing an unexec. After unexec the return value is undefined.
1991 return ((char *) DATA_END
);
1994 return ((char *) &edata
);
1998 #endif /* not CANNOT_DUMP */
2000 /* init_system_name sets up the string for the Lisp function
2001 system-name to return. */
2007 extern Lisp_Object Vsystem_name
;
2012 #include <sys/socket.h>
2014 #endif /* HAVE_SOCKETS */
2015 #endif /* not VMS */
2016 #endif /* not BSD4_1 */
2022 Vsystem_name
= build_string (sysname
);
2026 if ((sp
= egetenv ("SYS$NODE")) == 0)
2027 Vsystem_name
= build_string ("vax-vms");
2028 else if ((end
= index (sp
, ':')) == 0)
2029 Vsystem_name
= build_string (sp
);
2031 Vsystem_name
= make_string (sp
, end
- sp
);
2033 #ifndef HAVE_GETHOSTNAME
2036 Vsystem_name
= build_string (uts
.nodename
);
2037 #else /* HAVE_GETHOSTNAME */
2038 int hostname_size
= 256;
2039 char *hostname
= (char *) alloca (hostname_size
);
2041 /* Try to get the host name; if the buffer is too short, try
2042 again. Apparently, the only indication gethostname gives of
2043 whether the buffer was large enough is the presence or absence
2044 of a '\0' in the string. Eech. */
2047 gethostname (hostname
, hostname_size
- 1);
2048 hostname
[hostname_size
- 1] = '\0';
2050 /* Was the buffer large enough for the '\0'? */
2051 if (strlen (hostname
) < hostname_size
- 1)
2054 hostname_size
<<= 1;
2055 hostname
= (char *) alloca (hostname_size
);
2058 /* Turn the hostname into the official, fully-qualified hostname.
2059 Don't do this if we're going to dump; this can confuse system
2060 libraries on some machines and make the dumped emacs core dump. */
2063 #endif /* not CANNOT_DUMP */
2067 for (count
= 0; count
< 10; count
++)
2072 hp
= gethostbyname (hostname
);
2074 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2077 Fsleep_for (make_number (1), Qnil
);
2081 char *fqdn
= hp
->h_name
;
2084 if (!index (fqdn
, '.'))
2086 /* We still don't have a fully qualified domain name.
2087 Try to find one in the list of alternate names */
2088 char **alias
= hp
->h_aliases
;
2089 while (*alias
&& !index (*alias
, '.'))
2096 /* Convert the host name to lower case. */
2097 /* Using ctype.h here would introduce a possible locale
2098 dependence that is probably wrong for hostnames. */
2102 if (*p
>= 'A' && *p
<= 'Z')
2109 #endif /* HAVE_SOCKETS */
2110 Vsystem_name
= build_string (hostname
);
2111 #endif /* HAVE_GETHOSTNAME */
2116 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2117 if (*p
== ' ' || *p
== '\t')
2125 #ifdef HAVE_X_WINDOWS
2126 /* Cause explanatory error message at compile time,
2127 since the select emulation is not good enough for X. */
2128 int *x
= &x_windows_lose_if_no_select_system_call
;
2131 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2132 * Only checks read descriptors.
2134 /* How long to wait between checking fds in select */
2135 #define SELECT_PAUSE 1
2138 /* For longjmp'ing back to read_input_waiting. */
2140 jmp_buf read_alarm_throw
;
2142 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2143 The read_socket_hook function sets this to 1 while it is waiting. */
2145 int read_alarm_should_throw
;
2153 #else /* not BSD4_1 */
2154 signal (SIGALRM
, SIG_IGN
);
2155 #endif /* not BSD4_1 */
2156 if (read_alarm_should_throw
)
2157 longjmp (read_alarm_throw
, 1);
2160 /* Only rfds are checked. */
2162 select (nfds
, rfds
, wfds
, efds
, timeout
)
2164 int *rfds
, *wfds
, *efds
, *timeout
;
2166 int ravail
= 0, orfds
= 0, old_alarm
;
2167 int timeoutval
= timeout
? *timeout
: 100000;
2168 int *local_timeout
= &timeoutval
;
2169 extern int proc_buffered_char
[];
2170 #ifndef subprocesses
2171 int process_tick
= 0, update_tick
= 0;
2173 extern int process_tick
, update_tick
;
2175 SIGTYPE (*old_trap
) ();
2188 /* If we are looking only for the terminal, with no timeout,
2189 just read it and wait -- that's more efficient. */
2190 if (orfds
== 1 && *local_timeout
== 100000 && process_tick
== update_tick
)
2192 if (! detect_input_pending ())
2193 read_input_waiting ();
2198 /* Once a second, till the timer expires, check all the flagged read
2199 * descriptors to see if any input is available. If there is some then
2200 * set the corresponding bit in the return copy of rfds.
2204 register int to_check
, bit
, fd
;
2208 for (to_check
= nfds
, bit
= 1, fd
= 0; --to_check
>= 0; bit
<<= 1, fd
++)
2212 int avail
= 0, status
= 0;
2215 avail
= detect_input_pending (); /* Special keyboard handler */
2219 status
= ioctl (fd
, FIONREAD
, &avail
);
2220 #else /* no FIONREAD */
2222 abort (); /* I don't think we need it. */
2223 #else /* not MSDOS */
2224 /* Hoping it will return -1 if nothing available
2225 or 0 if all 0 chars requested are read. */
2226 if (proc_buffered_char
[fd
] >= 0)
2230 avail
= read (fd
, &buf
, 1);
2232 proc_buffered_char
[fd
] = buf
;
2234 #endif /* not MSDOS */
2235 #endif /* no FIONREAD */
2237 if (status
>= 0 && avail
> 0)
2245 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2247 old_alarm
= alarm (0);
2248 old_trap
= signal (SIGALRM
, select_alarm
);
2250 alarm (SELECT_PAUSE
);
2251 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2252 while (select_alarmed
== 0 && *local_timeout
!= 0
2253 && process_tick
== update_tick
)
2256 sleep_or_kbd_hit (SELECT_PAUSE
, (orfds
& 1) != 0);
2258 #else /* not MSDOS */
2259 /* If we are interested in terminal input,
2260 wait by reading the terminal.
2261 That makes instant wakeup for terminal input at least. */
2264 read_input_waiting ();
2265 if (detect_input_pending ())
2270 #endif /* not MSDOS */
2272 (*local_timeout
) -= SELECT_PAUSE
;
2273 /* Reset the old alarm if there was one */
2275 signal (SIGALRM
, old_trap
);
2278 /* Reset or forge an interrupt for the original handler. */
2279 old_alarm
-= SELECT_PAUSE
;
2281 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2285 if (*local_timeout
== 0) /* Stop on timer being cleared */
2291 /* Read keyboard input into the standard buffer,
2292 waiting for at least one character. */
2294 /* Make all keyboard buffers much bigger when using X windows. */
2295 #ifdef HAVE_X_WINDOWS
2296 #define BUFFER_SIZE_FACTOR 16
2298 #define BUFFER_SIZE_FACTOR 1
2301 read_input_waiting ()
2303 struct input_event e
;
2305 extern int quit_char
;
2307 if (read_socket_hook
)
2309 struct input_event buf
[256];
2311 read_alarm_should_throw
= 0;
2312 if (! setjmp (read_alarm_throw
))
2313 nread
= (*read_socket_hook
) (0, buf
, 256, 1, 0);
2317 /* Scan the chars for C-g and store them in kbd_buffer. */
2318 for (i
= 0; i
< nread
; i
++)
2320 kbd_buffer_store_event (&buf
[i
]);
2321 /* Don't look at input that follows a C-g too closely.
2322 This reduces lossage due to autorepeat on C-g. */
2323 if (buf
[i
].kind
== ascii_keystroke
2324 && XINT(buf
[i
].code
) == quit_char
)
2331 nread
= read (fileno (stdin
), buf
, 1);
2333 /* Scan the chars for C-g and store them in kbd_buffer. */
2334 e
.kind
= ascii_keystroke
;
2335 XSETFRAME (e
.frame_or_window
, selected_frame
);
2337 for (i
= 0; i
< nread
; i
++)
2339 /* Convert chars > 0177 to meta events if desired.
2340 We do this under the same conditions that read_avail_input does. */
2341 if (read_socket_hook
== 0)
2343 /* If the user says she has a meta key, then believe her. */
2344 if (meta_key
== 1 && (buf
[i
] & 0x80))
2345 e
.modifiers
= meta_modifier
;
2350 XSETINT (e
.code
, buf
[i
]);
2351 kbd_buffer_store_event (&e
);
2352 /* Don't look at input that follows a C-g too closely.
2353 This reduces lossage due to autorepeat on C-g. */
2354 if (buf
[i
] == quit_char
)
2360 #endif /* not HAVE_SELECT */
2361 #endif /* not VMS */
2365 * Partially emulate 4.2 open call.
2366 * open is defined as this in 4.1.
2368 * - added by Michael Bloom @ Citicorp/TTI
2373 sys_open (path
, oflag
, mode
)
2377 if (oflag
& O_CREAT
)
2378 return creat (path
, mode
);
2380 return open (path
, oflag
);
2387 lmode
= LINTRUP
| lmode
;
2388 ioctl (0, TIOCLSET
, &lmode
);
2395 lmode
= ~LINTRUP
& lmode
;
2396 ioctl (0, TIOCLSET
, &lmode
);
2403 interrupts_deferred
= 0;
2410 interrupts_deferred
= 1;
2413 /* still inside #ifdef BSD4_1 */
2416 int sigheld
; /* Mask of held signals */
2421 sigheld
|= sigbit (signum
);
2428 sigheld
|= sigbit (signum
);
2434 sigheld
&= ~sigbit (signum
);
2438 sigfree () /* Free all held signals */
2441 for (i
= 0; i
< NSIG
; i
++)
2442 if (sigheld
& sigbit (i
))
2449 return 1 << (i
- 1);
2451 #endif /* subprocesses */
2454 /* POSIX signals support - DJB */
2455 /* Anyone with POSIX signals should have ANSI C declarations */
2457 #ifdef POSIX_SIGNALS
2459 sigset_t old_mask
, empty_mask
, full_mask
, temp_mask
;
2460 static struct sigaction new_action
, old_action
;
2464 sigemptyset (&empty_mask
);
2465 sigfillset (&full_mask
);
2469 sys_signal (int signal_number
, signal_handler_t action
)
2472 /* This gets us restartable system calls for efficiency.
2473 The "else" code will works as well. */
2474 return (berk_signal (signal_number
, action
));
2476 sigemptyset (&new_action
.sa_mask
);
2477 new_action
.sa_handler
= action
;
2479 /* Emacs mostly works better with restartable system services. If this
2480 * flag exists, we probably want to turn it on here.
2482 new_action
.sa_flags
= SA_RESTART
;
2484 new_action
.sa_flags
= 0;
2486 sigaction (signal_number
, &new_action
, &old_action
);
2487 return (old_action
.sa_handler
);
2492 /* If we're compiling with GCC, we don't need this function, since it
2493 can be written as a macro. */
2495 sys_sigmask (int sig
)
2498 sigemptyset (&mask
);
2499 sigaddset (&mask
, sig
);
2505 sys_sigpause (sigset_t new_mask
)
2507 /* pause emulating berk sigpause... */
2508 sigsuspend (&new_mask
);
2512 /* I'd like to have these guys return pointers to the mask storage in here,
2513 but there'd be trouble if the code was saving multiple masks. I'll be
2514 safe and pass the structure. It normally won't be more than 2 bytes
2518 sys_sigblock (sigset_t new_mask
)
2521 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2526 sys_sigunblock (sigset_t new_mask
)
2529 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2534 sys_sigsetmask (sigset_t new_mask
)
2537 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2541 #endif /* POSIX_SIGNALS */
2550 register int length
;
2554 long max_str
= 65535;
2556 while (length
> max_str
) {
2557 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
2562 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
2564 while (length
-- > 0)
2566 #endif /* not VMS */
2569 #endif /* no bzero */
2572 /* Saying `void' requires a declaration, above, where bcopy is used
2573 and that declaration causes pain for systems where bcopy is a macro. */
2574 bcopy (b1
, b2
, length
)
2577 register int length
;
2580 long max_str
= 65535;
2582 while (length
> max_str
) {
2583 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
2589 (void) LIB$
MOVC3 (&length
, b1
, b2
);
2591 while (length
-- > 0)
2593 #endif /* not VMS */
2595 #endif /* no bcopy */
2599 bcmp (b1
, b2
, length
) /* This could be a macro! */
2602 register int length
;
2605 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
2606 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
2608 return STR$
COMPARE (&src1
, &src2
);
2610 while (length
-- > 0)
2615 #endif /* not VMS */
2617 #endif /* no bcmp */
2619 #endif /* not BSTRING */
2625 * The BSD random returns numbers in the range of
2626 * 0 to 2e31 - 1. The USG rand returns numbers in the
2627 * range of 0 to 2e15 - 1. This is probably not significant
2637 /* The BSD rand returns numbers in the range of 0 to 2e31 - 1,
2638 with unusable least significant bits. The USG rand returns
2639 numbers in the range of 0 to 2e15 - 1, all usable. Let us
2640 build a usable 30 bit number from either. */
2642 return (rand () << 15) + rand ();
2644 return (rand () & 0x3fff8000) + (rand () >> 16);
2659 #endif /* no random */
2660 #endif /* not HAVE_RANDOM */
2662 #ifdef WRONG_NAME_INSQUE
2675 /* If any place else asks for the TERM variable,
2676 allow it to be overridden with the EMACS_TERM variable
2677 before attempting to translate the logical name TERM. As a last
2678 resort, ask for VAX C's special idea of the TERM variable. */
2685 static char buf
[256];
2686 static struct dsc$descriptor_s equiv
2687 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2688 static struct dsc$descriptor_s d_name
2689 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2692 if (!strcmp (name
, "TERM"))
2694 val
= (char *) getenv ("EMACS_TERM");
2699 d_name
.dsc$w_length
= strlen (name
);
2700 d_name
.dsc$a_pointer
= name
;
2701 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2703 char *str
= (char *) xmalloc (eqlen
+ 1);
2704 bcopy (buf
, str
, eqlen
);
2706 /* This is a storage leak, but a pain to fix. With luck,
2707 no one will ever notice. */
2710 return (char *) getenv (name
);
2715 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2716 to force a call on the debugger from within the image. */
2721 LIB$
SIGNAL (SS$_DEBUG
);
2727 #ifdef LINK_CRTL_SHARE
2728 #ifdef SHAREABLE_LIB_BUG
2729 /* Variables declared noshare and initialized in sharable libraries
2730 cannot be shared. The VMS linker incorrectly forces you to use a private
2731 version which is uninitialized... If not for this "feature", we
2732 could use the C library definition of sys_nerr and sys_errlist. */
2734 char *sys_errlist
[] =
2738 "no such file or directory",
2740 "interrupted system call",
2742 "no such device or address",
2743 "argument list too long",
2744 "exec format error",
2747 "no more processes",
2748 "not enough memory",
2749 "permission denied",
2751 "block device required",
2752 "mount devices busy",
2754 "cross-device link",
2759 "file table overflow",
2760 "too many open files",
2764 "no space left on device",
2766 "read-only file system",
2772 "vax/vms specific error code nontranslatable error"
2774 #endif /* SHAREABLE_LIB_BUG */
2775 #endif /* LINK_CRTL_SHARE */
2778 #ifndef HAVE_STRERROR
2783 extern char *sys_errlist
[];
2784 extern int sys_nerr
;
2786 if (errnum
>= 0 && errnum
< sys_nerr
)
2787 return sys_errlist
[errnum
];
2788 return (char *) "Unknown error";
2791 #endif /* ! HAVE_STRERROR */
2793 #ifdef INTERRUPTIBLE_OPEN
2797 sys_open (path
, oflag
, mode
)
2801 register int rtnval
;
2803 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2804 && (errno
== EINTR
));
2808 #endif /* INTERRUPTIBLE_OPEN */
2810 #ifdef INTERRUPTIBLE_CLOSE
2815 register int rtnval
;
2817 while ((rtnval
= close (fd
)) == -1
2818 && (errno
== EINTR
));
2822 #endif /* INTERRUPTIBLE_CLOSE */
2824 #ifdef INTERRUPTIBLE_IO
2827 sys_read (fildes
, buf
, nbyte
)
2832 register int rtnval
;
2834 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
2835 && (errno
== EINTR
));
2840 sys_write (fildes
, buf
, nbyte
)
2845 register int rtnval
, bytes_written
;
2851 rtnval
= write (fildes
, buf
, nbyte
);
2858 return (bytes_written
? bytes_written
: -1);
2863 bytes_written
+= rtnval
;
2865 return (bytes_written
);
2868 #endif /* INTERRUPTIBLE_IO */
2873 * Substitute fork for vfork on USG flavors.
2881 #endif /* not HAVE_VFORK */
2885 * All of the following are for USG.
2887 * On USG systems the system calls are INTERRUPTIBLE by signals
2888 * that the user program has elected to catch. Thus the system call
2889 * must be retried in these cases. To handle this without massive
2890 * changes in the source code, we remap the standard system call names
2891 * to names for our own functions in sysdep.c that do the system call
2892 * with retries. Actually, for portability reasons, it is good
2893 * programming practice, as this example shows, to limit all actual
2894 * system calls to a single occurrence in the source. Sure, this
2895 * adds an extra level of function call overhead but it is almost
2896 * always negligible. Fred Fish, Unisoft Systems Inc.
2899 #ifndef HAVE_SYS_SIGLIST
2900 char *sys_siglist
[NSIG
+ 1] =
2903 /* AIX has changed the signals a bit */
2904 "bogus signal", /* 0 */
2905 "hangup", /* 1 SIGHUP */
2906 "interrupt", /* 2 SIGINT */
2907 "quit", /* 3 SIGQUIT */
2908 "illegal instruction", /* 4 SIGILL */
2909 "trace trap", /* 5 SIGTRAP */
2910 "IOT instruction", /* 6 SIGIOT */
2911 "crash likely", /* 7 SIGDANGER */
2912 "floating point exception", /* 8 SIGFPE */
2913 "kill", /* 9 SIGKILL */
2914 "bus error", /* 10 SIGBUS */
2915 "segmentation violation", /* 11 SIGSEGV */
2916 "bad argument to system call", /* 12 SIGSYS */
2917 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2918 "alarm clock", /* 14 SIGALRM */
2919 "software termination signum", /* 15 SIGTERM */
2920 "user defined signal 1", /* 16 SIGUSR1 */
2921 "user defined signal 2", /* 17 SIGUSR2 */
2922 "death of a child", /* 18 SIGCLD */
2923 "power-fail restart", /* 19 SIGPWR */
2924 "bogus signal", /* 20 */
2925 "bogus signal", /* 21 */
2926 "bogus signal", /* 22 */
2927 "bogus signal", /* 23 */
2928 "bogus signal", /* 24 */
2929 "LAN I/O interrupt", /* 25 SIGAIO */
2930 "PTY I/O interrupt", /* 26 SIGPTY */
2931 "I/O intervention required", /* 27 SIGIOINT */
2932 "HFT grant", /* 28 SIGGRANT */
2933 "HFT retract", /* 29 SIGRETRACT */
2934 "HFT sound done", /* 30 SIGSOUND */
2935 "HFT input ready", /* 31 SIGMSG */
2937 "bogus signal", /* 0 */
2938 "hangup", /* 1 SIGHUP */
2939 "interrupt", /* 2 SIGINT */
2940 "quit", /* 3 SIGQUIT */
2941 "illegal instruction", /* 4 SIGILL */
2942 "trace trap", /* 5 SIGTRAP */
2943 "IOT instruction", /* 6 SIGIOT */
2944 "EMT instruction", /* 7 SIGEMT */
2945 "floating point exception", /* 8 SIGFPE */
2946 "kill", /* 9 SIGKILL */
2947 "bus error", /* 10 SIGBUS */
2948 "segmentation violation", /* 11 SIGSEGV */
2949 "bad argument to system call", /* 12 SIGSYS */
2950 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2951 "alarm clock", /* 14 SIGALRM */
2952 "software termination signum", /* 15 SIGTERM */
2953 "user defined signal 1", /* 16 SIGUSR1 */
2954 "user defined signal 2", /* 17 SIGUSR2 */
2955 "death of a child", /* 18 SIGCLD */
2956 "power-fail restart", /* 19 SIGPWR */
2958 "window size change", /* 20 SIGWINCH */
2959 "urgent socket condition", /* 21 SIGURG */
2960 "pollable event occured", /* 22 SIGPOLL */
2961 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */
2962 "user stop requested from tty", /* 24 SIGTSTP */
2963 "stopped process has been continued", /* 25 SIGCONT */
2964 "background tty read attempted", /* 26 SIGTTIN */
2965 "background tty write attempted", /* 27 SIGTTOU */
2966 "virtual timer expired", /* 28 SIGVTALRM */
2967 "profiling timer expired", /* 29 SIGPROF */
2968 "exceeded cpu limit", /* 30 SIGXCPU */
2969 "exceeded file size limit", /* 31 SIGXFSZ */
2970 "process's lwps are blocked", /* 32 SIGWAITING */
2971 "special signal used by thread library", /* 33 SIGLWP */
2973 "Special Signal Used By CPR", /* 34 SIGFREEZE */
2976 "Special Signal Used By CPR", /* 35 SIGTHAW */
2979 #endif /* not AIX */
2982 #endif /* HAVE_SYS_SIGLIST */
2985 * Warning, this function may not duplicate 4.2 action properly
2986 * under error conditions.
2990 /* In 4.1, param.h fails to define this. */
2991 #define MAXPATHLEN 1024
3000 char *npath
, *spath
;
3001 extern char *getcwd ();
3003 BLOCK_INPUT
; /* getcwd uses malloc */
3004 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3007 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3008 up to first slash. Should be harmless on other systems. */
3009 while (*npath
&& *npath
!= '/')
3011 strcpy (pathname
, npath
);
3012 free (spath
); /* getcwd uses malloc */
3017 #endif /* HAVE_GETWD */
3020 * Emulate rename using unlink/link. Note that this is
3021 * only partially correct. Also, doesn't enforce restriction
3022 * that files be of same type (regular->regular, dir->dir, etc).
3031 if (access (from
, 0) == 0)
3034 if (link (from
, to
) == 0)
3035 if (unlink (from
) == 0)
3047 /* HPUX curses library references perror, but as far as we know
3048 it won't be called. Anyway this definition will do for now. */
3054 #endif /* not HAVE_PERROR */
3060 * Emulate BSD dup2. First close newd if it already exists.
3061 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3062 * until we are, then close the unsuccessful ones.
3069 register int fd
, ret
;
3074 fd
= fcntl (oldd
, F_DUPFD
, newd
);
3076 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, strerror (errno
));
3083 ret
= dup2 (old
,new);
3089 #endif /* not HAVE_DUP2 */
3092 * Gettimeofday. Simulate as much as possible. Only accurate
3093 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3094 * Only needed when subprocesses are defined.
3099 #ifndef HAVE_GETTIMEOFDAY
3103 gettimeofday (tp
, tzp
)
3105 struct timezone
*tzp
;
3107 extern long time ();
3109 tp
->tv_sec
= time ((long *)0);
3112 tzp
->tz_minuteswest
= -1;
3118 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3121 * This function will go away as soon as all the stubs fixed. (fnf)
3127 printf ("%s not yet implemented\r\n", badfunc
);
3136 char *sys_siglist
[NSIG
+ 1] =
3138 "null signal", /* 0 SIGNULL */
3139 "hangup", /* 1 SIGHUP */
3140 "interrupt", /* 2 SIGINT */
3141 "quit", /* 3 SIGQUIT */
3142 "illegal instruction", /* 4 SIGILL */
3143 "trace trap", /* 5 SIGTRAP */
3144 "abort termination", /* 6 SIGABRT */
3145 "SIGEMT", /* 7 SIGEMT */
3146 "floating point exception", /* 8 SIGFPE */
3147 "kill", /* 9 SIGKILL */
3148 "bus error", /* 10 SIGBUS */
3149 "segmentation violation", /* 11 SIGSEGV */
3150 "bad argument to system call", /* 12 SIGSYS */
3151 "write on a pipe with no reader", /* 13 SIGPIPE */
3152 "alarm clock", /* 14 SIGALRM */
3153 "software termination signal", /* 15 SIGTERM */
3154 "user defined signal 1", /* 16 SIGUSR1 */
3155 "user defined signal 2", /* 17 SIGUSR2 */
3156 "child stopped or terminated", /* 18 SIGCLD */
3157 "power-fail restart", /* 19 SIGPWR */
3158 "window size changed", /* 20 SIGWINCH */
3159 "undefined", /* 21 */
3160 "pollable event occurred", /* 22 SIGPOLL */
3161 "sendable stop signal not from tty", /* 23 SIGSTOP */
3162 "stop signal from tty", /* 24 SIGSTP */
3163 "continue a stopped process", /* 25 SIGCONT */
3164 "attempted background tty read", /* 26 SIGTTIN */
3165 "attempted background tty write", /* 27 SIGTTOU */
3166 "undefined", /* 28 */
3167 "undefined", /* 29 */
3168 "undefined", /* 30 */
3169 "undefined", /* 31 */
3170 "undefined", /* 32 */
3171 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
3172 "I/O is possible", /* 34 SIGIO */
3173 "exceeded cpu time limit", /* 35 SIGXCPU */
3174 "exceeded file size limit", /* 36 SIGXFSZ */
3175 "virtual time alarm", /* 37 SIGVTALRM */
3176 "profiling time alarm", /* 38 SIGPROF */
3177 "undefined", /* 39 */
3178 "file record locks revoked", /* 40 SIGLOST */
3179 "undefined", /* 41 */
3180 "undefined", /* 42 */
3181 "undefined", /* 43 */
3182 "undefined", /* 44 */
3183 "undefined", /* 45 */
3184 "undefined", /* 46 */
3185 "undefined", /* 47 */
3186 "undefined", /* 48 */
3187 "undefined", /* 49 */
3188 "undefined", /* 50 */
3189 "undefined", /* 51 */
3190 "undefined", /* 52 */
3191 "undefined", /* 53 */
3192 "undefined", /* 54 */
3193 "undefined", /* 55 */
3194 "undefined", /* 56 */
3195 "undefined", /* 57 */
3196 "undefined", /* 58 */
3197 "undefined", /* 59 */
3198 "undefined", /* 60 */
3199 "undefined", /* 61 */
3200 "undefined", /* 62 */
3201 "undefined", /* 63 */
3202 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3208 /* Directory routines for systems that don't have them. */
3210 #ifdef SYSV_SYSTEM_DIR
3214 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
3218 register DIR *dirp
; /* stream from opendir */
3222 rtnval
= sys_close (dirp
->dd_fd
);
3224 /* Some systems (like Solaris) allocate the buffer and the DIR all
3225 in one block. Why in the world are we freeing this ourselves
3227 #if ! (defined (sun) && defined (USG5_4))
3228 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3230 xfree ((char *) dirp
);
3234 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3235 #endif /* SYSV_SYSTEM_DIR */
3237 #ifdef NONSYSTEM_DIR_LIBRARY
3241 char *filename
; /* name of directory */
3243 register DIR *dirp
; /* -> malloc'ed storage */
3244 register int fd
; /* file descriptor for read */
3245 struct stat sbuf
; /* result of fstat */
3247 fd
= sys_open (filename
, 0);
3252 if (fstat (fd
, &sbuf
) < 0
3253 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3254 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
3258 return 0; /* bad luck today */
3263 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3270 register DIR *dirp
; /* stream from opendir */
3272 sys_close (dirp
->dd_fd
);
3273 xfree ((char *) dirp
);
3281 ino_t od_ino
; /* inode */
3282 char od_name
[DIRSIZ
]; /* filename */
3284 #endif /* not VMS */
3286 struct direct dir_static
; /* simulated directory contents */
3291 register DIR *dirp
; /* stream from opendir */
3294 register struct olddir
*dp
; /* -> directory data */
3296 register struct dir$_name
*dp
; /* -> directory data */
3297 register struct dir$_version
*dv
; /* -> version data */
3302 if (dirp
->dd_loc
>= dirp
->dd_size
)
3303 dirp
->dd_loc
= dirp
->dd_size
= 0;
3305 if (dirp
->dd_size
== 0 /* refill buffer */
3306 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3310 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3311 dirp
->dd_loc
+= sizeof (struct olddir
);
3313 if (dp
->od_ino
!= 0) /* not deleted entry */
3315 dir_static
.d_ino
= dp
->od_ino
;
3316 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3317 dir_static
.d_name
[DIRSIZ
] = '\0';
3318 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3319 dir_static
.d_reclen
= sizeof (struct direct
)
3321 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3322 return &dir_static
; /* -> simulated structure */
3325 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3326 if (dirp
->dd_loc
== 0)
3327 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3328 : dp
->dir$b_namecount
;
3329 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3330 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3331 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3332 dir_static
.d_reclen
= sizeof (struct direct
)
3334 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3335 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3336 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3337 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3344 /* readdirver is just like readdir except it returns all versions of a file
3345 as separate entries. */
3350 register DIR *dirp
; /* stream from opendir */
3352 register struct dir$_name
*dp
; /* -> directory data */
3353 register struct dir$_version
*dv
; /* -> version data */
3355 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3356 dirp
->dd_loc
= dirp
->dd_size
= 0;
3358 if (dirp
->dd_size
== 0 /* refill buffer */
3359 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3362 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3363 if (dirp
->dd_loc
== 0)
3364 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3365 : dp
->dir$b_namecount
;
3366 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3367 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3368 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3369 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3370 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3371 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3372 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3373 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3379 #endif /* NONSYSTEM_DIR_LIBRARY */
3383 set_file_times (filename
, atime
, mtime
)
3385 EMACS_TIME atime
, mtime
;
3388 struct timeval tv
[2];
3391 return utimes (filename
, tv
);
3392 #else /* not HAVE_UTIMES */
3394 utb
.actime
= EMACS_SECS (atime
);
3395 utb
.modtime
= EMACS_SECS (mtime
);
3396 return utime (filename
, &utb
);
3397 #endif /* not HAVE_UTIMES */
3400 /* mkdir and rmdir functions, for systems which don't have them. */
3404 * Written by Robert Rother, Mariah Corporation, August 1985.
3406 * If you want it, it's yours. All I ask in return is that if you
3407 * figure out how to do this in a Bourne Shell script you send me
3409 * sdcsvax!rmr or rmr@uscd
3411 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3412 * subroutine. 11Mar86; hoptoad!gnu
3414 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3415 * subroutine didn't return EEXIST. It does now.
3421 #ifdef MKDIR_PROTOTYPE
3425 mkdir (dpath
, dmode
)
3430 int cpid
, status
, fd
;
3431 struct stat statbuf
;
3433 if (stat (dpath
, &statbuf
) == 0)
3435 errno
= EEXIST
; /* Stat worked, so it already exists */
3439 /* If stat fails for a reason other than non-existence, return error */
3440 if (errno
!= ENOENT
)
3443 synch_process_alive
= 1;
3444 switch (cpid
= fork ())
3447 case -1: /* Error in fork */
3448 return (-1); /* Errno is set already */
3450 case 0: /* Child process */
3452 * Cheap hack to set mode of new directory. Since this
3453 * child process is going away anyway, we zap its umask.
3454 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3455 * directory. Does anybody care?
3457 status
= umask (0); /* Get current umask */
3458 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3459 fd
= sys_open("/dev/null", 2);
3466 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3467 _exit (-1); /* Can't exec /bin/mkdir */
3469 default: /* Parent process */
3470 wait_for_termination (cpid
);
3473 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3475 errno
= EIO
; /* We don't know why, but */
3476 return -1; /* /bin/mkdir failed */
3481 #endif /* not HAVE_MKDIR */
3488 int cpid
, status
, fd
;
3489 struct stat statbuf
;
3491 if (stat (dpath
, &statbuf
) != 0)
3493 /* Stat just set errno. We don't have to */
3497 synch_process_alive
= 1;
3498 switch (cpid
= fork ())
3501 case -1: /* Error in fork */
3502 return (-1); /* Errno is set already */
3504 case 0: /* Child process */
3505 fd
= sys_open("/dev/null", 2);
3512 wait_for_termination (cpid
);
3513 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3514 return -1; /* /bin/rmdir failed */
3515 default: /* Parent process */
3516 while (cpid
!= wait (&status
)); /* Wait for kid to finish */
3519 if (WIFSIGNALED (status
) || WEXITSTATUS (status
) != 0)
3521 errno
= EIO
; /* We don't know why, but */
3522 return -1; /* /bin/mkdir failed */
3527 #endif /* !HAVE_RMDIR */
3531 /* Functions for VMS */
3533 #include "vms-pwd.h"
3538 /* Return as a string the VMS error string pertaining to STATUS.
3539 Reuses the same static buffer each time it is called. */
3543 int status
; /* VMS status code */
3547 static char buf
[257];
3549 bufadr
[0] = sizeof buf
- 1;
3550 bufadr
[1] = (int) buf
;
3551 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3552 return "untranslatable VMS error status";
3560 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3561 * not work correctly. (It also doesn't work well in version 2.3.)
3566 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3567 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3571 unsigned short s_buflen
;
3572 unsigned short s_code
;
3574 unsigned short *s_retlenadr
;
3578 #define buflen s.s_buflen
3579 #define code s.s_code
3580 #define bufadr s.s_bufadr
3581 #define retlenadr s.s_retlenadr
3583 #define R_OK 4 /* test for read permission */
3584 #define W_OK 2 /* test for write permission */
3585 #define X_OK 1 /* test for execute (search) permission */
3586 #define F_OK 0 /* test for presence of file */
3589 sys_access (path
, mode
)
3593 static char *user
= NULL
;
3596 /* translate possible directory spec into .DIR file name, so brain-dead
3597 * access can treat the directory like a file. */
3598 if (directory_file_name (path
, dir_fn
))
3602 return access (path
, mode
);
3603 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3609 unsigned short int dummy
;
3611 static int constant
= ACL$C_FILE
;
3612 DESCRIPTOR (path_desc
, path
);
3613 DESCRIPTOR (user_desc
, user
);
3617 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3620 acces
|= CHP$M_READ
;
3622 acces
|= CHP$M_WRITE
;
3623 itemlst
[0].buflen
= sizeof (int);
3624 itemlst
[0].code
= CHP$_FLAGS
;
3625 itemlst
[0].bufadr
= (char *) &flags
;
3626 itemlst
[0].retlenadr
= &dummy
;
3627 itemlst
[1].buflen
= sizeof (int);
3628 itemlst
[1].code
= CHP$_ACCESS
;
3629 itemlst
[1].bufadr
= (char *) &acces
;
3630 itemlst
[1].retlenadr
= &dummy
;
3631 itemlst
[2].end
= CHP$_END
;
3632 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3633 return stat
== SS$_NORMAL
? 0 : -1;
3637 #else /* not VMS4_4 */
3640 #define ACE$M_WRITE 2
3641 #define ACE$C_KEYID 1
3643 static unsigned short memid
, grpid
;
3644 static unsigned int uic
;
3646 /* Called from init_sys_modes, so it happens not very often
3647 but at least each time Emacs is loaded. */
3648 sys_access_reinit ()
3654 sys_access (filename
, type
)
3660 int status
, size
, i
, typecode
, acl_controlled
;
3661 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3662 union prvdef prvmask
;
3664 /* Get UIC and GRP values for protection checking. */
3667 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3670 memid
= uic
& 0xFFFF;
3674 if (type
!= 2) /* not checking write access */
3675 return access (filename
, type
);
3677 /* Check write protection. */
3679 #define CHECKPRIV(bit) (prvmask.bit)
3680 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3682 /* Find privilege bits */
3683 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3685 error ("Unable to find privileges: %s", vmserrstr (status
));
3686 if (CHECKPRIV (PRV$V_BYPASS
))
3687 return 0; /* BYPASS enabled */
3689 fab
.fab$b_fac
= FAB$M_GET
;
3690 fab
.fab$l_fna
= filename
;
3691 fab
.fab$b_fns
= strlen (filename
);
3692 fab
.fab$l_xab
= &xab
;
3693 xab
= cc$rms_xabpro
;
3694 xab
.xab$l_aclbuf
= aclbuf
;
3695 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3696 status
= SYS$
OPEN (&fab
, 0, 0);
3699 SYS$
CLOSE (&fab
, 0, 0);
3700 /* Check system access */
3701 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITEABLE (XAB$V_SYS
))
3703 /* Check ACL entries, if any */
3705 if (xab
.xab$w_acllen
> 0)
3708 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3709 while (*aclptr
&& aclptr
< aclend
)
3711 size
= (*aclptr
& 0xff) / 4;
3712 typecode
= (*aclptr
>> 8) & 0xff;
3713 if (typecode
== ACE$C_KEYID
)
3714 for (i
= size
- 1; i
> 1; i
--)
3715 if (aclptr
[i
] == uic
)
3718 if (aclptr
[1] & ACE$M_WRITE
)
3719 return 0; /* Write access through ACL */
3721 aclptr
= &aclptr
[size
];
3723 if (acl_controlled
) /* ACL specified, prohibits write access */
3726 /* No ACL entries specified, check normal protection */
3727 if (WRITEABLE (XAB$V_WLD
)) /* World writeable */
3729 if (WRITEABLE (XAB$V_GRP
) &&
3730 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3731 return 0; /* Group writeable */
3732 if (WRITEABLE (XAB$V_OWN
) &&
3733 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3734 return 0; /* Owner writeable */
3736 return -1; /* Not writeable */
3738 #endif /* not VMS4_4 */
3741 static char vtbuf
[NAM$C_MAXRSS
+1];
3743 /* translate a vms file spec to a unix path */
3745 sys_translate_vms (vfile
)
3756 /* leading device or logical name is a root directory */
3757 if (p
= strchr (vfile
, ':'))
3766 if (*p
== '[' || *p
== '<')
3768 while (*++vfile
!= *p
+ 2)
3772 if (vfile
[-1] == *p
)
3795 static char utbuf
[NAM$C_MAXRSS
+1];
3797 /* translate a unix path to a VMS file spec */
3799 sys_translate_unix (ufile
)
3822 if (index (&ufile
[1], '/'))
3829 if (index (&ufile
[1], '/'))
3836 if (strncmp (ufile
, "./", 2) == 0)
3843 ufile
++; /* skip the dot */
3844 if (index (&ufile
[1], '/'))
3849 else if (strncmp (ufile
, "../", 3) == 0)
3857 ufile
+= 2; /* skip the dots */
3858 if (index (&ufile
[1], '/'))
3883 extern char *getcwd ();
3885 #define MAXPATHLEN 1024
3887 ptr
= xmalloc (MAXPATHLEN
);
3888 val
= getcwd (ptr
, MAXPATHLEN
);
3894 strcpy (pathname
, ptr
);
3902 long item_code
= JPI$_OWNER
;
3903 unsigned long parent_id
;
3906 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
3909 vaxc$errno
= status
;
3919 return (getgid () << 16) | getuid ();
3923 sys_read (fildes
, buf
, nbyte
)
3928 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
3933 sys_write (fildes
, buf
, nbyte
)
3938 register int nwrote
, rtnval
= 0;
3940 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
3946 return rtnval
? rtnval
: -1;
3947 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
3948 return rtnval
? rtnval
: -1;
3949 return (rtnval
+ nwrote
);
3954 * VAX/VMS VAX C RTL really loses. It insists that records
3955 * end with a newline (carriage return) character, and if they
3956 * don't it adds one (nice of it isn't it!)
3958 * Thus we do this stupidity below.
3962 sys_write (fildes
, buf
, nbytes
)
3965 unsigned int nbytes
;
3972 fstat (fildes
, &st
);
3978 /* Handle fixed-length files with carriage control. */
3979 if (st
.st_fab_rfm
== FAB$C_FIX
3980 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
3982 len
= st
.st_fab_mrs
;
3983 retval
= write (fildes
, p
, min (len
, nbytes
));
3986 retval
++; /* This skips the implied carriage control */
3990 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3991 while (*e
!= '\n' && e
> p
) e
--;
3992 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
3993 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3995 retval
= write (fildes
, p
, len
);
4006 /* Create file NEW copying its attributes from file OLD. If
4007 OLD is 0 or does not exist, create based on the value of
4010 /* Protection value the file should ultimately have.
4011 Set by create_copy_attrs, and use by rename_sansversions. */
4012 static unsigned short int fab_final_pro
;
4015 creat_copy_attrs (old
, new)
4018 struct FAB fab
= cc$rms_fab
;
4019 struct XABPRO xabpro
;
4020 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4021 extern int vms_stmlf_recfm
;
4025 fab
.fab$b_fac
= FAB$M_GET
;
4026 fab
.fab$l_fna
= old
;
4027 fab
.fab$b_fns
= strlen (old
);
4028 fab
.fab$l_xab
= (char *) &xabpro
;
4029 xabpro
= cc$rms_xabpro
;
4030 xabpro
.xab$l_aclbuf
= aclbuf
;
4031 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4032 /* Call $OPEN to fill in the fab & xabpro fields. */
4033 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4035 SYS$
CLOSE (&fab
, 0, 0);
4036 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4037 if (xabpro
.xab$w_acllen
> 0)
4039 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4040 /* If the acl buffer was too short, redo open with longer one.
4041 Wouldn't need to do this if there were some system imposed
4042 limit on the size of an ACL, but I can't find any such. */
4044 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4045 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4046 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4047 SYS$
CLOSE (&fab
, 0, 0);
4053 xabpro
.xab$l_aclbuf
= 0;
4058 fab
.fab$l_fna
= new;
4059 fab
.fab$b_fns
= strlen (new);
4063 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4064 fab
.fab$b_rat
= FAB$M_CR
;
4067 /* Set the file protections such that we will be able to manipulate
4068 this file. Once we are done writing and renaming it, we will set
4069 the protections back. */
4071 fab_final_pro
= xabpro
.xab$w_pro
;
4073 SYS$
SETDFPROT (0, &fab_final_pro
);
4074 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4076 /* Create the new file with either default attrs or attrs copied
4078 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4080 SYS$
CLOSE (&fab
, 0, 0);
4081 /* As this is a "replacement" for creat, return a file descriptor
4082 opened for writing. */
4083 return open (new, O_WRONLY
);
4088 #include <varargs.h>
4091 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4095 sys_creat (va_alist
)
4098 va_list list_incrementer
;
4101 int rfd
; /* related file descriptor */
4102 int fd
; /* Our new file descriptor */
4109 extern int vms_stmlf_recfm
;
4112 va_start (list_incrementer
);
4113 name
= va_arg (list_incrementer
, char *);
4114 mode
= va_arg (list_incrementer
, int);
4116 rfd
= va_arg (list_incrementer
, int);
4117 va_end (list_incrementer
);
4120 /* Use information from the related file descriptor to set record
4121 format of the newly created file. */
4122 fstat (rfd
, &st_buf
);
4123 switch (st_buf
.st_fab_rfm
)
4126 strcpy (rfm
, "rfm = fix");
4127 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4128 strcpy (rat
, "rat = ");
4129 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4131 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4132 strcat (rat
, "ftn");
4133 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4134 strcat (rat
, "prn");
4135 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4136 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4137 strcat (rat
, ", blk");
4139 strcat (rat
, "blk");
4140 return creat (name
, 0, rfm
, rat
, mrs
);
4143 strcpy (rfm
, "rfm = vfc");
4144 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4145 strcpy (rat
, "rat = ");
4146 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4148 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4149 strcat (rat
, "ftn");
4150 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4151 strcat (rat
, "prn");
4152 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4153 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4154 strcat (rat
, ", blk");
4156 strcat (rat
, "blk");
4157 return creat (name
, 0, rfm
, rat
, fsz
);
4160 strcpy (rfm
, "rfm = stm");
4164 strcpy (rfm
, "rfm = stmcr");
4168 strcpy (rfm
, "rfm = stmlf");
4172 strcpy (rfm
, "rfm = udf");
4176 strcpy (rfm
, "rfm = var");
4179 strcpy (rat
, "rat = ");
4180 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4182 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4183 strcat (rat
, "ftn");
4184 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4185 strcat (rat
, "prn");
4186 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4187 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4188 strcat (rat
, ", blk");
4190 strcat (rat
, "blk");
4194 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4195 strcpy (rat
, "rat=cr");
4197 /* Until the VAX C RTL fixes the many bugs with modes, always use
4198 mode 0 to get the user's default protection. */
4199 fd
= creat (name
, 0, rfm
, rat
);
4200 if (fd
< 0 && errno
== EEXIST
)
4202 if (unlink (name
) < 0)
4203 report_file_error ("delete", build_string (name
));
4204 fd
= creat (name
, 0, rfm
, rat
);
4210 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4211 sys_fwrite (ptr
, size
, num
, fp
)
4212 register char * ptr
;
4215 register int tot
= num
* size
;
4222 * The VMS C library routine creat actually creates a new version of an
4223 * existing file rather than truncating the old version. There are times
4224 * when this is not the desired behavior, for instance, when writing an
4225 * auto save file (you only want one version), or when you don't have
4226 * write permission in the directory containing the file (but the file
4227 * itself is writable). Hence this routine, which is equivalent to
4228 * "close (creat (fn, 0));" on Unix if fn already exists.
4234 struct FAB xfab
= cc$rms_fab
;
4235 struct RAB xrab
= cc$rms_rab
;
4238 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4239 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4240 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4241 xfab
.fab$l_fna
= fn
;
4242 xfab
.fab$b_fns
= strlen (fn
);
4243 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4245 xrab
.rab$l_fab
= &xfab
;
4247 /* This gibberish opens the file, positions to the first record, and
4248 deletes all records from there until the end of file. */
4249 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4251 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4252 (SYS$
FIND (&xrab
) & 01) == 01 &&
4253 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4264 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4265 SYSPRV or a readable SYSUAF.DAT. */
4271 * Routine to read the VMS User Authorization File and return
4272 * a specific user's record.
4275 static struct UAF retuaf
;
4278 get_uaf_name (uname
)
4285 uaf_fab
= cc$rms_fab
;
4286 uaf_rab
= cc$rms_rab
;
4287 /* initialize fab fields */
4288 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4289 uaf_fab
.fab$b_fns
= 21;
4290 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4291 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4292 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4293 /* initialize rab fields */
4294 uaf_rab
.rab$l_fab
= &uaf_fab
;
4295 /* open the User Authorization File */
4296 status
= SYS$
OPEN (&uaf_fab
);
4300 vaxc$errno
= status
;
4303 status
= SYS$
CONNECT (&uaf_rab
);
4307 vaxc$errno
= status
;
4310 /* read the requested record - index is in uname */
4311 uaf_rab
.rab$l_kbf
= uname
;
4312 uaf_rab
.rab$b_ksz
= strlen (uname
);
4313 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4314 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4315 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4316 status
= SYS$
GET (&uaf_rab
);
4320 vaxc$errno
= status
;
4323 /* close the User Authorization File */
4324 status
= SYS$
DISCONNECT (&uaf_rab
);
4328 vaxc$errno
= status
;
4331 status
= SYS$
CLOSE (&uaf_fab
);
4335 vaxc$errno
= status
;
4349 uaf_fab
= cc$rms_fab
;
4350 uaf_rab
= cc$rms_rab
;
4351 /* initialize fab fields */
4352 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4353 uaf_fab
.fab$b_fns
= 21;
4354 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4355 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4356 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4357 /* initialize rab fields */
4358 uaf_rab
.rab$l_fab
= &uaf_fab
;
4359 /* open the User Authorization File */
4360 status
= SYS$
OPEN (&uaf_fab
);
4364 vaxc$errno
= status
;
4367 status
= SYS$
CONNECT (&uaf_rab
);
4371 vaxc$errno
= status
;
4374 /* read the requested record - index is in uic */
4375 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4376 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4377 uaf_rab
.rab$b_ksz
= sizeof uic
;
4378 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4379 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4380 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4381 status
= SYS$
GET (&uaf_rab
);
4385 vaxc$errno
= status
;
4388 /* close the User Authorization File */
4389 status
= SYS$
DISCONNECT (&uaf_rab
);
4393 vaxc$errno
= status
;
4396 status
= SYS$
CLOSE (&uaf_fab
);
4400 vaxc$errno
= status
;
4406 static struct passwd retpw
;
4414 /* copy these out first because if the username is 32 chars, the next
4415 section will overwrite the first byte of the UIC */
4416 retpw
.pw_uid
= up
->uaf$w_mem
;
4417 retpw
.pw_gid
= up
->uaf$w_grp
;
4419 /* I suppose this is not the best sytle, to possibly overwrite one
4420 byte beyond the end of the field, but what the heck... */
4421 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4422 while (ptr
[-1] == ' ')
4425 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4427 /* the rest of these are counted ascii strings */
4428 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4429 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4430 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4431 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4432 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4433 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4434 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4435 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4439 #else /* not READ_SYSUAF */
4440 static struct passwd retpw
;
4441 #endif /* not READ_SYSUAF */
4452 unsigned char * full
;
4453 #endif /* READ_SYSUAF */
4458 if ('a' <= *ptr
&& *ptr
<= 'z')
4463 if (!(up
= get_uaf_name (name
)))
4465 return cnv_uaf_pw (up
);
4467 if (strcmp (name
, getenv ("USER")) == 0)
4469 retpw
.pw_uid
= getuid ();
4470 retpw
.pw_gid
= getgid ();
4471 strcpy (retpw
.pw_name
, name
);
4472 if (full
= egetenv ("FULLNAME"))
4473 strcpy (retpw
.pw_gecos
, full
);
4475 *retpw
.pw_gecos
= '\0';
4476 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4477 *retpw
.pw_shell
= '\0';
4482 #endif /* not READ_SYSUAF */
4492 if (!(up
= get_uaf_uic (uid
)))
4494 return cnv_uaf_pw (up
);
4496 if (uid
== sys_getuid ())
4497 return getpwnam (egetenv ("USER"));
4500 #endif /* not READ_SYSUAF */
4503 /* return total address space available to the current process. This is
4504 the sum of the current p0 size, p1 size and free page table entries
4509 unsigned long free_pages
;
4510 unsigned long frep0va
;
4511 unsigned long frep1va
;
4514 item_code
= JPI$_FREPTECNT
;
4515 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4518 vaxc$errno
= status
;
4523 item_code
= JPI$_FREP0VA
;
4524 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4527 vaxc$errno
= status
;
4530 item_code
= JPI$_FREP1VA
;
4531 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4534 vaxc$errno
= status
;
4538 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4541 define_logical_name (varname
, string
)
4545 struct dsc$descriptor_s strdsc
=
4546 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4547 struct dsc$descriptor_s envdsc
=
4548 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4549 struct dsc$descriptor_s lnmdsc
=
4550 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4552 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4555 delete_logical_name (varname
)
4558 struct dsc$descriptor_s envdsc
=
4559 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4560 struct dsc$descriptor_s lnmdsc
=
4561 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4563 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4574 error ("execvp system call not implemented");
4582 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4583 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4584 char from_esn
[NAM$C_MAXRSS
];
4585 char to_esn
[NAM$C_MAXRSS
];
4587 from_fab
.fab$l_fna
= from
;
4588 from_fab
.fab$b_fns
= strlen (from
);
4589 from_fab
.fab$l_nam
= &from_nam
;
4590 from_fab
.fab$l_fop
= FAB$M_NAM
;
4592 from_nam
.nam$l_esa
= from_esn
;
4593 from_nam
.nam$b_ess
= sizeof from_esn
;
4595 to_fab
.fab$l_fna
= to
;
4596 to_fab
.fab$b_fns
= strlen (to
);
4597 to_fab
.fab$l_nam
= &to_nam
;
4598 to_fab
.fab$l_fop
= FAB$M_NAM
;
4600 to_nam
.nam$l_esa
= to_esn
;
4601 to_nam
.nam$b_ess
= sizeof to_esn
;
4603 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4609 if (status
== RMS$_DEV
)
4613 vaxc$errno
= status
;
4618 /* This function renames a file like `rename', but it strips
4619 the version number from the "to" filename, such that the "to" file is
4620 will always be a new version. It also sets the file protection once it is
4621 finished. The protection that we will use is stored in fab_final_pro,
4622 and was set when we did a creat_copy_attrs to create the file that we
4625 We could use the chmod function, but Eunichs uses 3 bits per user category
4626 to describe the protection, and VMS uses 4 (write and delete are separate
4627 bits). To maintain portability, the VMS implementation of `chmod' wires
4628 the W and D bits together. */
4631 static struct fibdef fib
; /* We need this initialized to zero */
4632 char vms_file_written
[NAM$C_MAXRSS
];
4635 rename_sans_version (from
,to
)
4642 struct FAB to_fab
= cc$rms_fab
;
4643 struct NAM to_nam
= cc$rms_nam
;
4644 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4645 struct dsc$descriptor fib_attr
[2]
4646 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4647 char to_esn
[NAM$C_MAXRSS
];
4649 $
DESCRIPTOR (disk
,to_esn
);
4651 to_fab
.fab$l_fna
= to
;
4652 to_fab
.fab$b_fns
= strlen (to
);
4653 to_fab
.fab$l_nam
= &to_nam
;
4654 to_fab
.fab$l_fop
= FAB$M_NAM
;
4656 to_nam
.nam$l_esa
= to_esn
;
4657 to_nam
.nam$b_ess
= sizeof to_esn
;
4659 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4661 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4662 *(to_nam
.nam$l_ver
) = '\0';
4664 stat
= rename (from
, to_esn
);
4668 strcpy (vms_file_written
, to_esn
);
4670 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4671 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4673 /* Now set the file protection to the correct value */
4674 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4676 /* Copy these fields into the fib */
4677 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4678 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4679 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4681 SYS$
CLOSE (&to_fab
, 0, 0);
4683 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4686 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4687 0, 0, 0, &fib_attr
, 0);
4690 stat
= SYS$
DASSGN (chan
);
4693 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4703 unsigned short fid
[3];
4704 char esa
[NAM$C_MAXRSS
];
4707 fab
.fab$l_fop
= FAB$M_OFP
;
4708 fab
.fab$l_fna
= file
;
4709 fab
.fab$b_fns
= strlen (file
);
4710 fab
.fab$l_nam
= &nam
;
4713 nam
.nam$l_esa
= esa
;
4714 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4716 status
= SYS$
PARSE (&fab
);
4717 if ((status
& 1) == 0)
4720 vaxc$errno
= status
;
4723 status
= SYS$
SEARCH (&fab
);
4724 if ((status
& 1) == 0)
4727 vaxc$errno
= status
;
4731 fid
[0] = nam
.nam$w_fid
[0];
4732 fid
[1] = nam
.nam$w_fid
[1];
4733 fid
[2] = nam
.nam$w_fid
[2];
4735 fab
.fab$l_fna
= new;
4736 fab
.fab$b_fns
= strlen (new);
4738 status
= SYS$
PARSE (&fab
);
4739 if ((status
& 1) == 0)
4742 vaxc$errno
= status
;
4746 nam
.nam$w_fid
[0] = fid
[0];
4747 nam
.nam$w_fid
[1] = fid
[1];
4748 nam
.nam$w_fid
[2] = fid
[2];
4750 nam
.nam$l_esa
= nam
.nam$l_name
;
4751 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
4753 status
= SYS$
ENTER (&fab
);
4754 if ((status
& 1) == 0)
4757 vaxc$errno
= status
;
4767 printf ("%s not yet implemented\r\n", badfunc
);
4775 /* Arrange to return a range centered on zero. */
4776 return rand () - (1 << 30);
4787 /* Called from init_sys_modes. */
4792 /* If we're not on an HFT we shouldn't do any of this. We determine
4793 if we are on an HFT by trying to get an HFT error code. If this
4794 call fails, we're not on an HFT. */
4796 if (ioctl (0, HFQERROR
, &junk
) < 0)
4798 #else /* not IBMR2AIX */
4799 if (ioctl (0, HFQEIO
, 0) < 0)
4801 #endif /* not IBMR2AIX */
4803 /* On AIX the default hft keyboard mapping uses backspace rather than delete
4804 as the rubout key's ASCII code. Here this is changed. The bug is that
4805 there's no way to determine the old mapping, so in reset_sys_modes
4806 we need to assume that the normal map had been present. Of course, this
4807 code also doesn't help if on a terminal emulator which doesn't understand
4811 struct hfkeymap keymap
;
4813 buf
.hf_bufp
= (char *)&keymap
;
4814 buf
.hf_buflen
= sizeof (keymap
);
4815 keymap
.hf_nkeys
= 2;
4816 keymap
.hfkey
[0].hf_kpos
= 15;
4817 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4819 keymap
.hfkey
[0].hf_keyidh
= '<';
4820 #else /* not IBMR2AIX */
4821 keymap
.hfkey
[0].hf_page
= '<';
4822 #endif /* not IBMR2AIX */
4823 keymap
.hfkey
[0].hf_char
= 127;
4824 keymap
.hfkey
[1].hf_kpos
= 15;
4825 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4827 keymap
.hfkey
[1].hf_keyidh
= '<';
4828 #else /* not IBMR2AIX */
4829 keymap
.hfkey
[1].hf_page
= '<';
4830 #endif /* not IBMR2AIX */
4831 keymap
.hfkey
[1].hf_char
= 127;
4832 hftctl (0, HFSKBD
, &buf
);
4834 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
4836 line_ins_del_ok
= char_ins_del_ok
= 0;
4839 /* Reset the rubout key to backspace. */
4844 struct hfkeymap keymap
;
4848 if (ioctl (0, HFQERROR
, &junk
) < 0)
4850 #else /* not IBMR2AIX */
4851 if (ioctl (0, HFQEIO
, 0) < 0)
4853 #endif /* not IBMR2AIX */
4855 buf
.hf_bufp
= (char *)&keymap
;
4856 buf
.hf_buflen
= sizeof (keymap
);
4857 keymap
.hf_nkeys
= 2;
4858 keymap
.hfkey
[0].hf_kpos
= 15;
4859 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4861 keymap
.hfkey
[0].hf_keyidh
= '<';
4862 #else /* not IBMR2AIX */
4863 keymap
.hfkey
[0].hf_page
= '<';
4864 #endif /* not IBMR2AIX */
4865 keymap
.hfkey
[0].hf_char
= 8;
4866 keymap
.hfkey
[1].hf_kpos
= 15;
4867 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4869 keymap
.hfkey
[1].hf_keyidh
= '<';
4870 #else /* not IBMR2AIX */
4871 keymap
.hfkey
[1].hf_page
= '<';
4872 #endif /* not IBMR2AIX */
4873 keymap
.hfkey
[1].hf_char
= 8;
4874 hftctl (0, HFSKBD
, &buf
);
4881 /* These are included on Sunos 4.1 when we do not use shared libraries.
4882 X11 libraries may refer to these functions but (we hope) do not
4883 actually call them. */
4903 #endif /* USE_DL_STUBS */