]> code.delx.au - gnu-emacs/blobdiff - src/sysdep.c
* macterm.c (XTread_socket): Call DragWindow only for mouseDown events.
[gnu-emacs] / src / sysdep.c
index a7026b878245dc49b7cc2273b1ba4081a823943c..441b36290e1afdcaed352bd7f4e581f1121c4eb5 100644 (file)
@@ -1,5 +1,6 @@
 /* Interfaces to system-dependent kernel and library entries.
 /* Interfaces to system-dependent kernel and library entries.
-   Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
+   Copyright (C) 1985, 86,87,88,93,94,95,1999,2000,01,2003
+   Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 
 This file is part of GNU Emacs.
 
@@ -18,48 +19,60 @@ along with GNU Emacs; see the file COPYING.  If not, write to
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <signal.h>
 #include <setjmp.h>
 
 #include <signal.h>
 #include <setjmp.h>
-
-#include <config.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 #include "lisp.h"
 #include "lisp.h"
+/* Including stdlib.h isn't necessarily enough to get srandom
+   declared, e.g. without __USE_XOPEN_EXTENDED with glibc 2.  */
+#ifdef HAVE_RANDOM
+#if 0 /* It turns out that defining _OSF_SOURCE in osf5-0.h gets
+        random prototyped as returning `int'.  It looks to me as
+        though the best way to DTRT is to prefer the rand48 functions
+        (per libc.info).  -- fx */
+extern long int random P_ ((void));
+#endif
+#if 0 /* Don't prototype srandom; it takes an unsigned argument on
+        some systems, and an unsigned long on others, like FreeBSD
+        4.1.  */
+extern void srandom P_ ((unsigned int));
+#endif
+#endif
+
 #include "blockinput.h"
 #undef NULL
 
 #include "blockinput.h"
 #undef NULL
 
-#define min(x,y) ((x) > (y) ? (y) : (x))
-
-/* In this file, open, read and write refer to the system calls,
-   not our sugared interfaces  sys_open, sys_read and sys_write.
-   Contrariwise, for systems where we use the system calls directly,
-   define sys_read, etc. here as aliases for them.  */
-#ifndef read
-#define sys_read read
-#define sys_write write
-#endif /* `read' is not a macro */
+#ifdef MAC_OS8
+/* It is essential to include stdlib.h so that this file picks up
+   the correct definitions of rand, srand, and RAND_MAX.
+   Otherwise random numbers will not work correctly.  */
+#include <stdlib.h>
 
 
-#undef read
-#undef write
+#ifndef subprocesses
+/* Nonzero means delete a process right away if it exits (process.c).  */
+static int delete_exited_processes;
+#endif
+#endif  /* MAC_OS8 */
 
 #ifdef WINDOWSNT
 
 #ifdef WINDOWSNT
-#define read _read
-#define write _write
+#define read sys_read
+#define write sys_write
 #include <windows.h>
 #include <windows.h>
-extern int errno;
+#ifndef NULL
+#define NULL 0
+#endif
 #endif /* not WINDOWSNT */
 
 #endif /* not WINDOWSNT */
 
-#ifndef close
-#define sys_close close
-#else 
-#undef close
+#ifdef HAVE_CARBON
+#define read sys_read
 #endif
 
 #endif
 
-#ifndef open
-#define sys_open open
-#else /* `open' is a macro */
-#undef open
-#endif /* `open' is a macro */
-
 /* Does anyone other than VMS need this? */
 #ifndef fwrite
 #define sys_fwrite fwrite
 /* Does anyone other than VMS need this? */
 #ifndef fwrite
 #define sys_fwrite fwrite
@@ -67,18 +80,16 @@ extern int errno;
 #undef fwrite
 #endif
 
 #undef fwrite
 #endif
 
-#ifndef HAVE_H_ERRNO
-extern int h_errno;
-#endif
-
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
 
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
 
-/* Get _POSIX_VDISABLE, if it is available.  */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+#ifdef HAVE_SETPGID
+#if !defined (USG) || defined (BSD_PGRPS)
+#undef setpgrp
+#define setpgrp setpgid
+#endif
 #endif
 
 /* Get SI_SRPC_DOMAIN, if it is available.  */
 #endif
 
 /* Get SI_SRPC_DOMAIN, if it is available.  */
@@ -98,7 +109,11 @@ extern unsigned start __asm__ ("start");
 #endif
 #endif
 
 #endif
 #endif
 
+#ifndef USE_CRT_DLL
+#ifndef errno
 extern int errno;
 extern int errno;
+#endif
+#endif
 
 #ifdef VMS
 #include <rms.h>
 
 #ifdef VMS
 #include <rms.h>
@@ -123,17 +138,13 @@ extern int errno;
 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
 #endif /* VMS */
 
 #define MAXIOSIZE (32 * PAGESIZE) /* Don't I/O more than 32 blocks at a time */
 #endif /* VMS */
 
-#ifndef BSD4_1
-#ifdef BSD_SYSTEM /* avoid writing defined (BSD_SYSTEM) || defined (USG)
-             because the vms compiler doesn't grok `defined' */
-#include <fcntl.h>
-#endif
-#ifdef USG
-#ifndef USG5
+#ifndef VMS
+#include <sys/file.h>
+#endif /* not VMS */
+
+#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
 #include <fcntl.h>
 #endif
-#endif
-#endif /* not 4.1 bsd */
 
 #ifndef MSDOS
 #include <sys/ioctl.h>
 
 #ifndef MSDOS
 #include <sys/ioctl.h>
@@ -147,9 +158,8 @@ extern int errno;
 #undef TIOCSWINSZ
 #endif
 
 #undef TIOCSWINSZ
 #endif
 
-#ifdef USG
+#if defined (USG) || defined (DGUX)
 #include <sys/utsname.h>
 #include <sys/utsname.h>
-#include <string.h>
 #ifndef MEMORY_IN_STRING_H
 #include <memory.h>
 #endif
 #ifndef MEMORY_IN_STRING_H
 #include <memory.h>
 #endif
@@ -162,10 +172,11 @@ extern int errno;
 #include <sys/ptem.h>
 #endif
 #endif /* TIOCGWINSZ or ISC4_0 */
 #include <sys/ptem.h>
 #endif
 #endif /* TIOCGWINSZ or ISC4_0 */
-#endif /* USG */
+#endif /* USG or DGUX */
 
 extern int quit_char;
 
 
 extern int quit_char;
 
+#include "keyboard.h"
 #include "frame.h"
 #include "window.h"
 #include "termhooks.h"
 #include "frame.h"
 #include "window.h"
 #include "termhooks.h"
@@ -203,10 +214,6 @@ struct utimbuf {
 #endif
 #endif
 
 #endif
 #endif
 
-#ifndef VFORK_RETURN_TYPE
-#define VFORK_RETURN_TYPE int
-#endif
-
 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits.  */
 #ifndef LPASS8
 #define LPASS8 0
 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits.  */
 #ifndef LPASS8
 #define LPASS8 0
@@ -226,16 +233,35 @@ static int baud_convert[] =
   };
 #endif
 
   };
 #endif
 
-#ifdef HAVE_TERMIOS
-extern speed_t ospeed;
+#ifdef HAVE_SPEED_T
+#include <termios.h>
 #else
 #else
-extern short ospeed;
+#if defined (HAVE_LIBNCURSES) && ! defined (NCURSES_OSPEED_T)
+#else
+#if defined (HAVE_TERMIOS_H) && defined (GNU_LINUX)
+#include <termios.h>
+#endif
 #endif
 #endif
+#endif
+
+int emacs_ospeed;
 
 /* The file descriptor for Emacs's input terminal.
    Under Unix, this is normally zero except when using X;
    under VMS, we place the input channel number here.  */
 int input_fd;
 
 /* The file descriptor for Emacs's input terminal.
    Under Unix, this is normally zero except when using X;
    under VMS, we place the input channel number here.  */
 int input_fd;
+
+void croak P_ ((char *));
+
+#ifdef AIXHFT
+void hft_init ();
+void hft_reset ();
+#endif
+
+/* Temporary used by `sigblock' when defined in terms of signprocmask.  */
+
+SIGMASKTYPE sigprocmask_set;
+
 \f
 /* Specify a different file descriptor for further input operations.  */
 
 \f
 /* Specify a different file descriptor for further input operations.  */
 
@@ -248,6 +274,7 @@ change_input_fd (fd)
 
 /* Discard pending input on descriptor input_fd.  */
 
 
 /* Discard pending input on descriptor input_fd.  */
 
