]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.10/PyMod-2.7.10/Python/random.c
AppPkg/.../Python-2.7.10: AppPkg.dsc, pyconfig.h, PyMod-2.7.10
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / PyMod-2.7.10 / Python / random.c
index 14d81a91a7997c364b1f1714ac7a8d058ee33213..e69c6ddf6cb2b2734c54b85db6de403277699a49 100644 (file)
@@ -1,3 +1,15 @@
+/** @file\r
+\r
+  Copyright (c) 2015, Daryl McDaniel. All rights reserved.<BR>\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
 #include "Python.h"\r
 #ifdef MS_WINDOWS\r
 #include <windows.h>\r
@@ -153,8 +165,12 @@ vms_urandom(unsigned char *buffer, Py_ssize_t size, int raise)
 \r
 static struct {\r
     int fd;\r
+#ifdef HAVE_STRUCT_STAT_ST_DEV\r
     dev_t st_dev;\r
+#endif\r
+#ifdef HAVE_STRUCT_STAT_ST_INO\r
     ino_t st_ino;\r
+#endif\r
 } urandom_cache = { -1 };\r
 \r
 /* Read size bytes from /dev/urandom into buffer.\r
@@ -167,7 +183,7 @@ dev_urandom_noraise(unsigned char *buffer, Py_ssize_t size)
 \r
     assert (0 < size);\r
 \r
-    fd = open("/dev/urandom", O_RDONLY);\r
+    fd = open("/dev/urandom", O_RDONLY, 0);\r
     if (fd < 0)\r
         Py_FatalError("Failed to open /dev/urandom");\r
 \r
@@ -204,8 +220,14 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
     if (urandom_cache.fd >= 0) {\r
         /* Does the fd point to the same thing as before? (issue #21207) */\r
         if (fstat(urandom_cache.fd, &st)\r
+#ifdef HAVE_STRUCT_STAT_ST_DEV\r
             || st.st_dev != urandom_cache.st_dev\r
-            || st.st_ino != urandom_cache.st_ino) {\r
+#endif\r
+#ifdef  HAVE_STRUCT_STAT_ST_INO\r
+            || st.st_ino != urandom_cache.st_ino\r
+#endif\r
+           )\r
+        {\r
             /* Something changed: forget the cached fd (but don't close it,\r
                since it probably points to something important for some\r
                third-party code). */\r
@@ -216,7 +238,7 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
         fd = urandom_cache.fd;\r
     else {\r
         Py_BEGIN_ALLOW_THREADS\r
-        fd = open("/dev/urandom", O_RDONLY);\r
+        fd = open("/dev/urandom", O_RDONLY, 0);\r
         Py_END_ALLOW_THREADS\r
         if (fd < 0)\r
         {\r
@@ -250,8 +272,12 @@ dev_urandom_python(char *buffer, Py_ssize_t size)
             }\r
             else {\r
                 urandom_cache.fd = fd;\r
+#ifdef HAVE_STRUCT_STAT_ST_DEV\r
                 urandom_cache.st_dev = st.st_dev;\r
+#endif\r
+#ifdef HAVE_STRUCT_STAT_ST_INO\r
                 urandom_cache.st_ino = st.st_ino;\r
+#endif\r
             }\r
         }\r
     }\r