2 dnl Copyright (C) 2001-2004, 2006-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_SETENV],
9 AC_REQUIRE([gl_FUNC_SETENV_SEPARATE])
10 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
11 if test $ac_cv_func_setenv = no; then
14 AC_CACHE_CHECK([whether setenv validates arguments],
15 [gl_cv_func_setenv_works],
16 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
23 if (setenv ("", "", 0) != -1)
25 else if (errno != EINVAL)
29 if (setenv ("a", "=", 1) != 0)
31 else if (strcmp (getenv ("a"), "=") != 0)
36 [gl_cv_func_setenv_works=yes], [gl_cv_func_setenv_works=no],
38 # Guess yes on glibc systems.
39 *-gnu* | gnu*) gl_cv_func_setenv_works="guessing yes" ;;
40 # Guess yes on musl systems.
41 *-musl*) gl_cv_func_setenv_works="guessing yes" ;;
42 # If we don't know, obey --enable-cross-guesses.
43 *) gl_cv_func_setenv_works="$gl_cross_guess_normal" ;;
46 case "$gl_cv_func_setenv_works" in
55 # Like gl_FUNC_SETENV, except prepare for separate compilation
56 # (no REPLACE_SETENV, no AC_LIBOBJ).
57 AC_DEFUN([gl_FUNC_SETENV_SEPARATE],
59 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
60 AC_CHECK_DECLS_ONCE([setenv])
61 if test $ac_cv_have_decl_setenv = no; then
64 AC_CHECK_FUNCS_ONCE([setenv])
68 AC_DEFUN([gl_FUNC_UNSETENV],
70 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
71 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
72 AC_CHECK_DECLS_ONCE([unsetenv])
73 if test $ac_cv_have_decl_unsetenv = no; then
76 AC_CHECK_FUNCS([unsetenv])
77 if test $ac_cv_func_unsetenv = no; then
81 dnl Some BSDs return void, failing to do error checking.
82 AC_CACHE_CHECK([for unsetenv() return type], [gt_cv_func_unsetenv_ret],
87 #define _BSD 1 /* unhide unsetenv declaration in OSF/1 5.1 <stdlib.h> */
93 int unsetenv (const char *name);
96 [gt_cv_func_unsetenv_ret='int'],
97 [gt_cv_func_unsetenv_ret='void'])])
98 if test $gt_cv_func_unsetenv_ret = 'void'; then
99 AC_DEFINE([VOID_UNSETENV], [1], [Define to 1 if unsetenv returns void
104 dnl Solaris 10 unsetenv does not remove all copies of a name.
105 dnl Haiku alpha 2 unsetenv gets confused by assignment to environ.
106 dnl OpenBSD 4.7 unsetenv("") does not fail.
107 AC_CACHE_CHECK([whether unsetenv obeys POSIX],
108 [gl_cv_func_unsetenv_works],
113 extern char **environ;
116 char entry1[] = "a=1";
117 char entry2[] = "b=2";
118 char *env[] = { entry1, entry2, NULL };
119 if (putenv ((char *) "a=1")) return 1;
120 if (putenv (entry2)) return 2;
123 if (getenv ("a")) return 3;
124 if (!unsetenv ("") || errno != EINVAL) return 4;
127 if (!getenv ("a")) return 5;
130 if (getenv ("a")) return 6;
132 [gl_cv_func_unsetenv_works=yes],
133 [gl_cv_func_unsetenv_works=no],
135 # Guess yes on glibc systems.
136 *-gnu*) gl_cv_func_unsetenv_works="guessing yes" ;;
137 # If we don't know, obey --enable-cross-guesses.
138 *) gl_cv_func_unsetenv_works="$gl_cross_guess_normal" ;;
142 case "$gl_cv_func_unsetenv_works" in
151 # Prerequisites of lib/setenv.c.
152 AC_DEFUN([gl_PREREQ_SETENV],
154 AC_REQUIRE([AC_FUNC_ALLOCA])
155 AC_REQUIRE([gl_ENVIRON])
156 AC_CHECK_HEADERS_ONCE([unistd.h])
157 AC_CHECK_HEADERS([search.h])
158 AC_CHECK_FUNCS([tsearch])
161 # Prerequisites of lib/unsetenv.c.
162 AC_DEFUN([gl_PREREQ_UNSETENV],
164 AC_REQUIRE([gl_ENVIRON])
165 AC_CHECK_HEADERS_ONCE([unistd.h])