0d54a9613e64645119c791128b7fbf346164c551
[gnulib.git] / m4 / setenv.m4
1 # setenv.m4 serial 7
2 dnl Copyright (C) 2001-2004, 2006-2007 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.
6
7 AC_DEFUN([gl_FUNC_SETENV],
8 [
9   AC_CHECK_FUNCS_ONCE([setenv])
10   if test $ac_cv_func_setenv = no; then
11     AC_LIBOBJ([setenv])
12     gl_PREREQ_SETENV
13   fi
14 ])
15
16 AC_DEFUN([gl_FUNC_UNSETENV],
17 [
18   AC_CHECK_FUNCS([unsetenv])
19   if test $ac_cv_func_unsetenv = no; then
20     AC_LIBOBJ([unsetenv])
21     gl_PREREQ_UNSETENV
22   else
23     AC_CACHE_CHECK([for unsetenv() return type], gt_cv_func_unsetenv_ret,
24       [AC_TRY_COMPILE([#include <stdlib.h>
25 extern
26 #ifdef __cplusplus
27 "C"
28 #endif
29 #if defined(__STDC__) || defined(__cplusplus)
30 int unsetenv (const char *name);
31 #else
32 int unsetenv();
33 #endif
34 ], , gt_cv_func_unsetenv_ret='int', gt_cv_func_unsetenv_ret='void')])
35     if test $gt_cv_func_unsetenv_ret = 'void'; then
36       AC_DEFINE(VOID_UNSETENV, 1, [Define if unsetenv() returns void, not int.])
37     fi
38   fi
39 ])
40
41 # Check if a variable is properly declared.
42 # gt_CHECK_VAR_DECL(includes,variable)
43 AC_DEFUN([gt_CHECK_VAR_DECL],
44 [
45   define([gt_cv_var], [gt_cv_var_]$2[_declaration])
46   AC_MSG_CHECKING([if $2 is properly declared])
47   AC_CACHE_VAL(gt_cv_var, [
48     AC_TRY_COMPILE([$1
49       extern struct { int foo; } $2;],
50       [$2.foo = 1;],
51       gt_cv_var=no,
52       gt_cv_var=yes)])
53   AC_MSG_RESULT($gt_cv_var)
54   if test $gt_cv_var = yes; then
55     AC_DEFINE([HAVE_]translit($2, [a-z], [A-Z])[_DECL], 1,
56               [Define if you have the declaration of $2.])
57   fi
58 ])
59
60 # Prerequisites of lib/setenv.c.
61 AC_DEFUN([gl_PREREQ_SETENV],
62 [
63   AC_REQUIRE([AC_FUNC_ALLOCA])
64   AC_CHECK_HEADERS_ONCE(unistd.h)
65   AC_CHECK_HEADERS(search.h)
66   AC_CHECK_FUNCS(tsearch)
67   gt_CHECK_VAR_DECL([#include <unistd.h>], environ)
68 ])
69
70 # Prerequisites of lib/unsetenv.c.
71 AC_DEFUN([gl_PREREQ_UNSETENV],
72 [
73   AC_CHECK_HEADERS_ONCE(unistd.h)
74   gt_CHECK_VAR_DECL([#include <unistd.h>], environ)
75 ])