bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

getenv and Win32


From: Guido Flohr
Subject: getenv and Win32
Date: Wed, 07 Jan 2004 17:44:18 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030312

Hi,

I have a problem with the MSVC compiled version of the gettext runtime libraries under Windows. I change the environment variables LANG, LANGUAGE etc. from within a Perl module, and Perl uses the win32 functions SetEnvironmentVariableA/SetEnvironmentVariableW for manipulating the environment. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setenvironmentvariable.asp for a description.

GNU gettext, however, uses getenv() to read the environment and never sees these changes. An explanation for this can be found under http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_getenv.2c_._wgetenv.asp

It says:

        getenv operates only on the data structures accessible to the
        run-time library and not on the environment segment created
        for the process by the operating system.

I am no Windows expert and can only guess which behavior is correct for Windows, Perl's or GNU gettext's. For OS2 there is a special version of getenv() in gettext-runtime/intl/os2compat.c which has a comment "A version of getenv() that works from DLLs", and I suspect that a special getenv() function for Windows is also needed.

I have tried a quick hack in dcigettext.c:

#include <Windows.h>
static char*
win32_getenv (const char* what)
{
        char* buffer;
        /* FIXME: Maybe use GetEnvironmentVariableW() instead.  */
        unsigned long buflen = GetEnvironmentVariableA (what, NULL, 0);

        /* FIXME: Memory leak!  */
        buffer = malloc (buflen + 1);
        GetEnvironmentVariableA (what, buffer, buflen); 

        return buffer;
}       
#define getenv win32_getenv

This fixes my problem, but is of course not a real solution.

A similar problem with libintl seems to be discussed as bug #666947 of GNUWin32, see http://sourceforge.net/tracker/index.php?func=detail&aid=666947&group_id=23617&atid=379173. The fix proposed there defines a new function gettext_putenv() which changes the "correct" environment, and should be used as a replacement for putenv() when changing environment variables used by gettext, not exactly a clean solution.

Ciao

Guido
--
Imperia AG, Development
Leyboldstr. 10 - D-50354 Hürth - http://www.imperia.net/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]