(XDrawLine) [USE_MAC_IMAGE_IO]: Remove spurious return.
[bpt/emacs.git] / src / sysdep.c
index 1884c0c..6699d23 100644 (file)
@@ -1,12 +1,13 @@
 /* Interfaces to system-dependent kernel and library entries.
    Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1999, 2000, 2001,
 /* Interfaces to system-dependent kernel and library entries.
    Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1999, 2000, 2001,
-     2003, 2004  Free Software Foundation, Inc.
+                 2002, 2003, 2004, 2005, 2006, 2007, 2008
+                 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -16,8 +17,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
 
 You should have received a copy of the GNU General Public License
 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., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -47,13 +48,9 @@ extern void srandom P_ ((unsigned int));
 #endif
 
 #include "blockinput.h"
 #endif
 
 #include "blockinput.h"
-#undef NULL
 
 #ifdef MAC_OS8
 
 #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>
+#include <sys/param.h>
 
 #ifndef subprocesses
 /* Nonzero means delete a process right away if it exits (process.c).  */
 
 #ifndef subprocesses
 /* Nonzero means delete a process right away if it exits (process.c).  */
@@ -187,6 +184,7 @@ extern int quit_char;
 #define _P_WAIT 0
 int _CRTAPI1 _spawnlp (int, const char *, const char *, ...);
 int _CRTAPI1 _getpid (void);
 #define _P_WAIT 0
 int _CRTAPI1 _spawnlp (int, const char *, const char *, ...);
 int _CRTAPI1 _getpid (void);
+extern char *getwd (char *);
 #endif
 
 #ifdef NONSYSTEM_DIR_LIBRARY
 #endif
 
 #ifdef NONSYSTEM_DIR_LIBRARY
@@ -247,7 +245,7 @@ int emacs_ospeed;
    under VMS, we place the input channel number here.  */
 int input_fd;
 
    under VMS, we place the input channel number here.  */
 int input_fd;
 
-void croak P_ ((char *));
+void croak P_ ((char *)) NO_RETURN;
 
 #ifdef AIXHFT
 void hft_init ();
 
 #ifdef AIXHFT
 void hft_init ();
@@ -258,6 +256,81 @@ void hft_reset ();
 
 SIGMASKTYPE sigprocmask_set;
 
 
 SIGMASKTYPE sigprocmask_set;
 
+
+#if !defined (HAVE_GET_CURRENT_DIR_NAME) || defined (BROKEN_GET_CURRENT_DIR_NAME)
+
+/* Return the current working directory.  Returns NULL on errors.
+   Any other returned value must be freed with free. This is used
+   only when get_current_dir_name is not defined on the system.  */
+char*
+get_current_dir_name ()
+{
+  char *buf;
+  char *pwd;
+  struct stat dotstat, pwdstat;
+  /* If PWD is accurate, use it instead of calling getwd.  PWD is
+     sometimes a nicer name, and using it may avoid a fatal error if a
+     parent directory is searchable but not readable.  */
+    if ((pwd = getenv ("PWD")) != 0
+      && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1])))
+      && stat (pwd, &pwdstat) == 0
+      && stat (".", &dotstat) == 0
+      && dotstat.st_ino == pwdstat.st_ino
+      && dotstat.st_dev == pwdstat.st_dev
+#ifdef MAXPATHLEN
+      && strlen (pwd) < MAXPATHLEN
+#endif
+      )
+    {
+      buf = (char *) malloc (strlen (pwd) + 1);
+      if (!buf)
+        return NULL;
+      strcpy (buf, pwd);
+    }
+#ifdef HAVE_GETCWD
+  else
+    {
+      size_t buf_size = 1024;
+      buf = (char *) malloc (buf_size);
+      if (!buf)
+        return NULL;
+      for (;;)
+        {
+          if (getcwd (buf, buf_size) == buf)
+            break;
+          if (errno != ERANGE)
+            {
+              int tmp_errno = errno;
+              free (buf);
+              errno = tmp_errno;
+              return NULL;
+            }
+          buf_size *= 2;
+          buf = (char *) realloc (buf, buf_size);
+          if (!buf)
+            return NULL;
+        }
+    }
+#else
+  else
+    {
+      /* We need MAXPATHLEN here.  */
+      buf = (char *) malloc (MAXPATHLEN + 1);
+      if (!buf)
+        return NULL;
+      if (getwd (buf) == NULL)
+        {
+          int tmp_errno = errno;
+          free (buf);
+          errno = tmp_errno;
+          return NULL;
+        }
+    }
+#endif
+  return buf;
+}
+#endif
+
 \f
 /* Specify a different file descriptor for further input operations.  */
 
 \f
 /* Specify a different file descriptor for further input operations.  */
 
