Skip to content

Commit

Permalink
fix portability problem with uselocale(), et. al.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tytso committed Dec 5, 2024
1 parent 096463d commit 387731a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
3 changes: 3 additions & 0 deletions debugfs/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string.h>
#include <time.h>
#include <libgen.h>
#include <locale.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
Expand Down Expand Up @@ -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";
Expand Down
7 changes: 0 additions & 7 deletions misc/create_inode_libarchive.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ typedef ssize_t la_ssize_t;
#endif /* HAVE_ARCHIVE_H */

#include <libgen.h>
#include <locale.h>

static const char *(*dl_archive_entry_hardlink)(struct archive_entry *);
static const char *(*dl_archive_entry_pathname)(struct archive_entry *);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 387731a

Please sign in to comment.