lynx-dev
[Top][All Lists]
Advanced

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

Re: lynx-dev Re: putenv


From: Klaus Weide
Subject: Re: lynx-dev Re: putenv
Date: Wed, 20 Jan 1999 22:00:08 -0600 (CST)

Thanks Tom, Bela, Kim for the replies.

On Wed, 20 Jan 1999, Kim DeVaughn wrote:
> On Wed, Jan 20, 1999, Bela Lubkin (address@hidden) said:
> |
> | I would think this was POSIX/XPG mandated behavior.  Try this with Linux
> | & glibc:
> |
> |   main()
> |   {
> |     char *foo = "foo=bar";
> |
> |     putenv(foo);
> |     printf("%s\n", getenv("foo"));
> |     foo[6] = 'z';
> |     printf("%s\n", getenv("foo"));
> |   }
> |
> | I get:
> |
> |   bar
> |   baz
> 
> FWIW, on FreeBSD 2.2.8-STABLE (whose man page is below), I get:
> 
>   bar
>   Bus error (core dumped)
> 
> ie, a sig-10.

With linux/glibc, I also get a core dump with Bela's unmodified
example.  The statement
         foo[6] = 'z';
is invalid because it is modifying a constant string.
After changing the test to the following:

----- start -----
#include <stdlib.h>
#include <stdio.h>
#define TESTSIZE 100

int main()
{
    char *foo = malloc(TESTSIZE);
    sprintf(foo, "%s", "foo=bar");

    putenv(foo);
    printf("%s\n", getenv("foo"));
    foo[6] = 'z';
    printf("%s\n", getenv("foo"));
}
----- end -----

I get

  bar
  bar

on linux as I expected all along, but on 
  $ uname -a
  SunOS xochi 4.1.3_U1 6 sun4m
I get

  bar
  baz

as Bela.

So it seems C libraries are indeed different, and I have learned something
new.

> Note that the man page has no special warnings WRT the manner in which
> the string was allocated, etc.

The linxu manpage I have for putenv(3) also doesn't document any such
restrictions.  It would be nice if it had a warning that other systems might
have them, for portability.

   Klaus

reply via email to

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