1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/rand_util_posix.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,29 @@ 1.4 +// Copyright (c) 2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "base/rand_util.h" 1.9 + 1.10 +#include <fcntl.h> 1.11 +#include <unistd.h> 1.12 + 1.13 +#include "base/file_util.h" 1.14 +#include "base/logging.h" 1.15 + 1.16 +namespace base { 1.17 + 1.18 +uint64_t RandUint64() { 1.19 + uint64_t number; 1.20 + 1.21 + int urandom_fd = open("/dev/urandom", O_RDONLY); 1.22 + CHECK(urandom_fd >= 0); 1.23 + bool success = file_util::ReadFromFD(urandom_fd, 1.24 + reinterpret_cast<char*>(&number), 1.25 + sizeof(number)); 1.26 + CHECK(success); 1.27 + close(urandom_fd); 1.28 + 1.29 + return number; 1.30 +} 1.31 + 1.32 +} // namespace base