From 93d2f49c164efe716fa0dbd1dab2faae947af802 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sun, 16 Jul 2017 14:01:18 +0200 Subject: [PATCH] Bug 784961 - Undeclared identifier 'TIME_UTC' - GIMP fails to build... ...on macOS (with macports) Changed gimp_metadata_get_guid() to use a GRand that automatically seeds itself from /dev/urandom (if available) or the current time. --- libgimpbase/gimpmetadata.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c index 5024aa5033..56fc8c7e8e 100644 --- a/libgimpbase/gimpmetadata.c +++ b/libgimpbase/gimpmetadata.c @@ -206,29 +206,20 @@ gimp_metadata_init (GimpMetadata *metadata) gchar * gimp_metadata_get_guid (void) { - const int DALLOC = 36; - struct timespec ts; - long time; - gint shake; - gint bake; - gchar *GUID; - gchar *szHex; + GRand *rand; + gint bake; + gchar *GUID; + const gchar *szHex = "0123456789abcdef-"; - for (shake = 0; shake < 10; shake++) - { - timespec_get (&ts, TIME_UTC); - time = ts.tv_nsec / 1000; - srand (time); - } + rand = g_rand_new (); + +#define DALLOC 36 GUID = g_malloc0 (DALLOC); - bake = 0; - szHex = "0123456789abcdef-"; - for (bake = 0; bake < DALLOC; bake++) { - gint r = rand () % 16; + gint r = g_rand_int (rand) % 16; gchar c = ' '; switch (bake) @@ -256,6 +247,8 @@ gimp_metadata_get_guid (void) GUID[bake] = (bake < DALLOC) ? c : 0x00; } + g_rand_free (rand); + return GUID; }