Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / src / w32proc.c
index af92372..f7982f3 100644 (file)
@@ -1,6 +1,5 @@
 /* Process support for GNU Emacs on the Microsoft W32 API.
-   Copyright (C) 1992, 1995, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-                2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+   Copyright (C) 1992, 1995, 1999-2012  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -32,10 +31,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <setjmp.h>
 
 /* must include CRT headers *before* config.h */
-
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #undef signal
 #undef wait
@@ -55,7 +51,6 @@ extern BOOL WINAPI IsValidLocale (LCID, DWORD);
 #endif
 
 #include "lisp.h"
-#include "character.h"
 #include "w32.h"
 #include "w32heap.h"
 #include "systime.h"
@@ -71,49 +66,6 @@ extern BOOL WINAPI IsValidLocale (LCID, DWORD);
            + ((DWORD)(var) - (section)->VirtualAddress)                \
            + (filedata).file_base))
 
-/* Control whether spawnve quotes arguments as necessary to ensure
-   correct parsing by child process.  Because not all uses of spawnve
-   are careful about constructing argv arrays, we make this behavior
-   conditional (off by default). */
-Lisp_Object Vw32_quote_process_args;
-
-/* Control whether create_child causes the process' window to be
-   hidden.  The default is nil. */
-Lisp_Object Vw32_start_process_show_window;
-
-/* Control whether create_child causes the process to inherit Emacs'
-   console window, or be given a new one of its own.  The default is
-   nil, to allow multiple DOS programs to run on Win95.  Having separate
-   consoles also allows Emacs to cleanly terminate process groups.  */
-Lisp_Object Vw32_start_process_share_console;
-
-/* Control whether create_child cause the process to inherit Emacs'
-   error mode setting.  The default is t, to minimize the possibility of
-   subprocesses blocking when accessing unmounted drives.  */
-Lisp_Object Vw32_start_process_inherit_error_mode;
-
-/* Time to sleep before reading from a subprocess output pipe - this
-   avoids the inefficiency of frequently reading small amounts of data.
-   This is primarily necessary for handling DOS processes on Windows 95,
-   but is useful for W32 processes on both Windows 95 and NT as well.  */
-int w32_pipe_read_delay;
-
-/* Control conversion of upper case file names to lower case.
-   nil means no, t means yes. */
-Lisp_Object Vw32_downcase_file_names;
-
-/* Control whether stat() attempts to generate fake but hopefully
-   "accurate" inode values, by hashing the absolute truenames of files.
-   This should detect aliasing between long and short names, but still
-   allows the possibility of hash collisions.  */
-Lisp_Object Vw32_generate_fake_inodes;
-
-/* Control whether stat() attempts to determine file type and link count
-   exactly, at the expense of slower operation.  Since true hard links
-   are supported on NTFS volumes, this is only relevant on NT.  */
-Lisp_Object Vw32_get_true_file_attributes;
-extern Lisp_Object Qlocal;
-
 Lisp_Object Qhigh, Qlow;
 
 #ifdef EMACSDEBUG
@@ -159,7 +111,7 @@ int child_proc_count = 0;
 child_process child_procs[ MAX_CHILDREN ];
 child_process *dead_child = NULL;
 
-DWORD WINAPI reader_thread (void *arg);
+static DWORD WINAPI reader_thread (void *arg);
 
 /* Find an unused process slot.  */
 child_process *
@@ -168,14 +120,14 @@ new_child (void)
   child_process *cp;
   DWORD id;
 
-  for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
+  for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--)
     if (!CHILD_ACTIVE (cp))
-      goto Initialise;
+      goto Initialize;
   if (child_proc_count == MAX_CHILDREN)
     return NULL;
   cp = &child_procs[child_proc_count++];
 
- Initialise:
+ Initialize:
   memset (cp, 0, sizeof (*cp));
   cp->fd = -1;
   cp->pid = -1;