@@ -869,7 +942,7 @@ sys_subshell ()
       if (pid == -1)
        write (1, "Can't execute subshell", 22);
 #else   /* not WINDOWSNT */
       if (pid == -1)
        write (1, "Can't execute subshell", 22);
 #else   /* not WINDOWSNT */
-      execlp (sh, sh, 0);
+      execlp (sh, sh, (char *) 0);
       write (1, "Can't execute subshell", 22);
       _exit (1);
 #endif  /* not WINDOWSNT */
       write (1, "Can't execute subshell", 22);
       _exit (1);
 #endif  /* not WINDOWSNT */
@@ -940,7 +1013,7 @@ reset_sigio ()
 void
 request_sigio ()
 {
 void
 request_sigio ()
 {
-  if (read_socket_hook)
+  if (noninteractive || read_socket_hook)
     return;
 
 #ifdef SIGWINCH
     return;
 
 #ifdef SIGWINCH
@@ -954,7 +1027,7 @@ request_sigio ()
 void
 unrequest_sigio ()
 {
 void
 unrequest_sigio ()
 {
-  if (read_socket_hook)
+  if (noninteractive || read_socket_hook)
     return;
 
 #ifdef SIGWINCH
     return;
 
 #ifdef SIGWINCH
@@ -972,7 +1045,7 @@ request_sigio ()
 {
   int on = 1;
 
 {
   int on = 1;
 
-  if (read_socket_hook)
+  if (noninteractive || read_socket_hook)
     return;
 
   ioctl (input_fd, FIOASYNC, &on);
     return;
 
   ioctl (input_fd, FIOASYNC, &on);
@@ -984,7 +1057,7 @@ unrequest_sigio ()
 {
   int off = 0;
 
 {
   int off = 0;
 
-  if (read_socket_hook)
+  if (noninteractive || read_socket_hook)
     return;
 
   ioctl (input_fd, FIOASYNC, &off);
     return;
 
   ioctl (input_fd, FIOASYNC, &off);
@@ -1003,7 +1076,7 @@ request_sigio ()
   int on = 1;
   sigset_t st;
 
   int on = 1;
   sigset_t st;
 
-  if (read_socket_hook)
+  if (noninteractive || read_socket_hook)
     return;
 
   sigemptyset (&st);
     return;
 
   sigemptyset (&st);
@@ -1018,7 +1091,7 @@ unrequest_sigio ()
 {
   int off = 0;
 
 {
   int off = 0;
 
-  if (read_socket_hook)
+  if (noninteractive || read_socket_hook)
     return;
 
   ioctl (input_fd, FIOASYNC, &off);
     return;
 
   ioctl (input_fd, FIOASYNC, &off);
@@ -1031,7 +1104,7 @@ unrequest_sigio ()
 void
 request_sigio ()
 {
 void
 request_sigio ()
 {
-  if (read_socket_hook)
+  if (noninteractive || read_socket_hook)
     return;
 
   croak ("request_sigio");
     return;
 
   croak ("request_sigio");
@@ -1040,7 +1113,7 @@ request_sigio ()
 void
 unrequest_sigio ()
 {
 void
 unrequest_sigio ()
 {
-  if (read_socket_hook)
+  if (noninteractive || read_socket_hook)
     return;
 
   croak ("unrequest_sigio");
     return;
 
   croak ("unrequest_sigio");
@@ -1301,16 +1374,6 @@ init_sys_modes ()
 {
   struct emacs_tty tty;
 
 {
   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 */
@@ -1718,10 +1781,16 @@ get_frame_size (widthp, heightp)
 #else
 #ifdef VMS
 
 #else
 #ifdef VMS
 
+  /* Use a fresh channel since the current one may have stale info
+     (for example, from prior to a suspend); and to avoid a dependency
+     in the init sequence.  */
+  int chan;
   struct sensemode tty;
 
   struct sensemode tty;
 
-  SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0,
-           &tty.class, 12, 0, 0, 0, 0);
+  SYS$ASSIGN (&input_dsc, &chan, 0, 0);
+  SYS$QIOW (0, chan, IO$_SENSEMODE, &tty, 0, 0,
+            &tty.class, 12, 0, 0, 0, 0);
+  SYS$DASSGN (chan);
   *widthp = tty.scr_wid;
   *heightp = tty.scr_len;
 
   *widthp = tty.scr_wid;
   *heightp = tty.scr_len;
 
@@ -2157,12 +2226,16 @@ reset_sigio ()
 void
 request_sigio ()
 {
 void
 request_sigio ()
 {
+  if (noninteractive)
+    return;
   croak ("request sigio");
 }
 
 void
 unrequest_sigio ()
 {
   croak ("request sigio");
 }
 
 void
 unrequest_sigio ()
 {
+  if (noninteractive)
+    return;
   croak ("unrequest sigio");
 }
 
   croak ("unrequest sigio");
 }
 
@@ -2361,7 +2434,9 @@ init_system_name ()
                /* 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;
                /* 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, '.'))
+               while (*alias
+                      && (!index (*alias, '.')
+                          || !strcmp (*alias, "localhost.localdomain")))
                  alias++;
                if (*alias)
                  fqdn = *alias;
                  alias++;
                if (*alias)
                  fqdn = *alias;
@@ -2697,6 +2772,8 @@ reset_sigio ()
 void
 request_sigio ()
 {
 void
 request_sigio ()
 {
+  if (noninteractive)
+    return;
   sigrelse (SIGTINT);
 
   interrupts_deferred = 0;
   sigrelse (SIGTINT);
 
   interrupts_deferred = 0;
@@ -2705,6 +2782,8 @@ request_sigio ()
 void
 unrequest_sigio ()
 {
 void
 unrequest_sigio ()
 {
+  if (noninteractive)
+    return;
   sighold (SIGTINT);
 
   interrupts_deferred = 1;
   sighold (SIGTINT);
 
   interrupts_deferred = 1;
@@ -3242,6 +3321,15 @@ emacs_close (fd)
   int did_retry = 0;
   register int rtnval;
 
   int did_retry = 0;
   register int rtnval;
 
+#if defined (MAC_OSX) && defined (HAVE_CARBON)
+  {
+    extern int mac_try_close_socket P_ ((int));
+
+    if (mac_try_close_socket (fd))
+      return 0;
+  }
+#endif
+
   while ((rtnval = close (fd)) == -1
         && (errno == EINTR))
     did_retry = 1;
   while ((rtnval = close (fd)) == -1
         && (errno == EINTR))
     did_retry = 1;
@@ -3680,7 +3768,7 @@ set_file_times (filename, atime, mtime)
  *                                     sdcsvax!rmr or rmr@uscd
  *
  * Severely hacked over by John Gilmore to make a 4.2BSD compatible
  *                                     sdcsvax!rmr or rmr@uscd
  *
  * Severely hacked over by John Gilmore to make a 4.2BSD compatible
- * subroutine. 11Mar86; hoptoad!gnu
+ * subroutine.  11Mar86; hoptoad!gnu
  *
  * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
  * subroutine didn't return EEXIST.  It does now.
  *
  * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
  * subroutine didn't return EEXIST.  It does now.
@@ -3803,7 +3891,6 @@ rmdir (dpath)
 \f
 /* Functions for VMS */
 #ifdef VMS
 \f
 /* Functions for VMS */
 #ifdef VMS
-#include "vms-pwd.h"
 #include <acldef.h>
 #include <chpdef.h>
 #include <jpidef.h>
 #include <acldef.h>
 #include <chpdef.h>
 #include <jpidef.h>