]> code.delx.au - gnu-emacs/blobdiff - src/sysdep.c
Don't declare logb if it is a macro.
[gnu-emacs] / src / sysdep.c
index 42b6ce14d65da46ce89b1372ac54472b2965f420..d7b256c8454e84310507eeb1aa29b41a02e72bd7 100644 (file)
@@ -133,7 +133,7 @@ extern int errno;
 #ifndef MEMORY_IN_STRING_H
 #include <memory.h>
 #endif
-#ifdef TIOCGWINSZ
+#if defined (TIOCGWINSZ) || defined (ISC4_0)
 #ifdef NEED_SIOCTL
 #include <sys/sioctl.h>
 #endif
@@ -141,7 +141,7 @@ extern int errno;
 #include <sys/stream.h>
 #include <sys/ptem.h>
 #endif
-#endif /* TIOCGWINSZ */
+#endif /* TIOCGWINSZ or ISC4_0 */
 #endif /* USG */
 
 extern int quit_char;
@@ -464,14 +464,18 @@ child_setup_tty (out)
 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
   s.main.c_oflag |= OPOST;     /* Enable output postprocessing */
   s.main.c_oflag &= ~ONLCR;    /* Disable map of NL to CR-NL on output */
+#ifdef NLDLY
   s.main.c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
                                /* No output delays */
+#endif
   s.main.c_lflag &= ~ECHO;     /* Disable echo */
   s.main.c_lflag |= ISIG;      /* Enable signals */
-  s.main.c_iflag &= ~IUCLC;    /* Disable map of upper case to lower on
-                                  input */
-  s.main.c_oflag &= ~OLCUC;    /* Disable map of lower case to upper on
-                                  output */
+#ifdef IUCLC
+  s.main.c_iflag &= ~IUCLC;    /* Disable downcasing on input.  */
+#endif
+#ifdef OLCUC
+  s.main.c_oflag &= ~OLCUC;    /* Disable upcasing on output.  */
+#endif
   s.main.c_cflag = (s.main.c_cflag & ~CSIZE) | CS8; /* Don't strip 8th bit */
 #if 0
   /* Said to be unnecessary:  */
@@ -564,10 +568,6 @@ struct save_signal
 
 sys_suspend ()
 {
-#ifdef MSDOS   /* Demacs 1.1.2 91/10/20 Manabu Higashida */
-  int st;
-  char oldwd[MAXPATHLEN+1]; /* Fixed length is safe on MSDOS.  */
-#endif
 #ifdef VMS
   /* "Foster" parentage allows emacs to return to a subprocess that attached
      to the current emacs as a cheaper than starting a whole new process.  This
@@ -626,6 +626,22 @@ sys_suspend ()
 /* On a system where suspending is not implemented,
    instead fork a subshell and let it talk directly to the terminal
    while we wait.  */
+  sys_subshell ();
+
+#endif /* no USG_JOBCTRL */
+#endif /* no SIGTSTP */
+#endif /* not VMS */
+}
+
+/* Fork a subshell.  */
+
+sys_subshell ()
+{
+#ifndef VMS
+#ifdef MSDOS   /* Demacs 1.1.2 91/10/20 Manabu Higashida */
+  int st;
+  char oldwd[MAXPATHLEN+1]; /* Fixed length is safe on MSDOS.  */
+#endif
   int pid = fork ();
   struct save_signal saved_handlers[5];
 
@@ -706,10 +722,7 @@ sys_suspend ()
   synch_process_alive = 1;
   wait_for_termination (pid);
   restore_signal_handlers (saved_handlers);
-
-#endif /* no USG_JOBCTRL */
-#endif /* no SIGTSTP */
-#endif /* not VMS */
+#endif /* !VMS */
 }
 
 save_signal_handlers (saved_handlers)
@@ -834,7 +847,7 @@ unrequest_sigio ()
 \f
 /* Saving and restoring the process group of Emacs's terminal.  */
 
-#ifdef BSD
+#ifdef BSD_PGRPS
 
 /* The process group of which Emacs was a member when it initially
    started.
@@ -878,7 +891,7 @@ widen_foreground_group ()
   setpgrp (0, inherited_pgroup);
 }
 
-#endif
+#endif /* BSD_PGRPS */
 \f
 /* Getting and setting emacs_tty structures.  */
 
@@ -1111,7 +1124,7 @@ init_sys_modes ()
 #endif
 #endif /* not VMS */
 
-#ifdef BSD
+#ifdef BSD_PGRPS
   if (! read_socket_hook && EQ (Vwindow_system, Qnil))
     narrow_foreground_group ();
 #endif
@@ -1131,7 +1144,7 @@ init_sys_modes ()
       tty.main.c_lflag &= ~ECHO;       /* Disable echo */
       tty.main.c_lflag &= ~ICANON;     /* Disable erase/kill processing */
 #ifdef IEXTEN
