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 Tue, 09 Mar 2004 23:46:54 GMT
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 */
  
  
  

Mime
View raw message