Ticket #4097 (closed Bug report: fixed)

Opened 6 years ago

Last modified 6 years ago

Use of setenv() is not portable

Reported by: rkl Owned by:
Priority: normal Component: FileZilla Client
Keywords: Cc:
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

  Changed 6 years ago by codesquid

  • status changed from new to closed
  • resolution set to fixed

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

  Changed 6 years ago by rkl

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());

follow-up: ↓ 4   Changed 6 years ago by codesquid

What's wrong with it?

in reply to: ↑ 3   Changed 6 years ago by rkl

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.

  Changed 6 years ago by codesquid

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.