]> code.delx.au - gnu-emacs/blobdiff - src/w32.c
Merge changes from emacs-23
[gnu-emacs] / src / w32.c
index 2fbb3b6cb4ca1244ce0809f2a2261eeb79f2a97e..91893ddfc6107605a587885de84fa8bc119a9f52 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -95,7 +95,7 @@ typedef struct _MEMORY_STATUS_EX {
 #include <tlhelp32.h>
 #include <psapi.h>
 #include <w32api.h>
-#if !defined(__MINGW32__) || __W32API_MAJOR_VERSION < 3 || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 15)
+#if !defined (__MINGW32__) || __W32API_MAJOR_VERSION < 3 || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 15)
 /* This either is not in psapi.h or guarded by higher value of
    _WIN32_WINNT than what we use.  w32api supplied with MinGW 3.15
    defines it in psapi.h  */
@@ -150,6 +150,8 @@ typedef struct _PROCESS_MEMORY_COUNTERS_EX {
 typedef HRESULT (WINAPI * ShGetFolderPath_fn)
   (IN HWND, IN int, IN HANDLE, IN DWORD, OUT char *);
 
+Lisp_Object QCloaded_from;
+
 void globals_of_w32 (void);
 static DWORD get_rid (PSID);
 
@@ -1449,6 +1451,14 @@ sigprocmask (int how, const sigset_t *set, sigset_t *oset)
   return 0;
 }
 
+int
+pthread_sigmask (int how, const sigset_t *set, sigset_t *oset)
+{
+  if (sigprocmask (how, set, oset) == -1)
+    return EINVAL;
+  return 0;
+}
+
 int
 setpgrp (int pid, int gid)
 {
@@ -1561,6 +1571,7 @@ init_environment (char ** argv)
     char locale_name[32];
     struct stat ignored;
     char default_home[MAX_PATH];
+    int appdata = 0;
 
     static const struct env_entry
     {
@@ -1614,7 +1625,10 @@ init_environment (char ** argv)
 
            /* If we can't get the appdata dir, revert to old behavior.  */
            if (profile_result == S_OK)
-             env_vars[0].def_value = default_home;
+             {
+               env_vars[0].def_value = default_home;
+               appdata = 1;
+             }
          }
       }
 
@@ -1701,6 +1715,14 @@ init_environment (char ** argv)
                lpval = env_vars[i].def_value;
                dwType = REG_EXPAND_SZ;
                dont_free = 1;
+               if (!strcmp (env_vars[i].name, "HOME") && !appdata)
+                 {
+                   Lisp_Object warning[2];
+                   warning[0] = intern ("initialization");
+                   warning[1] = build_string ("Setting HOME to C:\\ by default is deprecated");
+                   Vdelayed_warnings_list = Fcons (Flist (2, warning),
+                                                   Vdelayed_warnings_list);
+                 }
              }
 
            if (lpval)
@@ -5700,6 +5722,54 @@ sys_localtime (const time_t *t)
   return localtime (t);
 }
 
+
+\f
+/* Delayed loading of libraries.  */
+
+Lisp_Object Vlibrary_cache;
+
+/* The argument LIBRARIES is an alist that associates a symbol
+   LIBRARY_ID, identifying an external DLL library known to Emacs, to
+   a list of filenames under which the library is usually found.  In
+   most cases, the argument passed as LIBRARIES is the variable
+   `dynamic-library-alist', which is initialized to a list of common
+   library names.  If the function loads the library successfully, it
+   returns the handle of the DLL, and records the filename in the
+   property :loaded-from of LIBRARY_ID; it returns NULL if the library
+   could not be found, or when it was already loaded (because the
+   handle is not recorded anywhere, and so is lost after use).  It
+   would be trivial to save the handle too in :loaded-from, but
+   currently there's no use case for it.  */
+HMODULE
+w32_delayed_load (Lisp_Object libraries, Lisp_Object library_id)
+{
+  HMODULE library_dll = NULL;
+
+  CHECK_SYMBOL (library_id);
+
+  if (CONSP (libraries) && NILP (Fassq (library_id, Vlibrary_cache)))
+    {
+      Lisp_Object found = Qnil;
+      Lisp_Object dlls = Fassq (library_id, libraries);
+
+      if (CONSP (dlls))
+        for (dlls = XCDR (dlls); CONSP (dlls); dlls = XCDR (dlls))
+          {
+            CHECK_STRING_CAR (dlls);
+            if (library_dll = LoadLibrary (SDATA (XCAR (dlls))))
+              {
+                found = XCAR (dlls);
+                break;
+              }
+          }
+
+      Fput (library_id, QCloaded_from, found);
+    }
+
+  return library_dll;
+}
+
+\f
 static void
 check_windows_init_file (void)
 {
@@ -5898,6 +5968,11 @@ globals_of_w32 (void)
   get_process_times_fn = (GetProcessTimes_Proc)
     GetProcAddress (kernel32, "GetProcessTimes");
 
+  DEFSYM (QCloaded_from, ":loaded-from");
+
+  Vlibrary_cache = Qnil;
+  staticpro (&Vlibrary_cache);
+
   g_b_init_is_windows_9x = 0;
   g_b_init_open_process_token = 0;
   g_b_init_get_token_information = 0;
@@ -6137,7 +6212,7 @@ emacs_gnutls_pull (gnutls_transport_ptr_t p, void* buf, size_t sz)
 
   for (;;)
     {
-      n = sys_read(fd, (char*)buf, sz);
+      n = sys_read (fd, (char*)buf, sz);
 
       if (n >= 0)
         return n;
@@ -6147,7 +6222,7 @@ emacs_gnutls_pull (gnutls_transport_ptr_t p, void* buf, size_t sz)
       if (err == EWOULDBLOCK)
         {
           /* Set a small timeout.  */
-          EMACS_SET_SECS_USECS(timeout, 1, 0);
+          EMACS_SET_SECS_USECS (timeout, 1, 0);
           FD_ZERO (&fdset);
           FD_SET ((int)fd, &fdset);
 
@@ -6166,7 +6241,7 @@ emacs_gnutls_pull (gnutls_transport_ptr_t p, void* buf, size_t sz)
             err = errno; /* Other errors are just passed on.  */
         }
 
-      gnutls_transport_set_errno (process->gnutls_state, err);
+      emacs_gnutls_transport_set_errno (process->gnutls_state, err);
 
       return -1;
     }
@@ -6177,7 +6252,7 @@ emacs_gnutls_push (gnutls_transport_ptr_t p, const void* buf, size_t sz)
 {
   struct Lisp_Process *process = (struct Lisp_Process *)p;
   int fd = process->outfd;
-  ssize_t n = sys_write(fd, buf, sz);
+  ssize_t n = sys_write (fd, buf, sz);
 
   /* 0 or more bytes written means everything went fine.  */
   if (n >= 0)
@@ -6185,8 +6260,8 @@ emacs_gnutls_push (gnutls_transport_ptr_t p, const void* buf, size_t sz)
 
   /* Negative bytes written means we got an error in errno.
      Translate the WSAEWOULDBLOCK alias EWOULDBLOCK to EAGAIN.  */
-  gnutls_transport_set_errno (process->gnutls_state,
-                              errno == EWOULDBLOCK ? EAGAIN : errno);
+  emacs_gnutls_transport_set_errno (process->gnutls_state,
+                                    errno == EWOULDBLOCK ? EAGAIN : errno);
 
   return -1;
 }