curl-users
setlocale() in curl
Date: Mon, 18 Oct 2004 11:59:21 +0200
Good morning (at least here),
I stumbled across a smaller problem with cURL command line, when
using in localized environment and using non-ASCII domain names
and did not find anything about this in the mail archives:
cURL does not pick up the current environments locale.
This is probably explained best by example:
% curl -v http://%c3%a4%c3%b6%c3%bc.com/
(for all those, whose mail clients cannot handle this: These
are german umlauts, the domain name should translate via
punycode into http://xn--4ca0bs.com/.)
* Couldn't find host www.öäü.de in the .netrc file, using defaults
* Input domain encoded as `US-ASCII'
* Failed to convert www.öäü.de to ACE; System iconv failed
* getaddrinfo(3) failed for www.öäü.de:80
The second line is of course already wrong. One cannot enter öäü
in US-ASCII and my system's locale is therefore set to UTF-8:
% set | grep -a LC_
LC_ALL=de_DE.UTF-8
GNU libidn seems to pick up the source encoding for the
domain name from nl_langinfo(), which in turn calls
setlocale() on FreeBSD.
According to the Single Unix Specification, Version 3, a properly
internationalized application should call “setlocale(LC_ALL, "");”
at initialization time to pick up the current locale settings from
the environment. I think, this makes sense for curl, too, so the patch
below remedies this for the current CVS version.
Comments, suggestions, critics are welcome.
Greets,
Peter
==
Index: src/main.c
===================================================================
RCS file: /cvsroot/curl/curl/src/main.c,v
retrieving revision 1.280
diff -u -r1.280 main.c
--- src/main.c 6 Oct 2004 07:50:18 -0000 1.280
+++ src/main.c 18 Oct 2004 09:41:35 -0000
@@ -32,6 +32,7 @@
#include <sys/stat.h>
#include <ctype.h>
#include <errno.h>
+#include <locale.h>
#include <curl/curl.h>
@@ -2791,6 +2792,9 @@
errorbuffer[0]=0; /* prevent junk from being output */
/* inits */
+ /* setup proper locale from environment */
+ setlocale(LC_ALL, "");
+
if (main_init() != CURLE_OK) {
helpf("error initializing curl library\n");
return CURLE_FAILED_INIT;
==
-- It is unwise to be too sure of one's own wisdom. It is healthy to be reminded that the strongest might weaken and the wisest might err. -- Mahatma GhandiReceived on 2004-10-18