1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
27 #include "blockinput.h"
30 #define min(x,y) ((x) > (y) ? (y) : (x))
32 /* In this file, open, read and write refer to the system calls,
33 not our sugared interfaces sys_open, sys_read and sys_write.
34 Contrariwise, for systems where we use the system calls directly,
35 define sys_read, etc. here as aliases for them. */
38 #define sys_write write
39 #endif /* `read' is not a macro */
49 #endif /* not WINDOWSNT */
52 #define sys_close close
59 #else /* `open' is a macro */
61 #endif /* `open' is a macro */
63 /* Does anyone other than VMS need this? */
65 #define sys_fwrite fwrite
75 #include <sys/types.h>
79 /* Get _POSIX_VDISABLE, if it is available. */
84 /* Get SI_SRPC_DOMAIN, if it is available. */
85 #ifdef HAVE_SYS_SYSTEMINFO_H
86 #include <sys/systeminfo.h>
89 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
93 #include <sys/param.h>
97 extern unsigned start
__asm__ ("start");
115 #include <sys/file.h>
123 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
127 #ifdef BSD_SYSTEM /* avoid writing defined (BSD_SYSTEM) || defined (USG)
128 because the vms compiler doesn't grok `defined' */
136 #endif /* not 4.1 bsd */
139 #include <sys/ioctl.h>
145 #ifdef BROKEN_TIOCGWINSZ
151 #include <sys/utsname.h>
153 #ifndef MEMORY_IN_STRING_H
156 #if defined (TIOCGWINSZ) || defined (ISC4_0)
158 #include <sys/sioctl.h>
161 #include <sys/stream.h>
162 #include <sys/ptem.h>
164 #endif /* TIOCGWINSZ or ISC4_0 */
167 extern int quit_char
;
171 #include "termhooks.h"
172 #include "termchar.h"
173 #include "termopts.h"
174 #include "dispextern.h"
179 /* In process.h which conflicts with the local copy. */
181 int _CRTAPI1
_spawnlp (int, const char *, const char *, ...);
182 int _CRTAPI1
_getpid (void);
185 #ifdef NONSYSTEM_DIR_LIBRARY
187 #endif /* NONSYSTEM_DIR_LIBRARY */
189 #include "syssignal.h"
196 #ifndef HAVE_STRUCT_UTIMBUF
197 /* We want to use utime rather than utimes, but we couldn't find the
198 structure declaration. We'll use the traditional one. */
206 #ifndef VFORK_RETURN_TYPE
207 #define VFORK_RETURN_TYPE int
210 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
216 #define LNOFLSH 0100000
219 static int baud_convert
[] =
224 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
225 1800, 2400, 4800, 9600, 19200, 38400
229 #ifdef HAVE_TERMIOS_H
230 extern speed_t ospeed
;
235 /* The file descriptor for Emacs's input terminal.
236 Under Unix, this is normally zero except when using X;
237 under VMS, we place the input channel number here. */
240 /* Specify a different file descriptor for further input operations. */
249 /* Discard pending input on descriptor input_fd. */
254 struct emacs_tty buf
;
259 /* Discarding input is not safe when the input could contain
260 replies from the X server. So don't do it. */
261 if (read_socket_hook
)
266 SYS$
QIOW (0, input_fd
, IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
267 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
273 ioctl (input_fd
, TIOCFLUSH
, &zero
);
275 #else /* not Apollo */
276 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
277 while (dos_keyread () != -1)
279 #else /* not MSDOS */
280 EMACS_GET_TTY (input_fd
, &buf
);
281 EMACS_SET_TTY (input_fd
, &buf
, 0);
282 #endif /* not MSDOS */
283 #endif /* not Apollo */
285 #endif /* not WINDOWSNT */
290 /* Arrange for character C to be read as the next input from
296 if (read_socket_hook
)
299 /* Should perhaps error if in batch mode */
301 ioctl (input_fd
, TIOCSTI
, &c
);
302 #else /* no TIOCSTI */
303 error ("Cannot stuff terminal input characters in this version of Unix");
304 #endif /* no TIOCSTI */
317 #else /* not DOS_NT */
321 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &sg
, 0, 0,
322 &sg
.class, 12, 0, 0, 0, 0 );
323 ospeed
= sg
.xmit_baud
;
329 tcgetattr (input_fd
, &sg
);
330 ospeed
= cfgetospeed (&sg
);
331 #if defined (USE_GETOBAUD) && defined (getobaud)
332 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
334 ospeed
= getobaud (sg
.c_cflag
);
336 #else /* neither VMS nor TERMIOS */
342 tcgetattr (input_fd
, &sg
);
344 ioctl (input_fd
, TCGETA
, &sg
);
346 ospeed
= sg
.c_cflag
& CBAUD
;
347 #else /* neither VMS nor TERMIOS nor TERMIO */
350 sg
.sg_ospeed
= B9600
;
351 if (ioctl (input_fd
, TIOCGETP
, &sg
) < 0)
353 ospeed
= sg
.sg_ospeed
;
354 #endif /* not HAVE_TERMIO */
355 #endif /* not HAVE_TERMIOS */
357 #endif /* not DOS_NT */
360 baud_rate
= (ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
361 ? baud_convert
[ospeed
] : 9600);
367 set_exclusive_use (fd
)
371 ioctl (fd
, FIOCLEX
, 0);
373 /* Ok to do nothing if this feature does not exist */
378 wait_without_blocking ()
381 wait3 (0, WNOHANG
| WUNTRACED
, 0);
383 croak ("wait_without_blocking");
385 synch_process_alive
= 0;
388 #endif /* not subprocesses */
390 int wait_debugging
; /* Set nonzero to make following function work under dbx
391 (at least for bsd). */
394 wait_for_termination_signal ()
397 /* Wait for subprocess with process id `pid' to terminate and
398 make sure it will get eliminated (not remain forever as a zombie) */
400 wait_for_termination (pid
)
409 status
= SYS$
FORCEX (&pid
, 0, 0);
412 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
413 /* Note that kill returns -1 even if the process is just a zombie now.
414 But inevitably a SIGCHLD interrupt should be generated
415 and child_sig will do wait3 and make the process go away. */
416 /* There is some indication that there is a bug involved with
417 termination of subprocesses, perhaps involving a kernel bug too,
418 but no idea what it is. Just as a hunch we signal SIGCHLD to see
419 if that causes the problem to go away or get worse. */
420 sigsetmask (sigmask (SIGCHLD
));
421 if (0 > kill (pid
, 0))
423 sigsetmask (SIGEMPTYMASK
);
424 kill (getpid (), SIGCHLD
);
430 sigpause (SIGEMPTYMASK
);
431 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
432 #if defined (UNIPLUS)
433 if (0 > kill (pid
, 0))
436 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
437 #ifdef POSIX_SIGNALS /* would this work for LINUX as well? */
438 sigblock (sigmask (SIGCHLD
));
439 if (0 > kill (pid
, 0))
441 sigunblock (sigmask (SIGCHLD
));
444 sigpause (SIGEMPTYMASK
);
445 #else /* not POSIX_SIGNALS */
446 #ifdef HAVE_SYSV_SIGPAUSE
448 if (0 > kill (pid
, 0))
454 #else /* not HAVE_SYSV_SIGPAUSE */
458 #else /* not WINDOWSNT */
459 if (0 > kill (pid
, 0))
461 /* Using sleep instead of pause avoids timing error.
462 If the inferior dies just before the sleep,
463 we lose just one second. */
465 #endif /* not WINDOWSNT */
466 #endif /* not HAVE_SYSV_SIGPAUSE */
467 #endif /* not POSIX_SIGNALS */
468 #endif /* not UNIPLUS */
469 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
471 #else /* not subprocesses */
474 #else /* not __DJGPP__ > 1 */
476 if (kill (pid
, 0) < 0)
482 if (status
== pid
|| status
== -1)
485 #endif /* not __DJGPP__ > 1*/
486 #endif /* not subprocesses */
493 * flush any pending output
494 * (may flush input as well; it does not matter the way we use it)
497 flush_pending_output (channel
)
501 /* If we try this, we get hit with SIGTTIN, because
502 the child's tty belongs to the child's pgrp. */
505 ioctl (channel
, TCFLSH
, 1);
509 /* 3rd arg should be ignored
510 but some 4.2 kernels actually want the address of an int
511 and nonzero means something different. */
512 ioctl (channel
, TIOCFLUSH
, &zero
);
519 /* Set up the terminal at the other end of a pseudo-terminal that
520 we will be controlling an inferior through.
521 It should not echo or do line-editing, since that is done
522 in Emacs. No padding needed for insertion into an Emacs buffer. */
524 child_setup_tty (out
)
530 EMACS_GET_TTY (out
, &s
);
532 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
533 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
534 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
536 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
537 /* No output delays */
539 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
540 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
542 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
545 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
548 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
550 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
551 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
553 /* Said to be unnecessary: */
554 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
555 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
558 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
559 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
560 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
561 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
564 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
568 /* AIX enhanced edit loses NULs, so disable it */
571 s
.main
.c_iflag
&= ~ASCEDIT
;
573 /* Also, PTY overloads NUL and BREAK.
574 don't ignore break, but don't signal either, so it looks like NUL. */
575 s
.main
.c_iflag
&= ~IGNBRK
;
576 s
.main
.c_iflag
&= ~BRKINT
;
577 /* QUIT and INTR work better as signals, so disable character forms */
578 s
.main
.c_cc
[VINTR
] = 0377;
579 #ifdef SIGNALS_VIA_CHARACTERS
580 /* the QUIT and INTR character are used in process_send_signal
581 so set them here to something useful. */
582 if (s
.main
.c_cc
[VQUIT
] == 0377)
583 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
584 if (s
.main
.c_cc
[VINTR
] == 0377)
585 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
586 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
587 /* QUIT and INTR work better as signals, so disable character forms */
588 s
.main
.c_cc
[VQUIT
] = 0377;
589 s
.main
.c_cc
[VINTR
] = 0377;
590 s
.main
.c_lflag
&= ~ISIG
;
591 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
592 s
.main
.c_cc
[VEOL
] = 0377;
593 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
596 #else /* not HAVE_TERMIO */
598 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
600 s
.main
.sg_flags
|= LPASS8
;
601 s
.main
.sg_erase
= 0377;
602 s
.main
.sg_kill
= 0377;
603 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
605 #endif /* not HAVE_TERMIO */
607 EMACS_SET_TTY (out
, &s
, 0);
616 ioctl (out
, FIOASYNC
, &zero
);
619 #endif /* not DOS_NT */
623 #endif /* subprocesses */
625 /* Record a signal code and the handler for it. */
629 SIGTYPE (*handler
) ();
632 /* Suspend the Emacs process; give terminal to its superior. */
637 /* "Foster" parentage allows emacs to return to a subprocess that attached
638 to the current emacs as a cheaper than starting a whole new process. This
639 is set up by KEPTEDITOR.COM. */
640 unsigned long parent_id
, foster_parent_id
;
643 fpid_string
= getenv ("EMACS_PARENT_PID");
644 if (fpid_string
!= NULL
)
646 sscanf (fpid_string
, "%x", &foster_parent_id
);
647 if (foster_parent_id
!= 0)
648 parent_id
= foster_parent_id
;
650 parent_id
= getppid ();
653 parent_id
= getppid ();
655 xfree (fpid_string
); /* On VMS, this was malloc'd */
657 if (parent_id
&& parent_id
!= 0xffffffff)
659 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
660 int status
= LIB$
ATTACH (&parent_id
) & 1;
661 signal (SIGINT
, oldsig
);
670 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
671 d_prompt
.a
= "Emacs: "; /* Just a reminder */
672 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
677 #if defined(SIGTSTP) && !defined(MSDOS)
680 int pgrp
= EMACS_GETPGRP (0);
681 EMACS_KILLPG (pgrp
, SIGTSTP
);
684 #else /* No SIGTSTP */
685 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
686 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
687 kill (getpid (), SIGQUIT
);
689 #else /* No SIGTSTP or USG_JOBCTRL */
691 /* On a system where suspending is not implemented,
692 instead fork a subshell and let it talk directly to the terminal
696 #endif /* no USG_JOBCTRL */
697 #endif /* no SIGTSTP */
701 /* Fork a subshell. */
706 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
708 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
711 struct save_signal saved_handlers
[5];
713 unsigned char *str
= 0;
716 saved_handlers
[0].code
= SIGINT
;
717 saved_handlers
[1].code
= SIGQUIT
;
718 saved_handlers
[2].code
= SIGTERM
;
720 saved_handlers
[3].code
= SIGIO
;
721 saved_handlers
[4].code
= 0;
723 saved_handlers
[3].code
= 0;
726 /* Mentioning current_buffer->buffer would mean including buffer.h,
727 which somehow wedges the hp compiler. So instead... */
729 dir
= intern ("default-directory");
730 if (NILP (Fboundp (dir
)))
732 dir
= Fsymbol_value (dir
);
736 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
737 str
= (unsigned char *) alloca (XSTRING (dir
)->size
+ 2);
738 len
= XSTRING (dir
)->size
;
739 bcopy (XSTRING (dir
)->data
, str
, len
);
740 if (str
[len
- 1] != '/') str
[len
++] = '/';
746 #else /* not WINDOWSNT */
751 save_signal_handlers (saved_handlers
);
752 synch_process_alive
= 1;
753 #endif /* __DJGPP__ > 1 */
757 error ("Can't spawn subshell");
761 #endif /* not WINDOWSNT */
765 #ifdef MSDOS /* MW, Aug 1993 */
768 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
771 sh
= (char *) egetenv ("SHELL");
775 /* Use our buffer's default directory for the subshell. */
780 close_process_descs (); /* Close Emacs's pipes/ptys */
783 #ifdef SET_EMACS_PRIORITY
785 extern int emacs_priority
;
787 if (emacs_priority
< 0)
788 nice (-emacs_priority
);
792 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
795 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
797 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
799 #else /* not MSDOS */
801 /* Waits for process completion */
802 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
804 write (1, "Can't execute subshell", 22);
807 #else /* not WINDOWSNT */
809 write (1, "Can't execute subshell", 22);
811 #endif /* not WINDOWSNT */
812 #endif /* not MSDOS */
815 /* Do this now if we did not do it before. */
816 #if !defined (MSDOS) || __DJGPP__ == 1
817 save_signal_handlers (saved_handlers
);
818 synch_process_alive
= 1;
822 wait_for_termination (pid
);
824 restore_signal_handlers (saved_handlers
);
825 synch_process_alive
= 0;
829 save_signal_handlers (saved_handlers
)
830 struct save_signal
*saved_handlers
;
832 while (saved_handlers
->code
)
834 saved_handlers
->handler
835 = (SIGTYPE (*) ()) signal (saved_handlers
->code
, SIG_IGN
);
840 restore_signal_handlers (saved_handlers
)
841 struct save_signal
*saved_handlers
;
843 while (saved_handlers
->code
)
845 signal (saved_handlers
->code
, saved_handlers
->handler
);
858 old_fcntl_flags
= fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
859 fcntl (fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
861 interrupts_deferred
= 0;
869 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
873 if (read_socket_hook
)
877 sigunblock (sigmask (SIGWINCH
));
879 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
| FASYNC
);
881 interrupts_deferred
= 0;
886 if (read_socket_hook
)
890 sigblock (sigmask (SIGWINCH
));
892 fcntl (input_fd
, F_SETFL
, old_fcntl_flags
);
893 interrupts_deferred
= 1;
896 #else /* no FASYNC */
897 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
903 if (read_socket_hook
)
906 ioctl (input_fd
, FIOASYNC
, &on
);
907 interrupts_deferred
= 0;
914 if (read_socket_hook
)
917 ioctl (input_fd
, FIOASYNC
, &off
);
918 interrupts_deferred
= 1;
921 #else /* not FASYNC, not STRIDE */
932 if (read_socket_hook
)
936 sigaddset(&st
, SIGIO
);
937 ioctl (input_fd
, FIOASYNC
, &on
);
938 interrupts_deferred
= 0;
939 sigprocmask(SIG_UNBLOCK
, &st
, (sigset_t
*)0);
946 if (read_socket_hook
)
949 ioctl (input_fd
, FIOASYNC
, &off
);
950 interrupts_deferred
= 1;
957 if (read_socket_hook
)
960 croak ("request_sigio");
965 if (read_socket_hook
)
968 croak ("unrequest_sigio");
976 /* Saving and restoring the process group of Emacs's terminal. */
980 /* The process group of which Emacs was a member when it initially
983 If Emacs was in its own process group (i.e. inherited_pgroup ==
984 getpid ()), then we know we're running under a shell with job
985 control (Emacs would never be run as part of a pipeline).
988 If Emacs was not in its own process group, then we know we're
989 running under a shell (or a caller) that doesn't know how to
990 separate itself from Emacs (like sh). Emacs must be in its own
991 process group in order to receive SIGIO correctly. In this
992 situation, we put ourselves in our own pgroup, forcibly set the
993 tty's pgroup to our pgroup, and make sure to restore and reinstate
994 the tty's pgroup just like any other terminal setting. If
995 inherited_group was not the tty's pgroup, then we'll get a
996 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
997 it goes foreground in the future, which is what should happen. */
998 int inherited_pgroup
;
1000 /* Split off the foreground process group to Emacs alone.
1001 When we are in the foreground, but not started in our own process
1002 group, redirect the TTY to point to our own process group. We need
1003 to be in our own process group to receive SIGIO properly. */
1004 narrow_foreground_group ()
1008 setpgrp (0, inherited_pgroup
);
1009 if (inherited_pgroup
!= me
)
1010 EMACS_SET_TTY_PGRP (input_fd
, &me
);
1014 /* Set the tty to our original foreground group. */
1015 widen_foreground_group ()
1017 if (inherited_pgroup
!= getpid ())
1018 EMACS_SET_TTY_PGRP (input_fd
, &inherited_pgroup
);
1019 setpgrp (0, inherited_pgroup
);
1022 #endif /* BSD_PGRPS */
1024 /* Getting and setting emacs_tty structures. */
1026 /* Set *TC to the parameters associated with the terminal FD.
1027 Return zero if all's well, or -1 if we ran into an error we
1028 couldn't deal with. */
1030 emacs_get_tty (fd
, settings
)
1032 struct emacs_tty
*settings
;
1034 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1036 /* We have those nifty POSIX tcmumbleattr functions. */
1037 if (tcgetattr (fd
, &settings
->main
) < 0)
1042 /* The SYSV-style interface? */
1043 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1048 /* Vehemently Monstrous System? :-) */
1049 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1050 &settings
->main
.class, 12, 0, 0, 0, 0)
1056 /* I give up - I hope you have the BSD ioctls. */
1057 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1059 #endif /* not DOS_NT */
1064 /* Suivant - Do we have to get struct ltchars data? */
1066 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1070 /* How about a struct tchars and a wordful of lmode bits? */
1072 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1073 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1077 /* We have survived the tempest. */
1082 /* Set the parameters of the tty on FD according to the contents of
1083 *SETTINGS. If FLUSHP is non-zero, we discard input.
1084 Return 0 if all went well, and -1 if anything failed. */
1087 emacs_set_tty (fd
, settings
, flushp
)
1089 struct emacs_tty
*settings
;
1092 /* Set the primary parameters - baud rate, character size, etcetera. */
1095 /* We have those nifty POSIX tcmumbleattr functions.
1096 William J. Smith <wjs@wiis.wang.com> writes:
1097 "POSIX 1003.1 defines tcsetattr() to return success if it was
1098 able to perform any of the requested actions, even if some
1099 of the requested actions could not be performed.
1100 We must read settings back to ensure tty setup properly.
1101 AIX requires this to keep tty from hanging occasionally." */
1102 /* This make sure that we don't loop indefinitely in here. */
1103 for (i
= 0 ; i
< 10 ; i
++)
1104 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1115 /* Get the current settings, and see if they're what we asked for. */
1116 tcgetattr (fd
, &new);
1117 /* We cannot use memcmp on the whole structure here because under
1118 * aix386 the termios structure has some reserved field that may
1121 if ( new.c_iflag
== settings
->main
.c_iflag
1122 && new.c_oflag
== settings
->main
.c_oflag
1123 && new.c_cflag
== settings
->main
.c_cflag
1124 && new.c_lflag
== settings
->main
.c_lflag
1125 && memcmp(new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1133 /* The SYSV-style interface? */
1134 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1139 /* Vehemently Monstrous System? :-) */
1140 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1141 &settings
->main
.class, 12, 0, 0, 0, 0)
1147 /* I give up - I hope you have the BSD ioctls. */
1148 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1150 #endif /* not DOS_NT */
1156 /* Suivant - Do we have to get struct ltchars data? */
1158 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1162 /* How about a struct tchars and a wordful of lmode bits? */
1164 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1165 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1169 /* We have survived the tempest. */
1174 /* The initial tty mode bits */
1175 struct emacs_tty old_tty
;
1177 /* 1 if we have been through init_sys_modes. */
1180 /* 1 if outer tty status has been recorded. */
1184 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1189 #ifndef F_SETOWN_BUG
1191 int old_fcntl_owner
;
1192 #endif /* F_SETOWN */
1193 #endif /* F_SETOWN_BUG */
1195 /* This may also be defined in stdio,
1196 but if so, this does no harm,
1197 and using the same name avoids wasting the other one's space. */
1199 #if defined (USG) || defined (DGUX)
1200 unsigned char _sobuf
[BUFSIZ
+8];
1202 char _sobuf
[BUFSIZ
];
1206 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1209 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1214 struct emacs_tty tty
;
1218 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1219 extern int (*interrupt_signal
) ();
1223 Vtty_erase_char
= Qnil
;
1230 input_ef
= get_kbd_event_flag ();
1231 /* LIB$GET_EF (&input_ef); */
1232 SYS$
CLREF (input_ef
);
1233 waiting_for_ast
= 0;
1235 timer_ef
= get_timer_event_flag ();
1236 /* LIB$GET_EF (&timer_ef); */
1237 SYS$
CLREF (timer_ef
);
1241 LIB$
GET_EF (&process_ef
);
1242 SYS$
CLREF (process_ef
);
1244 if (input_ef
/ 32 != process_ef
/ 32)
1245 croak ("Input and process event flags in different clusters.");
1247 if (input_ef
/ 32 != timer_ef
/ 32)
1248 croak ("Input and timer event flags in different clusters.");
1250 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1251 ((unsigned) 1 << (process_ef
% 32));
1253 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1254 ((unsigned) 1 << (timer_ef
% 32));
1256 sys_access_reinit ();
1258 #endif /* not VMS */
1261 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1262 narrow_foreground_group ();
1265 #ifdef HAVE_WINDOW_SYSTEM
1266 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1267 needs the initialization code below. */
1268 if (!read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1271 EMACS_GET_TTY (input_fd
, &old_tty
);
1277 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1278 Vtty_erase_char
= old_tty
.main
.c_cc
[VERASE
];
1281 /* This allows meta to be sent on 8th bit. */
1282 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1284 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1285 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1286 #ifdef INLCR /* I'm just being cautious,
1287 since I can't check how widespread INLCR is--rms. */
1288 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1291 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1293 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1294 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1296 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1298 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1301 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1303 tty
.main
.c_iflag
&= ~IXANY
;
1307 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1308 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1310 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1314 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1315 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1318 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1319 /* Set up C-g for both SIGQUIT and SIGINT.
1320 We don't know which we will get, but we handle both alike
1321 so which one it really gives us does not matter. */
1322 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1323 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1324 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1326 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1329 #if defined (mips) || defined (HAVE_TCATTR)
1331 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1334 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1335 #endif /* V_DSUSP */
1336 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1337 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1340 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1343 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1344 #endif /* VREPRINT */
1346 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1347 #endif /* VWERASE */
1349 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1350 #endif /* VDISCARD */
1352 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1355 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1357 #endif /* mips or HAVE_TCATTR */
1358 #ifdef SET_LINE_DISCIPLINE
1359 /* Need to explicitly request TERMIODISC line discipline or
1360 Ultrix's termios does not work correctly. */
1361 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1365 /* AIX enhanced edit loses NULs, so disable it. */
1366 tty
.main
.c_line
= 0;
1367 tty
.main
.c_iflag
&= ~ASCEDIT
;
1369 tty
.main
.c_cc
[VSTRT
] = 255;
1370 tty
.main
.c_cc
[VSTOP
] = 255;
1371 tty
.main
.c_cc
[VSUSP
] = 255;
1372 tty
.main
.c_cc
[VDSUSP
] = 255;
1373 #endif /* IBMR2AIX */
1374 /* Also, PTY overloads NUL and BREAK.
1375 don't ignore break, but don't signal either, so it looks like NUL.
1376 This really serves a purpose only if running in an XTERM window
1377 or via TELNET or the like, but does no harm elsewhere. */
1378 tty
.main
.c_iflag
&= ~IGNBRK
;
1379 tty
.main
.c_iflag
&= ~BRKINT
;
1381 #else /* if not HAVE_TERMIO */
1383 tty
.main
.tt_char
|= TT$M_NOECHO
;
1385 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1387 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1389 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1390 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1391 #else /* not VMS (BSD, that is) */
1393 Vtty_erase_char
= tty
.main
.sg_erase
;
1394 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1396 tty
.main
.sg_flags
|= ANYP
;
1397 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1398 #endif /* not DOS_NT */
1399 #endif /* not VMS (BSD, that is) */
1400 #endif /* not HAVE_TERMIO */
1402 /* If going to use CBREAK mode, we must request C-g to interrupt
1403 and turn off start and stop chars, etc. If not going to use
1404 CBREAK mode, do this anyway so as to turn off local flow
1405 control for user coming over network on 4.2; in this case,
1406 only t_stopc and t_startc really matter. */
1409 /* Note: if not using CBREAK mode, it makes no difference how we
1411 tty
.tchars
= new_tchars
;
1412 tty
.tchars
.t_intrc
= quit_char
;
1415 tty
.tchars
.t_startc
= '\021';
1416 tty
.tchars
.t_stopc
= '\023';
1419 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| old_tty
.lmode
;
1421 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1422 anything, and leaving it in breaks the meta key. Go figure. */
1423 tty
.lmode
&= ~LLITOUT
;
1430 #endif /* HAVE_TCHARS */
1431 #endif /* not HAVE_TERMIO */
1434 tty
.ltchars
= new_ltchars
;
1435 #endif /* HAVE_LTCHARS */
1436 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1438 internal_terminal_init ();
1442 EMACS_SET_TTY (input_fd
, &tty
, 0);
1444 /* This code added to insure that, if flow-control is not to be used,
1445 we have an unlocked terminal at the start. */
1448 if (!flow_control
) ioctl (input_fd
, TCXONC
, 1);
1452 if (!flow_control
) ioctl (input_fd
, TIOCSTART
, 0);
1456 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1458 if (!flow_control
) tcflow (input_fd
, TCOON
);
1466 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1467 to be only LF. This is the way that is done. */
1470 if (ioctl (1, HFTGETID
, &tty
) != -1)
1471 write (1, "\033[20l", 5);
1477 /* Appears to do nothing when in PASTHRU mode.
1478 SYS$QIOW (0, input_fd, IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1479 interrupt_signal, oob_chars, 0, 0, 0, 0);
1481 queue_kbd_input (0);
1486 #ifndef F_SETOWN_BUG
1487 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1489 && ! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1491 old_fcntl_owner
= fcntl (input_fd
, F_GETOWN
, 0);
1492 fcntl (input_fd
, F_SETOWN
, getpid ());
1493 init_sigio (input_fd
);
1495 #endif /* F_GETOWN */
1496 #endif /* F_SETOWN_BUG */
1497 #endif /* F_SETFL */
1500 if (interrupt_input
)
1501 init_sigio (input_fd
);
1504 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1508 /* This symbol is defined on recent USG systems.
1509 Someone says without this call USG won't really buffer the file
1510 even with a call to setbuf. */
1511 setvbuf (stdout
, _sobuf
, _IOFBF
, sizeof _sobuf
);
1513 setbuf (stdout
, _sobuf
);
1515 #ifdef HAVE_WINDOW_SYSTEM
1516 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1517 needs the initialization code below. */
1518 if (! read_socket_hook
&& EQ (Vwindow_system
, Qnil
))
1520 set_terminal_modes ();
1522 if (term_initted
&& no_redraw_on_reenter
)
1524 if (display_completed
)
1525 direct_output_forward_char (0);
1530 if (FRAMEP (Vterminal_frame
))
1531 FRAME_GARBAGED_P (XFRAME (Vterminal_frame
)) = 1;
1537 /* Return nonzero if safe to use tabs in output.
1538 At the time this is called, init_sys_modes has not been done yet. */
1542 struct emacs_tty tty
;
1544 EMACS_GET_TTY (input_fd
, &tty
);
1545 return EMACS_TTY_TABS_OK (&tty
);
1548 /* Get terminal size from system.
1549 Store number of lines into *HEIGHTP and width into *WIDTHP.
1550 We store 0 if there's no valid information. */
1552 get_frame_size (widthp
, heightp
)
1553 int *widthp
, *heightp
;
1559 struct winsize size
;
1561 if (ioctl (input_fd
, TIOCGWINSZ
, &size
) == -1)
1562 *widthp
= *heightp
= 0;
1565 *widthp
= size
.ws_col
;
1566 *heightp
= size
.ws_row
;
1572 /* SunOS - style. */
1573 struct ttysize size
;
1575 if (ioctl (input_fd
, TIOCGSIZE
, &size
) == -1)
1576 *widthp
= *heightp
= 0;
1579 *widthp
= size
.ts_cols
;
1580 *heightp
= size
.ts_lines
;
1586 struct sensemode tty
;
1588 SYS$
QIOW (0, input_fd
, IO$_SENSEMODE
, &tty
, 0, 0,
1589 &tty
.class, 12, 0, 0, 0, 0);
1590 *widthp
= tty
.scr_wid
;
1591 *heightp
= tty
.scr_len
;
1595 *widthp
= ScreenCols ();
1596 *heightp
= ScreenRows ();
1597 #else /* system doesn't know size */
1602 #endif /* not VMS */
1603 #endif /* not SunOS-style */
1604 #endif /* not BSD-style */
1607 /* Set the logical window size associated with descriptor FD
1608 to HEIGHT and WIDTH. This is used mainly with ptys. */
1611 set_window_size (fd
, height
, width
)
1612 int fd
, height
, width
;
1617 struct winsize size
;
1618 size
.ws_row
= height
;
1619 size
.ws_col
= width
;
1621 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1622 return 0; /* error */
1629 /* SunOS - style. */
1630 struct ttysize size
;
1631 size
.ts_lines
= height
;
1632 size
.ts_cols
= width
;
1634 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1640 #endif /* not SunOS-style */
1641 #endif /* not BSD-style */
1645 /* Prepare the terminal for exiting Emacs; move the cursor to the
1646 bottom of the frame, turn off interrupt-driven I/O, etc. */
1656 #ifdef HAVE_WINDOW_SYSTEM
1657 /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
1658 needs the clean-up code below. */
1659 if (read_socket_hook
|| !EQ (Vwindow_system
, Qnil
))
1662 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1663 clear_end_of_line (FRAME_WIDTH (selected_frame
));
1664 /* clear_end_of_line may move the cursor */
1665 cursor_to (FRAME_HEIGHT (selected_frame
) - 1, 0);
1666 #if defined (IBMR2AIX) && defined (AIXHFT)
1668 /* HFT devices normally use ^J as a LF/CR. We forced it to
1669 do the LF only. Now, we need to reset it. */
1672 if (ioctl (1, HFTGETID
, &tty
) != -1)
1673 write (1, "\033[20h", 5);
1677 reset_terminal_modes ();
1681 /* Avoid possible loss of output when changing terminal modes. */
1682 fsync (fileno (stdout
));
1687 #ifndef F_SETOWN_BUG
1688 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
1689 if (interrupt_input
)
1692 fcntl (input_fd
, F_SETOWN
, old_fcntl_owner
);
1694 #endif /* F_SETOWN */
1695 #endif /* F_SETOWN_BUG */
1697 fcntl (input_fd
, F_SETFL
, fcntl (input_fd
, F_GETFL
, 0) & ~O_NDELAY
);
1699 #endif /* F_SETFL */
1701 if (interrupt_input
)
1706 while (EMACS_SET_TTY (input_fd
, &old_tty
, 0) < 0 && errno
== EINTR
)
1709 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
1713 #ifdef SET_LINE_DISCIPLINE
1714 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
1715 A different old line discipline is therefore not restored, yet.
1716 Restore the old line discipline by hand. */
1717 ioctl (0, TIOCSETD
, &old_tty
.main
.c_line
);
1725 widen_foreground_group ();
1731 /* Set up the proper status flags for use of a pty. */
1736 /* I'm told that TOICREMOTE does not mean control chars
1737 "can't be sent" but rather that they don't have
1738 input-editing or signaling effects.
1739 That should be good, because we have other ways
1740 to do those things in Emacs.
1741 However, telnet mode seems not to work on 4.2.
1742 So TIOCREMOTE is turned off now. */
1744 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
1745 will hang. In particular, the "timeout" feature (which
1746 causes a read to return if there is no data available)
1747 does this. Also it is known that telnet mode will hang
1748 in such a way that Emacs must be stopped (perhaps this
1749 is the same problem).
1751 If TIOCREMOTE is turned off, then there is a bug in
1752 hp-ux which sometimes loses data. Apparently the
1753 code which blocks the master process when the internal
1754 buffer fills up does not work. Other than this,
1755 though, everything else seems to work fine.
1757 Since the latter lossage is more benign, we may as well
1758 lose that way. -- cph */
1763 ioctl (fd
, FIONBIO
, &on
);
1768 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
1769 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
1770 /* cause EMACS not to die when it should, i.e., when its own controlling */
1771 /* tty goes away. I've complained to the AIX developers, and they may */
1772 /* change this behavior, but I'm not going to hold my breath. */
1773 signal (SIGHUP
, SIG_IGN
);
1776 #endif /* HAVE_PTYS */
1780 /* Assigning an input channel is done at the start of Emacs execution.
1781 This is called each time Emacs is resumed, also, but does nothing
1782 because input_chain is no longer zero. */
1790 status
= SYS$
ASSIGN (&input_dsc
, &input_fd
, 0, 0);
1796 /* Deassigning the input channel is done before exiting. */
1800 return SYS$
DASSGN (input_fd
);
1805 /* Request reading one character into the keyboard buffer.
1806 This is done as soon as the buffer becomes empty. */
1811 extern kbd_input_ast ();
1813 waiting_for_ast
= 0;
1815 status
= SYS$
QIO (0, input_fd
, IO$_READVBLK
,
1816 &input_iosb
, kbd_input_ast
, 1,
1817 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
1822 /* Ast routine that is called when keyboard input comes in
1823 in accord with the SYS$QIO above. */
1827 register int c
= -1;
1828 int old_errno
= errno
;
1829 extern EMACS_TIME
*input_available_clear_time
;
1831 if (waiting_for_ast
)
1832 SYS$
SETEF (input_ef
);
1833 waiting_for_ast
= 0;
1836 if (input_count
== 25)
1838 printf ("Ast # %d,", input_count
);
1839 printf (" iosb = %x, %x, %x, %x",
1840 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
1843 if (input_iosb
.offset
)
1847 printf (", char = 0%o", c
);
1859 struct input_event e
;
1860 e
.kind
= ascii_keystroke
;
1861 XSETINT (e
.code
, c
);
1862 XSETFRAME (e
.frame_or_window
, selected_frame
);
1863 kbd_buffer_store_event (&e
);
1865 if (input_available_clear_time
)
1866 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
1870 /* Wait until there is something in kbd_buffer. */
1872 wait_for_kbd_input ()
1874 extern int have_process_input
, process_exited
;
1876 /* If already something, avoid doing system calls. */
1877 if (detect_input_pending ())
1881 /* Clear a flag, and tell ast routine above to set it. */
1882 SYS$
CLREF (input_ef
);
1883 waiting_for_ast
= 1;
1884 /* Check for timing error: ast happened while we were doing that. */
1885 if (!detect_input_pending ())
1887 /* No timing error: wait for flag to be set. */
1888 set_waiting_for_input (0);
1889 SYS$
WFLOR (input_ef
, input_eflist
);
1890 clear_waiting_for_input (0);
1891 if (!detect_input_pending ())
1892 /* Check for subprocess input availability */
1894 int dsp
= have_process_input
|| process_exited
;
1896 SYS$
CLREF (process_ef
);
1897 if (have_process_input
)
1898 process_command_input ();
1903 update_mode_lines
++;
1904 prepare_menu_bars ();
1905 redisplay_preserve_echo_area ();
1909 waiting_for_ast
= 0;
1912 /* Get rid of any pending QIO, when we are about to suspend
1913 or when we want to throw away pending input.
1914 We wait for a positive sign that the AST routine has run
1915 and therefore there is no I/O request queued when we return.
1916 SYS$SETAST is used to avoid a timing error. */
1921 printf ("At end_kbd_input.\n");
1925 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
1927 SYS$
CANCEL (input_fd
);
1932 /* Clear a flag, and tell ast routine above to set it. */
1933 SYS$
CLREF (input_ef
);
1934 waiting_for_ast
= 1;
1936 SYS$
CANCEL (input_fd
);
1938 SYS$
WAITFR (input_ef
);
1939 waiting_for_ast
= 0;
1942 /* Wait for either input available or time interval expiry. */
1944 input_wait_timeout (timeval
)
1945 int timeval
; /* Time to wait, in seconds */
1948 static int zero
= 0;
1949 static int large
= -10000000;
1951 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1953 /* If already something, avoid doing system calls. */
1954 if (detect_input_pending ())
1958 /* Clear a flag, and tell ast routine above to set it. */
1959 SYS$
CLREF (input_ef
);
1960 waiting_for_ast
= 1;
1961 /* Check for timing error: ast happened while we were doing that. */
1962 if (!detect_input_pending ())
1964 /* No timing error: wait for flag to be set. */
1966 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1967 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
1969 waiting_for_ast
= 0;
1972 /* The standard `sleep' routine works some other way
1973 and it stops working if you have ever quit out of it.
1974 This one continues to work. */
1980 static int zero
= 0;
1981 static int large
= -10000000;
1983 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
1986 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
1987 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2003 croak ("request sigio");
2008 croak ("unrequest sigio");
2013 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2018 #ifndef SYSTEM_MALLOC
2025 /* Some systems that cannot dump also cannot implement these. */
2028 * Return the address of the start of the text segment prior to
2029 * doing an unexec. After unexec the return value is undefined.
2030 * See crt0.c for further explanation and _start.
2034 #ifndef HAVE_TEXT_START
2039 return ((char *) TEXT_START
);
2043 return ((char *) csrt
);
2044 #else /* not GOULD */
2045 extern int _start ();
2046 return ((char *) _start
);
2048 #endif /* TEXT_START */
2050 #endif /* not HAVE_TEXT_START */
2053 * Return the address of the start of the data segment prior to
2054 * doing an unexec. After unexec the return value is undefined.
2055 * See crt0.c for further information and definition of data_start.
2057 * Apparently, on BSD systems this is etext at startup. On
2058 * USG systems (swapping) this is highly mmu dependent and
2059 * is also dependent on whether or not the program is running
2060 * with shared text. Generally there is a (possibly large)
2061 * gap between end of text and start of data with shared text.
2063 * On Uniplus+ systems with shared text, data starts at a
2064 * fixed address. Each port (from a given oem) is generally
2065 * different, and the specific value of the start of data can
2066 * be obtained via the UniPlus+ specific "uvar" system call,
2067 * however the method outlined in crt0.c seems to be more portable.
2069 * Probably what will have to happen when a USG unexec is available,
2070 * at least on UniPlus, is temacs will have to be made unshared so
2071 * that text and data are contiguous. Then once loadup is complete,
2072 * unexec will produce a shared executable where the data can be
2073 * at the normal shared text boundary and the startofdata variable
2074 * will be patched by unexec to the correct value.
2082 return ((char *) DATA_START
);
2084 #ifdef ORDINARY_LINK
2086 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2087 * data_start isn't defined. We take the address of environ, which
2088 * is known to live at or near the start of the system crt0.c, and
2089 * we don't sweat the handful of bytes that might lose.
2091 extern char **environ
;
2093 return((char *) &environ
);
2095 extern int data_start
;
2096 return ((char *) &data_start
);
2097 #endif /* ORDINARY_LINK */
2098 #endif /* DATA_START */
2100 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2103 /* Some systems that cannot dump also cannot implement these. */
2106 * Return the address of the end of the text segment prior to
2107 * doing an unexec. After unexec the return value is undefined.
2114 return ((char *) TEXT_END
);
2117 return ((char *) &etext
);
2122 * Return the address of the end of the data segment prior to
2123 * doing an unexec. After unexec the return value is undefined.
2130 return ((char *) DATA_END
);
2133 return ((char *) &edata
);
2137 #endif /* not CANNOT_DUMP */
2139 /* init_system_name sets up the string for the Lisp function
2140 system-name to return. */
2146 extern Lisp_Object Vsystem_name
;
2151 #include <sys/socket.h>
2153 #endif /* HAVE_SOCKETS */
2154 #endif /* not VMS */
2155 #endif /* not BSD4_1 */
2161 Vsystem_name
= build_string (sysname
);
2165 if ((sp
= egetenv ("SYS$NODE")) == 0)
2166 Vsystem_name
= build_string ("vax-vms");
2167 else if ((end
= index (sp
, ':')) == 0)
2168 Vsystem_name
= build_string (sp
);
2170 Vsystem_name
= make_string (sp
, end
- sp
);
2172 #ifndef HAVE_GETHOSTNAME
2175 Vsystem_name
= build_string (uts
.nodename
);
2176 #else /* HAVE_GETHOSTNAME */
2177 unsigned int hostname_size
= 256;
2178 char *hostname
= (char *) alloca (hostname_size
);
2180 /* Try to get the host name; if the buffer is too short, try
2181 again. Apparently, the only indication gethostname gives of
2182 whether the buffer was large enough is the presence or absence
2183 of a '\0' in the string. Eech. */
2186 gethostname (hostname
, hostname_size
- 1);
2187 hostname
[hostname_size
- 1] = '\0';
2189 /* Was the buffer large enough for the '\0'? */
2190 if (strlen (hostname
) < hostname_size
- 1)
2193 hostname_size
<<= 1;
2194 hostname
= (char *) alloca (hostname_size
);
2197 /* Turn the hostname into the official, fully-qualified hostname.
2198 Don't do this if we're going to dump; this can confuse system
2199 libraries on some machines and make the dumped emacs core dump. */
2202 #endif /* not CANNOT_DUMP */
2206 for (count
= 0;; count
++)
2211 hp
= gethostbyname (hostname
);
2213 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2218 Fsleep_for (make_number (1), Qnil
);
2222 char *fqdn
= (char *) hp
->h_name
;
2225 if (!index (fqdn
, '.'))
2227 /* We still don't have a fully qualified domain name.
2228 Try to find one in the list of alternate names */
2229 char **alias
= hp
->h_aliases
;
2230 while (*alias
&& !index (*alias
, '.'))
2237 /* Convert the host name to lower case. */
2238 /* Using ctype.h here would introduce a possible locale
2239 dependence that is probably wrong for hostnames. */
2243 if (*p
>= 'A' && *p
<= 'Z')
2250 #endif /* HAVE_SOCKETS */
2251 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN)) || HAVE_GETDOMAINNAME
2252 if (! index (hostname
, '.'))
2254 /* The hostname is not fully qualified. Append the domain name. */
2256 int hostlen
= strlen (hostname
);
2257 int domain_size
= 256;
2261 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
);
2262 char *domain
= fqdn
+ hostlen
+ 1;
2263 #if HAVE_SYSINFO && defined (SI_SRPC_DOMAIN)
2264 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2265 if (sys_domain_size
<= 0)
2267 if (domain_size
< sys_domain_size
)
2269 domain_size
= sys_domain_size
;
2272 #else /* HAVE_GETDOMAINNAME */
2273 if (getdomainname (domain
, domain_size
- 1) != 0 || ! *domain
)
2275 domain
[domain_size
- 1] = '\0';
2276 if (strlen (domain
) == domain_size
- 1)
2281 #endif /* HAVE_GETDOMAINNAME */
2282 strcpy (fqdn
, hostname
);
2283 fqdn
[hostlen
] = '.';
2288 #endif /*! ((HAVE_SYSINFO && defined (SI_SRPC_DOMAIN)) || HAVE_GETDOMAINNAME)*/
2289 Vsystem_name
= build_string (hostname
);
2290 #endif /* HAVE_GETHOSTNAME */
2295 for (p
= XSTRING (Vsystem_name
)->data
; *p
; p
++)
2296 if (*p
== ' ' || *p
== '\t')
2303 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2305 #include "sysselect.h"
2308 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2309 /* Cause explanatory error message at compile time,
2310 since the select emulation is not good enough for X. */
2311 int *x
= &x_windows_lose_if_no_select_system_call
;
2314 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2315 * Only checks read descriptors.
2317 /* How long to wait between checking fds in select */
2318 #define SELECT_PAUSE 1
2321 /* For longjmp'ing back to read_input_waiting. */
2323 jmp_buf read_alarm_throw
;
2325 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2326 The read_socket_hook function sets this to 1 while it is waiting. */
2328 int read_alarm_should_throw
;
2336 #else /* not BSD4_1 */
2337 signal (SIGALRM
, SIG_IGN
);
2338 #endif /* not BSD4_1 */
2339 if (read_alarm_should_throw
)
2340 longjmp (read_alarm_throw
, 1);
2344 /* Only rfds are checked. */
2346 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2348 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2349 EMACS_TIME
*timeout
;
2351 int ravail
= 0, old_alarm
;
2355 extern int proc_buffered_char
[];
2356 #ifndef subprocesses
2357 int process_tick
= 0, update_tick
= 0;
2359 extern int process_tick
, update_tick
;
2361 SIGTYPE (*old_trap
) ();
2364 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2365 /* If we're using X, then the native select will work; we only need the
2366 emulation for non-X usage. */
2367 if (!NILP (Vwindow_system
))
2368 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2370 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2371 local_timeout
= &timeoutval
;
2383 /* If we are looking only for the terminal, with no timeout,
2384 just read it and wait -- that's more efficient. */
2385 if (*local_timeout
== 100000 && process_tick
== update_tick
2386 && FD_ISSET (0, &orfds
))
2389 for (fd
= 1; fd
< nfds
; ++fd
)
2390 if (FD_ISSET (fd
, &orfds
))
2392 if (! detect_input_pending ())
2393 read_input_waiting ();
2399 /* Once a second, till the timer expires, check all the flagged read
2400 * descriptors to see if any input is available. If there is some then
2401 * set the corresponding bit in the return copy of rfds.
2405 register int to_check
, fd
;
2409 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2411 if (FD_ISSET (fd
, &orfds
))
2413 int avail
= 0, status
= 0;
2416 avail
= detect_input_pending (); /* Special keyboard handler */
2420 status
= ioctl (fd
, FIONREAD
, &avail
);
2421 #else /* no FIONREAD */
2422 /* Hoping it will return -1 if nothing available
2423 or 0 if all 0 chars requested are read. */
2424 if (proc_buffered_char
[fd
] >= 0)
2428 avail
= read (fd
, &buf
, 1);
2430 proc_buffered_char
[fd
] = buf
;
2432 #endif /* no FIONREAD */
2434 if (status
>= 0 && avail
> 0)
2442 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2444 old_alarm
= alarm (0);
2445 old_trap
= signal (SIGALRM
, select_alarm
);
2447 alarm (SELECT_PAUSE
);
2448 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2449 while (select_alarmed
== 0 && *local_timeout
!= 0
2450 && process_tick
== update_tick
)
2452 /* If we are interested in terminal input,
2453 wait by reading the terminal.
2454 That makes instant wakeup for terminal input at least. */
2455 if (FD_ISSET (0, &orfds
))
2457 read_input_waiting ();
2458 if (detect_input_pending ())
2464 (*local_timeout
) -= SELECT_PAUSE
;
2465 /* Reset the old alarm if there was one */
2467 signal (SIGALRM
, old_trap
);
2470 /* Reset or forge an interrupt for the original handler. */
2471 old_alarm
-= SELECT_PAUSE
;
2473 kill (getpid (), SIGALRM
); /* Fake an alarm with the orig' handler */
2477 if (*local_timeout
== 0) /* Stop on timer being cleared */
2482 #endif /* not WINDOWSNT */
2484 /* Read keyboard input into the standard buffer,
2485 waiting for at least one character. */
2487 /* Make all keyboard buffers much bigger when using a window system. */
2488 #ifdef HAVE_WINDOW_SYSTEM
2489 #define BUFFER_SIZE_FACTOR 16
2491 #define BUFFER_SIZE_FACTOR 1
2494 read_input_waiting ()
2496 struct input_event e
;
2498 extern int quit_char
;
2500 if (read_socket_hook
)
2502 struct input_event buf
[256];
2504 read_alarm_should_throw
= 0;
2505 if (! setjmp (read_alarm_throw
))
2506 nread
= (*read_socket_hook
) (0, buf
, 256, 1, 0);
2510 /* Scan the chars for C-g and store them in kbd_buffer. */
2511 for (i
= 0; i
< nread
; i
++)
2513 kbd_buffer_store_event (&buf
[i
]);
2514 /* Don't look at input that follows a C-g too closely.
2515 This reduces lossage due to autorepeat on C-g. */
2516 if (buf
[i
].kind
== ascii_keystroke
2517 && buf
[i
].code
== quit_char
)
2524 nread
= read (fileno (stdin
), buf
, 1);
2526 /* Scan the chars for C-g and store them in kbd_buffer. */
2527 e
.kind
= ascii_keystroke
;
2528 XSETFRAME (e
.frame_or_window
, selected_frame
);
2530 for (i
= 0; i
< nread
; i
++)
2532 /* Convert chars > 0177 to meta events if desired.
2533 We do this under the same conditions that read_avail_input does. */
2534 if (read_socket_hook
== 0)
2536 /* If the user says she has a meta key, then believe her. */
2537 if (meta_key
== 1 && (buf
[i
] & 0x80))
2538 e
.modifiers
= meta_modifier
;
2543 XSETINT (e
.code
, buf
[i
]);
2544 kbd_buffer_store_event (&e
);
2545 /* Don't look at input that follows a C-g too closely.
2546 This reduces lossage due to autorepeat on C-g. */
2547 if (buf
[i
] == quit_char
)
2553 #endif /* not HAVE_SELECT */
2554 #endif /* not VMS */
2555 #endif /* not MSDOS */
2559 * Partially emulate 4.2 open call.
2560 * open is defined as this in 4.1.
2562 * - added by Michael Bloom @ Citicorp/TTI
2567 sys_open (path
, oflag
, mode
)
2571 if (oflag
& O_CREAT
)
2572 return creat (path
, mode
);
2574 return open (path
, oflag
);
2582 lmode
= LINTRUP
| lmode
;
2583 ioctl (fd
, TIOCLSET
, &lmode
);
2590 lmode
= ~LINTRUP
& lmode
;
2591 ioctl (0, TIOCLSET
, &lmode
);
2598 interrupts_deferred
= 0;
2605 interrupts_deferred
= 1;
2608 /* still inside #ifdef BSD4_1 */
2611 int sigheld
; /* Mask of held signals */
2616 sigheld
|= sigbit (signum
);
2623 sigheld
|= sigbit (signum
);
2629 sigheld
&= ~sigbit (signum
);
2633 sigfree () /* Free all held signals */
2636 for (i
= 0; i
< NSIG
; i
++)
2637 if (sigheld
& sigbit (i
))
2644 return 1 << (i
- 1);
2646 #endif /* subprocesses */
2649 /* POSIX signals support - DJB */
2650 /* Anyone with POSIX signals should have ANSI C declarations */
2652 #ifdef POSIX_SIGNALS
2654 sigset_t old_mask
, empty_mask
, full_mask
, temp_mask
;
2655 static struct sigaction new_action
, old_action
;
2659 sigemptyset (&empty_mask
);
2660 sigfillset (&full_mask
);
2664 sys_signal (int signal_number
, signal_handler_t action
)
2667 /* This gets us restartable system calls for efficiency.
2668 The "else" code will works as well. */
2669 return (berk_signal (signal_number
, action
));
2671 sigemptyset (&new_action
.sa_mask
);
2672 new_action
.sa_handler
= action
;
2674 /* Emacs mostly works better with restartable system services. If this
2675 * flag exists, we probably want to turn it on here.
2677 new_action
.sa_flags
= SA_RESTART
;
2679 new_action
.sa_flags
= 0;
2681 sigaction (signal_number
, &new_action
, &old_action
);
2682 return (old_action
.sa_handler
);
2687 /* If we're compiling with GCC, we don't need this function, since it
2688 can be written as a macro. */
2690 sys_sigmask (int sig
)
2693 sigemptyset (&mask
);
2694 sigaddset (&mask
, sig
);
2700 sys_sigpause (sigset_t new_mask
)
2702 /* pause emulating berk sigpause... */
2703 sigsuspend (&new_mask
);
2707 /* I'd like to have these guys return pointers to the mask storage in here,
2708 but there'd be trouble if the code was saving multiple masks. I'll be
2709 safe and pass the structure. It normally won't be more than 2 bytes
2713 sys_sigblock (sigset_t new_mask
)
2716 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
2721 sys_sigunblock (sigset_t new_mask
)
2724 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
2729 sys_sigsetmask (sigset_t new_mask
)
2732 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
2736 #endif /* POSIX_SIGNALS */
2744 /* Figure out how many bits the system's random number generator uses.
2745 `random' and `lrand48' are assumed to return 31 usable bits.
2746 BSD `rand' returns a 31 bit value but the low order bits are unusable;
2747 so we'll shift it and treat it like the 15-bit USG `rand'. */
2751 # define RAND_BITS 31
2752 # else /* !HAVE_RANDOM */
2753 # ifdef HAVE_LRAND48
2754 # define RAND_BITS 31
2755 # define random lrand48
2756 # else /* !HAVE_LRAND48 */
2757 # define RAND_BITS 15
2758 # if RAND_MAX == 32767
2759 # define random rand
2760 # else /* RAND_MAX != 32767 */
2761 # if RAND_MAX == 2147483647
2762 # define random() (rand () >> 16)
2763 # else /* RAND_MAX != 2147483647 */
2765 # define random rand
2767 # define random() (rand () >> 16)
2769 # endif /* RAND_MAX != 2147483647 */
2770 # endif /* RAND_MAX != 32767 */
2771 # endif /* !HAVE_LRAND48 */
2772 # endif /* !HAVE_RANDOM */
2773 #endif /* !RAND_BITS */
2780 srandom ((unsigned int)arg
);
2782 # ifdef HAVE_LRAND48
2785 srand ((unsigned int)arg
);
2791 * Build a full Emacs-sized word out of whatever we've got.
2792 * This suffices even for a 64-bit architecture with a 15-bit rand.
2797 long val
= random ();
2798 #if VALBITS > RAND_BITS
2799 val
= (val
<< RAND_BITS
) ^ random ();
2800 #if VALBITS > 2*RAND_BITS
2801 val
= (val
<< RAND_BITS
) ^ random ();
2802 #if VALBITS > 3*RAND_BITS
2803 val
= (val
<< RAND_BITS
) ^ random ();
2804 #if VALBITS > 4*RAND_BITS
2805 val
= (val
<< RAND_BITS
) ^ random ();
2806 #endif /* need at least 5 */
2807 #endif /* need at least 4 */
2808 #endif /* need at least 3 */
2809 #endif /* need at least 2 */
2810 return val
& ((1L << VALBITS
) - 1);
2813 #ifdef WRONG_NAME_INSQUE
2826 /* If any place else asks for the TERM variable,
2827 allow it to be overridden with the EMACS_TERM variable
2828 before attempting to translate the logical name TERM. As a last
2829 resort, ask for VAX C's special idea of the TERM variable. */
2836 static char buf
[256];
2837 static struct dsc$descriptor_s equiv
2838 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
2839 static struct dsc$descriptor_s d_name
2840 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
2843 if (!strcmp (name
, "TERM"))
2845 val
= (char *) getenv ("EMACS_TERM");
2850 d_name
.dsc$w_length
= strlen (name
);
2851 d_name
.dsc$a_pointer
= name
;
2852 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
2854 char *str
= (char *) xmalloc (eqlen
+ 1);
2855 bcopy (buf
, str
, eqlen
);
2857 /* This is a storage leak, but a pain to fix. With luck,
2858 no one will ever notice. */
2861 return (char *) getenv (name
);
2866 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
2867 to force a call on the debugger from within the image. */
2872 LIB$
SIGNAL (SS$_DEBUG
);
2878 #ifdef LINK_CRTL_SHARE
2879 #ifdef SHARABLE_LIB_BUG
2880 /* Variables declared noshare and initialized in sharable libraries
2881 cannot be shared. The VMS linker incorrectly forces you to use a private
2882 version which is uninitialized... If not for this "feature", we
2883 could use the C library definition of sys_nerr and sys_errlist. */
2885 char *sys_errlist
[] =
2889 "no such file or directory",
2891 "interrupted system call",
2893 "no such device or address",
2894 "argument list too long",
2895 "exec format error",
2898 "no more processes",
2899 "not enough memory",
2900 "permission denied",
2902 "block device required",
2903 "mount devices busy",
2905 "cross-device link",
2910 "file table overflow",
2911 "too many open files",
2915 "no space left on device",
2917 "read-only file system",
2923 "vax/vms specific error code nontranslatable error"
2925 #endif /* SHARABLE_LIB_BUG */
2926 #endif /* LINK_CRTL_SHARE */
2929 #ifndef HAVE_STRERROR
2935 extern char *sys_errlist
[];
2936 extern int sys_nerr
;
2938 if (errnum
>= 0 && errnum
< sys_nerr
)
2939 return sys_errlist
[errnum
];
2940 return (char *) "Unknown error";
2942 #endif /* not WINDOWSNT */
2943 #endif /* ! HAVE_STRERROR */
2945 #ifdef INTERRUPTIBLE_OPEN
2949 sys_open (path
, oflag
, mode
)
2953 register int rtnval
;
2955 while ((rtnval
= open (path
, oflag
, mode
)) == -1
2956 && (errno
== EINTR
));
2960 #endif /* INTERRUPTIBLE_OPEN */
2962 #ifdef INTERRUPTIBLE_CLOSE
2968 register int rtnval
;
2970 while ((rtnval
= close (fd
)) == -1
2971 && (errno
== EINTR
))
2974 /* If close is interrupted SunOS 4.1 may or may not have closed the
2975 file descriptor. If it did the second close will fail with
2976 errno = EBADF. That means we have succeeded. */
2977 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
2983 #endif /* INTERRUPTIBLE_CLOSE */
2985 #ifdef INTERRUPTIBLE_IO
2988 sys_read (fildes
, buf
, nbyte
)
2993 register int rtnval
;
2995 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
2996 && (errno
== EINTR
));
3001 sys_write (fildes
, buf
, nbyte
)
3006 register int rtnval
, bytes_written
;
3012 rtnval
= write (fildes
, buf
, nbyte
);
3019 return (bytes_written
? bytes_written
: -1);
3024 bytes_written
+= rtnval
;
3026 return (bytes_written
);
3029 #endif /* INTERRUPTIBLE_IO */
3034 * Substitute fork for vfork on USG flavors.
3042 #endif /* not WINDOWSNT */
3043 #endif /* not HAVE_VFORK */
3047 * All of the following are for USG.
3049 * On USG systems the system calls are INTERRUPTIBLE by signals
3050 * that the user program has elected to catch. Thus the system call
3051 * must be retried in these cases. To handle this without massive
3052 * changes in the source code, we remap the standard system call names
3053 * to names for our own functions in sysdep.c that do the system call
3054 * with retries. Actually, for portability reasons, it is good
3055 * programming practice, as this example shows, to limit all actual
3056 * system calls to a single occurrence in the source. Sure, this
3057 * adds an extra level of function call overhead but it is almost
3058 * always negligible. Fred Fish, Unisoft Systems Inc.
3061 #ifndef HAVE_SYS_SIGLIST
3062 char *sys_siglist
[NSIG
+ 1] =
3065 /* AIX has changed the signals a bit */
3066 "bogus signal", /* 0 */
3067 "hangup", /* 1 SIGHUP */
3068 "interrupt", /* 2 SIGINT */
3069 "quit", /* 3 SIGQUIT */
3070 "illegal instruction", /* 4 SIGILL */
3071 "trace trap", /* 5 SIGTRAP */
3072 "IOT instruction", /* 6 SIGIOT */
3073 "crash likely", /* 7 SIGDANGER */
3074 "floating point exception", /* 8 SIGFPE */
3075 "kill", /* 9 SIGKILL */
3076 "bus error", /* 10 SIGBUS */
3077 "segmentation violation", /* 11 SIGSEGV */
3078 "bad argument to system call", /* 12 SIGSYS */
3079 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3080 "alarm clock", /* 14 SIGALRM */
3081 "software termination signum", /* 15 SIGTERM */
3082 "user defined signal 1", /* 16 SIGUSR1 */
3083 "user defined signal 2", /* 17 SIGUSR2 */
3084 "death of a child", /* 18 SIGCLD */
3085 "power-fail restart", /* 19 SIGPWR */
3086 "bogus signal", /* 20 */
3087 "bogus signal", /* 21 */
3088 "bogus signal", /* 22 */
3089 "bogus signal", /* 23 */
3090 "bogus signal", /* 24 */
3091 "LAN I/O interrupt", /* 25 SIGAIO */
3092 "PTY I/O interrupt", /* 26 SIGPTY */
3093 "I/O intervention required", /* 27 SIGIOINT */
3095 "HFT grant", /* 28 SIGGRANT */
3096 "HFT retract", /* 29 SIGRETRACT */
3097 "HFT sound done", /* 30 SIGSOUND */
3098 "HFT input ready", /* 31 SIGMSG */
3101 "bogus signal", /* 0 */
3102 "hangup", /* 1 SIGHUP */
3103 "interrupt", /* 2 SIGINT */
3104 "quit", /* 3 SIGQUIT */
3105 "illegal instruction", /* 4 SIGILL */
3106 "trace trap", /* 5 SIGTRAP */
3107 "IOT instruction", /* 6 SIGIOT */
3108 "EMT instruction", /* 7 SIGEMT */
3109 "floating point exception", /* 8 SIGFPE */
3110 "kill", /* 9 SIGKILL */
3111 "bus error", /* 10 SIGBUS */
3112 "segmentation violation", /* 11 SIGSEGV */
3113 "bad argument to system call", /* 12 SIGSYS */
3114 "write on a pipe with no one to read it", /* 13 SIGPIPE */
3115 "alarm clock", /* 14 SIGALRM */
3116 "software termination signum", /* 15 SIGTERM */
3117 "user defined signal 1", /* 16 SIGUSR1 */
3118 "user defined signal 2", /* 17 SIGUSR2 */
3119 "death of a child", /* 18 SIGCLD */
3120 "power-fail restart", /* 19 SIGPWR */
3122 "window size change", /* 20 SIGWINCH */
3123 "urgent socket condition", /* 21 SIGURG */
3124 "pollable event occurred", /* 22 SIGPOLL */
3125 "stop (cannot be caught or ignored)", /* 23 SIGSTOP */
3126 "user stop requested from tty", /* 24 SIGTSTP */
3127 "stopped process has been continued", /* 25 SIGCONT */
3128 "background tty read attempted", /* 26 SIGTTIN */
3129 "background tty write attempted", /* 27 SIGTTOU */
3130 "virtual timer expired", /* 28 SIGVTALRM */
3131 "profiling timer expired", /* 29 SIGPROF */
3132 "exceeded cpu limit", /* 30 SIGXCPU */
3133 "exceeded file size limit", /* 31 SIGXFSZ */
3134 "process's lwps are blocked", /* 32 SIGWAITING */
3135 "special signal used by thread library", /* 33 SIGLWP */
3137 "Special Signal Used By CPR", /* 34 SIGFREEZE */
3140 "Special Signal Used By CPR", /* 35 SIGTHAW */
3143 #endif /* not AIX */
3146 #endif /* HAVE_SYS_SIGLIST */
3149 * Warning, this function may not duplicate 4.2 action properly
3150 * under error conditions.
3154 /* In 4.1, param.h fails to define this. */
3155 #define MAXPATHLEN 1024
3164 char *npath
, *spath
;
3165 extern char *getcwd ();
3167 BLOCK_INPUT
; /* getcwd uses malloc */
3168 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3171 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3172 up to first slash. Should be harmless on other systems. */
3173 while (*npath
&& *npath
!= '/')
3175 strcpy (pathname
, npath
);
3176 free (spath
); /* getcwd uses malloc */
3181 #endif /* HAVE_GETWD */
3184 * Emulate rename using unlink/link. Note that this is
3185 * only partially correct. Also, doesn't enforce restriction
3186 * that files be of same type (regular->regular, dir->dir, etc).
3195 if (access (from
, 0) == 0)
3198 if (link (from
, to
) == 0)
3199 if (unlink (from
) == 0)
3211 /* HPUX curses library references perror, but as far as we know
3212 it won't be called. Anyway this definition will do for now. */
3218 #endif /* not HAVE_PERROR */
3224 * Emulate BSD dup2. First close newd if it already exists.
3225 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3226 * until we are, then close the unsuccessful ones.
3233 register int fd
, ret
;
3238 fd
= fcntl (oldd
, F_DUPFD
, newd
);
3240 error ("can't dup2 (%i,%i) : %s", oldd
, newd
, strerror (errno
));
3247 ret
= dup2 (old
,new);
3253 #endif /* not HAVE_DUP2 */
3256 * Gettimeofday. Simulate as much as possible. Only accurate
3257 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3258 * Only needed when subprocesses are defined.
3263 #ifndef HAVE_GETTIMEOFDAY
3267 gettimeofday (tp
, tzp
)
3269 struct timezone
*tzp
;
3271 extern long time ();
3273 tp
->tv_sec
= time ((long *)0);
3276 tzp
->tz_minuteswest
= -1;
3282 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3285 * This function will go away as soon as all the stubs fixed. (fnf)
3291 printf ("%s not yet implemented\r\n", badfunc
);
3300 char *sys_siglist
[NSIG
+ 1] =
3302 "null signal", /* 0 SIGNULL */
3303 "hangup", /* 1 SIGHUP */
3304 "interrupt", /* 2 SIGINT */
3305 "quit", /* 3 SIGQUIT */
3306 "illegal instruction", /* 4 SIGILL */
3307 "trace trap", /* 5 SIGTRAP */
3308 "abort termination", /* 6 SIGABRT */
3309 "SIGEMT", /* 7 SIGEMT */
3310 "floating point exception", /* 8 SIGFPE */
3311 "kill", /* 9 SIGKILL */
3312 "bus error", /* 10 SIGBUS */
3313 "segmentation violation", /* 11 SIGSEGV */
3314 "bad argument to system call", /* 12 SIGSYS */
3315 "write on a pipe with no reader", /* 13 SIGPIPE */
3316 "alarm clock", /* 14 SIGALRM */
3317 "software termination signal", /* 15 SIGTERM */
3318 "user defined signal 1", /* 16 SIGUSR1 */
3319 "user defined signal 2", /* 17 SIGUSR2 */
3320 "child stopped or terminated", /* 18 SIGCLD */
3321 "power-fail restart", /* 19 SIGPWR */
3322 "window size changed", /* 20 SIGWINCH */
3323 "undefined", /* 21 */
3324 "pollable event occurred", /* 22 SIGPOLL */
3325 "sendable stop signal not from tty", /* 23 SIGSTOP */
3326 "stop signal from tty", /* 24 SIGSTP */
3327 "continue a stopped process", /* 25 SIGCONT */
3328 "attempted background tty read", /* 26 SIGTTIN */
3329 "attempted background tty write", /* 27 SIGTTOU */
3330 "undefined", /* 28 */
3331 "undefined", /* 29 */
3332 "undefined", /* 30 */
3333 "undefined", /* 31 */
3334 "undefined", /* 32 */
3335 "socket (TCP/IP) urgent data arrival", /* 33 SIGURG */
3336 "I/O is possible", /* 34 SIGIO */
3337 "exceeded cpu time limit", /* 35 SIGXCPU */
3338 "exceeded file size limit", /* 36 SIGXFSZ */
3339 "virtual time alarm", /* 37 SIGVTALRM */
3340 "profiling time alarm", /* 38 SIGPROF */
3341 "undefined", /* 39 */
3342 "file record locks revoked", /* 40 SIGLOST */
3343 "undefined", /* 41 */
3344 "undefined", /* 42 */
3345 "undefined", /* 43 */
3346 "undefined", /* 44 */
3347 "undefined", /* 45 */
3348 "undefined", /* 46 */
3349 "undefined", /* 47 */
3350 "undefined", /* 48 */
3351 "undefined", /* 49 */
3352 "undefined", /* 50 */
3353 "undefined", /* 51 */
3354 "undefined", /* 52 */
3355 "undefined", /* 53 */
3356 "undefined", /* 54 */
3357 "undefined", /* 55 */
3358 "undefined", /* 56 */
3359 "undefined", /* 57 */
3360 "undefined", /* 58 */
3361 "undefined", /* 59 */
3362 "undefined", /* 60 */
3363 "undefined", /* 61 */
3364 "undefined", /* 62 */
3365 "undefined", /* 63 */
3366 "notification message in mess. queue", /* 64 SIGDGNOTIFY */
3372 /* Directory routines for systems that don't have them. */
3374 #ifdef SYSV_SYSTEM_DIR
3378 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
3382 register DIR *dirp
; /* stream from opendir */
3386 rtnval
= sys_close (dirp
->dd_fd
);
3388 /* Some systems (like Solaris) allocate the buffer and the DIR all
3389 in one block. Why in the world are we freeing this ourselves
3391 #if ! (defined (sun) && defined (USG5_4))
3392 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3394 xfree ((char *) dirp
);
3398 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3399 #endif /* SYSV_SYSTEM_DIR */
3401 #ifdef NONSYSTEM_DIR_LIBRARY
3405 char *filename
; /* name of directory */
3407 register DIR *dirp
; /* -> malloc'ed storage */
3408 register int fd
; /* file descriptor for read */
3409 struct stat sbuf
; /* result of fstat */
3411 fd
= sys_open (filename
, 0);
3416 if (fstat (fd
, &sbuf
) < 0
3417 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3418 || (dirp
= (DIR *) malloc (sizeof (DIR))) == 0)
3422 return 0; /* bad luck today */
3427 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3434 register DIR *dirp
; /* stream from opendir */
3436 sys_close (dirp
->dd_fd
);
3437 xfree ((char *) dirp
);
3445 ino_t od_ino
; /* inode */
3446 char od_name
[DIRSIZ
]; /* filename */
3448 #endif /* not VMS */
3450 struct direct dir_static
; /* simulated directory contents */
3455 register DIR *dirp
; /* stream from opendir */
3458 register struct olddir
*dp
; /* -> directory data */
3460 register struct dir$_name
*dp
; /* -> directory data */
3461 register struct dir$_version
*dv
; /* -> version data */
3466 if (dirp
->dd_loc
>= dirp
->dd_size
)
3467 dirp
->dd_loc
= dirp
->dd_size
= 0;
3469 if (dirp
->dd_size
== 0 /* refill buffer */
3470 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3474 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3475 dirp
->dd_loc
+= sizeof (struct olddir
);
3477 if (dp
->od_ino
!= 0) /* not deleted entry */
3479 dir_static
.d_ino
= dp
->od_ino
;
3480 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3481 dir_static
.d_name
[DIRSIZ
] = '\0';
3482 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3483 dir_static
.d_reclen
= sizeof (struct direct
)
3485 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3486 return &dir_static
; /* -> simulated structure */
3489 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3490 if (dirp
->dd_loc
== 0)
3491 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3492 : dp
->dir$b_namecount
;
3493 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3494 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3495 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3496 dir_static
.d_reclen
= sizeof (struct direct
)
3498 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3499 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3500 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3501 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3508 /* readdirver is just like readdir except it returns all versions of a file
3509 as separate entries. */
3514 register DIR *dirp
; /* stream from opendir */
3516 register struct dir$_name
*dp
; /* -> directory data */
3517 register struct dir$_version
*dv
; /* -> version data */
3519 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3520 dirp
->dd_loc
= dirp
->dd_size
= 0;
3522 if (dirp
->dd_size
== 0 /* refill buffer */
3523 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3526 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3527 if (dirp
->dd_loc
== 0)
3528 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3529 : dp
->dir$b_namecount
;
3530 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3531 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3532 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3533 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3534 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3535 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3536 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3537 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3543 #endif /* NONSYSTEM_DIR_LIBRARY */
3547 set_file_times (filename
, atime
, mtime
)
3549 EMACS_TIME atime
, mtime
;
3552 struct timeval tv
[2];
3555 return utimes (filename
, tv
);
3556 #else /* not HAVE_UTIMES */
3558 utb
.actime
= EMACS_SECS (atime
);
3559 utb
.modtime
= EMACS_SECS (mtime
);
3560 return utime (filename
, &utb
);
3561 #endif /* not HAVE_UTIMES */
3564 /* mkdir and rmdir functions, for systems which don't have them. */
3568 * Written by Robert Rother, Mariah Corporation, August 1985.
3570 * If you want it, it's yours. All I ask in return is that if you
3571 * figure out how to do this in a Bourne Shell script you send me
3573 * sdcsvax!rmr or rmr@uscd
3575 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3576 * subroutine. 11Mar86; hoptoad!gnu
3578 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3579 * subroutine didn't return EEXIST. It does now.
3585 #ifdef MKDIR_PROTOTYPE
3589 mkdir (dpath
, dmode
)
3594 int cpid
, status
, fd
;
3595 struct stat statbuf
;
3597 if (stat (dpath
, &statbuf
) == 0)
3599 errno
= EEXIST
; /* Stat worked, so it already exists */
3603 /* If stat fails for a reason other than non-existence, return error */
3604 if (errno
!= ENOENT
)
3607 synch_process_alive
= 1;
3608 switch (cpid
= fork ())
3611 case -1: /* Error in fork */
3612 return (-1); /* Errno is set already */
3614 case 0: /* Child process */
3616 * Cheap hack to set mode of new directory. Since this
3617 * child process is going away anyway, we zap its umask.
3618 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3619 * directory. Does anybody care?
3621 status
= umask (0); /* Get current umask */
3622 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3623 fd
= sys_open("/dev/null", 2);
3630 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3631 _exit (-1); /* Can't exec /bin/mkdir */
3633 default: /* Parent process */
3634 wait_for_termination (cpid
);
3637 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3639 errno
= EIO
; /* We don't know why, but */
3640 return -1; /* /bin/mkdir failed */
3645 #endif /* not HAVE_MKDIR */
3652 int cpid
, status
, fd
;
3653 struct stat statbuf
;
3655 if (stat (dpath
, &statbuf
) != 0)
3657 /* Stat just set errno. We don't have to */
3661 synch_process_alive
= 1;
3662 switch (cpid
= fork ())
3665 case -1: /* Error in fork */
3666 return (-1); /* Errno is set already */
3668 case 0: /* Child process */
3669 fd
= sys_open("/dev/null", 2);
3676 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3677 _exit (-1); /* Can't exec /bin/rmdir */
3679 default: /* Parent process */
3680 wait_for_termination (cpid
);
3683 if (synch_process_death
!= 0 || synch_process_retcode
!= 0)
3685 errno
= EIO
; /* We don't know why, but */
3686 return -1; /* /bin/rmdir failed */
3691 #endif /* !HAVE_RMDIR */
3695 /* Functions for VMS */
3697 #include "vms-pwd.h"
3702 /* Return as a string the VMS error string pertaining to STATUS.
3703 Reuses the same static buffer each time it is called. */
3707 int status
; /* VMS status code */
3711 static char buf
[257];
3713 bufadr
[0] = sizeof buf
- 1;
3714 bufadr
[1] = (int) buf
;
3715 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
3716 return "untranslatable VMS error status";
3724 /* The following is necessary because 'access' emulation by VMS C (2.0) does
3725 * not work correctly. (It also doesn't work well in version 2.3.)
3730 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
3731 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
3735 unsigned short s_buflen
;
3736 unsigned short s_code
;
3738 unsigned short *s_retlenadr
;
3742 #define buflen s.s_buflen
3743 #define code s.s_code
3744 #define bufadr s.s_bufadr
3745 #define retlenadr s.s_retlenadr
3747 #define R_OK 4 /* test for read permission */
3748 #define W_OK 2 /* test for write permission */
3749 #define X_OK 1 /* test for execute (search) permission */
3750 #define F_OK 0 /* test for presence of file */
3753 sys_access (path
, mode
)
3757 static char *user
= NULL
;
3760 /* translate possible directory spec into .DIR file name, so brain-dead
3761 * access can treat the directory like a file. */
3762 if (directory_file_name (path
, dir_fn
))
3766 return access (path
, mode
);
3767 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
3773 unsigned short int dummy
;
3775 static int constant
= ACL$C_FILE
;
3776 DESCRIPTOR (path_desc
, path
);
3777 DESCRIPTOR (user_desc
, user
);
3781 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
3784 acces
|= CHP$M_READ
;
3786 acces
|= CHP$M_WRITE
;
3787 itemlst
[0].buflen
= sizeof (int);
3788 itemlst
[0].code
= CHP$_FLAGS
;
3789 itemlst
[0].bufadr
= (char *) &flags
;
3790 itemlst
[0].retlenadr
= &dummy
;
3791 itemlst
[1].buflen
= sizeof (int);
3792 itemlst
[1].code
= CHP$_ACCESS
;
3793 itemlst
[1].bufadr
= (char *) &acces
;
3794 itemlst
[1].retlenadr
= &dummy
;
3795 itemlst
[2].end
= CHP$_END
;
3796 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
3797 return stat
== SS$_NORMAL
? 0 : -1;
3801 #else /* not VMS4_4 */
3804 #define ACE$M_WRITE 2
3805 #define ACE$C_KEYID 1
3807 static unsigned short memid
, grpid
;
3808 static unsigned int uic
;
3810 /* Called from init_sys_modes, so it happens not very often
3811 but at least each time Emacs is loaded. */
3812 sys_access_reinit ()
3818 sys_access (filename
, type
)
3824 int status
, size
, i
, typecode
, acl_controlled
;
3825 unsigned int *aclptr
, *aclend
, aclbuf
[60];
3826 union prvdef prvmask
;
3828 /* Get UIC and GRP values for protection checking. */
3831 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
3834 memid
= uic
& 0xFFFF;
3838 if (type
!= 2) /* not checking write access */
3839 return access (filename
, type
);
3841 /* Check write protection. */
3843 #define CHECKPRIV(bit) (prvmask.bit)
3844 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
3846 /* Find privilege bits */
3847 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
3849 error ("Unable to find privileges: %s", vmserrstr (status
));
3850 if (CHECKPRIV (PRV$V_BYPASS
))
3851 return 0; /* BYPASS enabled */
3853 fab
.fab$b_fac
= FAB$M_GET
;
3854 fab
.fab$l_fna
= filename
;
3855 fab
.fab$b_fns
= strlen (filename
);
3856 fab
.fab$l_xab
= &xab
;
3857 xab
= cc$rms_xabpro
;
3858 xab
.xab$l_aclbuf
= aclbuf
;
3859 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
3860 status
= SYS$
OPEN (&fab
, 0, 0);
3863 SYS$
CLOSE (&fab
, 0, 0);
3864 /* Check system access */
3865 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
3867 /* Check ACL entries, if any */
3869 if (xab
.xab$w_acllen
> 0)
3872 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
3873 while (*aclptr
&& aclptr
< aclend
)
3875 size
= (*aclptr
& 0xff) / 4;
3876 typecode
= (*aclptr
>> 8) & 0xff;
3877 if (typecode
== ACE$C_KEYID
)
3878 for (i
= size
- 1; i
> 1; i
--)
3879 if (aclptr
[i
] == uic
)
3882 if (aclptr
[1] & ACE$M_WRITE
)
3883 return 0; /* Write access through ACL */
3885 aclptr
= &aclptr
[size
];
3887 if (acl_controlled
) /* ACL specified, prohibits write access */
3890 /* No ACL entries specified, check normal protection */
3891 if (WRITABLE (XAB$V_WLD
)) /* World writable */
3893 if (WRITABLE (XAB$V_GRP
) &&
3894 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
3895 return 0; /* Group writable */
3896 if (WRITABLE (XAB$V_OWN
) &&
3897 (xab
.xab$l_uic
& 0xFFFF) == memid
)
3898 return 0; /* Owner writable */
3900 return -1; /* Not writable */
3902 #endif /* not VMS4_4 */
3905 static char vtbuf
[NAM$C_MAXRSS
+1];
3907 /* translate a vms file spec to a unix path */
3909 sys_translate_vms (vfile
)
3920 /* leading device or logical name is a root directory */
3921 if (p
= strchr (vfile
, ':'))
3930 if (*p
== '[' || *p
== '<')
3932 while (*++vfile
!= *p
+ 2)
3936 if (vfile
[-1] == *p
)
3959 static char utbuf
[NAM$C_MAXRSS
+1];
3961 /* translate a unix path to a VMS file spec */
3963 sys_translate_unix (ufile
)
3986 if (index (&ufile
[1], '/'))
3993 if (index (&ufile
[1], '/'))
4000 if (strncmp (ufile
, "./", 2) == 0)
4007 ufile
++; /* skip the dot */
4008 if (index (&ufile
[1], '/'))
4013 else if (strncmp (ufile
, "../", 3) == 0)
4021 ufile
+= 2; /* skip the dots */
4022 if (index (&ufile
[1], '/'))
4047 extern char *getcwd ();
4049 #define MAXPATHLEN 1024
4051 ptr
= xmalloc (MAXPATHLEN
);
4052 val
= getcwd (ptr
, MAXPATHLEN
);
4058 strcpy (pathname
, ptr
);
4066 long item_code
= JPI$_OWNER
;
4067 unsigned long parent_id
;
4070 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4073 vaxc$errno
= status
;
4083 return (getgid () << 16) | getuid ();
4087 sys_read (fildes
, buf
, nbyte
)
4092 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4097 sys_write (fildes
, buf
, nbyte
)
4102 register int nwrote
, rtnval
= 0;
4104 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4110 return rtnval
? rtnval
: -1;
4111 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4112 return rtnval
? rtnval
: -1;
4113 return (rtnval
+ nwrote
);
4118 * VAX/VMS VAX C RTL really loses. It insists that records
4119 * end with a newline (carriage return) character, and if they
4120 * don't it adds one (nice of it isn't it!)
4122 * Thus we do this stupidity below.
4126 sys_write (fildes
, buf
, nbytes
)
4129 unsigned int nbytes
;
4136 fstat (fildes
, &st
);
4142 /* Handle fixed-length files with carriage control. */
4143 if (st
.st_fab_rfm
== FAB$C_FIX
4144 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4146 len
= st
.st_fab_mrs
;
4147 retval
= write (fildes
, p
, min (len
, nbytes
));
4150 retval
++; /* This skips the implied carriage control */
4154 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4155 while (*e
!= '\n' && e
> p
) e
--;
4156 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4157 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4159 retval
= write (fildes
, p
, len
);
4170 /* Create file NEW copying its attributes from file OLD. If
4171 OLD is 0 or does not exist, create based on the value of
4174 /* Protection value the file should ultimately have.
4175 Set by create_copy_attrs, and use by rename_sansversions. */
4176 static unsigned short int fab_final_pro
;
4179 creat_copy_attrs (old
, new)
4182 struct FAB fab
= cc$rms_fab
;
4183 struct XABPRO xabpro
;
4184 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4185 extern int vms_stmlf_recfm
;
4189 fab
.fab$b_fac
= FAB$M_GET
;
4190 fab
.fab$l_fna
= old
;
4191 fab
.fab$b_fns
= strlen (old
);
4192 fab
.fab$l_xab
= (char *) &xabpro
;
4193 xabpro
= cc$rms_xabpro
;
4194 xabpro
.xab$l_aclbuf
= aclbuf
;
4195 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4196 /* Call $OPEN to fill in the fab & xabpro fields. */
4197 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4199 SYS$
CLOSE (&fab
, 0, 0);
4200 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4201 if (xabpro
.xab$w_acllen
> 0)
4203 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4204 /* If the acl buffer was too short, redo open with longer one.
4205 Wouldn't need to do this if there were some system imposed
4206 limit on the size of an ACL, but I can't find any such. */
4208 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4209 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4210 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4211 SYS$
CLOSE (&fab
, 0, 0);
4217 xabpro
.xab$l_aclbuf
= 0;
4222 fab
.fab$l_fna
= new;
4223 fab
.fab$b_fns
= strlen (new);
4227 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4228 fab
.fab$b_rat
= FAB$M_CR
;
4231 /* Set the file protections such that we will be able to manipulate
4232 this file. Once we are done writing and renaming it, we will set
4233 the protections back. */
4235 fab_final_pro
= xabpro
.xab$w_pro
;
4237 SYS$
SETDFPROT (0, &fab_final_pro
);
4238 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4240 /* Create the new file with either default attrs or attrs copied
4242 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4244 SYS$
CLOSE (&fab
, 0, 0);
4245 /* As this is a "replacement" for creat, return a file descriptor
4246 opened for writing. */
4247 return open (new, O_WRONLY
);
4252 #include <varargs.h>
4255 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4259 sys_creat (va_alist
)
4262 va_list list_incrementer
;
4265 int rfd
; /* related file descriptor */
4266 int fd
; /* Our new file descriptor */
4273 extern int vms_stmlf_recfm
;
4276 va_start (list_incrementer
);
4277 name
= va_arg (list_incrementer
, char *);
4278 mode
= va_arg (list_incrementer
, int);
4280 rfd
= va_arg (list_incrementer
, int);
4281 va_end (list_incrementer
);
4284 /* Use information from the related file descriptor to set record
4285 format of the newly created file. */
4286 fstat (rfd
, &st_buf
);
4287 switch (st_buf
.st_fab_rfm
)
4290 strcpy (rfm
, "rfm = fix");
4291 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4292 strcpy (rat
, "rat = ");
4293 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4295 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4296 strcat (rat
, "ftn");
4297 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4298 strcat (rat
, "prn");
4299 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4300 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4301 strcat (rat
, ", blk");
4303 strcat (rat
, "blk");
4304 return creat (name
, 0, rfm
, rat
, mrs
);
4307 strcpy (rfm
, "rfm = vfc");
4308 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4309 strcpy (rat
, "rat = ");
4310 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4312 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4313 strcat (rat
, "ftn");
4314 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4315 strcat (rat
, "prn");
4316 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4317 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4318 strcat (rat
, ", blk");
4320 strcat (rat
, "blk");
4321 return creat (name
, 0, rfm
, rat
, fsz
);
4324 strcpy (rfm
, "rfm = stm");
4328 strcpy (rfm
, "rfm = stmcr");
4332 strcpy (rfm
, "rfm = stmlf");
4336 strcpy (rfm
, "rfm = udf");
4340 strcpy (rfm
, "rfm = var");
4343 strcpy (rat
, "rat = ");
4344 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4346 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4347 strcat (rat
, "ftn");
4348 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4349 strcat (rat
, "prn");
4350 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4351 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4352 strcat (rat
, ", blk");
4354 strcat (rat
, "blk");
4358 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4359 strcpy (rat
, "rat=cr");
4361 /* Until the VAX C RTL fixes the many bugs with modes, always use
4362 mode 0 to get the user's default protection. */
4363 fd
= creat (name
, 0, rfm
, rat
);
4364 if (fd
< 0 && errno
== EEXIST
)
4366 if (unlink (name
) < 0)
4367 report_file_error ("delete", build_string (name
));
4368 fd
= creat (name
, 0, rfm
, rat
);
4374 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4375 sys_fwrite (ptr
, size
, num
, fp
)
4376 register char * ptr
;
4379 register int tot
= num
* size
;
4386 * The VMS C library routine creat actually creates a new version of an
4387 * existing file rather than truncating the old version. There are times
4388 * when this is not the desired behavior, for instance, when writing an
4389 * auto save file (you only want one version), or when you don't have
4390 * write permission in the directory containing the file (but the file
4391 * itself is writable). Hence this routine, which is equivalent to
4392 * "close (creat (fn, 0));" on Unix if fn already exists.
4398 struct FAB xfab
= cc$rms_fab
;
4399 struct RAB xrab
= cc$rms_rab
;
4402 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4403 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4404 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4405 xfab
.fab$l_fna
= fn
;
4406 xfab
.fab$b_fns
= strlen (fn
);
4407 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4409 xrab
.rab$l_fab
= &xfab
;
4411 /* This gibberish opens the file, positions to the first record, and
4412 deletes all records from there until the end of file. */
4413 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4415 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4416 (SYS$
FIND (&xrab
) & 01) == 01 &&
4417 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4428 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4429 SYSPRV or a readable SYSUAF.DAT. */
4435 * Routine to read the VMS User Authorization File and return
4436 * a specific user's record.
4439 static struct UAF retuaf
;
4442 get_uaf_name (uname
)
4449 uaf_fab
= cc$rms_fab
;
4450 uaf_rab
= cc$rms_rab
;
4451 /* initialize fab fields */
4452 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4453 uaf_fab
.fab$b_fns
= 21;
4454 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4455 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4456 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4457 /* initialize rab fields */
4458 uaf_rab
.rab$l_fab
= &uaf_fab
;
4459 /* open the User Authorization File */
4460 status
= SYS$
OPEN (&uaf_fab
);
4464 vaxc$errno
= status
;
4467 status
= SYS$
CONNECT (&uaf_rab
);
4471 vaxc$errno
= status
;
4474 /* read the requested record - index is in uname */
4475 uaf_rab
.rab$l_kbf
= uname
;
4476 uaf_rab
.rab$b_ksz
= strlen (uname
);
4477 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4478 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4479 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4480 status
= SYS$
GET (&uaf_rab
);
4484 vaxc$errno
= status
;
4487 /* close the User Authorization File */
4488 status
= SYS$
DISCONNECT (&uaf_rab
);
4492 vaxc$errno
= status
;
4495 status
= SYS$
CLOSE (&uaf_fab
);
4499 vaxc$errno
= status
;
4513 uaf_fab
= cc$rms_fab
;
4514 uaf_rab
= cc$rms_rab
;
4515 /* initialize fab fields */
4516 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4517 uaf_fab
.fab$b_fns
= 21;
4518 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4519 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4520 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4521 /* initialize rab fields */
4522 uaf_rab
.rab$l_fab
= &uaf_fab
;
4523 /* open the User Authorization File */
4524 status
= SYS$
OPEN (&uaf_fab
);
4528 vaxc$errno
= status
;
4531 status
= SYS$
CONNECT (&uaf_rab
);
4535 vaxc$errno
= status
;
4538 /* read the requested record - index is in uic */
4539 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4540 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4541 uaf_rab
.rab$b_ksz
= sizeof uic
;
4542 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4543 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4544 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4545 status
= SYS$
GET (&uaf_rab
);
4549 vaxc$errno
= status
;
4552 /* close the User Authorization File */
4553 status
= SYS$
DISCONNECT (&uaf_rab
);
4557 vaxc$errno
= status
;
4560 status
= SYS$
CLOSE (&uaf_fab
);
4564 vaxc$errno
= status
;
4570 static struct passwd retpw
;
4578 /* copy these out first because if the username is 32 chars, the next
4579 section will overwrite the first byte of the UIC */
4580 retpw
.pw_uid
= up
->uaf$w_mem
;
4581 retpw
.pw_gid
= up
->uaf$w_grp
;
4583 /* I suppose this is not the best style, to possibly overwrite one
4584 byte beyond the end of the field, but what the heck... */
4585 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4586 while (ptr
[-1] == ' ')
4589 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4591 /* the rest of these are counted ascii strings */
4592 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4593 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4594 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4595 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4596 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4597 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4598 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4599 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4603 #else /* not READ_SYSUAF */
4604 static struct passwd retpw
;
4605 #endif /* not READ_SYSUAF */
4616 unsigned char * full
;
4617 #endif /* READ_SYSUAF */
4622 if ('a' <= *ptr
&& *ptr
<= 'z')
4627 if (!(up
= get_uaf_name (name
)))
4629 return cnv_uaf_pw (up
);
4631 if (strcmp (name
, getenv ("USER")) == 0)
4633 retpw
.pw_uid
= getuid ();
4634 retpw
.pw_gid
= getgid ();
4635 strcpy (retpw
.pw_name
, name
);
4636 if (full
= egetenv ("FULLNAME"))
4637 strcpy (retpw
.pw_gecos
, full
);
4639 *retpw
.pw_gecos
= '\0';
4640 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4641 *retpw
.pw_shell
= '\0';
4646 #endif /* not READ_SYSUAF */
4656 if (!(up
= get_uaf_uic (uid
)))
4658 return cnv_uaf_pw (up
);
4660 if (uid
== sys_getuid ())
4661 return getpwnam (egetenv ("USER"));
4664 #endif /* not READ_SYSUAF */
4667 /* return total address space available to the current process. This is
4668 the sum of the current p0 size, p1 size and free page table entries
4673 unsigned long free_pages
;
4674 unsigned long frep0va
;
4675 unsigned long frep1va
;
4678 item_code
= JPI$_FREPTECNT
;
4679 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4682 vaxc$errno
= status
;
4687 item_code
= JPI$_FREP0VA
;
4688 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
4691 vaxc$errno
= status
;
4694 item_code
= JPI$_FREP1VA
;
4695 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
4698 vaxc$errno
= status
;
4702 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
4705 define_logical_name (varname
, string
)
4709 struct dsc$descriptor_s strdsc
=
4710 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
4711 struct dsc$descriptor_s envdsc
=
4712 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4713 struct dsc$descriptor_s lnmdsc
=
4714 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4716 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
4719 delete_logical_name (varname
)
4722 struct dsc$descriptor_s envdsc
=
4723 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
4724 struct dsc$descriptor_s lnmdsc
=
4725 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
4727 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
4738 error ("execvp system call not implemented");
4746 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
4747 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
4748 char from_esn
[NAM$C_MAXRSS
];
4749 char to_esn
[NAM$C_MAXRSS
];
4751 from_fab
.fab$l_fna
= from
;
4752 from_fab
.fab$b_fns
= strlen (from
);
4753 from_fab
.fab$l_nam
= &from_nam
;
4754 from_fab
.fab$l_fop
= FAB$M_NAM
;
4756 from_nam
.nam$l_esa
= from_esn
;
4757 from_nam
.nam$b_ess
= sizeof from_esn
;
4759 to_fab
.fab$l_fna
= to
;
4760 to_fab
.fab$b_fns
= strlen (to
);
4761 to_fab
.fab$l_nam
= &to_nam
;
4762 to_fab
.fab$l_fop
= FAB$M_NAM
;
4764 to_nam
.nam$l_esa
= to_esn
;
4765 to_nam
.nam$b_ess
= sizeof to_esn
;
4767 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
4773 if (status
== RMS$_DEV
)
4777 vaxc$errno
= status
;
4782 /* This function renames a file like `rename', but it strips
4783 the version number from the "to" filename, such that the "to" file is
4784 will always be a new version. It also sets the file protection once it is
4785 finished. The protection that we will use is stored in fab_final_pro,
4786 and was set when we did a creat_copy_attrs to create the file that we
4789 We could use the chmod function, but Eunichs uses 3 bits per user category
4790 to describe the protection, and VMS uses 4 (write and delete are separate
4791 bits). To maintain portability, the VMS implementation of `chmod' wires
4792 the W and D bits together. */
4795 static struct fibdef fib
; /* We need this initialized to zero */
4796 char vms_file_written
[NAM$C_MAXRSS
];
4799 rename_sans_version (from
,to
)
4806 struct FAB to_fab
= cc$rms_fab
;
4807 struct NAM to_nam
= cc$rms_nam
;
4808 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
4809 struct dsc$descriptor fib_attr
[2]
4810 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
4811 char to_esn
[NAM$C_MAXRSS
];
4813 $
DESCRIPTOR (disk
,to_esn
);
4815 to_fab
.fab$l_fna
= to
;
4816 to_fab
.fab$b_fns
= strlen (to
);
4817 to_fab
.fab$l_nam
= &to_nam
;
4818 to_fab
.fab$l_fop
= FAB$M_NAM
;
4820 to_nam
.nam$l_esa
= to_esn
;
4821 to_nam
.nam$b_ess
= sizeof to_esn
;
4823 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
4825 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
4826 *(to_nam
.nam$l_ver
) = '\0';
4828 stat
= rename (from
, to_esn
);
4832 strcpy (vms_file_written
, to_esn
);
4834 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
4835 to_fab
.fab$b_fns
= strlen (vms_file_written
);
4837 /* Now set the file protection to the correct value */
4838 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
4840 /* Copy these fields into the fib */
4841 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
4842 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
4843 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
4845 SYS$
CLOSE (&to_fab
, 0, 0);
4847 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
4850 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
4851 0, 0, 0, &fib_attr
, 0);
4854 stat
= SYS$
DASSGN (chan
);
4857 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
4867 unsigned short fid
[3];
4868 char esa
[NAM$C_MAXRSS
];
4871 fab
.fab$l_fop
= FAB$M_OFP
;
4872 fab
.fab$l_fna
= file
;
4873 fab
.fab$b_fns
= strlen (file
);
4874 fab
.fab$l_nam
= &nam
;
4877 nam
.nam$l_esa
= esa
;
4878 nam
.nam$b_ess
= NAM$C_MAXRSS
;
4880 status
= SYS$
PARSE (&fab
);
4881 if ((status
& 1) == 0)
4884 vaxc$errno
= status
;
4887 status
= SYS$
SEARCH (&fab
);
4888 if ((status
& 1) == 0)
4891 vaxc$errno
= status
;
4895 fid
[0] = nam
.nam$w_fid
[0];
4896 fid
[1] = nam
.nam$w_fid
[1];
4897 fid
[2] = nam
.nam$w_fid
[2];
4899 fab
.fab$l_fna
= new;
4900 fab
.fab$b_fns
= strlen (new);
4902 status
= SYS$
PARSE (&fab
);
4903 if ((status
& 1) == 0)
4906 vaxc$errno
= status
;
4910 nam
.nam$w_fid
[0] = fid
[0];
4911 nam
.nam$w_fid
[1] = fid
[1];
4912 nam
.nam$w_fid
[2] = fid
[2];
4914 nam
.nam$l_esa
= nam
.nam$l_name
;
4915 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
4917 status
= SYS$
ENTER (&fab
);
4918 if ((status
& 1) == 0)
4921 vaxc$errno
= status
;
4931 printf ("%s not yet implemented\r\n", badfunc
);
4939 /* Arrange to return a range centered on zero. */
4940 return rand () - (1 << 30);
4951 /* Called from init_sys_modes. */
4956 /* If we're not on an HFT we shouldn't do any of this. We determine
4957 if we are on an HFT by trying to get an HFT error code. If this
4958 call fails, we're not on an HFT. */
4960 if (ioctl (0, HFQERROR
, &junk
) < 0)
4962 #else /* not IBMR2AIX */
4963 if (ioctl (0, HFQEIO
, 0) < 0)
4965 #endif /* not IBMR2AIX */
4967 /* On AIX the default hft keyboard mapping uses backspace rather than delete
4968 as the rubout key's ASCII code. Here this is changed. The bug is that
4969 there's no way to determine the old mapping, so in reset_sys_modes
4970 we need to assume that the normal map had been present. Of course, this
4971 code also doesn't help if on a terminal emulator which doesn't understand
4975 struct hfkeymap keymap
;
4977 buf
.hf_bufp
= (char *)&keymap
;
4978 buf
.hf_buflen
= sizeof (keymap
);
4979 keymap
.hf_nkeys
= 2;
4980 keymap
.hfkey
[0].hf_kpos
= 15;
4981 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
4983 keymap
.hfkey
[0].hf_keyidh
= '<';
4984 #else /* not IBMR2AIX */
4985 keymap
.hfkey
[0].hf_page
= '<';
4986 #endif /* not IBMR2AIX */
4987 keymap
.hfkey
[0].hf_char
= 127;
4988 keymap
.hfkey
[1].hf_kpos
= 15;
4989 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
4991 keymap
.hfkey
[1].hf_keyidh
= '<';
4992 #else /* not IBMR2AIX */
4993 keymap
.hfkey
[1].hf_page
= '<';
4994 #endif /* not IBMR2AIX */
4995 keymap
.hfkey
[1].hf_char
= 127;
4996 hftctl (0, HFSKBD
, &buf
);
4998 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
5000 line_ins_del_ok
= char_ins_del_ok
= 0;
5003 /* Reset the rubout key to backspace. */
5008 struct hfkeymap keymap
;
5012 if (ioctl (0, HFQERROR
, &junk
) < 0)
5014 #else /* not IBMR2AIX */
5015 if (ioctl (0, HFQEIO
, 0) < 0)
5017 #endif /* not IBMR2AIX */
5019 buf
.hf_bufp
= (char *)&keymap
;
5020 buf
.hf_buflen
= sizeof (keymap
);
5021 keymap
.hf_nkeys
= 2;
5022 keymap
.hfkey
[0].hf_kpos
= 15;
5023 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5025 keymap
.hfkey
[0].hf_keyidh
= '<';
5026 #else /* not IBMR2AIX */
5027 keymap
.hfkey
[0].hf_page
= '<';
5028 #endif /* not IBMR2AIX */
5029 keymap
.hfkey
[0].hf_char
= 8;
5030 keymap
.hfkey
[1].hf_kpos
= 15;
5031 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5033 keymap
.hfkey
[1].hf_keyidh
= '<';
5034 #else /* not IBMR2AIX */
5035 keymap
.hfkey
[1].hf_page
= '<';
5036 #endif /* not IBMR2AIX */
5037 keymap
.hfkey
[1].hf_char
= 8;
5038 hftctl (0, HFSKBD
, &buf
);
5045 /* These are included on Sunos 4.1 when we do not use shared libraries.
5046 X11 libraries may refer to these functions but (we hope) do not
5047 actually call them. */
5067 #endif /* USE_DL_STUBS */
5076 register int length
;
5080 long max_str
= 65535;
5082 while (length
> max_str
) {
5083 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5088 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5090 while (length
-- > 0)
5092 #endif /* not VMS */
5095 #endif /* no bzero */
5096 #endif /* BSTRING */
5098 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5101 /* Saying `void' requires a declaration, above, where bcopy is used
5102 and that declaration causes pain for systems where bcopy is a macro. */
5103 bcopy (b1
, b2
, length
)
5106 register int length
;
5109 long max_str
= 65535;
5111 while (length
> max_str
) {
5112 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5118 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5120 while (length
-- > 0)
5122 #endif /* not VMS */
5124 #endif /* (defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5129 bcmp (b1
, b2
, length
) /* This could be a macro! */
5132 register int length
;
5135 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5136 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5138 return STR$
COMPARE (&src1
, &src2
);
5140 while (length
-- > 0)
5145 #endif /* not VMS */
5147 #endif /* no bcmp */
5148 #endif /* not BSTRING */