Skip to content

Commit bd53eaa

Browse files
wojujow-
authored andcommitted
make_ext4fs: explicitly call setlocale() before creating image
The alphasort(3) function, which is used as comparison function for scandir(3) is locale dependent (at least in glibc, in which it defers to strcoll(3)). This patch explicitly calls setlocale(3), setting the locale to "C". Currently, there are no other calls to setlocale(), so this does not change the behaviour. However, we'd like to be sure that in the future no-one will break that. Signed-off-by: Wojtek Porczyk <[email protected]>
1 parent 98e3d5c commit bd53eaa

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

make_ext4fs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <unistd.h>
3434
#include <sys/stat.h>
3535
#include <sys/types.h>
36+
#include <locale.h>
3637

3738
/* TODO: Not implemented:
3839
Allocating blocks in the same block group as the file inode
@@ -66,6 +67,9 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path
6667
u32 dirs = 0;
6768
bool needs_lost_and_found = false;
6869

70+
/* alphasort is locale-dependent; let's fix the locale to some sane value */
71+
setlocale(LC_COLLATE, "C");
72+
6973
if (full_path) {
7074
entries = scandir(full_path, &namelist, filter_dot, (void*)alphasort);
7175
if (entries < 0) {

0 commit comments

Comments
 (0)