Web lists-archives.com

Re: [Mingw-users] setenv()




-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 17/11/16 09:00, Anton Shepelev wrote:
> As I can tell, the variable buf is a local one, whereas according
> to the putenv man entry, "The string pointed to by string becomes
> part of the environment, so altering the string changes the
> environment."

- From you reference to "man entry", may I deduce that this relates to
some non-Windows implementation of putenv()?  Linux' glibc perhaps?

> Does the Microsoft implementation copy the string passed?

Yes.  Given MS-DOS' organization of the environment as a contiguous
sequence of NUL separated name=value C strings, terminated by a single
zero-length C string, that would have been a practical necessity.  Of
course, there's no guarantee that Windows' has adopted that MS-DOS
environment organizational legacy, but the printf() statements, which
I added to the sample implementation, confirm that the pointer returned
by getenv() bears no relationship to the original address of the string
passed to putenv(); altering that latter string, (or even just allowing
it to be discarded from the stack, as in that sample implementation),
after passing it to putenv() will not change the environment, (nor will
it lead to environment corruption).  OTOH, the temptation to strdup()
the source string, before passing that to putenv(), would create a
memory leak.

- -- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/Linux)

iQIcBAEBAgAGBQJYLZxKAAoJEMCtNsY0flo/sOQP/iX0mh+43RjgQlWpTYg+R4Gm
F7lpL9pBeNJuGgLeULGxd60k7u1yIm/li8OA1jTAeOvfzwe8nKV9YDf19lb6nI1i
c8CTzTy4hGy9Ne7+8NgqszcgdHEyobUqrzDh5SeEtUWp+bCWN5RoKhu3Vrbo83C8
uYcODzbuHM/y9Qljsk095o1ZrM8sgw2vgZh8bMdnqD6ym9wnGPO0aUyRB135M0S4
m5RNSZdJbCSQq6RuYwmUaalSFyf5PCaZxB9YNJ3pEB7sOSbBXmv8GfK8Nr6zvpsO
nA5yJthJM8nHjtPSFdb63crAzmXeMHftdL5xC0cpWRb5O3zeZP1fyPKw4/G4qqMG
UlienocW1+IIOHmPdToBnr62gcnODyWM0AaUrONy4ukXLHCsLtkbCip2HTrF9arG
QWFemEgvsD0dDu99MISKAN9qZP1frHNnKmR7TBfoMeEt85gr4i98BjHlyKwOz+UA
ZJRaSYJdcY8SsCBaWCoSDP71UpqBUQS/3GfJ97dYPlbOgKe1/5Jot6Rbwe6/rGzn
FMnmBMWubB3HtHxwa1tUS/BOs8DH7TrHG8kxSM0h9B2SFfsickhFXJqGUBJGxPNq
n3frZyLSOAxotESfWI6fruYu8eMGDFctY2lFPqFkHXdEXMfm1ohQjYaldWSypeqc
KQQpVQow2jgNs91qOl2h
=SIDk
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe