upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / misc / netware / rand.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #define APR_WANT_MEMFUNC
18 #include "apr_want.h"
19 #include "apr_general.h"
20 #include "apr_private.h"
21
22 #if APR_HAS_RANDOM
23
24 #include <nks/plat.h>
25
26 static int NXSeedRandomInternal( size_t width, void *seed )
27 {
28     static int init = 0;
29     int                        *s = (int *) seed;
30     union { int x; char y[4]; } u;
31
32     if (!init) {
33         srand(NXGetSystemTick());
34         init = 1;
35     }
36  
37     if (width > 3)
38     {
39         do
40         {
41             *s++ = rand();
42         }
43         while ((width -= 4) > 3);
44     }
45  
46     if (width > 0)
47     {
48         char *p = (char *) s;
49
50         u.x = rand();
51  
52         while (width > 0)
53            *p++ = u.y[width--];
54     }
55  
56     return APR_SUCCESS;
57 }
58
59 APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf, 
60 #ifdef APR_ENABLE_FOR_1_0
61                                                     apr_size_t length)
62 #else
63                                                     int length)
64 #endif
65 {
66     if (NXSeedRandom(length, buf) != 0) {
67         return NXSeedRandomInternal (length, buf);
68     }
69     return APR_SUCCESS;
70 }
71
72 #endif /* APR_HAS_RANDOM */