2 dnl Copyright (C) 2001-2004, 2006-2011 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 $ac_cv_func_setenv = no; then
13 AC_CACHE_CHECK([whether setenv validates arguments],
14 [gl_cv_func_setenv_works],
15 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
22 if (setenv ("", "", 0) != -1)
24 else if (errno != EINVAL)
28 if (setenv ("a", "=", 1) != 0)
30 else if (strcmp (getenv ("a"), "=") != 0)
35 [gl_cv_func_setenv_works=yes], [gl_cv_func_setenv_works=no],
36 [gl_cv_func_setenv_works="guessing no"])])
37 if test "$gl_cv_func_setenv_works" != yes; then
43 # Like gl_FUNC_SETENV, except prepare for separate compilation
44 # (no REPLACE_SETENV, no AC_LIBOBJ).
45 AC_DEFUN([gl_FUNC_SETENV_SEPARATE],
47 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
48 AC_CHECK_DECLS_ONCE([setenv])
49 if test $ac_cv_have_decl_setenv = no; then
52 AC_CHECK_FUNCS_ONCE([setenv])
56 AC_DEFUN([gl_FUNC_UNSETENV],
58 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
59 AC_CHECK_DECLS_ONCE([unsetenv])
60 if test $ac_cv_have_decl_unsetenv = no; then
63 AC_CHECK_FUNCS([unsetenv])
64 if test $ac_cv_func_unsetenv = no; then
68 dnl Some BSDs return void, failing to do error checking.
69 AC_CACHE_CHECK([for unsetenv() return type], [gt_cv_func_unsetenv_ret],
74 #define _BSD 1 /* unhide unsetenv declaration in OSF/1 5.1 <stdlib.h> */
80 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
91 dnl Solaris 10 unsetenv does not remove all copies of a name.
92 dnl Haiku alpha 2 unsetenv gets confused by assignment to environ.
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([[
99 extern char **environ;
101 char entry1[] = "a=1";
102 char entry2[] = "b=2";
103 char *env[] = { entry1, entry2, NULL };
104 if (putenv ((char *) "a=1")) return 1;
105 if (putenv (entry2)) return 2;
108 if (getenv ("a")) return 3;
109 if (!unsetenv ("") || errno != EINVAL) return 4;
112 if (!getenv ("a")) return 5;
115 if (getenv ("a")) return 6;
117 [gl_cv_func_unsetenv_works=yes], [gl_cv_func_unsetenv_works=no],
118 [gl_cv_func_unsetenv_works="guessing no"])])
119 if test "$gl_cv_func_unsetenv_works" != yes; then
125 # Prerequisites of lib/setenv.c.
126 AC_DEFUN([gl_PREREQ_SETENV],
128 AC_REQUIRE([AC_FUNC_ALLOCA])
129 AC_REQUIRE([gl_ENVIRON])
130 AC_CHECK_HEADERS_ONCE([unistd.h])
131 AC_CHECK_HEADERS([search.h])
132 AC_CHECK_FUNCS([tsearch])
135 # Prerequisites of lib/unsetenv.c.
136 AC_DEFUN([gl_PREREQ_UNSETENV],
138 AC_REQUIRE([gl_ENVIRON])
139 AC_CHECK_HEADERS_ONCE([unistd.h])