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 normaly zero except when using X;
197 under VMS, we place the input channel number here.
198 This allows us to write more code that works for both VMS and Unix. */
201 /* Specify a different file descriptor for further input operations. */
210 /* Discard pending input on descriptor input_fd. */
214 struct emacs_tty buf
;
219 /* Discarding input is not safe when the input could contain
220 replies from the X server. So don't do it. */
221 if (read_socket_hook
)
226 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
227 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
233 ioctl (input_fd
, TIOCFLUSH
, &zero
);
235 #else /* not Apollo */
236 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
237 while (dos_keyread () != -1)
239 #else /* not MSDOS */
240 EMACS_GET_TTY (input_fd
, &buf
);
241 EMACS_SET_TTY (input_fd
, &buf
, 0);
242 #endif /* not MSDOS */
243 #endif /* not Apollo */
249 /* Arrange for character C to be read as the next input from
255 /* Should perhaps error if in batch mode */
257 ioctl (input_fd
, TIOCSTI
, &c
);
258 #else /* no TIOCSTI */
259 error ("Cannot stuff terminal input characters in this version of Unix");
260 #endif /* no TIOCSTI */
277 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
278 &sg
.class, 12, 0, 0, 0, 0 );
279 ospeed
= sg
.xmit_baud
;
285 tcgetattr (input_fd
, &sg
);
286 ospeed
= cfgetospeed (&sg
);
287 #if defined (USE_GETOBAUD) && defined (getobaud)
288 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
290 ospeed
= getobaud (sg
.c_cflag
);
292 #else /* neither VMS nor TERMIOS */
298 tcgetattr (input_fd
, &sg
);
300 ioctl (input_fd
, TCGETA
, &sg
);
302 ospeed
= sg
.c_cflag
& CBAUD
;
303 #else /* neither VMS nor TERMIOS nor TERMIO */
306 sg
.sg_ospeed
= B9600
;
307 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
309 ospeed
= sg
.sg_ospeed
;
310 #endif /* not HAVE_TERMIO */
311 #endif /* not HAVE_TERMIOS */
313 #endif /* not MSDOS */
316 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
317 ? baud_convert
[ospeed
] : 9600);
323 set_exclusive_use (fd
)
327 ioctl (fd
, FIOCLEX
, 0);
329 /* Ok to do nothing if this feature does not exist */
334 wait_without_blocking ()
337 wait3 (0, WNOHANG
| WUNTRACED
, 0);
339 croak ("wait_without_blocking");
341 synch_process_alive
= 0;
344 #endif /* not subprocesses */
346 int wait_debugging
; /* Set nonzero to make following function work under dbx
347 (at least for bsd). */
350 wait_for_termination_signal ()
353 /* Wait for subprocess with process id `pid' to terminate and
354 make sure it will get eliminated (not remain forever as a zombie) */
356 wait_for_termination (pid
)
365 status
= SYS$
FORCEX (&pid
, 0, 0);
368 #if defined (BSD) || (defined (HPUX) && !defined (HPUX_5))
369 /* Note that kill returns -1 even if the process is just a zombie now.
370 But inevitably a SIGCHLD interrupt should be generated
371 and child_sig will do wait3 and make the process go away. */
372 /* There is some indication that there is a bug involved with
373 termination of subprocesses, perhaps involving a kernel bug too,
374 but no idea what it is. Just as a hunch we signal SIGCHLD to see
375 if that causes the problem to go away or get worse. */
376 sigsetmask (sigmask (SIGCHLD
));
377 if (0 > kill (pid
, 0))
379 sigsetmask (SIGEMPTYMASK
);
380 kill (getpid (), SIGCHLD
);
386 sigpause (SIGEMPTYMASK
);
387 #else /* not BSD, and not HPUX version >= 6 */
388 #if defined (UNIPLUS)
389 if (0 > kill (pid
, 0))
392 #else /* neither BSD nor UNIPLUS: random sysV */
393 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
394 sigblock (sigmask (SIGCHLD
));
395 if (0 > kill (pid
, 0))
397 sigunblock (sigmask (SIGCHLD
));
400 sigpause (SIGEMPTYMASK
);
401 #else /* not POSIX_SIGNALS */
402 #ifdef HAVE_SYSV_SIGPAUSE
404 if (0 > kill (pid
, 0))
410 #else /* not HAVE_SYSV_SIGPAUSE */
411 if (0 > kill (pid
, 0))
413 /* Using sleep instead of pause avoids timing error.
414 If the inferior dies just before the sleep,
415 we lose just one second. */
417 #endif /* not HAVE_SYSV_SIGPAUSE */
418 #endif /* not POSIX_SIGNALS */
419 #endif /* not UNIPLUS */
420 #endif /* not BSD, and not HPUX version >= 6 */
422 #else /* not subprocesses */
424 if (kill (pid
, 0) < 0)
430 if (status
== pid
|| status
== -1)
433 #endif /* not subprocesses */
440 * flush any pending output
441 * (may flush input as well; it does not matter the way we use it)
444 flush_pending_output (channel
)
448 /* If we try this, we get hit with SIGTTIN, because
449 the child's tty belongs to the child's pgrp. */
452 ioctl (channel
, TCFLSH
, 1);
456 /* 3rd arg should be ignored
457 but some 4.2 kernels actually want the address of an int
458 and nonzero means something different. */
459 ioctl (channel
, TIOCFLUSH
, &zero
);
466 /* Set up the terminal at the other end of a pseudo-terminal that
467 we will be controlling an inferior through.
468 It should not echo or do line-editing, since that is done
469 in Emacs. No padding needed for insertion into an Emacs buffer. */
471 child_setup_tty (out
)
477 EMACS_GET_TTY (out
, &s
);
479 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
480 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
481 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
483 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
484 /* No output delays */
486 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
487 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
489 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
492 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
494 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
496 /* Said to be unnecessary: */
497 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
498 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
501 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
502 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
503 s
.main
.c_cc
[VERASE
] = 0377; /* disable erase processing */
504 s
.main
.c_cc
[VKILL
] = 0377; /* disable kill processing */
507 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
511 /* AIX enhanced edit loses NULs, so disable it */
514 s
.main
.c_iflag
&= ~ASCEDIT
;
516 /* Also, PTY overloads NUL and BREAK.
517 don't ignore break, but don't signal either, so it looks like NUL. */
518 s
.main
.c_iflag
&= ~IGNBRK
;
519 s
.main
.c_iflag
&= ~BRKINT
;
520 /* QUIT and INTR work better as signals, so disable character forms */
521 s
.main
.c_cc
[VINTR
] = 0377;
522 #ifdef SIGNALS_VIA_CHARACTERS
523 /* the QUIT and INTR character are used in process_send_signal
524 so set them here to something useful. */
525 if (s
.main
.c_cc
[VQUIT
] == 0377)
526 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
527 if (s
.main
.c_cc
[VINTR
] == 0377)
528 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
529 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
530 /* QUIT and INTR work better as signals, so disable character forms */
531 s
.main
.c_cc
[VQUIT
] = 0377;
532 s
.main
.c_cc
[VINTR
] = 0377;
533 s
.main
.c_lflag
&= ~ISIG
;
534 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
535 s
.main
.c_cc
[VEOL
] = 0377;
536 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
539 #else /* not HAVE_TERMIO */
541 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
543 s
.main
.sg_flags
|= LPASS8
;
544 s
.main
.sg_erase
= 0377;
545 s
.main
.sg_kill
= 0377;
546 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
548 #endif /* not HAVE_TERMIO */
550 EMACS_SET_TTY (out
, &s
, 0);
559 ioctl (out
, FIOASYNC
, &zero
);
562 #endif /* not MSDOS */
566 #endif /* subprocesses */
572 EMACS_SET_TTY_PGRP (input_fd
, &pid
);
575 /* Record a signal code and the handler for it. */
579 SIGTYPE (*handler
) ();
582 /* Suspend the Emacs process; give terminal to its superior. */
587 /* "Foster" parentage allows emacs to return to a subprocess that attached
588 to the current emacs as a cheaper than starting a whole new process. This
589 is set up by KEPTEDITOR.COM. */
590 unsigned long parent_id
, foster_parent_id
;
593 fpid_string
= getenv ("EMACS_PARENT_PID");
594 if (fpid_string
!= NULL
)
596 sscanf (fpid_string
, "%x", &foster_parent_id
);
597 if (foster_parent_id
!= 0)
598 parent_id
= foster_parent_id
;
600 parent_id
= getppid ();
603 parent_id
= getppid ();
605 xfree (fpid_string
); /* On VMS, this was malloc'd */
607 if (parent_id
&& parent_id
!= 0xffffffff)
609 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
610 int status
= LIB$
ATTACH (&parent_id
) & 1;
611 signal (SIGINT
, oldsig
);
620 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
621 d_prompt
.a
= "Emacs: "; /* Just a reminder */
622 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
627 #if defined(SIGTSTP) && !defined(MSDOS)
630 int pgrp
= EMACS_GETPGRP (0);
631 EMACS_KILLPG (pgrp
, SIGTSTP
);
634 #else /* No SIGTSTP */
635 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
636 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
637 kill (getpid (), SIGQUIT
);
639 #else /* No SIGTSTP or USG_JOBCTRL */
641 /* On a system where suspending is not implemented,
642 instead fork a subshell and let it talk directly to the terminal
646 #endif /* no USG_JOBCTRL */
647 #endif /* no SIGTSTP */
651 /* Fork a subshell. */
656 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
658 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
661 struct save_signal saved_handlers
[5];
663 unsigned char *str
= 0;
666 saved_handlers
[0].code
= SIGINT
;
667 saved_handlers
[1].code
= SIGQUIT
;
668 saved_handlers
[2].code
= SIGTERM
;
670 saved_handlers
[3].code
= SIGIO
;
671 saved_handlers
[4].code
= 0;
673 saved_handlers
[3].code
= 0;
676 /* Mentioning current_buffer->buffer would mean including buffer.h,
677 which somehow wedges the hp compiler. So instead... */
679 dir
= intern ("default-directory");
681 if (XFASTINT (Fboundp (dir
)) == XFASTINT (Qnil
))
683 dir
= Fsymbol_value (dir
);
687 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
688 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
689 len
= XSTRING (dir
)->size
;
690 bcopy (XSTRING (dir
)->data
, str
, len
);
691 if (str
[len
- 1] != '/') str
[len
++] = '/';
698 error ("Can't spawn subshell");
703 #ifdef MSDOS /* MW, Aug 1993 */
706 sh
= (char *) egetenv ("SHELL");
710 /* Use our buffer's default directory for the subshell. */
715 close_process_descs (); /* Close Emacs's pipes/ptys */
718 #ifdef SET_EMACS_PRIORITY
720 extern int emacs_priority
;
722 if (emacs_priority
< 0)
723 nice (-emacs_priority
);
727 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
731 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
732 #else /* not MSDOS */
734 write (1, "Can't execute subshell", 22);
736 #endif /* not MSDOS */
739 save_signal_handlers (saved_handlers
);
740 synch_process_alive
= 1;
741 wait_for_termination (pid
);
742 restore_signal_handlers (saved_handlers
);
746 save_signal_handlers (saved_handlers
)
747 struct save_signal
*saved_handlers
;
749 while (saved_handlers
->code
)
751 saved_handlers
->handler
752 = (SIGTYPE (*) ()) signal (saved_handlers
->code
, SIG_IGN
);
757 restore_signal_handlers (saved_handlers
)
758 struct save_signal
*saved_handlers
;
760 while (saved_handlers
->code
)
762 signal (saved_handlers
->code
, saved_handlers
->handler
);
774 old_fcntl_flags
= fcntl (input_fd
, F_GETFL
, 0) & ~FASYNC
;
784 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
789 sigunblock (sigmask (SIGWINCH
));
791 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
793 interrupts_deferred
= 0;
799 sigblock (sigmask (SIGWINCH
));
801 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
802 interrupts_deferred
= 1;
805 #else /* no FASYNC */
806 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
811 ioctl (input_fd
, FIOASYNC
, &on
);
812 interrupts_deferred
= 0;
819 ioctl (input_fd
, FIOASYNC
, &off
);
820 interrupts_deferred
= 1;
823 #else /* not FASYNC, not STRIDE */
835 sigaddset(&st
, SIGIO
);
836 ioctl (input_fd
, FIOASYNC
, &on
);
837 interrupts_deferred
= 0;
838 sigprocmask(SIG_UNBLOCK
, &st
, (sigset_t
*)0);
845 ioctl (input_fd
, FIOASYNC
, &off
);
846 interrupts_deferred
= 1;
853 croak ("request_sigio");
858 croak ("unrequest_sigio");
866 /* Saving and restoring the process group of Emacs's terminal. */
870 /* The process group of which Emacs was a member when it initially
873 If Emacs was in its own process group (i.e. inherited_pgroup ==
874 getpid ()), then we know we're running under a shell with job
875 control (Emacs would never be run as part of a pipeline).
878 If Emacs was not in its own process group, then we know we're
879 running under a shell (or a caller) that doesn't know how to
880 separate itself from Emacs (like sh). Emacs must be in its own
881 process group in order to receive SIGIO correctly. In this
882 situation, we put ourselves in our own pgroup, forcibly set the
883 tty's pgroup to our pgroup, and make sure to restore and reinstate
884 the tty's pgroup just like any other terminal setting. If
885 inherited_group was not the tty's pgroup, then we'll get a
886 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
887 it goes foreground in the future, which is what should happen. */
888 int inherited_pgroup
;
890 /* Split off the foreground process group to Emacs alone.
891 When we are in the foreground, but not started in our own process
892 group, redirect the TTY to point to our own process group. We need
893 to be in our own process group to receive SIGIO properly. */
894 narrow_foreground_group ()
898 setpgrp (0, inherited_pgroup
);
899 if (inherited_pgroup
!= me
)
900 EMACS_SET_TTY_PGRP (input_fd
, &me
);
904 /* Set the tty to our original foreground group. */
905 widen_foreground_group ()
907 if (inherited_pgroup
!= getpid ())
908 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
909 setpgrp (0, inherited_pgroup
);
912 #endif /* BSD_PGRPS */
914 /* Getting and setting emacs_tty structures. */
916 /* Set *TC to the parameters associated with the terminal FD.
917 Return zero if all's well, or -1 if we ran into an error we
918 couldn't deal with. */
920 emacs_get_tty (fd
, settings
)
922 struct emacs_tty
*settings
;
924 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
926 /* We have those nifty POSIX tcmumbleattr functions. */
927 if (tcgetattr (fd
, &settings
->main
) < 0)
932 /* The SYSV-style interface? */
933 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
938 /* Vehemently Monstrous System? :-) */
939 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
940 &settings
->main
.class, 12, 0, 0, 0, 0)
946 /* I give up - I hope you have the BSD ioctls. */
947 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
949 #endif /* not MSDOS */
954 /* Suivant - Do we have to get struct ltchars data? */
956 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
960 /* How about a struct tchars and a wordful of lmode bits? */
962 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
963 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
967 /* We have survived the tempest. */
972 /* Set the parameters of the tty on FD according to the contents of
973 *SETTINGS. If WAITP is non-zero, we wait for all queued output to
974 be written before making the change; otherwise, we forget any
975 queued input and make the change immediately.
976 Return 0 if all went well, and -1 if anything failed. */
978 emacs_set_tty (fd
, settings
, waitp
)
980 struct emacs_tty
*settings
;
983 /* Set the primary parameters - baud rate, character size, etcetera. */
986 /* We have those nifty POSIX tcmumbleattr functions.
987 William J. Smith <wjs@wiis.wang.com> writes:
988 "POSIX 1003.1 defines tcsetattr() to return success if it was
989 able to perform any of the requested actions, even if some
990 of the requested actions could not be performed.
991 We must read settings back to ensure tty setup properly.
992 AIX requires this to keep tty from hanging occasionally." */
993 /* This make sure that we don't loop indefinitely in here. */
994 for (i
= 0 ; i
< 10 ; i
++)
995 if (tcsetattr (fd
, waitp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1006 /* Get the current settings, and see if they're what we asked for. */
1007 tcgetattr (fd
, &new);
1008 /* We cannot use memcmp on the whole structure here because under
1009 * aix386 the termios structure has some reserved field that may
1012 if ( new.c_iflag
== settings
->main
.c_iflag
1013 && new.c_oflag
== settings
->main
.c_oflag
1014 && new.c_cflag
== settings
->main
.c_cflag
1015 && new.c_lflag
== settings
->main
.c_lflag
1016 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1024 /* The SYSV-style interface? */
1025 if (ioctl (fd
, waitp
? TCSETAW
: TCSETAF
, &settings
->main
) < 0)
1030 /* Vehemently Monstrous System? :-) */
1031 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1032 &settings
->main
.class, 12, 0, 0, 0, 0)
1038 /* I give up - I hope you have the BSD ioctls. */
1039 if (ioctl (fd
, (waitp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1041 #endif /* not MSDOS */
1047 /* Suivant - Do we have to get struct ltchars data? */
1049 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1053 /* How about a struct tchars and a wordful of lmode bits? */
1055 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1056 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1060 /* We have survived the tempest. */
1065 /* The initial tty mode bits */
1066 struct emacs_tty old_tty
;
1068 int term_initted
; /* 1 if outer tty status has been recorded */
1071 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1076 #ifndef F_SETOWN_BUG
1078 int old_fcntl_owner
;
1079 #endif /* F_SETOWN */
1080 #endif /* F_SETOWN_BUG */
1082 /* This may also be defined in stdio,
1083 but if so, this does no harm,
1084 and using the same name avoids wasting the other one's space. */
1086 #if defined (USG) || defined (DGUX)
1087 unsigned char _sobuf
[BUFSIZ
+8];
1089 char _sobuf
[BUFSIZ
];
1093 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1096 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1101 struct emacs_tty tty
;
1105 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1106 extern int (*interrupt_signal
) ();
1115 input_ef
= get_kbd_event_flag ();
1116 /* LIB$GET_EF (&input_ef); */
1117 SYS$
CLREF (input_ef
);
1118 waiting_for_ast
= 0;
1120 timer_ef
= get_timer_event_flag ();
1121 /* LIB$GET_EF (&timer_ef); */
1122 SYS$
CLREF (timer_ef
);
1126 LIB$
GET_EF (&process_ef
);
1127 SYS$
CLREF (process_ef
);
1129 if (input_ef
/ 32 != process_ef
/ 32)
1130 croak ("Input and process event flags in different clusters.");
1132 if (input_ef
/ 32 != timer_ef
/ 32)
1133 croak ("Input and timer event flags in different clusters.");
1135 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1136 ((unsigned) 1 << (process_ef
% 32));
1138 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1139 ((unsigned) 1 << (timer_ef
% 32));
1141 sys_access_reinit ();
1143 #endif /* not VMS */
1146 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1147 narrow_foreground_group ();
1150 EMACS_GET_TTY (input_fd
, &old_tty
);
1152 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1156 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1158 /* This allows meta to be sent on 8th bit. */
1159 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1161 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1162 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1164 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1166 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1167 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1169 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1171 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1174 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1176 tty
.main
.c_iflag
&= ~IXANY
;
1180 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1181 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1183 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1187 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1188 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1191 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1192 /* Set up C-g for both SIGQUIT and SIGINT.
1193 We don't know which we will get, but we handle both alike
1194 so which one it really gives us does not matter. */
1195 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1196 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1197 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1199 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1202 #if defined (mips) || defined (HAVE_TCATTR)
1204 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1207 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1208 #endif /* V_DSUSP */
1209 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1210 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1213 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1216 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1217 #endif /* VREPRINT */
1219 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1220 #endif /* VWERASE */
1222 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1223 #endif /* VDISCARD */
1225 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1228 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1230 #endif /* mips or HAVE_TCATTR */
1233 /* AIX enhanced edit loses NULs, so disable it */
1234 tty
.main
.c_line
= 0;
1235 tty
.main
.c_iflag
&= ~ASCEDIT
;
1237 tty
.main
.c_cc
[VSTRT
] = 255;
1238 tty
.main
.c_cc
[VSTOP
] = 255;
1239 tty
.main
.c_cc
[VSUSP
] = 255;
1240 tty
.main
.c_cc
[VDSUSP
] = 255;
1241 #endif /* IBMR2AIX */
1242 /* Also, PTY overloads NUL and BREAK.
1243 don't ignore break, but don't signal either, so it looks like NUL.
1244 This really serves a purpose only if running in an XTERM window
1245 or via TELNET or the like, but does no harm elsewhere. */
1246 tty
.main
.c_iflag
&= ~IGNBRK
;
1247 tty
.main
.c_iflag
&= ~BRKINT
;
1249 #else /* if not HAVE_TERMIO */
1251 tty
.main
.tt_char
|= TT$M_NOECHO
;
1253 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1255 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1257 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1258 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1259 #else /* not VMS (BSD, that is) */
1261 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1263 tty
.main
.sg_flags
|= ANYP
;
1264 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1266 #endif /* not VMS (BSD, that is) */
1267 #endif /* not HAVE_TERMIO */
1269 /* If going to use CBREAK mode, we must request C-g to interrupt
1270 and turn off start and stop chars, etc. If not going to use
1271 CBREAK mode, do this anyway so as to turn off local flow
1272 control for user coming over network on 4.2; in this case,
1273 only t_stopc and t_startc really matter. */
1276 /* Note: if not using CBREAK mode, it makes no difference how we
1278 tty
.tchars
= new_tchars
;
1279 tty
.tchars
.t_intrc
= quit_char
;
1282 tty
.tchars
.t_startc
= '\021';
1283 tty
.tchars
.t_stopc
= '\023';
1286 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1288 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1289 anything, and leaving it in breaks the meta key. Go figure. */
1290 tty
.lmode
&= ~LLITOUT
;
1297 #endif /* HAVE_TCHARS */
1298 #endif /* not HAVE_TERMIO */
1301 tty
.ltchars
= new_ltchars
;
1302 #endif /* HAVE_LTCHARS */
1303 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1304 internal_terminal_init ();
1308 EMACS_SET_TTY (input_fd
, &tty
, 0);
1310 /* This code added to insure that, if flow-control is not to be used,
1311 we have an unlocked terminal at the start. */
1314 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1318 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1326 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1327 to be only LF. This is the way that is done. */
1330 if (ioctl (1, HFTGETID
, &tty
) != -1)
1331 write (1, "\033[20l", 5);
1337 /* Appears to do nothing when in PASTHRU mode.
1338 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1339 interrupt_signal, oob_chars, 0, 0, 0, 0);
1341 queue_kbd_input (0);
1346 #ifndef F_SETOWN_BUG
1347 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1349 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1351 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1352 fcntl (input_fd
, F_SETOWN
, getpid ());
1355 #endif /* F_GETOWN */
1356 #endif /* F_SETOWN_BUG */
1357 #endif /* F_SETFL */
1360 if (interrupt_input
)
1364 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1368 /* This symbol is defined on recent USG systems.
1369 Someone says without this call USG won't really buffer the file
1370 even with a call to setbuf. */
1371 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
1373 setbuf (stdout
, _sobuf
);
1375 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1376 set_terminal_modes ();
1378 if (term_initted
&& no_redraw_on_reenter
)
1380 if (display_completed
)
1381 direct_output_forward_char (0);
1387 if (FRAMEP (Vterminal_frame
))
1388 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1395 /* Return nonzero if safe to use tabs in output.
1396 At the time this is called, init_sys_modes has not been done yet. */
1400 struct emacs_tty tty
;
1402 EMACS_GET_TTY (input_fd
, &tty
);
1403 return EMACS_TTY_TABS_OK (&tty
);
1406 /* Get terminal size from system.
1407 Store number of lines into *HEIGHTP and width into *WIDTHP.
1408 We store 0 if there's no valid information. */
1410 get_frame_size (widthp
, heightp
)
1411 int *widthp
, *heightp
;
1417 struct winsize size
;
1419 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1420 *widthp
= *heightp
= 0;
1423 *widthp
= size
.ws_col
;
1424 *heightp
= size
.ws_row
;
1430 /* SunOS - style. */
1431 struct ttysize size
;
1433 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1434 *widthp
= *heightp
= 0;
1437 *widthp
= size
.ts_cols
;
1438 *heightp
= size
.ts_lines
;
1444 struct sensemode tty
;
1446 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1447 &tty
.class, 12, 0, 0, 0, 0);
1448 *widthp
= tty
.scr_wid
;
1449 *heightp
= tty
.scr_len
;
1453 *widthp
= ScreenCols ();
1454 *heightp
= ScreenRows ();
1455 #else /* system doesn't know size */
1460 #endif /* not VMS */
1461 #endif /* not SunOS-style */
1462 #endif /* not BSD-style */
1465 /* Set the logical window size associated with descriptor FD
1466 to HEIGHT and WIDTH. This is used mainly with ptys. */
1469 set_window_size (fd
, height
, width
)
1470 int fd
, height
, width
;
1475 struct winsize size
;
1476 size
.ws_row
= height
;
1477 size
.ws_col
= width
;
1479 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1480 return 0; /* error */
1487 /* SunOS - style. */
1488 struct ttysize size
;
1489 size
.ts_lines
= height
;
1490 size
.ts_cols
= width
;
1492 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1498 #endif /* not SunOS-style */
1499 #endif /* not BSD-style */
1503 /* Prepare the terminal for exiting Emacs; move the cursor to the
1504 bottom of the frame, turn off interrupt-driven I/O, etc. */
1514 if (read_socket_hook
|| !EQ (Vwindow_system
, Qnil
))
1516 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1517 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1518 /* clear_end_of_line may move the cursor */
1519 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1522 /* HFT devices normally use ^J as a LF/CR. We forced it to
1523 do the LF only. Now, we need to reset it. */
1526 if (ioctl (1, HFTGETID
, &tty
) != -1)
1527 write (1, "\033[20h", 5);
1531 reset_terminal_modes ();
1535 /* Avoid possible loss of output when changing terminal modes. */
1536 fsync (fileno (stdout
));
1541 #ifndef F_SETOWN_BUG
1542 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1543 if (interrupt_input
)
1546 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1548 #endif /* F_SETOWN */
1549 #endif /* F_SETOWN_BUG */
1551 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1553 #endif /* F_SETFL */
1555 if (interrupt_input
)
1559 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1562 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1571 widen_foreground_group ();
1577 /* Set up the proper status flags for use of a pty. */
1582 /* I'm told that TOICREMOTE does not mean control chars
1583 "can't be sent" but rather that they don't have
1584 input-editing or signaling effects.
1585 That should be good, because we have other ways
1586 to do those things in Emacs.
1587 However, telnet mode seems not to work on 4.2.
1588 So TIOCREMOTE is turned off now. */
1590 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1591 will hang. In particular, the "timeout" feature (which
1592 causes a read to return if there is no data available)
1593 does this. Also it is known that telnet mode will hang
1594 in such a way that Emacs must be stopped (perhaps this
1595 is the same problem).
1597 If TIOCREMOTE is turned off, then there is a bug in
1598 hp-ux which sometimes loses data. Apparently the
1599 code which blocks the master process when the internal
1600 buffer fills up does not work. Other than this,
1601 though, everything else seems to work fine.
1603 Since the latter lossage is more benign, we may as well
1604 lose that way. -- cph */
1609 ioctl (fd
, FIONBIO
, &on
);
1614 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1615 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1616 /* cause EMACS not to die when it should, i.e., when its own controlling */
1617 /* tty goes away. I've complained to the AIX developers, and they may */
1618 /* change this behavior, but I'm not going to hold my breath. */
1619 signal (SIGHUP
, SIG_IGN
);
1622 #endif /* HAVE_PTYS */
1626 /* Assigning an input channel is done at the start of Emacs execution.
1627 This is called each time Emacs is resumed, also, but does nothing
1628 because input_chain is no longer zero. */
1636 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1642 /* Deassigning the input channel is done before exiting. */
1646 return SYS$
DASSGN (input_fd
);
1651 /* Request reading one character into the keyboard buffer.
1652 This is done as soon as the buffer becomes empty. */
1657 extern kbd_input_ast ();
1659 waiting_for_ast
= 0;
1661 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1662 &input_iosb
, kbd_input_ast
, 1,
1663 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1668 /* Ast routine that is called when keyboard input comes in
1669 in accord with the SYS$QIO above. */
1673 register int c
= -1;
1674 int old_errno
= errno
;
1675 extern EMACS_TIME
*input_available_clear_time
;
1677 if (waiting_for_ast
)
1678 SYS$
SETEF (input_ef
);
1679 waiting_for_ast
= 0;
1682 if (input_count
== 25)
1684 printf ("Ast # %d,", input_count
);
1685 printf (" iosb = %x, %x, %x, %x",
1686 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1689 if (input_iosb
.offset
)
1693 printf (", char = 0%o", c
);
1705 struct input_event e
;
1706 e
.kind
= ascii_keystroke
;
1707 XSET (e
.code
, Lisp_Int
, c
);
1709 XSET(e
.frame_or_window
, Lisp_Frame
, selected_frame
);
1711 e
.frame_or_window
= Qnil
;
1713 kbd_buffer_store_event (&e
);
1715 if (input_available_clear_time
)
1716 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1720 /* Wait until there is something in kbd_buffer. */
1722 wait_for_kbd_input ()
1724 extern int have_process_input
, process_exited
;
1726 /* If already something, avoid doing system calls. */
1727 if (detect_input_pending ())
1731 /* Clear a flag, and tell ast routine above to set it. */
1732 SYS$
CLREF (input_ef
);
1733 waiting_for_ast
= 1;
1734 /* Check for timing error: ast happened while we were doing that. */
1735 if (!detect_input_pending ())
1737 /* No timing error: wait for flag to be set. */
1738 set_waiting_for_input (0);
1739 SYS$
WFLOR (input_ef
, input_eflist
);
1740 clear_waiting_for_input (0);
1741 if (!detect_input_pending ())
1742 /* Check for subprocess input availability */
1744 int dsp
= have_process_input
|| process_exited
;
1746 SYS$
CLREF (process_ef
);
1747 if (have_process_input
)
1748 process_command_input ();
1753 update_mode_lines
++;
1754 prepare_menu_bars ();
1755 redisplay_preserve_echo_area ();
1759 waiting_for_ast
= 0;
1762 /* Get rid of any pending QIO, when we are about to suspend
1763 or when we want to throw away pending input.
1764 We wait for a positive sign that the AST routine has run
1765 and therefore there is no I/O request queued when we return.
1766 SYS$SETAST is used to avoid a timing error. */
1771 printf ("At end_kbd_input.\n");
1775 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
1777 SYS$
CANCEL (input_fd
);
1782 /* Clear a flag, and tell ast routine above to set it. */
1783 SYS$
CLREF (input_ef
);
1784 waiting_for_ast
= 1;
1786 SYS$
CANCEL (input_fd
);
1788 SYS$
WAITFR (input_ef
);
1789 waiting_for_ast
= 0;
1792 /* Wait for either input available or time interval expiry. */
1794 input_wait_timeout (timeval
)
1795 int timeval
; /* Time to wait, in seconds */
1798 static int zero
= 0;
1799 static int large
= -10000000;
1801 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1803 /* If already something, avoid doing system calls. */
1804 if (detect_input_pending ())
1808 /* Clear a flag, and tell ast routine above to set it. */
1809 SYS$
CLREF (input_ef
);
1810 waiting_for_ast
= 1;
1811 /* Check for timing error: ast happened while we were doing that. */
1812 if (!detect_input_pending ())
1814 /* No timing error: wait for flag to be set. */
1816 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1817 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
1819 waiting_for_ast
= 0;
1822 /* The standard `sleep' routine works some other way
1823 and it stops working if you have ever quit out of it.
1824 This one continues to work. */
1830 static int zero
= 0;
1831 static int large
= -10000000;
1833 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1836 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1837 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
1852 croak ("request sigio");
1857 croak ("unrequest sigio");
1862 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
1867 #ifndef SYSTEM_MALLOC
1874 /* Some systems that cannot dump also cannot implement these. */
1877 * Return the address of the start of the text segment prior to
1878 * doing an unexec. After unexec the return value is undefined.
1879 * See crt0.c for further explanation and _start.
1883 #ifndef HAVE_TEXT_START
1888 return ((char *) TEXT_START
);
1892 return ((char *) csrt
);
1893 #else /* not GOULD */
1894 extern int _start ();
1895 return ((char *) _start
);
1897 #endif /* TEXT_START */
1899 #endif /* not HAVE_TEXT_START */
1902 * Return the address of the start of the data segment prior to
1903 * doing an unexec. After unexec the return value is undefined.
1904 * See crt0.c for further information and definition of data_start.
1906 * Apparently, on BSD systems this is etext at startup. On
1907 * USG systems (swapping) this is highly mmu dependent and
1908 * is also dependent on whether or not the program is running
1909 * with shared text. Generally there is a (possibly large)
1910 * gap between end of text and start of data with shared text.
1912 * On Uniplus+ systems with shared text, data starts at a
1913 * fixed address. Each port (from a given oem) is generally
1914 * different, and the specific value of the start of data can
1915 * be obtained via the UniPlus+ specific "uvar" system call,
1916 * however the method outlined in crt0.c seems to be more portable.
1918 * Probably what will have to happen when a USG unexec is available,
1919 * at least on UniPlus, is temacs will have to be made unshared so
1920 * that text and data are contiguous. Then once loadup is complete,
1921 * unexec will produce a shared executable where the data can be
1922 * at the normal shared text boundry and the startofdata variable
1923 * will be patched by unexec to the correct value.
1931 return ((char *) DATA_START
);
1933 #ifdef ORDINARY_LINK
1935 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
1936 * data_start isn't defined. We take the address of environ, which
1937 * is known to live at or near the start of the system crt0.c, and
1938 * we don't sweat the handful of bytes that might lose.
1940 extern char **environ
;
1942 return((char *) &environ
);
1944 extern int data_start
;
1945 return ((char *) &data_start
);
1946 #endif /* ORDINARY_LINK */
1947 #endif /* DATA_START */
1949 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
1952 /* Some systems that cannot dump also cannot implement these. */
1955 * Return the address of the end of the text segment prior to
1956 * doing an unexec. After unexec the return value is undefined.
1963 return ((char *) TEXT_END
);
1966 return ((char *) &etext
);
1971 * Return the address of the end of the data segment prior to
1972 * doing an unexec. After unexec the return value is undefined.
1979 return ((char *) DATA_END
);
1982 return ((char *) &edata
);
1986 #endif /* not CANNOT_DUMP */
1988 /* init_system_name sets up the string for the Lisp function
1989 system-name to return. */
1995 extern Lisp_Object Vsystem_name
;
2000 #include <sys/socket.h>
2002 #endif /* HAVE_SOCKETS */
2003 #endif /* not VMS */
2004 #endif /* not BSD4_1 */
2010 Vsystem_name
= build_string (sysname
);
2014 if ((sp
= egetenv ("SYS$NODE")) == 0)
2015 Vsystem_name
= build_string ("vax-vms");
2016 else if ((end
= index (sp
, ':')) == 0)
2017 Vsystem_name
= build_string (sp
);
2019 Vsystem_name
= make_string (sp
, end
- sp
);
2021 #ifndef HAVE_GETHOSTNAME
2024 Vsystem_name
= build_string (uts
.nodename
);
2025 #else /* HAVE_GETHOSTNAME */
2026 int hostname_size
= 256;
2027 char *hostname
= (char *) alloca (hostname_size
);
2029 /* Try to get the host name; if the buffer is too short, try
2030 again. Apparently, the only indication gethostname gives of
2031 whether the buffer was large enough is the presence or absence
2032 of a '\0' in the string. Eech. */
2035 gethostname (hostname
, hostname_size
- 1);
2036 hostname
[hostname_size
- 1] = '\0';
2038 /* Was the buffer large enough for the '\0'? */
2039 if (strlen (hostname
) < hostname_size
- 1)
2042 hostname_size
<<= 1;
2043 hostname
= (char *) alloca (hostname_size
);
2046 /* Turn the hostname into the official, fully-qualified hostname.
2047 Don't do this if we're going to dump; this can confuse system
2048 libraries on some machines and make the dumped emacs core dump. */
2051 #endif /* not CANNOT_DUMP */
2055 for (count
= 0; count
< 10; count
++)
2060 hp
= gethostbyname (hostname
);
2062 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2065 Fsleep_for (make_number (1), Qnil
);
2069 char *fqdn
= hp
->h_name
;
2072 if (!index (fqdn
, '.'))
2074 /* We still don't have a fully qualified domain name.
2075 Try to find one in the list of alternate names */
2076 char **alias
= hp
->h_aliases
;
2077 while (*alias
&& !index (*alias
, '.'))
2084 /* Convert the host name to lower case. */
2085 /* Using ctype.h here would introduce a possible locale
2086 dependence that is probably wrong for hostnames. */
2090 if (*p
>= 'A' && *p
<= 'Z')
2097 #endif /* HAVE_SOCKETS */
2098 Vsystem_name
= build_string (hostname
);
2099 #endif /* HAVE_GETHOSTNAME */
2104 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2105 if (*p
== ' ' || *p
== '\t')
2113 #ifdef HAVE_X_WINDOWS
2114 /* Cause explanatory error message at compile time,
2115 since the select emulation is not good enough for X. */
2116 int *x
= &x_windows_lose_if_no_select_system_call
;
2119 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2120 * Only checks read descriptors.
2122 /* How long to wait between checking fds in select */
2123 #define SELECT_PAUSE 1
2126 /* For longjmp'ing back to read_input_waiting. */
2128 jmp_buf read_alarm_throw
;
2130 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2131 The read_socket_hook function sets this to 1 while it is waiting. */
2133 int read_alarm_should_throw
;
2141 #else /* not BSD4_1 */
2142 signal (SIGALRM
, SIG_IGN
);
2143 #endif /* not BSD4_1 */
2144 if (read_alarm_should_throw
)
2145 longjmp (read_alarm_throw
, 1);
2148 /* Only rfds are checked. */
2150 select (nfds
, rfds
, wfds
, efds
, timeout
)
2152 int *rfds
, *wfds
, *efds
, *timeout
;
2154 int ravail
= 0, orfds
= 0, old_alarm
;
2155 int timeoutval
= timeout
? *timeout
: 100000;
2156 int *local_timeout
= &timeoutval
;
2157 extern int proc_buffered_char
[];
2158 #ifndef subprocesses
2159 int process_tick
= 0, update_tick
= 0;
2161 extern int process_tick
, update_tick
;
2163 SIGTYPE (*old_trap
) ();
2176 /* If we are looking only for the terminal, with no timeout,
2177 just read it and wait -- that's more efficient. */
2178 if (orfds
== 1 && *local_timeout
== 100000 && process_tick
== update_tick
)
2180 if (! detect_input_pending ())
2181 read_input_waiting ();
2186 /* Once a second, till the timer expires, check all the flagged read
2187 * descriptors to see if any input is available. If there is some then
2188 * set the corresponding bit in the return copy of rfds.
2192 register int to_check
, bit
, fd
;
2196 for (to_check
= nfds
, bit
= 1, fd
= 0; --to_check
>= 0; bit
<<= 1, fd
++)
2200 int avail
= 0, status
= 0;
2203 avail
= detect_input_pending (); /* Special keyboard handler */
2207 status
= ioctl (fd
, FIONREAD
, &avail
);
2208 #else /* no FIONREAD */
2210 abort (); /* I don't think we need it. */
2211 #else /* not MSDOS */
2212 /* Hoping it will return -1 if nothing available
2213 or 0 if all 0 chars requested are read. */
2214 if (proc_buffered_char
[fd
] >= 0)
2218 avail
= read (fd
, &buf
, 1);
2220 proc_buffered_char
[fd
] = buf
;
2222 #endif /* not MSDOS */
2223 #endif /* no FIONREAD */
2225 if (status
>= 0 && avail
> 0)
2233 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2235 old_alarm
= alarm (0);
2236 old_trap
= signal (SIGALRM
, select_alarm
);
2238 alarm (SELECT_PAUSE
);
2239 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2240 while (select_alarmed
== 0 && *local_timeout
!= 0
2241 && process_tick
== update_tick
)
2244 sleep_or_kbd_hit (SELECT_PAUSE
, (orfds
& 1) != 0);
2246 #else /* not MSDOS */
2247 /* If we are interested in terminal input,
2248 wait by reading the terminal.
2249 That makes instant wakeup for terminal input at least. */
2252 read_input_waiting ();
2253 if (detect_input_pending ())
2258 #endif /* not MSDOS */
2260 (*local_timeout
) -= SELECT_PAUSE
;
2261 /* Reset the old alarm if there was one */
2263 signal (SIGALRM
, old_trap
);
2266 /* Reset or forge an interrupt for the original handler. */
2267 old_alarm
-= SELECT_PAUSE
;
2269 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2273 if (*local_timeout
== 0) /* Stop on timer being cleared */
2279 /* Read keyboard input into the standard buffer,
2280 waiting for at least one character. */
2282 /* Make all keyboard buffers much bigger when using X windows. */
2283 #ifdef HAVE_X_WINDOWS
2284 #define BUFFER_SIZE_FACTOR 16
2286 #define BUFFER_SIZE_FACTOR 1
2289 read_input_waiting ()
2291 struct input_event e
;
2293 extern int quit_char
;
2295 if (read_socket_hook
)
2297 struct input_event buf
[256];
2299 read_alarm_should_throw
= 0;
2300 if (! setjmp (read_alarm_throw
))
2301 nread
= (*read_socket_hook
) (0, buf
, 256, 1, 0);
2305 /* Scan the chars for C-g and store them in kbd_buffer. */
2306 for (i
= 0; i
< nread
; i
++)
2308 kbd_buffer_store_event (&buf
[i
]);
2309 /* Don't look at input that follows a C-g too closely.
2310 This reduces lossage due to autorepeat on C-g. */
2311 if (buf
[i
].kind
== ascii_keystroke
2312 && XINT(buf
[i
].code
) == quit_char
)
2319 nread
= read (fileno (stdin
), buf
, 1);
2321 /* Scan the chars for C-g and store them in kbd_buffer. */
2322 e
.kind
= ascii_keystroke
;
2323 e
.frame_or_window
= selected_frame
;
2325 for (i
= 0; i
< nread
; i
++)
2327 /* Convert chars > 0177 to meta events if desired.
2328 We do this under the same conditions that read_avail_input does. */
2329 if (read_socket_hook
== 0)
2331 /* If the user says she has a meta key, then believe her. */
2332 if (meta_key
== 1 && (buf
[i
] & 0x80))
2333 e
.modifiers
= meta_modifier
;
2338 XSET (e
.code
, Lisp_Int
, buf
[i
]);
2339 kbd_buffer_store_event (&e
);
2340 /* Don't look at input that follows a C-g too closely.
2341 This reduces lossage due to autorepeat on C-g. */
2342 if (buf
[i
] == quit_char
)
2348 #endif /* not HAVE_SELECT */
2349 #endif /* not VMS */
2353 * Partially emulate 4.2 open call.
2354 * open is defined as this in 4.1.
2356 * - added by Michael Bloom @ Citicorp/TTI
2361 sys_open (path
, oflag
, mode
)
2365 if (oflag
& O_CREAT
)
2366 return creat (path
, mode
);
2368 return open (path
, oflag
);
2375 lmode
= LINTRUP
| lmode
;
2376 ioctl (0, TIOCLSET
, &lmode
);
2383 lmode
= ~LINTRUP
& lmode
;
2384 ioctl (0, TIOCLSET
, &lmode
);
2391 interrupts_deferred
= 0;
2398 interrupts_deferred
= 1;
2401 /* still inside #ifdef BSD4_1 */
2404 int sigheld
; /* Mask of held signals */
2409 sigheld
|= sigbit (signum
);
2416 sigheld
|= sigbit (signum
);
2422 sigheld
&= ~sigbit (signum
);
2426 sigfree () /* Free all held signals */
2429 for (i
= 0; i
< NSIG
; i
++)
2430 if (sigheld
& sigbit (i
))
2437 return 1 << (i
- 1);
2439 #endif /* subprocesses */
2442 /* POSIX signals support - DJB */
2443 /* Anyone with POSIX signals should have ANSI C declarations */
2445 #ifdef POSIX_SIGNALS
2447 sigset_t old_mask
, empty_mask
, full_mask
, temp_mask
;
2448 static struct sigaction new_action
, old_action
;
2452 sigemptyset (&empty_mask
);
2453 sigfillset (&full_mask
);
2457 sys_signal (int signal_number
, signal_handler_t action
)
2460 /* This gets us restartable system calls for efficiency.
2461 The "else" code will works as well. */
2462 return (berk_signal (signal_number
, action
));
2464 sigemptyset (&new_action
.sa_mask
);
2465 new_action
.sa_handler
= action
;
2467 /* Emacs mostly works better with restartable system services. If this
2468 * flag exists, we probably want to turn it on here.
2470 new_action
.sa_flags
= SA_RESTART
;
2472 new_action
.sa_flags
= 0;
2474 sigaction (signal_number
, &new_action
, &old_action
);
2475 return (old_action
.sa_handler
);
2480 /* If we're compiling with GCC, we don't need this function, since it
2481 can be written as a macro. */
2483 sys_sigmask (int sig
)
2486 sigemptyset (&mask
);
2487 sigaddset (&mask
, sig
);
2493 sys_sigpause (sigset_t new_mask
)
2495 /* pause emulating berk sigpause... */
2496 sigsuspend (&new_mask
);
2500 /* I'd like to have these guys return pointers to the mask storage in here,
2501 but there'd be trouble if the code was saving multiple masks. I'll be
2502 safe and pass the structure. It normally won't be more than 2 bytes
2506 sys_sigblock (sigset_t new_mask
)
2509 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2514 sys_sigunblock (sigset_t new_mask
)
2517 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2522 sys_sigsetmask (sigset_t new_mask
)
2525 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2529 #endif /* POSIX_SIGNALS */
2538 register int length
;
2542 long max_str
= 65535;
2544 while (length
> max_str
) {
2545 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
2550 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
2552 while (length
-- > 0)
2554 #endif /* not VMS */
2557 #endif /* no bzero */
2560 /* Saying `void' requires a declaration, above, where bcopy is used
2561 and that declaration causes pain for systems where bcopy is a macro. */
2562 bcopy (b1
, b2
, length
)
2565 register int length
;
2568 long max_str
= 65535;
2570 while (length
> max_str
) {
2571 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
2577 (void) LIB$
MOVC3 (&length
, b1
, b2
);
2579 while (length
-- > 0)
2581 #endif /* not VMS */
2583 #endif /* no bcopy */
2587 bcmp (b1
, b2
, length
) /* This could be a macro! */
2590 register int length
;
2593 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
2594 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
2596 return STR$
COMPARE (&src1
, &src2
);
2598 while (length
-- > 0)
2603 #endif /* not VMS */
2605 #endif /* no bcmp */
2607 #endif /* not BSTRING */
2613 * The BSD random returns numbers in the range of
2614 * 0 to 2e31 - 1. The USG rand returns numbers in the
2615 * range of 0 to 2e15 - 1. This is probably not significant
2625 /* The BSD rand returns numbers in the range of 0 to 2e31 - 1,
2626 with unusable least significant bits. The USG rand returns
2627 numbers in the range of 0 to 2e15 - 1, all usable. Let us
2628 build a usable 30 bit number from either. */
2630 return (rand () << 15) + rand ();
2632 return (rand () & 0x3fff8000) + (rand () >> 16);
2647 #endif /* no random */
2648 #endif /* not HAVE_RANDOM */
2650 #ifdef WRONG_NAME_INSQUE
2663 /* If any place else asks for the TERM variable,
2664 allow it to be overridden with the EMACS_TERM variable
2665 before attempting to translate the logical name TERM. As a last
2666 resort, ask for VAX C's special idea of the TERM variable. */
2673 static char buf
[256];
2674 static struct dsc$descriptor_s equiv
2675 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2676 static struct dsc$descriptor_s d_name
2677 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2680 if (!strcmp (name
, "TERM"))
2682 val
= (char *) getenv ("EMACS_TERM");
2687 d_name
.dsc$w_length
= strlen (name
);
2688 d_name
.dsc$a_pointer
= name
;
2689 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2691 char *str
= (char *) xmalloc (eqlen
+ 1);
2692 bcopy (buf
, str
, eqlen
);
2694 /* This is a storage leak, but a pain to fix. With luck,
2695 no one will ever notice. */
2698 return (char *) getenv (name
);
2703 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2704 to force a call on the debugger from within the image. */
2709 LIB$
SIGNAL (SS$_DEBUG
);
2715 #ifdef LINK_CRTL_SHARE
2716 #ifdef SHAREABLE_LIB_BUG
2717 /* Variables declared noshare and initialized in sharable libraries
2718 cannot be shared. The VMS linker incorrectly forces you to use a private
2719 version which is uninitialized... If not for this "feature", we
2720 could use the C library definition of sys_nerr and sys_errlist. */
2722 char *sys_errlist
[] =
2726 "no such file or directory",
2728 "interrupted system call",
2730 "no such device or address",
2731 "argument list too long",
2732 "exec format error",
2735 "no more processes",
2736 "not enough memory",
2737 "permission denied",
2739 "block device required",
2740 "mount devices busy",
2742 "cross-device link",
2747 "file table overflow",
2748 "too many open files",
2752 "no space left on device",
2754 "read-only file system",
2760 "vax/vms specific error code nontranslatable error"
2762 #endif /* SHAREABLE_LIB_BUG */
2763 #endif /* LINK_CRTL_SHARE */
2766 #ifndef HAVE_STRERROR
2771 extern char *sys_errlist
[];
2772 extern int sys_nerr
;
2774 if (errnum
>= 0 && errnum
< sys_nerr
)
2775 return sys_errlist
[errnum
];
2776 return (char *) "Unknown error";
2779 #endif /* ! HAVE_STRERROR */
2781 #ifdef INTERRUPTIBLE_OPEN
2785 sys_open (path
, oflag
, mode
)
2789 register int rtnval
;
2791 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2792 && (errno
== EINTR
));
2796 #endif /* INTERRUPTIBLE_OPEN */
2798 #ifdef INTERRUPTIBLE_CLOSE
2803 register int rtnval
;
2805 while ((rtnval
= close (fd
)) == -1
2806 && (errno
== EINTR
));
2810 #endif /* INTERRUPTIBLE_CLOSE */
2812 #ifdef INTERRUPTIBLE_IO
2815 sys_read (fildes
, buf
, nbyte
)
2820 register int rtnval
;
2822 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
2823 && (errno
== EINTR
));
2828 sys_write (fildes
, buf
, nbyte
)
2833 register int rtnval
, bytes_written
;
2839 rtnval
= write (fildes
, buf
, nbyte
);
2846 return (bytes_written
? bytes_written
: -1);
2851 bytes_written
+= rtnval
;
2853 return (bytes_written
);
2856 #endif /* INTERRUPTIBLE_IO */
2861 * Substitute fork for vfork on USG flavors.
2869 #endif /* not HAVE_VFORK */
2873 * All of the following are for USG.
2875 * On USG systems the system calls are INTERRUPTIBLE by signals
2876 * that the user program has elected to catch. Thus the system call
2877 * must be retried in these cases. To handle this without massive
2878 * changes in the source code, we remap the standard system call names
2879 * to names for our own functions in sysdep.c that do the system call
2880 * with retries. Actually, for portability reasons, it is good
2881 * programming practice, as this example shows, to limit all actual
2882 * system calls to a single occurrence in the source. Sure, this
2883 * adds an extra level of function call overhead but it is almost
2884 * always negligible. Fred Fish, Unisoft Systems Inc.
2887 #ifndef HAVE_SYS_SIGLIST
2888 char *sys_siglist
[NSIG
+ 1] =
2891 /* AIX has changed the signals a bit */
2892 "bogus signal", /* 0 */
2893 "hangup", /* 1 SIGHUP */
2894 "interrupt", /* 2 SIGINT */
2895 "quit", /* 3 SIGQUIT */
2896 "illegal instruction", /* 4 SIGILL */
2897 "trace trap", /* 5 SIGTRAP */
2898 "IOT instruction", /* 6 SIGIOT */
2899 "crash likely", /* 7 SIGDANGER */
2900 "floating point exception", /* 8 SIGFPE */
2901 "kill", /* 9 SIGKILL */
2902 "bus error", /* 10 SIGBUS */
2903 "segmentation violation", /* 11 SIGSEGV */
2904 "bad argument to system call", /* 12 SIGSYS */
2905 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2906 "alarm clock", /* 14 SIGALRM */
2907 "software termination signum", /* 15 SIGTERM */
2908 "user defined signal 1", /* 16 SIGUSR1 */
2909 "user defined signal 2", /* 17 SIGUSR2 */
2910 "death of a child", /* 18 SIGCLD */
2911 "power-fail restart", /* 19 SIGPWR */
2912 "bogus signal", /* 20 */
2913 "bogus signal", /* 21 */
2914 "bogus signal", /* 22 */
2915 "bogus signal", /* 23 */
2916 "bogus signal", /* 24 */
2917 "LAN I/O interrupt", /* 25 SIGAIO */
2918 "PTY I/O interrupt", /* 26 SIGPTY */
2919 "I/O intervention required", /* 27 SIGIOINT */
2920 "HFT grant", /* 28 SIGGRANT */
2921 "HFT retract", /* 29 SIGRETRACT */
2922 "HFT sound done", /* 30 SIGSOUND */
2923 "HFT input ready", /* 31 SIGMSG */
2925 "bogus signal", /* 0 */
2926 "hangup", /* 1 SIGHUP */
2927 "interrupt", /* 2 SIGINT */
2928 "quit", /* 3 SIGQUIT */
2929 "illegal instruction", /* 4 SIGILL */
2930 "trace trap", /* 5 SIGTRAP */
2931 "IOT instruction", /* 6 SIGIOT */
2932 "EMT instruction", /* 7 SIGEMT */
2933 "floating point exception", /* 8 SIGFPE */
2934 "kill", /* 9 SIGKILL */
2935 "bus error", /* 10 SIGBUS */
2936 "segmentation violation", /* 11 SIGSEGV */
2937 "bad argument to system call", /* 12 SIGSYS */
2938 "write on a pipe with no one to read it", /* 13 SIGPIPE */
2939 "alarm clock", /* 14 SIGALRM */
2940 "software termination signum", /* 15 SIGTERM */
2941 "user defined signal 1", /* 16 SIGUSR1 */
2942 "user defined signal 2", /* 17 SIGUSR2 */
2943 "death of a child", /* 18 SIGCLD */
2944 "power-fail restart", /* 19 SIGPWR */
2946 "window size change", /* 20 SIGWINCH */
2947 "urgent socket condition", /* 21 SIGURG */
2948 "pollable event occured", /* 22 SIGPOLL */
2949 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */
2950 "user stop requested from tty", /* 24 SIGTSTP */
2951 "stopped process has been continued", /* 25 SIGCONT */
2952 "background tty read attempted", /* 26 SIGTTIN */
2953 "background tty write attempted", /* 27 SIGTTOU */
2954 "virtual timer expired", /* 28 SIGVTALRM */
2955 "profiling timer expired", /* 29 SIGPROF */
2956 "exceeded cpu limit", /* 30 SIGXCPU */
2957 "exceeded file size limit", /* 31 SIGXFSZ */
2958 "process's lwps are blocked", /* 32 SIGWAITING */
2959 "special signal used by thread library", /* 33 SIGLWP */
2961 "Special Signal Used By CPR", /* 34 SIGFREEZE */
2964 "Special Signal Used By CPR", /* 35 SIGTHAW */
2967 #endif /* not AIX */
2970 #endif /* HAVE_SYS_SIGLIST */
2973 * Warning, this function may not duplicate 4.2 action properly
2974 * under error conditions.
2978 /* In 4.1, param.h fails to define this. */
2979 #define MAXPATHLEN 1024
2988 char *npath
, *spath
;
2989 extern char *getcwd ();
2991 BLOCK_INPUT
; /* getcwd uses malloc */
2992 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
2995 /* On Altos 3068, getcwd can return @hostname/dir, so discard
2996 up to first slash. Should be harmless on other systems. */
2997 while (*npath
&& *npath
!= '/')
2999 strcpy (pathname
, npath
);
3000 free (spath
); /* getcwd uses malloc */
3005 #endif /* HAVE_GETWD */
3008 * Emulate rename using unlink/link. Note that this is
3009 * only partially correct. Also, doesn't enforce restriction
3010 * that files be of same type (regular->regular, dir->dir, etc).
3019 if (access (from
, 0) == 0)
3022 if (link (from
, to
) == 0)
3023 if (unlink (from
) == 0)
3035 /* HPUX curses library references perror, but as far as we know
3036 it won't be called. Anyway this definition will do for now. */
3042 #endif /* not HAVE_PERROR */
3048 * Emulate BSD dup2. First close newd if it already exists.
3049 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3050 * until we are, then close the unsuccessful ones.
3057 register int fd
, ret
;
3062 fd
= fcntl (oldd
, F_DUPFD
, newd
);
3064 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, strerror (errno
));
3071 ret
= dup2 (old
,new);
3077 #endif /* not HAVE_DUP2 */
3080 * Gettimeofday. Simulate as much as possible. Only accurate
3081 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3082 * Only needed when subprocesses are defined.
3087 #ifndef HAVE_GETTIMEOFDAY
3091 gettimeofday (tp
, tzp
)
3093 struct timezone
*tzp
;
3095 extern long time ();
3097 tp
->tv_sec
= time ((long *)0);
3100 tzp
->tz_minuteswest
= -1;
3106 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3109 * This function will go away as soon as all the stubs fixed. (fnf)
3115 printf ("%s not yet implemented\r\n", badfunc
);
3124 char *sys_siglist
[NSIG
+ 1] =
3126 "null signal", /* 0 SIGNULL */
3127 "hangup", /* 1 SIGHUP */
3128 "interrupt", /* 2 SIGINT */
3129 "quit", /* 3 SIGQUIT */
3130 "illegal instruction", /* 4 SIGILL */
3131 "trace trap", /* 5 SIGTRAP */
3132 "abort termination", /* 6 SIGABRT */
3133 "SIGEMT", /* 7 SIGEMT */
3134 "floating point exception", /* 8 SIGFPE */
3135 "kill", /* 9 SIGKILL */
3136 "bus error", /* 10 SIGBUS */
3137 "segmentation violation", /* 11 SIGSEGV */
3138 "bad argument to system call", /* 12 SIGSYS */
3139 "write on a pipe with no reader", /* 13 SIGPIPE */
3140 "alarm clock", /* 14 SIGALRM */
3141 "software termination signal", /* 15 SIGTERM */
3142 "user defined signal 1", /* 16 SIGUSR1 */
3143 "user defined signal 2", /* 17 SIGUSR2 */
3144 "child stopped or terminated", /* 18 SIGCLD */
3145 "power-fail restart", /* 19 SIGPWR */
3146 "window size changed", /* 20 SIGWINCH */
3147 "undefined", /* 21 */
3148 "pollable event occurred", /* 22 SIGPOLL */
3149 "sendable stop signal not from tty", /* 23 SIGSTOP */
3150 "stop signal from tty", /* 24 SIGSTP */
3151 "continue a stopped process", /* 25 SIGCONT */
3152 "attempted background tty read", /* 26 SIGTTIN */
3153 "attempted background tty write", /* 27 SIGTTOU */
3154 "undefined", /* 28 */
3155 "undefined", /* 29 */
3156 "undefined", /* 30 */
3157 "undefined", /* 31 */
3158 "undefined", /* 32 */
3159 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
3160 "I/O is possible", /* 34 SIGIO */
3161 "exceeded cpu time limit", /* 35 SIGXCPU */
3162 "exceeded file size limit", /* 36 SIGXFSZ */
3163 "virtual time alarm", /* 37 SIGVTALRM */
3164 "profiling time alarm", /* 38 SIGPROF */
3165 "undefined", /* 39 */
3166 "file record locks revoked", /* 40 SIGLOST */
3167 "undefined", /* 41 */
3168 "undefined", /* 42 */
3169 "undefined", /* 43 */
3170 "undefined", /* 44 */
3171 "undefined", /* 45 */
3172 "undefined", /* 46 */
3173 "undefined", /* 47 */
3174 "undefined", /* 48 */
3175 "undefined", /* 49 */
3176 "undefined", /* 50 */
3177 "undefined", /* 51 */
3178 "undefined", /* 52 */
3179 "undefined", /* 53 */
3180 "undefined", /* 54 */
3181 "undefined", /* 55 */
3182 "undefined", /* 56 */
3183 "undefined", /* 57 */
3184 "undefined", /* 58 */
3185 "undefined", /* 59 */
3186 "undefined", /* 60 */
3187 "undefined", /* 61 */
3188 "undefined", /* 62 */
3189 "undefined", /* 63 */
3190 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3196 /* Directory routines for systems that don't have them. */
3198 #ifdef SYSV_SYSTEM_DIR
3202 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
3206 register DIR *dirp
; /* stream from opendir */
3210 rtnval
= sys_close (dirp
->dd_fd
);
3212 /* Some systems (like Solaris) allocate the buffer and the DIR all
3213 in one block. Why in the world are we freeing this ourselves
3215 #if ! (defined (sun) && defined (USG5_4))
3216 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3218 xfree ((char *) dirp
);
3222 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3223 #endif /* SYSV_SYSTEM_DIR */
3225 #ifdef NONSYSTEM_DIR_LIBRARY
3229 char *filename
; /* name of directory */
3231 register DIR *dirp
; /* -> malloc'ed storage */
3232 register int fd
; /* file descriptor for read */
3233 struct stat sbuf
; /* result of fstat */
3235 fd
= sys_open (filename
, 0);
3240 if (fstat (fd
, &sbuf
) < 0
3241 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3242 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
3246 return 0; /* bad luck today */
3251 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3258 register DIR *dirp
; /* stream from opendir */
3260 sys_close (dirp
->dd_fd
);
3261 xfree ((char *) dirp
);
3269 ino_t od_ino
; /* inode */
3270 char od_name
[DIRSIZ
]; /* filename */
3272 #endif /* not VMS */
3274 struct direct dir_static
; /* simulated directory contents */
3279 register DIR *dirp
; /* stream from opendir */
3282 register struct olddir
*dp
; /* -> directory data */
3284 register struct dir$_name
*dp
; /* -> directory data */
3285 register struct dir$_version
*dv
; /* -> version data */
3290 if (dirp
->dd_loc
>= dirp
->dd_size
)
3291 dirp
->dd_loc
= dirp
->dd_size
= 0;
3293 if (dirp
->dd_size
== 0 /* refill buffer */
3294 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3298 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3299 dirp
->dd_loc
+= sizeof (struct olddir
);
3301 if (dp
->od_ino
!= 0) /* not deleted entry */
3303 dir_static
.d_ino
= dp
->od_ino
;
3304 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3305 dir_static
.d_name
[DIRSIZ
] = '\0';
3306 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3307 dir_static
.d_reclen
= sizeof (struct direct
)
3309 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3310 return &dir_static
; /* -> simulated structure */
3313 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3314 if (dirp
->dd_loc
== 0)
3315 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3316 : dp
->dir$b_namecount
;
3317 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3318 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3319 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3320 dir_static
.d_reclen
= sizeof (struct direct
)
3322 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3323 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3324 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3325 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3332 /* readdirver is just like readdir except it returns all versions of a file
3333 as separate entries. */
3338 register DIR *dirp
; /* stream from opendir */
3340 register struct dir$_name
*dp
; /* -> directory data */
3341 register struct dir$_version
*dv
; /* -> version data */
3343 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3344 dirp
->dd_loc
= dirp
->dd_size
= 0;
3346 if (dirp
->dd_size
== 0 /* refill buffer */
3347 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3350 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3351 if (dirp
->dd_loc
== 0)
3352 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3353 : dp
->dir$b_namecount
;
3354 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3355 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3356 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3357 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3358 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3359 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3360 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3361 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3367 #endif /* NONSYSTEM_DIR_LIBRARY */
3371 set_file_times (filename
, atime
, mtime
)
3373 EMACS_TIME atime
, mtime
;
3376 struct timeval tv
[2];
3379 return utimes (filename
, tv
);
3380 #else /* not HAVE_UTIMES */
3382 utb
.actime
= EMACS_SECS (atime
);
3383 utb
.modtime
= EMACS_SECS (mtime
);
3384 return utime (filename
, &utb
);
3385 #endif /* not HAVE_UTIMES */
3388 /* mkdir and rmdir functions, for systems which don't have them. */
3392 * Written by Robert Rother, Mariah Corporation, August 1985.
3394 * If you want it, it's yours. All I ask in return is that if you
3395 * figure out how to do this in a Bourne Shell script you send me
3397 * sdcsvax!rmr or rmr@uscd
3399 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3400 * subroutine. 11Mar86; hoptoad!gnu
3402 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3403 * subroutine didn't return EEXIST. It does now.
3409 #ifdef MKDIR_PROTOTYPE
3413 mkdir (dpath
, dmode
)
3418 int cpid
, status
, fd
;
3419 struct stat statbuf
;
3421 if (stat (dpath
, &statbuf
) == 0)
3423 errno
= EEXIST
; /* Stat worked, so it already exists */
3427 /* If stat fails for a reason other than non-existence, return error */
3428 if (errno
!= ENOENT
)
3431 synch_process_alive
= 1;
3432 switch (cpid
= fork ())
3435 case -1: /* Error in fork */
3436 return (-1); /* Errno is set already */
3438 case 0: /* Child process */
3440 * Cheap hack to set mode of new directory. Since this
3441 * child process is going away anyway, we zap its umask.
3442 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3443 * directory. Does anybody care?
3445 status
= umask (0); /* Get current umask */
3446 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3447 fd
= sys_open("/dev/null", 2);
3454 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3455 _exit (-1); /* Can't exec /bin/mkdir */
3457 default: /* Parent process */
3458 wait_for_termination (cpid
);
3461 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3463 errno
= EIO
; /* We don't know why, but */
3464 return -1; /* /bin/mkdir failed */
3469 #endif /* not HAVE_MKDIR */
3476 int cpid
, status
, fd
;
3477 struct stat statbuf
;
3479 if (stat (dpath
, &statbuf
) != 0)
3481 /* Stat just set errno. We don't have to */
3485 synch_process_alive
= 1;
3486 switch (cpid
= fork ())
3489 case -1: /* Error in fork */
3490 return (-1); /* Errno is set already */
3492 case 0: /* Child process */
3493 fd
= sys_open("/dev/null", 2);
3500 wait_for_termination (cpid
);
3501 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3502 return -1; /* /bin/rmdir failed */
3503 default: /* Parent process */
3504 while (cpid
!= wait (&status
)); /* Wait for kid to finish */
3507 if (WIFSIGNALED (status
) || WEXITSTATUS (status
) != 0)
3509 errno
= EIO
; /* We don't know why, but */
3510 return -1; /* /bin/mkdir failed */
3515 #endif /* !HAVE_RMDIR */
3519 /* Functions for VMS */
3521 #include "vms-pwd.h"
3526 /* Return as a string the VMS error string pertaining to STATUS.
3527 Reuses the same static buffer each time it is called. */
3531 int status
; /* VMS status code */
3535 static char buf
[257];
3537 bufadr
[0] = sizeof buf
- 1;
3538 bufadr
[1] = (int) buf
;
3539 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3540 return "untranslatable VMS error status";
3548 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3549 * not work correctly. (It also doesn't work well in version 2.3.)
3554 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3555 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3559 unsigned short s_buflen
;
3560 unsigned short s_code
;
3562 unsigned short *s_retlenadr
;
3566 #define buflen s.s_buflen
3567 #define code s.s_code
3568 #define bufadr s.s_bufadr
3569 #define retlenadr s.s_retlenadr
3571 #define R_OK 4 /* test for read permission */
3572 #define W_OK 2 /* test for write permission */
3573 #define X_OK 1 /* test for execute (search) permission */
3574 #define F_OK 0 /* test for presence of file */
3577 sys_access (path
, mode
)
3581 static char *user
= NULL
;
3584 /* translate possible directory spec into .DIR file name, so brain-dead
3585 * access can treat the directory like a file. */
3586 if (directory_file_name (path
, dir_fn
))
3590 return access (path
, mode
);
3591 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3597 unsigned short int dummy
;
3599 static int constant
= ACL$C_FILE
;
3600 DESCRIPTOR (path_desc
, path
);
3601 DESCRIPTOR (user_desc
, user
);
3605 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3608 acces
|= CHP$M_READ
;
3610 acces
|= CHP$M_WRITE
;
3611 itemlst
[0].buflen
= sizeof (int);
3612 itemlst
[0].code
= CHP$_FLAGS
;
3613 itemlst
[0].bufadr
= (char *) &flags
;
3614 itemlst
[0].retlenadr
= &dummy
;
3615 itemlst
[1].buflen
= sizeof (int);
3616 itemlst
[1].code
= CHP$_ACCESS
;
3617 itemlst
[1].bufadr
= (char *) &acces
;
3618 itemlst
[1].retlenadr
= &dummy
;
3619 itemlst
[2].end
= CHP$_END
;
3620 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3621 return stat
== SS$_NORMAL
? 0 : -1;
3625 #else /* not VMS4_4 */
3628 #define ACE$M_WRITE 2
3629 #define ACE$C_KEYID 1
3631 static unsigned short memid
, grpid
;
3632 static unsigned int uic
;
3634 /* Called from init_sys_modes, so it happens not very often
3635 but at least each time Emacs is loaded. */
3636 sys_access_reinit ()
3642 sys_access (filename
, type
)
3648 int status
, size
, i
, typecode
, acl_controlled
;
3649 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3650 union prvdef prvmask
;
3652 /* Get UIC and GRP values for protection checking. */
3655 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3658 memid
= uic
& 0xFFFF;
3662 if (type
!= 2) /* not checking write access */
3663 return access (filename
, type
);
3665 /* Check write protection. */
3667 #define CHECKPRIV(bit) (prvmask.bit)
3668 #define WRITEABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3670 /* Find privilege bits */
3671 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3673 error ("Unable to find privileges: %s", vmserrstr (status
));
3674 if (CHECKPRIV (PRV$V_BYPASS
))
3675 return 0; /* BYPASS enabled */
3677 fab
.fab$b_fac
= FAB$M_GET
;
3678 fab
.fab$l_fna
= filename
;
3679 fab
.fab$b_fns
= strlen (filename
);
3680 fab
.fab$l_xab
= &xab
;
3681 xab
= cc$rms_xabpro
;
3682 xab
.xab$l_aclbuf
= aclbuf
;
3683 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3684 status
= SYS$
OPEN (&fab
, 0, 0);
3687 SYS$
CLOSE (&fab
, 0, 0);
3688 /* Check system access */
3689 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITEABLE (XAB$V_SYS
))
3691 /* Check ACL entries, if any */
3693 if (xab
.xab$w_acllen
> 0)
3696 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3697 while (*aclptr
&& aclptr
< aclend
)
3699 size
= (*aclptr
& 0xff) / 4;
3700 typecode
= (*aclptr
>> 8) & 0xff;
3701 if (typecode
== ACE$C_KEYID
)
3702 for (i
= size
- 1; i
> 1; i
--)
3703 if (aclptr
[i
] == uic
)
3706 if (aclptr
[1] & ACE$M_WRITE
)
3707 return 0; /* Write access through ACL */
3709 aclptr
= &aclptr
[size
];
3711 if (acl_controlled
) /* ACL specified, prohibits write access */
3714 /* No ACL entries specified, check normal protection */
3715 if (WRITEABLE (XAB$V_WLD
)) /* World writeable */
3717 if (WRITEABLE (XAB$V_GRP
) &&
3718 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3719 return 0; /* Group writeable */
3720 if (WRITEABLE (XAB$V_OWN
) &&
3721 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3722 return 0; /* Owner writeable */
3724 return -1; /* Not writeable */
3726 #endif /* not VMS4_4 */
3729 static char vtbuf
[NAM$C_MAXRSS
+1];
3731 /* translate a vms file spec to a unix path */
3733 sys_translate_vms (vfile
)
3744 /* leading device or logical name is a root directory */
3745 if (p
= strchr (vfile
, ':'))
3754 if (*p
== '[' || *p
== '<')
3756 while (*++vfile
!= *p
+ 2)
3760 if (vfile
[-1] == *p
)
3783 static char utbuf
[NAM$C_MAXRSS
+1];
3785 /* translate a unix path to a VMS file spec */
3787 sys_translate_unix (ufile
)
3810 if (index (&ufile
[1], '/'))
3817 if (index (&ufile
[1], '/'))
3824 if (strncmp (ufile
, "./", 2) == 0)
3831 ufile
++; /* skip the dot */
3832 if (index (&ufile
[1], '/'))
3837 else if (strncmp (ufile
, "../", 3) == 0)
3845 ufile
+= 2; /* skip the dots */
3846 if (index (&ufile
[1], '/'))
3871 extern char *getcwd ();
3873 #define MAXPATHLEN 1024
3875 ptr
= xmalloc (MAXPATHLEN
);
3876 val
= getcwd (ptr
, MAXPATHLEN
);
3882 strcpy (pathname
, ptr
);
3890 long item_code
= JPI$_OWNER
;
3891 unsigned long parent_id
;
3894 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
3897 vaxc$errno
= status
;
3907 return (getgid () << 16) | getuid ();
3911 sys_read (fildes
, buf
, nbyte
)
3916 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
3921 sys_write (fildes
, buf
, nbyte
)
3926 register int nwrote
, rtnval
= 0;
3928 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
3934 return rtnval
? rtnval
: -1;
3935 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
3936 return rtnval
? rtnval
: -1;
3937 return (rtnval
+ nwrote
);
3942 * VAX/VMS VAX C RTL really loses. It insists that records
3943 * end with a newline (carriage return) character, and if they
3944 * don't it adds one (nice of it isn't it!)
3946 * Thus we do this stupidity below.
3950 sys_write (fildes
, buf
, nbytes
)
3953 unsigned int nbytes
;
3960 fstat (fildes
, &st
);
3966 /* Handle fixed-length files with carriage control. */
3967 if (st
.st_fab_rfm
== FAB$C_FIX
3968 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
3970 len
= st
.st_fab_mrs
;
3971 retval
= write (fildes
, p
, min (len
, nbytes
));
3974 retval
++; /* This skips the implied carriage control */
3978 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3979 while (*e
!= '\n' && e
> p
) e
--;
3980 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
3981 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
3983 retval
= write (fildes
, p
, len
);
3994 /* Create file NEW copying its attributes from file OLD. If
3995 OLD is 0 or does not exist, create based on the value of
3998 /* Protection value the file should ultimately have.
3999 Set by create_copy_attrs, and use by rename_sansversions. */
4000 static unsigned short int fab_final_pro
;
4003 creat_copy_attrs (old
, new)
4006 struct FAB fab
= cc$rms_fab
;
4007 struct XABPRO xabpro
;
4008 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4009 extern int vms_stmlf_recfm
;
4013 fab
.fab$b_fac
= FAB$M_GET
;
4014 fab
.fab$l_fna
= old
;
4015 fab
.fab$b_fns
= strlen (old
);
4016 fab
.fab$l_xab
= (char *) &xabpro
;
4017 xabpro
= cc$rms_xabpro
;
4018 xabpro
.xab$l_aclbuf
= aclbuf
;
4019 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4020 /* Call $OPEN to fill in the fab & xabpro fields. */
4021 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4023 SYS$
CLOSE (&fab
, 0, 0);
4024 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4025 if (xabpro
.xab$w_acllen
> 0)
4027 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4028 /* If the acl buffer was too short, redo open with longer one.
4029 Wouldn't need to do this if there were some system imposed
4030 limit on the size of an ACL, but I can't find any such. */
4032 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4033 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4034 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4035 SYS$
CLOSE (&fab
, 0, 0);
4041 xabpro
.xab$l_aclbuf
= 0;
4046 fab
.fab$l_fna
= new;
4047 fab
.fab$b_fns
= strlen (new);
4051 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4052 fab
.fab$b_rat
= FAB$M_CR
;
4055 /* Set the file protections such that we will be able to manipulate
4056 this file. Once we are done writing and renaming it, we will set
4057 the protections back. */
4059 fab_final_pro
= xabpro
.xab$w_pro
;
4061 SYS$
SETDFPROT (0, &fab_final_pro
);
4062 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4064 /* Create the new file with either default attrs or attrs copied
4066 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4068 SYS$
CLOSE (&fab
, 0, 0);
4069 /* As this is a "replacement" for creat, return a file descriptor
4070 opened for writing. */
4071 return open (new, O_WRONLY
);
4076 #include <varargs.h>
4079 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4083 sys_creat (va_alist
)
4086 va_list list_incrementer
;
4089 int rfd
; /* related file descriptor */
4090 int fd
; /* Our new file descriptor */
4097 extern int vms_stmlf_recfm
;
4100 va_start (list_incrementer
);
4101 name
= va_arg (list_incrementer
, char *);
4102 mode
= va_arg (list_incrementer
, int);
4104 rfd
= va_arg (list_incrementer
, int);
4105 va_end (list_incrementer
);
4108 /* Use information from the related file descriptor to set record
4109 format of the newly created file. */
4110 fstat (rfd
, &st_buf
);
4111 switch (st_buf
.st_fab_rfm
)
4114 strcpy (rfm
, "rfm = fix");
4115 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4116 strcpy (rat
, "rat = ");
4117 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4119 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4120 strcat (rat
, "ftn");
4121 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4122 strcat (rat
, "prn");
4123 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4124 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4125 strcat (rat
, ", blk");
4127 strcat (rat
, "blk");
4128 return creat (name
, 0, rfm
, rat
, mrs
);
4131 strcpy (rfm
, "rfm = vfc");
4132 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4133 strcpy (rat
, "rat = ");
4134 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4136 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4137 strcat (rat
, "ftn");
4138 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4139 strcat (rat
, "prn");
4140 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4141 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4142 strcat (rat
, ", blk");
4144 strcat (rat
, "blk");
4145 return creat (name
, 0, rfm
, rat
, fsz
);
4148 strcpy (rfm
, "rfm = stm");
4152 strcpy (rfm
, "rfm = stmcr");
4156 strcpy (rfm
, "rfm = stmlf");
4160 strcpy (rfm
, "rfm = udf");
4164 strcpy (rfm
, "rfm = var");
4167 strcpy (rat
, "rat = ");
4168 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4170 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4171 strcat (rat
, "ftn");
4172 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4173 strcat (rat
, "prn");
4174 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4175 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4176 strcat (rat
, ", blk");
4178 strcat (rat
, "blk");
4182 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4183 strcpy (rat
, "rat=cr");
4185 /* Until the VAX C RTL fixes the many bugs with modes, always use
4186 mode 0 to get the user's default protection. */
4187 fd
= creat (name
, 0, rfm
, rat
);
4188 if (fd
< 0 && errno
== EEXIST
)
4190 if (unlink (name
) < 0)
4191 report_file_error ("delete", build_string (name
));
4192 fd
= creat (name
, 0, rfm
, rat
);
4198 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4199 sys_fwrite (ptr
, size
, num
, fp
)
4200 register char * ptr
;
4203 register int tot
= num
* size
;
4210 * The VMS C library routine creat actually creates a new version of an
4211 * existing file rather than truncating the old version. There are times
4212 * when this is not the desired behavior, for instance, when writing an
4213 * auto save file (you only want one version), or when you don't have
4214 * write permission in the directory containing the file (but the file
4215 * itself is writable). Hence this routine, which is equivalent to
4216 * "close (creat (fn, 0));" on Unix if fn already exists.
4222 struct FAB xfab
= cc$rms_fab
;
4223 struct RAB xrab
= cc$rms_rab
;
4226 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4227 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4228 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4229 xfab
.fab$l_fna
= fn
;
4230 xfab
.fab$b_fns
= strlen (fn
);
4231 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4233 xrab
.rab$l_fab
= &xfab
;
4235 /* This gibberish opens the file, positions to the first record, and
4236 deletes all records from there until the end of file. */
4237 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4239 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4240 (SYS$
FIND (&xrab
) & 01) == 01 &&
4241 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4252 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4253 SYSPRV or a readable SYSUAF.DAT. */
4259 * Routine to read the VMS User Authorization File and return
4260 * a specific user's record.
4263 static struct UAF retuaf
;
4266 get_uaf_name (uname
)
4273 uaf_fab
= cc$rms_fab
;
4274 uaf_rab
= cc$rms_rab
;
4275 /* initialize fab fields */
4276 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4277 uaf_fab
.fab$b_fns
= 21;
4278 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4279 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4280 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4281 /* initialize rab fields */
4282 uaf_rab
.rab$l_fab
= &uaf_fab
;
4283 /* open the User Authorization File */
4284 status
= SYS$
OPEN (&uaf_fab
);
4288 vaxc$errno
= status
;
4291 status
= SYS$
CONNECT (&uaf_rab
);
4295 vaxc$errno
= status
;
4298 /* read the requested record - index is in uname */
4299 uaf_rab
.rab$l_kbf
= uname
;
4300 uaf_rab
.rab$b_ksz
= strlen (uname
);
4301 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4302 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4303 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4304 status
= SYS$
GET (&uaf_rab
);
4308 vaxc$errno
= status
;
4311 /* close the User Authorization File */
4312 status
= SYS$
DISCONNECT (&uaf_rab
);
4316 vaxc$errno
= status
;
4319 status
= SYS$
CLOSE (&uaf_fab
);
4323 vaxc$errno
= status
;
4337 uaf_fab
= cc$rms_fab
;
4338 uaf_rab
= cc$rms_rab
;
4339 /* initialize fab fields */
4340 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4341 uaf_fab
.fab$b_fns
= 21;
4342 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4343 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4344 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4345 /* initialize rab fields */
4346 uaf_rab
.rab$l_fab
= &uaf_fab
;
4347 /* open the User Authorization File */
4348 status
= SYS$
OPEN (&uaf_fab
);
4352 vaxc$errno
= status
;
4355 status
= SYS$
CONNECT (&uaf_rab
);
4359 vaxc$errno
= status
;
4362 /* read the requested record - index is in uic */
4363 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4364 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4365 uaf_rab
.rab$b_ksz
= sizeof uic
;
4366 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4367 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4368 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4369 status
= SYS$
GET (&uaf_rab
);
4373 vaxc$errno
= status
;
4376 /* close the User Authorization File */
4377 status
= SYS$
DISCONNECT (&uaf_rab
);
4381 vaxc$errno
= status
;
4384 status
= SYS$
CLOSE (&uaf_fab
);
4388 vaxc$errno
= status
;
4394 static struct passwd retpw
;
4402 /* copy these out first because if the username is 32 chars, the next
4403 section will overwrite the first byte of the UIC */
4404 retpw
.pw_uid
= up
->uaf$w_mem
;
4405 retpw
.pw_gid
= up
->uaf$w_grp
;
4407 /* I suppose this is not the best sytle, to possibly overwrite one
4408 byte beyond the end of the field, but what the heck... */
4409 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4410 while (ptr
[-1] == ' ')
4413 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4415 /* the rest of these are counted ascii strings */
4416 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4417 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4418 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4419 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4420 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4421 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4422 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4423 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4427 #else /* not READ_SYSUAF */
4428 static struct passwd retpw
;
4429 #endif /* not READ_SYSUAF */
4440 unsigned char * full
;
4441 #endif /* READ_SYSUAF */
4446 if ('a' <= *ptr
&& *ptr
<= 'z')
4451 if (!(up
= get_uaf_name (name
)))
4453 return cnv_uaf_pw (up
);
4455 if (strcmp (name
, getenv ("USER")) == 0)
4457 retpw
.pw_uid
= getuid ();
4458 retpw
.pw_gid
= getgid ();
4459 strcpy (retpw
.pw_name
, name
);
4460 if (full
= egetenv ("FULLNAME"))
4461 strcpy (retpw
.pw_gecos
, full
);
4463 *retpw
.pw_gecos
= '\0';
4464 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4465 *retpw
.pw_shell
= '\0';
4470 #endif /* not READ_SYSUAF */
4480 if (!(up
= get_uaf_uic (uid
)))
4482 return cnv_uaf_pw (up
);
4484 if (uid
== sys_getuid ())
4485 return getpwnam (egetenv ("USER"));
4488 #endif /* not READ_SYSUAF */
4491 /* return total address space available to the current process. This is
4492 the sum of the current p0 size, p1 size and free page table entries
4497 unsigned long free_pages
;
4498 unsigned long frep0va
;
4499 unsigned long frep1va
;
4502 item_code
= JPI$_FREPTECNT
;
4503 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4506 vaxc$errno
= status
;
4511 item_code
= JPI$_FREP0VA
;
4512 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4515 vaxc$errno
= status
;
4518 item_code
= JPI$_FREP1VA
;
4519 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4522 vaxc$errno
= status
;
4526 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4529 define_logical_name (varname
, string
)
4533 struct dsc$descriptor_s strdsc
=
4534 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4535 struct dsc$descriptor_s envdsc
=
4536 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4537 struct dsc$descriptor_s lnmdsc
=
4538 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4540 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4543 delete_logical_name (varname
)
4546 struct dsc$descriptor_s envdsc
=
4547 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4548 struct dsc$descriptor_s lnmdsc
=
4549 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4551 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4562 error ("execvp system call not implemented");
4570 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4571 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4572 char from_esn
[NAM$C_MAXRSS
];
4573 char to_esn
[NAM$C_MAXRSS
];
4575 from_fab
.fab$l_fna
= from
;
4576 from_fab
.fab$b_fns
= strlen (from
);
4577 from_fab
.fab$l_nam
= &from_nam
;
4578 from_fab
.fab$l_fop
= FAB$M_NAM
;
4580 from_nam
.nam$l_esa
= from_esn
;
4581 from_nam
.nam$b_ess
= sizeof from_esn
;
4583 to_fab
.fab$l_fna
= to
;
4584 to_fab
.fab$b_fns
= strlen (to
);
4585 to_fab
.fab$l_nam
= &to_nam
;
4586 to_fab
.fab$l_fop
= FAB$M_NAM
;
4588 to_nam
.nam$l_esa
= to_esn
;
4589 to_nam
.nam$b_ess
= sizeof to_esn
;
4591 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4597 if (status
== RMS$_DEV
)
4601 vaxc$errno
= status
;
4606 /* This function renames a file like `rename', but it strips
4607 the version number from the "to" filename, such that the "to" file is
4608 will always be a new version. It also sets the file protection once it is
4609 finished. The protection that we will use is stored in fab_final_pro,
4610 and was set when we did a creat_copy_attrs to create the file that we
4613 We could use the chmod function, but Eunichs uses 3 bits per user category
4614 to describe the protection, and VMS uses 4 (write and delete are separate
4615 bits). To maintain portability, the VMS implementation of `chmod' wires
4616 the W and D bits together. */
4619 static struct fibdef fib
; /* We need this initialized to zero */
4620 char vms_file_written
[NAM$C_MAXRSS
];
4623 rename_sans_version (from
,to
)
4630 struct FAB to_fab
= cc$rms_fab
;
4631 struct NAM to_nam
= cc$rms_nam
;
4632 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4633 struct dsc$descriptor fib_attr
[2]
4634 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4635 char to_esn
[NAM$C_MAXRSS
];
4637 $
DESCRIPTOR (disk
,to_esn
);
4639 to_fab
.fab$l_fna
= to
;
4640 to_fab
.fab$b_fns
= strlen (to
);
4641 to_fab
.fab$l_nam
= &to_nam
;
4642 to_fab
.fab$l_fop
= FAB$M_NAM
;
4644 to_nam
.nam$l_esa
= to_esn
;
4645 to_nam
.nam$b_ess
= sizeof to_esn
;
4647 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4649 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4650 *(to_nam
.nam$l_ver
) = '\0';
4652 stat
= rename (from
, to_esn
);
4656 strcpy (vms_file_written
, to_esn
);
4658 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4659 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4661 /* Now set the file protection to the correct value */
4662 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4664 /* Copy these fields into the fib */
4665 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4666 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4667 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4669 SYS$
CLOSE (&to_fab
, 0, 0);
4671 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4674 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4675 0, 0, 0, &fib_attr
, 0);
4678 stat
= SYS$
DASSGN (chan
);
4681 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4691 unsigned short fid
[3];
4692 char esa
[NAM$C_MAXRSS
];
4695 fab
.fab$l_fop
= FAB$M_OFP
;
4696 fab
.fab$l_fna
= file
;
4697 fab
.fab$b_fns
= strlen (file
);
4698 fab
.fab$l_nam
= &nam
;
4701 nam
.nam$l_esa
= esa
;
4702 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4704 status
= SYS$
PARSE (&fab
);
4705 if ((status
& 1) == 0)
4708 vaxc$errno
= status
;
4711 status
= SYS$
SEARCH (&fab
);
4712 if ((status
& 1) == 0)
4715 vaxc$errno
= status
;
4719 fid
[0] = nam
.nam$w_fid
[0];
4720 fid
[1] = nam
.nam$w_fid
[1];
4721 fid
[2] = nam
.nam$w_fid
[2];
4723 fab
.fab$l_fna
= new;
4724 fab
.fab$b_fns
= strlen (new);
4726 status
= SYS$
PARSE (&fab
);
4727 if ((status
& 1) == 0)
4730 vaxc$errno
= status
;
4734 nam
.nam$w_fid
[0] = fid
[0];
4735 nam
.nam$w_fid
[1] = fid
[1];
4736 nam
.nam$w_fid
[2] = fid
[2];
4738 nam
.nam$l_esa
= nam
.nam$l_name
;
4739 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
4741 status
= SYS$
ENTER (&fab
);
4742 if ((status
& 1) == 0)
4745 vaxc$errno
= status
;
4755 printf ("%s not yet implemented\r\n", badfunc
);
4763 /* Arrange to return a range centered on zero. */
4764 return rand () - (1 << 30);
4775 /* Called from init_sys_modes. */
4780 /* If we're not on an HFT we shouldn't do any of this. We determine
4781 if we are on an HFT by trying to get an HFT error code. If this
4782 call fails, we're not on an HFT. */
4784 if (ioctl (0, HFQERROR
, &junk
) < 0)
4786 #else /* not IBMR2AIX */
4787 if (ioctl (0, HFQEIO
, 0) < 0)
4789 #endif /* not IBMR2AIX */
4791 /* On AIX the default hft keyboard mapping uses backspace rather than delete
4792 as the rubout key's ASCII code. Here this is changed. The bug is that
4793 there's no way to determine the old mapping, so in reset_sys_modes
4794 we need to assume that the normal map had been present. Of course, this
4795 code also doesn't help if on a terminal emulator which doesn't understand
4799 struct hfkeymap keymap
;
4801 buf
.hf_bufp
= (char *)&keymap
;
4802 buf
.hf_buflen
= sizeof (keymap
);
4803 keymap
.hf_nkeys
= 2;
4804 keymap
.hfkey
[0].hf_kpos
= 15;
4805 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4807 keymap
.hfkey
[0].hf_keyidh
= '<';
4808 #else /* not IBMR2AIX */
4809 keymap
.hfkey
[0].hf_page
= '<';
4810 #endif /* not IBMR2AIX */
4811 keymap
.hfkey
[0].hf_char
= 127;
4812 keymap
.hfkey
[1].hf_kpos
= 15;
4813 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4815 keymap
.hfkey
[1].hf_keyidh
= '<';
4816 #else /* not IBMR2AIX */
4817 keymap
.hfkey
[1].hf_page
= '<';
4818 #endif /* not IBMR2AIX */
4819 keymap
.hfkey
[1].hf_char
= 127;
4820 hftctl (0, HFSKBD
, &buf
);
4822 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
4824 line_ins_del_ok
= char_ins_del_ok
= 0;
4827 /* Reset the rubout key to backspace. */
4832 struct hfkeymap keymap
;
4836 if (ioctl (0, HFQERROR
, &junk
) < 0)
4838 #else /* not IBMR2AIX */
4839 if (ioctl (0, HFQEIO
, 0) < 0)
4841 #endif /* not IBMR2AIX */
4843 buf
.hf_bufp
= (char *)&keymap
;
4844 buf
.hf_buflen
= sizeof (keymap
);
4845 keymap
.hf_nkeys
= 2;
4846 keymap
.hfkey
[0].hf_kpos
= 15;
4847 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4849 keymap
.hfkey
[0].hf_keyidh
= '<';
4850 #else /* not IBMR2AIX */
4851 keymap
.hfkey
[0].hf_page
= '<';
4852 #endif /* not IBMR2AIX */
4853 keymap
.hfkey
[0].hf_char
= 8;
4854 keymap
.hfkey
[1].hf_kpos
= 15;
4855 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4857 keymap
.hfkey
[1].hf_keyidh
= '<';
4858 #else /* not IBMR2AIX */
4859 keymap
.hfkey
[1].hf_page
= '<';
4860 #endif /* not IBMR2AIX */
4861 keymap
.hfkey
[1].hf_char
= 8;
4862 hftctl (0, HFSKBD
, &buf
);
4869 /* These are included on Sunos 4.1 when we do not use shared libraries.
4870 X11 libraries may refer to these functions but (we hope) do not
4871 actually call them. */
4891 #endif /* USE_DL_STUBS */