]> code.delx.au - gnu-emacs/blobdiff - src/w32.c
Merge from emacs-24; up to 2014-06-25T10:17:41Z!rgm@gnu.org
[gnu-emacs] / src / w32.c
index 371cae9cb9bd9f132be095cbe46137bfcea8297a..7cb9d8960c501e2987432de25e8d2545040eda0a 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -73,9 +73,11 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <grp.h>
 
 /* MinGW64 (_W64) defines these in its _mingw.h.  */
-#if defined(__GNUC__) && !defined(_W64)
-#define _ANONYMOUS_UNION
-#define _ANONYMOUS_STRUCT
+#ifndef _ANONYMOUS_UNION
+# define _ANONYMOUS_UNION
+#endif
+#ifndef _ANONYMOUS_STRUCT
+# define _ANONYMOUS_STRUCT
 #endif
 #include <windows.h>
 /* Some versions of compiler define MEMORYSTATUSEX, some don't, so we
@@ -880,7 +882,7 @@ set_named_security_info (LPCTSTR lpObjectName,
          g_b_init_set_named_security_info_a = 1;
          hm_advapi32 = LoadLibrary ("Advapi32.dll");
          s_pfn_Set_Named_Security_InfoA =
-           (SetNamedSecurityInfoA_Proc) GetProcAddress (hm_advapi32, 
+           (SetNamedSecurityInfoA_Proc) GetProcAddress (hm_advapi32,
                                                         "SetNamedSecurityInfoA");
        }
       if (s_pfn_Set_Named_Security_InfoA == NULL)
@@ -6953,6 +6955,35 @@ system_process_attributes (Lisp_Object pid)
   return attrs;
 }
 
+int
+w32_memory_info (unsigned long long *totalram, unsigned long long *freeram,
+                unsigned long long *totalswap, unsigned long long *freeswap)
+{
+  MEMORYSTATUS memst;
+  MEMORY_STATUS_EX memstex;
+
+  /* Use GlobalMemoryStatusEx if available, as it can report more than
+     2GB of memory.  */
+  if (global_memory_status_ex (&memstex))
+    {
+      *totalram  = memstex.ullTotalPhys;
+      *freeram   = memstex.ullAvailPhys;
+      *totalswap = memstex.ullTotalPageFile;
+      *freeswap  = memstex.ullAvailPageFile;
+      return 0;
+    }
+  else if (global_memory_status (&memst))
+    {
+      *totalram = memst.dwTotalPhys;
+      *freeram   = memst.dwAvailPhys;
+      *totalswap = memst.dwTotalPageFile;
+      *freeswap  = memst.dwAvailPageFile;
+      return 0;
+    }
+  else
+    return -1;
+}
+
 \f
 /* Wrappers for  winsock functions to map between our file descriptors
    and winsock's handles; also set h_errno for convenience.
@@ -7834,7 +7865,7 @@ pipe2 (int * phandles, int pipe2_flags)
   int rc;
   unsigned flags;
 
-  eassert (pipe2_flags == O_CLOEXEC);
+  eassert (pipe2_flags == (O_BINARY | O_CLOEXEC));
 
   /* make pipe handles non-inheritable; when we spawn a child, we
      replace the relevant handle with an inheritable one.  Also put
@@ -8610,6 +8641,7 @@ network_interface_list (void)
 Lisp_Object
 network_interface_info (Lisp_Object ifname)
 {
+  CHECK_STRING (ifname);
   return network_interface_get_info (ifname);
 }