1 /* Interfaces to system-dependent kernel and library entries.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
33 /* Including stdlib.h isn't necessarily enough to get srandom
34 declared, e.g. without __USE_XOPEN_EXTENDED with glibc 2. */
36 #if 0 /* It turns out that defining _OSF_SOURCE in osf5-0.h gets
37 random prototyped as returning `int'. It looks to me as
38 though the best way to DTRT is to prefer the rand48 functions
39 (per libc.info). -- fx */
40 extern long int random
P_ ((void));
42 #if 0 /* Don't prototype srandom; it takes an unsigned argument on
43 some systems, and an unsigned long on others, like FreeBSD
45 extern void srandom
P_ ((unsigned int));
49 /* The w32 build defines select stuff in w32.h, which is included by
50 sys/select.h (included below). */
52 #include "sysselect.h"
55 #include "blockinput.h"
58 #include <sys/param.h>
61 /* Nonzero means delete a process right away if it exits (process.c). */
62 static int delete_exited_processes
;
68 #define write sys_write
73 #endif /* not WINDOWSNT */
75 /* Does anyone other than VMS need this? */
77 #define sys_fwrite fwrite
82 #include <sys/types.h>
87 #if !defined (USG) || defined (BSD_PGRPS)
89 #define setpgrp setpgid
93 /* Get SI_SRPC_DOMAIN, if it is available. */
94 #ifdef HAVE_SYS_SYSTEMINFO_H
95 #include <sys/systeminfo.h>
98 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
102 #include <sys/param.h>
106 extern unsigned start
__asm__ ("start");
128 #include <sys/file.h>
136 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
140 #include <sys/file.h>
148 #include <sys/ioctl.h>
154 #ifdef BROKEN_TIOCGWINSZ
159 #if defined (USG) || defined (DGUX)
160 #include <sys/utsname.h>
161 #ifndef MEMORY_IN_STRING_H
164 #if defined (TIOCGWINSZ) || defined (ISC4_0)
166 #include <sys/sioctl.h>
169 #include <sys/stream.h>
170 #include <sys/ptem.h>
172 #endif /* TIOCGWINSZ or ISC4_0 */
173 #endif /* USG or DGUX */
175 extern int quit_char
;
177 #include "keyboard.h"
180 #include "termhooks.h"
181 #include "termchar.h"
182 #include "termopts.h"
183 #include "dispextern.h"
185 #include "cm.h" /* for reset_sys_modes */
189 /* In process.h which conflicts with the local copy. */
191 int _CRTAPI1
_spawnlp (int, const char *, const char *, ...);
192 int _CRTAPI1
_getpid (void);
193 extern char *getwd (char *);
196 #ifdef NONSYSTEM_DIR_LIBRARY
198 #endif /* NONSYSTEM_DIR_LIBRARY */
200 #include "syssignal.h"
207 #ifndef HAVE_STRUCT_UTIMBUF
208 /* We want to use utime rather than utimes, but we couldn't find the
209 structure declaration. We'll use the traditional one. */
217 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
223 #define LNOFLSH 0100000
226 static int baud_convert
[] =
231 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
232 1800, 2400, 4800, 9600, 19200, 38400
239 #if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
241 #if defined (HAVE_TERMIOS_H) && defined (GNU_LINUX)
249 void croak
P_ ((char *)) NO_RETURN
;
252 void hft_init
P_ ((struct tty_display_info
*));
253 void hft_reset
P_ ((struct tty_display_info
*));
256 /* Temporary used by `sigblock' when defined in terms of signprocmask. */
258 SIGMASKTYPE sigprocmask_set
;
261 #if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
263 /* Return the current working directory. Returns NULL on errors.
264 Any other returned value must be freed with free. This is used
265 only when get_current_dir_name is not defined on the system. */
267 get_current_dir_name ()
271 struct stat dotstat
, pwdstat
;
272 /* If PWD is accurate, use it instead of calling getwd. PWD is
273 sometimes a nicer name, and using it may avoid a fatal error if a
274 parent directory is searchable but not readable. */
275 if ((pwd
= getenv ("PWD")) != 0
276 && (IS_DIRECTORY_SEP (*pwd
) || (*pwd
&& IS_DEVICE_SEP (pwd
[1])))
277 && stat (pwd
, &pwdstat
) == 0
278 && stat (".", &dotstat
) == 0
279 && dotstat
.st_ino
== pwdstat
.st_ino
280 && dotstat
.st_dev
== pwdstat
.st_dev
282 && strlen (pwd
) < MAXPATHLEN
286 buf
= (char *) malloc (strlen (pwd
) + 1);
294 size_t buf_size
= 1024;
295 buf
= (char *) malloc (buf_size
);
300 if (getcwd (buf
, buf_size
) == buf
)
304 int tmp_errno
= errno
;
310 buf
= (char *) realloc (buf
, buf_size
);
318 /* We need MAXPATHLEN here. */
319 buf
= (char *) malloc (MAXPATHLEN
+ 1);
322 if (getwd (buf
) == NULL
)
324 int tmp_errno
= errno
;
336 /* Discard pending input on all input descriptors. */
342 struct emacs_tty buf
;
349 SYS$
QIOW (0, fileno (CURTTY()->input
), IO$_READVBLK
|IO$M_PURGE
, input_iosb
, 0, 0,
350 &buf
.main
, 0, 0, terminator_mask
, 0, 0);
355 struct tty_display_info
*tty
;
356 for (tty
= tty_list
; tty
; tty
= tty
->next
)
360 ioctl (fileno (tty
->input
), TIOCFLUSH
, &zero
);
363 #else /* not Apollo */
364 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
365 while (dos_keyread () != -1)
367 #else /* not MSDOS */
369 struct tty_display_info
*tty
;
370 for (tty
= tty_list
; tty
; tty
= tty
->next
)
372 if (tty
->input
) /* Is the device suspended? */
374 EMACS_GET_TTY (fileno (tty
->input
), &buf
);
375 EMACS_SET_TTY (fileno (tty
->input
), &buf
, 0);
379 #endif /* not MSDOS */
380 #endif /* not Apollo */
382 #endif /* not WINDOWSNT */
388 /* Arrange for character C to be read as the next input from
390 XXX What if we have multiple ttys?
396 if (! FRAME_TERMCAP_P (SELECTED_FRAME ()))
399 /* Should perhaps error if in batch mode */
401 ioctl (fileno (CURTTY()->input
), TIOCSTI
, &c
);
402 #else /* no TIOCSTI */
403 error ("Cannot stuff terminal input characters in this version of Unix");
404 #endif /* no TIOCSTI */
410 init_baud_rate (int fd
)
416 #ifdef INIT_BAUD_RATE
421 #else /* not DOS_NT */
425 SYS$
QIOW (0, fd
, IO$_SENSEMODE
, &sg
, 0, 0,
426 &sg
.class, 12, 0, 0, 0, 0 );
427 emacs_ospeed
= sg
.xmit_baud
;
434 emacs_ospeed
= cfgetospeed (&sg
);
435 #if defined (USE_GETOBAUD) && defined (getobaud)
436 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
437 if (emacs_ospeed
== 0)
438 emacs_ospeed
= getobaud (sg
.c_cflag
);
440 #else /* neither VMS nor TERMIOS */
448 ioctl (fd
, TCGETA
, &sg
);
450 emacs_ospeed
= sg
.c_cflag
& CBAUD
;
451 #else /* neither VMS nor TERMIOS nor TERMIO */
454 sg
.sg_ospeed
= B9600
;
455 if (ioctl (fd
, TIOCGETP
, &sg
) < 0)
457 emacs_ospeed
= sg
.sg_ospeed
;
458 #endif /* not HAVE_TERMIO */
459 #endif /* not HAVE_TERMIOS */
461 #endif /* not DOS_NT */
462 #endif /* not INIT_BAUD_RATE */
465 baud_rate
= (emacs_ospeed
< sizeof baud_convert
/ sizeof baud_convert
[0]
466 ? baud_convert
[emacs_ospeed
] : 9600);
474 set_exclusive_use (fd
)
478 ioctl (fd
, FIOCLEX
, 0);
480 /* Ok to do nothing if this feature does not exist */
485 wait_without_blocking ()
488 wait3 (0, WNOHANG
| WUNTRACED
, 0);
490 croak ("wait_without_blocking");
492 synch_process_alive
= 0;
495 #endif /* not subprocesses */
497 int wait_debugging
; /* Set nonzero to make following function work under dbx
498 (at least for bsd). */
501 wait_for_termination_signal ()
504 /* Wait for subprocess with process id `pid' to terminate and
505 make sure it will get eliminated (not remain forever as a zombie) */
508 wait_for_termination (pid
)
517 status
= SYS$
FORCEX (&pid
, 0, 0);
520 #if defined (BSD_SYSTEM) || (defined (HPUX) && !defined (HPUX_5))
521 /* Note that kill returns -1 even if the process is just a zombie now.
522 But inevitably a SIGCHLD interrupt should be generated
523 and child_sig will do wait3 and make the process go away. */
524 /* There is some indication that there is a bug involved with
525 termination of subprocesses, perhaps involving a kernel bug too,
526 but no idea what it is. Just as a hunch we signal SIGCHLD to see
527 if that causes the problem to go away or get worse. */
528 sigsetmask (sigmask (SIGCHLD
));
529 if (0 > kill (pid
, 0))
531 sigsetmask (SIGEMPTYMASK
);
532 kill (getpid (), SIGCHLD
);
538 sigpause (SIGEMPTYMASK
);
539 #else /* not BSD_SYSTEM, and not HPUX version >= 6 */
540 #if defined (UNIPLUS)
541 if (0 > kill (pid
, 0))
544 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
545 #ifdef POSIX_SIGNALS /* would this work for GNU/Linux as well? */
546 sigblock (sigmask (SIGCHLD
));
548 if (kill (pid
, 0) == -1 && errno
== ESRCH
)
550 sigunblock (sigmask (SIGCHLD
));
554 sigsuspend (&empty_mask
);
555 #else /* not POSIX_SIGNALS */
556 #ifdef HAVE_SYSV_SIGPAUSE
558 if (0 > kill (pid
, 0))
564 #else /* not HAVE_SYSV_SIGPAUSE */
568 #else /* not WINDOWSNT */
569 if (0 > kill (pid
, 0))
571 /* Using sleep instead of pause avoids timing error.
572 If the inferior dies just before the sleep,
573 we lose just one second. */
575 #endif /* not WINDOWSNT */
576 #endif /* not HAVE_SYSV_SIGPAUSE */
577 #endif /* not POSIX_SIGNALS */
578 #endif /* not UNIPLUS */
579 #endif /* not BSD_SYSTEM, and not HPUX version >= 6 */
581 #else /* not subprocesses */
584 #else /* not __DJGPP__ > 1 */
586 if (kill (pid
, 0) < 0)
592 if (status
== pid
|| status
== -1)
595 #endif /* not __DJGPP__ > 1*/
596 #endif /* not subprocesses */
603 * flush any pending output
604 * (may flush input as well; it does not matter the way we use it)
608 flush_pending_output (channel
)
612 /* If we try this, we get hit with SIGTTIN, because
613 the child's tty belongs to the child's pgrp. */
616 ioctl (channel
, TCFLSH
, 1);
620 /* 3rd arg should be ignored
621 but some 4.2 kernels actually want the address of an int
622 and nonzero means something different. */
623 ioctl (channel
, TIOCFLUSH
, &zero
);
630 /* Set up the terminal at the other end of a pseudo-terminal that
631 we will be controlling an inferior through.
632 It should not echo or do line-editing, since that is done
633 in Emacs. No padding needed for insertion into an Emacs buffer. */
636 child_setup_tty (out
)
642 EMACS_GET_TTY (out
, &s
);
644 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
645 s
.main
.c_oflag
|= OPOST
; /* Enable output postprocessing */
646 s
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL on output */
648 s
.main
.c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
649 /* No output delays */
651 s
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
652 s
.main
.c_lflag
|= ISIG
; /* Enable signals */
653 #if 0 /* This causes bugs in (for instance) telnet to certain sites. */
654 s
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
655 #ifdef INLCR /* Just being cautious, since I can't check how
656 widespread INLCR is--rms. */
657 s
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
661 s
.main
.c_iflag
&= ~IUCLC
; /* Disable downcasing on input. */
664 s
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
667 s
.main
.c_oflag
&= ~OLCUC
; /* Disable upcasing on output. */
669 s
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
670 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CSIZE
) | CS8
; /* Don't strip 8th bit */
672 /* Said to be unnecessary: */
673 s
.main
.c_cc
[VMIN
] = 1; /* minimum number of characters to accept */
674 s
.main
.c_cc
[VTIME
] = 0; /* wait forever for at least 1 character */
677 s
.main
.c_lflag
|= ICANON
; /* Enable erase/kill and eof processing */
678 s
.main
.c_cc
[VEOF
] = 04; /* insure that EOF is Control-D */
679 s
.main
.c_cc
[VERASE
] = CDISABLE
; /* disable erase processing */
680 s
.main
.c_cc
[VKILL
] = CDISABLE
; /* disable kill processing */
683 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
686 #ifdef SIGNALS_VIA_CHARACTERS
687 /* the QUIT and INTR character are used in process_send_signal
688 so set them here to something useful. */
689 if (s
.main
.c_cc
[VQUIT
] == CDISABLE
)
690 s
.main
.c_cc
[VQUIT
] = '\\'&037; /* Control-\ */
691 if (s
.main
.c_cc
[VINTR
] == CDISABLE
)
692 s
.main
.c_cc
[VINTR
] = 'C'&037; /* Control-C */
693 #endif /* not SIGNALS_VIA_CHARACTERS */
696 /* AIX enhanced edit loses NULs, so disable it */
699 s
.main
.c_iflag
&= ~ASCEDIT
;
701 /* Also, PTY overloads NUL and BREAK.
702 don't ignore break, but don't signal either, so it looks like NUL. */
703 s
.main
.c_iflag
&= ~IGNBRK
;
704 s
.main
.c_iflag
&= ~BRKINT
;
705 /* rms: Formerly it set s.main.c_cc[VINTR] to 0377 here
706 unconditionally. Then a SIGNALS_VIA_CHARACTERS conditional
707 would force it to 0377. That looks like duplicated code. */
708 #ifndef SIGNALS_VIA_CHARACTERS
709 /* QUIT and INTR work better as signals, so disable character forms */
710 s
.main
.c_cc
[VQUIT
] = CDISABLE
;
711 s
.main
.c_cc
[VINTR
] = CDISABLE
;
712 s
.main
.c_lflag
&= ~ISIG
;
713 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
714 s
.main
.c_cc
[VEOL
] = CDISABLE
;
715 s
.main
.c_cflag
= (s
.main
.c_cflag
& ~CBAUD
) | B9600
; /* baud rate sanity */
718 #else /* not HAVE_TERMIO */
720 s
.main
.sg_flags
&= ~(ECHO
| CRMOD
| ANYP
| ALLDELAY
| RAW
| LCASE
722 s
.main
.sg_flags
|= LPASS8
;
723 s
.main
.sg_erase
= 0377;
724 s
.main
.sg_kill
= 0377;
725 s
.lmode
= LLITOUT
| s
.lmode
; /* Don't strip 8th bit */
727 #endif /* not HAVE_TERMIO */
729 EMACS_SET_TTY (out
, &s
, 0);
738 ioctl (out
, FIOASYNC
, &zero
);
741 #endif /* not DOS_NT */
745 #endif /* subprocesses */
747 /* Record a signal code and the handler for it. */
751 SIGTYPE (*handler
) P_ ((int));
754 static void save_signal_handlers
P_ ((struct save_signal
*));
755 static void restore_signal_handlers
P_ ((struct save_signal
*));
757 /* Suspend the Emacs process; give terminal to its superior. */
763 /* "Foster" parentage allows emacs to return to a subprocess that attached
764 to the current emacs as a cheaper than starting a whole new process. This
765 is set up by KEPTEDITOR.COM. */
766 unsigned long parent_id
, foster_parent_id
;
769 fpid_string
= getenv ("EMACS_PARENT_PID");
770 if (fpid_string
!= NULL
)
772 sscanf (fpid_string
, "%x", &foster_parent_id
);
773 if (foster_parent_id
!= 0)
774 parent_id
= foster_parent_id
;
776 parent_id
= getppid ();
779 parent_id
= getppid ();
781 xfree (fpid_string
); /* On VMS, this was malloc'd */
783 if (parent_id
&& parent_id
!= 0xffffffff)
785 SIGTYPE (*oldsig
)() = (int) signal (SIGINT
, SIG_IGN
);
786 int status
= LIB$
ATTACH (&parent_id
) & 1;
787 signal (SIGINT
, oldsig
);
796 d_prompt
.l
= sizeof ("Emacs: "); /* Our special prompt */
797 d_prompt
.a
= "Emacs: "; /* Just a reminder */
798 LIB$
SPAWN (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &d_prompt
, 0);
803 #if defined (SIGTSTP) && !defined (MSDOS)
806 int pgrp
= EMACS_GETPGRP (0);
807 EMACS_KILLPG (pgrp
, SIGTSTP
);
810 #else /* No SIGTSTP */
811 #ifdef USG_JOBCTRL /* If you don't know what this is don't mess with it */
812 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
813 kill (getpid (), SIGQUIT
);
815 #else /* No SIGTSTP or USG_JOBCTRL */
817 /* On a system where suspending is not implemented,
818 instead fork a subshell and let it talk directly to the terminal
822 #endif /* no USG_JOBCTRL */
823 #endif /* no SIGTSTP */
827 /* Fork a subshell. */
834 #ifdef DOS_NT /* Demacs 1.1.2 91/10/20 Manabu Higashida */
836 char oldwd
[MAXPATHLEN
+1]; /* Fixed length is safe on MSDOS. */
839 struct save_signal saved_handlers
[5];
841 unsigned char *str
= 0;
844 saved_handlers
[0].code
= SIGINT
;
845 saved_handlers
[1].code
= SIGQUIT
;
846 saved_handlers
[2].code
= SIGTERM
;
848 saved_handlers
[3].code
= SIGIO
;
849 saved_handlers
[4].code
= 0;
851 saved_handlers
[3].code
= 0;
854 /* Mentioning current_buffer->buffer would mean including buffer.h,
855 which somehow wedges the hp compiler. So instead... */
857 dir
= intern ("default-directory");
858 if (NILP (Fboundp (dir
)))
860 dir
= Fsymbol_value (dir
);
864 dir
= expand_and_dir_to_file (Funhandled_file_name_directory (dir
), Qnil
);
865 str
= (unsigned char *) alloca (SCHARS (dir
) + 2);
867 bcopy (SDATA (dir
), str
, len
);
868 if (str
[len
- 1] != '/') str
[len
++] = '/';
875 save_signal_handlers (saved_handlers
);
876 synch_process_alive
= 1;
877 #endif /* __DJGPP__ > 1 */
881 error ("Can't spawn subshell");
888 #ifdef DOS_NT /* MW, Aug 1993 */
891 sh
= (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */
894 sh
= (char *) egetenv ("SHELL");
898 /* Use our buffer's default directory for the subshell. */
900 chdir ((char *) str
);
903 close_process_descs (); /* Close Emacs's pipes/ptys */
906 #ifdef SET_EMACS_PRIORITY
908 extern EMACS_INT emacs_priority
;
910 if (emacs_priority
< 0)
911 nice (-emacs_priority
);
915 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
917 char *epwd
= getenv ("PWD");
918 char old_pwd
[MAXPATHLEN
+1+4];
920 /* If PWD is set, pass it with corrected value. */
923 strcpy (old_pwd
, epwd
);
924 if (str
[len
- 1] == '/')
926 setenv ("PWD", str
, 1);
931 putenv (old_pwd
); /* restore previous value */
933 #if 0 /* This is also reported if last command executed in subshell failed, KFS */
935 report_file_error ("Can't execute subshell", Fcons (build_string (sh
), Qnil
));
937 #else /* not MSDOS */
939 /* Waits for process completion */
940 pid
= _spawnlp (_P_WAIT
, sh
, sh
, NULL
);
943 write (1, "Can't execute subshell", 22);
944 #else /* not WINDOWSNT */
945 execlp (sh
, sh
, (char *) 0);
946 write (1, "Can't execute subshell", 22);
948 #endif /* not WINDOWSNT */
949 #endif /* not MSDOS */
952 /* Do this now if we did not do it before. */
953 #if !defined (MSDOS) || __DJGPP__ == 1
954 save_signal_handlers (saved_handlers
);
955 synch_process_alive
= 1;
959 wait_for_termination (pid
);
961 restore_signal_handlers (saved_handlers
);
962 synch_process_alive
= 0;
965 #endif /* !MAC_OS8 */
968 save_signal_handlers (saved_handlers
)
969 struct save_signal
*saved_handlers
;
971 while (saved_handlers
->code
)
973 saved_handlers
->handler
974 = (SIGTYPE (*) P_ ((int))) signal (saved_handlers
->code
, SIG_IGN
);
980 restore_signal_handlers (saved_handlers
)
981 struct save_signal
*saved_handlers
;
983 while (saved_handlers
->code
)
985 signal (saved_handlers
->code
, saved_handlers
->handler
);
991 /* If SIGIO is broken, don't do anything. */
1003 request_sigio (void)
1008 unrequest_sigio (void)
1015 int old_fcntl_flags
[MAXDESC
];
1022 old_fcntl_flags
[fd
] = fcntl (fd
, F_GETFL
, 0) & ~FASYNC
;
1023 fcntl (fd
, F_SETFL
, old_fcntl_flags
[fd
] | FASYNC
);
1025 interrupts_deferred
= 0;
1033 fcntl (fd
, F_SETFL
, old_fcntl_flags
[fd
]);
1037 #ifdef FASYNC /* F_SETFL does not imply existence of FASYNC */
1038 /* XXX Uhm, FASYNC is not used anymore here. */
1039 /* XXX Yeah, but you need it for SIGIO, don't you? */
1048 sigunblock (sigmask (SIGWINCH
));
1050 sigunblock (sigmask (SIGIO
));
1052 interrupts_deferred
= 0;
1056 unrequest_sigio (void)
1061 #if 0 /* XXX What's wrong with blocking SIGIO under X? */
1067 sigblock (sigmask (SIGWINCH
));
1069 sigblock (sigmask (SIGIO
));
1070 interrupts_deferred
= 1;
1073 #else /* no FASYNC */
1074 #ifdef STRIDE /* Stride doesn't have FASYNC - use FIOASYNC */
1081 if (noninteractive
|| read_socket_hook
)
1084 /* XXX CURTTY() is bogus here. */
1085 ioctl (fileno (CURTTY ()->input
), FIOASYNC
, &on
);
1086 interrupts_deferred
= 0;
1094 if (noninteractive
|| read_socket_hook
)
1097 /* XXX CURTTY() is bogus here. */
1098 ioctl (fileno (CURTTY ()->input
), FIOASYNC
, &off
);
1099 interrupts_deferred
= 1;
1102 #else /* not FASYNC, not STRIDE */
1106 #include <termios.h>
1114 if (noninteractive
|| read_socket_hook
)
1118 sigaddset (&st
, SIGIO
);
1119 ioctl (0, FIOASYNC
, &on
); /* XXX This fails for multiple ttys. */
1120 interrupts_deferred
= 0;
1121 sigprocmask (SIG_UNBLOCK
, &st
, (sigset_t
*)0);
1129 if (noninteractive
|| read_socket_hook
)
1132 ioctl (0, FIOASYNC
, &off
); /* XXX This fails for multiple ttys. */
1133 interrupts_deferred
= 1;
1136 #else /* ! _CX_UX */
1142 if (noninteractive
|| read_socket_hook
)
1145 croak ("request_sigio");
1151 if (noninteractive
|| read_socket_hook
)
1154 croak ("unrequest_sigio");
1161 #endif /* F_SETFL */
1164 /* Saving and restoring the process group of Emacs's terminal. */
1168 /* The process group of which Emacs was a member when it initially
1171 If Emacs was in its own process group (i.e. inherited_pgroup ==
1172 getpid ()), then we know we're running under a shell with job
1173 control (Emacs would never be run as part of a pipeline).
1176 If Emacs was not in its own process group, then we know we're
1177 running under a shell (or a caller) that doesn't know how to
1178 separate itself from Emacs (like sh). Emacs must be in its own
1179 process group in order to receive SIGIO correctly. In this
1180 situation, we put ourselves in our own pgroup, forcibly set the
1181 tty's pgroup to our pgroup, and make sure to restore and reinstate
1182 the tty's pgroup just like any other terminal setting. If
1183 inherited_group was not the tty's pgroup, then we'll get a
1184 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
1185 it goes foreground in the future, which is what should happen.
1187 This variable is initialized in emacs.c. */
1188 int inherited_pgroup
;
1190 /* Split off the foreground process group to Emacs alone. When we are
1191 in the foreground, but not started in our own process group,
1192 redirect the tty device handle FD to point to our own process
1193 group. We need to be in our own process group to receive SIGIO
1196 narrow_foreground_group (int fd
)
1200 setpgrp (0, inherited_pgroup
);
1202 /* XXX inherited_pgroup should not be zero here, but GTK seems to
1204 if (! inherited_pgroup
)
1205 abort (); /* Should not happen. */
1207 if (inherited_pgroup
!= me
)
1208 EMACS_SET_TTY_PGRP (fd
, &me
); /* XXX This only works on the controlling tty. */
1212 /* Set the tty to our original foreground group. */
1214 widen_foreground_group (int fd
)
1216 if (inherited_pgroup
!= getpid ())
1217 EMACS_SET_TTY_PGRP (fd
, &inherited_pgroup
);
1218 setpgrp (0, inherited_pgroup
);
1221 #endif /* BSD_PGRPS */
1223 /* Getting and setting emacs_tty structures. */
1225 /* Set *TC to the parameters associated with the terminal FD.
1226 Return zero if all's well, or -1 if we ran into an error we
1227 couldn't deal with. */
1229 emacs_get_tty (fd
, settings
)
1231 struct emacs_tty
*settings
;
1233 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
1235 /* We have those nifty POSIX tcmumbleattr functions. */
1236 bzero (&settings
->main
, sizeof (settings
->main
));
1237 if (tcgetattr (fd
, &settings
->main
) < 0)
1242 /* The SYSV-style interface? */
1243 if (ioctl (fd
, TCGETA
, &settings
->main
) < 0)
1248 /* Vehemently Monstrous System? :-) */
1249 if (! (SYS$
QIOW (0, fd
, IO$_SENSEMODE
, settings
, 0, 0,
1250 &settings
->main
.class, 12, 0, 0, 0, 0)
1256 /* I give up - I hope you have the BSD ioctls. */
1257 if (ioctl (fd
, TIOCGETP
, &settings
->main
) < 0)
1259 #endif /* not DOS_NT */
1264 /* Suivant - Do we have to get struct ltchars data? */
1266 if (ioctl (fd
, TIOCGLTC
, &settings
->ltchars
) < 0)
1270 /* How about a struct tchars and a wordful of lmode bits? */
1272 if (ioctl (fd
, TIOCGETC
, &settings
->tchars
) < 0
1273 || ioctl (fd
, TIOCLGET
, &settings
->lmode
) < 0)
1277 /* We have survived the tempest. */
1282 /* Set the parameters of the tty on FD according to the contents of
1283 *SETTINGS. If FLUSHP is non-zero, we discard input.
1284 Return 0 if all went well, and -1 if anything failed. */
1287 emacs_set_tty (fd
, settings
, flushp
)
1289 struct emacs_tty
*settings
;
1292 /* Set the primary parameters - baud rate, character size, etcetera. */
1295 /* We have those nifty POSIX tcmumbleattr functions.
1296 William J. Smith <wjs@wiis.wang.com> writes:
1297 "POSIX 1003.1 defines tcsetattr to return success if it was
1298 able to perform any of the requested actions, even if some
1299 of the requested actions could not be performed.
1300 We must read settings back to ensure tty setup properly.
1301 AIX requires this to keep tty from hanging occasionally." */
1302 /* This make sure that we don't loop indefinitely in here. */
1303 for (i
= 0 ; i
< 10 ; i
++)
1304 if (tcsetattr (fd
, flushp
? TCSAFLUSH
: TCSADRAIN
, &settings
->main
) < 0)
1315 bzero (&new, sizeof (new));
1316 /* Get the current settings, and see if they're what we asked for. */
1317 tcgetattr (fd
, &new);
1318 /* We cannot use memcmp on the whole structure here because under
1319 * aix386 the termios structure has some reserved field that may
1322 if ( new.c_iflag
== settings
->main
.c_iflag
1323 && new.c_oflag
== settings
->main
.c_oflag
1324 && new.c_cflag
== settings
->main
.c_cflag
1325 && new.c_lflag
== settings
->main
.c_lflag
1326 && memcmp (new.c_cc
, settings
->main
.c_cc
, NCCS
) == 0)
1334 /* The SYSV-style interface? */
1335 if (ioctl (fd
, flushp
? TCSETAF
: TCSETAW
, &settings
->main
) < 0)
1340 /* Vehemently Monstrous System? :-) */
1341 if (! (SYS$
QIOW (0, fd
, IO$_SETMODE
, &input_iosb
, 0, 0,
1342 &settings
->main
.class, 12, 0, 0, 0, 0)
1348 /* I give up - I hope you have the BSD ioctls. */
1349 if (ioctl (fd
, (flushp
) ? TIOCSETP
: TIOCSETN
, &settings
->main
) < 0)
1351 #endif /* not DOS_NT */
1357 /* Suivant - Do we have to get struct ltchars data? */
1359 if (ioctl (fd
, TIOCSLTC
, &settings
->ltchars
) < 0)
1363 /* How about a struct tchars and a wordful of lmode bits? */
1365 if (ioctl (fd
, TIOCSETC
, &settings
->tchars
) < 0
1366 || ioctl (fd
, TIOCLSET
, &settings
->lmode
) < 0)
1370 /* We have survived the tempest. */
1377 /* BSD 4.1 needs to keep track of the lmode bits in order to start
1382 #ifndef F_SETOWN_BUG
1384 int old_fcntl_owner
[MAXDESC
];
1385 #endif /* F_SETOWN */
1386 #endif /* F_SETOWN_BUG */
1388 /* This may also be defined in stdio,
1389 but if so, this does no harm,
1390 and using the same name avoids wasting the other one's space. */
1393 extern char *_sobuf
;
1395 #if defined (USG) || defined (DGUX)
1396 unsigned char _sobuf
[BUFSIZ
+8];
1398 char _sobuf
[BUFSIZ
];
1403 static struct ltchars new_ltchars
= {-1,-1,-1,-1,-1,-1};
1406 static struct tchars new_tchars
= {-1,-1,-1,-1,-1,-1};
1409 /* Initialize the terminal mode on all tty devices that are currently
1413 init_all_sys_modes (void)
1415 struct tty_display_info
*tty
;
1416 for (tty
= tty_list
; tty
; tty
= tty
->next
)
1417 init_sys_modes (tty
);
1420 /* Initialize the terminal mode on the given tty device. */
1423 init_sys_modes (tty_out
)
1424 struct tty_display_info
*tty_out
;
1426 struct emacs_tty tty
;
1430 static int oob_chars
[2] = {0, 1 << 7}; /* catch C-g's */
1431 extern int (*interrupt_signal
) ();
1435 Vtty_erase_char
= Qnil
;
1440 if (!tty_out
->output
)
1441 return; /* The tty is suspended. */
1445 input_ef
= get_kbd_event_flag ();
1446 /* LIB$GET_EF (&input_ef); */
1447 SYS$
CLREF (input_ef
);
1448 waiting_for_ast
= 0;
1450 timer_ef
= get_timer_event_flag ();
1451 /* LIB$GET_EF (&timer_ef); */
1452 SYS$
CLREF (timer_ef
);
1456 LIB$
GET_EF (&process_ef
);
1457 SYS$
CLREF (process_ef
);
1459 if (input_ef
/ 32 != process_ef
/ 32)
1460 croak ("Input and process event flags in different clusters.");
1462 if (input_ef
/ 32 != timer_ef
/ 32)
1463 croak ("Input and timer event flags in different clusters.");
1465 input_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1466 ((unsigned) 1 << (process_ef
% 32));
1468 timer_eflist
= ((unsigned) 1 << (input_ef
% 32)) |
1469 ((unsigned) 1 << (timer_ef
% 32));
1471 sys_access_reinit ();
1477 /* read_socket_hook is not global anymore. I think doing this
1478 unconditionally will not cause any problems. */
1479 if (! read_socket_hook
&& EQ (Vinitial_window_system
, Qnil
))
1481 narrow_foreground_group (fileno (tty_out
->input
));
1484 if (! tty_out
->old_tty
)
1485 tty_out
->old_tty
= (struct emacs_tty
*) xmalloc (sizeof (struct emacs_tty
));
1487 EMACS_GET_TTY (fileno (tty_out
->input
), tty_out
->old_tty
);
1489 tty
= *tty_out
->old_tty
;
1491 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
1492 XSETINT (Vtty_erase_char
, tty
.main
.c_cc
[VERASE
]);
1495 /* This allows meta to be sent on 8th bit. */
1496 tty
.main
.c_iflag
&= ~INPCK
; /* don't check input for parity */
1498 tty
.main
.c_iflag
|= (IGNBRK
); /* Ignore break condition */
1499 tty
.main
.c_iflag
&= ~ICRNL
; /* Disable map of CR to NL on input */
1500 #ifdef INLCR /* I'm just being cautious,
1501 since I can't check how widespread INLCR is--rms. */
1502 tty
.main
.c_iflag
&= ~INLCR
; /* Disable map of NL to CR on input */
1505 tty
.main
.c_iflag
&= ~ISTRIP
; /* don't strip 8th bit on input */
1507 tty
.main
.c_lflag
&= ~ECHO
; /* Disable echo */
1508 tty
.main
.c_lflag
&= ~ICANON
; /* Disable erase/kill processing */
1510 tty
.main
.c_lflag
&= ~IEXTEN
; /* Disable other editing characters. */
1512 tty
.main
.c_lflag
|= ISIG
; /* Enable signals */
1513 if (tty_out
->flow_control
)
1515 tty
.main
.c_iflag
|= IXON
; /* Enable start/stop output control */
1517 tty
.main
.c_iflag
&= ~IXANY
;
1521 tty
.main
.c_iflag
&= ~IXON
; /* Disable start/stop output control */
1522 tty
.main
.c_oflag
&= ~ONLCR
; /* Disable map of NL to CR-NL
1524 tty
.main
.c_oflag
&= ~TAB3
; /* Disable tab expansion */
1526 if (tty_out
->meta_key
)
1528 tty
.main
.c_cflag
|= CS8
; /* allow 8th bit on input */
1529 tty
.main
.c_cflag
&= ~PARENB
;/* Don't check parity */
1532 if (tty_out
->input
== stdin
)
1534 tty
.main
.c_cc
[VINTR
] = quit_char
; /* C-g (usually) gives SIGINT */
1535 /* Set up C-g for both SIGQUIT and SIGINT.
1536 We don't know which we will get, but we handle both alike
1537 so which one it really gives us does not matter. */
1538 tty
.main
.c_cc
[VQUIT
] = quit_char
;
1542 /* We normally don't get interrupt or quit signals from tty
1543 devices other than our controlling terminal; therefore,
1544 we must handle C-g as normal input. Unfortunately, this
1545 means that the interrupt and quit feature must be
1546 disabled on secondary ttys, or we would not even see the
1549 Note that even though emacsclient could have special code
1550 to pass SIGINT to Emacs, we should _not_ enable
1551 interrupt/quit keys for emacsclient frames. This means
1552 that we can't break out of loops in C code from a
1553 secondary tty frame, but we can always decide what
1554 display the C-g came from, which is more important from a
1555 usability point of view. (Consider the case when two
1556 people work together using the same Emacs instance.) */
1557 tty
.main
.c_cc
[VINTR
] = CDISABLE
;
1558 tty
.main
.c_cc
[VQUIT
] = CDISABLE
;
1560 tty
.main
.c_cc
[VMIN
] = 1; /* Input should wait for at least 1 char */
1561 tty
.main
.c_cc
[VTIME
] = 0; /* no matter how long that takes. */
1563 tty
.main
.c_cc
[VSWTCH
] = CDISABLE
; /* Turn off shell layering use
1567 #if defined (mips) || defined (HAVE_TCATTR)
1569 tty
.main
.c_cc
[VSUSP
] = CDISABLE
; /* Turn off mips handling of C-z. */
1572 tty
.main
.c_cc
[V_DSUSP
] = CDISABLE
; /* Turn off mips handling of C-y. */
1573 #endif /* V_DSUSP */
1574 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
1575 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1578 tty
.main
.c_cc
[VLNEXT
] = CDISABLE
;
1581 tty
.main
.c_cc
[VREPRINT
] = CDISABLE
;
1582 #endif /* VREPRINT */
1584 tty
.main
.c_cc
[VWERASE
] = CDISABLE
;
1585 #endif /* VWERASE */
1587 tty
.main
.c_cc
[VDISCARD
] = CDISABLE
;
1588 #endif /* VDISCARD */
1590 if (tty_out
->flow_control
)
1593 tty
.main
.c_cc
[VSTART
] = '\021';
1596 tty
.main
.c_cc
[VSTOP
] = '\023';
1602 tty
.main
.c_cc
[VSTART
] = CDISABLE
;
1605 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1608 #endif /* mips or HAVE_TCATTR */
1610 #ifdef SET_LINE_DISCIPLINE
1611 /* Need to explicitly request TERMIODISC line discipline or
1612 Ultrix's termios does not work correctly. */
1613 tty
.main
.c_line
= SET_LINE_DISCIPLINE
;
1617 /* AIX enhanced edit loses NULs, so disable it. */
1618 tty
.main
.c_line
= 0;
1619 tty
.main
.c_iflag
&= ~ASCEDIT
;
1621 tty
.main
.c_cc
[VSTRT
] = CDISABLE
;
1622 tty
.main
.c_cc
[VSTOP
] = CDISABLE
;
1623 tty
.main
.c_cc
[VSUSP
] = CDISABLE
;
1624 tty
.main
.c_cc
[VDSUSP
] = CDISABLE
;
1625 #endif /* IBMR2AIX */
1626 if (tty_out
->flow_control
)
1629 tty
.main
.c_cc
[VSTART
] = '\021';
1632 tty
.main
.c_cc
[VSTOP
] = '\023';
1635 /* Also, PTY overloads NUL and BREAK.
1636 don't ignore break, but don't signal either, so it looks like NUL.
1637 This really serves a purpose only if running in an XTERM window
1638 or via TELNET or the like, but does no harm elsewhere. */
1639 tty
.main
.c_iflag
&= ~IGNBRK
;
1640 tty
.main
.c_iflag
&= ~BRKINT
;
1642 #else /* if not HAVE_TERMIO */
1644 tty
.main
.tt_char
|= TT$M_NOECHO
;
1646 tty
.main
.tt_char
|= TT$M_EIGHTBIT
;
1647 if (tty_out
->flow_control
)
1648 tty
.main
.tt_char
|= TT$M_TTSYNC
;
1650 tty
.main
.tt_char
&= ~TT$M_TTSYNC
;
1651 tty
.main
.tt2_char
|= TT2$M_PASTHRU
| TT2$M_XON
;
1652 #else /* not VMS (BSD, that is) */
1654 XSETINT (Vtty_erase_char
, tty
.main
.sg_erase
);
1655 tty
.main
.sg_flags
&= ~(ECHO
| CRMOD
| XTABS
);
1657 tty
.main
.sg_flags
|= ANYP
;
1658 tty
.main
.sg_flags
|= interrupt_input
? RAW
: CBREAK
;
1659 #endif /* not DOS_NT */
1660 #endif /* not VMS (BSD, that is) */
1661 #endif /* not HAVE_TERMIO */
1663 /* If going to use CBREAK mode, we must request C-g to interrupt
1664 and turn off start and stop chars, etc. If not going to use
1665 CBREAK mode, do this anyway so as to turn off local flow
1666 control for user coming over network on 4.2; in this case,
1667 only t_stopc and t_startc really matter. */
1670 /* Note: if not using CBREAK mode, it makes no difference how we
1672 tty
.tchars
= new_tchars
;
1673 tty
.tchars
.t_intrc
= quit_char
;
1674 if (tty_out
->flow_control
)
1676 tty
.tchars
.t_startc
= '\021';
1677 tty
.tchars
.t_stopc
= '\023';
1680 tty
.lmode
= LDECCTQ
| LLITOUT
| LPASS8
| LNOFLSH
| tty_out
->old_tty
.lmode
;
1682 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
1683 anything, and leaving it in breaks the meta key. Go figure. */
1684 tty
.lmode
&= ~LLITOUT
;
1691 #endif /* HAVE_TCHARS */
1692 #endif /* not HAVE_TERMIO */
1695 tty
.ltchars
= new_ltchars
;
1696 #endif /* HAVE_LTCHARS */
1697 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
1698 if (!tty_out
->term_initted
)
1699 internal_terminal_init ();
1703 EMACS_SET_TTY (fileno (tty_out
->input
), &tty
, 0);
1705 /* This code added to insure that, if flow-control is not to be used,
1706 we have an unlocked terminal at the start. */
1709 if (!tty_out
->flow_control
) ioctl (fileno (tty_out
->input
), TCXONC
, 1);
1713 if (!tty_out
->flow_control
) ioctl (fileno (tty_out
->input
), TIOCSTART
, 0);
1717 #if defined (HAVE_TERMIOS) || defined (HPUX9)
1719 if (!tty_out
->flow_control
) tcflow (fileno (tty_out
->input
), TCOON
);
1727 /* IBM's HFT device usually thinks a ^J should be LF/CR. We need it
1728 to be only LF. This is the way that is done. */
1731 if (ioctl (1, HFTGETID
, &tty
) != -1)
1732 write (1, "\033[20l", 5);
1738 /* Appears to do nothing when in PASTHRU mode.
1739 SYS$QIOW (0, fileno (tty_out->input), IO$_SETMODE|IO$M_OUTBAND, 0, 0, 0,
1740 interrupt_signal, oob_chars, 0, 0, 0, 0);
1742 queue_kbd_input (0);
1746 #ifndef F_SETOWN_BUG
1747 #ifdef F_GETOWN /* F_SETFL does not imply existence of F_GETOWN */
1748 if (interrupt_input
)
1750 old_fcntl_owner
[fileno (tty_out
->input
)] =
1751 fcntl (fileno (tty_out
->input
), F_GETOWN
, 0);
1752 fcntl (fileno (tty_out
->input
), F_SETOWN
, getpid ());
1753 init_sigio (fileno (tty_out
->input
));
1757 fcntl (gpm_fd
, F_SETOWN
, getpid ());
1758 fcntl (gpm_fd
, F_SETFL
, fcntl (gpm_fd
, F_GETFL
, 0) | O_NONBLOCK
);
1759 init_sigio (gpm_fd
);
1761 #endif /* HAVE_GPM */
1763 #endif /* F_GETOWN */
1764 #endif /* F_SETOWN_BUG */
1765 #endif /* F_SETFL */
1768 if (interrupt_input
)
1769 init_sigio (fileno (tty_out
->input
));
1772 #ifdef VMS /* VMS sometimes has this symbol but lacks setvbuf. */
1776 /* This symbol is defined on recent USG systems.
1777 Someone says without this call USG won't really buffer the file
1778 even with a call to setbuf. */
1779 setvbuf (tty_out
->output
, (char *) _sobuf
, _IOFBF
, sizeof _sobuf
);
1781 setbuf (tty_out
->output
, (char *) _sobuf
);
1784 if (tty_out
->terminal
->set_terminal_modes_hook
)
1785 tty_out
->terminal
->set_terminal_modes_hook (tty_out
->terminal
);
1787 if (!tty_out
->term_initted
)
1789 Lisp_Object tail
, frame
;
1790 FOR_EACH_FRAME (tail
, frame
)
1792 /* XXX This needs to be revised. */
1793 if (FRAME_TERMCAP_P (XFRAME (frame
))
1794 && FRAME_TTY (XFRAME (frame
)) == tty_out
)
1795 init_frame_faces (XFRAME (frame
));
1799 if (tty_out
->term_initted
&& no_redraw_on_reenter
)
1801 /* XXX This seems wrong on multi-tty. */
1802 if (display_completed
)
1803 direct_output_forward_char (0);
1807 Lisp_Object tail
, frame
;
1809 FOR_EACH_FRAME (tail
, frame
)
1811 if (FRAME_TERMCAP_P (XFRAME (frame
))
1812 && FRAME_TTY (XFRAME (frame
)) == tty_out
)
1813 FRAME_GARBAGED_P (XFRAME (frame
)) = 1;
1817 tty_out
->term_initted
= 1;
1820 /* Return nonzero if safe to use tabs in output.
1821 At the time this is called, init_sys_modes has not been done yet. */
1824 tabs_safe_p (int fd
)
1826 struct emacs_tty etty
;
1828 EMACS_GET_TTY (fd
, &etty
);
1829 return EMACS_TTY_TABS_OK (&etty
);
1832 /* Get terminal size from system.
1833 Store number of lines into *HEIGHTP and width into *WIDTHP.
1834 We store 0 if there's no valid information. */
1837 get_tty_size (int fd
, int *widthp
, int *heightp
)
1843 struct winsize size
;
1845 if (ioctl (fd
, TIOCGWINSZ
, &size
) == -1)
1846 *widthp
= *heightp
= 0;
1849 *widthp
= size
.ws_col
;
1850 *heightp
= size
.ws_row
;
1856 /* SunOS - style. */
1857 struct ttysize size
;
1859 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1860 *widthp
= *heightp
= 0;
1863 *widthp
= size
.ts_cols
;
1864 *heightp
= size
.ts_lines
;
1870 /* Use a fresh channel since the current one may have stale info
1871 (for example, from prior to a suspend); and to avoid a dependency
1872 in the init sequence. */
1874 struct sensemode tty
;
1876 SYS$
ASSIGN (&input_dsc
, &chan
, 0, 0);
1877 SYS$
QIOW (0, chan
, IO$_SENSEMODE
, &tty
, 0, 0,
1878 &tty
.class, 12, 0, 0, 0, 0);
1880 *widthp
= tty
.scr_wid
;
1881 *heightp
= tty
.scr_len
;
1885 *widthp
= ScreenCols ();
1886 *heightp
= ScreenRows ();
1887 #else /* system doesn't know size */
1891 #endif /* not VMS */
1892 #endif /* not SunOS-style */
1893 #endif /* not BSD-style */
1896 /* Set the logical window size associated with descriptor FD
1897 to HEIGHT and WIDTH. This is used mainly with ptys. */
1900 set_window_size (fd
, height
, width
)
1901 int fd
, height
, width
;
1906 struct winsize size
;
1907 size
.ws_row
= height
;
1908 size
.ws_col
= width
;
1910 if (ioctl (fd
, TIOCSWINSZ
, &size
) == -1)
1911 return 0; /* error */
1918 /* SunOS - style. */
1919 struct ttysize size
;
1920 size
.ts_lines
= height
;
1921 size
.ts_cols
= width
;
1923 if (ioctl (fd
, TIOCGSIZE
, &size
) == -1)
1929 #endif /* not SunOS-style */
1930 #endif /* not BSD-style */
1935 /* Prepare all terminal devices for exiting Emacs. */
1938 reset_all_sys_modes (void)
1940 struct tty_display_info
*tty
;
1941 for (tty
= tty_list
; tty
; tty
= tty
->next
)
1942 reset_sys_modes (tty
);
1945 /* Prepare the terminal for closing it; move the cursor to the
1946 bottom of the frame, turn off interrupt-driven I/O, etc. */
1949 reset_sys_modes (tty_out
)
1950 struct tty_display_info
*tty_out
;
1957 if (!tty_out
->term_initted
)
1960 if (!tty_out
->output
)
1961 return; /* The tty is suspended. */
1963 /* Go to and clear the last line of the terminal. */
1965 cmgoto (tty_out
, FrameRows (tty_out
) - 1, 0);
1967 /* Code adapted from tty_clear_end_of_line. */
1968 if (tty_out
->TS_clr_line
)
1970 emacs_tputs (tty_out
, tty_out
->TS_clr_line
, 1, cmputc
);
1973 { /* have to do it the hard way */
1975 tty_turn_off_insert (tty_out
);
1977 for (i
= curX (tty_out
); i
< FrameCols (tty_out
) - 1; i
++)
1979 fputc (' ', tty_out
->output
);
1983 cmgoto (tty_out
, FrameRows (tty_out
) - 1, 0);
1984 fflush (tty_out
->output
);
1986 #if defined (IBMR2AIX) && defined (AIXHFT)
1988 /* HFT devices normally use ^J as a LF/CR. We forced it to
1989 do the LF only. Now, we need to reset it. */
1992 if (ioctl (1, HFTGETID
, &tty
) != -1)
1993 write (1, "\033[20h", 5);
1997 if (tty_out
->terminal
->reset_terminal_modes_hook
)
1998 tty_out
->terminal
->reset_terminal_modes_hook (tty_out
->terminal
);
2002 /* Avoid possible loss of output when changing terminal modes. */
2003 fsync (fileno (tty_out
->output
));
2008 #ifndef F_SETOWN_BUG
2009 #ifdef F_SETOWN /* F_SETFL does not imply existence of F_SETOWN */
2010 if (interrupt_input
)
2012 reset_sigio (fileno (tty_out
->input
));
2013 fcntl (fileno (tty_out
->input
), F_SETOWN
,
2014 old_fcntl_owner
[fileno (tty_out
->input
)]);
2016 #endif /* F_SETOWN */
2017 #endif /* F_SETOWN_BUG */
2019 fcntl (fileno (tty_out
->input
), F_SETFL
,
2020 fcntl (fileno (tty_out
->input
), F_GETFL
, 0) & ~O_NDELAY
);
2022 #endif /* F_SETFL */
2024 if (interrupt_input
)
2025 reset_sigio (fileno (tty_out
->input
));
2028 if (tty_out
->old_tty
)
2029 while (EMACS_SET_TTY (fileno (tty_out
->input
),
2030 tty_out
->old_tty
, 0) < 0 && errno
== EINTR
)
2033 #ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida */
2037 #ifdef SET_LINE_DISCIPLINE
2038 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
2039 A different old line discipline is therefore not restored, yet.
2040 Restore the old line discipline by hand. */
2041 ioctl (0, TIOCSETD
, &tty_out
->old_tty
.main
.c_line
);
2049 widen_foreground_group (fileno (tty_out
->input
));
2055 /* Set up the proper status flags for use of a pty. */
2061 /* I'm told that TOICREMOTE does not mean control chars
2062 "can't be sent" but rather that they don't have
2063 input-editing or signaling effects.
2064 That should be good, because we have other ways
2065 to do those things in Emacs.
2066 However, telnet mode seems not to work on 4.2.
2067 So TIOCREMOTE is turned off now. */
2069 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
2070 will hang. In particular, the "timeout" feature (which
2071 causes a read to return if there is no data available)
2072 does this. Also it is known that telnet mode will hang
2073 in such a way that Emacs must be stopped (perhaps this
2074 is the same problem).
2076 If TIOCREMOTE is turned off, then there is a bug in
2077 hp-ux which sometimes loses data. Apparently the
2078 code which blocks the master process when the internal
2079 buffer fills up does not work. Other than this,
2080 though, everything else seems to work fine.
2082 Since the latter lossage is more benign, we may as well
2083 lose that way. -- cph */
2085 #if defined(SYSV_PTYS) || defined(UNIX98_PTYS)
2088 ioctl (fd
, FIONBIO
, &on
);
2093 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
2094 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
2095 /* cause EMACS not to die when it should, i.e., when its own controlling */
2096 /* tty goes away. I've complained to the AIX developers, and they may */
2097 /* change this behavior, but I'm not going to hold my breath. */
2098 signal (SIGHUP
, SIG_IGN
);
2101 #endif /* HAVE_PTYS */
2105 /* Assigning an input channel is done at the start of Emacs execution.
2106 This is called each time Emacs is resumed, also, but does nothing
2107 because input_chain is no longer zero. */
2114 if (fileno (CURTTY ()->input
)) == 0)
2116 status
= SYS$
ASSIGN (&input_dsc
, &fileno (CURTTY ()->input
)), 0, 0);
2122 /* Deassigning the input channel is done before exiting. */
2127 return SYS$
DASSGN (fileno (CURTTY ()->input
)));
2132 /* Request reading one character into the keyboard buffer.
2133 This is done as soon as the buffer becomes empty. */
2139 extern kbd_input_ast ();
2141 waiting_for_ast
= 0;
2143 status
= SYS$
QIO (0, fileno (CURTTY()->input
), IO$_READVBLK
,
2144 &input_iosb
, kbd_input_ast
, 1,
2145 &input_buffer
, 1, 0, terminator_mask
, 0, 0);
2150 /* Ast routine that is called when keyboard input comes in
2151 in accord with the SYS$QIO above. */
2156 register int c
= -1;
2157 int old_errno
= errno
;
2158 extern EMACS_TIME
*input_available_clear_time
;
2160 if (waiting_for_ast
)
2161 SYS$
SETEF (input_ef
);
2162 waiting_for_ast
= 0;
2165 if (input_count
== 25)
2167 printf ("Ast # %d,", input_count
);
2168 printf (" iosb = %x, %x, %x, %x",
2169 input_iosb
.offset
, input_iosb
.status
, input_iosb
.termlen
,
2172 if (input_iosb
.offset
)
2176 printf (", char = 0%o", c
);
2188 struct input_event e
;
2191 e
.kind
= ASCII_KEYSTROKE_EVENT
;
2192 XSETINT (e
.code
, c
);
2193 e
.frame_or_window
= selected_frame
;
2194 kbd_buffer_store_event (&e
);
2196 if (input_available_clear_time
)
2197 EMACS_SET_SECS_USECS (*input_available_clear_time
, 0, 0);
2201 /* Wait until there is something in kbd_buffer. */
2204 wait_for_kbd_input ()
2206 extern int have_process_input
, process_exited
;
2208 /* If already something, avoid doing system calls. */
2209 if (detect_input_pending ())
2213 /* Clear a flag, and tell ast routine above to set it. */
2214 SYS$
CLREF (input_ef
);
2215 waiting_for_ast
= 1;
2216 /* Check for timing error: ast happened while we were doing that. */
2217 if (!detect_input_pending ())
2219 /* No timing error: wait for flag to be set. */
2220 set_waiting_for_input (0);
2221 SYS$
WFLOR (input_ef
, input_eflist
);
2222 clear_waiting_for_input ();
2223 if (!detect_input_pending ())
2224 /* Check for subprocess input availability */
2226 int dsp
= have_process_input
|| process_exited
;
2228 SYS$
CLREF (process_ef
);
2229 if (have_process_input
)
2230 process_command_input ();
2235 update_mode_lines
++;
2236 prepare_menu_bars ();
2237 redisplay_preserve_echo_area (18);
2241 waiting_for_ast
= 0;
2244 /* Get rid of any pending QIO, when we are about to suspend
2245 or when we want to throw away pending input.
2246 We wait for a positive sign that the AST routine has run
2247 and therefore there is no I/O request queued when we return.
2248 SYS$SETAST is used to avoid a timing error. */
2254 printf ("At end_kbd_input.\n");
2258 if (LIB$
AST_IN_PROG ()) /* Don't wait if suspending from kbd_buffer_store_event! */
2260 SYS$
CANCEL (fileno (CURTTY()->input
));
2265 /* Clear a flag, and tell ast routine above to set it. */
2266 SYS$
CLREF (input_ef
);
2267 waiting_for_ast
= 1;
2269 SYS$
CANCEL (fileno (CURTTY()->input
));
2271 SYS$
WAITFR (input_ef
);
2272 waiting_for_ast
= 0;
2275 /* Wait for either input available or time interval expiry. */
2278 input_wait_timeout (timeval
)
2279 int timeval
; /* Time to wait, in seconds */
2282 static int zero
= 0;
2283 static int large
= -10000000;
2285 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2287 /* If already something, avoid doing system calls. */
2288 if (detect_input_pending ())
2292 /* Clear a flag, and tell ast routine above to set it. */
2293 SYS$
CLREF (input_ef
);
2294 waiting_for_ast
= 1;
2295 /* Check for timing error: ast happened while we were doing that. */
2296 if (!detect_input_pending ())
2298 /* No timing error: wait for flag to be set. */
2300 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2301 SYS$
WFLOR (timer_ef
, timer_eflist
); /* Wait for timer expiry or input */
2303 waiting_for_ast
= 0;
2306 /* The standard `sleep' routine works some other way
2307 and it stops working if you have ever quit out of it.
2308 This one continues to work. */
2314 static int zero
= 0;
2315 static int large
= -10000000;
2317 LIB$
EMUL (&timeval
, &large
, &zero
, time
); /* Convert to VMS format */
2320 if (SYS$
SETIMR (timer_ef
, time
, 0, 1) & 1) /* Set timer */
2321 SYS$
WAITFR (timer_ef
); /* Wait for timer expiry only */
2342 croak ("request sigio");
2350 croak ("unrequest sigio");
2355 /* Note that VMS compiler won't accept defined (CANNOT_DUMP). */
2360 #ifndef SYSTEM_MALLOC
2367 /* Some systems that cannot dump also cannot implement these. */
2370 * Return the address of the start of the text segment prior to
2371 * doing an unexec. After unexec the return value is undefined.
2372 * See crt0.c for further explanation and _start.
2376 #if !(defined (__NetBSD__) && defined (__ELF__))
2377 #ifndef HAVE_TEXT_START
2382 return ((char *) TEXT_START
);
2386 return ((char *) csrt
);
2387 #else /* not GOULD */
2388 extern int _start ();
2389 return ((char *) _start
);
2391 #endif /* TEXT_START */
2393 #endif /* not HAVE_TEXT_START */
2397 * Return the address of the start of the data segment prior to
2398 * doing an unexec. After unexec the return value is undefined.
2399 * See crt0.c for further information and definition of data_start.
2401 * Apparently, on BSD systems this is etext at startup. On
2402 * USG systems (swapping) this is highly mmu dependent and
2403 * is also dependent on whether or not the program is running
2404 * with shared text. Generally there is a (possibly large)
2405 * gap between end of text and start of data with shared text.
2407 * On Uniplus+ systems with shared text, data starts at a
2408 * fixed address. Each port (from a given oem) is generally
2409 * different, and the specific value of the start of data can
2410 * be obtained via the UniPlus+ specific "uvar" system call,
2411 * however the method outlined in crt0.c seems to be more portable.
2413 * Probably what will have to happen when a USG unexec is available,
2414 * at least on UniPlus, is temacs will have to be made unshared so
2415 * that text and data are contiguous. Then once loadup is complete,
2416 * unexec will produce a shared executable where the data can be
2417 * at the normal shared text boundary and the startofdata variable
2418 * will be patched by unexec to the correct value.
2422 #ifndef start_of_data
2427 return ((char *) DATA_START
);
2429 #ifdef ORDINARY_LINK
2431 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
2432 * data_start isn't defined. We take the address of environ, which
2433 * is known to live at or near the start of the system crt0.c, and
2434 * we don't sweat the handful of bytes that might lose.
2436 extern char **environ
;
2438 return ((char *) &environ
);
2440 extern int data_start
;
2441 return ((char *) &data_start
);
2442 #endif /* ORDINARY_LINK */
2443 #endif /* DATA_START */
2445 #endif /* start_of_data */
2446 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
2448 /* init_system_name sets up the string for the Lisp function
2449 system-name to return. */
2455 extern Lisp_Object Vsystem_name
;
2460 #include <sys/socket.h>
2462 #endif /* HAVE_SOCKETS */
2463 #endif /* not VMS */
2464 #endif /* not BSD4_1 */
2467 #ifndef HAVE_H_ERRNO
2470 #endif /* TRY_AGAIN */
2476 Vsystem_name
= build_string (sysname
);
2480 if ((sp
= egetenv ("SYS$NODE")) == 0)
2481 Vsystem_name
= build_string ("vax-vms");
2482 else if ((end
= index (sp
, ':')) == 0)
2483 Vsystem_name
= build_string (sp
);
2485 Vsystem_name
= make_string (sp
, end
- sp
);
2487 #ifndef HAVE_GETHOSTNAME
2490 Vsystem_name
= build_string (uts
.nodename
);
2491 #else /* HAVE_GETHOSTNAME */
2492 unsigned int hostname_size
= 256;
2493 char *hostname
= (char *) alloca (hostname_size
);
2495 /* Try to get the host name; if the buffer is too short, try
2496 again. Apparently, the only indication gethostname gives of
2497 whether the buffer was large enough is the presence or absence
2498 of a '\0' in the string. Eech. */
2501 gethostname (hostname
, hostname_size
- 1);
2502 hostname
[hostname_size
- 1] = '\0';
2504 /* Was the buffer large enough for the '\0'? */
2505 if (strlen (hostname
) < hostname_size
- 1)
2508 hostname_size
<<= 1;
2509 hostname
= (char *) alloca (hostname_size
);
2512 /* Turn the hostname into the official, fully-qualified hostname.
2513 Don't do this if we're going to dump; this can confuse system
2514 libraries on some machines and make the dumped emacs core dump. */
2517 #endif /* not CANNOT_DUMP */
2518 if (! index (hostname
, '.'))
2522 for (count
= 0;; count
++)
2527 hp
= gethostbyname (hostname
);
2529 if (! (hp
== 0 && h_errno
== TRY_AGAIN
))
2534 Fsleep_for (make_number (1), Qnil
);
2538 char *fqdn
= (char *) hp
->h_name
;
2543 if (!index (fqdn
, '.'))
2545 /* We still don't have a fully qualified domain name.
2546 Try to find one in the list of alternate names */
2547 char **alias
= hp
->h_aliases
;
2549 && (!index (*alias
, '.')
2550 || !strcmp (*alias
, "localhost.localdomain")))
2557 /* Convert the host name to lower case. */
2558 /* Using ctype.h here would introduce a possible locale
2559 dependence that is probably wrong for hostnames. */
2563 if (*p
>= 'A' && *p
<= 'Z')
2570 #endif /* HAVE_SOCKETS */
2571 /* We used to try using getdomainname here,
2572 but NIIBE Yutaka <gniibe@etl.go.jp> says that
2573 getdomainname gets the NIS/YP domain which often is not the same
2574 as in Internet domain name. */
2575 #if 0 /* Turned off because sysinfo is not really likely to return the
2576 correct Internet domain. */
2577 #if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
2578 if (! index (hostname
, '.'))
2580 /* The hostname is not fully qualified. Append the domain name. */
2582 int hostlen
= strlen (hostname
);
2583 int domain_size
= 256;
2587 char *domain
= (char *) alloca (domain_size
+ 1);
2588 char *fqdn
= (char *) alloca (hostlen
+ 1 + domain_size
+ 1);
2589 int sys_domain_size
= sysinfo (SI_SRPC_DOMAIN
, domain
, domain_size
);
2590 if (sys_domain_size
<= 0)
2592 if (domain_size
< sys_domain_size
)
2594 domain_size
= sys_domain_size
;
2597 strcpy (fqdn
, hostname
);
2598 if (domain
[0] == '.')
2599 strcpy (fqdn
+ hostlen
, domain
);
2600 else if (domain
[0] != 0)
2602 fqdn
[hostlen
] = '.';
2603 strcpy (fqdn
+ hostlen
+ 1, domain
);
2609 #endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
2611 Vsystem_name
= build_string (hostname
);
2612 #endif /* HAVE_GETHOSTNAME */
2617 for (p
= SDATA (Vsystem_name
); *p
; p
++)
2618 if (*p
== ' ' || *p
== '\t')
2625 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2627 #include "sysselect.h"
2630 #if defined (HAVE_X_WINDOWS) && !defined (HAVE_SELECT)
2631 /* Cause explanatory error message at compile time,
2632 since the select emulation is not good enough for X. */
2633 int *x
= &x_windows_lose_if_no_select_system_call
;
2636 /* Emulate as much as select as is possible under 4.1 and needed by Gnu Emacs
2637 * Only checks read descriptors.
2639 /* How long to wait between checking fds in select */
2640 #define SELECT_PAUSE 1
2643 /* For longjmp'ing back to read_input_waiting. */
2645 jmp_buf read_alarm_throw
;
2647 /* Nonzero if the alarm signal should throw back to read_input_waiting.
2648 The read_socket_hook function sets this to 1 while it is waiting. */
2650 int read_alarm_should_throw
;
2658 #else /* not BSD4_1 */
2659 signal (SIGALRM
, SIG_IGN
);
2660 #endif /* not BSD4_1 */
2661 SIGNAL_THREAD_CHECK (SIGALRM
);
2662 if (read_alarm_should_throw
)
2663 longjmp (read_alarm_throw
, 1);
2667 /* Only rfds are checked. */
2669 sys_select (nfds
, rfds
, wfds
, efds
, timeout
)
2671 SELECT_TYPE
*rfds
, *wfds
, *efds
;
2672 EMACS_TIME
*timeout
;
2674 /* XXX This needs to be updated for multi-tty support. Is there
2675 anybody who needs to emulate select these days? */
2680 extern int proc_buffered_char
[];
2681 #ifndef subprocesses
2682 int process_tick
= 0, update_tick
= 0;
2684 extern int process_tick
, update_tick
;
2688 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
2689 /* If we're using X, then the native select will work; we only need the
2690 emulation for non-X usage. */
2691 if (!NILP (Vinitial_window_system
))
2692 return select (nfds
, rfds
, wfds
, efds
, timeout
);
2694 timeoutval
= timeout
? EMACS_SECS (*timeout
) : 100000;
2695 local_timeout
= &timeoutval
;
2707 /* If we are looking only for the terminal, with no timeout,
2708 just read it and wait -- that's more efficient. */
2709 if (*local_timeout
== 100000 && process_tick
== update_tick
2710 && FD_ISSET (0, &orfds
))
2713 for (fd
= 1; fd
< nfds
; ++fd
)
2714 if (FD_ISSET (fd
, &orfds
))
2716 if (! detect_input_pending ())
2717 read_input_waiting ();
2723 /* Once a second, till the timer expires, check all the flagged read
2724 * descriptors to see if any input is available. If there is some then
2725 * set the corresponding bit in the return copy of rfds.
2729 register int to_check
, fd
;
2733 for (to_check
= nfds
, fd
= 0; --to_check
>= 0; fd
++)
2735 if (FD_ISSET (fd
, &orfds
))
2737 int avail
= 0, status
= 0;
2740 avail
= detect_input_pending (); /* Special keyboard handler */
2744 status
= ioctl (fd
, FIONREAD
, &avail
);
2745 #else /* no FIONREAD */
2746 /* Hoping it will return -1 if nothing available
2747 or 0 if all 0 chars requested are read. */
2748 if (proc_buffered_char
[fd
] >= 0)
2752 avail
= read (fd
, &buf
, 1);
2754 proc_buffered_char
[fd
] = buf
;
2756 #endif /* no FIONREAD */
2758 if (status
>= 0 && avail
> 0)
2766 if (*local_timeout
== 0 || ravail
!= 0 || process_tick
!= update_tick
)
2769 turn_on_atimers (0);
2770 signal (SIGALRM
, select_alarm
);
2772 alarm (SELECT_PAUSE
);
2774 /* Wait for a SIGALRM (or maybe a SIGTINT) */
2775 while (select_alarmed
== 0 && *local_timeout
!= 0
2776 && process_tick
== update_tick
)
2778 /* If we are interested in terminal input,
2779 wait by reading the terminal.
2780 That makes instant wakeup for terminal input at least. */
2781 if (FD_ISSET (0, &orfds
))
2783 read_input_waiting ();
2784 if (detect_input_pending ())
2790 (*local_timeout
) -= SELECT_PAUSE
;
2792 /* Reset the old alarm if there was one. */
2793 turn_on_atimers (1);
2795 if (*local_timeout
== 0) /* Stop on timer being cleared */
2800 #endif /* not WINDOWSNT */
2802 /* Read keyboard input into the standard buffer,
2803 waiting for at least one character. */
2806 read_input_waiting ()
2808 /* XXX This needs to be updated for multi-tty support. Is there
2809 anybody who needs to emulate select these days? */
2811 extern int quit_char
;
2813 if (read_socket_hook
)
2815 struct input_event hold_quit
;
2817 EVENT_INIT (hold_quit
);
2818 hold_quit
.kind
= NO_EVENT
;
2820 read_alarm_should_throw
= 0;
2821 if (! setjmp (read_alarm_throw
))
2822 nread
= (*read_socket_hook
) (0, 1, &hold_quit
);
2826 if (hold_quit
.kind
!= NO_EVENT
)
2827 kbd_buffer_store_event (&hold_quit
);
2831 struct input_event e
;
2833 nread
= read (fileno (stdin
), buf
, 1);
2836 /* Scan the chars for C-g and store them in kbd_buffer. */
2837 e
.kind
= ASCII_KEYSTROKE_EVENT
;
2838 e
.frame_or_window
= selected_frame
;
2840 for (i
= 0; i
< nread
; i
++)
2842 /* Convert chars > 0177 to meta events if desired.
2843 We do this under the same conditions that read_avail_input does. */
2844 if (read_socket_hook
== 0)
2846 /* If the user says she has a meta key, then believe her. */
2847 if (meta_key
== 1 && (buf
[i
] & 0x80))
2848 e
.modifiers
= meta_modifier
;
2853 XSETINT (e
.code
, buf
[i
]);
2854 kbd_buffer_store_event (&e
);
2855 /* Don't look at input that follows a C-g too closely.
2856 This reduces lossage due to autorepeat on C-g. */
2857 if (buf
[i
] == quit_char
)
2863 #if !defined (HAVE_SELECT) || defined (BROKEN_SELECT_NON_X)
2864 #define select sys_select
2867 #endif /* not HAVE_SELECT */
2868 #endif /* not VMS */
2869 #endif /* not MSDOS */
2878 lmode
= LINTRUP
| lmode
;
2879 ioctl (fd
, TIOCLSET
, &lmode
);
2888 lmode
= ~LINTRUP
& lmode
;
2889 ioctl (fd
, TIOCLSET
, &lmode
);
2899 interrupts_deferred
= 0;
2909 interrupts_deferred
= 1;
2912 /* still inside #ifdef BSD4_1 */
2915 int sigheld
; /* Mask of held signals */
2921 sigheld
|= sigbit (signum
);
2929 sigheld
|= sigbit (signum
);
2936 sigheld
&= ~sigbit (signum
);
2941 sigfree () /* Free all held signals */
2944 for (i
= 0; i
< NSIG
; i
++)
2945 if (sigheld
& sigbit (i
))
2953 return 1 << (i
- 1);
2955 #endif /* subprocesses */
2958 /* POSIX signals support - DJB */
2959 /* Anyone with POSIX signals should have ANSI C declarations */
2961 #ifdef POSIX_SIGNALS
2963 sigset_t empty_mask
, full_mask
;
2966 sys_signal (int signal_number
, signal_handler_t action
)
2968 struct sigaction new_action
, old_action
;
2969 sigemptyset (&new_action
.sa_mask
);
2970 new_action
.sa_handler
= action
;
2971 #if defined (SA_RESTART) && ! defined (BROKEN_SA_RESTART) && !defined(SYNC_INPUT)
2972 /* Emacs mostly works better with restartable system services. If this
2973 flag exists, we probably want to turn it on here.
2974 However, on some systems this resets the timeout of `select'
2975 which means that `select' never finishes if it keeps getting signals.
2976 BROKEN_SA_RESTART is defined on those systems. */
2977 /* It's not clear why the comment above says "mostly works better". --Stef
2978 When SYNC_INPUT is set, we don't want SA_RESTART because we need to poll
2979 for pending input so we need long-running syscalls to be interrupted
2980 after a signal that sets the interrupt_input_pending flag. */
2981 new_action
.sa_flags
= SA_RESTART
;
2983 new_action
.sa_flags
= 0;
2985 sigaction (signal_number
, &new_action
, &old_action
);
2986 return (old_action
.sa_handler
);
2990 /* If we're compiling with GCC, we don't need this function, since it
2991 can be written as a macro. */
2993 sys_sigmask (int sig
)
2996 sigemptyset (&mask
);
2997 sigaddset (&mask
, sig
);
3002 /* I'd like to have these guys return pointers to the mask storage in here,
3003 but there'd be trouble if the code was saving multiple masks. I'll be
3004 safe and pass the structure. It normally won't be more than 2 bytes
3008 sys_sigblock (sigset_t new_mask
)
3011 sigprocmask (SIG_BLOCK
, &new_mask
, &old_mask
);
3016 sys_sigunblock (sigset_t new_mask
)
3019 sigprocmask (SIG_UNBLOCK
, &new_mask
, &old_mask
);
3024 sys_sigsetmask (sigset_t new_mask
)
3027 sigprocmask (SIG_SETMASK
, &new_mask
, &old_mask
);
3031 #endif /* POSIX_SIGNALS */
3033 #if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
3034 static char *my_sys_siglist
[NSIG
];
3038 # define sys_siglist my_sys_siglist
3044 #ifdef POSIX_SIGNALS
3045 sigemptyset (&empty_mask
);
3046 sigfillset (&full_mask
);
3049 #if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
3053 sys_siglist
[SIGABRT
] = "Aborted";
3056 sys_siglist
[SIGAIO
] = "LAN I/O interrupt";
3059 sys_siglist
[SIGALRM
] = "Alarm clock";
3062 sys_siglist
[SIGBUS
] = "Bus error";
3065 sys_siglist
[SIGCLD
] = "Child status changed";
3068 sys_siglist
[SIGCHLD
] = "Child status changed";
3071 sys_siglist
[SIGCONT
] = "Continued";
3074 sys_siglist
[SIGDANGER
] = "Swap space dangerously low";
3077 sys_siglist
[SIGDGNOTIFY
] = "Notification message in queue";
3080 sys_siglist
[SIGEMT
] = "Emulation trap";
3083 sys_siglist
[SIGFPE
] = "Arithmetic exception";
3086 sys_siglist
[SIGFREEZE
] = "SIGFREEZE";
3089 sys_siglist
[SIGGRANT
] = "Monitor mode granted";
3092 sys_siglist
[SIGHUP
] = "Hangup";
3095 sys_siglist
[SIGILL
] = "Illegal instruction";
3098 sys_siglist
[SIGINT
] = "Interrupt";
3101 sys_siglist
[SIGIO
] = "I/O possible";
3104 sys_siglist
[SIGIOINT
] = "I/O intervention required";
3107 sys_siglist
[SIGIOT
] = "IOT trap";
3110 sys_siglist
[SIGKILL
] = "Killed";
3113 sys_siglist
[SIGLOST
] = "Resource lost";
3116 sys_siglist
[SIGLWP
] = "SIGLWP";
3119 sys_siglist
[SIGMSG
] = "Monitor mode data available";
3122 sys_siglist
[SIGWIND
] = "SIGPHONE";
3125 sys_siglist
[SIGPIPE
] = "Broken pipe";
3128 sys_siglist
[SIGPOLL
] = "Pollable event occurred";
3131 sys_siglist
[SIGPROF
] = "Profiling timer expired";
3134 sys_siglist
[SIGPTY
] = "PTY I/O interrupt";
3137 sys_siglist
[SIGPWR
] = "Power-fail restart";
3140 sys_siglist
[SIGQUIT
] = "Quit";
3143 sys_siglist
[SIGRETRACT
] = "Need to relinguish monitor mode";
3146 sys_siglist
[SIGSAK
] = "Secure attention";
3149 sys_siglist
[SIGSEGV
] = "Segmentation violation";
3152 sys_siglist
[SIGSOUND
] = "Sound completed";
3155 sys_siglist
[SIGSTOP
] = "Stopped (signal)";
3158 sys_siglist
[SIGSTP
] = "Stopped (user)";
3161 sys_siglist
[SIGSYS
] = "Bad argument to system call";
3164 sys_siglist
[SIGTERM
] = "Terminated";
3167 sys_siglist
[SIGTHAW
] = "SIGTHAW";
3170 sys_siglist
[SIGTRAP
] = "Trace/breakpoint trap";
3173 sys_siglist
[SIGTSTP
] = "Stopped (user)";
3176 sys_siglist
[SIGTTIN
] = "Stopped (tty input)";
3179 sys_siglist
[SIGTTOU
] = "Stopped (tty output)";
3182 sys_siglist
[SIGURG
] = "Urgent I/O condition";
3185 sys_siglist
[SIGUSR1
] = "User defined signal 1";
3188 sys_siglist
[SIGUSR2
] = "User defined signal 2";
3191 sys_siglist
[SIGVTALRM
] = "Virtual timer expired";
3194 sys_siglist
[SIGWAITING
] = "Process's LWPs are blocked";
3197 sys_siglist
[SIGWINCH
] = "Window size changed";
3200 sys_siglist
[SIGWIND
] = "SIGWIND";
3203 sys_siglist
[SIGXCPU
] = "CPU time limit exceeded";
3206 sys_siglist
[SIGXFSZ
] = "File size limit exceeded";
3209 #endif /* !defined HAVE_STRSIGNAL && !defined HAVE_DECL_SYS_SIGLIST */
3218 /* Figure out how many bits the system's random number generator uses.
3219 `random' and `lrand48' are assumed to return 31 usable bits.
3220 BSD `rand' returns a 31 bit value but the low order bits are unusable;
3221 so we'll shift it and treat it like the 15-bit USG `rand'. */
3225 # define RAND_BITS 31
3226 # else /* !HAVE_RANDOM */
3227 # ifdef HAVE_LRAND48
3228 # define RAND_BITS 31
3229 # define random lrand48
3230 # else /* !HAVE_LRAND48 */
3231 # define RAND_BITS 15
3232 # if RAND_MAX == 32767
3233 # define random rand
3234 # else /* RAND_MAX != 32767 */
3235 # if RAND_MAX == 2147483647
3236 # define random() (rand () >> 16)
3237 # else /* RAND_MAX != 2147483647 */
3239 # define random rand
3241 # define random() (rand () >> 16)
3243 # endif /* RAND_MAX != 2147483647 */
3244 # endif /* RAND_MAX != 32767 */
3245 # endif /* !HAVE_LRAND48 */
3246 # endif /* !HAVE_RANDOM */
3247 #endif /* !RAND_BITS */
3254 srandom ((unsigned int)arg
);
3256 # ifdef HAVE_LRAND48
3259 srand ((unsigned int)arg
);
3265 * Build a full Emacs-sized word out of whatever we've got.
3266 * This suffices even for a 64-bit architecture with a 15-bit rand.
3271 long val
= random ();
3272 #if VALBITS > RAND_BITS
3273 val
= (val
<< RAND_BITS
) ^ random ();
3274 #if VALBITS > 2*RAND_BITS
3275 val
= (val
<< RAND_BITS
) ^ random ();
3276 #if VALBITS > 3*RAND_BITS
3277 val
= (val
<< RAND_BITS
) ^ random ();
3278 #if VALBITS > 4*RAND_BITS
3279 val
= (val
<< RAND_BITS
) ^ random ();
3280 #endif /* need at least 5 */
3281 #endif /* need at least 4 */
3282 #endif /* need at least 3 */
3283 #endif /* need at least 2 */
3284 return val
& ((1L << VALBITS
) - 1);
3287 #ifdef WRONG_NAME_INSQUE
3300 /* If any place else asks for the TERM variable,
3301 allow it to be overridden with the EMACS_TERM variable
3302 before attempting to translate the logical name TERM. As a last
3303 resort, ask for VAX C's special idea of the TERM variable. */
3310 static char buf
[256];
3311 static struct dsc$descriptor_s equiv
3312 = {sizeof (buf
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, buf
};
3313 static struct dsc$descriptor_s d_name
3314 = {0, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, 0};
3317 if (!strcmp (name
, "TERM"))
3319 val
= (char *) getenv ("EMACS_TERM");
3324 d_name
.dsc$w_length
= strlen (name
);
3325 d_name
.dsc$a_pointer
= name
;
3326 if (LIB$
SYS_TRNLOG (&d_name
, &eqlen
, &equiv
) == 1)
3328 char *str
= (char *) xmalloc (eqlen
+ 1);
3329 bcopy (buf
, str
, eqlen
);
3331 /* This is a storage leak, but a pain to fix. With luck,
3332 no one will ever notice. */
3335 return (char *) getenv (name
);
3340 /* Since VMS doesn't believe in core dumps, the only way to debug this beast is
3341 to force a call on the debugger from within the image. */
3345 reset_all_sys_modes ();
3346 LIB$
SIGNAL (SS$_DEBUG
);
3352 #ifdef LINK_CRTL_SHARE
3353 #ifdef SHARABLE_LIB_BUG
3354 /* Variables declared noshare and initialized in sharable libraries
3355 cannot be shared. The VMS linker incorrectly forces you to use a private
3356 version which is uninitialized... If not for this "feature", we
3357 could use the C library definition of sys_nerr and sys_errlist. */
3359 char *sys_errlist
[] =
3363 "no such file or directory",
3365 "interrupted system call",
3367 "no such device or address",
3368 "argument list too long",
3369 "exec format error",
3372 "no more processes",
3373 "not enough memory",
3374 "permission denied",
3376 "block device required",
3377 "mount devices busy",
3379 "cross-device link",
3384 "file table overflow",
3385 "too many open files",
3389 "no space left on device",
3391 "read-only file system",
3397 "vax/vms specific error code nontranslatable error"
3399 #endif /* SHARABLE_LIB_BUG */
3400 #endif /* LINK_CRTL_SHARE */
3403 #ifndef HAVE_STRERROR
3409 extern char *sys_errlist
[];
3410 extern int sys_nerr
;
3412 if (errnum
>= 0 && errnum
< sys_nerr
)
3413 return sys_errlist
[errnum
];
3414 return (char *) "Unknown error";
3416 #endif /* not WINDOWSNT */
3417 #endif /* ! HAVE_STRERROR */
3420 emacs_open (path
, oflag
, mode
)
3424 register int rtnval
;
3427 if (oflag
& O_CREAT
)
3428 return creat (path
, mode
);
3431 while ((rtnval
= open (path
, oflag
, mode
)) == -1
3432 && (errno
== EINTR
))
3442 register int rtnval
;
3444 while ((rtnval
= close (fd
)) == -1
3445 && (errno
== EINTR
))
3448 /* If close is interrupted SunOS 4.1 may or may not have closed the
3449 file descriptor. If it did the second close will fail with
3450 errno = EBADF. That means we have succeeded. */
3451 if (rtnval
== -1 && did_retry
&& errno
== EBADF
)
3458 emacs_read (fildes
, buf
, nbyte
)
3463 register int rtnval
;
3465 while ((rtnval
= read (fildes
, buf
, nbyte
)) == -1
3466 && (errno
== EINTR
))
3472 emacs_write (fildes
, buf
, nbyte
)
3477 register int rtnval
, bytes_written
;
3483 rtnval
= write (fildes
, buf
, nbyte
);
3490 /* I originally used `QUIT' but that might causes files to
3491 be truncated if you hit C-g in the middle of it. --Stef */
3492 if (interrupt_input_pending
)
3493 handle_async_input ();
3498 return (bytes_written
? bytes_written
: -1);
3503 bytes_written
+= rtnval
;
3505 return (bytes_written
);
3510 * All of the following are for USG.
3512 * On USG systems the system calls are INTERRUPTIBLE by signals
3513 * that the user program has elected to catch. Thus the system call
3514 * must be retried in these cases. To handle this without massive
3515 * changes in the source code, we remap the standard system call names
3516 * to names for our own functions in sysdep.c that do the system call
3517 * with retries. Actually, for portability reasons, it is good
3518 * programming practice, as this example shows, to limit all actual
3519 * system calls to a single occurrence in the source. Sure, this
3520 * adds an extra level of function call overhead but it is almost
3521 * always negligible. Fred Fish, Unisoft Systems Inc.
3525 * Warning, this function may not duplicate 4.2 action properly
3526 * under error conditions.
3530 /* In 4.1, param.h fails to define this. */
3531 #define MAXPATHLEN 1024
3540 char *npath
, *spath
;
3541 extern char *getcwd ();
3543 BLOCK_INPUT
; /* getcwd uses malloc */
3544 spath
= npath
= getcwd ((char *) 0, MAXPATHLEN
);
3550 /* On Altos 3068, getcwd can return @hostname/dir, so discard
3551 up to first slash. Should be harmless on other systems. */
3552 while (*npath
&& *npath
!= '/')
3554 strcpy (pathname
, npath
);
3555 free (spath
); /* getcwd uses malloc */
3560 #endif /* HAVE_GETWD */
3563 * Emulate rename using unlink/link. Note that this is
3564 * only partially correct. Also, doesn't enforce restriction
3565 * that files be of same type (regular->regular, dir->dir, etc).
3574 if (access (from
, 0) == 0)
3577 if (link (from
, to
) == 0)
3578 if (unlink (from
) == 0)
3590 /* HPUX curses library references perror, but as far as we know
3591 it won't be called. Anyway this definition will do for now. */
3597 #endif /* not HAVE_PERROR */
3603 * Emulate BSD dup2. First close newd if it already exists.
3604 * Then, attempt to dup oldd. If not successful, call dup2 recursively
3605 * until we are, then close the unsuccessful ones.
3612 register int fd
, ret
;
3617 return fcntl (oldd
, F_DUPFD
, newd
);
3624 ret
= dup2 (old
,new);
3630 #endif /* not HAVE_DUP2 */
3633 * Gettimeofday. Simulate as much as possible. Only accurate
3634 * to nearest second. Emacs doesn't use tzp so ignore it for now.
3635 * Only needed when subprocesses are defined.
3640 #ifndef HAVE_GETTIMEOFDAY
3645 gettimeofday (tp
, tzp
)
3647 struct timezone
*tzp
;
3649 extern long time ();
3651 tp
->tv_sec
= time ((long *)0);
3654 tzp
->tz_minuteswest
= -1;
3661 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
3664 * This function will go away as soon as all the stubs fixed. (fnf)
3671 printf ("%s not yet implemented\r\n", badfunc
);
3672 reset_all_sys_modes ();
3678 /* Directory routines for systems that don't have them. */
3680 #ifdef SYSV_SYSTEM_DIR
3684 #if defined (BROKEN_CLOSEDIR) || !defined (HAVE_CLOSEDIR)
3688 register DIR *dirp
; /* stream from opendir */
3692 rtnval
= emacs_close (dirp
->dd_fd
);
3694 /* Some systems (like Solaris) allocate the buffer and the DIR all
3695 in one block. Why in the world are we freeing this ourselves
3697 #if ! (defined (sun) && defined (USG5_4))
3698 xfree ((char *) dirp
->dd_buf
); /* directory block defined in <dirent.h> */
3700 xfree ((char *) dirp
);
3704 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
3705 #endif /* SYSV_SYSTEM_DIR */
3707 #ifdef NONSYSTEM_DIR_LIBRARY
3711 char *filename
; /* name of directory */
3713 register DIR *dirp
; /* -> malloc'ed storage */
3714 register int fd
; /* file descriptor for read */
3715 struct stat sbuf
; /* result of fstat */
3717 fd
= emacs_open (filename
, O_RDONLY
, 0);
3722 if (fstat (fd
, &sbuf
) < 0
3723 || (sbuf
.st_mode
& S_IFMT
) != S_IFDIR
3724 || (dirp
= (DIR *) xmalloc (sizeof (DIR))) == 0)
3728 return 0; /* bad luck today */
3733 dirp
->dd_loc
= dirp
->dd_size
= 0; /* refill needed */
3740 register DIR *dirp
; /* stream from opendir */
3742 emacs_close (dirp
->dd_fd
);
3743 xfree ((char *) dirp
);
3751 ino_t od_ino
; /* inode */
3752 char od_name
[DIRSIZ
]; /* filename */
3754 #endif /* not VMS */
3756 struct direct dir_static
; /* simulated directory contents */
3761 register DIR *dirp
; /* stream from opendir */
3764 register struct olddir
*dp
; /* -> directory data */
3766 register struct dir$_name
*dp
; /* -> directory data */
3767 register struct dir$_version
*dv
; /* -> version data */
3772 if (dirp
->dd_loc
>= dirp
->dd_size
)
3773 dirp
->dd_loc
= dirp
->dd_size
= 0;
3775 if (dirp
->dd_size
== 0 /* refill buffer */
3776 && (dirp
->dd_size
= emacs_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3780 dp
= (struct olddir
*) &dirp
->dd_buf
[dirp
->dd_loc
];
3781 dirp
->dd_loc
+= sizeof (struct olddir
);
3783 if (dp
->od_ino
!= 0) /* not deleted entry */
3785 dir_static
.d_ino
= dp
->od_ino
;
3786 strncpy (dir_static
.d_name
, dp
->od_name
, DIRSIZ
);
3787 dir_static
.d_name
[DIRSIZ
] = '\0';
3788 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3789 dir_static
.d_reclen
= sizeof (struct direct
)
3791 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3792 return &dir_static
; /* -> simulated structure */
3795 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3796 if (dirp
->dd_loc
== 0)
3797 dirp
->dd_loc
= (dp
->dir$b_namecount
&1) ? dp
->dir$b_namecount
+ 1
3798 : dp
->dir$b_namecount
;
3799 dv
= (struct dir$_version
*)&dp
->dir$t_name
[dirp
->dd_loc
];
3800 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3801 dir_static
.d_namlen
= dp
->dir$b_namecount
;
3802 dir_static
.d_reclen
= sizeof (struct direct
)
3804 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3805 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3806 dir_static
.d_name
[dir_static
.d_namlen
] = '\0';
3807 dirp
->dd_loc
= dirp
->dd_size
; /* only one record at a time */
3814 /* readdirver is just like readdir except it returns all versions of a file
3815 as separate entries. */
3820 register DIR *dirp
; /* stream from opendir */
3822 register struct dir$_name
*dp
; /* -> directory data */
3823 register struct dir$_version
*dv
; /* -> version data */
3825 if (dirp
->dd_loc
>= dirp
->dd_size
- sizeof (struct dir$_name
))
3826 dirp
->dd_loc
= dirp
->dd_size
= 0;
3828 if (dirp
->dd_size
== 0 /* refill buffer */
3829 && (dirp
->dd_size
= sys_read (dirp
->dd_fd
, dirp
->dd_buf
, DIRBLKSIZ
)) <= 0)
3832 dp
= (struct dir$_name
*) dirp
->dd_buf
;
3833 if (dirp
->dd_loc
== 0)
3834 dirp
->dd_loc
= (dp
->dir$b_namecount
& 1) ? dp
->dir$b_namecount
+ 1
3835 : dp
->dir$b_namecount
;
3836 dv
= (struct dir$_version
*) &dp
->dir$t_name
[dirp
->dd_loc
];
3837 strncpy (dir_static
.d_name
, dp
->dir$t_name
, dp
->dir$b_namecount
);
3838 sprintf (&dir_static
.d_name
[dp
->dir$b_namecount
], ";%d", dv
->dir$w_version
);
3839 dir_static
.d_namlen
= strlen (dir_static
.d_name
);
3840 dir_static
.d_ino
= dv
->dir$w_fid_num
;
3841 dir_static
.d_reclen
= sizeof (struct direct
) - MAXNAMLEN
+ 3
3842 + dir_static
.d_namlen
- dir_static
.d_namlen
% 4;
3843 dirp
->dd_loc
= ((char *) (++dv
) - dp
->dir$t_name
);
3849 #endif /* NONSYSTEM_DIR_LIBRARY */
3853 set_file_times (filename
, atime
, mtime
)
3854 const char *filename
;
3855 EMACS_TIME atime
, mtime
;
3858 struct timeval tv
[2];
3861 return utimes (filename
, tv
);
3862 #else /* not HAVE_UTIMES */
3864 utb
.actime
= EMACS_SECS (atime
);
3865 utb
.modtime
= EMACS_SECS (mtime
);
3866 return utime (filename
, &utb
);
3867 #endif /* not HAVE_UTIMES */
3870 /* mkdir and rmdir functions, for systems which don't have them. */
3874 * Written by Robert Rother, Mariah Corporation, August 1985.
3876 * If you want it, it's yours. All I ask in return is that if you
3877 * figure out how to do this in a Bourne Shell script you send me
3879 * sdcsvax!rmr or rmr@uscd
3881 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
3882 * subroutine. 11Mar86; hoptoad!gnu
3884 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
3885 * subroutine didn't return EEXIST. It does now.
3891 #ifdef MKDIR_PROTOTYPE
3895 mkdir (dpath
, dmode
)
3900 int cpid
, status
, fd
;
3901 struct stat statbuf
;
3903 if (stat (dpath
, &statbuf
) == 0)
3905 errno
= EEXIST
; /* Stat worked, so it already exists */
3909 /* If stat fails for a reason other than non-existence, return error */
3910 if (errno
!= ENOENT
)
3913 synch_process_alive
= 1;
3914 switch (cpid
= fork ())
3917 case -1: /* Error in fork */
3918 return (-1); /* Errno is set already */
3920 case 0: /* Child process */
3922 * Cheap hack to set mode of new directory. Since this
3923 * child process is going away anyway, we zap its umask.
3924 * FIXME, this won't suffice to set SUID, SGID, etc. on this
3925 * directory. Does anybody care?
3927 status
= umask (0); /* Get current umask */
3928 status
= umask (status
| (0777 & ~dmode
)); /* Set for mkdir */
3929 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3936 execl ("/bin/mkdir", "mkdir", dpath
, (char *) 0);
3937 _exit (-1); /* Can't exec /bin/mkdir */
3939 default: /* Parent process */
3940 wait_for_termination (cpid
);
3943 if (synch_process_death
!= 0 || synch_process_retcode
!= 0
3944 || synch_process_termsig
!= 0)
3946 errno
= EIO
; /* We don't know why, but */
3947 return -1; /* /bin/mkdir failed */
3952 #endif /* not HAVE_MKDIR */
3959 int cpid
, status
, fd
;
3960 struct stat statbuf
;
3962 if (stat (dpath
, &statbuf
) != 0)
3964 /* Stat just set errno. We don't have to */
3968 synch_process_alive
= 1;
3969 switch (cpid
= fork ())
3972 case -1: /* Error in fork */
3973 return (-1); /* Errno is set already */
3975 case 0: /* Child process */
3976 fd
= emacs_open ("/dev/null", O_RDWR
, 0);
3983 execl ("/bin/rmdir", "rmdir", dpath
, (char *) 0);
3984 _exit (-1); /* Can't exec /bin/rmdir */
3986 default: /* Parent process */
3987 wait_for_termination (cpid
);
3990 if (synch_process_death
!= 0 || synch_process_retcode
!= 0
3991 || synch_process_termsig
!= 0)
3993 errno
= EIO
; /* We don't know why, but */
3994 return -1; /* /bin/rmdir failed */
3999 #endif /* !HAVE_RMDIR */
4003 /* Functions for VMS */
4009 /* Return as a string the VMS error string pertaining to STATUS.
4010 Reuses the same static buffer each time it is called. */
4014 int status
; /* VMS status code */
4018 static char buf
[257];
4020 bufadr
[0] = sizeof buf
- 1;
4021 bufadr
[1] = (int) buf
;
4022 if (! (SYS$
GETMSG (status
, &len
, bufadr
, 0x1, 0) & 1))
4023 return "untranslatable VMS error status";
4031 /* The following is necessary because 'access' emulation by VMS C (2.0) does
4032 * not work correctly. (It also doesn't work well in version 2.3.)
4037 #define DESCRIPTOR(name,string) struct dsc$descriptor_s name = \
4038 { strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
4042 unsigned short s_buflen
;
4043 unsigned short s_code
;
4045 unsigned short *s_retlenadr
;
4049 #define buflen s.s_buflen
4050 #define code s.s_code
4051 #define bufadr s.s_bufadr
4052 #define retlenadr s.s_retlenadr
4054 #define R_OK 4 /* test for read permission */
4055 #define W_OK 2 /* test for write permission */
4056 #define X_OK 1 /* test for execute (search) permission */
4057 #define F_OK 0 /* test for presence of file */
4060 sys_access (path
, mode
)
4064 static char *user
= NULL
;
4067 /* translate possible directory spec into .DIR file name, so brain-dead
4068 * access can treat the directory like a file. */
4069 if (directory_file_name (path
, dir_fn
))
4073 return access (path
, mode
);
4074 if (user
== NULL
&& (user
= (char *) getenv ("USER")) == NULL
)
4080 unsigned short int dummy
;
4082 static int constant
= ACL$C_FILE
;
4083 DESCRIPTOR (path_desc
, path
);
4084 DESCRIPTOR (user_desc
, user
);
4088 if ((mode
& X_OK
) && ((stat
= access (path
, mode
)) < 0 || mode
== X_OK
))
4091 acces
|= CHP$M_READ
;
4093 acces
|= CHP$M_WRITE
;
4094 itemlst
[0].buflen
= sizeof (int);
4095 itemlst
[0].code
= CHP$_FLAGS
;
4096 itemlst
[0].bufadr
= (char *) &flags
;
4097 itemlst
[0].retlenadr
= &dummy
;
4098 itemlst
[1].buflen
= sizeof (int);
4099 itemlst
[1].code
= CHP$_ACCESS
;
4100 itemlst
[1].bufadr
= (char *) &acces
;
4101 itemlst
[1].retlenadr
= &dummy
;
4102 itemlst
[2].end
= CHP$_END
;
4103 stat
= SYS$
CHECK_ACCESS (&constant
, &path_desc
, &user_desc
, itemlst
);
4104 return stat
== SS$_NORMAL
? 0 : -1;
4108 #else /* not VMS4_4 */
4111 #define ACE$M_WRITE 2
4112 #define ACE$C_KEYID 1
4114 static unsigned short memid
, grpid
;
4115 static unsigned int uic
;
4117 /* Called from init_sys_modes, so it happens not very often
4118 but at least each time Emacs is loaded. */
4120 sys_access_reinit ()
4126 sys_access (filename
, type
)
4132 int status
, size
, i
, typecode
, acl_controlled
;
4133 unsigned int *aclptr
, *aclend
, aclbuf
[60];
4134 union prvdef prvmask
;
4136 /* Get UIC and GRP values for protection checking. */
4139 status
= LIB$
GETJPI (&JPI$_UIC
, 0, 0, &uic
, 0, 0);
4142 memid
= uic
& 0xFFFF;
4146 if (type
!= 2) /* not checking write access */
4147 return access (filename
, type
);
4149 /* Check write protection. */
4151 #define CHECKPRIV(bit) (prvmask.bit)
4152 #define WRITABLE(field) (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
4154 /* Find privilege bits */
4155 status
= SYS$
SETPRV (0, 0, 0, prvmask
);
4157 error ("Unable to find privileges: %s", vmserrstr (status
));
4158 if (CHECKPRIV (PRV$V_BYPASS
))
4159 return 0; /* BYPASS enabled */
4161 fab
.fab$b_fac
= FAB$M_GET
;
4162 fab
.fab$l_fna
= filename
;
4163 fab
.fab$b_fns
= strlen (filename
);
4164 fab
.fab$l_xab
= &xab
;
4165 xab
= cc$rms_xabpro
;
4166 xab
.xab$l_aclbuf
= aclbuf
;
4167 xab
.xab$w_aclsiz
= sizeof (aclbuf
);
4168 status
= SYS$
OPEN (&fab
, 0, 0);
4171 SYS$
CLOSE (&fab
, 0, 0);
4172 /* Check system access */
4173 if (CHECKPRIV (PRV$V_SYSPRV
) && WRITABLE (XAB$V_SYS
))
4175 /* Check ACL entries, if any */
4177 if (xab
.xab$w_acllen
> 0)
4180 aclend
= &aclbuf
[xab
.xab$w_acllen
/ 4];
4181 while (*aclptr
&& aclptr
< aclend
)
4183 size
= (*aclptr
& 0xff) / 4;
4184 typecode
= (*aclptr
>> 8) & 0xff;
4185 if (typecode
== ACE$C_KEYID
)
4186 for (i
= size
- 1; i
> 1; i
--)
4187 if (aclptr
[i
] == uic
)
4190 if (aclptr
[1] & ACE$M_WRITE
)
4191 return 0; /* Write access through ACL */
4193 aclptr
= &aclptr
[size
];
4195 if (acl_controlled
) /* ACL specified, prohibits write access */
4198 /* No ACL entries specified, check normal protection */
4199 if (WRITABLE (XAB$V_WLD
)) /* World writable */
4201 if (WRITABLE (XAB$V_GRP
) &&
4202 (unsigned short) (xab
.xab$l_uic
>> 16) == grpid
)
4203 return 0; /* Group writable */
4204 if (WRITABLE (XAB$V_OWN
) &&
4205 (xab
.xab$l_uic
& 0xFFFF) == memid
)
4206 return 0; /* Owner writable */
4208 return -1; /* Not writable */
4210 #endif /* not VMS4_4 */
4213 static char vtbuf
[NAM$C_MAXRSS
+1];
4215 /* translate a vms file spec to a unix path */
4217 sys_translate_vms (vfile
)
4228 /* leading device or logical name is a root directory */
4229 if (p
= strchr (vfile
, ':'))
4238 if (*p
== '[' || *p
== '<')
4240 while (*++vfile
!= *p
+ 2)
4244 if (vfile
[-1] == *p
)
4267 static char utbuf
[NAM$C_MAXRSS
+1];
4269 /* translate a unix path to a VMS file spec */
4271 sys_translate_unix (ufile
)
4294 if (index (&ufile
[1], '/'))
4301 if (index (&ufile
[1], '/'))
4308 if (strncmp (ufile
, "./", 2) == 0)
4315 ufile
++; /* skip the dot */
4316 if (index (&ufile
[1], '/'))
4321 else if (strncmp (ufile
, "../", 3) == 0)
4329 ufile
+= 2; /* skip the dots */
4330 if (index (&ufile
[1], '/'))
4355 extern char *getcwd ();
4357 #define MAXPATHLEN 1024
4359 ptr
= xmalloc (MAXPATHLEN
);
4360 val
= getcwd (ptr
, MAXPATHLEN
);
4366 strcpy (pathname
, ptr
);
4375 long item_code
= JPI$_OWNER
;
4376 unsigned long parent_id
;
4379 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &parent_id
)) & 1) == 0)
4382 vaxc$errno
= status
;
4392 return (getgid () << 16) | getuid ();
4397 sys_read (fildes
, buf
, nbyte
)
4402 return read (fildes
, buf
, (nbyte
< MAXIOSIZE
? nbyte
: MAXIOSIZE
));
4407 sys_write (fildes
, buf
, nbyte
)
4412 register int nwrote
, rtnval
= 0;
4414 while (nbyte
> MAXIOSIZE
&& (nwrote
= write (fildes
, buf
, MAXIOSIZE
)) > 0) {
4420 return rtnval
? rtnval
: -1;
4421 if ((nwrote
= write (fildes
, buf
, nbyte
)) < 0)
4422 return rtnval
? rtnval
: -1;
4423 return (rtnval
+ nwrote
);
4428 * VAX/VMS VAX C RTL really loses. It insists that records
4429 * end with a newline (carriage return) character, and if they
4430 * don't it adds one (nice of it isn't it!)
4432 * Thus we do this stupidity below.
4437 sys_write (fildes
, buf
, nbytes
)
4440 unsigned int nbytes
;
4447 fstat (fildes
, &st
);
4453 /* Handle fixed-length files with carriage control. */
4454 if (st
.st_fab_rfm
== FAB$C_FIX
4455 && ((st
.st_fab_rat
& (FAB$M_FTN
| FAB$M_CR
)) != 0))
4457 len
= st
.st_fab_mrs
;
4458 retval
= write (fildes
, p
, min (len
, nbytes
));
4461 retval
++; /* This skips the implied carriage control */
4465 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4466 while (*e
!= '\n' && e
> p
) e
--;
4467 if (p
== e
) /* Ok.. so here we add a newline... sigh. */
4468 e
= p
+ min (MAXIOSIZE
, nbytes
) - 1;
4470 retval
= write (fildes
, p
, len
);
4481 /* Create file NEW copying its attributes from file OLD. If
4482 OLD is 0 or does not exist, create based on the value of
4485 /* Protection value the file should ultimately have.
4486 Set by create_copy_attrs, and use by rename_sansversions. */
4487 static unsigned short int fab_final_pro
;
4490 creat_copy_attrs (old
, new)
4493 struct FAB fab
= cc$rms_fab
;
4494 struct XABPRO xabpro
;
4495 char aclbuf
[256]; /* Choice of size is arbitrary. See below. */
4496 extern int vms_stmlf_recfm
;
4500 fab
.fab$b_fac
= FAB$M_GET
;
4501 fab
.fab$l_fna
= old
;
4502 fab
.fab$b_fns
= strlen (old
);
4503 fab
.fab$l_xab
= (char *) &xabpro
;
4504 xabpro
= cc$rms_xabpro
;
4505 xabpro
.xab$l_aclbuf
= aclbuf
;
4506 xabpro
.xab$w_aclsiz
= sizeof aclbuf
;
4507 /* Call $OPEN to fill in the fab & xabpro fields. */
4508 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4510 SYS$
CLOSE (&fab
, 0, 0);
4511 fab
.fab$l_alq
= 0; /* zero the allocation quantity */
4512 if (xabpro
.xab$w_acllen
> 0)
4514 if (xabpro
.xab$w_acllen
> sizeof aclbuf
)
4515 /* If the acl buffer was too short, redo open with longer one.
4516 Wouldn't need to do this if there were some system imposed
4517 limit on the size of an ACL, but I can't find any such. */
4519 xabpro
.xab$l_aclbuf
= (char *) alloca (xabpro
.xab$w_acllen
);
4520 xabpro
.xab$w_aclsiz
= xabpro
.xab$w_acllen
;
4521 if (SYS$
OPEN (&fab
, 0, 0) & 1)
4522 SYS$
CLOSE (&fab
, 0, 0);
4528 xabpro
.xab$l_aclbuf
= 0;
4533 fab
.fab$l_fna
= new;
4534 fab
.fab$b_fns
= strlen (new);
4538 fab
.fab$b_rfm
= vms_stmlf_recfm
? FAB$C_STMLF
: FAB$C_VAR
;
4539 fab
.fab$b_rat
= FAB$M_CR
;
4542 /* Set the file protections such that we will be able to manipulate
4543 this file. Once we are done writing and renaming it, we will set
4544 the protections back. */
4546 fab_final_pro
= xabpro
.xab$w_pro
;
4548 SYS$
SETDFPROT (0, &fab_final_pro
);
4549 xabpro
.xab$w_pro
&= 0xff0f; /* set O:rewd for now. This is set back later. */
4551 /* Create the new file with either default attrs or attrs copied
4553 if (!(SYS$
CREATE (&fab
, 0, 0) & 1))
4555 SYS$
CLOSE (&fab
, 0, 0);
4556 /* As this is a "replacement" for creat, return a file descriptor
4557 opened for writing. */
4558 return open (new, O_WRONLY
);
4563 #include <varargs.h>
4566 #define va_count(X) ((X) = *(((int *) &(va_alist)) - 1))
4571 sys_creat (va_alist
)
4574 va_list list_incrementer
;
4577 int rfd
; /* related file descriptor */
4578 int fd
; /* Our new file descriptor */
4585 extern int vms_stmlf_recfm
;
4588 va_start (list_incrementer
);
4589 name
= va_arg (list_incrementer
, char *);
4590 mode
= va_arg (list_incrementer
, int);
4592 rfd
= va_arg (list_incrementer
, int);
4593 va_end (list_incrementer
);
4596 /* Use information from the related file descriptor to set record
4597 format of the newly created file. */
4598 fstat (rfd
, &st_buf
);
4599 switch (st_buf
.st_fab_rfm
)
4602 strcpy (rfm
, "rfm = fix");
4603 sprintf (mrs
, "mrs = %d", st_buf
.st_fab_mrs
);
4604 strcpy (rat
, "rat = ");
4605 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4607 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4608 strcat (rat
, "ftn");
4609 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4610 strcat (rat
, "prn");
4611 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4612 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4613 strcat (rat
, ", blk");
4615 strcat (rat
, "blk");
4616 return creat (name
, 0, rfm
, rat
, mrs
);
4619 strcpy (rfm
, "rfm = vfc");
4620 sprintf (fsz
, "fsz = %d", st_buf
.st_fab_fsz
);
4621 strcpy (rat
, "rat = ");
4622 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4624 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4625 strcat (rat
, "ftn");
4626 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4627 strcat (rat
, "prn");
4628 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4629 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4630 strcat (rat
, ", blk");
4632 strcat (rat
, "blk");
4633 return creat (name
, 0, rfm
, rat
, fsz
);
4636 strcpy (rfm
, "rfm = stm");
4640 strcpy (rfm
, "rfm = stmcr");
4644 strcpy (rfm
, "rfm = stmlf");
4648 strcpy (rfm
, "rfm = udf");
4652 strcpy (rfm
, "rfm = var");
4655 strcpy (rat
, "rat = ");
4656 if (st_buf
.st_fab_rat
& FAB$M_CR
)
4658 else if (st_buf
.st_fab_rat
& FAB$M_FTN
)
4659 strcat (rat
, "ftn");
4660 else if (st_buf
.st_fab_rat
& FAB$M_PRN
)
4661 strcat (rat
, "prn");
4662 if (st_buf
.st_fab_rat
& FAB$M_BLK
)
4663 if (st_buf
.st_fab_rat
& (FAB$M_CR
|FAB$M_FTN
|FAB$M_PRN
))
4664 strcat (rat
, ", blk");
4666 strcat (rat
, "blk");
4670 strcpy (rfm
, vms_stmlf_recfm
? "rfm = stmlf" : "rfm=var");
4671 strcpy (rat
, "rat=cr");
4673 /* Until the VAX C RTL fixes the many bugs with modes, always use
4674 mode 0 to get the user's default protection. */
4675 fd
= creat (name
, 0, rfm
, rat
);
4676 if (fd
< 0 && errno
== EEXIST
)
4678 if (unlink (name
) < 0)
4679 report_file_error ("delete", build_string (name
));
4680 fd
= creat (name
, 0, rfm
, rat
);
4686 /* fwrite to stdout is S L O W. Speed it up by using fputc...*/
4688 sys_fwrite (ptr
, size
, num
, fp
)
4689 register char * ptr
;
4692 register int tot
= num
* size
;
4700 * The VMS C library routine creat actually creates a new version of an
4701 * existing file rather than truncating the old version. There are times
4702 * when this is not the desired behavior, for instance, when writing an
4703 * auto save file (you only want one version), or when you don't have
4704 * write permission in the directory containing the file (but the file
4705 * itself is writable). Hence this routine, which is equivalent to
4706 * "close (creat (fn, 0));" on Unix if fn already exists.
4712 struct FAB xfab
= cc$rms_fab
;
4713 struct RAB xrab
= cc$rms_rab
;
4716 xfab
.fab$l_fop
= FAB$M_TEF
; /* free allocated but unused blocks on close */
4717 xfab
.fab$b_fac
= FAB$M_TRN
| FAB$M_GET
; /* allow truncate and get access */
4718 xfab
.fab$b_shr
= FAB$M_NIL
; /* allow no sharing - file must be locked */
4719 xfab
.fab$l_fna
= fn
;
4720 xfab
.fab$b_fns
= strlen (fn
);
4721 xfab
.fab$l_dna
= ";0"; /* default to latest version of the file */
4723 xrab
.rab$l_fab
= &xfab
;
4725 /* This gibberish opens the file, positions to the first record, and
4726 deletes all records from there until the end of file. */
4727 if ((SYS$
OPEN (&xfab
) & 01) == 01)
4729 if ((SYS$
CONNECT (&xrab
) & 01) == 01 &&
4730 (SYS$
FIND (&xrab
) & 01) == 01 &&
4731 (SYS$
TRUNCATE (&xrab
) & 01) == 01)
4742 /* Define this symbol to actually read SYSUAF.DAT. This requires either
4743 SYSPRV or a readable SYSUAF.DAT. */
4749 * Routine to read the VMS User Authorization File and return
4750 * a specific user's record.
4753 static struct UAF retuaf
;
4756 get_uaf_name (uname
)
4763 uaf_fab
= cc$rms_fab
;
4764 uaf_rab
= cc$rms_rab
;
4765 /* initialize fab fields */
4766 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4767 uaf_fab
.fab$b_fns
= 21;
4768 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4769 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4770 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4771 /* initialize rab fields */
4772 uaf_rab
.rab$l_fab
= &uaf_fab
;
4773 /* open the User Authorization File */
4774 status
= SYS$
OPEN (&uaf_fab
);
4778 vaxc$errno
= status
;
4781 status
= SYS$
CONNECT (&uaf_rab
);
4785 vaxc$errno
= status
;
4788 /* read the requested record - index is in uname */
4789 uaf_rab
.rab$l_kbf
= uname
;
4790 uaf_rab
.rab$b_ksz
= strlen (uname
);
4791 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4792 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4793 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4794 status
= SYS$
GET (&uaf_rab
);
4798 vaxc$errno
= status
;
4801 /* close the User Authorization File */
4802 status
= SYS$
DISCONNECT (&uaf_rab
);
4806 vaxc$errno
= status
;
4809 status
= SYS$
CLOSE (&uaf_fab
);
4813 vaxc$errno
= status
;
4827 uaf_fab
= cc$rms_fab
;
4828 uaf_rab
= cc$rms_rab
;
4829 /* initialize fab fields */
4830 uaf_fab
.fab$l_fna
= "SYS$SYSTEM:SYSUAF.DAT";
4831 uaf_fab
.fab$b_fns
= 21;
4832 uaf_fab
.fab$b_fac
= FAB$M_GET
;
4833 uaf_fab
.fab$b_org
= FAB$C_IDX
;
4834 uaf_fab
.fab$b_shr
= FAB$M_GET
|FAB$M_PUT
|FAB$M_UPD
|FAB$M_DEL
;
4835 /* initialize rab fields */
4836 uaf_rab
.rab$l_fab
= &uaf_fab
;
4837 /* open the User Authorization File */
4838 status
= SYS$
OPEN (&uaf_fab
);
4842 vaxc$errno
= status
;
4845 status
= SYS$
CONNECT (&uaf_rab
);
4849 vaxc$errno
= status
;
4852 /* read the requested record - index is in uic */
4853 uaf_rab
.rab$b_krf
= 1; /* 1st alternate key */
4854 uaf_rab
.rab$l_kbf
= (char *) &uic
;
4855 uaf_rab
.rab$b_ksz
= sizeof uic
;
4856 uaf_rab
.rab$b_rac
= RAB$C_KEY
;
4857 uaf_rab
.rab$l_ubf
= (char *)&retuaf
;
4858 uaf_rab
.rab$w_usz
= sizeof retuaf
;
4859 status
= SYS$
GET (&uaf_rab
);
4863 vaxc$errno
= status
;
4866 /* close the User Authorization File */
4867 status
= SYS$
DISCONNECT (&uaf_rab
);
4871 vaxc$errno
= status
;
4874 status
= SYS$
CLOSE (&uaf_fab
);
4878 vaxc$errno
= status
;
4884 static struct passwd retpw
;
4892 /* copy these out first because if the username is 32 chars, the next
4893 section will overwrite the first byte of the UIC */
4894 retpw
.pw_uid
= up
->uaf$w_mem
;
4895 retpw
.pw_gid
= up
->uaf$w_grp
;
4897 /* I suppose this is not the best style, to possibly overwrite one
4898 byte beyond the end of the field, but what the heck... */
4899 ptr
= &up
->uaf$t_username
[UAF$S_USERNAME
];
4900 while (ptr
[-1] == ' ')
4903 strcpy (retpw
.pw_name
, up
->uaf$t_username
);
4905 /* the rest of these are counted ascii strings */
4906 strncpy (retpw
.pw_gecos
, &up
->uaf$t_owner
[1], up
->uaf$t_owner
[0]);
4907 retpw
.pw_gecos
[up
->uaf$t_owner
[0]] = '\0';
4908 strncpy (retpw
.pw_dir
, &up
->uaf$t_defdev
[1], up
->uaf$t_defdev
[0]);
4909 retpw
.pw_dir
[up
->uaf$t_defdev
[0]] = '\0';
4910 strncat (retpw
.pw_dir
, &up
->uaf$t_defdir
[1], up
->uaf$t_defdir
[0]);
4911 retpw
.pw_dir
[up
->uaf$t_defdev
[0] + up
->uaf$t_defdir
[0]] = '\0';
4912 strncpy (retpw
.pw_shell
, &up
->uaf$t_defcli
[1], up
->uaf$t_defcli
[0]);
4913 retpw
.pw_shell
[up
->uaf$t_defcli
[0]] = '\0';
4917 #else /* not READ_SYSUAF */
4918 static struct passwd retpw
;
4919 #endif /* not READ_SYSUAF */
4930 unsigned char * full
;
4931 #endif /* READ_SYSUAF */
4936 if ('a' <= *ptr
&& *ptr
<= 'z')
4941 if (!(up
= get_uaf_name (name
)))
4943 return cnv_uaf_pw (up
);
4945 if (strcmp (name
, getenv ("USER")) == 0)
4947 retpw
.pw_uid
= getuid ();
4948 retpw
.pw_gid
= getgid ();
4949 strcpy (retpw
.pw_name
, name
);
4950 if (full
= egetenv ("FULLNAME"))
4951 strcpy (retpw
.pw_gecos
, full
);
4953 *retpw
.pw_gecos
= '\0';
4954 strcpy (retpw
.pw_dir
, egetenv ("HOME"));
4955 *retpw
.pw_shell
= '\0';
4960 #endif /* not READ_SYSUAF */
4970 if (!(up
= get_uaf_uic (uid
)))
4972 return cnv_uaf_pw (up
);
4974 if (uid
== sys_getuid ())
4975 return getpwnam (egetenv ("USER"));
4978 #endif /* not READ_SYSUAF */
4981 /* return total address space available to the current process. This is
4982 the sum of the current p0 size, p1 size and free page table entries
4988 unsigned long free_pages
;
4989 unsigned long frep0va
;
4990 unsigned long frep1va
;
4993 item_code
= JPI$_FREPTECNT
;
4994 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &free_pages
)) & 1) == 0)
4997 vaxc$errno
= status
;
5002 item_code
= JPI$_FREP0VA
;
5003 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep0va
)) & 1) == 0)
5006 vaxc$errno
= status
;
5009 item_code
= JPI$_FREP1VA
;
5010 if (((status
= LIB$
GETJPI (&item_code
, 0, 0, &frep1va
)) & 1) == 0)
5013 vaxc$errno
= status
;
5017 return free_pages
+ frep0va
+ (0x7fffffff - frep1va
);
5021 define_logical_name (varname
, string
)
5025 struct dsc$descriptor_s strdsc
=
5026 {strlen (string
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, string
};
5027 struct dsc$descriptor_s envdsc
=
5028 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
5029 struct dsc$descriptor_s lnmdsc
=
5030 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
5032 return LIB$
SET_LOGICAL (&envdsc
, &strdsc
, &lnmdsc
, 0, 0);
5036 delete_logical_name (varname
)
5039 struct dsc$descriptor_s envdsc
=
5040 {strlen (varname
), DSC$K_DTYPE_T
, DSC$K_CLASS_S
, varname
};
5041 struct dsc$descriptor_s lnmdsc
=
5042 {7, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, "LNM$JOB"};
5044 return LIB$
DELETE_LOGICAL (&envdsc
, &lnmdsc
);
5062 error ("execvp system call not implemented");
5071 struct FAB from_fab
= cc$rms_fab
, to_fab
= cc$rms_fab
;
5072 struct NAM from_nam
= cc$rms_nam
, to_nam
= cc$rms_nam
;
5073 char from_esn
[NAM$C_MAXRSS
];
5074 char to_esn
[NAM$C_MAXRSS
];
5076 from_fab
.fab$l_fna
= from
;
5077 from_fab
.fab$b_fns
= strlen (from
);
5078 from_fab
.fab$l_nam
= &from_nam
;
5079 from_fab
.fab$l_fop
= FAB$M_NAM
;
5081 from_nam
.nam$l_esa
= from_esn
;
5082 from_nam
.nam$b_ess
= sizeof from_esn
;
5084 to_fab
.fab$l_fna
= to
;
5085 to_fab
.fab$b_fns
= strlen (to
);
5086 to_fab
.fab$l_nam
= &to_nam
;
5087 to_fab
.fab$l_fop
= FAB$M_NAM
;
5089 to_nam
.nam$l_esa
= to_esn
;
5090 to_nam
.nam$b_ess
= sizeof to_esn
;
5092 status
= SYS$
RENAME (&from_fab
, 0, 0, &to_fab
);
5098 if (status
== RMS$_DEV
)
5102 vaxc$errno
= status
;
5107 /* This function renames a file like `rename', but it strips
5108 the version number from the "to" filename, such that the "to" file is
5109 will always be a new version. It also sets the file protection once it is
5110 finished. The protection that we will use is stored in fab_final_pro,
5111 and was set when we did a creat_copy_attrs to create the file that we
5114 We could use the chmod function, but Eunichs uses 3 bits per user category
5115 to describe the protection, and VMS uses 4 (write and delete are separate
5116 bits). To maintain portability, the VMS implementation of `chmod' wires
5117 the W and D bits together. */
5120 static struct fibdef fib
; /* We need this initialized to zero */
5121 char vms_file_written
[NAM$C_MAXRSS
];
5124 rename_sans_version (from
,to
)
5131 struct FAB to_fab
= cc$rms_fab
;
5132 struct NAM to_nam
= cc$rms_nam
;
5133 struct dsc$descriptor fib_d
={sizeof (fib
),0,0,(char*) &fib
};
5134 struct dsc$descriptor fib_attr
[2]
5135 = {{sizeof (fab_final_pro
),ATR$C_FPRO
,0,(char*) &fab_final_pro
},{0,0,0,0}};
5136 char to_esn
[NAM$C_MAXRSS
];
5138 $
DESCRIPTOR (disk
,to_esn
);
5140 to_fab
.fab$l_fna
= to
;
5141 to_fab
.fab$b_fns
= strlen (to
);
5142 to_fab
.fab$l_nam
= &to_nam
;
5143 to_fab
.fab$l_fop
= FAB$M_NAM
;
5145 to_nam
.nam$l_esa
= to_esn
;
5146 to_nam
.nam$b_ess
= sizeof to_esn
;
5148 status
= SYS$
PARSE (&to_fab
, 0, 0); /* figure out the full file name */
5150 if (to_nam
.nam$l_fnb
&& NAM$M_EXP_VER
)
5151 *(to_nam
.nam$l_ver
) = '\0';
5153 stat
= rename (from
, to_esn
);
5157 strcpy (vms_file_written
, to_esn
);
5159 to_fab
.fab$l_fna
= vms_file_written
; /* this points to the versionless name */
5160 to_fab
.fab$b_fns
= strlen (vms_file_written
);
5162 /* Now set the file protection to the correct value */
5163 SYS$
OPEN (&to_fab
, 0, 0); /* This fills in the nam$w_fid fields */
5165 /* Copy these fields into the fib */
5166 fib
.fib$r_fid_overlay
.fib$w_fid
[0] = to_nam
.nam$w_fid
[0];
5167 fib
.fib$r_fid_overlay
.fib$w_fid
[1] = to_nam
.nam$w_fid
[1];
5168 fib
.fib$r_fid_overlay
.fib$w_fid
[2] = to_nam
.nam$w_fid
[2];
5170 SYS$
CLOSE (&to_fab
, 0, 0);
5172 stat
= SYS$
ASSIGN (&disk
, &chan
, 0, 0); /* open a channel to the disk */
5175 stat
= SYS$
QIOW (0, chan
, IO$_MODIFY
, iosb
, 0, 0, &fib_d
,
5176 0, 0, 0, &fib_attr
, 0);
5179 stat
= SYS$
DASSGN (chan
);
5182 strcpy (vms_file_written
, to_esn
); /* We will write this to the terminal*/
5193 unsigned short fid
[3];
5194 char esa
[NAM$C_MAXRSS
];
5197 fab
.fab$l_fop
= FAB$M_OFP
;
5198 fab
.fab$l_fna
= file
;
5199 fab
.fab$b_fns
= strlen (file
);
5200 fab
.fab$l_nam
= &nam
;
5203 nam
.nam$l_esa
= esa
;
5204 nam
.nam$b_ess
= NAM$C_MAXRSS
;
5206 status
= SYS$
PARSE (&fab
);
5207 if ((status
& 1) == 0)
5210 vaxc$errno
= status
;
5213 status
= SYS$
SEARCH (&fab
);
5214 if ((status
& 1) == 0)
5217 vaxc$errno
= status
;
5221 fid
[0] = nam
.nam$w_fid
[0];
5222 fid
[1] = nam
.nam$w_fid
[1];
5223 fid
[2] = nam
.nam$w_fid
[2];
5225 fab
.fab$l_fna
= new;
5226 fab
.fab$b_fns
= strlen (new);
5228 status
= SYS$
PARSE (&fab
);
5229 if ((status
& 1) == 0)
5232 vaxc$errno
= status
;
5236 nam
.nam$w_fid
[0] = fid
[0];
5237 nam
.nam$w_fid
[1] = fid
[1];
5238 nam
.nam$w_fid
[2] = fid
[2];
5240 nam
.nam$l_esa
= nam
.nam$l_name
;
5241 nam
.nam$b_esl
= nam
.nam$b_name
+ nam
.nam$b_type
+ nam
.nam$b_ver
;
5243 status
= SYS$
ENTER (&fab
);
5244 if ((status
& 1) == 0)
5247 vaxc$errno
= status
;
5258 printf ("%s not yet implemented\r\n", badfunc
);
5259 reset_all_sys_modes ();
5266 /* Arrange to return a range centered on zero. */
5267 return rand () - (1 << 30);
5279 /* Called from init_sys_modes. */
5281 hft_init (struct tty_display_info
*tty_out
)
5285 /* If we're not on an HFT we shouldn't do any of this. We determine
5286 if we are on an HFT by trying to get an HFT error code. If this
5287 call fails, we're not on an HFT. */
5289 if (ioctl (0, HFQERROR
, &junk
) < 0)
5291 #else /* not IBMR2AIX */
5292 if (ioctl (0, HFQEIO
, 0) < 0)
5294 #endif /* not IBMR2AIX */
5296 /* On AIX the default hft keyboard mapping uses backspace rather than delete
5297 as the rubout key's ASCII code. Here this is changed. The bug is that
5298 there's no way to determine the old mapping, so in reset_sys_modes
5299 we need to assume that the normal map had been present. Of course, this
5300 code also doesn't help if on a terminal emulator which doesn't understand
5304 struct hfkeymap keymap
;
5306 buf
.hf_bufp
= (char *)&keymap
;
5307 buf
.hf_buflen
= sizeof (keymap
);
5308 keymap
.hf_nkeys
= 2;
5309 keymap
.hfkey
[0].hf_kpos
= 15;
5310 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5312 keymap
.hfkey
[0].hf_keyidh
= '<';
5313 #else /* not IBMR2AIX */
5314 keymap
.hfkey
[0].hf_page
= '<';
5315 #endif /* not IBMR2AIX */
5316 keymap
.hfkey
[0].hf_char
= 127;
5317 keymap
.hfkey
[1].hf_kpos
= 15;
5318 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5320 keymap
.hfkey
[1].hf_keyidh
= '<';
5321 #else /* not IBMR2AIX */
5322 keymap
.hfkey
[1].hf_page
= '<';
5323 #endif /* not IBMR2AIX */
5324 keymap
.hfkey
[1].hf_char
= 127;
5325 hftctl (0, HFSKBD
, &buf
);
5329 /* Reset the rubout key to backspace. */
5332 hft_reset (struct tty_display_info
*tty_out
)
5335 struct hfkeymap keymap
;
5339 if (ioctl (0, HFQERROR
, &junk
) < 0)
5341 #else /* not IBMR2AIX */
5342 if (ioctl (0, HFQEIO
, 0) < 0)
5344 #endif /* not IBMR2AIX */
5346 buf
.hf_bufp
= (char *)&keymap
;
5347 buf
.hf_buflen
= sizeof (keymap
);
5348 keymap
.hf_nkeys
= 2;
5349 keymap
.hfkey
[0].hf_kpos
= 15;
5350 keymap
.hfkey
[0].hf_kstate
= HFMAPCHAR
| HFSHFNONE
;
5352 keymap
.hfkey
[0].hf_keyidh
= '<';
5353 #else /* not IBMR2AIX */
5354 keymap
.hfkey
[0].hf_page
= '<';
5355 #endif /* not IBMR2AIX */
5356 keymap
.hfkey
[0].hf_char
= 8;
5357 keymap
.hfkey
[1].hf_kpos
= 15;
5358 keymap
.hfkey
[1].hf_kstate
= HFMAPCHAR
| HFSHFSHFT
;
5360 keymap
.hfkey
[1].hf_keyidh
= '<';
5361 #else /* not IBMR2AIX */
5362 keymap
.hfkey
[1].hf_page
= '<';
5363 #endif /* not IBMR2AIX */
5364 keymap
.hfkey
[1].hf_char
= 8;
5365 hftctl (0, HFSKBD
, &buf
);
5372 /* These are included on Sunos 4.1 when we do not use shared libraries.
5373 X11 libraries may refer to these functions but (we hope) do not
5374 actually call them. */
5394 #endif /* USE_DL_STUBS */
5403 register int length
;
5407 long max_str
= 65535;
5409 while (length
> max_str
) {
5410 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5415 (void) LIB$
MOVC5 (&zero
, &zero
, &zero
, &max_str
, b
);
5417 while (length
-- > 0)
5419 #endif /* not VMS */
5422 #endif /* no bzero */
5423 #endif /* BSTRING */
5425 #if (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY)
5428 /* Saying `void' requires a declaration, above, where bcopy is used
5429 and that declaration causes pain for systems where bcopy is a macro. */
5430 bcopy (b1
, b2
, length
)
5433 register int length
;
5436 long max_str
= 65535;
5438 while (length
> max_str
) {
5439 (void) LIB$
MOVC3 (&max_str
, b1
, b2
);
5445 (void) LIB$
MOVC3 (&length
, b1
, b2
);
5447 while (length
-- > 0)
5449 #endif /* not VMS */
5451 #endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
5456 bcmp (b1
, b2
, length
) /* This could be a macro! */
5459 register int length
;
5462 struct dsc$descriptor_s src1
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b1
};
5463 struct dsc$descriptor_s src2
= {length
, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, b2
};
5465 return STR$
COMPARE (&src1
, &src2
);
5467 while (length
-- > 0)
5472 #endif /* not VMS */
5474 #endif /* no bcmp */
5475 #endif /* not BSTRING */
5477 #ifndef HAVE_STRSIGNAL
5484 if (0 <= code
&& code
< NSIG
)
5487 signame
= sys_errlist
[code
];
5489 /* Cast to suppress warning if the table has const char *. */
5490 signame
= (char *) sys_siglist
[code
];
5496 #endif /* HAVE_STRSIGNAL */
5498 /* arch-tag: edb43589-4e09-4544-b325-978b5b121dcf
5499 (do not change this comment) */