Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: third_party/libc++/src/random.cpp

Issue 75213003: Add libc++ and libc++abi to third-party. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/libc++/src/optional.cpp ('k') | third_party/libc++/src/regex.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/libc++/src/random.cpp
===================================================================
--- third_party/libc++/src/random.cpp (revision 0)
+++ third_party/libc++/src/random.cpp (revision 0)
@@ -0,0 +1,74 @@
+//===-------------------------- random.cpp --------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#if defined(_WIN32)
+// Must be defined before including stdlib.h to enable rand_s().
+#define _CRT_RAND_S
+#include <stdio.h>
+#endif
+
+#include "random"
+#include "system_error"
+
+#ifdef __sun__
+#define rename solaris_headers_are_broken
+#endif
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if defined(_WIN32)
+random_device::random_device(const string&)
+{
+}
+
+random_device::~random_device()
+{
+}
+
+unsigned
+random_device::operator()()
+{
+ unsigned r;
+ errno_t err = rand_s(&r);
+ if (err)
+ __throw_system_error(err, "random_device rand_s failed.");
+ return r;
+}
+#else
+random_device::random_device(const string& __token)
+ : __f_(open(__token.c_str(), O_RDONLY))
+{
+ if (__f_ <= 0)
+ __throw_system_error(errno, ("random_device failed to open " + __token).c_str());
+}
+
+random_device::~random_device()
+{
+ close(__f_);
+}
+
+unsigned
+random_device::operator()()
+{
+ unsigned r;
+ read(__f_, &r, sizeof(r));
+ return r;
+}
+#endif // defined(_WIN32)
+
+double
+random_device::entropy() const _NOEXCEPT
+{
+ return 0;
+}
+
+_LIBCPP_END_NAMESPACE_STD
Property changes on: third_party/libc++/src/random.cpp
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « third_party/libc++/src/optional.cpp ('k') | third_party/libc++/src/regex.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698