diff options
Diffstat (limited to 'gl/m4/setenv.m4')
-rw-r--r-- | gl/m4/setenv.m4 | 127 |
1 files changed, 88 insertions, 39 deletions
diff --git a/gl/m4/setenv.m4 b/gl/m4/setenv.m4 index 58f6d138..cb5351a0 100644 --- a/gl/m4/setenv.m4 +++ b/gl/m4/setenv.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # setenv.m4 serial 16 | 1 | # setenv.m4 serial 26 |
2 | dnl Copyright (C) 2001-2004, 2006-2010 Free Software Foundation, Inc. | 2 | dnl Copyright (C) 2001-2004, 2006-2013 Free Software Foundation, Inc. |
3 | dnl This file is free software; the Free Software Foundation | 3 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 4 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 5 | dnl with or without modifications, as long as this notice is preserved. |
@@ -7,16 +7,7 @@ dnl with or without modifications, as long as this notice is preserved. | |||
7 | AC_DEFUN([gl_FUNC_SETENV], | 7 | AC_DEFUN([gl_FUNC_SETENV], |
8 | [ | 8 | [ |
9 | AC_REQUIRE([gl_FUNC_SETENV_SEPARATE]) | 9 | AC_REQUIRE([gl_FUNC_SETENV_SEPARATE]) |
10 | if test $HAVE_SETENV$REPLACE_SETENV != 10; then | 10 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
11 | AC_LIBOBJ([setenv]) | ||
12 | fi | ||
13 | ]) | ||
14 | |||
15 | # Like gl_FUNC_SETENV, except prepare for separate compilation (no AC_LIBOBJ). | ||
16 | AC_DEFUN([gl_FUNC_SETENV_SEPARATE], | ||
17 | [ | ||
18 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) | ||
19 | AC_CHECK_FUNCS_ONCE([setenv]) | ||
20 | if test $ac_cv_func_setenv = no; then | 11 | if test $ac_cv_func_setenv = no; then |
21 | HAVE_SETENV=0 | 12 | HAVE_SETENV=0 |
22 | else | 13 | else |
@@ -27,69 +18,127 @@ AC_DEFUN([gl_FUNC_SETENV_SEPARATE], | |||
27 | #include <errno.h> | 18 | #include <errno.h> |
28 | #include <string.h> | 19 | #include <string.h> |
29 | ]], [[ | 20 | ]], [[ |
30 | if (setenv ("", "", 0) != -1) return 1; | 21 | int result = 0; |
31 | if (errno != EINVAL) return 2; | 22 | { |
32 | if (setenv ("a", "=", 1) != 0) return 3; | 23 | if (setenv ("", "", 0) != -1) |
33 | if (strcmp (getenv ("a"), "=") != 0) return 4; | 24 | result |= 1; |
25 | else if (errno != EINVAL) | ||
26 | result |= 2; | ||
27 | } | ||
28 | { | ||
29 | if (setenv ("a", "=", 1) != 0) | ||
30 | result |= 4; | ||
31 | else if (strcmp (getenv ("a"), "=") != 0) | ||
32 | result |= 8; | ||
33 | } | ||
34 | return result; | ||
34 | ]])], | 35 | ]])], |
35 | [gl_cv_func_setenv_works=yes], [gl_cv_func_setenv_works=no], | 36 | [gl_cv_func_setenv_works=yes], [gl_cv_func_setenv_works=no], |
36 | [gl_cv_func_setenv_works="guessing no"])]) | 37 | [case "$host_os" in |
37 | if test "$gl_cv_func_setenv_works" != yes; then | 38 | # Guess yes on glibc systems. |
38 | REPLACE_SETENV=1 | 39 | *-gnu*) gl_cv_func_setenv_works="guessing yes" ;; |
39 | AC_LIBOBJ([setenv]) | 40 | # If we don't know, assume the worst. |
40 | fi | 41 | *) gl_cv_func_setenv_works="guessing no" ;; |
42 | esac | ||
43 | ])]) | ||
44 | case "$gl_cv_func_setenv_works" in | ||
45 | *yes) ;; | ||
46 | *) | ||
47 | REPLACE_SETENV=1 | ||
48 | ;; | ||
49 | esac | ||
41 | fi | 50 | fi |
51 | ]) | ||
52 | |||
53 | # Like gl_FUNC_SETENV, except prepare for separate compilation | ||
54 | # (no REPLACE_SETENV, no AC_LIBOBJ). | ||
55 | AC_DEFUN([gl_FUNC_SETENV_SEPARATE], | ||
56 | [ | ||
57 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) | ||
58 | AC_CHECK_DECLS_ONCE([setenv]) | ||
59 | if test $ac_cv_have_decl_setenv = no; then | ||
60 | HAVE_DECL_SETENV=0 | ||
61 | fi | ||
62 | AC_CHECK_FUNCS_ONCE([setenv]) | ||
42 | gl_PREREQ_SETENV | 63 | gl_PREREQ_SETENV |
43 | ]) | 64 | ]) |
44 | 65 | ||
45 | AC_DEFUN([gl_FUNC_UNSETENV], | 66 | AC_DEFUN([gl_FUNC_UNSETENV], |
46 | [ | 67 | [ |
47 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) | 68 | AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
69 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
70 | AC_CHECK_DECLS_ONCE([unsetenv]) | ||
71 | if test $ac_cv_have_decl_unsetenv = no; then | ||
72 | HAVE_DECL_UNSETENV=0 | ||
73 | fi | ||
48 | AC_CHECK_FUNCS([unsetenv]) | 74 | AC_CHECK_FUNCS([unsetenv]) |
49 | if test $ac_cv_func_unsetenv = no; then | 75 | if test $ac_cv_func_unsetenv = no; then |
50 | HAVE_UNSETENV=0 | 76 | HAVE_UNSETENV=0 |
51 | AC_LIBOBJ([unsetenv]) | ||
52 | gl_PREREQ_UNSETENV | ||
53 | else | 77 | else |
78 | HAVE_UNSETENV=1 | ||
54 | dnl Some BSDs return void, failing to do error checking. | 79 | dnl Some BSDs return void, failing to do error checking. |
55 | AC_CACHE_CHECK([for unsetenv() return type], [gt_cv_func_unsetenv_ret], | 80 | AC_CACHE_CHECK([for unsetenv() return type], [gt_cv_func_unsetenv_ret], |
56 | [AC_TRY_COMPILE([#include <stdlib.h> | 81 | [AC_COMPILE_IFELSE( |
82 | [AC_LANG_PROGRAM( | ||
83 | [[ | ||
84 | #undef _BSD | ||
85 | #define _BSD 1 /* unhide unsetenv declaration in OSF/1 5.1 <stdlib.h> */ | ||
86 | #include <stdlib.h> | ||
57 | extern | 87 | extern |
58 | #ifdef __cplusplus | 88 | #ifdef __cplusplus |
59 | "C" | 89 | "C" |
60 | #endif | 90 | #endif |
61 | #if defined(__STDC__) || defined(__cplusplus) | ||
62 | int unsetenv (const char *name); | 91 | int unsetenv (const char *name); |
63 | #else | 92 | ]], |
64 | int unsetenv(); | 93 | [[]])], |
65 | #endif | 94 | [gt_cv_func_unsetenv_ret='int'], |
66 | ], , gt_cv_func_unsetenv_ret='int', gt_cv_func_unsetenv_ret='void')]) | 95 | [gt_cv_func_unsetenv_ret='void'])]) |
67 | if test $gt_cv_func_unsetenv_ret = 'void'; then | 96 | if test $gt_cv_func_unsetenv_ret = 'void'; then |
68 | AC_DEFINE([VOID_UNSETENV], [1], [Define to 1 if unsetenv returns void | 97 | AC_DEFINE([VOID_UNSETENV], [1], [Define to 1 if unsetenv returns void |
69 | instead of int.]) | 98 | instead of int.]) |
70 | REPLACE_UNSETENV=1 | 99 | REPLACE_UNSETENV=1 |
71 | AC_LIBOBJ([unsetenv]) | ||
72 | fi | 100 | fi |
73 | 101 | ||
74 | dnl Solaris 10 unsetenv does not remove all copies of a name. | 102 | dnl Solaris 10 unsetenv does not remove all copies of a name. |
75 | AC_CACHE_CHECK([whether unsetenv works on duplicates], | 103 | dnl Haiku alpha 2 unsetenv gets confused by assignment to environ. |
104 | dnl OpenBSD 4.7 unsetenv("") does not fail. | ||
105 | AC_CACHE_CHECK([whether unsetenv obeys POSIX], | ||
76 | [gl_cv_func_unsetenv_works], | 106 | [gl_cv_func_unsetenv_works], |
77 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ | 107 | [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ |
78 | #include <stdlib.h> | 108 | #include <stdlib.h> |
109 | #include <errno.h> | ||
110 | extern char **environ; | ||
79 | ]], [[ | 111 | ]], [[ |
80 | char entry[] = "b=2"; | 112 | char entry1[] = "a=1"; |
113 | char entry2[] = "b=2"; | ||
114 | char *env[] = { entry1, entry2, NULL }; | ||
81 | if (putenv ((char *) "a=1")) return 1; | 115 | if (putenv ((char *) "a=1")) return 1; |
82 | if (putenv (entry)) return 2; | 116 | if (putenv (entry2)) return 2; |
83 | entry[0] = 'a'; | 117 | entry2[0] = 'a'; |
84 | unsetenv ("a"); | 118 | unsetenv ("a"); |
85 | if (getenv ("a")) return 3; | 119 | if (getenv ("a")) return 3; |
120 | if (!unsetenv ("") || errno != EINVAL) return 4; | ||
121 | entry2[0] = 'b'; | ||
122 | environ = env; | ||
123 | if (!getenv ("a")) return 5; | ||
124 | entry2[0] = 'a'; | ||
125 | unsetenv ("a"); | ||
126 | if (getenv ("a")) return 6; | ||
86 | ]])], | 127 | ]])], |
87 | [gl_cv_func_unsetenv_works=yes], [gl_cv_func_unsetenv_works=no], | 128 | [gl_cv_func_unsetenv_works=yes], [gl_cv_func_unsetenv_works=no], |
88 | [gl_cv_func_unsetenv_works="guessing no"])]) | 129 | [case "$host_os" in |
89 | if test "$gl_cv_func_unsetenv_works" != yes; then | 130 | # Guess yes on glibc systems. |
90 | REPLACE_UNSETENV=1 | 131 | *-gnu*) gl_cv_func_unsetenv_works="guessing yes" ;; |
91 | AC_LIBOBJ([unsetenv]) | 132 | # If we don't know, assume the worst. |
92 | fi | 133 | *) gl_cv_func_unsetenv_works="guessing no" ;; |
134 | esac | ||
135 | ])]) | ||
136 | case "$gl_cv_func_unsetenv_works" in | ||
137 | *yes) ;; | ||
138 | *) | ||
139 | REPLACE_UNSETENV=1 | ||
140 | ;; | ||
141 | esac | ||
93 | fi | 142 | fi |
94 | ]) | 143 | ]) |
95 | 144 | ||