You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bn...@apache.org on 2004/03/10 00:46:54 UTC
cvs commit: apr/misc/netware rand.c
bnicholes 2004/03/09 15:46:54
Modified: misc/netware rand.c
Log:
Allow support for random bytes on older hardware
Revision Changes Path
1.10 +41 -1 apr/misc/netware/rand.c
Index: rand.c
===================================================================
RCS file: /home/cvs/apr/misc/netware/rand.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- rand.c 13 Feb 2004 09:38:32 -0000 1.9
+++ rand.c 9 Mar 2004 23:46:54 -0000 1.10
@@ -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 */