| File: | root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/nspr/pr/./../../../../../nsprpub/pr/src/md/unix/uxrng.c |
| Warning: | line 112, column 9 Value stored to 'size' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | |
| 5 | #include "primpl.h" |
| 6 | |
| 7 | #include <string.h> |
| 8 | #include <unistd.h> |
| 9 | #include <errno(*__errno_location ()).h> |
| 10 | #include <sys/time.h> |
| 11 | |
| 12 | #if defined(SOLARIS) |
| 13 | |
| 14 | static size_t |
| 15 | GetHighResClock(void* buf, size_t maxbytes) |
| 16 | { |
| 17 | hrtime_t t; |
| 18 | t = gethrtime(); |
| 19 | if (t) { |
| 20 | return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t)); |
| 21 | } |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | #elif defined(AIX) |
| 26 | |
| 27 | static size_t |
| 28 | GetHighResClock(void* buf, size_t maxbytes) |
| 29 | { |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | #elif (defined(LINUX1) || defined(FREEBSD) || defined(__FreeBSD_kernel__) || \ |
| 34 | defined(NETBSD) || defined(__NetBSD_kernel__) || defined(OPENBSD) || \ |
| 35 | defined(__GNU__)) |
| 36 | #include <sys/types.h> |
| 37 | #include <sys/stat.h> |
| 38 | #include <fcntl.h> |
| 39 | |
| 40 | static int fdDevURandom; |
| 41 | static PRCallOnceType coOpenDevURandom; |
| 42 | |
| 43 | static PRStatus |
| 44 | OpenDevURandom(void) |
| 45 | { |
| 46 | fdDevURandom = open("/dev/urandom", O_RDONLY00); |
| 47 | return ((-1 == fdDevURandom) ? PR_FAILURE : PR_SUCCESS); |
| 48 | } /* end OpenDevURandom() */ |
| 49 | |
| 50 | static size_t |
| 51 | GetDevURandom(void* buf, size_t size) |
| 52 | { |
| 53 | int bytesIn; |
| 54 | int rc; |
| 55 | |
| 56 | rc = PR_CallOnce(&coOpenDevURandom, OpenDevURandom); |
| 57 | if (PR_FAILURE == rc) { |
| 58 | _PR_MD_MAP_OPEN_ERROR_MD_unix_map_open_error(errno(*__errno_location ())); |
| 59 | return (0); |
| 60 | } |
| 61 | |
| 62 | bytesIn = read(fdDevURandom, buf, size); |
| 63 | if (-1 == bytesIn) { |
| 64 | _PR_MD_MAP_READ_ERROR_MD_unix_map_read_error(errno(*__errno_location ())); |
| 65 | return (0); |
| 66 | } |
| 67 | |
| 68 | return (bytesIn); |
| 69 | } /* end GetDevURandom() */ |
| 70 | |
| 71 | static size_t |
| 72 | GetHighResClock(void* buf, size_t maxbytes) |
| 73 | { |
| 74 | return (GetDevURandom(buf, maxbytes)); |
| 75 | } |
| 76 | |
| 77 | #elif defined(NTO) || defined(QNX) || defined(DARWIN) || defined(RISCOS) |
| 78 | #include <sys/times.h> |
| 79 | |
| 80 | static size_t |
| 81 | GetHighResClock(void* buf, size_t maxbytes) |
| 82 | { |
| 83 | int ticks; |
| 84 | struct tms buffer; |
| 85 | |
| 86 | ticks = times(&buffer); |
| 87 | return _pr_CopyLowBits(buf, maxbytes, &ticks, sizeof(ticks)); |
| 88 | } |
| 89 | #else |
| 90 | #error ! Platform undefined |
| 91 | #endif /* defined(SOLARIS) */ |
| 92 | |
| 93 | extern PRSize |
| 94 | _PR_MD_GetRandomNoise(void* buf, PRSize size) |
| 95 | { |
| 96 | struct timeval tv; |
| 97 | int n = 0; |
| 98 | int s; |
| 99 | |
| 100 | n += GetHighResClock(buf, size); |
| 101 | size -= n; |
| 102 | |
| 103 | GETTIMEOFDAY(&tv)gettimeofday((&tv), ((void*)0)); |
| 104 | |
| 105 | if (size > 0) { |
| 106 | s = _pr_CopyLowBits((char*)buf + n, size, &tv.tv_usec, sizeof(tv.tv_usec)); |
| 107 | size -= s; |
| 108 | n += s; |
| 109 | } |
| 110 | if (size > 0) { |
| 111 | s = _pr_CopyLowBits((char*)buf + n, size, &tv.tv_sec, sizeof(tv.tv_usec)); |
| 112 | size -= s; |
Value stored to 'size' is never read | |
| 113 | n += s; |
| 114 | } |
| 115 | |
| 116 | return n; |
| 117 | } /* end _PR_MD_GetRandomNoise() */ |