+void
 discard_tty_input ()
 {
 #ifndef WINDOWSNT
 discard_tty_input ()
 {
 #ifndef WINDOWSNT
@@ -290,8 +317,13 @@ discard_tty_input ()
 /* Arrange for character C to be read as the next input from
    the terminal.  */
 
 /* Arrange for character C to be read as the next input from
    the terminal.  */
 
+void
+#ifdef PROTOTYPES
+stuff_char (char c)
+#else
 stuff_char (c)
      char c;
 stuff_char (c)
      char c;
+#endif
 {
   if (read_socket_hook)
     return;
 {
   if (read_socket_hook)
     return;
@@ -306,32 +338,36 @@ stuff_char (c)
 
 #endif /* SIGTSTP */
 \f
 
 #endif /* SIGTSTP */
 \f
+void
 init_baud_rate ()
 {
   if (noninteractive)
 init_baud_rate ()
 {
   if (noninteractive)
-    ospeed = 0;
+    emacs_ospeed = 0;
   else
     {
   else
     {
+#ifdef INIT_BAUD_RATE
+      INIT_BAUD_RATE ();
+#else
 #ifdef DOS_NT
 #ifdef DOS_NT
-    ospeed = 15;
+    emacs_ospeed = 15;
 #else  /* not DOS_NT */
 #ifdef VMS
       struct sensemode sg;
 
       SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0,
                &sg.class, 12, 0, 0, 0, 0 );
 #else  /* not DOS_NT */
 #ifdef VMS
       struct sensemode sg;
 
       SYS$QIOW (0, input_fd, IO$_SENSEMODE, &sg, 0, 0,
                &sg.class, 12, 0, 0, 0, 0 );
-      ospeed = sg.xmit_baud;
+      emacs_ospeed = sg.xmit_baud;
 #else /* not VMS */
 #ifdef HAVE_TERMIOS
       struct termios sg;
 
       sg.c_cflag = B9600;
       tcgetattr (input_fd, &sg);
 #else /* not VMS */
 #ifdef HAVE_TERMIOS
       struct termios sg;
 
       sg.c_cflag = B9600;
       tcgetattr (input_fd, &sg);
-      ospeed = cfgetospeed (&sg);
+      emacs_ospeed = cfgetospeed (&sg);
 #if defined (USE_GETOBAUD) && defined (getobaud)
       /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
 #if defined (USE_GETOBAUD) && defined (getobaud)
       /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
-      if (ospeed == 0)
-        ospeed = getobaud (sg.c_cflag);
+      if (emacs_ospeed == 0)
+        emacs_ospeed = getobaud (sg.c_cflag);
 #endif
 #else /* neither VMS nor TERMIOS */
 #ifdef HAVE_TERMIO
 #endif
 #else /* neither VMS nor TERMIOS */
 #ifdef HAVE_TERMIO
@@ -343,27 +379,29 @@ init_baud_rate ()
 #else
       ioctl (input_fd, TCGETA, &sg);
 #endif
 #else
       ioctl (input_fd, TCGETA, &sg);
 #endif
-      ospeed = sg.c_cflag & CBAUD;
+      emacs_ospeed = sg.c_cflag & CBAUD;
 #else /* neither VMS nor TERMIOS nor TERMIO */
       struct sgttyb sg;
 #else /* neither VMS nor TERMIOS nor TERMIO */
       struct sgttyb sg;
-      
+
       sg.sg_ospeed = B9600;
       if (ioctl (input_fd, TIOCGETP, &sg) < 0)
        abort ();
       sg.sg_ospeed = B9600;
       if (ioctl (input_fd, TIOCGETP, &sg) < 0)
        abort ();
-      ospeed = sg.sg_ospeed;
+      emacs_ospeed = sg.sg_ospeed;
 #endif /* not HAVE_TERMIO */
 #endif /* not HAVE_TERMIOS */
 #endif /* not VMS */
 #endif /* not DOS_NT */
 #endif /* not HAVE_TERMIO */
 #endif /* not HAVE_TERMIOS */
 #endif /* not VMS */
 #endif /* not DOS_NT */
+#endif /* not INIT_BAUD_RATE */
     }
     }
-   
-  baud_rate = (ospeed < sizeof baud_convert / sizeof baud_convert[0]
-              ? baud_convert[ospeed] : 9600);
+
+  baud_rate = (emacs_ospeed < sizeof baud_convert / sizeof baud_convert[0]
+              ? baud_convert[emacs_ospeed] : 9600);
   if (baud_rate == 0)
     baud_rate = 1200;
 }
 
 /*ARGSUSED*/
   if (baud_rate == 0)
     baud_rate = 1200;
 }
 
 /*ARGSUSED*/
+void
 set_exclusive_use (fd)
      int fd;
 {
 set_exclusive_use (fd)
      int fd;
 {
@@ -397,6 +435,7 @@ wait_for_termination_signal ()
 /* Wait for subprocess with process id `pid' to terminate and
    make sure it will get eliminated (not remain forever as a zombie) */
 
 /* Wait for subprocess with process id `pid' to terminate and
    make sure it will get eliminated (not remain forever as a zombie) */
 
+void
 wait_for_termination (pid)
      int pid;
 {
 wait_for_termination (pid)
      int pid;
 {
@@ -434,14 +473,16 @@ wait_for_termination (pid)
        break;
       wait (0);
 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
        break;
       wait (0);
 #else /* neither BSD_SYSTEM nor UNIPLUS: random sysV */
-#ifdef POSIX_SIGNALS    /* would this work for LINUX as well? */
+#ifdef POSIX_SIGNALS    /* would this work for GNU/Linux as well? */
       sigblock (sigmask (SIGCHLD));
       sigblock (sigmask (SIGCHLD));
-      if (0 > kill (pid, 0))
+      errno = 0;
+      if (kill (pid, 0) == -1 && errno == ESRCH)
        {
          sigunblock (sigmask (SIGCHLD));
          break;
        }
        {
          sigunblock (sigmask (SIGCHLD));
          break;
        }
-      sigpause (SIGEMPTYMASK);
+
+      sigsuspend (&empty_mask);
 #else /* not POSIX_SIGNALS */
 #ifdef HAVE_SYSV_SIGPAUSE
       sighold (SIGCHLD);
 #else /* not POSIX_SIGNALS */
 #ifdef HAVE_SYSV_SIGPAUSE
       sighold (SIGCHLD);
@@ -493,7 +534,8 @@ wait_for_termination (pid)
  *     flush any pending output
  *      (may flush input as well; it does not matter the way we use it)
  */
  *     flush any pending output
  *      (may flush input as well; it does not matter the way we use it)
  */
+
+void
 flush_pending_output (channel)
      int channel;
 {
 flush_pending_output (channel)
      int channel;
 {
@@ -521,6 +563,7 @@ flush_pending_output (channel)
     It should not echo or do line-editing, since that is done
     in Emacs.  No padding needed for insertion into an Emacs buffer.  */
 
     It should not echo or do line-editing, since that is done
     in Emacs.  No padding needed for insertion into an Emacs buffer.  */
 
+void
 child_setup_tty (out)
      int out;
 {
 child_setup_tty (out)
      int out;
 {
@@ -538,6 +581,13 @@ child_setup_tty (out)
 #endif
   s.main.c_lflag &= ~ECHO;     /* Disable echo */
   s.main.c_lflag |= ISIG;      /* Enable signals */
 #endif
   s.main.c_lflag &= ~ECHO;     /* Disable echo */
   s.main.c_lflag |= ISIG;      /* Enable signals */
+#if 0  /* This causes bugs in (for instance) telnet to certain sites.  */
+  s.main.c_iflag &= ~ICRNL;    /* Disable map of CR to NL on input */
+#ifdef INLCR  /* Just being cautious, since I can't check how
+                widespread INLCR is--rms.  */
+  s.main.c_iflag &= ~INLCR;    /* Disable map of NL to CR on input */
+#endif
+#endif
 #ifdef IUCLC
   s.main.c_iflag &= ~IUCLC;    /* Disable downcasing on input.  */
 #endif
 #ifdef IUCLC
   s.main.c_iflag &= ~IUCLC;    /* Disable downcasing on input.  */
 #endif
@@ -626,11 +676,15 @@ child_setup_tty (out)
 struct save_signal
 {
   int code;
 struct save_signal
 {
   int code;
-  SIGTYPE (*handler) ();
+  SIGTYPE (*handler) P_ ((int));
 };
 
 };
 
+static void save_signal_handlers P_ ((struct save_signal *));
+static void restore_signal_handlers P_ ((struct save_signal *));
+
 /* Suspend the Emacs process; give terminal to its superior.  */
 
 /* Suspend the Emacs process; give terminal to its superior.  */
 
+void
 sys_suspend ()
 {
 #ifdef VMS
 sys_suspend ()
 {
 #ifdef VMS
@@ -674,7 +728,7 @@ sys_suspend ()
     }
   return -1;
 #else
     }
   return -1;
 #else
-#if defined(SIGTSTP) && !defined(MSDOS)
+#if defined (SIGTSTP) && !defined (MSDOS)
 
   {
     int pgrp = EMACS_GETPGRP (0);
 
   {
     int pgrp = EMACS_GETPGRP (0);
@@ -700,10 +754,12 @@ sys_suspend ()
 
 /* Fork a subshell.  */
 
 
 /* Fork a subshell.  */
 
+#ifndef MAC_OS8
+void
 sys_subshell ()
 {
 #ifndef VMS
 sys_subshell ()
 {
 #ifndef VMS
-#ifdef MSDOS   /* Demacs 1.1.2 91/10/20 Manabu Higashida */
+#ifdef DOS_NT  /* Demacs 1.1.2 91/10/20 Manabu Higashida */
   int st;
   char oldwd[MAXPATHLEN+1]; /* Fixed length is safe on MSDOS.  */
 #endif
   int st;
   char oldwd[MAXPATHLEN+1]; /* Fixed length is safe on MSDOS.  */
 #endif
@@ -734,35 +790,30 @@ sys_subshell ()
     goto xyzzy;
 
   dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil);
     goto xyzzy;
 
   dir = expand_and_dir_to_file (Funhandled_file_name_directory (dir), Qnil);
-  str = (unsigned char *) alloca (XSTRING (dir)->size + 2);
-  len = XSTRING (dir)->size;
-  bcopy (XSTRING (dir)->data, str, len);
+  str = (unsigned char *) alloca (SCHARS (dir) + 2);
+  len = SCHARS (dir);
+  bcopy (SDATA (dir), str, len);
   if (str[len - 1] != '/') str[len++] = '/';
   str[len] = 0;
  xyzzy:
 
   if (str[len - 1] != '/') str[len++] = '/';
   str[len] = 0;
  xyzzy:
 
-#ifdef WINDOWSNT
-  pid = -1;
-#else /* not WINDOWSNT */
-
-#ifdef MSDOS
+#ifdef DOS_NT
   pid = 0;
 #if __DJGPP__ > 1
   save_signal_handlers (saved_handlers);
   synch_process_alive = 1;
 #endif /* __DJGPP__ > 1 */
   pid = 0;
 #if __DJGPP__ > 1
   save_signal_handlers (saved_handlers);
   synch_process_alive = 1;
 #endif /* __DJGPP__ > 1 */
-#else  
+#else
   pid = vfork ();
   if (pid == -1)
     error ("Can't spawn subshell");
 #endif
 
   if (pid == 0)
   pid = vfork ();
   if (pid == -1)
     error ("Can't spawn subshell");
 #endif
 
   if (pid == 0)
-#endif /* not WINDOWSNT */
     {
       char *sh = 0;
 
     {
       char *sh = 0;
 
-#ifdef MSDOS    /* MW, Aug 1993 */
+#ifdef DOS_NT    /* MW, Aug 1993 */
       getwd (oldwd);
       if (sh == 0)
        sh = (char *) egetenv ("SUSPEND");      /* KFS, 1994-12-14 */
       getwd (oldwd);
       if (sh == 0)
        sh = (char *) egetenv ("SUSPEND");      /* KFS, 1994-12-14 */
@@ -774,7 +825,7 @@ sys_subshell ()
 
       /* Use our buffer's default directory for the subshell.  */
       if (str)
 
       /* Use our buffer's default directory for the subshell.  */
       if (str)
-       chdir (str);
+       chdir ((char *) str);
 
 #ifdef subprocesses
       close_process_descs ();  /* Close Emacs's pipes/ptys */
 
 #ifdef subprocesses
       close_process_descs ();  /* Close Emacs's pipes/ptys */
@@ -782,7 +833,7 @@ sys_subshell ()
 
 #ifdef SET_EMACS_PRIORITY
       {
 
 #ifdef SET_EMACS_PRIORITY
       {
-       extern int emacs_priority;
+       extern EMACS_INT emacs_priority;
 
        if (emacs_priority < 0)
          nice (-emacs_priority);
 
        if (emacs_priority < 0)
          nice (-emacs_priority);
@@ -790,8 +841,23 @@ sys_subshell ()
 #endif
 
 #ifdef MSDOS    /* Demacs 1.1.2 91/10/20 Manabu Higashida */
 #endif
 
 #ifdef MSDOS    /* Demacs 1.1.2 91/10/20 Manabu Higashida */
-      st = system (sh);
-      chdir (oldwd);
+      {
+       char *epwd = getenv ("PWD");
+       char old_pwd[MAXPATHLEN+1+4];
+
+       /* If PWD is set, pass it with corrected value.  */
+       if (epwd)
+         {
+           strcpy (old_pwd, epwd);
+           if (str[len - 1] == '/')
+             str[len - 1] = '\0';
+           setenv ("PWD", str, 1);
+         }
+       st = system (sh);
+       chdir (oldwd);
+       if (epwd)
+         putenv (old_pwd);     /* restore previous value */
+      }
 #if 0  /* This is also reported if last command executed in subshell failed, KFS */
       if (st)
        report_file_error ("Can't execute subshell", Fcons (build_string (sh), Qnil));
 #if 0  /* This is also reported if last command executed in subshell failed, KFS */
       if (st)
        report_file_error ("Can't execute subshell", Fcons (build_string (sh), Qnil));
@@ -800,10 +866,9 @@ sys_subshell ()
 #ifdef  WINDOWSNT
       /* Waits for process completion */
       pid = _spawnlp (_P_WAIT, sh, sh, NULL);
 #ifdef  WINDOWSNT
       /* Waits for process completion */
       pid = _spawnlp (_P_WAIT, sh, sh, NULL);
+      chdir (oldwd);
       if (pid == -1)
        write (1, "Can't execute subshell", 22);
       if (pid == -1)
        write (1, "Can't execute subshell", 22);
-
-      take_console ();
 #else   /* not WINDOWSNT */
       execlp (sh, sh, 0);
       write (1, "Can't execute subshell", 22);
 #else   /* not WINDOWSNT */
       execlp (sh, sh, 0);
       write (1, "Can't execute subshell", 22);
@@ -818,25 +883,28 @@ sys_subshell ()
   synch_process_alive = 1;
 #endif
 
   synch_process_alive = 1;
 #endif
 
-#ifndef MSDOS
+#ifndef DOS_NT
   wait_for_termination (pid);
 #endif
   restore_signal_handlers (saved_handlers);
   synch_process_alive = 0;
 #endif /* !VMS */
 }
   wait_for_termination (pid);
 #endif
   restore_signal_handlers (saved_handlers);
   synch_process_alive = 0;
 #endif /* !VMS */
 }
+#endif /* !MAC_OS8 */
 
 
+static void
 save_signal_handlers (saved_handlers)
      struct save_signal *saved_handlers;
 {
   while (saved_handlers->code)
     {
       saved_handlers->handler
 save_signal_handlers (saved_handlers)
      struct save_signal *saved_handlers;
 {
   while (saved_handlers->code)
     {
       saved_handlers->handler
-       = (SIGTYPE (*) ()) signal (saved_handlers->code, SIG_IGN);
+       = (SIGTYPE (*) P_ ((int))) signal (saved_handlers->code, SIG_IGN);
       saved_handlers++;
     }
 }
 
       saved_handlers++;
     }
 }
 
+static void
 restore_signal_handlers (saved_handlers)
      struct save_signal *saved_handlers;
 {
 restore_signal_handlers (saved_handlers)
      struct save_signal *saved_handlers;
 {
@@ -851,6 +919,7 @@ restore_signal_handlers (saved_handlers)
 
 int old_fcntl_flags;
 
 
 int old_fcntl_flags;
 
+void
 init_sigio (fd)
      int fd;
 {
 init_sigio (fd)
      int fd;
 {
@@ -861,6 +930,7 @@ init_sigio (fd)
   interrupts_deferred = 0;
 }
 
   interrupts_deferred = 0;
 }
 
+void
 reset_sigio ()
 {
   unrequest_sigio ();
 reset_sigio ()
 {
   unrequest_sigio ();
@@ -868,6 +938,7 @@ reset_sigio ()
 
 #ifdef FASYNC          /* F_SETFL does not imply existence of FASYNC */
 
 
 #ifdef FASYNC          /* F_SETFL does not imply existence of FASYNC */
 
+void
 request_sigio ()
 {
   if (read_socket_hook)
 request_sigio ()
 {
   if (read_socket_hook)
@@ -881,6 +952,7 @@ request_sigio ()
   interrupts_deferred = 0;
 }
 
   interrupts_deferred = 0;
 }
 
+void
 unrequest_sigio ()
 {
   if (read_socket_hook)
 unrequest_sigio ()
 {
   if (read_socket_hook)
@@ -896,6 +968,7 @@ unrequest_sigio ()
 #else /* no FASYNC */
 #ifdef STRIDE          /* Stride doesn't have FASYNC - use FIOASYNC */
 
 #else /* no FASYNC */
 #ifdef STRIDE          /* Stride doesn't have FASYNC - use FIOASYNC */
 
+void
 request_sigio ()
 {
   int on = 1;
 request_sigio ()
 {
   int on = 1;
@@ -907,6 +980,7 @@ request_sigio ()
   interrupts_deferred = 0;
 }
 
   interrupts_deferred = 0;
 }
 
+void
 unrequest_sigio ()
 {
   int off = 0;
 unrequest_sigio ()
 {
   int off = 0;
@@ -919,11 +993,12 @@ unrequest_sigio ()
 }
 
 #else /* not FASYNC, not STRIDE */
 }
 
 #else /* not FASYNC, not STRIDE */
+
 #ifdef _CX_UX
 
 #include <termios.h>
 
 #ifdef _CX_UX
 
 #include <termios.h>
 
+void
 request_sigio ()
 {
   int on = 1;
 request_sigio ()
 {
   int on = 1;
@@ -932,13 +1007,14 @@ request_sigio ()
   if (read_socket_hook)
     return;
 
   if (read_socket_hook)
     return;
 
-  sigemptyset(&st);
-  sigaddset(&st, SIGIO);
+  sigemptyset (&st);
+  sigaddset (&st, SIGIO);
   ioctl (input_fd, FIOASYNC, &on);
   interrupts_deferred = 0;
   ioctl (input_fd, FIOASYNC, &on);
   interrupts_deferred = 0;
-  sigprocmask(SIG_UNBLOCK, &st, (sigset_t *)0);
+  sigprocmask (SIG_UNBLOCK, &st, (sigset_t *)0);
 }
 
 }
 
+void
 unrequest_sigio ()
 {
   int off = 0;
 unrequest_sigio ()
 {
   int off = 0;
@@ -951,7 +1027,9 @@ unrequest_sigio ()
 }
 
 #else /* ! _CX_UX */
 }
 
 #else /* ! _CX_UX */
+#ifndef MSDOS
 
 
+void
 request_sigio ()
 {
   if (read_socket_hook)
 request_sigio ()
 {
   if (read_socket_hook)
@@ -959,7 +1037,8 @@ request_sigio ()
 
   croak ("request_sigio");
 }
 
   croak ("request_sigio");
 }
+
+void
 unrequest_sigio ()
 {
   if (read_socket_hook)
 unrequest_sigio ()
 {
   if (read_socket_hook)
@@ -967,7 +1046,8 @@ unrequest_sigio ()
 
   croak ("unrequest_sigio");
 }
 
   croak ("unrequest_sigio");
 }
+
+#endif /* MSDOS */
 #endif /* _CX_UX */
 #endif /* STRIDE */
 #endif /* FASYNC */
 #endif /* _CX_UX */
 #endif /* STRIDE */
 #endif /* FASYNC */
@@ -1001,6 +1081,7 @@ int inherited_pgroup;
    When we are in the foreground, but not started in our own process
    group, redirect the TTY to point to our own process group.  We need
    to be in our own process group to receive SIGIO properly.  */
    When we are in the foreground, but not started in our own process
    group, redirect the TTY to point to our own process group.  We need
    to be in our own process group to receive SIGIO properly.  */
+void
 narrow_foreground_group ()
 {
   int me = getpid ();
 narrow_foreground_group ()
 {
   int me = getpid ();
@@ -1012,6 +1093,7 @@ narrow_foreground_group ()
 }
 
 /* Set the tty to our original foreground group.  */
 }
 
 /* Set the tty to our original foreground group.  */
+void
 widen_foreground_group ()
 {
   if (inherited_pgroup != getpid ())
 widen_foreground_group ()
 {
   if (inherited_pgroup != getpid ())
@@ -1034,6 +1116,7 @@ emacs_get_tty (fd, settings)
   /* Retrieve the primary parameters - baud rate, character size, etcetera.  */
 #ifdef HAVE_TCATTR
   /* We have those nifty POSIX tcmumbleattr functions.  */
   /* Retrieve the primary parameters - baud rate, character size, etcetera.  */
 #ifdef HAVE_TCATTR
   /* We have those nifty POSIX tcmumbleattr functions.  */
+  bzero (&settings->main, sizeof (settings->main));
   if (tcgetattr (fd, &settings->main) < 0)
     return -1;
 
   if (tcgetattr (fd, &settings->main) < 0)
     return -1;
 
@@ -1094,7 +1177,7 @@ emacs_set_tty (fd, settings, flushp)
   int i;
   /* We have those nifty POSIX tcmumbleattr functions.
      William J. Smith <wjs@wiis.wang.com> writes:
   int i;
   /* We have those nifty POSIX tcmumbleattr functions.
      William J. Smith <wjs@wiis.wang.com> writes:
-     "POSIX 1003.1 defines tcsetattr() to return success if it was
+     "POSIX 1003.1 defines tcsetattr to return success if it was
      able to perform any of the requested actions, even if some
      of the requested actions could not be performed.
      We must read settings back to ensure tty setup properly.
      able to perform any of the requested actions, even if some
      of the requested actions could not be performed.
      We must read settings back to ensure tty setup properly.
@@ -1112,6 +1195,7 @@ emacs_set_tty (fd, settings, flushp)
       {
        struct termios new;
 
       {
        struct termios new;
 
+       bzero (&new, sizeof (new));
        /* Get the current settings, and see if they're what we asked for.  */
        tcgetattr (fd, &new);
        /* We cannot use memcmp on the whole structure here because under
        /* Get the current settings, and see if they're what we asked for.  */
        tcgetattr (fd, &new);
        /* We cannot use memcmp on the whole structure here because under
@@ -1122,7 +1206,7 @@ emacs_set_tty (fd, settings, flushp)
            && new.c_oflag == settings->main.c_oflag
            && new.c_cflag == settings->main.c_cflag
            && new.c_lflag == settings->main.c_lflag
            && new.c_oflag == settings->main.c_oflag
            && new.c_cflag == settings->main.c_cflag
            && new.c_lflag == settings->main.c_lflag
-           && memcmp(new.c_cc, settings->main.c_cc, NCCS) == 0)
+           && memcmp (new.c_cc, settings->main.c_cc, NCCS) == 0)
          break;
        else
          continue;
          break;
        else
          continue;
@@ -1165,7 +1249,7 @@ emacs_set_tty (fd, settings, flushp)
       || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
     return -1;
 #endif
       || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
     return -1;
 #endif
-  
+
   /* We have survived the tempest.  */
   return 0;
 }
   /* We have survived the tempest.  */
   return 0;
 }
@@ -1196,23 +1280,38 @@ int old_fcntl_owner;
    but if so, this does no harm,
    and using the same name avoids wasting the other one's space.  */
 
    but if so, this does no harm,
    and using the same name avoids wasting the other one's space.  */
 
+#ifdef nec_ews_svr4
+extern char *_sobuf ;
+#else
 #if defined (USG) || defined (DGUX)
 unsigned char _sobuf[BUFSIZ+8];
 #else
 char _sobuf[BUFSIZ];
 #endif
 #if defined (USG) || defined (DGUX)
 unsigned char _sobuf[BUFSIZ+8];
 #else
 char _sobuf[BUFSIZ];
 #endif
+#endif
+
 #ifdef HAVE_LTCHARS
 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
 #endif
 #ifdef HAVE_TCHARS
 #ifdef HAVE_LTCHARS
 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
 #endif
 #ifdef HAVE_TCHARS
-  static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
-#endif 
+static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
+#endif
 
 
+void
 init_sys_modes ()
 {
   struct emacs_tty tty;
 
 init_sys_modes ()
 {
   struct emacs_tty tty;
 
+#ifdef MAC_OS8
+/* cus-start.el complains if delete-exited-processes is not defined */
+#ifndef subprocesses
+  DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes,
+              doc: /* *Non-nil means delete processes immediately when they exit.
+nil means don't delete them until `list-processes' is run.  */);
+  delete_exited_processes = 0;
+#endif
+#endif /* MAC_OS8 */
+
 #ifdef VMS
 #if 0
   static int oob_chars[2] = {0, 1 << 7}; /* catch C-g's */
 #ifdef VMS
 #if 0
   static int oob_chars[2] = {0, 1 << 7}; /* catch C-g's */
@@ -1220,6 +1319,8 @@ init_sys_modes ()
 #endif
 #endif
 
 #endif
 #endif
 
+  Vtty_erase_char = Qnil;
+
   if (noninteractive)
     return;
 
   if (noninteractive)
     return;
 
@@ -1273,6 +1374,8 @@ init_sys_modes ()
       tty = old_tty;
 
 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
       tty = old_tty;
 
 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
+      XSETINT (Vtty_erase_char, old_tty.main.c_cc[VERASE]);
+
 #ifdef DGUX
       /* This allows meta to be sent on 8th bit.  */
       tty.main.c_iflag &= ~INPCK;      /* don't check input for parity */
 #ifdef DGUX
       /* This allows meta to be sent on 8th bit.  */
       tty.main.c_iflag &= ~INPCK;      /* don't check input for parity */
@@ -1301,7 +1404,7 @@ init_sys_modes ()
        }
       else
        tty.main.c_iflag &= ~IXON;      /* Disable start/stop output control */
        }
       else
        tty.main.c_iflag &= ~IXON;      /* Disable start/stop output control */
-      tty.main.c_oflag &= ~ONLCR;      /* Disable map of NL to CR-NL 
+      tty.main.c_oflag &= ~ONLCR;      /* Disable map of NL to CR-NL
                                           on output */
       tty.main.c_oflag &= ~TAB3;       /* Disable tab expansion */
 #ifdef CS8
                                           on output */
       tty.main.c_oflag &= ~TAB3;       /* Disable tab expansion */
 #ifdef CS8
@@ -1322,6 +1425,7 @@ init_sys_modes ()
       tty.main.c_cc[VSWTCH] = CDISABLE;        /* Turn off shell layering use
                                           of C-z */
 #endif /* VSWTCH */
       tty.main.c_cc[VSWTCH] = CDISABLE;        /* Turn off shell layering use
                                           of C-z */
 #endif /* VSWTCH */
+
 #if defined (mips) || defined (HAVE_TCATTR)
 #ifdef VSUSP
       tty.main.c_cc[VSUSP] = CDISABLE; /* Turn off mips handling of C-z.  */
 #if defined (mips) || defined (HAVE_TCATTR)
 #ifdef VSUSP
       tty.main.c_cc[VSUSP] = CDISABLE; /* Turn off mips handling of C-z.  */
@@ -1344,13 +1448,27 @@ init_sys_modes ()
 #ifdef VDISCARD
       tty.main.c_cc[VDISCARD] = CDISABLE;
 #endif /* VDISCARD */
 #ifdef VDISCARD
       tty.main.c_cc[VDISCARD] = CDISABLE;
 #endif /* VDISCARD */
+
+      if (flow_control)
+       {
+#ifdef VSTART
+         tty.main.c_cc[VSTART] = '\021';
+#endif /* VSTART */
+#ifdef VSTOP
+         tty.main.c_cc[VSTOP] = '\023';
+#endif /* VSTOP */
+       }
+      else
+       {
 #ifdef VSTART
 #ifdef VSTART
-      tty.main.c_cc[VSTART] = CDISABLE;
+         tty.main.c_cc[VSTART] = CDISABLE;
 #endif /* VSTART */
 #ifdef VSTOP
 #endif /* VSTART */
 #ifdef VSTOP
-      tty.main.c_cc[VSTOP] = CDISABLE;
+         tty.main.c_cc[VSTOP] = CDISABLE;
 #endif /* VSTOP */
 #endif /* VSTOP */
+       }
 #endif /* mips or HAVE_TCATTR */
 #endif /* mips or HAVE_TCATTR */
+
 #ifdef SET_LINE_DISCIPLINE
       /* Need to explicitly request TERMIODISC line discipline or
          Ultrix's termios does not work correctly.  */
 #ifdef SET_LINE_DISCIPLINE
       /* Need to explicitly request TERMIODISC line discipline or
          Ultrix's termios does not work correctly.  */
@@ -1367,6 +1485,15 @@ init_sys_modes ()
       tty.main.c_cc[VSUSP] = 255;
       tty.main.c_cc[VDSUSP] = 255;
 #endif /* IBMR2AIX */
       tty.main.c_cc[VSUSP] = 255;
       tty.main.c_cc[VDSUSP] = 255;
 #endif /* IBMR2AIX */
+      if (flow_control)
+       {
+#ifdef VSTART
+         tty.main.c_cc[VSTART] = '\021';
+#endif /* VSTART */
+#ifdef VSTOP
+         tty.main.c_cc[VSTOP] = '\023';
+#endif /* VSTOP */
+       }
       /* Also, PTY overloads NUL and BREAK.
         don't ignore break, but don't signal either, so it looks like NUL.
         This really serves a purpose only if running in an XTERM window
       /* Also, PTY overloads NUL and BREAK.
         don't ignore break, but don't signal either, so it looks like NUL.
         This really serves a purpose only if running in an XTERM window
@@ -1386,6 +1513,7 @@ init_sys_modes ()
       tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON;
 #else /* not VMS (BSD, that is) */
 #ifndef DOS_NT
       tty.main.tt2_char |= TT2$M_PASTHRU | TT2$M_XON;
 #else /* not VMS (BSD, that is) */
 #ifndef DOS_NT
+      XSETINT (Vtty_erase_char, tty.main.sg_erase);
       tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
       if (meta_key)
        tty.main.sg_flags |= ANYP;
       tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
       if (meta_key)
        tty.main.sg_flags |= ANYP;
@@ -1417,7 +1545,7 @@ init_sys_modes ()
         anything, and leaving it in breaks the meta key.  Go figure.  */
       tty.lmode &= ~LLITOUT;
 #endif
         anything, and leaving it in breaks the meta key.  Go figure.  */
       tty.lmode &= ~LLITOUT;
 #endif
-      
+
 #ifdef BSD4_1
       lmode = tty.lmode;
 #endif
 #ifdef BSD4_1
       lmode = tty.lmode;
 #endif
@@ -1503,17 +1631,28 @@ init_sys_modes ()
   /* This symbol is defined on recent USG systems.
      Someone says without this call USG won't really buffer the file
      even with a call to setbuf. */
   /* This symbol is defined on recent USG systems.
      Someone says without this call USG won't really buffer the file
      even with a call to setbuf. */
-  setvbuf (stdout, _sobuf, _IOFBF, sizeof _sobuf);
+  setvbuf (stdout, (char *) _sobuf, _IOFBF, sizeof _sobuf);
 #else
 #else
-  setbuf (stdout, _sobuf);
+  setbuf (stdout, (char *) _sobuf);
 #endif
 #ifdef HAVE_WINDOW_SYSTEM
   /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
      needs the initialization code below.  */
 #endif
 #ifdef HAVE_WINDOW_SYSTEM
   /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
      needs the initialization code below.  */
-  if (! read_socket_hook && EQ (Vwindow_system, Qnil))
+  if (EQ (Vwindow_system, Qnil)
+#ifndef WINDOWSNT
+      /* When running in tty mode on NT/Win95, we have a read_socket
+        hook, but still need the rest of the initialization code below.  */
+      && (! read_socket_hook)
+#endif
+      )
 #endif
     set_terminal_modes ();
 
 #endif
     set_terminal_modes ();
 
+  if (!term_initted
+      && FRAMEP (Vterminal_frame)
+      && FRAME_TERMCAP_P (XFRAME (Vterminal_frame)))
+    init_frame_faces (XFRAME (Vterminal_frame));
+
   if (term_initted && no_redraw_on_reenter)
     {
       if (display_completed)
   if (term_initted && no_redraw_on_reenter)
     {
       if (display_completed)
@@ -1531,7 +1670,8 @@ init_sys_modes ()
 
 /* Return nonzero if safe to use tabs in output.
    At the time this is called, init_sys_modes has not been done yet.  */
 
 /* Return nonzero if safe to use tabs in output.
    At the time this is called, init_sys_modes has not been done yet.  */
-   
+
+int
 tabs_safe_p ()
 {
   struct emacs_tty tty;
 tabs_safe_p ()
 {
   struct emacs_tty tty;
@@ -1544,6 +1684,7 @@ tabs_safe_p ()
    Store number of lines into *HEIGHTP and width into *WIDTHP.
    We store 0 if there's no valid information.  */
 
    Store number of lines into *HEIGHTP and width into *WIDTHP.
    We store 0 if there's no valid information.  */
 
+void
 get_frame_size (widthp, heightp)
      int *widthp, *heightp;
 {
 get_frame_size (widthp, heightp)
      int *widthp, *heightp;
 {
@@ -1565,7 +1706,7 @@ get_frame_size (widthp, heightp)
 #ifdef TIOCGSIZE
 
   /* SunOS - style.  */
 #ifdef TIOCGSIZE
 
   /* SunOS - style.  */
-  struct ttysize size;  
+  struct ttysize size;
 
   if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
     *widthp = *heightp = 0;
 
   if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
     *widthp = *heightp = 0;
@@ -1579,7 +1720,7 @@ get_frame_size (widthp, heightp)
 #ifdef VMS
 
   struct sensemode tty;
 #ifdef VMS
 
   struct sensemode tty;
-  
+
   SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0,
            &tty.class, 12, 0, 0, 0, 0);
   *widthp = tty.scr_wid;
   SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0,
            &tty.class, 12, 0, 0, 0, 0);
   *widthp = tty.scr_wid;
@@ -1622,7 +1763,7 @@ set_window_size (fd, height, width)
 #ifdef TIOCSSIZE
 
   /* SunOS - style.  */
 #ifdef TIOCSSIZE
 
   /* SunOS - style.  */
-  struct ttysize size;  
+  struct ttysize size;
   size.ts_lines = height;
   size.ts_cols = width;
 
   size.ts_lines = height;
   size.ts_cols = width;
 
@@ -1639,8 +1780,11 @@ set_window_size (fd, height, width)
 \f
 /* Prepare the terminal for exiting Emacs; move the cursor to the
    bottom of the frame, turn off interrupt-driven I/O, etc.  */
 \f
 /* Prepare the terminal for exiting Emacs; move the cursor to the
    bottom of the frame, turn off interrupt-driven I/O, etc.  */
+void
 reset_sys_modes ()
 {
 reset_sys_modes ()
 {
+  struct frame *sf;
+
   if (noninteractive)
     {
       fflush (stdout);
   if (noninteractive)
     {
       fflush (stdout);
@@ -1651,16 +1795,23 @@ reset_sys_modes ()
 #ifdef HAVE_WINDOW_SYSTEM
   /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
      needs the clean-up code below.  */
 #ifdef HAVE_WINDOW_SYSTEM
   /* Emacs' window system on MSDOG uses the `internal terminal' and therefore
      needs the clean-up code below.  */
-  if (read_socket_hook || !EQ (Vwindow_system, Qnil))
+  if (!EQ (Vwindow_system, Qnil)
+#ifndef WINDOWSNT
+      /* When running in tty mode on NT/Win95, we have a read_socket
+        hook, but still need the rest of the clean-up code below.  */
+      || read_socket_hook
+#endif
+      )
     return;
 #endif
     return;
 #endif
-  cursor_to (FRAME_HEIGHT (selected_frame) - 1, 0);
-  clear_end_of_line (FRAME_WIDTH (selected_frame));
+  sf = SELECTED_FRAME ();
+  cursor_to (FRAME_LINES (sf) - 1, 0);
+  clear_end_of_line (FRAME_COLS (sf));
   /* clear_end_of_line may move the cursor */
   /* clear_end_of_line may move the cursor */
-  cursor_to (FRAME_HEIGHT (selected_frame) - 1, 0);
+  cursor_to (FRAME_LINES (sf) - 1, 0);
 #if defined (IBMR2AIX) && defined (AIXHFT)
   {
 #if defined (IBMR2AIX) && defined (AIXHFT)
   {
-    /* HFT devices normally use ^J as a LF/CR.  We forced it to 
+    /* HFT devices normally use ^J as a LF/CR.  We forced it to
        do the LF only.  Now, we need to reset it. */
     struct termio tty;
 
        do the LF only.  Now, we need to reset it. */
     struct termio tty;
 
@@ -1725,6 +1876,7 @@ reset_sys_modes ()
 
 /* Set up the proper status flags for use of a pty.  */
 
 
 /* Set up the proper status flags for use of a pty.  */
 
+void
 setup_pty (fd)
      int fd;
 {
 setup_pty (fd)
      int fd;
 {
@@ -1742,17 +1894,17 @@ setup_pty (fd)
      does this.  Also it is known that telnet mode will hang
      in such a way that Emacs must be stopped (perhaps this
      is the same problem).
      does this.  Also it is known that telnet mode will hang
      in such a way that Emacs must be stopped (perhaps this
      is the same problem).
-     
+
      If TIOCREMOTE is turned off, then there is a bug in
      hp-ux which sometimes loses data.  Apparently the
      code which blocks the master process when the internal
      buffer fills up does not work.  Other than this,
      though, everything else seems to work fine.
      If TIOCREMOTE is turned off, then there is a bug in
      hp-ux which sometimes loses data.  Apparently the
      code which blocks the master process when the internal
      buffer fills up does not work.  Other than this,
      though, everything else seems to work fine.
-     
+
      Since the latter lossage is more benign, we may as well
      lose that way.  -- cph */
 #ifdef FIONBIO
      Since the latter lossage is more benign, we may as well
      lose that way.  -- cph */
 #ifdef FIONBIO
-#ifdef SYSV_PTYS
+#if defined(SYSV_PTYS) || defined(UNIX98_PTYS)
   {
     int on = 1;
     ioctl (fd, FIONBIO, &on);
   {
     int on = 1;
     ioctl (fd, FIONBIO, &on);
@@ -1776,10 +1928,11 @@ setup_pty (fd)
    This is called each time Emacs is resumed, also, but does nothing
    because input_chain is no longer zero.  */
 
    This is called each time Emacs is resumed, also, but does nothing
    because input_chain is no longer zero.  */
 
+void
 init_vms_input ()
 {
   int status;
 init_vms_input ()
 {
   int status;
-  
+
   if (input_fd == 0)
     {
       status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0);
   if (input_fd == 0)
     {
       status = SYS$ASSIGN (&input_dsc, &input_fd, 0, 0);
@@ -1790,6 +1943,7 @@ init_vms_input ()
 
 /* Deassigning the input channel is done before exiting.  */
 
 
 /* Deassigning the input channel is done before exiting.  */
 
+void
 stop_vms_input ()
 {
   return SYS$DASSGN (input_fd);
 stop_vms_input ()
 {
   return SYS$DASSGN (input_fd);
@@ -1800,6 +1954,7 @@ short input_buffer;
 /* Request reading one character into the keyboard buffer.
    This is done as soon as the buffer becomes empty.  */
 
 /* Request reading one character into the keyboard buffer.
    This is done as soon as the buffer becomes empty.  */
 
+void
 queue_kbd_input ()
 {
   int status;
 queue_kbd_input ()
 {
   int status;
@@ -1817,6 +1972,7 @@ int input_count;
 /* Ast routine that is called when keyboard input comes in
    in accord with the SYS$QIO above.  */
 
 /* Ast routine that is called when keyboard input comes in
    in accord with the SYS$QIO above.  */
 
+void
 kbd_input_ast ()
 {
   register int c = -1;
 kbd_input_ast ()
 {
   register int c = -1;
@@ -1852,9 +2008,11 @@ kbd_input_ast ()
   if (c >= 0)
     {
       struct input_event e;
   if (c >= 0)
     {
       struct input_event e;
-      e.kind = ascii_keystroke;
+      EVENT_INIT (e);
+
+      e.kind = ASCII_KEYSTROKE_EVENT;
       XSETINT (e.code, c);
       XSETINT (e.code, c);
-      XSETFRAME (e.frame_or_window, selected_frame);
+      e.frame_or_window = selected_frame;
       kbd_buffer_store_event (&e);
     }
   if (input_available_clear_time)
       kbd_buffer_store_event (&e);
     }
   if (input_available_clear_time)
@@ -1864,6 +2022,7 @@ kbd_input_ast ()
 
 /* Wait until there is something in kbd_buffer.  */
 
 
 /* Wait until there is something in kbd_buffer.  */
 
+void
 wait_for_kbd_input ()
 {
   extern int have_process_input, process_exited;
 wait_for_kbd_input ()
 {
   extern int have_process_input, process_exited;
@@ -1882,7 +2041,7 @@ wait_for_kbd_input ()
       /* No timing error: wait for flag to be set.  */
       set_waiting_for_input (0);
       SYS$WFLOR (input_ef, input_eflist);
       /* No timing error: wait for flag to be set.  */
       set_waiting_for_input (0);
       SYS$WFLOR (input_ef, input_eflist);
-      clear_waiting_for_input (0);
+      clear_waiting_for_input ();
       if (!detect_input_pending ())
        /* Check for subprocess input availability */
        {
       if (!detect_input_pending ())
        /* Check for subprocess input availability */
        {
@@ -1897,7 +2056,7 @@ wait_for_kbd_input ()
            {
              update_mode_lines++;
              prepare_menu_bars ();
            {
              update_mode_lines++;
              prepare_menu_bars ();
-             redisplay_preserve_echo_area ();
+             redisplay_preserve_echo_area (18);
            }
        }
     }
            }
        }
     }
@@ -1910,6 +2069,7 @@ wait_for_kbd_input ()
    and therefore there is no I/O request queued when we return.
    SYS$SETAST is used to avoid a timing error.  */
 
    and therefore there is no I/O request queued when we return.
    SYS$SETAST is used to avoid a timing error.  */
 
+void
 end_kbd_input ()
 {
 #ifdef ASTDEBUG
 end_kbd_input ()
 {
 #ifdef ASTDEBUG
@@ -1936,6 +2096,7 @@ end_kbd_input ()
 
 /* Wait for either input available or time interval expiry.  */
 
 
 /* Wait for either input available or time interval expiry.  */
 
+void
 input_wait_timeout (timeval)
      int timeval;              /* Time to wait, in seconds */
 {
 input_wait_timeout (timeval)
      int timeval;              /* Time to wait, in seconds */
 {
@@ -1974,7 +2135,7 @@ sys_sleep (timeval)
   int time [2];
   static int zero = 0;
   static int large = -10000000;
   int time [2];
   static int zero = 0;
   static int large = -10000000;
-  
+
   LIB$EMUL (&timeval, &large, &zero, time);      /* Convert to VMS format */
 
   SYS$CANTIM (1, 0);
   LIB$EMUL (&timeval, &large, &zero, time);      /* Convert to VMS format */
 
   SYS$CANTIM (1, 0);
@@ -1982,6 +2143,7 @@ sys_sleep (timeval)
     SYS$WAITFR (timer_ef);       /* Wait for timer expiry only */
 }
 
     SYS$WAITFR (timer_ef);       /* Wait for timer expiry only */
 }
 
+void
 init_sigio (fd)
      int fd;
 {
 init_sigio (fd)
      int fd;
 {
@@ -1993,11 +2155,13 @@ reset_sigio ()
   unrequest_sigio ();
 }
 
   unrequest_sigio ();
 }
 
+void
 request_sigio ()
 {
   croak ("request sigio");
 }
 
 request_sigio ()
 {
   croak ("request sigio");
 }
 
+void
 unrequest_sigio ()
 {
   croak ("unrequest sigio");
 unrequest_sigio ()
 {
   croak ("unrequest sigio");
@@ -2026,6 +2190,7 @@ unrequest_sigio ()
  *
  */
 
  *
  */
 
+#if !(defined (__NetBSD__) && defined (__ELF__))
 #ifndef HAVE_TEXT_START
 char *
 start_of_text ()
 #ifndef HAVE_TEXT_START
 char *
 start_of_text ()
@@ -2043,6 +2208,7 @@ start_of_text ()
 #endif /* TEXT_START */
 }
 #endif /* not HAVE_TEXT_START */
 #endif /* TEXT_START */
 }
 #endif /* not HAVE_TEXT_START */
+#endif
 
 /*
  *     Return the address of the start of the data segment prior to
 
 /*
  *     Return the address of the start of the data segment prior to
@@ -2069,7 +2235,8 @@ start_of_text ()
  *     will be patched by unexec to the correct value.
  *
  */
  *     will be patched by unexec to the correct value.
  *
  */
+
+#ifndef start_of_data
 char *
 start_of_data ()
 {
 char *
 start_of_data ()
 {
@@ -2085,51 +2252,15 @@ start_of_data ()
    */
   extern char **environ;
 
    */
   extern char **environ;
 
-  return((char *) &environ);
+  return ((char *) &environ);
 #else
   extern int data_start;
   return ((char *) &data_start);
 #endif /* ORDINARY_LINK */
 #endif /* DATA_START */
 }
 #else
   extern int data_start;
   return ((char *) &data_start);
 #endif /* ORDINARY_LINK */
 #endif /* DATA_START */
 }
+#endif /* start_of_data */
 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
-
-#ifndef CANNOT_DUMP
-/* Some systems that cannot dump also cannot implement these.  */
-
-/*
- *     Return the address of the end of the text segment prior to
- *     doing an unexec.  After unexec the return value is undefined.
- */
-char *
-end_of_text ()
-{
-#ifdef TEXT_END
-  return ((char *) TEXT_END);
-#else
-  extern int etext;
-  return ((char *) &etext);
-#endif
-}
-/*
- *     Return the address of the end of the data segment prior to
- *     doing an unexec.  After unexec the return value is undefined.
- */
-
-char *
-end_of_data ()
-{
-#ifdef DATA_END
-  return ((char *) DATA_END);
-#else
-  extern int edata;
-  return ((char *) &edata);
-#endif
-}
-
-#endif /* not CANNOT_DUMP */
 \f
 /* init_system_name sets up the string for the Lisp function
    system-name to return. */
 \f
 /* init_system_name sets up the string for the Lisp function
    system-name to return. */
@@ -2149,6 +2280,12 @@ extern Lisp_Object Vsystem_name;
 #endif /* not VMS */
 #endif /* not BSD4_1 */
 
 #endif /* not VMS */
 #endif /* not BSD4_1 */
 
+#ifdef TRY_AGAIN
+#ifndef HAVE_H_ERRNO
+extern int h_errno;
+#endif
+#endif /* TRY_AGAIN */
+
 void
 init_system_name ()
 {
 void
 init_system_name ()
 {
@@ -2195,53 +2332,64 @@ init_system_name ()
 #ifndef CANNOT_DUMP
   if (initialized)
 #endif /* not CANNOT_DUMP */
 #ifndef CANNOT_DUMP
   if (initialized)
 #endif /* not CANNOT_DUMP */
-    {
-      struct hostent *hp;
-      int count;
-      for (count = 0; count < 10; count++)
-       {
+    if (! index (hostname, '.'))
+      {
+       struct hostent *hp;
+       int count;
+       for (count = 0;; count++)
+         {
 #ifdef TRY_AGAIN
 #ifdef TRY_AGAIN
-         h_errno = 0;
+           h_errno = 0;
 #endif
 #endif
-         hp = gethostbyname (hostname);
+           hp = gethostbyname (hostname);
 #ifdef TRY_AGAIN
 #ifdef TRY_AGAIN
-         if (! (hp == 0 && h_errno == TRY_AGAIN))
+           if (! (hp == 0 && h_errno == TRY_AGAIN))
 #endif
 #endif
-           break;
-         Fsleep_for (make_number (1), Qnil);
-       }
-      if (hp)
-       {
-         char *fqdn = (char *) hp->h_name;
-         char *p;
-
-         if (!index (fqdn, '.'))
-           {
-             /* We still don't have a fully qualified domain name.
-                Try to find one in the list of alternate names */
-             char **alias = hp->h_aliases;
-             while (*alias && !index (*alias, '.'))
-               alias++;
-             if (*alias)
-               fqdn = *alias;
-           }
-         hostname = fqdn;
+             break;
+           if (count >= 5)
+             break;
+           Fsleep_for (make_number (1), Qnil);
+         }
+       if (hp)
+         {
+           char *fqdn = (char *) hp->h_name;
 #if 0
 #if 0
-         /* Convert the host name to lower case.  */
-         /* Using ctype.h here would introduce a possible locale
-            dependence that is probably wrong for hostnames.  */
-         p = hostname;
-         while (*p)
-           {
-             if (*p >= 'A' && *p <= 'Z')
-               *p += 'a' - 'A';
-             p++;
-           }
+           char *p;
+#endif
+
+           if (!index (fqdn, '.'))
+             {
+               /* We still don't have a fully qualified domain name.
+                  Try to find one in the list of alternate names */
+               char **alias = hp->h_aliases;
+               while (*alias && !index (*alias, '.'))
+                 alias++;
+               if (*alias)
+                 fqdn = *alias;
+             }
+           hostname = fqdn;
+#if 0
+           /* Convert the host name to lower case.  */
+           /* Using ctype.h here would introduce a possible locale
+              dependence that is probably wrong for hostnames.  */
+           p = hostname;
+           while (*p)
+             {
+               if (*p >= 'A' && *p <= 'Z')
+                 *p += 'a' - 'A';
+               p++;
+             }
 #endif
 #endif
-       }
-    }
+         }
+      }
 #endif /* HAVE_SOCKETS */
 #endif /* HAVE_SOCKETS */
-#if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN)) || HAVE_GETDOMAINNAME
+  /* We used to try using getdomainname here,
+     but NIIBE Yutaka <gniibe@etl.go.jp> says that
+     getdomainname gets the NIS/YP domain which often is not the same
+     as in Internet domain name.  */
+#if 0 /* Turned off because sysinfo is not really likely to return the
+        correct Internet domain.  */
+#if (HAVE_SYSINFO && defined (SI_SRPC_DOMAIN))
   if (! index (hostname, '.'))
     {
       /* The hostname is not fully qualified.  Append the domain name.  */
   if (! index (hostname, '.'))
     {
       /* The hostname is not fully qualified.  Append the domain name.  */
@@ -2251,9 +2399,8 @@ init_system_name ()
 
       for (;;)
        {
 
       for (;;)
        {
-         char *fqdn = (char *) alloca (hostlen + 1 + domain_size);
-         char *domain = fqdn + hostlen + 1;
-#if HAVE_SYSINFO && defined (SI_SRPC_DOMAIN)
+         char *domain = (char *) alloca (domain_size + 1);
+         char *fqdn = (char *) alloca (hostlen + 1 + domain_size + 1);
          int sys_domain_size = sysinfo (SI_SRPC_DOMAIN, domain, domain_size);
          if (sys_domain_size <= 0)
            break;
          int sys_domain_size = sysinfo (SI_SRPC_DOMAIN, domain, domain_size);
          if (sys_domain_size <= 0)
            break;
@@ -2262,30 +2409,27 @@ init_system_name ()
              domain_size = sys_domain_size;
              continue;
            }
              domain_size = sys_domain_size;
              continue;
            }
-#else /* HAVE_GETDOMAINNAME */
-         if (getdomainname (domain, domain_size - 1) != 0 || ! *domain)
-           break;
-         domain[domain_size - 1] = '\0';
-         if (strlen (domain) == domain_size - 1)
+         strcpy (fqdn, hostname);
+         if (domain[0] == '.')
+           strcpy (fqdn + hostlen, domain);
+         else if (domain[0] != 0)
            {
            {
-             domain_size *= 2;
-             continue;
+             fqdn[hostlen] = '.';
+             strcpy (fqdn + hostlen + 1, domain);
            }
            }
-#endif /* HAVE_GETDOMAINNAME */
-         strcpy (fqdn, hostname);
-         fqdn[hostlen] = '.';
          hostname = fqdn;
          break;
        }
     }
          hostname = fqdn;
          break;
        }
     }
-#endif /*! ((HAVE_SYSINFO && defined (SI_SRPC_DOMAIN)) || HAVE_GETDOMAINNAME)*/
+#endif /* HAVE_SYSINFO && defined (SI_SRPC_DOMAIN) */
+#endif /* 0 */
   Vsystem_name = build_string (hostname);
 #endif /* HAVE_GETHOSTNAME */
 #endif /* VMS */
 #endif /* BSD4_1 */
   {
     unsigned char *p;
   Vsystem_name = build_string (hostname);
 #endif /* HAVE_GETHOSTNAME */
 #endif /* VMS */
 #endif /* BSD4_1 */
   {
     unsigned char *p;
-    for (p = XSTRING (Vsystem_name)->data; *p; p++)
+    for (p = SDATA (Vsystem_name); *p; p++)
       if (*p == ' ' || *p == '\t')
        *p = '-';
   }
       if (*p == ' ' || *p == '\t')
        *p = '-';
   }
@@ -2341,7 +2485,7 @@ sys_select (nfds, rfds, wfds, efds, timeout)
      SELECT_TYPE *rfds, *wfds, *efds;
      EMACS_TIME *timeout;
 {
      SELECT_TYPE *rfds, *wfds, *efds;
      EMACS_TIME *timeout;
 {
-  int ravail = 0, old_alarm;
+  int ravail = 0;
   SELECT_TYPE orfds;
   int timeoutval;
   int *local_timeout;
   SELECT_TYPE orfds;
   int timeoutval;
   int *local_timeout;
@@ -2351,7 +2495,6 @@ sys_select (nfds, rfds, wfds, efds, timeout)
 #else
   extern int process_tick, update_tick;
 #endif
 #else
   extern int process_tick, update_tick;
 #endif
-  SIGTYPE (*old_trap) ();
   unsigned char buf;
 
 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
   unsigned char buf;
 
 #if defined (HAVE_SELECT) && defined (HAVE_X_WINDOWS)
@@ -2392,7 +2535,7 @@ sys_select (nfds, rfds, wfds, efds, timeout)
   /* Once a second, till the timer expires, check all the flagged read
    * descriptors to see if any input is available.  If there is some then
    * set the corresponding bit in the return copy of rfds.
   /* Once a second, till the timer expires, check all the flagged read
    * descriptors to see if any input is available.  If there is some then
    * set the corresponding bit in the return copy of rfds.
-   */ 
+   */
   while (1)
     {
       register int to_check, fd;
   while (1)
     {
       register int to_check, fd;
@@ -2434,10 +2577,12 @@ sys_select (nfds, rfds, wfds, efds, timeout)
        }
       if (*local_timeout == 0 || ravail != 0 || process_tick != update_tick)
        break;
        }
       if (*local_timeout == 0 || ravail != 0 || process_tick != update_tick)
        break;
-      old_alarm = alarm (0);
-      old_trap = signal (SIGALRM, select_alarm);
+
+      turn_on_atimers (0);
+      signal (SIGALRM, select_alarm);
       select_alarmed = 0;
       alarm (SELECT_PAUSE);
       select_alarmed = 0;
       alarm (SELECT_PAUSE);
+
       /* Wait for a SIGALRM (or maybe a SIGTINT) */
       while (select_alarmed == 0 && *local_timeout != 0
             && process_tick == update_tick)
       /* Wait for a SIGALRM (or maybe a SIGTINT) */
       while (select_alarmed == 0 && *local_timeout != 0
             && process_tick == update_tick)
@@ -2455,18 +2600,10 @@ sys_select (nfds, rfds, wfds, efds, timeout)
            pause ();
        }
       (*local_timeout) -= SELECT_PAUSE;
            pause ();
        }
       (*local_timeout) -= SELECT_PAUSE;
-      /* Reset the old alarm if there was one */
-      alarm (0);
-      signal (SIGALRM, old_trap);
-      if (old_alarm != 0)
-       {
-         /* Reset or forge an interrupt for the original handler. */
-         old_alarm -= SELECT_PAUSE;
-         if (old_alarm <= 0)
-           kill (getpid (), SIGALRM); /* Fake an alarm with the orig' handler */
-         else
-           alarm (old_alarm);
-       }
+
+      /* Reset the old alarm if there was one.  */
+      turn_on_atimers (1);
+
       if (*local_timeout == 0)  /* Stop on timer being cleared */
        break;
     }
       if (*local_timeout == 0)  /* Stop on timer being cleared */
        break;
     }
@@ -2484,19 +2621,21 @@ sys_select (nfds, rfds, wfds, efds, timeout)
 #define BUFFER_SIZE_FACTOR 1
 #endif
 
 #define BUFFER_SIZE_FACTOR 1
 #endif
 
+void
 read_input_waiting ()
 {
 read_input_waiting ()
 {
-  struct input_event e;
   int nread, i;
   extern int quit_char;
 
   if (read_socket_hook)
     {
       struct input_event buf[256];
   int nread, i;
   extern int quit_char;
 
   if (read_socket_hook)
     {
       struct input_event buf[256];
-
+      for (i = 0; i < 256; i++)
+       EVENT_INIT (buf[i]);
+      
       read_alarm_should_throw = 0;
       if (! setjmp (read_alarm_throw))
       read_alarm_should_throw = 0;
       if (! setjmp (read_alarm_throw))
-       nread = (*read_socket_hook) (0, buf, 256, 1, 0);
+       nread = (*read_socket_hook) (0, buf, 256, 1);
       else
        nread = -1;
 
       else
        nread = -1;
 
@@ -2506,19 +2645,21 @@ read_input_waiting ()
          kbd_buffer_store_event (&buf[i]);
          /* Don't look at input that follows a C-g too closely.
             This reduces lossage due to autorepeat on C-g.  */
          kbd_buffer_store_event (&buf[i]);
          /* Don't look at input that follows a C-g too closely.
             This reduces lossage due to autorepeat on C-g.  */
-         if (buf[i].kind == ascii_keystroke
+         if (buf[i].kind == ASCII_KEYSTROKE_EVENT
              && buf[i].code == quit_char)
            break;
        }
     }
   else
     {
              && buf[i].code == quit_char)
            break;
        }
     }
   else
     {
+      struct input_event e;
       char buf[3];
       nread = read (fileno (stdin), buf, 1);
       char buf[3];
       nread = read (fileno (stdin), buf, 1);
+      EVENT_INIT (e);
 
       /* Scan the chars for C-g and store them in kbd_buffer.  */
 
       /* Scan the chars for C-g and store them in kbd_buffer.  */
-      e.kind = ascii_keystroke;
-      XSETFRAME (e.frame_or_window, selected_frame);
+      e.kind = ASCII_KEYSTROKE_EVENT;
+      e.frame_or_window = selected_frame;
       e.modifiers = 0;
       for (i = 0; i < nread; i++)
        {
       e.modifiers = 0;
       for (i = 0; i < nread; i++)
        {
@@ -2548,25 +2689,7 @@ read_input_waiting ()
 #endif /* not MSDOS */
 \f
 #ifdef BSD4_1
 #endif /* not MSDOS */
 \f
 #ifdef BSD4_1
-/*
- * Partially emulate 4.2 open call.
- * open is defined as this in 4.1.
- *
- * - added by Michael Bloom @ Citicorp/TTI
- *
- */
-
-int
-sys_open (path, oflag, mode)
-     char *path;
-     int oflag, mode;
-{
-  if (oflag & O_CREAT) 
-    return creat (path, mode);
-  else
-    return open (path, oflag);
-}
-
+void
 init_sigio (fd)
      int fd;
 {
 init_sigio (fd)
      int fd;
 {
@@ -2576,6 +2699,7 @@ init_sigio (fd)
   ioctl (fd, TIOCLSET, &lmode);
 }
 
   ioctl (fd, TIOCLSET, &lmode);
 }
 
+void
 reset_sigio ()
 {
   if (noninteractive)
 reset_sigio ()
 {
   if (noninteractive)
@@ -2584,6 +2708,7 @@ reset_sigio ()
   ioctl (0, TIOCLSET, &lmode);
 }
 
   ioctl (0, TIOCLSET, &lmode);
 }
 
+void
 request_sigio ()
 {
   sigrelse (SIGTINT);
 request_sigio ()
 {
   sigrelse (SIGTINT);
@@ -2591,6 +2716,7 @@ request_sigio ()
   interrupts_deferred = 0;
 }
 
   interrupts_deferred = 0;
 }
 
+void
 unrequest_sigio ()
 {
   sighold (SIGTINT);
 unrequest_sigio ()
 {
   sighold (SIGTINT);
@@ -2603,6 +2729,7 @@ unrequest_sigio ()
 
 int sigheld; /* Mask of held signals */
 
 
 int sigheld; /* Mask of held signals */
 
+void
 sigholdx (signum)
      int signum;
 {
 sigholdx (signum)
      int signum;
 {
@@ -2610,12 +2737,14 @@ sigholdx (signum)
   sighold (signum);
 }
 
   sighold (signum);
 }
 
+void
 sigisheld (signum)
      int signum;
 {
   sigheld |= sigbit (signum);
 }
 
 sigisheld (signum)
      int signum;
 {
   sigheld |= sigbit (signum);
 }
 
+void
 sigunhold (signum)
      int signum;
 {
 sigunhold (signum)
      int signum;
 {
@@ -2623,6 +2752,7 @@ sigunhold (signum)
   sigrelse (signum);
 }
 
   sigrelse (signum);
 }
 
+void
 sigfree ()    /* Free all held signals */
 {
   int i;
 sigfree ()    /* Free all held signals */
 {
   int i;
@@ -2632,6 +2762,7 @@ sigfree ()    /* Free all held signals */
   sigheld = 0;
 }
 
   sigheld = 0;
 }
 
+int
 sigbit (i)
 {
   return 1 << (i - 1);
 sigbit (i)
 {
   return 1 << (i - 1);
@@ -2644,36 +2775,26 @@ sigbit (i)
 
 #ifdef POSIX_SIGNALS
 
 
 #ifdef POSIX_SIGNALS
 
-sigset_t old_mask, empty_mask, full_mask, temp_mask;
-static struct sigaction new_action, old_action;
-
-init_signals ()
-{
-  sigemptyset (&empty_mask);
-  sigfillset (&full_mask);
-}
+sigset_t empty_mask, full_mask;
 
 signal_handler_t
 sys_signal (int signal_number, signal_handler_t action)
 {
 
 signal_handler_t
 sys_signal (int signal_number, signal_handler_t action)
 {
-#ifdef DGUX
-  /* This gets us restartable system calls for efficiency.
-     The "else" code will works as well. */
-  return (berk_signal (signal_number, action));
-#else
+  struct sigaction new_action, old_action;
   sigemptyset (&new_action.sa_mask);
   new_action.sa_handler = action;
   sigemptyset (&new_action.sa_mask);
   new_action.sa_handler = action;
-#ifdef SA_RESTART
+#if defined (SA_RESTART) && ! defined (BROKEN_SA_RESTART)
   /* Emacs mostly works better with restartable system services. If this
   /* Emacs mostly works better with restartable system services. If this
-   * flag exists, we probably want to turn it on here.
-   */
+     flag exists, we probably want to turn it on here.
+     However, on some systems this resets the timeout of `select'
+     which means that `select' never finishes if it keeps getting signals.
+     BROKEN_SA_RESTART is defined on those systems.  */
   new_action.sa_flags = SA_RESTART;
 #else
   new_action.sa_flags = 0;
 #endif
   sigaction (signal_number, &new_action, &old_action);
   return (old_action.sa_handler);
   new_action.sa_flags = SA_RESTART;
 #else
   new_action.sa_flags = 0;
 #endif
   sigaction (signal_number, &new_action, &old_action);
   return (old_action.sa_handler);
-#endif /* DGUX */
 }
 
 #ifndef __GNUC__
 }
 
 #ifndef __GNUC__
@@ -2689,14 +2810,6 @@ sys_sigmask (int sig)
 }
 #endif
 
 }
 #endif
 
-int
-sys_sigpause (sigset_t new_mask)
-{
-  /* pause emulating berk sigpause... */
-  sigsuspend (&new_mask);
-  return (EINTR);
-}
-
 /* I'd like to have these guys return pointers to the mask storage in here,
    but there'd be trouble if the code was saving multiple masks.  I'll be
    safe and pass the structure.  It normally won't be more than 2 bytes
 /* I'd like to have these guys return pointers to the mask storage in here,
    but there'd be trouble if the code was saving multiple masks.  I'll be
    safe and pass the structure.  It normally won't be more than 2 bytes
@@ -2728,6 +2841,185 @@ sys_sigsetmask (sigset_t new_mask)
 
 #endif /* POSIX_SIGNALS */
 \f
 
 #endif /* POSIX_SIGNALS */
 \f
+#if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
+static char *my_sys_siglist[NSIG];
+# ifdef sys_siglist
+#  undef sys_siglist
+# endif
+# define sys_siglist my_sys_siglist
+#endif
+
+void
+init_signals ()
+{
+#ifdef POSIX_SIGNALS
+  sigemptyset (&empty_mask);
+  sigfillset (&full_mask);
+#endif
+
+#if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST
+  if (! initialized)
+    {
+# ifdef SIGABRT
+      sys_siglist[SIGABRT] = "Aborted";
+# endif
+# ifdef SIGAIO
+      sys_siglist[SIGAIO] = "LAN I/O interrupt";
+# endif
+# ifdef SIGALRM
+      sys_siglist[SIGALRM] = "Alarm clock";
+# endif
+# ifdef SIGBUS
+      sys_siglist[SIGBUS] = "Bus error";
+# endif
+# ifdef SIGCLD
+      sys_siglist[SIGCLD] = "Child status changed";
+# endif
+# ifdef SIGCHLD
+      sys_siglist[SIGCHLD] = "Child status changed";
+# endif
+# ifdef SIGCONT
+      sys_siglist[SIGCONT] = "Continued";
+# endif
+# ifdef SIGDANGER
+      sys_siglist[SIGDANGER] = "Swap space dangerously low";
+# endif
+# ifdef SIGDGNOTIFY
+      sys_siglist[SIGDGNOTIFY] = "Notification message in queue";
+# endif
+# ifdef SIGEMT
+      sys_siglist[SIGEMT] = "Emulation trap";
+# endif
+# ifdef SIGFPE
+      sys_siglist[SIGFPE] = "Arithmetic exception";
+# endif
+# ifdef SIGFREEZE
+      sys_siglist[SIGFREEZE] = "SIGFREEZE";
+# endif
+# ifdef SIGGRANT
+      sys_siglist[SIGGRANT] = "Monitor mode granted";
+# endif
+# ifdef SIGHUP
+      sys_siglist[SIGHUP] = "Hangup";
+# endif
+# ifdef SIGILL
+      sys_siglist[SIGILL] = "Illegal instruction";
+# endif
+# ifdef SIGINT
+      sys_siglist[SIGINT] = "Interrupt";
+# endif
+# ifdef SIGIO
+      sys_siglist[SIGIO] = "I/O possible";
+# endif
+# ifdef SIGIOINT
+      sys_siglist[SIGIOINT] = "I/O intervention required";
+# endif
+# ifdef SIGIOT
+      sys_siglist[SIGIOT] = "IOT trap";
+# endif
+# ifdef SIGKILL
+      sys_siglist[SIGKILL] = "Killed";
+# endif
+# ifdef SIGLOST
+      sys_siglist[SIGLOST] = "Resource lost";
+# endif
+# ifdef SIGLWP
+      sys_siglist[SIGLWP] = "SIGLWP";
+# endif
+# ifdef SIGMSG
+      sys_siglist[SIGMSG] = "Monitor mode data available";
+# endif
+# ifdef SIGPHONE
+      sys_siglist[SIGWIND] = "SIGPHONE";
+# endif
+# ifdef SIGPIPE
+      sys_siglist[SIGPIPE] = "Broken pipe";
+# endif
+# ifdef SIGPOLL
+      sys_siglist[SIGPOLL] = "Pollable event occurred";
+# endif
+# ifdef SIGPROF
+      sys_siglist[SIGPROF] = "Profiling timer expired";
+# endif
+# ifdef SIGPTY
+      sys_siglist[SIGPTY] = "PTY I/O interrupt";
+# endif
+# ifdef SIGPWR
+      sys_siglist[SIGPWR] = "Power-fail restart";
+# endif
+# ifdef SIGQUIT
+      sys_siglist[SIGQUIT] = "Quit";
+# endif
+# ifdef SIGRETRACT
+      sys_siglist[SIGRETRACT] = "Need to relinguish monitor mode";
+# endif
+# ifdef SIGSAK
+      sys_siglist[SIGSAK] = "Secure attention";
+# endif
+# ifdef SIGSEGV
+      sys_siglist[SIGSEGV] = "Segmentation violation";
+# endif
+# ifdef SIGSOUND
+      sys_siglist[SIGSOUND] = "Sound completed";
+# endif
+# ifdef SIGSTOP
+      sys_siglist[SIGSTOP] = "Stopped (signal)";
+# endif
+# ifdef SIGSTP
+      sys_siglist[SIGSTP] = "Stopped (user)";
+# endif
+# ifdef SIGSYS
+      sys_siglist[SIGSYS] = "Bad argument to system call";
+# endif
+# ifdef SIGTERM
+      sys_siglist[SIGTERM] = "Terminated";
+# endif
+# ifdef SIGTHAW
+      sys_siglist[SIGTHAW] = "SIGTHAW";
+# endif
+# ifdef SIGTRAP
+      sys_siglist[SIGTRAP] = "Trace/breakpoint trap";
+# endif
+# ifdef SIGTSTP
+      sys_siglist[SIGTSTP] = "Stopped (user)";
+# endif
+# ifdef SIGTTIN
+      sys_siglist[SIGTTIN] = "Stopped (tty input)";
+# endif
+# ifdef SIGTTOU
+      sys_siglist[SIGTTOU] = "Stopped (tty output)";
+# endif
+# ifdef SIGURG
+      sys_siglist[SIGURG] = "Urgent I/O condition";
+# endif
+# ifdef SIGUSR1
+      sys_siglist[SIGUSR1] = "User defined signal 1";
+# endif
+# ifdef SIGUSR2
+      sys_siglist[SIGUSR2] = "User defined signal 2";
+# endif
+# ifdef SIGVTALRM
+      sys_siglist[SIGVTALRM] = "Virtual timer expired";
+# endif
+# ifdef SIGWAITING
+      sys_siglist[SIGWAITING] = "Process's LWPs are blocked";
+# endif
+# ifdef SIGWINCH
+      sys_siglist[SIGWINCH] = "Window size changed";
+# endif
+# ifdef SIGWIND
+      sys_siglist[SIGWIND] = "SIGWIND";
+# endif
+# ifdef SIGXCPU
+      sys_siglist[SIGXCPU] = "CPU time limit exceeded";
+# endif
+# ifdef SIGXFSZ
+      sys_siglist[SIGXFSZ] = "File size limit exceeded";
+# endif
+    }
+#endif /* !defined HAVE_STRSIGNAL && !defined HAVE_DECL_SYS_SIGLIST */
+}
+\f
 #ifndef HAVE_RANDOM
 #ifdef random
 #define HAVE_RANDOM
 #ifndef HAVE_RANDOM
 #ifdef random
 #define HAVE_RANDOM
@@ -2935,26 +3227,25 @@ strerror (errnum)
 #endif /* not WINDOWSNT */
 #endif /* ! HAVE_STRERROR */
 \f
 #endif /* not WINDOWSNT */
 #endif /* ! HAVE_STRERROR */
 \f
-#ifdef INTERRUPTIBLE_OPEN
-
 int
 int
-/* VARARGS 2 */
-sys_open (path, oflag, mode)
-     char *path;
+emacs_open (path, oflag, mode)
+     const char *path;
      int oflag, mode;
 {
   register int rtnval;
      int oflag, mode;
 {
   register int rtnval;
-  
+
+#ifdef BSD4_1
+  if (oflag & O_CREAT)
+    return creat (path, mode);
+#endif
+
   while ((rtnval = open (path, oflag, mode)) == -1
         && (errno == EINTR));
   return (rtnval);
 }
 
   while ((rtnval = open (path, oflag, mode)) == -1
         && (errno == EINTR));
   return (rtnval);
 }
 
-#endif /* INTERRUPTIBLE_OPEN */
-
-#ifdef INTERRUPTIBLE_CLOSE
-
-sys_close (fd)
+int
+emacs_close (fd)
      int fd;
 {
   int did_retry = 0;
      int fd;
 {
   int did_retry = 0;
@@ -2973,27 +3264,23 @@ sys_close (fd)
   return rtnval;
 }
 
   return rtnval;
 }
 
-#endif /* INTERRUPTIBLE_CLOSE */
-
-#ifdef INTERRUPTIBLE_IO
-
 int
 int
-sys_read (fildes, buf, nbyte)
+emacs_read (fildes, buf, nbyte)
      int fildes;
      char *buf;
      unsigned int nbyte;
 {
   register int rtnval;
      int fildes;
      char *buf;
      unsigned int nbyte;
 {
   register int rtnval;
-  
+
   while ((rtnval = read (fildes, buf, nbyte)) == -1
         && (errno == EINTR));
   return (rtnval);
 }
 
 int
   while ((rtnval = read (fildes, buf, nbyte)) == -1
         && (errno == EINTR));
   return (rtnval);
 }
 
 int
-sys_write (fildes, buf, nbyte)
+emacs_write (fildes, buf, nbyte)
      int fildes;
      int fildes;
-     char *buf;
+     const char *buf;
      unsigned int nbyte;
 {
   register int rtnval, bytes_written;
      unsigned int nbyte;
 {
   register int rtnval, bytes_written;
@@ -3018,22 +3305,6 @@ sys_write (fildes, buf, nbyte)
     }
   return (bytes_written);
 }
     }
   return (bytes_written);
 }
-
-#endif /* INTERRUPTIBLE_IO */
-\f
-#ifndef HAVE_VFORK
-#ifndef WINDOWSNT
-/*
- *      Substitute fork for vfork on USG flavors.
- */
-
-VFORK_RETURN_TYPE
-vfork ()
-{
-  return (fork ());
-}
-#endif /* not WINDOWSNT */
-#endif /* not HAVE_VFORK */
 \f
 #ifdef USG
 /*
 \f
 #ifdef USG
 /*
@@ -3051,93 +3322,6 @@ vfork ()
  *     always negligible.   Fred Fish, Unisoft Systems Inc.
  */
 
  *     always negligible.   Fred Fish, Unisoft Systems Inc.
  */
 
-#ifndef HAVE_SYS_SIGLIST
-char *sys_siglist[NSIG + 1] =
-{
-#ifdef AIX
-/* AIX has changed the signals a bit */
-  "bogus signal",                      /* 0 */
-  "hangup",                            /* 1  SIGHUP */
-  "interrupt",                         /* 2  SIGINT */
-  "quit",                              /* 3  SIGQUIT */
-  "illegal instruction",               /* 4  SIGILL */
-  "trace trap",                                /* 5  SIGTRAP */
-  "IOT instruction",                   /* 6  SIGIOT */
-  "crash likely",                      /* 7  SIGDANGER */
-  "floating point exception",          /* 8  SIGFPE */
-  "kill",                              /* 9  SIGKILL */
-  "bus error",                         /* 10 SIGBUS */
-  "segmentation violation",            /* 11 SIGSEGV */
-  "bad argument to system call",       /* 12 SIGSYS */
-  "write on a pipe with no one to read it", /* 13 SIGPIPE */
-  "alarm clock",                       /* 14 SIGALRM */
-  "software termination signum",       /* 15 SIGTERM */
-  "user defined signal 1",             /* 16 SIGUSR1 */
-  "user defined signal 2",             /* 17 SIGUSR2 */
-  "death of a child",                  /* 18 SIGCLD */
-  "power-fail restart",                        /* 19 SIGPWR */
-  "bogus signal",                      /* 20 */
-  "bogus signal",                      /* 21 */
-  "bogus signal",                      /* 22 */
-  "bogus signal",                      /* 23 */
-  "bogus signal",                      /* 24 */
-  "LAN I/O interrupt",                 /* 25 SIGAIO */
-  "PTY I/O interrupt",                 /* 26 SIGPTY */
-  "I/O intervention required",         /* 27 SIGIOINT */
-#ifdef AIXHFT
-  "HFT grant",                         /* 28 SIGGRANT */
-  "HFT retract",                       /* 29 SIGRETRACT */
-  "HFT sound done",                    /* 30 SIGSOUND */
-  "HFT input ready",                   /* 31 SIGMSG */
-#endif
-#else /* not AIX */
-  "bogus signal",                      /* 0 */
-  "hangup",                            /* 1  SIGHUP */
-  "interrupt",                         /* 2  SIGINT */
-  "quit",                              /* 3  SIGQUIT */
-  "illegal instruction",               /* 4  SIGILL */
-  "trace trap",                                /* 5  SIGTRAP */
-  "IOT instruction",                   /* 6  SIGIOT */
-  "EMT instruction",                   /* 7  SIGEMT */
-  "floating point exception",          /* 8  SIGFPE */
-  "kill",                              /* 9  SIGKILL */
-  "bus error",                         /* 10 SIGBUS */
-  "segmentation violation",            /* 11 SIGSEGV */
-  "bad argument to system call",       /* 12 SIGSYS */
-  "write on a pipe with no one to read it", /* 13 SIGPIPE */
-  "alarm clock",                       /* 14 SIGALRM */
-  "software termination signum",       /* 15 SIGTERM */
-  "user defined signal 1",             /* 16 SIGUSR1 */
-  "user defined signal 2",             /* 17 SIGUSR2 */
-  "death of a child",                  /* 18 SIGCLD */
-  "power-fail restart",                        /* 19 SIGPWR */
-#ifdef sun
-  "window size change",                            /* 20 SIGWINCH */
-  "urgent socket condition",               /* 21 SIGURG */
-  "pollable event occurred",               /* 22 SIGPOLL */
-  "stop (cannot be caught or ignored)", /*  23 SIGSTOP */
-  "user stop requested from tty",          /* 24 SIGTSTP */
-  "stopped process has been continued",        /* 25 SIGCONT */
-  "background tty read attempted",         /* 26 SIGTTIN */
-  "background tty write attempted",    /* 27 SIGTTOU */
-  "virtual timer expired",                 /* 28 SIGVTALRM */
-  "profiling timer expired",               /* 29 SIGPROF */
-  "exceeded cpu limit",                            /* 30 SIGXCPU */
-  "exceeded file size limit",              /* 31 SIGXFSZ */
-  "process's lwps are blocked",            /*  32 SIGWAITING */
-  "special signal used by thread library", /* 33 SIGLWP */
-#ifdef SIGFREEZE
-  "Special Signal Used By CPR",            /* 34 SIGFREEZE */
-#endif
-#ifdef SIGTHAW
-  "Special Signal Used By CPR",            /* 35 SIGTHAW */
-#endif
-#endif /* sun */
-#endif /* not AIX */
-  0
-  };
-#endif /* HAVE_SYS_SIGLIST */
-
 /*
  *     Warning, this function may not duplicate 4.2 action properly
  *     under error conditions.
 /*
  *     Warning, this function may not duplicate 4.2 action properly
  *     under error conditions.
@@ -3160,7 +3344,10 @@ getwd (pathname)
   BLOCK_INPUT;                 /* getcwd uses malloc */
   spath = npath = getcwd ((char *) 0, MAXPATHLEN);
   if (spath == 0)
   BLOCK_INPUT;                 /* getcwd uses malloc */
   spath = npath = getcwd ((char *) 0, MAXPATHLEN);
   if (spath == 0)
-    return spath;
+    {
+      UNBLOCK_INPUT;
+      return spath;
+    }
   /* On Altos 3068, getcwd can return @hostname/dir, so discard
      up to first slash.  Should be harmless on other systems.  */
   while (*npath && *npath != '/')
   /* On Altos 3068, getcwd can return @hostname/dir, so discard
      up to first slash.  Should be harmless on other systems.  */
   while (*npath && *npath != '/')
@@ -3224,13 +3411,11 @@ dup2 (oldd, newd)
      int newd;
 {
   register int fd, ret;
      int newd;
 {
   register int fd, ret;
-  
-  sys_close (newd);
+
+  emacs_close (newd);
 
 #ifdef F_DUPFD
 
 #ifdef F_DUPFD
-  fd = fcntl (oldd, F_DUPFD, newd);
-  if (fd != newd)
-    error ("can't dup2 (%i,%i) : %s", oldd, newd, strerror (errno));
+  return fcntl (oldd, F_DUPFD, newd);
 #else
   fd = dup (old);
   if (fd == -1)
 #else
   fd = dup (old);
   if (fd == -1)
@@ -3238,7 +3423,7 @@ dup2 (oldd, newd)
   if (fd == new)
     return new;
   ret = dup2 (old,new);
   if (fd == new)
     return new;
   ret = dup2 (old,new);
-  sys_close (fd);
+  emacs_close (fd);
   return ret;
 #endif
 }
   return ret;
 #endif
 }
@@ -3255,29 +3440,32 @@ dup2 (oldd, newd)
 #ifndef VMS
 #ifndef HAVE_GETTIMEOFDAY
 #ifdef HAVE_TIMEVAL
 #ifndef VMS
 #ifndef HAVE_GETTIMEOFDAY
 #ifdef HAVE_TIMEVAL
+
 /* ARGSUSED */
 /* ARGSUSED */
+int
 gettimeofday (tp, tzp)
      struct timeval *tp;
      struct timezone *tzp;
 {
   extern long time ();
 
 gettimeofday (tp, tzp)
      struct timeval *tp;
      struct timezone *tzp;
 {
   extern long time ();
 
-  tp->tv_sec = time ((long *)0);    
+  tp->tv_sec = time ((long *)0);
   tp->tv_usec = 0;
   if (tzp != 0)
     tzp->tz_minuteswest = -1;
   tp->tv_usec = 0;
   if (tzp != 0)
     tzp->tz_minuteswest = -1;
+  return 0;
 }
 }
+
 #endif
 #endif
 #endif
 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
 #endif
 #endif
 #endif
 #endif /* subprocess && !HAVE_GETTIMEOFDAY && HAVE_TIMEVAL && !VMS */
-  
+
 /*
  *     This function will go away as soon as all the stubs fixed. (fnf)
  */
 
 /*
  *     This function will go away as soon as all the stubs fixed. (fnf)
  */
 
+void
 croak (badfunc)
      char *badfunc;
 {
 croak (badfunc)
      char *badfunc;
 {
@@ -3288,87 +3476,13 @@ croak (badfunc)
 
 #endif /* USG */
 \f
 
 #endif /* USG */
 \f
-#ifdef DGUX
-
-char *sys_siglist[NSIG + 1] =
-{
-  "null signal",                        /*  0 SIGNULL   */
-  "hangup",                             /*  1 SIGHUP    */
-  "interrupt",                          /*  2 SIGINT    */
-  "quit",                               /*  3 SIGQUIT   */
-  "illegal instruction",                /*  4 SIGILL    */
-  "trace trap",                                 /*  5 SIGTRAP   */
-  "abort termination",                  /*  6 SIGABRT   */
-  "SIGEMT",                             /*  7 SIGEMT    */
-  "floating point exception",           /*  8 SIGFPE    */
-  "kill",                               /*  9 SIGKILL   */
-  "bus error",                          /* 10 SIGBUS    */
-  "segmentation violation",             /* 11 SIGSEGV   */
-  "bad argument to system call",        /* 12 SIGSYS    */
-  "write on a pipe with no reader",     /* 13 SIGPIPE   */
-  "alarm clock",                        /* 14 SIGALRM   */
-  "software termination signal",        /* 15 SIGTERM   */
-  "user defined signal 1",              /* 16 SIGUSR1   */
-  "user defined signal 2",              /* 17 SIGUSR2   */
-  "child stopped or terminated",        /* 18 SIGCLD    */
-  "power-fail restart",                         /* 19 SIGPWR    */
-  "window size changed",                /* 20 SIGWINCH  */
-  "undefined",                          /* 21           */
-  "pollable event occurred",            /* 22 SIGPOLL   */
-  "sendable stop signal not from tty",  /* 23 SIGSTOP   */
-  "stop signal from tty",               /* 24 SIGSTP    */
-  "continue a stopped process",                 /* 25 SIGCONT   */
-  "attempted background tty read",      /* 26 SIGTTIN   */
-  "attempted background tty write",     /* 27 SIGTTOU   */
-  "undefined",                          /* 28           */
-  "undefined",                          /* 29           */
-  "undefined",                          /* 30           */
-  "undefined",                          /* 31           */
-  "undefined",                          /* 32           */
-  "socket (TCP/IP) urgent data arrival", /* 33 SIGURG    */
-  "I/O is possible",                    /* 34 SIGIO     */
-  "exceeded cpu time limit",            /* 35 SIGXCPU   */
-  "exceeded file size limit",           /* 36 SIGXFSZ   */
-  "virtual time alarm",                         /* 37 SIGVTALRM */
-  "profiling time alarm",               /* 38 SIGPROF   */
-  "undefined",                          /* 39           */
-  "file record locks revoked",          /* 40 SIGLOST   */
-  "undefined",                          /* 41           */
-  "undefined",                          /* 42           */
-  "undefined",                          /* 43           */
-  "undefined",                          /* 44           */
-  "undefined",                          /* 45           */
-  "undefined",                          /* 46           */
-  "undefined",                          /* 47           */
-  "undefined",                          /* 48           */
-  "undefined",                          /* 49           */
-  "undefined",                          /* 50           */
-  "undefined",                          /* 51           */
-  "undefined",                          /* 52           */
-  "undefined",                          /* 53           */
-  "undefined",                          /* 54           */
-  "undefined",                          /* 55           */
-  "undefined",                          /* 56           */
-  "undefined",                          /* 57           */
-  "undefined",                          /* 58           */
-  "undefined",                          /* 59           */
-  "undefined",                          /* 60           */
-  "undefined",                          /* 61           */
-  "undefined",                          /* 62           */
-  "undefined",                          /* 63           */
-  "notification message in mess. queue", /* 64 SIGDGNOTIFY */
-  0
-};
-
-#endif /* DGUX */
-\f
 /* Directory routines for systems that don't have them. */
 
 #ifdef SYSV_SYSTEM_DIR
 
 #include <dirent.h>
 
 /* Directory routines for systems that don't have them. */
 
 #ifdef SYSV_SYSTEM_DIR
 
 #include <dirent.h>
 
-#if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
+#if defined (BROKEN_CLOSEDIR) || !defined (HAVE_CLOSEDIR)
 
 int
 closedir (dirp)
 
 int
 closedir (dirp)
@@ -3376,7 +3490,7 @@ closedir (dirp)
 {
   int rtnval;
 
 {
   int rtnval;
 
-  rtnval = sys_close (dirp->dd_fd);
+  rtnval = emacs_close (dirp->dd_fd);
 
   /* Some systems (like Solaris) allocate the buffer and the DIR all
      in one block.  Why in the world are we freeing this ourselves
 
   /* Some systems (like Solaris) allocate the buffer and the DIR all
      in one block.  Why in the world are we freeing this ourselves
@@ -3401,16 +3515,16 @@ opendir (filename)
   register int fd;             /* file descriptor for read */
   struct stat sbuf;            /* result of fstat */
 
   register int fd;             /* file descriptor for read */
   struct stat sbuf;            /* result of fstat */
 
-  fd = sys_open (filename, 0);
+  fd = emacs_open (filename, O_RDONLY, 0);
   if (fd < 0)
     return 0;
 
   BLOCK_INPUT;
   if (fstat (fd, &sbuf) < 0
       || (sbuf.st_mode & S_IFMT) != S_IFDIR
   if (fd < 0)
     return 0;
 
   BLOCK_INPUT;
   if (fstat (fd, &sbuf) < 0
       || (sbuf.st_mode & S_IFMT) != S_IFDIR
-      || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
+      || (dirp = (DIR *) xmalloc (sizeof (DIR))) == 0)
     {
     {
-      sys_close (fd);
+      emacs_close (fd);
       UNBLOCK_INPUT;
       return 0;                /* bad luck today */
     }
       UNBLOCK_INPUT;
       return 0;                /* bad luck today */
     }
@@ -3426,7 +3540,7 @@ void
 closedir (dirp)
      register DIR *dirp;               /* stream from opendir */
 {
 closedir (dirp)
      register DIR *dirp;               /* stream from opendir */
 {
-  sys_close (dirp->dd_fd);
+  emacs_close (dirp->dd_fd);
   xfree ((char *) dirp);
 }
 
   xfree ((char *) dirp);
 }
 
@@ -3460,7 +3574,7 @@ readdir (dirp)
        dirp->dd_loc = dirp->dd_size = 0;
 
       if (dirp->dd_size == 0   /* refill buffer */
        dirp->dd_loc = dirp->dd_size = 0;
 
       if (dirp->dd_size == 0   /* refill buffer */
-         && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
+         && (dirp->dd_size = emacs_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
        return 0;
 
 #ifndef VMS
        return 0;
 
 #ifndef VMS
@@ -3538,7 +3652,7 @@ readdirver (dirp)
 \f
 int
 set_file_times (filename, atime, mtime)
 \f
 int
 set_file_times (filename, atime, mtime)
-     char *filename;
+     const char *filename;
      EMACS_TIME atime, mtime;
 {
 #ifdef HAVE_UTIMES
      EMACS_TIME atime, mtime;
 {
 #ifdef HAVE_UTIMES
@@ -3613,7 +3727,7 @@ mkdir (dpath, dmode)
                 */
       status = umask (0);      /* Get current umask */
       status = umask (status | (0777 & ~dmode));       /* Set for mkdir */
                 */
       status = umask (0);      /* Get current umask */
       status = umask (status | (0777 & ~dmode));       /* Set for mkdir */
-      fd = sys_open("/dev/null", 2);
+      fd = emacs_open ("/dev/null", O_RDWR, 0);
       if (fd >= 0)
         {
          dup2 (fd, 0);
       if (fd >= 0)
         {
          dup2 (fd, 0);
@@ -3659,7 +3773,7 @@ rmdir (dpath)
       return (-1);             /* Errno is set already */
 
     case 0:                    /* Child process */
       return (-1);             /* Errno is set already */
 
     case 0:                    /* Child process */
-      fd = sys_open("/dev/null", 2);
+      fd = emacs_open ("/dev/null", O_RDWR, 0);
       if (fd >= 0)
         {
          dup2 (fd, 0);
       if (fd >= 0)
         {
          dup2 (fd, 0);
@@ -3713,7 +3827,7 @@ vmserrstr (status)
 
 #ifdef access
 #undef access
 
 #ifdef access
 #undef access
-  
+
 /* The following is necessary because 'access' emulation by VMS C (2.0) does
  * not work correctly.  (It also doesn't work well in version 2.3.)
  */
 /* The following is necessary because 'access' emulation by VMS C (2.0) does
  * not work correctly.  (It also doesn't work well in version 2.3.)
  */
@@ -3754,7 +3868,7 @@ sys_access (path, mode)
    * access can treat the directory like a file.  */
   if (directory_file_name (path, dir_fn))
     path = dir_fn;
    * access can treat the directory like a file.  */
   if (directory_file_name (path, dir_fn))
     path = dir_fn;
-  
+
   if (mode == F_OK)
     return access (path, mode);
   if (user == NULL && (user = (char *) getenv ("USER")) == NULL)
   if (mode == F_OK)
     return access (path, mode);
   if (user == NULL && (user = (char *) getenv ("USER")) == NULL)
@@ -3768,7 +3882,7 @@ sys_access (path, mode)
     static int constant = ACL$C_FILE;
     DESCRIPTOR (path_desc, path);
     DESCRIPTOR (user_desc, user);
     static int constant = ACL$C_FILE;
     DESCRIPTOR (path_desc, path);
     DESCRIPTOR (user_desc, user);
+
     flags = 0;
     acces = 0;
     if ((mode & X_OK) && ((stat = access (path, mode)) < 0 || mode == X_OK))
     flags = 0;
     acces = 0;
     if ((mode & X_OK) && ((stat = access (path, mode)) < 0 || mode == X_OK))
@@ -3802,6 +3916,7 @@ static unsigned int uic;
 
 /* Called from init_sys_modes, so it happens not very often
    but at least each time Emacs is loaded.  */
 
 /* Called from init_sys_modes, so it happens not very often
    but at least each time Emacs is loaded.  */
+void
 sys_access_reinit ()
 {
   uic = 0;
 sys_access_reinit ()
 {
   uic = 0;
@@ -3832,7 +3947,7 @@ sys_access (filename, type)
     return access (filename, type);
 
   /* Check write protection. */
     return access (filename, type);
 
   /* Check write protection. */
-    
+
 #define CHECKPRIV(bit)    (prvmask.bit)
 #define WRITABLE(field)  (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
 
 #define CHECKPRIV(bit)    (prvmask.bit)
 #define WRITABLE(field)  (! ((xab.xab$w_pro >> field) & XAB$M_NOWRITE))
 
@@ -3894,7 +4009,7 @@ sys_access (filename, type)
 }
 #endif /* not VMS4_4 */
 #endif /* access */
 }
 #endif /* not VMS4_4 */
 #endif /* access */
-  
+
 static char vtbuf[NAM$C_MAXRSS+1];
 
 /* translate a vms file spec to a unix path */
 static char vtbuf[NAM$C_MAXRSS+1];
 
 /* translate a vms file spec to a unix path */
@@ -3935,7 +4050,7 @@ sys_translate_vms (vfile)
            *targ++ = '.';
            *targ++ = '.';
            break;
            *targ++ = '.';
            *targ++ = '.';
            break;
-           
+
          default:
            *targ++ = *vfile;
            break;
          default:
            *targ++ = *vfile;
            break;
@@ -4028,7 +4143,7 @@ sys_translate_unix (ufile)
       ufile++;
     }
   *targ = '\0';
       ufile++;
     }
   *targ = '\0';
-  
+
   return utbuf;
 }
 
   return utbuf;
 }
 
@@ -4050,10 +4165,11 @@ getwd (pathname)
     }
   strcpy (pathname, ptr);
   xfree (ptr);
     }
   strcpy (pathname, ptr);
   xfree (ptr);
-  
+
  return pathname;
 }
 
  return pathname;
 }
 
+int
 getppid ()
 {
   long item_code = JPI$_OWNER;
 getppid ()
 {
   long item_code = JPI$_OWNER;
@@ -4076,6 +4192,7 @@ sys_getuid ()
   return (getgid () << 16) | getuid ();
 }
 
   return (getgid () << 16) | getuid ();
 }
 
+#undef read
 int
 sys_read (fildes, buf, nbyte)
      int fildes;
 int
 sys_read (fildes, buf, nbyte)
      int fildes;
@@ -4115,6 +4232,7 @@ sys_write (fildes, buf, nbyte)
  *     Thus we do this stupidity below.
  */
 
  *     Thus we do this stupidity below.
  */
 
+#undef write
 int
 sys_write (fildes, buf, nbytes)
      int fildes;
 int
 sys_write (fildes, buf, nbytes)
      int fildes;
@@ -4249,6 +4367,7 @@ creat_copy_attrs (old, new)
 #endif
 #endif
 
 #endif
 #endif
 
+int
 sys_creat (va_alist)
      va_dcl
 {
 sys_creat (va_alist)
      va_dcl
 {
@@ -4365,6 +4484,7 @@ sys_creat (va_alist)
 #endif /* creat */
 
 /* fwrite to stdout is S L O W.  Speed it up by using fputc...*/
 #endif /* creat */
 
 /* fwrite to stdout is S L O W.  Speed it up by using fputc...*/
+int
 sys_fwrite (ptr, size, num, fp)
      register char * ptr;
      FILE * fp;
 sys_fwrite (ptr, size, num, fp)
      register char * ptr;
      FILE * fp;
@@ -4373,6 +4493,7 @@ sys_fwrite (ptr, size, num, fp)
 
   while (tot--)
     fputc (*ptr++, fp);
 
   while (tot--)
     fputc (*ptr++, fp);
+  return num;
 }
 
 /*
 }
 
 /*
@@ -4381,7 +4502,7 @@ sys_fwrite (ptr, size, num, fp)
  * when this is not the desired behavior, for instance, when writing an
  * auto save file (you only want one version), or when you don't have
  * write permission in the directory containing the file (but the file
  * when this is not the desired behavior, for instance, when writing an
  * auto save file (you only want one version), or when you don't have
  * write permission in the directory containing the file (but the file
- * itself is writable).  Hence this routine, which is equivalent to 
+ * itself is writable).  Hence this routine, which is equivalent to
  * "close (creat (fn, 0));" on Unix if fn already exists.
  */
 int
  * "close (creat (fn, 0));" on Unix if fn already exists.
  */
 int
@@ -4438,7 +4559,7 @@ get_uaf_name (uname)
   register status;
   struct FAB uaf_fab;
   struct RAB uaf_rab;
   register status;
   struct FAB uaf_fab;
   struct RAB uaf_rab;
-  
+
   uaf_fab = cc$rms_fab;
   uaf_rab = cc$rms_rab;
   /* initialize fab fields */
   uaf_fab = cc$rms_fab;
   uaf_rab = cc$rms_rab;
   /* initialize fab fields */
@@ -4502,7 +4623,7 @@ get_uaf_uic (uic)
   register status;
   struct FAB uaf_fab;
   struct RAB uaf_rab;
   register status;
   struct FAB uaf_fab;
   struct RAB uaf_rab;
-  
+
   uaf_fab = cc$rms_fab;
   uaf_rab = cc$rms_rab;
   /* initialize fab fields */
   uaf_fab = cc$rms_fab;
   uaf_rab = cc$rms_rab;
   /* initialize fab fields */
@@ -4660,6 +4781,7 @@ getpwuid (uid)
 /* return total address space available to the current process.  This is
    the sum of the current p0 size, p1 size and free page table entries
    available. */
 /* return total address space available to the current process.  This is
    the sum of the current p0 size, p1 size and free page table entries
    available. */
+int
 vlimit ()
 {
   int item_code;
 vlimit ()
 {
   int item_code;
@@ -4695,6 +4817,7 @@ vlimit ()
   return free_pages + frep0va + (0x7fffffff - frep1va);
 }
 
   return free_pages + frep0va + (0x7fffffff - frep1va);
 }
 
+int
 define_logical_name (varname, string)
      char *varname;
      char *string;
 define_logical_name (varname, string)
      char *varname;
      char *string;
@@ -4709,6 +4832,7 @@ define_logical_name (varname, string)
   return LIB$SET_LOGICAL (&envdsc, &strdsc, &lnmdsc, 0, 0);
 }
 
   return LIB$SET_LOGICAL (&envdsc, &strdsc, &lnmdsc, 0, 0);
 }
 
+int
 delete_logical_name (varname)
      char *varname;
 {
 delete_logical_name (varname)
      char *varname;
 {
@@ -4720,15 +4844,23 @@ delete_logical_name (varname)
   return LIB$DELETE_LOGICAL (&envdsc, &lnmdsc);
 }
 
   return LIB$DELETE_LOGICAL (&envdsc, &lnmdsc);
 }
 
+int
 ulimit ()
 ulimit ()
-{}
+{
+  return 0;
+}
 
 
+int
 setpgrp ()
 setpgrp ()
-{}
+{
+  return 0;
+}
 
 
+int
 execvp ()
 {
   error ("execvp system call not implemented");
 execvp ()
 {
   error ("execvp system call not implemented");
+  return -1;
 }
 
 int
 }
 
 int
@@ -4784,7 +4916,7 @@ rename (from, to)
    bits).  To maintain portability, the VMS implementation of `chmod' wires
    the W and D bits together.  */
 
    bits).  To maintain portability, the VMS implementation of `chmod' wires
    the W and D bits together.  */
 
+
 static struct fibdef fib;      /* We need this initialized to zero */
 char vms_file_written[NAM$C_MAXRSS];
 
 static struct fibdef fib;      /* We need this initialized to zero */
 char vms_file_written[NAM$C_MAXRSS];
 
@@ -4851,6 +4983,7 @@ rename_sans_version (from,to)
   return 0;
 }
 
   return 0;
 }
 
+int
 link (file, new)
      char * file, * new;
 {
 link (file, new)
      char * file, * new;
 {
@@ -4918,6 +5051,7 @@ link (file, new)
   return 0;
 }
 
   return 0;
 }
 
+void
 croak (badfunc)
      char *badfunc;
 {
 croak (badfunc)
      char *badfunc;
 {
@@ -4933,6 +5067,7 @@ random ()
   return rand () - (1 << 30);
 }
 
   return rand () - (1 << 30);
 }
 
+void
 srandom (seed)
 {
   srand (seed);
 srandom (seed)
 {
   srand (seed);
@@ -4942,13 +5077,14 @@ srandom (seed)
 #ifdef AIXHFT
 
 /* Called from init_sys_modes.  */
 #ifdef AIXHFT
 
 /* Called from init_sys_modes.  */
+void
 hft_init ()
 {
   int junk;
 
   /* If we're not on an HFT we shouldn't do any of this.  We determine
      if we are on an HFT by trying to get an HFT error code.  If this
 hft_init ()
 {
   int junk;
 
   /* If we're not on an HFT we shouldn't do any of this.  We determine
      if we are on an HFT by trying to get an HFT error code.  If this
-     call fails, we're not on an HFT. */ 
+     call fails, we're not on an HFT. */
 #ifdef IBMR2AIX
   if (ioctl (0, HFQERROR, &junk) < 0)
     return;
 #ifdef IBMR2AIX
   if (ioctl (0, HFQERROR, &junk) < 0)
     return;
@@ -4962,7 +5098,7 @@ hft_init ()
      there's no way to determine the old mapping, so in reset_sys_modes
      we need to assume that the normal map had been present.  Of course, this
      code also doesn't help if on a terminal emulator which doesn't understand
      there's no way to determine the old mapping, so in reset_sys_modes
      we need to assume that the normal map had been present.  Of course, this
      code also doesn't help if on a terminal emulator which doesn't understand
-     HFT VTD's. */
+     HFT VTD's.  */
   {
     struct hfbuf buf;
     struct hfkeymap keymap;
   {
     struct hfbuf buf;
     struct hfkeymap keymap;
@@ -4993,8 +5129,9 @@ hft_init ()
   line_ins_del_ok = char_ins_del_ok = 0;
 }
 
   line_ins_del_ok = char_ins_del_ok = 0;
 }
 
-/* Reset the rubout key to backspace. */
+/* Reset the rubout key to backspace.  */
 
 
+void
 hft_reset ()
 {
   struct hfbuf buf;
 hft_reset ()
 {
   struct hfbuf buf;
@@ -5114,7 +5251,7 @@ bcopy (b1, b2, length)
     *b2++ = *b1++;
 #endif /* not VMS */
 }
     *b2++ = *b1++;
 #endif /* not VMS */
 }
-#endif /* (defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
+#endif /* (!defined (BSTRING) && !defined (bcopy)) || defined (NEED_BCOPY) */
 
 #ifndef BSTRING
 #ifndef bcmp
 
 #ifndef BSTRING
 #ifndef bcmp
@@ -5139,3 +5276,27 @@ bcmp (b1, b2, length)    /* This could be a macro! */
 }
 #endif /* no bcmp */
 #endif /* not BSTRING */
 }
 #endif /* no bcmp */
 #endif /* not BSTRING */
+\f
+#ifndef HAVE_STRSIGNAL
+char *
+strsignal (code)
+     int code;
+{
+  char *signame = 0;
+
+  if (0 <= code && code < NSIG)
+    {
+#ifdef VMS
+      signame = sys_errlist[code];
+#else
+      /* Cast to suppress warning if the table has const char *.  */
+      signame = (char *) sys_siglist[code];
+#endif
+    }
+
+  return signame;
+}
+#endif /* HAVE_STRSIGNAL */
+
+/* arch-tag: edb43589-4e09-4544-b325-978b5b121dcf
+   (do not change this comment) */