2 dnl Copyright (C) 2001-2004, 2006-2010 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 if test $HAVE_SETENV$REPLACE_SETENV != 10; then
15 # Like gl_FUNC_SETENV, except prepare for separate compilation (no AC_LIBOBJ).
16 AC_DEFUN([gl_FUNC_SETENV_SEPARATE],
18 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
19 AC_CHECK_DECLS_ONCE([setenv])
20 if test $ac_cv_have_decl_setenv = no; then
23 AC_CHECK_FUNCS_ONCE([setenv])
24 if test $ac_cv_func_setenv = yes; then
25 AC_CACHE_CHECK([whether setenv validates arguments],
26 [gl_cv_func_setenv_works],
27 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
34 if (setenv ("", "", 0) != -1)
36 else if (errno != EINVAL)
40 if (setenv ("a", "=", 1) != 0)
42 else if (strcmp (getenv ("a"), "=") != 0)
47 [gl_cv_func_setenv_works=yes], [gl_cv_func_setenv_works=no],
48 [gl_cv_func_setenv_works="guessing no"])])
49 if test "$gl_cv_func_setenv_works" != yes; then
57 AC_DEFUN([gl_FUNC_UNSETENV],
59 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
60 AC_CHECK_FUNCS([unsetenv])
61 if test $ac_cv_func_unsetenv = no; then
66 dnl Some BSDs return void, failing to do error checking.
67 AC_CACHE_CHECK([for unsetenv() return type], [gt_cv_func_unsetenv_ret],
76 #if defined(__STDC__) || defined(__cplusplus)
77 int unsetenv (const char *name);
83 [gt_cv_func_unsetenv_ret='int'],
84 [gt_cv_func_unsetenv_ret='void'])])
85 if test $gt_cv_func_unsetenv_ret = 'void'; then
86 AC_DEFINE([VOID_UNSETENV], [1], [Define to 1 if unsetenv returns void
92 dnl Solaris 10 unsetenv does not remove all copies of a name.
93 dnl OpenBSD 4.7 unsetenv("") does not fail.
94 AC_CACHE_CHECK([whether unsetenv obeys POSIX],
95 [gl_cv_func_unsetenv_works],
96 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
100 char entry[] = "b=2";
101 if (putenv ((char *) "a=1")) return 1;
102 if (putenv (entry)) return 2;
105 if (getenv ("a")) return 3;
106 if (!unsetenv ("") || errno != EINVAL) return 4;
108 [gl_cv_func_unsetenv_works=yes], [gl_cv_func_unsetenv_works=no],
109 [gl_cv_func_unsetenv_works="guessing no"])])
110 if test "$gl_cv_func_unsetenv_works" != yes; then
112 AC_LIBOBJ([unsetenv])
117 # Prerequisites of lib/setenv.c.
118 AC_DEFUN([gl_PREREQ_SETENV],
120 AC_REQUIRE([AC_FUNC_ALLOCA])
121 AC_REQUIRE([gl_ENVIRON])
122 AC_CHECK_HEADERS_ONCE([unistd.h])
123 AC_CHECK_HEADERS([search.h])
124 AC_CHECK_FUNCS([tsearch])
127 # Prerequisites of lib/unsetenv.c.
128 AC_DEFUN([gl_PREREQ_UNSETENV],
130 AC_REQUIRE([gl_ENVIRON])
131 AC_CHECK_HEADERS_ONCE([unistd.h])