fix setenv

Eric Blake ebb9@byu.net
Mon Nov 16 13:58:00 GMT 2009


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

I noticed that cygwin setenv differs from Linux and from POSIX
requirements.  STC:

#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
int
main (void)
{
  /* Test overwriting.  */
  assert (setenv ("a", "=", -1) == 0);
  assert (setenv ("a", "2", 0) == 0);
  assert (strcmp (getenv ("a"), "=") == 0); // fails here

  /* Required to fail with EINVAL.  */
  errno = 0;
  assert (setenv ("", "", 1) == -1); // and here
  assert (errno == EINVAL);
  errno = 0;
  assert (setenv ("a=b", "", 0) == -1); // and here
  assert (errno == EINVAL);
  errno = 0;
  assert (setenv (NULL, "", 0) == -1);
  assert (errno == EINVAL); // and here
  return 0;
}


2009-11-16  Eric Blake  <ebb9@byu.net>

	* environ.cc (setenv): Detect invalid argument.
	(unsetenv): Distinguish EFAULT from EINVAL.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksBWj4ACgkQ84KuGfSFAYCwngCdG+FVRKgMjTzXnn0AKhRzPCh3
OxsAn35wV0l/J8Q4AAKrAyqPvMmfyGQB
=LaHp
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cygwin.patch32
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20091116/16c62b3a/attachment.ksh>


More information about the Cygwin-patches mailing list