diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 06:23:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 06:23:09 +0000 |
commit | 30d479c28c831a0d4f1fdb54a9e346b0fc176be1 (patch) | |
tree | aa35d7414ce9f1326abf6f723f6dfa5b0aa08b1d /misc/netware/rand.c | |
parent | Initial commit. (diff) | |
download | apr-30d479c28c831a0d4f1fdb54a9e346b0fc176be1.tar.xz apr-30d479c28c831a0d4f1fdb54a9e346b0fc176be1.zip |
Adding upstream version 1.7.2.upstream/1.7.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc/netware/rand.c')
-rw-r--r-- | misc/netware/rand.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/misc/netware/rand.c b/misc/netware/rand.c new file mode 100644 index 0000000..a2baae7 --- /dev/null +++ b/misc/netware/rand.c @@ -0,0 +1,70 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define APR_WANT_MEMFUNC +#include "apr_want.h" +#include "apr_general.h" +#include "apr_private.h" + +#if APR_HAS_RANDOM + +#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) +{ + if (NXSeedRandom(length, buf) != 0) { + return NXSeedRandomInternal (length, buf); + } + return APR_SUCCESS; +} + + + +#endif /* APR_HAS_RANDOM */ |