src: use SPDX identifiers
[urcu.git] / src / compat-rand.h
CommitLineData
acdb82a2
MJ
1// SPDX-FileCopyrightText: 1996 Ulrich Drepper <drepper@cygnus.com>
2// SPDX-FileCopyrightText: 2013 Pierre-Luc St-Charles <pierre-luc.st-charles@polymtl.ca>
3//
4// SPDX-License-Identifier: LGPL-2.1-or-later
5
094c8c59
MJ
6#ifndef _COMPAT_RAND_H
7#define _COMPAT_RAND_H
e1c0b55c
PLSC
8
9/*
e1c0b55c
PLSC
10 * Userspace RCU library - rand/rand_r Compatibility Header
11 *
e1c0b55c
PLSC
12 * Note: this file is only used to simplify the code required to
13 * use the 'rand_r(...)' system function across multiple platforms,
14 * which might not always be referenced the same way.
e1c0b55c
PLSC
15 */
16
3e4ae45a 17#ifndef HAVE_RAND_R
e1c0b55c
PLSC
18/*
19 * Reentrant random function from POSIX.1c.
20 * Copyright (C) 1996, 1999 Free Software Foundation, Inc.
21 * This file is part of the GNU C Library.
22 * Contributed by Ulrich Drepper <drepper@cygnus.com <mailto:drepper@cygnus.com>>, 1996.
23 */
24static inline int rand_r(unsigned int *seed)
25{
26 unsigned int next = *seed;
27 int result;
28
29 next *= 1103515245;
30 next += 12345;
31 result = (unsigned int) (next / 65536) % 2048;
32
33 next *= 1103515245;
34 next += 12345;
35 result <<= 10;
36 result ^= (unsigned int) (next / 65536) % 1024;
37
38 next *= 1103515245;
39 next += 12345;
40 result <<= 10;
41 result ^= (unsigned int) (next / 65536) % 1024;
42
43 *seed = next;
44
45 return result;
46}
3e4ae45a 47#endif /* HAVE_RAND_R */
e1c0b55c 48
094c8c59 49#endif /* _COMPAT_RAND_H */
This page took 0.041028 seconds and 4 git commands to generate.