This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Move getentropy/getrandom into own file


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bbf6993a2dba70ee9cd99b20a039e15d754400ef

commit bbf6993a2dba70ee9cd99b20a039e15d754400ef
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Jan 19 20:58:06 2017 +0100

    Move getentropy/getrandom into own file
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/Makefile.in        |  1 +
 winsup/cygwin/libc/getentropy.cc | 70 ++++++++++++++++++++++++++++++++++++++++
 winsup/cygwin/miscfuncs.cc       | 57 --------------------------------
 3 files changed, 71 insertions(+), 57 deletions(-)

diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 7c01df7..bffb24a 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -307,6 +307,7 @@ DLL_OFILES:= \
 	fork.o \
 	fts.o \
 	ftw.o \
+	getentropy.o \
 	getopt.o \
 	glob.o \
 	glob_pattern_p.o \
diff --git a/winsup/cygwin/libc/getentropy.cc b/winsup/cygwin/libc/getentropy.cc
new file mode 100644
index 0000000..5918eb5
--- /dev/null
+++ b/winsup/cygwin/libc/getentropy.cc
@@ -0,0 +1,70 @@
+/* getentropy.cc: getentropy/getrandmom functions
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#include "winsup.h"
+#include <ntsecapi.h>
+#include <sys/param.h>
+#include <sys/random.h>
+#include "cygtls.h"
+#include "ntdll.h"
+
+extern "C" int
+getentropy (void *ptr, size_t len)
+{
+  /* Per BSD man page: The maximum buffer size permitted is 256 bytes.
+     If buflen exceeds this, an error of EIO will be indicated. */
+  if (len > 256)
+    {
+      debug_printf ("len (%U) > 256", len);
+      set_errno (EIO);
+      return -1;
+    }
+  __try
+    {
+      if (!RtlGenRandom (ptr, len))
+	{
+	  debug_printf ("RtlGenRandom() = FALSE");
+	  set_errno (EIO);
+	  return -1;
+	}
+    }
+  __except (EFAULT)
+    {
+      return -1;
+    }
+  __endtry
+  return 0;
+}
+
+extern "C" ssize_t
+getrandom (void *ptr, size_t len, unsigned int flags)
+{
+  if (flags & ~(GRND_NONBLOCK | GRND_RANDOM))
+    {
+      debug_printf ("invalid flags: %y", flags);
+      set_errno (EINVAL);
+      return -1;
+    }
+  /* Max. bytes returned by Linux call. */
+  len = MAX (len, (flags & GRND_RANDOM) ? 512 : 33554431);
+  __try
+    {
+      if (!RtlGenRandom (ptr, len))
+	{
+	  debug_printf ("RtlGenRandom() = FALSE");
+	  set_errno (EIO);
+	  return -1;
+	}
+    }
+  __except (EFAULT)
+    {
+      return -1;
+    }
+  __endtry
+  return len;
+}
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc
index 044d727..a84c587 100644
--- a/winsup/cygwin/miscfuncs.cc
+++ b/winsup/cygwin/miscfuncs.cc
@@ -14,7 +14,6 @@ details. */
 #include <alloca.h>
 #include <limits.h>
 #include <sys/param.h>
-#include <sys/random.h>
 #include <wchar.h>
 #include "cygtls.h"
 #include "ntdll.h"
@@ -235,62 +234,6 @@ check_iovec (const struct iovec *iov, int iovcnt, bool forwrite)
   return -1;
 }
 
-extern "C" int
-getentropy (void *ptr, size_t len)
-{
-  /* Per BSD man page: The maximum buffer size permitted is 256 bytes.
-     If buflen exceeds this, an error of EIO will be indicated. */
-  if (len > 256)
-    {
-      debug_printf ("len (%U) > 256", len);
-      set_errno (EIO);
-      return -1;
-    }
-  __try
-    {
-      if (!RtlGenRandom (ptr, len))
-	{
-	  debug_printf ("RtlGenRandom() = FALSE");
-	  set_errno (EIO);
-	  return -1;
-	}
-    }
-  __except (EFAULT)
-    {
-      return -1;
-    }
-  __endtry
-  return 0;
-}
-
-extern "C" ssize_t
-getrandom (void *ptr, size_t len, unsigned int flags)
-{
-  if (flags & ~(GRND_NONBLOCK | GRND_RANDOM))
-    {
-      debug_printf ("invalid flags: %y", flags);
-      set_errno (EINVAL);
-      return -1;
-    }
-  /* Max. bytes returned by Linux call. */
-  len = MAX (len, (flags & GRND_RANDOM) ? 512 : 33554431);
-  __try
-    {
-      if (!RtlGenRandom (ptr, len))
-	{
-	  debug_printf ("RtlGenRandom() = FALSE");
-	  set_errno (EIO);
-	  return -1;
-	}
-    }
-  __except (EFAULT)
-    {
-      return -1;
-    }
-  __endtry
-  return len;
-}
-
 /* Try hard to schedule another thread.  
    Remember not to call this in a lock condition or you'll potentially
    suffer starvation.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]