File reproducible.patch of Package mkfontscale

commit 7b4203577af4b835ef069e0cd2bd9510b599789c
Author: Bernhard M. Wiedemann <bwiedemann@suse.de>
Date:   Mon Sep 10 10:17:52 2018 +0200

    Sort input file list
    
    so that openSUSE's installation-images builds in a reproducible way
    in spite of indeterministic filesystem readdir order
    
    See https://reproducible-builds.org/ for why this is good.
    
    Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>

diff --git a/mkfontscale.c b/mkfontscale.c
index e9b9488..eca8a1b 100644
--- a/mkfontscale.c
+++ b/mkfontscale.c
@@ -778,14 +778,13 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
 {
     char *dirname, *fontscale_name, *filename, *encdir;
     FILE *fontscale, *encfile;
-    DIR *dirp;
-    struct dirent *entry;
+    struct dirent** namelist;
     FT_Error ftrc;
     FT_Face face;
     ListPtr encoding, xlfd, lp;
     HashTablePtr entries;
     HashBucketPtr *array;
-    int i, n, found, rc;
+    int i, n, dirn, diri, found, rc;
     int isBitmap=0,xl=0;
 
     if (exclusionSuffix)
@@ -825,10 +824,10 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
         }
     }
 
-    dirp = opendir(dirname);
-    if(dirp == NULL) {
+    dirn = scandir(dirname, &namelist, NULL, alphasort);
+    if(dirn < 0) {
         fprintf(stderr, "%s: ", dirname);
-        perror("opendir");
+        perror("scandir");
         return 0;
     }
 
@@ -843,7 +842,8 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
         return 0;
     }
 
-    while((entry = readdir(dirp)) != NULL) {
+    for(diri = dirn - 1; diri >= 0; diri--) {
+        struct dirent *entry = namelist[diri];
         int have_face = 0;
         char *xlfd_name = NULL;
 	struct stat f_stat;
@@ -991,7 +991,9 @@ doDirectory(const char *dirname_given, int numEncodings, ListPtr encodingsToDo)
 #undef PRIO
     }
 
-    closedir(dirp);
+    while(dirn--)
+        free(namelist[dirn]);
+    free(namelist);
     n = hashElements(entries);
     fprintf(fontscale, "%d\n", n);
     array = hashArray(entries, 1);