setenv.m4 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # setenv.m4 serial 16
  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.
  6. AC_DEFUN([gl_FUNC_SETENV],
  7. [
  8. AC_REQUIRE([gl_FUNC_SETENV_SEPARATE])
  9. if test $HAVE_SETENV$REPLACE_SETENV != 10; then
  10. AC_LIBOBJ([setenv])
  11. fi
  12. ])
  13. # Like gl_FUNC_SETENV, except prepare for separate compilation (no AC_LIBOBJ).
  14. AC_DEFUN([gl_FUNC_SETENV_SEPARATE],
  15. [
  16. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  17. AC_CHECK_FUNCS_ONCE([setenv])
  18. if test $ac_cv_func_setenv = no; then
  19. HAVE_SETENV=0
  20. else
  21. AC_CACHE_CHECK([whether setenv validates arguments],
  22. [gl_cv_func_setenv_works],
  23. [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  24. #include <stdlib.h>
  25. #include <errno.h>
  26. #include <string.h>
  27. ]], [[
  28. if (setenv ("", "", 0) != -1) return 1;
  29. if (errno != EINVAL) return 2;
  30. if (setenv ("a", "=", 1) != 0) return 3;
  31. if (strcmp (getenv ("a"), "=") != 0) return 4;
  32. ]])],
  33. [gl_cv_func_setenv_works=yes], [gl_cv_func_setenv_works=no],
  34. [gl_cv_func_setenv_works="guessing no"])])
  35. if test "$gl_cv_func_setenv_works" != yes; then
  36. REPLACE_SETENV=1
  37. AC_LIBOBJ([setenv])
  38. fi
  39. fi
  40. gl_PREREQ_SETENV
  41. ])
  42. AC_DEFUN([gl_FUNC_UNSETENV],
  43. [
  44. AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  45. AC_CHECK_FUNCS([unsetenv])
  46. if test $ac_cv_func_unsetenv = no; then
  47. HAVE_UNSETENV=0
  48. AC_LIBOBJ([unsetenv])
  49. gl_PREREQ_UNSETENV
  50. else
  51. dnl Some BSDs return void, failing to do error checking.
  52. AC_CACHE_CHECK([for unsetenv() return type], [gt_cv_func_unsetenv_ret],
  53. [AC_TRY_COMPILE([#include <stdlib.h>
  54. extern
  55. #ifdef __cplusplus
  56. "C"
  57. #endif
  58. #if defined(__STDC__) || defined(__cplusplus)
  59. int unsetenv (const char *name);
  60. #else
  61. int unsetenv();
  62. #endif
  63. ], , gt_cv_func_unsetenv_ret='int', gt_cv_func_unsetenv_ret='void')])
  64. if test $gt_cv_func_unsetenv_ret = 'void'; then
  65. AC_DEFINE([VOID_UNSETENV], [1], [Define to 1 if unsetenv returns void
  66. instead of int.])
  67. REPLACE_UNSETENV=1
  68. AC_LIBOBJ([unsetenv])
  69. fi
  70. dnl Solaris 10 unsetenv does not remove all copies of a name.
  71. AC_CACHE_CHECK([whether unsetenv works on duplicates],
  72. [gl_cv_func_unsetenv_works],
  73. [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  74. #include <stdlib.h>
  75. ]], [[
  76. char entry[] = "b=2";
  77. if (putenv ((char *) "a=1")) return 1;
  78. if (putenv (entry)) return 2;
  79. entry[0] = 'a';
  80. unsetenv ("a");
  81. if (getenv ("a")) return 3;
  82. ]])],
  83. [gl_cv_func_unsetenv_works=yes], [gl_cv_func_unsetenv_works=no],
  84. [gl_cv_func_unsetenv_works="guessing no"])])
  85. if test "$gl_cv_func_unsetenv_works" != yes; then
  86. REPLACE_UNSETENV=1
  87. AC_LIBOBJ([unsetenv])
  88. fi
  89. fi
  90. ])
  91. # Prerequisites of lib/setenv.c.
  92. AC_DEFUN([gl_PREREQ_SETENV],
  93. [
  94. AC_REQUIRE([AC_FUNC_ALLOCA])
  95. AC_REQUIRE([gl_ENVIRON])
  96. AC_CHECK_HEADERS_ONCE([unistd.h])
  97. AC_CHECK_HEADERS([search.h])
  98. AC_CHECK_FUNCS([tsearch])
  99. ])
  100. # Prerequisites of lib/unsetenv.c.
  101. AC_DEFUN([gl_PREREQ_UNSETENV],
  102. [
  103. AC_REQUIRE([gl_ENVIRON])
  104. AC_CHECK_HEADERS_ONCE([unistd.h])
  105. ])