Clean-up left-overs after 2012-09-23T08:44:20Z!eggert@cs.ucla.edu wrt signal handling.
[bpt/emacs.git] / src / w32proc.c
index 5bdeba2..8dbd063 100644 (file)
@@ -1,4 +1,4 @@
-/* Process support for GNU Emacs on the Microsoft W32 API.
+/* Process support for GNU Emacs on the Microsoft Windows API.
    Copyright (C) 1992, 1995, 1999-2012  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -28,7 +28,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <fcntl.h>
 #include <signal.h>
 #include <sys/file.h>
-#include <setjmp.h>
 
 /* must include CRT headers *before* config.h */
 #include <config.h>
@@ -103,6 +102,29 @@ sys_signal (int sig, signal_handler handler)
   return old;
 }
 
+/* Emulate sigaction. */
+int
+sigaction (int sig, const struct sigaction *act, struct sigaction *oact)
+{
+  signal_handler old;
+
+  if (sig != SIGCHLD)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+  old = sig_handlers[sig];
+  if (act)
+    sig_handlers[sig] = act->sa_handler;
+  if (oact)
+    {
+      oact->sa_handler = old;
+      oact->sa_flags = 0;
+      oact->sa_mask = empty_mask;
+    }
+  return 0;
+}
+
 /* Defined in <process.h> which conflicts with the local copy */
 #define _P_NOWAIT 1
 
@@ -176,7 +198,7 @@ delete_child (child_process *cp)
   /* Should not be deleting a child that is still needed. */
   for (i = 0; i < MAXDESC; i++)
     if (fd_info[i].cp == cp)
-      abort ();
+      emacs_abort ();
 
   if (!CHILD_ACTIVE (cp))
     return;
@@ -316,7 +338,7 @@ create_child (char *exe, char *cmdline, char *env, int is_gui_app,
   DWORD flags;
   char dir[ MAXPATHLEN ];
 
-  if (cp == NULL) abort ();
+  if (cp == NULL) emacs_abort ();
 
   memset (&start, 0, sizeof (start));
   start.cb = sizeof (start);
@@ -405,7 +427,7 @@ register_child (int pid, int fd)
   if (fd_info[fd].cp != NULL)
     {
       DebPrint (("register_child: fd_info[%d] apparently in use!\n", fd));
-      abort ();
+      emacs_abort ();
     }
 
   fd_info[fd].cp = cp;
@@ -459,7 +481,7 @@ sys_wait (int *status)
       /* We want to wait for a specific child */
       wait_hnd[nh] = dead_child->procinfo.hProcess;
       cps[nh] = dead_child;
-      if (!wait_hnd[nh]) abort ();
+      if (!wait_hnd[nh]) emacs_abort ();
       nh++;
       active = 0;
       goto get_result;
@@ -507,7 +529,7 @@ sys_wait (int *status)
       active -= WAIT_ABANDONED_0;
     }
   else
-    abort ();
+    emacs_abort ();
 
 get_result:
   if (!GetExitCodeProcess (wait_hnd[active], &retval))
@@ -549,7 +571,7 @@ get_result:
 
       /* Report the status of the synchronous process.  */
       if (WIFEXITED (retval))
-       synch_process_retcode = WRETCODE (retval);
+       synch_process_retcode = WEXITSTATUS (retval);
       else if (WIFSIGNALED (retval))
        {
          int code = WTERMSIG (retval);
@@ -777,7 +799,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
     }
 
   /* Handle executable names without an executable suffix.  */
