printing: Avoid getrandom
authorMatthias Clasen <mclasen@redhat.com>
Fri, 17 Feb 2023 20:40:45 +0000 (15:40 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 17 Feb 2023 22:20:44 +0000 (17:20 -0500)
GLib has perfectly serviceable random number
apis, and this breaks the macOs build.

modules/printbackends/gtkprintbackendutils.c

index b1c8023468075e60229ef06da4b08b9c0c2186fc..3755044d0b18a742b9112521eebf04047b143e7a 100644 (file)
@@ -19,7 +19,6 @@
 
 
 #include <glib.h>
-#include <sys/random.h>
 
 #include "gtkprintbackendutils.h"
 
@@ -114,15 +113,13 @@ random_string (int n)
                           "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                           "0123456789";
 
-  char *str = g_new0 (char, n+1);
-  getrandom (str, n, 0);
-  for (int i=0; i<n; i++)
+  char *str = g_new0 (char, n + 1);
+  for (int i = 0; i < n; i++)
     {
-      int rand = str[i] + 128;
-      int idx = rand % ((int) sizeof charset);
+      int idx = g_random_int_range (0, strlen (charset));
       str[i] = charset[idx];
     }
   str[n] = '\0';
 
   return str;
-}
\ No newline at end of file
+}