apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bnicho...@apache.org
Subject cvs commit: apr/misc/netware rand.c
Date Wed, 10 Mar 2004 15:55:22 GMT
bnicholes    2004/03/10 07:55:22

  Modified:    misc/netware Tag: APR_0_9_BRANCH rand.c
  Log:
  Allow support for random bytes on older hardware
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.7.2.2   +37 -1     apr/misc/netware/rand.c
  
  Index: rand.c
  ===================================================================
  RCS file: /home/cvs/apr/misc/netware/rand.c,v
  retrieving revision 1.7.2.1
  retrieving revision 1.7.2.2
  diff -u -r1.7.2.1 -r1.7.2.2
  --- rand.c	13 Feb 2004 09:33:49 -0000	1.7.2.1
  +++ rand.c	10 Mar 2004 15:55:22 -0000	1.7.2.2
  @@ -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 @@
                                                       int length)
   #endif
   {
  -    return NXSeedRandom(length, buf);
  +    if (NXSeedRandom(length, buf) != 0) {
  +        return NXSeedRandomInternal (length, buf);
  +    }
  +    return APR_SUCCESS;
   }
   
   #endif /* APR_HAS_RANDOM */
  
  
  

Mime
View raw message