Provide a return value for unsetenv() if the system doesn't.
[gnulib.git] / m4 / setenv.m4
1 # setenv.m4 serial 5
2 dnl Copyright (C) 2001-2004 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License.  As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 AC_DEFUN([gt_FUNC_SETENV],
10 [
11   AC_REPLACE_FUNCS(setenv unsetenv)
12   if test $ac_cv_func_setenv = no; then
13     gl_PREREQ_SETENV
14   fi
15   if test $ac_cv_func_unsetenv = no; then
16     gl_PREREQ_UNSETENV
17   else
18     AC_CACHE_CHECK([for unsetenv() return type], gt_cv_func_unsetenv_ret,
19       [AC_TRY_COMPILE([#include <stdlib.h>
20 extern
21 #ifdef __cplusplus
22 "C"
23 #endif
24 #if defined(__STDC__) || defined(__cplusplus)
25 int unsetenv (const char *name);
26 #else
27 int unsetenv();
28 #endif
29 ], , gt_cv_func_unsetenv_ret='int', gt_cv_func_unsetenv_ret='void')])
30     if test $gt_cv_func_unsetenv_ret = 'void'; then
31       AC_DEFINE(VOID_UNSETENV, 1, [Define if unsetenv() returns void, not int.])
32     fi
33   fi
34 ])
35
36 # Check if a variable is properly declared.
37 # gt_CHECK_VAR_DECL(includes,variable)
38 AC_DEFUN([gt_CHECK_VAR_DECL],
39 [
40   define([gt_cv_var], [gt_cv_var_]$2[_declaration])
41   AC_MSG_CHECKING([if $2 is properly declared])
42   AC_CACHE_VAL(gt_cv_var, [
43     AC_TRY_COMPILE([$1
44       extern struct { int foo; } $2;],
45       [$2.foo = 1;],
46       gt_cv_var=no,
47       gt_cv_var=yes)])
48   AC_MSG_RESULT($gt_cv_var)
49   if test $gt_cv_var = yes; then
50     AC_DEFINE([HAVE_]translit($2, [a-z], [A-Z])[_DECL], 1,
51               [Define if you have the declaration of $2.])
52   fi
53 ])
54
55 # Prerequisites of lib/setenv.c.
56 AC_DEFUN([gl_PREREQ_SETENV],
57 [
58   AC_REQUIRE([AC_FUNC_ALLOCA])
59   AC_CHECK_HEADERS_ONCE(unistd.h)
60   AC_CHECK_HEADERS(search.h)
61   AC_CHECK_FUNCS(tsearch)
62   gt_CHECK_VAR_DECL([#include <errno.h>], errno)
63   gt_CHECK_VAR_DECL([#include <unistd.h>], environ)
64 ])
65
66 # Prerequisites of lib/unsetenv.c.
67 AC_DEFUN([gl_PREREQ_UNSETENV],
68 [
69   AC_CHECK_HEADERS_ONCE(unistd.h)
70   gt_CHECK_VAR_DECL([#include <errno.h>], errno)
71   gt_CHECK_VAR_DECL([#include <unistd.h>], environ)
72 ])