-  program = make_string (cmdname, strlen (cmdname));
+  program = build_string (cmdname);
   if (NILP (Ffile_executable_p (program)))
     {
       struct gcpro gcpro1;
@@ -799,7 +821,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
   unixtodos_filename (cmdname);
   argv[0] = cmdname;
 
-  /* Determine whether program is a 16-bit DOS executable, or a w32
+  /* Determine whether program is a 16-bit DOS executable, or a 32-bit Windows
      executable that is implicitly linked to the Cygnus dll (implying it
      was compiled with the Cygnus GNU toolchain and hence relies on
      cygwin.dll to parse the command line - we use this to decide how to
@@ -1080,7 +1102,7 @@ extern int proc_buffered_char[];
 
 int
 sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
-           EMACS_TIME *timeout)
+           EMACS_TIME *timeout, void *ignored)
 {
   SELECT_TYPE orfds;
   DWORD timeout_ms, start_time;
@@ -1090,7 +1112,8 @@ sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
   HANDLE wait_hnd[MAXDESC + MAX_CHILDREN];
   int fdindex[MAXDESC];   /* mapping from wait handles back to descriptors */
 
-  timeout_ms = timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFINITE;
+  timeout_ms =
+    timeout ? (timeout->tv_sec * 1000 + timeout->tv_nsec / 1000000) : INFINITE;
 
   /* If the descriptor sets are NULL but timeout isn't, then just Sleep.  */
   if (rfds == NULL && wfds == NULL && efds == NULL && timeout != NULL)
@@ -1188,7 +1211,7 @@ sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
 #endif
                wait_hnd[nh] = cp->char_avail;
                fdindex[nh] = i;
-               if (!wait_hnd[nh]) abort ();
+               if (!wait_hnd[nh]) emacs_abort ();
                nh++;
 #ifdef FULL_DEBUG
                DebPrint (("select waiting on child %d fd %d\n",
@@ -1275,7 +1298,7 @@ count_children:
       active -= WAIT_ABANDONED_0;
     }
   else
-    abort ();
+    emacs_abort ();
 
   /* Loop over all handles after active (now officially documented as
      being the first signaled handle in the array).  We do this to
@@ -1385,7 +1408,7 @@ find_child_console (HWND hwnd, LPARAM arg)
 
       GetClassName (hwnd, window_class, sizeof (window_class));
       if (strcmp (window_class,
-                 (os_subtype == OS_WIN95)
+                 (os_subtype == OS_9X)
                  ? "tty"
                  : "ConsoleWindowClass") == 0)
        {
@@ -1516,7 +1539,7 @@ sys_kill (int pid, int sig)
       if (NILP (Vw32_start_process_share_console) && cp && cp->hwnd)
        {
 #if 1
-         if (os_subtype == OS_WIN95)
+         if (os_subtype == OS_9X)
            {
 /*
    Another possibility is to try terminating the VDM out-right by
@@ -1535,7 +1558,7 @@ sys_kill (int pid, int sig)
 
 */
 #if 0
-             /* On Win95, posting WM_QUIT causes the 16-bit subsystem
+             /* On Windows 95, posting WM_QUIT causes the 16-bit subsystem
                 to hang when cmdproxy is used in conjunction with
                 command.com for an interactive shell.  Posting
                 WM_CLOSE pops up a dialog that, when Yes is selected,
@@ -1809,7 +1832,7 @@ If successful, the return value is t, otherwise nil.  */)
       CHECK_NUMBER (process);
 
       /* Allow pid to be an internally generated one, or one obtained
-        externally.  This is necessary because real pids on Win95 are
+        externally.  This is necessary because real pids on Windows 95 are
         negative.  */
 
       pid = XINT (process);
@@ -1948,8 +1971,12 @@ If LCID (a 16-bit number) is not a valid locale, the result is nil.  */)
       got_full = GetLocaleInfo (XINT (lcid),
                                XINT (longform),
                                full_name, sizeof (full_name));
+      /* GetLocaleInfo's return value includes the terminating null
+        character, when the returned information is a string, whereas
+        make_unibyte_string needs the string length without the
+        terminating null.  */
       if (got_full)
-       return make_unibyte_string (full_name, got_full);
+       return make_unibyte_string (full_name, got_full - 1);
     }
 
   return Qnil;