@@ -222,7 +174,7 @@ delete_child (child_process *cp)
          cp->status = STATUS_READ_ERROR;
          SetEvent (cp->char_consumed);
 #if 0
-          /* We used to forceably terminate the thread here, but it
+          /* We used to forcibly terminate the thread here, but it
              is normally unnecessary, and in abnormal cases, the worst that
              will happen is we have an extra idle thread hanging around
              waiting for the zombie process.  */
@@ -268,7 +220,7 @@ find_child_pid (DWORD pid)
 {
   child_process *cp;
 
-  for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
+  for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--)
     if (CHILD_ACTIVE (cp) && pid == cp->pid)
       return cp;
   return NULL;
@@ -279,7 +231,7 @@ find_child_pid (DWORD pid)
    is normally blocked until woken by select() to check for input by
    reading one char.  When the read completes, char_avail is signaled
    to wake up the select emulator and the thread blocks itself again. */
-DWORD WINAPI
+static DWORD WINAPI
 reader_thread (void *arg)
 {
   child_process *cp;
@@ -289,7 +241,8 @@ reader_thread (void *arg)
 
   /* We have to wait for the go-ahead before we can start */
   if (cp == NULL
-      || WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0)
+      || WaitForSingleObject (cp->char_consumed, INFINITE) != WAIT_OBJECT_0
+      || cp->fd < 0)
     return 1;
 
   for (;;)
@@ -495,7 +448,7 @@ sys_wait (int *status)
     }
   else
     {
-      for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
+      for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--)
        /* some child_procs might be sockets; ignore them */
        if (CHILD_ACTIVE (cp) && cp->procinfo.hProcess
            && (cp->fd < 0 || (fd_info[cp->fd].flags & FILE_AT_EOF) != 0))
@@ -608,7 +561,7 @@ get_result:
 # define IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER
 #endif
 
-void
+static void
 w32_executable_type (char * filename,
                     int * is_dos_app,
                     int * is_cygnus_app,
@@ -726,7 +679,7 @@ unwind:
   close_file_data (&executable);
 }
 
-int
+static int
 compare_env (const void *strp1, const void *strp2)
 {
   const char *str1 = *(const char **)strp1, *str2 = *(const char **)strp2;
@@ -750,7 +703,7 @@ compare_env (const void *strp1, const void *strp2)
     return 1;
 }
 
-void
+static void
 merge_and_sort_env (char **envp1, char **envp2, char **new_envp)
 {
   char **optr, **nptr;
@@ -868,7 +821,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
 
      The w32 GNU-based library from Cygnus doubles quotes to escape
      them, while MSVC uses backslash for escaping.  (Actually the MSVC
-     startup code does attempt to recognise doubled quotes and accept
+     startup code does attempt to recognize doubled quotes and accept
      them, but gets it wrong and ends up requiring three quotes to get a
      single embedded quote!)  So by default we decide whether to use
      quote or backslash as the escape character based on whether the
@@ -876,7 +829,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
 
      Note that using backslash to escape embedded quotes requires
      additional special handling if an embedded quote is already
-     preceeded by backslash, or if an arg requiring quoting ends with
+     preceded by backslash, or if an arg requiring quoting ends with
      backslash.  In such cases, the run of escape characters needs to be
      doubled.  For consistency, we apply this special handling as long
      as the escape character is not quote.
@@ -895,7 +848,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
        escape_char = is_cygnus_app ? '"' : '\\';
     }
 
-  /* Cygwin apps needs quoting a bit more often */
+  /* Cygwin apps needs quoting a bit more often */
   if (escape_char == '"')
     sepchars = "\r\n\t\f '";
 
@@ -1098,7 +1051,7 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp)
    detect that we were woken up by C-g, we return -1 with errno set to
    EINTR as on Unix.  */
 
-/* From ntterm.c */
+/* From w32console.c */
 extern HANDLE keyboard_handle;
 
 /* From w32xfns.c */
@@ -1245,7 +1198,7 @@ sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
 count_children:
   /* Add handles of child processes.  */
   nc = 0;
