Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#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 Tim Kosse, 16 years ago

Resolution: fixed
Status: newclosed

Thanks, fixed. Now checking for setenv in configure, falling back to putenv if setenv is not available.

comment:2 by Richard Lloyd, 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:3 by Tim Kosse, 16 years ago

What's wrong with it?

in reply to:  3 comment:4 by Richard Lloyd, 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 Tim Kosse, 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."

Note: See TracTickets for help on using tickets.