| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/rand_util.h" | 5 #include "base/rand_util.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 | 14 |
| 15 uint64 RandUInt64() { | 15 uint64 RandUint64() { |
| 16 uint64 number; | 16 uint64 number; |
| 17 | 17 |
| 18 int urandom_fd = open("/dev/urandom", O_RDONLY); | 18 int urandom_fd = open("/dev/urandom", O_RDONLY); |
| 19 CHECK(urandom_fd >= 0); | 19 CHECK(urandom_fd >= 0); |
| 20 ssize_t bytes_read = read(urandom_fd, &number, sizeof(number)); | 20 ssize_t bytes_read = read(urandom_fd, &number, sizeof(number)); |
| 21 CHECK(bytes_read == sizeof(number)); | 21 CHECK(bytes_read == sizeof(number)); |
| 22 close(urandom_fd); | 22 close(urandom_fd); |
| 23 | 23 |
| 24 return number; | 24 return number; |
| 25 } | 25 } |
| 26 | 26 |
| 27 } // namespace base | 27 } // namespace base |
| OLD | NEW |