-  for (cp = child_procs+(child_proc_count-1); cp >= child_procs; cp--)
+  for (cp = child_procs + (child_proc_count-1); cp >= child_procs; cp--)
     /* Some child_procs might be sockets; ignore them.  Also some
        children may have died already, but we haven't finished reading
        the process output; ignore them too.  */
@@ -1604,8 +1557,6 @@ sys_kill (int pid, int sig)
   return rc;
 }
 
-/* extern int report_file_error (char *, Lisp_Object); */
-
 /* The following two routines are used to manipulate stdin, stdout, and
    stderr of our child processes.
 
@@ -1694,8 +1645,6 @@ set_process_dir (char * dir)
   process_dir = dir;
 }
 
-#ifdef HAVE_SOCKETS
-
 /* To avoid problems with winsock implementations that work over dial-up
    connections causing or requiring a connection to exist while Emacs is
    running, Emacs no longer automatically loads winsock on startup if it
@@ -1707,13 +1656,11 @@ set_process_dir (char * dir)
    dial-up users to only be connected when they actually need to use
    socket services.  */
 
-/* From nt.c */
+/* From w32.c */
 extern HANDLE winsock_lib;
 extern BOOL term_winsock (void);
 extern BOOL init_winsock (int load_now);
 
-extern Lisp_Object Vsystem_name;
-
 DEFUN ("w32-has-winsock", Fw32_has_winsock, Sw32_has_winsock, 0, 1, 0,
        doc: /* Test for presence of the Windows socket library `winsock'.
 Returns non-nil if winsock support is present, nil otherwise.
@@ -1759,8 +1706,6 @@ socket connections still exist.  */)
   return term_winsock () ? Qt : Qnil;
 }
 
-#endif /* HAVE_SOCKETS */
-
 \f
 /* Some miscellaneous functions that are Windows specific, but not GUI
    specific (ie. are applicable in terminal or batch mode as well).  */
@@ -2003,7 +1948,7 @@ human-readable form.  */)
   return make_number (GetThreadLocale ());
 }
 
