Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
enable locales in all programs
Browse files Browse the repository at this point in the history
This is a pre-condition for using libarchive directly: libarchive
needs to know what the encoding of filenames is, and it uses the
current locale for that. Without setlocale(), the locale is "C", which
only supports ASCII filenames, leading to warnings about "Can't
encode..." from libarchive when it is forced to fall back to copying
strings verbatim when writing archives that require UTF-8 encoding.

As a side effect, error messages from libc will get translated
according to the user's environment.

Signed-off-by: Patrick Ohly <[email protected]>
  • Loading branch information
pohly authored and tmarcu committed Dec 8, 2016
1 parent 7542d21 commit b618516
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/create_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <errno.h>
#include <getopt.h>
#include <glib.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -259,6 +260,11 @@ int main(int argc, char **argv)
/* keep valgrind working well */
setenv("G_SLICE", "always-malloc", 0);

if (!setlocale(LC_ALL, "")) {
fprintf(stderr, "%s: setlocale() failed\n", argv[0]);
return EXIT_FAILURE;
}

if (!parse_options(argc, argv)) {
free_globals();
return EXIT_FAILURE;
Expand Down
6 changes: 6 additions & 0 deletions src/make_fullfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define _GNU_SOURCE
#include <assert.h>
#include <getopt.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -93,6 +94,11 @@ int main(int argc, char **argv)
/* keep valgrind working well */
setenv("G_SLICE", "always-malloc", 0);

if (!setlocale(LC_ALL, "")) {
fprintf(stderr, "%s: setlocale() failed\n", argv[0]);
return EXIT_FAILURE;
}

if (!parse_options(argc, argv)) {
free_state_globals();
return EXIT_FAILURE;
Expand Down
6 changes: 6 additions & 0 deletions src/make_packs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <getopt.h>
#include <getopt.h>
#include <glib.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -101,6 +102,11 @@ int main(int argc, char **argv)
int exit_status = EXIT_FAILURE;
char *file_path = NULL;

if (!setlocale(LC_ALL, "")) {
fprintf(stderr, "%s: setlocale() failed\n", argv[0]);
return EXIT_FAILURE;
}

if (!parse_options(argc, argv)) {
free_state_globals();
return EXIT_FAILURE;
Expand Down

0 comments on commit b618516

Please sign in to comment.