]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/uuid/detail/random_provider_getentropy.ipp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / uuid / detail / random_provider_getentropy.ipp
1 //
2 // Copyright (c) 2017 James E. King III
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // https://www.boost.org/LICENSE_1_0.txt)
7 //
8 // getentropy() capable platforms
9 //
10
11 #include <boost/config.hpp>
12 #include <boost/throw_exception.hpp>
13 #include <cerrno>
14 #include <cstddef>
15 #include <unistd.h>
16
17 namespace boost {
18 namespace uuids {
19 namespace detail {
20
21 class random_provider_base
22 {
23 public:
24 //! Obtain entropy and place it into a memory location
25 //! \param[in] buf the location to write entropy
26 //! \param[in] siz the number of bytes to acquire
27 void get_random_bytes(void *buf, std::size_t siz)
28 {
29 int res = getentropy(buf, siz);
30 if (BOOST_UNLIKELY(-1 == res))
31 {
32 int err = errno;
33 BOOST_THROW_EXCEPTION(entropy_error(err, "getentropy"));
34 }
35 }
36 };
37
38 } // detail
39 } // uuids
40 } // boost