-DWORD
+static DWORD
 int_from_hex (char * s)
 {
   DWORD val = 0;
@@ -2025,7 +1970,7 @@ int_from_hex (char * s)
    function isn't given a context pointer.  */
 Lisp_Object Vw32_valid_locale_ids;
 
-BOOL CALLBACK
+static BOOL CALLBACK
 enum_locale_fn (LPTSTR localeNum)
 {
   DWORD id = int_from_hex (localeNum);
@@ -2089,7 +2034,7 @@ If successful, the new locale id is returned, otherwise nil.  */)
    function isn't given a context pointer.  */
 Lisp_Object Vw32_valid_codepages;
 
-BOOL CALLBACK
+static BOOL CALLBACK
 enum_codepage_fn (LPTSTR codepageNum)
 {
   DWORD id = atoi (codepageNum);
@@ -2268,10 +2213,9 @@ syms_of_ntproc (void)
   DEFSYM (Qhigh, "high");
   DEFSYM (Qlow, "low");
 
-#ifdef HAVE_SOCKETS
   defsubr (&Sw32_has_winsock);
   defsubr (&Sw32_unload_winsock);
-#endif
+
   defsubr (&Sw32_short_file_name);
   defsubr (&Sw32_long_file_name);
   defsubr (&Sw32_set_process_priority);
@@ -2292,7 +2236,7 @@ syms_of_ntproc (void)
   defsubr (&Sw32_get_keyboard_layout);
   defsubr (&Sw32_set_keyboard_layout);
 
-  DEFVAR_LISP ("w32-quote-process-args", &Vw32_quote_process_args,
+  DEFVAR_LISP ("w32-quote-process-args", Vw32_quote_process_args,
               doc: /* Non-nil enables quoting of process arguments to ensure correct parsing.
 Because Windows does not directly pass argv arrays to child processes,
 programs have to reconstruct the argv array by parsing the command
@@ -2305,14 +2249,14 @@ will be chosen based on the type of the program.  */);
   Vw32_quote_process_args = Qt;
 
   DEFVAR_LISP ("w32-start-process-show-window",
-              &Vw32_start_process_show_window,
+              Vw32_start_process_show_window,
               doc: /* When nil, new child processes hide their windows.
 When non-nil, they show their window in the method of their choice.
 This variable doesn't affect GUI applications, which will never be hidden.  */);
   Vw32_start_process_show_window = Qnil;
 
   DEFVAR_LISP ("w32-start-process-share-console",
-              &Vw32_start_process_share_console,
+              Vw32_start_process_share_console,
               doc: /* When nil, new child processes are given a new console.
 When non-nil, they share the Emacs console; this has the limitation of
 allowing only one DOS subprocess to run at a time (whether started directly
@@ -2322,13 +2266,13 @@ otherwise respond to interrupts from Emacs.  */);
   Vw32_start_process_share_console = Qnil;
 
   DEFVAR_LISP ("w32-start-process-inherit-error-mode",
-              &Vw32_start_process_inherit_error_mode,
+              Vw32_start_process_inherit_error_mode,
               doc: /* When nil, new child processes revert to the default error mode.
 When non-nil, they inherit their error mode setting from Emacs, which stops
 them blocking when trying to access unmounted drives etc.  */);
   Vw32_start_process_inherit_error_mode = Qt;
 
-  DEFVAR_INT ("w32-pipe-read-delay", &w32_pipe_read_delay,
+  DEFVAR_INT ("w32-pipe-read-delay", w32_pipe_read_delay,
              doc: /* Forced delay before reading subprocess output.
 This is done to improve the buffering of subprocess output, by
 avoiding the inefficiency of frequently reading small amounts of data.
@@ -2339,7 +2283,7 @@ of time slices to wait (effectively boosting the priority of the child
 process temporarily).  A value of zero disables waiting entirely.  */);
   w32_pipe_read_delay = 50;
 
-  DEFVAR_LISP ("w32-downcase-file-names", &Vw32_downcase_file_names,
+  DEFVAR_LISP ("w32-downcase-file-names", Vw32_downcase_file_names,
               doc: /* Non-nil means convert all-upper case file names to lower case.
 This applies when performing completions and file name expansion.
 Note that the value of this setting also affects remote file names,
@@ -2348,16 +2292,16 @@ filesystems via ange-ftp.  */);
   Vw32_downcase_file_names = Qnil;
 
 #if 0
-  DEFVAR_LISP ("w32-generate-fake-inodes", &Vw32_generate_fake_inodes,
+  DEFVAR_LISP ("w32-generate-fake-inodes", Vw32_generate_fake_inodes,
               doc: /* Non-nil means attempt to fake realistic inode values.
 This works by hashing the truename of files, and should detect
 aliasing between long and short (8.3 DOS) names, but can have
-false positives because of hash collisions.  Note that determing
+false positives because of hash collisions.  Note that determining
 the truename of a file can be slow.  */);
   Vw32_generate_fake_inodes = Qnil;
 #endif
 
-  DEFVAR_LISP ("w32-get-true-file-attributes", &Vw32_get_true_file_attributes,
+  DEFVAR_LISP ("w32-get-true-file-attributes", Vw32_get_true_file_attributes,
               doc: /* Non-nil means determine accurate file attributes in `file-attributes'.
 This option controls whether to issue additional system calls to determine
 accurate link counts, file type, and ownership information.  It is more
@@ -2375,7 +2319,4 @@ where the performance impact may be noticeable even on modern hardware.  */);
   staticpro (&Vw32_valid_locale_ids);
   staticpro (&Vw32_valid_codepages);
 }
-/* end of ntproc.c */
-
-/* arch-tag: 23d3a34c-06d2-48a1-833b-ac7609aa5250
-   (do not change this comment) */
+/* end of w32proc.c */