+/** @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
\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
\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
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
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
}\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