[uClibc]rand functions
Geoffrey Espin
espin at idiom.com
Tue Feb 26 01:26:18 UTC 2002
This patch adds glibc's rand48 functions, needed by the pppd package.
--
Geoffrey Espin
espin at idiom.com
--
diff -b -Naur uClibc.orig/include/ieee754.h uClibc/include/ieee754.h
--- uClibc.orig/include/ieee754.h Wed Dec 31 16:00:00 1969
+++ uClibc/include/ieee754.h Mon Feb 25 15:50:03 2002
@@ -0,0 +1,199 @@
+/* Copyright (C) 1992, 1995, 1996, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#ifndef _IEEE754_H
+
+#define _IEEE754_H 1
+#include <features.h>
+
+#include <endian.h>
+
+__BEGIN_DECLS
+
+union ieee754_float
+ {
+ float f;
+
+ /* This is the IEEE 754 single-precision format. */
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int negative:1;
+ unsigned int exponent:8;
+ unsigned int mantissa:23;
+#endif /* Big endian. */
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ unsigned int mantissa:23;
+ unsigned int exponent:8;
+ unsigned int negative:1;
+#endif /* Little endian. */
+ } ieee;
+
+ /* This format makes it easier to see if a NaN is a signalling NaN. */
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int negative:1;
+ unsigned int exponent:8;
+ unsigned int quiet_nan:1;
+ unsigned int mantissa:22;
+#endif /* Big endian. */
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ unsigned int mantissa:22;
+ unsigned int quiet_nan:1;
+ unsigned int exponent:8;
+ unsigned int negative:1;
+#endif /* Little endian. */
+ } ieee_nan;
+ };
+
+#define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */
+
+
+union ieee754_double
+ {
+ double d;
+
+ /* This is the IEEE 754 double-precision format. */
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int negative:1;
+ unsigned int exponent:11;
+ /* Together these comprise the mantissa. */
+ unsigned int mantissa0:20;
+ unsigned int mantissa1:32;
+#endif /* Big endian. */
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+# if __FLOAT_WORD_ORDER == BIG_ENDIAN
+ unsigned int mantissa0:20;
+ unsigned int exponent:11;
+ unsigned int negative:1;
+ unsigned int mantissa1:32;
+# else
+ /* Together these comprise the mantissa. */
+ unsigned int mantissa1:32;
+ unsigned int mantissa0:20;
+ unsigned int exponent:11;
+ unsigned int negative:1;
+# endif
+#endif /* Little endian. */
+ } ieee;
+
+ /* This format makes it easier to see if a NaN is a signalling NaN. */
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int negative:1;
+ unsigned int exponent:11;
+ unsigned int quiet_nan:1;
+ /* Together these comprise the mantissa. */
+ unsigned int mantissa0:19;
+ unsigned int mantissa1:32;
+#else
+# if __FLOAT_WORD_ORDER == BIG_ENDIAN
+ unsigned int mantissa0:19;
+ unsigned int quiet_nan:1;
+ unsigned int exponent:11;
+ unsigned int negative:1;
+ unsigned int mantissa1:32;
+# else
+ /* Together these comprise the mantissa. */
+ unsigned int mantissa1:32;
+ unsigned int mantissa0:19;
+ unsigned int quiet_nan:1;
+ unsigned int exponent:11;
+ unsigned int negative:1;
+# endif
+#endif
+ } ieee_nan;
+ };
+
+#define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */
+
+
+union ieee854_long_double
+ {
+ long double d;
+
+ /* This is the IEEE 854 double-extended-precision format. */
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int negative:1;
+ unsigned int exponent:15;
+ unsigned int empty:16;
+ unsigned int mantissa0:32;
+ unsigned int mantissa1:32;
+#endif
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+# if __FLOAT_WORD_ORDER == BIG_ENDIAN
+ unsigned int exponent:15;
+ unsigned int negative:1;
+ unsigned int empty:16;
+ unsigned int mantissa0:32;
+ unsigned int mantissa1:32;
+# else
+ unsigned int mantissa1:32;
+ unsigned int mantissa0:32;
+ unsigned int exponent:15;
+ unsigned int negative:1;
+ unsigned int empty:16;
+# endif
+#endif
+ } ieee;
+
+ /* This is for NaNs in the IEEE 854 double-extended-precision format. */
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int negative:1;
+ unsigned int exponent:15;
+ unsigned int empty:16;
+ unsigned int one:1;
+ unsigned int quiet_nan:1;
+ unsigned int mantissa0:30;
+ unsigned int mantissa1:32;
+#endif
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+# if __FLOAT_WORD_ORDER == BIG_ENDIAN
+ unsigned int exponent:15;
+ unsigned int negative:1;
+ unsigned int empty:16;
+ unsigned int mantissa0:30;
+ unsigned int quiet_nan:1;
+ unsigned int one:1;
+ unsigned int mantissa1:32;
+# else
+ unsigned int mantissa1:32;
+ unsigned int mantissa0:30;
+ unsigned int quiet_nan:1;
+ unsigned int one:1;
+ unsigned int exponent:15;
+ unsigned int negative:1;
+ unsigned int empty:16;
+# endif
+#endif
+ } ieee_nan;
+ };
+
+#define IEEE854_LONG_DOUBLE_BIAS 0x3fff
+
+__END_DECLS
+
+#endif /* ieee754.h */
diff -b -Naur uClibc.orig/libc/misc/internals/interp.c uClibc/libc/misc/internals/interp.c
--- uClibc.orig/libc/misc/internals/interp.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/misc/internals/interp.c Mon Feb 25 14:15:55 2002
@@ -0,0 +1,2 @@
+/* Force shared libraries to know about the correct library loader */
+const char __dl_ldso__[] __attribute__ ((section (".interp"))) ="";
diff -b -Naur uClibc.orig/libc/stdlib/Makefile uClibc/libc/stdlib/Makefile
--- uClibc.orig/libc/stdlib/Makefile Wed Feb 13 01:47:03 2002
+++ uClibc/libc/stdlib/Makefile Mon Feb 25 17:03:23 2002
@@ -36,10 +36,16 @@
MSRC2=atexit.c
MOBJ2=atexit.o on_exit.o __exit_handler.o exit.o
+# all from glibc-2.2.5
+CSRC_RAND=drand48.c drand48-iter.c drand48_r.c erand48.c erand48_r.c \
+ jrand48.c jrand48_r.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c \
+ nrand48.c nrand48_r.c rand_r.c srand48.c srand48_r.c
CSRC = abort.c getenv.c mktemp.c qsort.c realpath.c abs.c bsearch.c \
mkstemp.c putenv.c rand.c random.c setenv.c system.c div.c ldiv.c \
- getpt.c ptsname.c grantpt.c unlockpt.c gcvt.c
+ getpt.c ptsname.c grantpt.c unlockpt.c gcvt.c \
+ $(CSRC_RAND)
+
ifeq ($(HAS_FLOATING_POINT),true)
CSRC += strtod.c
endif
diff -b -Naur uClibc.orig/libc/stdlib/drand48-iter.c uClibc/libc/stdlib/drand48-iter.c
--- uClibc.orig/libc/stdlib/drand48-iter.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/drand48-iter.c Mon Feb 25 15:41:22 2002
@@ -0,0 +1,59 @@
+/* Copyright (C) 1995, 1996, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+/* Global state for non-reentrant functions. */
+struct drand48_data __libc_drand48_data;
+
+
+int
+__drand48_iterate (xsubi, buffer)
+ unsigned short int xsubi[3];
+ struct drand48_data *buffer;
+{
+ uint64_t X;
+ uint64_t result;
+
+ /* Initialize buffer, if not yet done. */
+ if (__builtin_expect (!buffer->__init, 0))
+ {
+ buffer->__a = 0x5deece66dull;
+ buffer->__c = 0xb;
+ buffer->__init = 1;
+ }
+
+ /* Do the real work. We choose a data type which contains at least
+ 48 bits. Because we compute the modulus it does not care how
+ many bits really are computed. */
+
+ X = (uint64_t) xsubi[2] << 32 | (uint32_t) xsubi[1] << 16 | xsubi[0];
+
+ result = X * buffer->__a + buffer->__c;
+
+ xsubi[0] = result & 0xffff;
+ xsubi[1] = (result >> 16) & 0xffff;
+ xsubi[2] = (result >> 32) & 0xffff;
+
+ return 0;
+}
diff -b -Naur uClibc.orig/libc/stdlib/drand48.c uClibc/libc/stdlib/drand48.c
--- uClibc.orig/libc/stdlib/drand48.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/drand48.c Mon Feb 25 15:41:22 2002
@@ -0,0 +1,33 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+/* Global state for non-reentrant functions. Defined in drand48-iter.c. */
+extern struct drand48_data __libc_drand48_data;
+
+double
+drand48 ()
+{
+ double result;
+
+ (void) __erand48_r (__libc_drand48_data.__x, &__libc_drand48_data, &result);
+
+ return result;
+}
diff -b -Naur uClibc.orig/libc/stdlib/drand48_r.c uClibc/libc/stdlib/drand48_r.c
--- uClibc.orig/libc/stdlib/drand48_r.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/drand48_r.c Mon Feb 25 15:41:22 2002
@@ -0,0 +1,30 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <math.h>
+#include <stdlib.h>
+
+int
+drand48_r (buffer, result)
+ struct drand48_data *buffer;
+ double *result;
+{
+ return __erand48_r (buffer->__x, buffer, result);
+}
diff -b -Naur uClibc.orig/libc/stdlib/erand48.c uClibc/libc/stdlib/erand48.c
--- uClibc.orig/libc/stdlib/erand48.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/erand48.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,34 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+/* Global state for non-reentrant functions. Defined in drand48-iter.c. */
+extern struct drand48_data __libc_drand48_data;
+
+double
+erand48 (xsubi)
+ unsigned short int xsubi[3];
+{
+ double result;
+
+ (void) __erand48_r (xsubi, &__libc_drand48_data, &result);
+
+ return result;
+}
diff -b -Naur uClibc.orig/libc/stdlib/erand48_r.c uClibc/libc/stdlib/erand48_r.c
--- uClibc.orig/libc/stdlib/erand48_r.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/erand48_r.c Mon Feb 25 15:49:02 2002
@@ -0,0 +1,50 @@
+/* Copyright (C) 1995, 1997, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <ieee754.h>
+#include <stdlib.h>
+#include <limits.h>
+
+
+int
+__erand48_r (xsubi, buffer, result)
+ unsigned short int xsubi[3];
+ struct drand48_data *buffer;
+ double *result;
+{
+ union ieee754_double temp;
+
+ /* Compute next state. */
+ if (__drand48_iterate (xsubi, buffer) < 0)
+ return -1;
+
+ /* Construct a positive double with the 48 random bits distributed over
+ its fractional part so the resulting FP number is [0.0,1.0). */
+
+ temp.ieee.negative = 0;
+ temp.ieee.exponent = IEEE754_DOUBLE_BIAS;
+ temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12);
+ temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4);
+
+ /* Please note the lower 4 bits of mantissa1 are always 0. */
+ *result = temp.d - 1.0;
+
+ return 0;
+}
+weak_alias (__erand48_r, erand48_r)
diff -b -Naur uClibc.orig/libc/stdlib/jrand48.c uClibc/libc/stdlib/jrand48.c
--- uClibc.orig/libc/stdlib/jrand48.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/jrand48.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,34 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+/* Global state for non-reentrant functions. Defined in drand48-iter.c. */
+extern struct drand48_data __libc_drand48_data;
+
+long int
+jrand48 (xsubi)
+ unsigned short int xsubi[3];
+{
+ long int result;
+
+ (void) __jrand48_r (xsubi, &__libc_drand48_data, &result);
+
+ return result;
+}
diff -b -Naur uClibc.orig/libc/stdlib/jrand48_r.c uClibc/libc/stdlib/jrand48_r.c
--- uClibc.orig/libc/stdlib/jrand48_r.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/jrand48_r.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,37 @@
+/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+int
+__jrand48_r (xsubi, buffer, result)
+ unsigned short int xsubi[3];
+ struct drand48_data *buffer;
+ long int *result;
+{
+ /* Compute next state. */
+ if (__drand48_iterate (xsubi, buffer) < 0)
+ return -1;
+
+ /* Store the result. */
+ *result = ((xsubi[2] << 16) | xsubi[1]) & 0xffffffffl;
+
+ return 0;
+}
+weak_alias (__jrand48_r, jrand48_r)
diff -b -Naur uClibc.orig/libc/stdlib/lrand48.c uClibc/libc/stdlib/lrand48.c
--- uClibc.orig/libc/stdlib/lrand48.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/lrand48.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,33 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+/* Global state for non-reentrant functions. Defined in drand48-iter.c. */
+extern struct drand48_data __libc_drand48_data;
+
+long int
+lrand48 ()
+{
+ long int result;
+
+ (void) __nrand48_r (__libc_drand48_data.__x, &__libc_drand48_data, &result);
+
+ return result;
+}
diff -b -Naur uClibc.orig/libc/stdlib/lrand48_r.c uClibc/libc/stdlib/lrand48_r.c
--- uClibc.orig/libc/stdlib/lrand48_r.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/lrand48_r.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,32 @@
+/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+int
+lrand48_r (buffer, result)
+ struct drand48_data *buffer;
+ long int *result;
+{
+ /* Be generous for the arguments, detect some errors. */
+ if (buffer == NULL)
+ return -1;
+
+ return __nrand48_r (buffer->__x, buffer, result);
+}
diff -b -Naur uClibc.orig/libc/stdlib/mrand48.c uClibc/libc/stdlib/mrand48.c
--- uClibc.orig/libc/stdlib/mrand48.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/mrand48.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,33 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+/* Global state for non-reentrant functions. Defined in drand48-iter.c. */
+extern struct drand48_data __libc_drand48_data;
+
+long int
+mrand48 ()
+{
+ long int result;
+
+ (void) __jrand48_r (__libc_drand48_data.__x, &__libc_drand48_data, &result);
+
+ return result;
+}
diff -b -Naur uClibc.orig/libc/stdlib/mrand48_r.c uClibc/libc/stdlib/mrand48_r.c
--- uClibc.orig/libc/stdlib/mrand48_r.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/mrand48_r.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,32 @@
+/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+int
+mrand48_r (buffer, result)
+ struct drand48_data *buffer;
+ long int *result;
+{
+ /* Be generous for the arguments, detect some errors. */
+ if (buffer == NULL)
+ return -1;
+
+ return __jrand48_r (buffer->__x, buffer, result);
+}
diff -b -Naur uClibc.orig/libc/stdlib/nrand48.c uClibc/libc/stdlib/nrand48.c
--- uClibc.orig/libc/stdlib/nrand48.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/nrand48.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,34 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+/* Global state for non-reentrant functions. Defined in drand48-iter.c. */
+extern struct drand48_data __libc_drand48_data;
+
+long int
+nrand48 (xsubi)
+ unsigned short int xsubi[3];
+{
+ long int result;
+
+ (void) __nrand48_r (xsubi, &__libc_drand48_data, &result);
+
+ return result;
+}
diff -b -Naur uClibc.orig/libc/stdlib/nrand48_r.c uClibc/libc/stdlib/nrand48_r.c
--- uClibc.orig/libc/stdlib/nrand48_r.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/nrand48_r.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,40 @@
+/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+int
+__nrand48_r (xsubi, buffer, result)
+ unsigned short int xsubi[3];
+ struct drand48_data *buffer;
+ long int *result;
+{
+ /* Compute next state. */
+ if (__drand48_iterate (xsubi, buffer) < 0)
+ return -1;
+
+ /* Store the result. */
+ if (sizeof (unsigned short int) == 2)
+ *result = xsubi[2] << 15 | xsubi[1] >> 1;
+ else
+ *result = xsubi[2] >> 1;
+
+ return 0;
+}
+weak_alias (__nrand48_r, nrand48_r)
diff -b -Naur uClibc.orig/libc/stdlib/rand_r.c uClibc/libc/stdlib/rand_r.c
--- uClibc.orig/libc/stdlib/rand_r.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/rand_r.c Mon Feb 25 15:41:32 2002
@@ -0,0 +1,49 @@
+/* Reentrant random function frm POSIX.1c.
+ Copyright (C) 1996, 1999 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+
+/* This algorithm is mentioned in the ISO C standard, here extended
+ for 32 bits. */
+int
+rand_r (unsigned int *seed)
+{
+ unsigned int next = *seed;
+ int result;
+
+ next *= 1103515245;
+ next += 12345;
+ result = (unsigned int) (next / 65536) % 2048;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 10;
+ result ^= (unsigned int) (next / 65536) % 1024;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 10;
+ result ^= (unsigned int) (next / 65536) % 1024;
+
+ *seed = next;
+
+ return result;
+}
diff -b -Naur uClibc.orig/libc/stdlib/srand48.c uClibc/libc/stdlib/srand48.c
--- uClibc.orig/libc/stdlib/srand48.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/srand48.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,30 @@
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+
+/* Global state for non-reentrant functions. Defined in drand48-iter.c. */
+extern struct drand48_data __libc_drand48_data;
+
+void
+srand48 (seedval)
+ long seedval;
+{
+ (void) __srand48_r (seedval, &__libc_drand48_data);
+}
diff -b -Naur uClibc.orig/libc/stdlib/srand48_r.c uClibc/libc/stdlib/srand48_r.c
--- uClibc.orig/libc/stdlib/srand48_r.c Wed Dec 31 16:00:00 1969
+++ uClibc/libc/stdlib/srand48_r.c Mon Feb 25 15:39:20 2002
@@ -0,0 +1,42 @@
+/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper at gnu.ai.mit.edu>, August 1995.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdlib.h>
+#include <limits.h>
+
+int
+__srand48_r (seedval, buffer)
+ long int seedval;
+ struct drand48_data *buffer;
+{
+ /* The standards say we only have 32 bits. */
+ if (sizeof (long int) > 4)
+ seedval &= 0xffffffffl;
+
+ buffer->__x[2] = seedval >> 16;
+ buffer->__x[1] = seedval & 0xffffl;
+ buffer->__x[0] = 0x330e;
+
+ buffer->__a = 0x5deece66dull;
+ buffer->__c = 0xb;
+ buffer->__init = 1;
+
+ return 0;
+}
+weak_alias (__srand48_r, srand48_r)
More information about the uClibc
mailing list