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