From 387731a2db95b1d66b7cbdec7106156dd75988e7 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 4 Dec 2024 20:25:32 -0500 Subject: [PATCH] fix portability problem with uselocale(), et. al. misc/create_inode_libarchive.c uses uselocale(), newlocale(), et. al. These functions are defined in POSIX.1-2017, which isn't available everywhere --- including MacOS and Windows. We don't actually need to use these functions, since mke2fs already calls setlocale() to initialize to use the default locale. So there was no reason to set and restore the locale to use exactly the default locale. Signed-off-by: Theodore Ts'o --- debugfs/debugfs.c | 3 +++ misc/create_inode_libarchive.c | 7 ------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index 909c1df39..8acb56a4d 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef HAVE_GETOPT_H #include #else @@ -2571,6 +2572,8 @@ int main(int argc, char **argv) char *jbd_debug; #endif + setlocale(LC_CTYPE, ""); + if (debug_prog_name == 0) #ifdef READ_ONLY debug_prog_name = "rdebugfs"; diff --git a/misc/create_inode_libarchive.c b/misc/create_inode_libarchive.c index d14efe81d..d094d1349 100644 --- a/misc/create_inode_libarchive.c +++ b/misc/create_inode_libarchive.c @@ -58,7 +58,6 @@ typedef ssize_t la_ssize_t; #endif /* HAVE_ARCHIVE_H */ #include -#include static const char *(*dl_archive_entry_hardlink)(struct archive_entry *); static const char *(*dl_archive_entry_pathname)(struct archive_entry *); @@ -583,8 +582,6 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino, struct archive *a; struct archive_entry *entry; errcode_t retval = 0; - locale_t archive_locale; - locale_t old_locale; ext2_ino_t dirinode, tmpino; const struct stat *st; @@ -594,8 +591,6 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino, return 1; } - archive_locale = newlocale(LC_CTYPE_MASK, "", (locale_t)0); - old_locale = uselocale(archive_locale); a = dl_archive_read_new(); if (a == NULL) { retval = 1; @@ -720,8 +715,6 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino, out: dl_archive_read_close(a); dl_archive_read_free(a); - uselocale(old_locale); - freelocale(archive_locale); return retval; }