migration from private to rsa
[external/bash.git] / debian / patches / random.dpatch
1 #! /bin/sh -e
2
3 dir=.
4 if [ $# -eq 3 -a "$2" = '-d' ]; then
5     pdir="-d $3"
6     dir=$3
7 elif [ $# -ne 1 ]; then
8     echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
9     exit 1
10 fi
11 case "$1" in
12     -patch)
13         patch $pdir -f --no-backup-if-mismatch -p1 < $0
14         echo '2.05' > $dir/_distribution
15         echo '0' > $dir/_patchlevel
16         cd $dir && autoconf
17         rm -f $dir/_distribution $dir/_patchlevel
18         ;;
19     -unpatch)
20         patch $pdir -f --no-backup-if-mismatch -R -p1 < $0
21         rm -f $dir/configure $dir/_distribution $dir/_patchlevel
22         ;;
23     *)
24         echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
25         exit 1
26 esac
27 exit 0
28
29 # DP: use the system random functions
30
31 diff -urb bash.orig/config.h.in bash/config.h.in
32 --- bash.orig/config.h.in       2003-09-22 14:42:35.000000000 +0200
33 +++ bash/config.h.in    2003-09-28 00:27:15.000000000 +0200
34 @@ -606,6 +606,9 @@
35  /* Define if you have the putenv function.  */
36  #undef HAVE_PUTENV
37  
38 +/* Define if you have the random function.  */
39 +#undef HAVE_RANDOM
40 +
41  /* Define if you have the readlink function. */
42  #undef HAVE_READLINK
43  
44 @@ -696,6 +699,9 @@
45  /* Define if you have the strsignal function or macro. */
46  #undef HAVE_STRSIGNAL
47  
48 +/* Define if you have the srandom function.  */
49 +#undef HAVE_SRANDOM
50 +
51  /* Define if you have the sysconf function. */
52  #undef HAVE_SYSCONF
53  
54 diff -urb bash.orig/variables.c bash/variables.c
55 --- bash.orig/variables.c       2003-07-31 16:28:57.000000000 +0200
56 +++ bash/variables.c    2003-09-28 00:27:15.000000000 +0200
57 @@ -1098,16 +1098,22 @@
58  static unsigned long rseed = 1;
59  static int last_random_value;
60  
61 -/* A linear congruential random number generator based on the example
62 -   one in the ANSI C standard.  This one isn't very good, but a more
63 -   complicated one is overkill. */
64 +/* Use the random number genrator provided by the standard C library,
65 +   else use a linear congruential random number generator based on the
66 +   ANSI C standard.  This one isn't very good (the values are alternately
67 +   odd and even, for example), but a more complicated one is overkill. */
68  
69  /* Returns a pseudo-random number between 0 and 32767. */
70  static int
71  brand ()
72  {
73 +#if defined(HAVE_RANDOM)
74 +  rseed = (unsigned int) (labs(random()) & 32767);
75 +  return rseed;
76 +#else
77    rseed = rseed * 1103515245 + 12345;
78    return ((unsigned int)((rseed >> 16) & 32767));      /* was % 32768 */
79 +#endif
80  }
81  
82  /* Set the random number generator seed to SEED. */
83 @@ -1115,8 +1121,12 @@
84  sbrand (seed)
85       unsigned long seed;
86  {
87 +#if defined(HAVE_SRANDOM)
88 +  srandom(seed);
89 +#else
90    rseed = seed;
91    last_random_value = 0;
92 +#endif
93  }
94  
95  static SHELL_VAR *
96 --- bash/configure.in~  2004-03-02 00:04:29.000000000 +0100
97 +++ bash/configure.in   2004-03-02 00:05:48.000000000 +0100
98 @@ -667,6 +667,9 @@
99  
100  AC_FUNC_MKTIME
101  
102 +dnl checks for random functions
103 +AC_CHECK_FUNCS(random srandom)
104 +
105  dnl
106  dnl Checks for lib/intl and related code (uses some of the output from
107  dnl AM_GNU_GETTEXT)