diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7841,19 +7841,24 @@ posix_unsetenv(PyObject *self, PyObject *args) { PyObject *name; +#ifndef HAVE_BROKEN_UNSETENV int err; +#endif if (!PyArg_ParseTuple(args, "O&:unsetenv", PyUnicode_FSConverter, &name)) return NULL; - +#ifdef HAVE_BROKEN_UNSETENV + unsetenv(PyBytes_AS_STRING(name)); +#else err = unsetenv(PyBytes_AS_STRING(name)); if (err) { Py_DECREF(name); return posix_error(); } +#endif /* Remove the key from posix_putenv_garbage; * this will cause it to be collected. This has to diff --git a/configure.in b/configure.in --- a/configure.in +++ b/configure.in @@ -2688,6 +2688,15 @@ [AC_MSG_RESULT(no) ]) +AC_MSG_CHECKING(for broken unsetenv) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +]], [[int res = unsetenv("DUMMY")]])], + [AC_MSG_RESULT(no)], + [AC_DEFINE(HAVE_BROKEN_UNSETENV, 1, Define if `unsetenv` does not return an int.) + AC_MSG_RESULT(yes) +]) + dnl check for true AC_CHECK_PROGS(TRUE, true, /bin/true) diff --git a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -95,6 +95,9 @@ /* define to 1 if your sem_getvalue is broken. */ #undef HAVE_BROKEN_SEM_GETVALUE +/* Define if `unsetenv` does not return an int. */ +#undef HAVE_BROKEN_UNSETENV + /* Define this if you have the type _Bool. */ #undef HAVE_C99_BOOL