[kdbus] KDBUS_ITEM_PAYLOAD_OFF items are (once again) relative to msg header
[platform/upstream/glib.git] / glib / grand.c
index 0c10124..ac1053d 100644 (file)
@@ -56,6 +56,7 @@
 
 #ifdef G_OS_WIN32
 #include <stdlib.h>
+#include <process.h> /* For getpid() */
 #endif
 
 /**
  * generation, nonces, salts or one-time pads.
  *
  * This PRNG is suitable for non-cryptographic use such as in games
- * (shuffling a card deck, generating levels), generating data for a
- * test suite, etc. If you need random data for cryptographic
- * purposes, it is recommended to use platform-specific APIs such as
- * <literal>/dev/random</literal> on Unix, or CryptGenRandom() on
- * Windows.
+ * (shuffling a card deck, generating levels), generating data for
+ * a test suite, etc. If you need random data for cryptographic
+ * purposes, it is recommended to use platform-specific APIs such
+ * as `/dev/random` on UNIX, or CryptGenRandom() on Windows.
  *
  * GRand uses the Mersenne Twister PRNG, which was originally
  * developed by Makoto Matsumoto and Takuji Nishimura. Further
- * information can be found at <ulink
- * url="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html">
- * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html</ulink>.
+ * information can be found at
+ * [this page](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html).
  *
  * If you just need a random number, you simply call the g_random_*
  * functions, which will create a globally used #GRand and use the
@@ -94,7 +93,7 @@
  *
  * The g_rand*_range functions will return high quality equally
  * distributed random numbers, whereas for example the
- * <literal>(g_random_int()&percnt;max)</literal> approach often
+ * `(g_random_int()%max)` approach often
  * doesn't yield equally distributed numbers.
  *
  * GLib changed the seeding algorithm for the pseudo-random number
@@ -173,7 +172,7 @@ struct _GRand
  * 
  * Creates a new random number generator initialized with @seed.
  * 
- * Return value: the new #GRand
+ * Returns: the new #GRand
  **/
 GRand*
 g_rand_new_with_seed (guint32 seed)
@@ -191,7 +190,7 @@ g_rand_new_with_seed (guint32 seed)
  * 
  * Creates a new random number generator initialized with @seed.
  * 
- * Return value: the new #GRand
+ * Returns: the new #GRand
  *
  * Since: 2.4
  */
@@ -208,12 +207,12 @@ g_rand_new_with_seed_array (const guint32 *seed,
  * g_rand_new:
  * 
  * Creates a new random number generator initialized with a seed taken
- * either from <filename>/dev/urandom</filename> (if existing) or from 
- * the current time (as a fallback).
+ * either from `/dev/urandom` (if existing) or from the current time
+ * (as a fallback).
  *
  * On Windows, the seed is taken from rand_s().
  * 
- * Return value: the new #GRand
+ * Returns: the new #GRand
  */
 GRand* 
 g_rand_new (void)
@@ -263,10 +262,23 @@ g_rand_new (void)
       seed[3] = getppid ();
     }
 #else /* G_OS_WIN32 */
+  /* rand_s() is only available since Visual Studio 2005 */
+#if defined(_MSC_VER) && _MSC_VER >= 1400
   gint i;
 
   for (i = 0; i < G_N_ELEMENTS (seed); i++)
     rand_s (&seed[i]);
+#else
+#warning Using insecure seed for random number generation because of missing rand_s() in Windows XP
+  GTimeVal now;
+
+  g_get_current_time (&now);
+  seed[0] = now.tv_sec;
+  seed[1] = now.tv_usec;
+  seed[2] = getpid ();
+  seed[3] = 0;
+#endif
+
 #endif
 
   return g_rand_new_with_seed_array (seed, 4);
@@ -294,7 +306,7 @@ g_rand_free (GRand *rand)
  * This way you can take a snapshot of the random number generator for
  * replaying later.
  *
- * Return value: the new #GRand
+ * Returns: the new #GRand
  *
  * Since: 2.4
  */
@@ -431,7 +443,7 @@ g_rand_set_seed_array (GRand         *rand,
  * Returns the next random #guint32 from @rand_ equally distributed over
  * the range [0..2^32-1].
  *
- * Return value: a random number
+ * Returns: a random number
  */
 guint32
 g_rand_int (GRand *rand)
@@ -480,7 +492,7 @@ g_rand_int (GRand *rand)
  * Returns the next random #gint32 from @rand_ equally distributed over
  * the range [@begin..@end-1].
  *
- * Return value: a random number
+ * Returns: a random number
  */
 gint32 
 g_rand_int_range (GRand  *rand,
@@ -563,7 +575,7 @@ g_rand_int_range (GRand  *rand,
  * Returns the next random #gdouble from @rand_ equally distributed over
  * the range [0..1).
  *
- * Return value: a random number
+ * Returns: a random number
  */
 gdouble 
 g_rand_double (GRand *rand)
@@ -590,7 +602,7 @@ g_rand_double (GRand *rand)
  * Returns the next random #gdouble from @rand_ equally distributed over
  * the range [@begin..@end).
  *
- * Return value: a random number
+ * Returns: a random number
  */
 gdouble 
 g_rand_double_range (GRand   *rand,
@@ -630,7 +642,7 @@ get_global_random (void)
  * Return a random #guint32 equally distributed over the range
  * [0..2^32-1].
  *
- * Return value: a random number
+ * Returns: a random number
  */
 guint32
 g_random_int (void)
@@ -650,7 +662,7 @@ g_random_int (void)
  * Returns a random #gint32 equally distributed over the range
  * [@begin..@end-1].
  *
- * Return value: a random number
+ * Returns: a random number
  */
 gint32 
 g_random_int_range (gint32 begin,
@@ -668,7 +680,7 @@ g_random_int_range (gint32 begin,
  *
  * Returns a random #gdouble equally distributed over the range [0..1).
  *
- * Return value: a random number
+ * Returns: a random number
  */
 gdouble 
 g_random_double (void)
@@ -688,7 +700,7 @@ g_random_double (void)
  * Returns a random #gdouble equally distributed over the range
  * [@begin..@end).
  *
- * Return value: a random number
+ * Returns: a random number
  */
 gdouble 
 g_random_double_range (gdouble begin,