[PATCH] opkg: set locale from system environment variables

21 views
Skip to first unread message

Piotr Łobacz

unread,
Jul 19, 2023, 3:36:18 PM7/19/23
to opkg-...@googlegroups.com, Piotr Łobacz
A C program inherits its locale environment variables when it starts up.
This happens automatically. However, these variables do not automatically
control the locale used by the library functions, because ISO C says that
all programs start by default in the standard ‘C’ locale.

Fixes warnings:
Warning when reading ar archive header: Pathname can't be converted from UTF-8 to current locale. (errno=84)

[1] https://www.gnu.org/software/libc/manual/html_node/Setting-the-Locale.html

Signed-off-by: Piotr Łobacz <p.lo...@welotec.com>
---
src/opkg.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/src/opkg.c b/src/opkg.c
index 544c58a..0c729ff 100644
--- a/src/opkg.c
+++ b/src/opkg.c
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
+#include <locale.h>

#include "opkg_conf.h"
#include "opkg_cmd.h"
@@ -408,6 +409,7 @@ int main(int argc, char *argv[])
if (opkg_conf_init())
goto err0;

+ setlocale(LC_ALL, "");
opkg_config->verbosity = NOTICE;

opts = args_parse(argc, argv);
--
2.34.1

Reply all
Reply to author
Forward
0 new messages