[distcc] distc-1.1 on Solaris 8

Martin Pool mbp at samba.org
Wed Jan 29 23:45:31 GMT 2003

On 29 Jan 2003, Dimitri PAPADOPOULOS-ORFANOS <papadopo at shfj.cea.fr> wrote:

> It should be:
>   static const char *dcc_safeguard_set = "_DISTCC_SAFEGUARD=1";
> instead of:
>   static char *dcc_safeguard_set = "_DISTCC_SAFEGUARD=1";
> Sun compilers complain if you put a const string into
> a string. Then cast "const char *" to "char *" when
> calling putenv(). 

Well, either way is ugly, but I suppose making the variable const is
slightly better.  I wish C had const_cast.

> Now it may be that the argument of putenv() _must_ be
> allocated with malloc(), so that the system is able to
> modify the value of the environment variable in place,
> which is obviously not possible with a constant string.

It may be so, but I didn't see any documentation that says that putenv
is allowed to assume the string was malloc'd and therefore realloc
it.  On the contrary, XSH says 

   The space used by string is no longer used once a new
   string-defining name is passed to putenv().

> This will of course result in a small memory leak, but
> this memory leak seems to be required by the putenv()
> API. See the references I had sent you.

I'm curious what happens when a new program is exec()'d, because
obviously the heap won't be around.  I suppose that all the current
variables get rewritten into a new specially allocated block of

> I can see no other reason for requiring a "char *" instead of a
> "const char *" argument.

My guess would be that it is just a very old interface.


More information about the distcc mailing list