diff options
author | bnicholes <bnicholes@13f79535-47bb-0310-9956-ffa450edef68> | 2004-03-10 15:55:22 +0000 |
---|---|---|
committer | bnicholes <bnicholes@13f79535-47bb-0310-9956-ffa450edef68> | 2004-03-10 15:55:22 +0000 |
commit | 38aa72aa94a8f7c5936d364ef083b3779683e27b (patch) | |
tree | 6100d10c1dc29c03bbafaf39904127fc31e3a43e | |
parent | c787e028667723cd986c61c42cb7c61f417f4b7b (diff) | |
download | libapr-38aa72aa94a8f7c5936d364ef083b3779683e27b.tar.gz |
Allow support for random bytes on older hardware
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/APR_0_9_BRANCH@64960 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | misc/netware/rand.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/misc/netware/rand.c b/misc/netware/rand.c index e2bf3a4fc..1cf66a12a 100644 --- a/misc/netware/rand.c +++ b/misc/netware/rand.c @@ -22,6 +22,39 @@ #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, #ifdef APR_ENABLE_FOR_1_0 apr_size_t length) @@ -29,7 +62,10 @@ APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf, int length) #endif { - return NXSeedRandom(length, buf); + if (NXSeedRandom(length, buf) != 0) { + return NXSeedRandomInternal (length, buf); + } + return APR_SUCCESS; } #endif /* APR_HAS_RANDOM */ |