diff mbox

Fix build breakage on MinGW due to missing setenv

Message ID 20170703100258.15837-1-Anton.Kolesov@synopsys.com
State New
Headers show

Commit Message

Anton Kolesov July 3, 2017, 10:02 a.m. UTC
Patch [1] broke a build on MinGW hosts, because MinGW doesn't provide POSIX
functions setenv () and unsetenv (), instead there is a putenv () wrapper
around WinAPI function, although with a different signature.

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9a6c7d9c0

gdb/ChangeLog
yyyy-mm-dd  Anton Kolesov  <Anton.Kolesov@synopsys.com>

	* unittests/environ-selftests.c (run_tests): Use putenv on MinGW.
---
 gdb/unittests/environ-selftests.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Yao Qi July 3, 2017, 11:21 a.m. UTC | #1
On Mon, Jul 3, 2017 at 11:02 AM, Anton Kolesov
<Anton.Kolesov@synopsys.com> wrote:
> Patch [1] broke a build on MinGW hosts, because MinGW doesn't provide POSIX
> functions setenv () and unsetenv (), instead there is a putenv () wrapper
> around WinAPI function, although with a different signature.
>
> [1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9a6c7d9c0

The better fix, IMO, is to use setenv and unsetenv
module in gnulib.  However, I didn't check gnulib
manual about portability problems not fixed by gnulib.
Sergio Durigan Junior July 3, 2017, 3:26 p.m. UTC | #2
On Monday, July 03 2017, Yao Qi wrote:

> On Mon, Jul 3, 2017 at 11:02 AM, Anton Kolesov
> <Anton.Kolesov@synopsys.com> wrote:
>> Patch [1] broke a build on MinGW hosts, because MinGW doesn't provide POSIX
>> functions setenv () and unsetenv (), instead there is a putenv () wrapper
>> around WinAPI function, although with a different signature.
>>
>> [1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9a6c7d9c0
>
> The better fix, IMO, is to use setenv and unsetenv
> module in gnulib.  However, I didn't check gnulib
> manual about portability problems not fixed by gnulib.

According to:

  <https://www.gnu.org/software/gnulib/manual/html_node/setenv.html#setenv>

There is only one portability problem not fixed by gnulib, and I don't
think it affects us:

  Older versions of POSIX required that setenv(NULL,"",0) gracefully
  fail with EINVAL, but not all implementations guarantee this, and the
  requirement was removed.

So it should be possible to import setenv from gnulib without problems,
I think.

Cheers,
diff mbox

Patch

diff --git a/gdb/unittests/environ-selftests.c b/gdb/unittests/environ-selftests.c
index 28b16f8..8872bfa 100644
--- a/gdb/unittests/environ-selftests.c
+++ b/gdb/unittests/environ-selftests.c
@@ -30,7 +30,11 @@  run_tests ()
 {
   /* Set a test environment variable.  This will be unset at the end
      of this function.  */
+#ifndef USE_WIN32API
   if (setenv ("GDB_SELFTEST_ENVIRON", "1", 1) != 0)
+#else
+  if (putenv ("GDB_SELFTEST_ENVIRON=1") != 0)
+#endif
     error (_("Could not set environment variable for testing."));
 
   gdb_environ env;
@@ -90,7 +94,13 @@  run_tests ()
   SELF_CHECK (num_found == 1);
 
   /* Get rid of our test variable.  */
+#ifndef USE_WIN32API
   unsetenv ("GDB_SELFTEST_ENVIRON");
+#else
+  /* putenv ("var=") has the same meaning as unsetenv ("var"), unlike the
+     setenv ("var="), which would assign an empty value.  */
+  putenv ("GDB_SELFTEST_ENVIRON=");
+#endif
 
   /* Test the case when we set a variable A, then set a variable B,
      then unset A, and make sure that we cannot find A in the environ