summaryrefslogtreecommitdiff
path: root/misc/netware/rand.c
diff options
context:
space:
mode:
authorbnicholes <bnicholes@13f79535-47bb-0310-9956-ffa450edef68>2004-03-09 23:46:54 +0000
committerbnicholes <bnicholes@13f79535-47bb-0310-9956-ffa450edef68>2004-03-09 23:46:54 +0000
commitef8a66c8a6cfde695bf189cf0d11c7ed5a5df4b2 (patch)
tree700f91b552c11a5f553be480fbb207e4fe364ae1 /misc/netware/rand.c
parent78e39fb516a56758252311f8be083aa8e6bd949d (diff)
downloadlibapr-ef8a66c8a6cfde695bf189cf0d11c7ed5a5df4b2.tar.gz
Allow support for random bytes on older hardware
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64957 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc/netware/rand.c')
-rw-r--r--misc/netware/rand.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/misc/netware/rand.c b/misc/netware/rand.c
index 0a602b0c1..c8afa3b55 100644
--- a/misc/netware/rand.c
+++ b/misc/netware/rand.c
@@ -22,10 +22,50 @@
#include <nks/plat.h>
+static int NXSeedRandomInternal( size_t width, void *seed )
+{
+ static int init = 0;
+ int *s = (int *) seed;
+ union { int x; char y[4]; } u;
+
+ if (!init) {
+ srand(NXGetSystemTick());
+ init = 1;
+ }
+
+ if (width > 3)
+ {
+ do
+ {
+ *s++ = rand();
+ }
+ while ((width -= 4) > 3);
+ }
+
+ if (width > 0)
+ {
+ char *p = (char *) s;
+
+ u.x = rand();
+
+ while (width > 0)
+ *p++ = u.y[width--];
+ }
+
+ return APR_SUCCESS;
+}
+
APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf,
apr_size_t length)
{
- return NXSeedRandom(length, buf);
+ int ret;
+
+ if (NXSeedRandom(length, buf) != 0) {
+ return NXSeedRandomInternal (length, buf);
+ }
+ return APR_SUCCESS;
}
+
+
#endif /* APR_HAS_RANDOM */