From 7aa74e3029c4b3b5a1c42dea5d66891b88c576a4 Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Thu, 1 Jun 2017 15:28:27 +0200 Subject: [PATCH] Sort file lists to enable more reproducible builds without patching individual build definitions like https://github.com/boostorg/container/pull/50 --- src/engine/fileunix.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/engine/fileunix.c b/src/engine/fileunix.c index 766b0afdd..1e072f235 100644 --- a/src/engine/fileunix.c +++ b/src/engine/fileunix.c @@ -111,7 +111,8 @@ int file_collect_dir_content_( file_info_t * const d ) { LIST * files = L0; PATHNAME f; - DIR * dd; + int n; + STRUCT_DIRENT ** namelist; STRUCT_DIRENT * dirent; string path[ 1 ]; char const * dirstr; @@ -128,13 +129,14 @@ int file_collect_dir_content_( file_info_t * const d ) if ( !*dirstr ) dirstr = "."; - if ( !( dd = opendir( dirstr ) ) ) + if ( -1 == ( n = scandir( dirstr, &namelist, NULL, alphasort ) ) ) return -1; string_new( path ); - while ( ( dirent = readdir( dd ) ) ) + while ( n-- ) { OBJECT * name; + dirent = namelist[ n ]; f.f_base.ptr = dirent->d_name #ifdef old_sinix - 2 /* Broken structure definition on sinix. */ @@ -150,10 +152,11 @@ int file_collect_dir_content_( file_info_t * const d ) files = list_push_back( files, name ); else object_free( name ); + free( dirent ); } string_free( path ); - closedir( dd ); + free( namelist ); d->files = files; return 0;