-      tty.main.c_iflag &= ~IEXTEN;     /* Disable other editing characters.  */
+      tty.main.c_lflag &= ~IEXTEN;     /* Disable other editing characters.  */
 #endif
       tty.main.c_lflag |= ISIG;        /* Enable signals */
       if (flow_control)
@@ -1358,10 +1371,10 @@ tabs_safe_p ()
   EMACS_GET_TTY (input_fd, &tty);
   return EMACS_TTY_TABS_OK (&tty);
 }
-
+\f
 /* Get terminal size from system.
-   Store number of lines into *heightp and width into *widthp.
-   If zero or a negative number is stored, the value is not valid.  */
+   Store number of lines into *HEIGHTP and width into *WIDTHP.
+   We store 0 if there's no valid information.  */
 
 get_frame_size (widthp, heightp)
      int *widthp, *heightp;
@@ -1418,6 +1431,43 @@ get_frame_size (widthp, heightp)
 #endif /* not BSD-style */
 }
 
+/* Set the logical window size associated with descriptor FD
+   to HEIGHT and WIDTH.  This is used mainly with ptys.  */
+
+int
+set_window_size (fd, height, width)
+     int fd, height, width;
+{
+#ifdef TIOCSWINSZ
+
+  /* BSD-style.  */
+  struct winsize size;
+  size.ws_row = height;
+  size.ws_col = width;
+
+  if (ioctl (fd, TIOCSWINSZ, &size) == -1)
+    return 0; /* error */
+  else
+    return 1;
+
+#else
+#ifdef TIOCSSIZE
+
+  /* SunOS - style.  */
+  struct ttysize size;  
+  size.ts_lines = height;
+  size.ts_cols = width;
+
+  if (ioctl (fd, TIOCGSIZE, &size) == -1)
+    return 0;
+  else
+    return 1;
+#else
+  return -1;
+#endif /* not SunOS-style */
+#endif /* not BSD-style */
+}
+
 \f
 /* Prepare the terminal for exiting Emacs; move the cursor to the
    bottom of the frame, turn off interrupt-driven I/O, etc.  */
@@ -1466,6 +1516,9 @@ reset_sys_modes ()
     }
 #endif /* F_SETOWN */
 #endif /* F_SETOWN_BUG */
+#ifdef O_NDELAY
+  fcntl (input_fd, F_SETFL, fcntl (input_fd, F_GETFL, 0) & ~O_NDELAY);
+#endif
 #endif /* F_SETFL */
 #ifdef BSD4_1
   if (interrupt_input)
@@ -1483,7 +1536,7 @@ reset_sys_modes ()
   hft_reset ();
 #endif
 
-#ifdef BSD
+#ifdef BSD_PGRPS
   widen_foreground_group ();
 #endif
 }
@@ -1796,7 +1849,7 @@ unrequest_sigio ()
  *
  */
 
-#ifndef CANNOT_UNEXEC
+#if !defined (CANNOT_UNEXEC) && !defined (HAVE_TEXT_START)
 char *
 start_of_text ()
 {
@@ -1812,7 +1865,7 @@ start_of_text ()
 #endif /* GOULD */
 #endif /* TEXT_START */
 }
-#endif /* not CANNOT_UNEXEC */
+#endif /* not CANNOT_UNEXEC and not HAVE_TEXT_START */
 
 /*
  *     Return the address of the start of the data segment prior to
@@ -1901,7 +1954,7 @@ end_of_data ()
 
 #endif /* not CANNOT_DUMP */
 \f
-/* Get_system_name returns as its value
+/* get_system_name returns as its value
  a string for the Lisp function system-name to return. */
 
 #ifdef BSD4_1
@@ -1910,103 +1963,129 @@ end_of_data ()
 
 /* Can't have this within the function since `static' is #defined to 
    nothing for some USG systems.  */
-#ifdef USG
-#ifdef HAVE_GETHOSTNAME
-static char get_system_name_name[256];
-#else /* not HAVE_GETHOSTNAME */
-static struct utsname get_system_name_name;
-#endif /* not HAVE_GETHOSTNAME */
-#endif /* USG */
+static char *get_system_name_cache;
+static int get_system_name_predump_p;
 
 #ifndef BSD4_1
-#ifndef USG
 #ifndef VMS
 #ifdef HAVE_SOCKETS
 #include <sys/socket.h>
 #include <netdb.h>
 #endif /* HAVE_SOCKETS */
 #endif /* not VMS */
