~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to system/lib/libcxx/random.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===-------------------------- random.cpp --------------------------------===//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is dual licensed under the MIT and the University of Illinois Open
 
6
// Source Licenses. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
 
 
10
#include "random"
 
11
#include "system_error"
 
12
 
 
13
#ifdef __sun__
 
14
#define rename solaris_headers_are_broken
 
15
#endif
 
16
#include <fcntl.h>
 
17
#include <unistd.h>
 
18
#include <errno.h>
 
19
 
 
20
_LIBCPP_BEGIN_NAMESPACE_STD
 
21
 
 
22
random_device::random_device(const string& __token)
 
23
    : __f_(open(__token.c_str(), O_RDONLY))
 
24
{
 
25
    if (__f_ <= 0)
 
26
        __throw_system_error(errno, ("random_device failed to open " + __token).c_str());
 
27
}
 
28
 
 
29
random_device::~random_device()
 
30
{
 
31
    close(__f_);
 
32
}
 
33
 
 
34
unsigned
 
35
random_device::operator()()
 
36
{
 
37
    unsigned r;
 
38
    read(__f_, &r, sizeof(r));
 
39
    return r;
 
40
}
 
41
 
 
42
double
 
43
random_device::entropy() const _NOEXCEPT
 
44
{
 
45
    return 0;
 
46
}
 
47
 
 
48
_LIBCPP_END_NAMESPACE_STD