#4097 closed Bug report (fixed)
Use of setenv() is not portable
Reported by: | Richard Lloyd | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | FileZilla Client |
Keywords: | Cc: | ||
Component version: | Operating system type: | ||
Operating system version: | HP-UX 11.11 |
Description
In the FileZilla Client 3.1.6 code, src/interface/locale_initializer.cpp makes a call to setenv(), which unfortunately not every platform has (my example is HP-UX 11.11). To fix this in a somewhat kludgy way, I took the gitsetenv() routine from git's compat/setenv.c and put it in locale_initializer.cpp (I had to cast the malloc() call in the gitsetenv() function to (char *) as well). Whether there's a more elegant solution, I'll leave it up to you (e.g. you could test for setenv() in configure and #ifdef HAVE_SETENV or something, but you'll still need some code for your equivalent setenv() call of course).
Change History (5)
comment:1 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 by , 16 years ago
Thanks for the code fix, but there appears be a minor typo in the putenv() section of code. In 3.2.0rc1, this now reads (line 97 onwards):
std::string str("LC_ALL=");
str += locale;
putenv(str.c_ctr());
I suspect that putenv() call should actually read:
putenv(str.c_str());
comment:4 by , 16 years ago
The HP-UX 11.11 C++ compiler baulked at the original putenv() parameter (str.c_ctr()) and looking at the code in the setenv() section, it looked like it should be str.c_str() (i.e. "s" instead of the "c" in "ctr"), which did indeed compile OK.
comment:5 by , 16 years ago
Of course, silly typo. Correct algorithm though.
To quote Knuth: "Beware of bugs in the above code; I have only proved it correct, not tried it."
Thanks, fixed. Now checking for setenv in configure, falling back to putenv if setenv is not available.