-#endif /* not USG */
 #endif /* not BSD4_1 */
 
 char *
 get_system_name ()
 {
-#ifdef USG
-#ifdef HAVE_GETHOSTNAME
-  gethostname (get_system_name_name, sizeof (get_system_name_name));
-  return get_system_name_name;
-#else /* not HAVE_GETHOSTNAME */
-  uname (&get_system_name_name);
-  return (get_system_name_name.nodename);
-#endif /* not HAVE_GETHOSTNAME */
-#else /* Not USG */
 #ifdef BSD4_1
   return sysname;
-#else /* not USG, not 4.1 */
-  static char system_name_saved[32];
-#ifdef VMS
-  char *sp;
-  if ((sp = egetenv ("SYS$NODE")) == 0)
-    sp = "vax-vms";
-  else
+#else
+#ifndef CANNOT_DUMP
+  /* If the cached value is from before the dump, and we've dumped
+     since then, then the cached value is no good. */
+  if (get_system_name_predump_p && initialized && get_system_name_cache)
     {
-      char *end;
-
-      if ((end = index (sp, ':')) != 0)
-       *end = '\0';
+      xfree (get_system_name_cache);
+      get_system_name_cache = 0;
     }
-  strcpy (system_name_saved, sp);
-#else /* not VMS */
-  gethostname (system_name_saved, sizeof (system_name_saved));
-#ifdef HAVE_SOCKETS
-  /* Turn the hostname into the official, fully-qualified hostname.
-     Don't do this if we're going to dump; this can confuse system
-     libraries on some machines and make the dumped emacs core dump. */
-#ifndef CANNOT_DUMP
-  if (initialized)
-#endif /* not CANNOT_DUMP */
+#endif
+  if (!get_system_name_cache)
     {
-      struct hostent *hp;
-      hp = gethostbyname (system_name_saved);
-      if (hp && strlen (hp->h_name) < sizeof(system_name_saved))
-       strcpy (system_name_saved, hp->h_name);
-      if (hp && !index (system_name_saved, '.'))
+      /* No cached value, so get the name from the system.  */
+#ifdef VMS
+      char *sp;
+      if ((sp = egetenv ("SYS$NODE")) == 0)
+       sp = "vax-vms";
+      else
        {
-         /* 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 && strlen (*alias) < sizeof (system_name_saved))
-           strcpy (system_name_saved, *alias);
-       }
-    }
-#endif /* HAVE_SOCKETS */
-#endif /* not VMS */
-  return system_name_saved;
-#endif /* not USG, not 4.1 */
-#endif /* not USG */
-}
+         char *end;
 
-#ifdef VMS
+         if ((end = index (sp, ':')) != 0)
+           *end = '\0';
+       }
+      get_system_name_cache = (char *) xmalloc (strlen (sp) + 1);
+      strcpy (get_system_name_cache, sp);
+#else
 #ifndef HAVE_GETHOSTNAME
-void gethostname(buf, len)
-    char *buf;
-    int len;
-{
-    char *s;
-    s = getenv ("SYS$NODE");
-    if (s == NULL)
-        buf[0] = '\0';
-    else {
-        strncpy (buf, s, len - 2);
-        buf[len - 1] = '\0';
-    } /* else */
-} /* static void gethostname */
-#endif /* ! HAVE_GETHOSTNAME */
-#endif /* VMS */
+      struct utsname uts;
+      uname (&uts);
+      get_system_name_cache = (char *) xmalloc (strlen (uts.nodename) + 1);
+      strcpy (get_system_name_cache, uts.nodename);
+#else /* HAVE_GETHOSTNAME */
+      {
+       int hostname_size = 256;
+       char *hostname = (char *) xmalloc (hostname_size);
+
+       /* Try to get the host name; if the buffer is too short, try
+          again.  Apparently, the only indication gethostname gives of
+          whether the buffer was large enough is the presence or absence
+          of a '\0' in the string.  Eech.  */
+       for (;;)
+         {
+           gethostname (hostname, hostname_size - 1);
+           hostname[hostname_size - 1] = '\0';
+
+           /* Was the buffer large enough for the '\0'?  */
+           if (strlen (hostname) < hostname_size - 1)
+             break;
 
+           hostname_size <<= 1;
+           hostname = (char *) xrealloc (hostname, hostname_size);
+         }
+       get_system_name_cache = hostname;
+#ifdef HAVE_SOCKETS
+       /* Turn the hostname into the official, fully-qualified hostname.
+          Don't do this if we're going to dump; this can confuse system
+          libraries on some machines and make the dumped emacs core dump. */
+#ifndef CANNOT_DUMP
+       if (initialized)
+#endif /* not CANNOT_DUMP */
+         {
+           struct hostent *hp = gethostbyname (hostname);
+           if (hp)
+             {
+               char *fqdn = 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 = (char *) xrealloc (hostname, strlen (fqdn) + 1);
+               strcpy (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 /* HAVE_SOCKETS */
+       get_system_name_cache = hostname;
+      }
+#endif /* HAVE_GETHOSTNAME */
+#endif /* VMS */
+#ifndef CANNOT_DUMP
+      get_system_name_predump_p = !initialized;
+#endif
+    }
+  return (get_system_name_cache);
+#endif /* BSD4_1 */
+}
 \f
 #ifndef VMS
 #ifndef HAVE_SELECT
@@ -2742,7 +2821,7 @@ sys_write (fildes, buf, nbyte)
          if (errno == EINTR)
            continue;
          else
-           return (-1);
+           return (bytes_written ? bytes_written : -1);
        }
 
       buf += rtnval;
@@ -2856,8 +2935,12 @@ char *sys_siglist[NSIG + 1] =
   "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