This commit globally defines the `Z_LIBC_DATA` macro, which is used to place variables into the libc memory partition, so that it can be re-used. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
33 lines
605 B
C
33 lines
605 B
C
/*
|
|
* Copyright (c) 2021 Space Cubics, LLC.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <zephyr/sys/libc-hooks.h>
|
|
|
|
#define OUTPUT_BITS (0x7fffffffU)
|
|
#define MULTIPLIER (1103515245U)
|
|
#define INCREMENT (12345U)
|
|
|
|
int rand_r(unsigned int *seed)
|
|
{
|
|
*seed = (MULTIPLIER * *seed + INCREMENT) & OUTPUT_BITS;
|
|
|
|
return *seed;
|
|
}
|
|
|
|
#ifdef CONFIG_MINIMAL_LIBC_NON_REENTRANT_FUNCTIONS
|
|
static Z_LIBC_DATA unsigned int srand_seed = 1;
|
|
|
|
void srand(unsigned int s)
|
|
{
|
|
srand_seed = s;
|
|
}
|
|
|
|
int rand(void)
|
|
{
|
|
return rand_r(&srand_seed);
|
|
}
|
|
#endif /* CONFIG_MINIMAL_LIBC_NON_REENTRANT_FUNCTIONS */
|