GNU Binutils with patches for OS216
Revision | 3d99e817a90b2a37860d527f2fb5643e7b861e7d (tree) |
---|---|
Zeit | 2017-07-10 19:23:12 |
Autor | Anton Kolesov <Anton.Kolesov@syno...> |
Commiter | Anton Kolesov |
Import setenv and unsetenv from gnulib
This patch supersedes
https://sourceware.org/ml/gdb-patches/2017-07/msg00009.html
---
Patch [1] broke a build on MinGW hosts, because MinGW doesn't provide POSIX
functions setenv () and unsetenv (). This can be fixed by using
implementations from gnulib.
[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9a6c7d9c0
gdb/ChangeLog
yyyy-mm-dd Anton Kolesov <Anton.Kolesov@synopsys.com>
* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add setenv and
unsetenv.
* gnulib/aclocal.m4: Regenerate.
* gnulib/config.in: Regenerate.
* gnulib/configure: Regenerate.
* gnulib/import/Makefile.am: Regenerate.
* gnulib/import/Makefile.in: Regenerate.
* gnulib/import/m4/gnulib-cache.m4: Regenerate.
* gnulib/import/m4/gnulib-comp.m4: Regenerate.
* gnulib/import/m4/environ.m4: New file.
* gnulib/import/m4/setenv.m4: New file.
* gnulib/import/setenv.c: New file.
* gnulib/import/unsetenv.c: New file.
@@ -1023,6 +1023,7 @@ m4_include([import/m4/dirfd.m4]) | ||
1023 | 1023 | m4_include([import/m4/dirname.m4]) |
1024 | 1024 | m4_include([import/m4/double-slash-root.m4]) |
1025 | 1025 | m4_include([import/m4/eealloc.m4]) |
1026 | +m4_include([import/m4/environ.m4]) | |
1026 | 1027 | m4_include([import/m4/errno_h.m4]) |
1027 | 1028 | m4_include([import/m4/exponentd.m4]) |
1028 | 1029 | m4_include([import/m4/exponentl.m4]) |
@@ -1071,6 +1072,7 @@ m4_include([import/m4/rawmemchr.m4]) | ||
1071 | 1072 | m4_include([import/m4/readlink.m4]) |
1072 | 1073 | m4_include([import/m4/rename.m4]) |
1073 | 1074 | m4_include([import/m4/rmdir.m4]) |
1075 | +m4_include([import/m4/setenv.m4]) | |
1074 | 1076 | m4_include([import/m4/signal_h.m4]) |
1075 | 1077 | m4_include([import/m4/ssize_t.m4]) |
1076 | 1078 | m4_include([import/m4/stat.m4]) |
@@ -95,6 +95,9 @@ | ||
95 | 95 | /* Define to 1 when the gnulib module dirfd should be tested. */ |
96 | 96 | #undef GNULIB_TEST_DIRFD |
97 | 97 | |
98 | +/* Define to 1 when the gnulib module environ should be tested. */ | |
99 | +#undef GNULIB_TEST_ENVIRON | |
100 | + | |
98 | 101 | /* Define to 1 when the gnulib module frexp should be tested. */ |
99 | 102 | #undef GNULIB_TEST_FREXP |
100 | 103 |
@@ -140,6 +143,9 @@ | ||
140 | 143 | /* Define to 1 when the gnulib module rmdir should be tested. */ |
141 | 144 | #undef GNULIB_TEST_RMDIR |
142 | 145 | |
146 | +/* Define to 1 when the gnulib module setenv should be tested. */ | |
147 | +#undef GNULIB_TEST_SETENV | |
148 | + | |
143 | 149 | /* Define to 1 when the gnulib module stat should be tested. */ |
144 | 150 | #undef GNULIB_TEST_STAT |
145 | 151 |
@@ -152,6 +158,9 @@ | ||
152 | 158 | /* Define to 1 when the gnulib module strtok_r should be tested. */ |
153 | 159 | #undef GNULIB_TEST_STRTOK_R |
154 | 160 | |
161 | +/* Define to 1 when the gnulib module unsetenv should be tested. */ | |
162 | +#undef GNULIB_TEST_UNSETENV | |
163 | + | |
155 | 164 | /* Define to 1 if you have 'alloca' after including <alloca.h>, a header that |
156 | 165 | may be supplied by this distribution. */ |
157 | 166 | #undef HAVE_ALLOCA |
@@ -201,6 +210,10 @@ | ||
201 | 210 | */ |
202 | 211 | #undef HAVE_DECL_MEMMEM |
203 | 212 | |
213 | +/* Define to 1 if you have the declaration of `setenv', and to 0 if you don't. | |
214 | + */ | |
215 | +#undef HAVE_DECL_SETENV | |
216 | + | |
204 | 217 | /* Define to 1 if you have the declaration of `strtok_r', and to 0 if you |
205 | 218 | don't. */ |
206 | 219 | #undef HAVE_DECL_STRTOK_R |
@@ -209,12 +222,19 @@ | ||
209 | 222 | don't. */ |
210 | 223 | #undef HAVE_DECL_TOWLOWER |
211 | 224 | |
225 | +/* Define to 1 if you have the declaration of `unsetenv', and to 0 if you | |
226 | + don't. */ | |
227 | +#undef HAVE_DECL_UNSETENV | |
228 | + | |
212 | 229 | /* Define to 1 if you have the <dirent.h> header file. */ |
213 | 230 | #undef HAVE_DIRENT_H |
214 | 231 | |
215 | 232 | /* Define to 1 if you have the `dirfd' function. */ |
216 | 233 | #undef HAVE_DIRFD |
217 | 234 | |
235 | +/* Define if you have the declaration of environ. */ | |
236 | +#undef HAVE_ENVIRON_DECL | |
237 | + | |
218 | 238 | /* Define to 1 if you have the <features.h> header file. */ |
219 | 239 | #undef HAVE_FEATURES_H |
220 | 240 |
@@ -1126,6 +1146,12 @@ | ||
1126 | 1146 | /* Define to 1 if 'long double' and 'double' have the same representation. */ |
1127 | 1147 | #undef HAVE_SAME_LONG_DOUBLE_AS_DOUBLE |
1128 | 1148 | |
1149 | +/* Define to 1 if you have the <search.h> header file. */ | |
1150 | +#undef HAVE_SEARCH_H | |
1151 | + | |
1152 | +/* Define to 1 if you have the `setenv' function. */ | |
1153 | +#undef HAVE_SETENV | |
1154 | + | |
1129 | 1155 | /* Define to 1 if 'sig_atomic_t' is a signed integer type. */ |
1130 | 1156 | #undef HAVE_SIGNED_SIG_ATOMIC_T |
1131 | 1157 |
@@ -1189,9 +1215,15 @@ | ||
1189 | 1215 | /* Define to 1 if you have the `towlower' function. */ |
1190 | 1216 | #undef HAVE_TOWLOWER |
1191 | 1217 | |
1218 | +/* Define to 1 if you have the `tsearch' function. */ | |
1219 | +#undef HAVE_TSEARCH | |
1220 | + | |
1192 | 1221 | /* Define to 1 if you have the <unistd.h> header file. */ |
1193 | 1222 | #undef HAVE_UNISTD_H |
1194 | 1223 | |
1224 | +/* Define to 1 if you have the `unsetenv' function. */ | |
1225 | +#undef HAVE_UNSETENV | |
1226 | + | |
1195 | 1227 | /* Define to 1 if the system has the type 'unsigned long long int'. */ |
1196 | 1228 | #undef HAVE_UNSIGNED_LONG_LONG_INT |
1197 | 1229 |
@@ -1407,6 +1439,9 @@ | ||
1407 | 1439 | #endif |
1408 | 1440 | |
1409 | 1441 | |
1442 | +/* Define to 1 if unsetenv returns void instead of int. */ | |
1443 | +#undef VOID_UNSETENV | |
1444 | + | |
1410 | 1445 | /* Define to l, ll, u, ul, ull, etc., as suitable for constants of type |
1411 | 1446 | 'wchar_t'. */ |
1412 | 1447 | #undef WCHAR_T_SUFFIX |
@@ -3307,6 +3307,7 @@ as_fn_append ac_func_list " readlink" | ||
3307 | 3307 | as_fn_append ac_func_list " realpath" |
3308 | 3308 | as_fn_append ac_header_list " sys/param.h" |
3309 | 3309 | as_fn_append ac_header_list " dirent.h" |
3310 | +as_fn_append ac_header_list " unistd.h" | |
3310 | 3311 | as_fn_append ac_func_list " btowc" |
3311 | 3312 | as_fn_append ac_func_list " isblank" |
3312 | 3313 | as_fn_append ac_func_list " iswctype" |
@@ -3324,7 +3325,6 @@ as_fn_append ac_header_list " limits.h" | ||
3324 | 3325 | as_fn_append ac_header_list " wchar.h" |
3325 | 3326 | as_fn_append ac_header_list " stdint.h" |
3326 | 3327 | as_fn_append ac_header_list " inttypes.h" |
3327 | -as_fn_append ac_header_list " unistd.h" | |
3328 | 3328 | as_fn_append ac_func_list " symlink" |
3329 | 3329 | as_fn_append ac_func_list " lstat" |
3330 | 3330 | as_fn_append ac_header_list " math.h" |
@@ -3333,6 +3333,7 @@ as_fn_append ac_func_list " mbrtowc" | ||
3333 | 3333 | as_fn_append ac_header_list " sys/mman.h" |
3334 | 3334 | as_fn_append ac_func_list " mprotect" |
3335 | 3335 | as_fn_append ac_func_list " link" |
3336 | +as_fn_append ac_func_list " setenv" | |
3336 | 3337 | as_fn_append ac_header_list " sys/stat.h" |
3337 | 3338 | as_fn_append ac_header_list " features.h" |
3338 | 3339 | as_fn_append ac_func_list " iswcntrl" |
@@ -5311,6 +5312,7 @@ fi | ||
5311 | 5312 | # Code from module dirname-lgpl: |
5312 | 5313 | # Code from module dosname: |
5313 | 5314 | # Code from module double-slash-root: |
5315 | + # Code from module environ: | |
5314 | 5316 | # Code from module errno: |
5315 | 5317 | # Code from module extensions: |
5316 | 5318 | # Code from module extern-inline: |
@@ -5352,6 +5354,7 @@ fi | ||
5352 | 5354 | # Code from module rename: |
5353 | 5355 | # Code from module rmdir: |
5354 | 5356 | # Code from module same-inode: |
5357 | + # Code from module setenv: | |
5355 | 5358 | # Code from module signal-h: |
5356 | 5359 | # Code from module snippet/_Noreturn: |
5357 | 5360 | # Code from module snippet/arg-nonnull: |
@@ -5376,6 +5379,7 @@ fi | ||
5376 | 5379 | # Code from module sys_types: |
5377 | 5380 | # Code from module time: |
5378 | 5381 | # Code from module unistd: |
5382 | + # Code from module unsetenv: | |
5379 | 5383 | # Code from module update-copyright: |
5380 | 5384 | # Code from module verify: |
5381 | 5385 | # Code from module wchar: |
@@ -6826,6 +6830,59 @@ $as_echo "$gl_cv_pragma_columns" >&6; } | ||
6826 | 6830 | |
6827 | 6831 | |
6828 | 6832 | |
6833 | + | |
6834 | + | |
6835 | + | |
6836 | + | |
6837 | + | |
6838 | + | |
6839 | + | |
6840 | + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if environ is properly declared" >&5 | |
6841 | +$as_echo_n "checking if environ is properly declared... " >&6; } | |
6842 | + if test "${gt_cv_var_environ_declaration+set}" = set; then : | |
6843 | + $as_echo_n "(cached) " >&6 | |
6844 | +else | |
6845 | + | |
6846 | + cat confdefs.h - <<_ACEOF >conftest.$ac_ext | |
6847 | +/* end confdefs.h. */ | |
6848 | +#if HAVE_UNISTD_H | |
6849 | + #include <unistd.h> | |
6850 | + #endif | |
6851 | + /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */ | |
6852 | + #include <stdlib.h> | |
6853 | + | |
6854 | + extern struct { int foo; } environ; | |
6855 | +int | |
6856 | +main () | |
6857 | +{ | |
6858 | +environ.foo = 1; | |
6859 | + ; | |
6860 | + return 0; | |
6861 | +} | |
6862 | +_ACEOF | |
6863 | +if ac_fn_c_try_compile "$LINENO"; then : | |
6864 | + gt_cv_var_environ_declaration=no | |
6865 | +else | |
6866 | + gt_cv_var_environ_declaration=yes | |
6867 | +fi | |
6868 | +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext | |
6869 | +fi | |
6870 | + | |
6871 | + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_var_environ_declaration" >&5 | |
6872 | +$as_echo "$gt_cv_var_environ_declaration" >&6; } | |
6873 | + if test $gt_cv_var_environ_declaration = yes; then | |
6874 | + | |
6875 | +$as_echo "#define HAVE_ENVIRON_DECL 1" >>confdefs.h | |
6876 | + | |
6877 | + fi | |
6878 | + | |
6879 | + | |
6880 | + if test $gt_cv_var_environ_declaration != yes; then | |
6881 | + HAVE_DECL_ENVIRON=0 | |
6882 | + fi | |
6883 | + | |
6884 | + | |
6885 | + | |
6829 | 6886 | { $as_echo "$as_me:${as_lineno-$LINENO}: checking for complete errno.h" >&5 |
6830 | 6887 | $as_echo_n "checking for complete errno.h... " >&6; } |
6831 | 6888 | if test "${gl_cv_header_errno_h_complete+set}" = set; then : |
@@ -9919,8 +9976,6 @@ $as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h | ||
9919 | 9976 | |
9920 | 9977 | |
9921 | 9978 | |
9922 | - | |
9923 | - | |
9924 | 9979 | { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working fcntl.h" >&5 |
9925 | 9980 | $as_echo_n "checking for working fcntl.h... " >&6; } |
9926 | 9981 | if test "${gl_cv_header_working_fcntl_h+set}" = set; then : |
@@ -11411,6 +11466,55 @@ $as_echo "$gl_cv_func_memmem_works_always" >&6; } | ||
11411 | 11466 | |
11412 | 11467 | |
11413 | 11468 | |
11469 | +ac_fn_c_check_decl "$LINENO" "setenv" "ac_cv_have_decl_setenv" "$ac_includes_default" | |
11470 | +if test "x$ac_cv_have_decl_setenv" = x""yes; then : | |
11471 | + ac_have_decl=1 | |
11472 | +else | |
11473 | + ac_have_decl=0 | |
11474 | +fi | |
11475 | + | |
11476 | +cat >>confdefs.h <<_ACEOF | |
11477 | +#define HAVE_DECL_SETENV $ac_have_decl | |
11478 | +_ACEOF | |
11479 | + | |
11480 | + | |
11481 | + | |
11482 | + | |
11483 | + | |
11484 | + | |
11485 | + if test $ac_cv_have_decl_setenv = no; then | |
11486 | + HAVE_DECL_SETENV=0 | |
11487 | + fi | |
11488 | + | |
11489 | + | |
11490 | + | |
11491 | + | |
11492 | + | |
11493 | + for ac_header in search.h | |
11494 | +do : | |
11495 | + ac_fn_c_check_header_mongrel "$LINENO" "search.h" "ac_cv_header_search_h" "$ac_includes_default" | |
11496 | +if test "x$ac_cv_header_search_h" = x""yes; then : | |
11497 | + cat >>confdefs.h <<_ACEOF | |
11498 | +#define HAVE_SEARCH_H 1 | |
11499 | +_ACEOF | |
11500 | + | |
11501 | +fi | |
11502 | + | |
11503 | +done | |
11504 | + | |
11505 | + for ac_func in tsearch | |
11506 | +do : | |
11507 | + ac_fn_c_check_func "$LINENO" "tsearch" "ac_cv_func_tsearch" | |
11508 | +if test "x$ac_cv_func_tsearch" = x""yes; then : | |
11509 | + cat >>confdefs.h <<_ACEOF | |
11510 | +#define HAVE_TSEARCH 1 | |
11511 | +_ACEOF | |
11512 | + | |
11513 | +fi | |
11514 | +done | |
11515 | + | |
11516 | + | |
11517 | + | |
11414 | 11518 | |
11415 | 11519 | GNULIB_PTHREAD_SIGMASK=0; |
11416 | 11520 | GNULIB_RAISE=0; |
@@ -12246,6 +12350,17 @@ $as_echo "$gl_cv_next_time_h" >&6; } | ||
12246 | 12350 | |
12247 | 12351 | |
12248 | 12352 | |
12353 | +ac_fn_c_check_decl "$LINENO" "unsetenv" "ac_cv_have_decl_unsetenv" "$ac_includes_default" | |
12354 | +if test "x$ac_cv_have_decl_unsetenv" = x""yes; then : | |
12355 | + ac_have_decl=1 | |
12356 | +else | |
12357 | + ac_have_decl=0 | |
12358 | +fi | |
12359 | + | |
12360 | +cat >>confdefs.h <<_ACEOF | |
12361 | +#define HAVE_DECL_UNSETENV $ac_have_decl | |
12362 | +_ACEOF | |
12363 | + | |
12249 | 12364 | |
12250 | 12365 | { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether <wchar.h> uses 'inline' correctly" >&5 |
12251 | 12366 | $as_echo_n "checking whether <wchar.h> uses 'inline' correctly... " >&6; } |
@@ -12917,6 +13032,22 @@ $as_echo "#define DOUBLE_SLASH_IS_DISTINCT_ROOT 1" >>confdefs.h | ||
12917 | 13032 | |
12918 | 13033 | |
12919 | 13034 | |
13035 | + | |
13036 | + | |
13037 | + | |
13038 | + GNULIB_ENVIRON=1 | |
13039 | + | |
13040 | + | |
13041 | + | |
13042 | + | |
13043 | + | |
13044 | +$as_echo "#define GNULIB_TEST_ENVIRON 1" >>confdefs.h | |
13045 | + | |
13046 | + | |
13047 | + | |
13048 | + | |
13049 | + | |
13050 | + | |
12920 | 13051 | { $as_echo "$as_me:${as_lineno-$LINENO}: checking for flexible array member" >&5 |
12921 | 13052 | $as_echo_n "checking for flexible array member... " >&6; } |
12922 | 13053 | if test "${ac_cv_c_flexmember+set}" = set; then : |
@@ -17099,6 +17230,102 @@ $as_echo "#define GNULIB_TEST_RMDIR 1" >>confdefs.h | ||
17099 | 17230 | |
17100 | 17231 | |
17101 | 17232 | |
17233 | + if test $ac_cv_func_setenv = no; then | |
17234 | + HAVE_SETENV=0 | |
17235 | + else | |
17236 | + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether setenv validates arguments" >&5 | |
17237 | +$as_echo_n "checking whether setenv validates arguments... " >&6; } | |
17238 | +if test "${gl_cv_func_setenv_works+set}" = set; then : | |
17239 | + $as_echo_n "(cached) " >&6 | |
17240 | +else | |
17241 | + if test "$cross_compiling" = yes; then : | |
17242 | + case "$host_os" in | |
17243 | + # Guess yes on glibc systems. | |
17244 | + *-gnu*) gl_cv_func_setenv_works="guessing yes" ;; | |
17245 | + # If we don't know, assume the worst. | |
17246 | + *) gl_cv_func_setenv_works="guessing no" ;; | |
17247 | + esac | |
17248 | + | |
17249 | +else | |
17250 | + cat confdefs.h - <<_ACEOF >conftest.$ac_ext | |
17251 | +/* end confdefs.h. */ | |
17252 | + | |
17253 | + #include <stdlib.h> | |
17254 | + #include <errno.h> | |
17255 | + #include <string.h> | |
17256 | + | |
17257 | +int | |
17258 | +main () | |
17259 | +{ | |
17260 | + | |
17261 | + int result = 0; | |
17262 | + { | |
17263 | + if (setenv ("", "", 0) != -1) | |
17264 | + result |= 1; | |
17265 | + else if (errno != EINVAL) | |
17266 | + result |= 2; | |
17267 | + } | |
17268 | + { | |
17269 | + if (setenv ("a", "=", 1) != 0) | |
17270 | + result |= 4; | |
17271 | + else if (strcmp (getenv ("a"), "=") != 0) | |
17272 | + result |= 8; | |
17273 | + } | |
17274 | + return result; | |
17275 | + | |
17276 | + ; | |
17277 | + return 0; | |
17278 | +} | |
17279 | +_ACEOF | |
17280 | +if ac_fn_c_try_run "$LINENO"; then : | |
17281 | + gl_cv_func_setenv_works=yes | |
17282 | +else | |
17283 | + gl_cv_func_setenv_works=no | |
17284 | +fi | |
17285 | +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ | |
17286 | + conftest.$ac_objext conftest.beam conftest.$ac_ext | |
17287 | +fi | |
17288 | + | |
17289 | +fi | |
17290 | +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_setenv_works" >&5 | |
17291 | +$as_echo "$gl_cv_func_setenv_works" >&6; } | |
17292 | + case "$gl_cv_func_setenv_works" in | |
17293 | + *yes) ;; | |
17294 | + *) | |
17295 | + REPLACE_SETENV=1 | |
17296 | + ;; | |
17297 | + esac | |
17298 | + fi | |
17299 | + | |
17300 | + if test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1; then | |
17301 | + | |
17302 | + | |
17303 | + | |
17304 | + | |
17305 | + | |
17306 | + | |
17307 | + | |
17308 | + | |
17309 | + gl_LIBOBJS="$gl_LIBOBJS setenv.$ac_objext" | |
17310 | + | |
17311 | + fi | |
17312 | + | |
17313 | + | |
17314 | + | |
17315 | + | |
17316 | + | |
17317 | + GNULIB_SETENV=1 | |
17318 | + | |
17319 | + | |
17320 | + | |
17321 | + | |
17322 | + | |
17323 | +$as_echo "#define GNULIB_TEST_SETENV 1" >>confdefs.h | |
17324 | + | |
17325 | + | |
17326 | + | |
17327 | + | |
17328 | + | |
17102 | 17329 | |
17103 | 17330 | |
17104 | 17331 |
@@ -18642,6 +18869,164 @@ fi | ||
18642 | 18869 | |
18643 | 18870 | |
18644 | 18871 | |
18872 | + if test $ac_cv_have_decl_unsetenv = no; then | |
18873 | + HAVE_DECL_UNSETENV=0 | |
18874 | + fi | |
18875 | + for ac_func in unsetenv | |
18876 | +do : | |
18877 | + ac_fn_c_check_func "$LINENO" "unsetenv" "ac_cv_func_unsetenv" | |
18878 | +if test "x$ac_cv_func_unsetenv" = x""yes; then : | |
18879 | + cat >>confdefs.h <<_ACEOF | |
18880 | +#define HAVE_UNSETENV 1 | |
18881 | +_ACEOF | |
18882 | + | |
18883 | +fi | |
18884 | +done | |
18885 | + | |
18886 | + if test $ac_cv_func_unsetenv = no; then | |
18887 | + HAVE_UNSETENV=0 | |
18888 | + else | |
18889 | + HAVE_UNSETENV=1 | |
18890 | + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for unsetenv() return type" >&5 | |
18891 | +$as_echo_n "checking for unsetenv() return type... " >&6; } | |
18892 | +if test "${gt_cv_func_unsetenv_ret+set}" = set; then : | |
18893 | + $as_echo_n "(cached) " >&6 | |
18894 | +else | |
18895 | + cat confdefs.h - <<_ACEOF >conftest.$ac_ext | |
18896 | +/* end confdefs.h. */ | |
18897 | + | |
18898 | +#undef _BSD | |
18899 | +#define _BSD 1 /* unhide unsetenv declaration in OSF/1 5.1 <stdlib.h> */ | |
18900 | +#include <stdlib.h> | |
18901 | +extern | |
18902 | +#ifdef __cplusplus | |
18903 | +"C" | |
18904 | +#endif | |
18905 | +int unsetenv (const char *name); | |
18906 | + | |
18907 | +int | |
18908 | +main () | |
18909 | +{ | |
18910 | + | |
18911 | + ; | |
18912 | + return 0; | |
18913 | +} | |
18914 | +_ACEOF | |
18915 | +if ac_fn_c_try_compile "$LINENO"; then : | |
18916 | + gt_cv_func_unsetenv_ret='int' | |
18917 | +else | |
18918 | + gt_cv_func_unsetenv_ret='void' | |
18919 | +fi | |
18920 | +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext | |
18921 | +fi | |
18922 | +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gt_cv_func_unsetenv_ret" >&5 | |
18923 | +$as_echo "$gt_cv_func_unsetenv_ret" >&6; } | |
18924 | + if test $gt_cv_func_unsetenv_ret = 'void'; then | |
18925 | + | |
18926 | +$as_echo "#define VOID_UNSETENV 1" >>confdefs.h | |
18927 | + | |
18928 | + REPLACE_UNSETENV=1 | |
18929 | + fi | |
18930 | + | |
18931 | + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether unsetenv obeys POSIX" >&5 | |
18932 | +$as_echo_n "checking whether unsetenv obeys POSIX... " >&6; } | |
18933 | +if test "${gl_cv_func_unsetenv_works+set}" = set; then : | |
18934 | + $as_echo_n "(cached) " >&6 | |
18935 | +else | |
18936 | + if test "$cross_compiling" = yes; then : | |
18937 | + case "$host_os" in | |
18938 | + # Guess yes on glibc systems. | |
18939 | + *-gnu*) gl_cv_func_unsetenv_works="guessing yes" ;; | |
18940 | + # If we don't know, assume the worst. | |
18941 | + *) gl_cv_func_unsetenv_works="guessing no" ;; | |
18942 | + esac | |
18943 | + | |
18944 | +else | |
18945 | + cat confdefs.h - <<_ACEOF >conftest.$ac_ext | |
18946 | +/* end confdefs.h. */ | |
18947 | + | |
18948 | + #include <stdlib.h> | |
18949 | + #include <errno.h> | |
18950 | + extern char **environ; | |
18951 | + | |
18952 | +int | |
18953 | +main () | |
18954 | +{ | |
18955 | + | |
18956 | + char entry1[] = "a=1"; | |
18957 | + char entry2[] = "b=2"; | |
18958 | + char *env[] = { entry1, entry2, NULL }; | |
18959 | + if (putenv ((char *) "a=1")) return 1; | |
18960 | + if (putenv (entry2)) return 2; | |
18961 | + entry2[0] = 'a'; | |
18962 | + unsetenv ("a"); | |
18963 | + if (getenv ("a")) return 3; | |
18964 | + if (!unsetenv ("") || errno != EINVAL) return 4; | |
18965 | + entry2[0] = 'b'; | |
18966 | + environ = env; | |
18967 | + if (!getenv ("a")) return 5; | |
18968 | + entry2[0] = 'a'; | |
18969 | + unsetenv ("a"); | |
18970 | + if (getenv ("a")) return 6; | |
18971 | + | |
18972 | + ; | |
18973 | + return 0; | |
18974 | +} | |
18975 | +_ACEOF | |
18976 | +if ac_fn_c_try_run "$LINENO"; then : | |
18977 | + gl_cv_func_unsetenv_works=yes | |
18978 | +else | |
18979 | + gl_cv_func_unsetenv_works=no | |
18980 | +fi | |
18981 | +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ | |
18982 | + conftest.$ac_objext conftest.beam conftest.$ac_ext | |
18983 | +fi | |
18984 | + | |
18985 | +fi | |
18986 | +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_unsetenv_works" >&5 | |
18987 | +$as_echo "$gl_cv_func_unsetenv_works" >&6; } | |
18988 | + case "$gl_cv_func_unsetenv_works" in | |
18989 | + *yes) ;; | |
18990 | + *) | |
18991 | + REPLACE_UNSETENV=1 | |
18992 | + ;; | |
18993 | + esac | |
18994 | + fi | |
18995 | + | |
18996 | + if test $HAVE_UNSETENV = 0 || test $REPLACE_UNSETENV = 1; then | |
18997 | + | |
18998 | + | |
18999 | + | |
19000 | + | |
19001 | + | |
19002 | + | |
19003 | + | |
19004 | + | |
19005 | + gl_LIBOBJS="$gl_LIBOBJS unsetenv.$ac_objext" | |
19006 | + | |
19007 | + | |
19008 | + | |
19009 | + | |
19010 | + | |
19011 | + fi | |
19012 | + | |
19013 | + | |
19014 | + | |
19015 | + | |
19016 | + | |
19017 | + GNULIB_UNSETENV=1 | |
19018 | + | |
19019 | + | |
19020 | + | |
19021 | + | |
19022 | + | |
19023 | +$as_echo "#define GNULIB_TEST_UNSETENV 1" >>confdefs.h | |
19024 | + | |
19025 | + | |
19026 | + | |
19027 | + | |
19028 | + | |
19029 | + | |
18645 | 19030 | |
18646 | 19031 | |
18647 | 19032 |
@@ -21,7 +21,7 @@ | ||
21 | 21 | # the same distribution terms as the rest of that program. |
22 | 22 | # |
23 | 23 | # Generated by gnulib-tool. |
24 | -# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes limits-h lstat memchr memmem pathmax rawmemchr readlink rename signal-h strchrnul strstr strtok_r sys_stat unistd update-copyright wchar wctype-h | |
24 | +# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes limits-h lstat memchr memmem pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h | |
25 | 25 | |
26 | 26 | AUTOMAKE_OPTIONS = 1.9.6 gnits |
27 | 27 |
@@ -928,6 +928,15 @@ EXTRA_DIST += same-inode.h | ||
928 | 928 | |
929 | 929 | ## end gnulib module same-inode |
930 | 930 | |
931 | +## begin gnulib module setenv | |
932 | + | |
933 | + | |
934 | +EXTRA_DIST += setenv.c | |
935 | + | |
936 | +EXTRA_libgnu_a_SOURCES += setenv.c | |
937 | + | |
938 | +## end gnulib module setenv | |
939 | + | |
931 | 940 | ## begin gnulib module signal-h |
932 | 941 | |
933 | 942 | BUILT_SOURCES += signal.h |
@@ -1862,6 +1871,15 @@ EXTRA_DIST += unistd.in.h | ||
1862 | 1871 | |
1863 | 1872 | ## end gnulib module unistd |
1864 | 1873 | |
1874 | +## begin gnulib module unsetenv | |
1875 | + | |
1876 | + | |
1877 | +EXTRA_DIST += unsetenv.c | |
1878 | + | |
1879 | +EXTRA_libgnu_a_SOURCES += unsetenv.c | |
1880 | + | |
1881 | +## end gnulib module unsetenv | |
1882 | + | |
1865 | 1883 | ## begin gnulib module update-copyright |
1866 | 1884 | |
1867 | 1885 |
@@ -36,7 +36,7 @@ | ||
36 | 36 | # the same distribution terms as the rest of that program. |
37 | 37 | # |
38 | 38 | # Generated by gnulib-tool. |
39 | -# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes limits-h lstat memchr memmem pathmax rawmemchr readlink rename signal-h strchrnul strstr strtok_r sys_stat unistd update-copyright wchar wctype-h | |
39 | +# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes limits-h lstat memchr memmem pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h | |
40 | 40 | |
41 | 41 | |
42 | 42 |
@@ -74,6 +74,7 @@ am__aclocal_m4_deps = $(top_srcdir)/import/m4/00gnulib.m4 \ | ||
74 | 74 | $(top_srcdir)/import/m4/dirname.m4 \ |
75 | 75 | $(top_srcdir)/import/m4/double-slash-root.m4 \ |
76 | 76 | $(top_srcdir)/import/m4/eealloc.m4 \ |
77 | + $(top_srcdir)/import/m4/environ.m4 \ | |
77 | 78 | $(top_srcdir)/import/m4/errno_h.m4 \ |
78 | 79 | $(top_srcdir)/import/m4/exponentd.m4 \ |
79 | 80 | $(top_srcdir)/import/m4/exponentl.m4 \ |
@@ -122,6 +123,7 @@ am__aclocal_m4_deps = $(top_srcdir)/import/m4/00gnulib.m4 \ | ||
122 | 123 | $(top_srcdir)/import/m4/readlink.m4 \ |
123 | 124 | $(top_srcdir)/import/m4/rename.m4 \ |
124 | 125 | $(top_srcdir)/import/m4/rmdir.m4 \ |
126 | + $(top_srcdir)/import/m4/setenv.m4 \ | |
125 | 127 | $(top_srcdir)/import/m4/signal_h.m4 \ |
126 | 128 | $(top_srcdir)/import/m4/ssize_t.m4 \ |
127 | 129 | $(top_srcdir)/import/m4/stat.m4 \ |
@@ -1289,7 +1291,7 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h \ | ||
1289 | 1291 | mbrtowc.c mbsinit.c mbsrtowcs-impl.h mbsrtowcs-state.c \ |
1290 | 1292 | mbsrtowcs.c memchr.c memchr.valgrind memmem.c str-two-way.h \ |
1291 | 1293 | pathmax.h rawmemchr.c rawmemchr.valgrind readlink.c rename.c \ |
1292 | - rmdir.c same-inode.h signal.in.h \ | |
1294 | + rmdir.c same-inode.h setenv.c signal.in.h \ | |
1293 | 1295 | $(top_srcdir)/import/extra/snippet/_Noreturn.h \ |
1294 | 1296 | $(top_srcdir)/import/extra/snippet/arg-nonnull.h \ |
1295 | 1297 | $(top_srcdir)/import/extra/snippet/c++defs.h \ |
@@ -1297,7 +1299,7 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h \ | ||
1297 | 1299 | stdbool.in.h stddef.in.h stdint.in.h stdio.in.h stdlib.in.h \ |
1298 | 1300 | strchrnul.c strchrnul.valgrind streq.h string.in.h \ |
1299 | 1301 | str-two-way.h strstr.c strtok_r.c sys_stat.in.h sys_time.in.h \ |
1300 | - sys_types.in.h time.in.h unistd.in.h \ | |
1302 | + sys_types.in.h time.in.h unistd.in.h unsetenv.c \ | |
1301 | 1303 | $(top_srcdir)/import/extra/update-copyright verify.h \ |
1302 | 1304 | wchar.in.h wctype.in.h |
1303 | 1305 |
@@ -1343,7 +1345,7 @@ EXTRA_libgnu_a_SOURCES = alloca.c canonicalize-lgpl.c dirfd.c float.c \ | ||
1343 | 1345 | gettimeofday.c isnan.c isnand.c isnan.c isnanl.c lstat.c \ |
1344 | 1346 | malloc.c mbrtowc.c mbsinit.c mbsrtowcs-state.c mbsrtowcs.c \ |
1345 | 1347 | memchr.c memmem.c rawmemchr.c readlink.c rename.c rmdir.c \ |
1346 | - stat.c strchrnul.c strstr.c strtok_r.c | |
1348 | + setenv.c stat.c strchrnul.c strstr.c strtok_r.c unsetenv.c | |
1347 | 1349 | |
1348 | 1350 | # Use this preprocessor expression to decide whether #include_next works. |
1349 | 1351 | # Do not rely on a 'configure'-time test for this, since the expression |
@@ -1449,6 +1451,7 @@ distclean-compile: | ||
1449 | 1451 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readlink.Po@am__quote@ |
1450 | 1452 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rename.Po@am__quote@ |
1451 | 1453 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rmdir.Po@am__quote@ |
1454 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setenv.Po@am__quote@ | |
1452 | 1455 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stat.Po@am__quote@ |
1453 | 1456 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strchrnul.Po@am__quote@ |
1454 | 1457 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stripslash.Po@am__quote@ |
@@ -1456,6 +1459,7 @@ distclean-compile: | ||
1456 | 1459 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strstr.Po@am__quote@ |
1457 | 1460 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strtok_r.Po@am__quote@ |
1458 | 1461 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unistd.Po@am__quote@ |
1462 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unsetenv.Po@am__quote@ | |
1459 | 1463 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wctype-h.Po@am__quote@ |
1460 | 1464 | |
1461 | 1465 | .c.o: |
@@ -0,0 +1,47 @@ | ||
1 | +# environ.m4 serial 6 | |
2 | +dnl Copyright (C) 2001-2004, 2006-2016 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_ONCE([gl_ENVIRON], | |
8 | +[ | |
9 | + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) | |
10 | + dnl Persuade glibc <unistd.h> to declare environ. | |
11 | + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | |
12 | + | |
13 | + AC_CHECK_HEADERS_ONCE([unistd.h]) | |
14 | + gt_CHECK_VAR_DECL( | |
15 | + [#if HAVE_UNISTD_H | |
16 | + #include <unistd.h> | |
17 | + #endif | |
18 | + /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */ | |
19 | + #include <stdlib.h> | |
20 | + ], | |
21 | + [environ]) | |
22 | + if test $gt_cv_var_environ_declaration != yes; then | |
23 | + HAVE_DECL_ENVIRON=0 | |
24 | + fi | |
25 | +]) | |
26 | + | |
27 | +# Check if a variable is properly declared. | |
28 | +# gt_CHECK_VAR_DECL(includes,variable) | |
29 | +AC_DEFUN([gt_CHECK_VAR_DECL], | |
30 | +[ | |
31 | + define([gt_cv_var], [gt_cv_var_]$2[_declaration]) | |
32 | + AC_MSG_CHECKING([if $2 is properly declared]) | |
33 | + AC_CACHE_VAL([gt_cv_var], [ | |
34 | + AC_COMPILE_IFELSE( | |
35 | + [AC_LANG_PROGRAM( | |
36 | + [[$1 | |
37 | + extern struct { int foo; } $2;]], | |
38 | + [[$2.foo = 1;]])], | |
39 | + [gt_cv_var=no], | |
40 | + [gt_cv_var=yes])]) | |
41 | + AC_MSG_RESULT([$gt_cv_var]) | |
42 | + if test $gt_cv_var = yes; then | |
43 | + AC_DEFINE([HAVE_]m4_translit($2, [a-z], [A-Z])[_DECL], 1, | |
44 | + [Define if you have the declaration of $2.]) | |
45 | + fi | |
46 | + undefine([gt_cv_var]) | |
47 | +]) |
@@ -27,7 +27,7 @@ | ||
27 | 27 | |
28 | 28 | |
29 | 29 | # Specification in the form of a command-line invocation: |
30 | -# gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes limits-h lstat memchr memmem pathmax rawmemchr readlink rename signal-h strchrnul strstr strtok_r sys_stat unistd update-copyright wchar wctype-h | |
30 | +# gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl inttypes limits-h lstat memchr memmem pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h | |
31 | 31 | |
32 | 32 | # Specification in the form of a few gnulib-tool.m4 macro invocations: |
33 | 33 | gl_LOCAL_DIR([]) |
@@ -48,12 +48,14 @@ gl_MODULES([ | ||
48 | 48 | rawmemchr |
49 | 49 | readlink |
50 | 50 | rename |
51 | + setenv | |
51 | 52 | signal-h |
52 | 53 | strchrnul |
53 | 54 | strstr |
54 | 55 | strtok_r |
55 | 56 | sys_stat |
56 | 57 | unistd |
58 | + unsetenv | |
57 | 59 | update-copyright |
58 | 60 | wchar |
59 | 61 | wctype-h |
@@ -53,6 +53,7 @@ AC_DEFUN([gl_EARLY], | ||
53 | 53 | # Code from module dirname-lgpl: |
54 | 54 | # Code from module dosname: |
55 | 55 | # Code from module double-slash-root: |
56 | + # Code from module environ: | |
56 | 57 | # Code from module errno: |
57 | 58 | # Code from module extensions: |
58 | 59 | # Code from module extern-inline: |
@@ -94,6 +95,7 @@ AC_DEFUN([gl_EARLY], | ||
94 | 95 | # Code from module rename: |
95 | 96 | # Code from module rmdir: |
96 | 97 | # Code from module same-inode: |
98 | + # Code from module setenv: | |
97 | 99 | # Code from module signal-h: |
98 | 100 | # Code from module snippet/_Noreturn: |
99 | 101 | # Code from module snippet/arg-nonnull: |
@@ -118,6 +120,7 @@ AC_DEFUN([gl_EARLY], | ||
118 | 120 | # Code from module sys_types: |
119 | 121 | # Code from module time: |
120 | 122 | # Code from module unistd: |
123 | + # Code from module unsetenv: | |
121 | 124 | # Code from module update-copyright: |
122 | 125 | # Code from module verify: |
123 | 126 | # Code from module wchar: |
@@ -160,6 +163,8 @@ AC_DEFUN([gl_INIT], | ||
160 | 163 | gl_DIRENT_MODULE_INDICATOR([dirfd]) |
161 | 164 | gl_DIRNAME_LGPL |
162 | 165 | gl_DOUBLE_SLASH_ROOT |
166 | + gl_ENVIRON | |
167 | + gl_UNISTD_MODULE_INDICATOR([environ]) | |
163 | 168 | gl_HEADER_ERRNO_H |
164 | 169 | AC_REQUIRE([gl_EXTERN_INLINE]) |
165 | 170 | AC_C_FLEXIBLE_ARRAY_MEMBER |
@@ -285,6 +290,11 @@ AC_DEFUN([gl_INIT], | ||
285 | 290 | AC_LIBOBJ([rmdir]) |
286 | 291 | fi |
287 | 292 | gl_UNISTD_MODULE_INDICATOR([rmdir]) |
293 | + gl_FUNC_SETENV | |
294 | + if test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1; then | |
295 | + AC_LIBOBJ([setenv]) | |
296 | + fi | |
297 | + gl_STDLIB_MODULE_INDICATOR([setenv]) | |
288 | 298 | gl_SIGNAL_H |
289 | 299 | gt_TYPE_SSIZE_T |
290 | 300 | gl_FUNC_STAT |
@@ -328,6 +338,12 @@ AC_DEFUN([gl_INIT], | ||
328 | 338 | AC_PROG_MKDIR_P |
329 | 339 | gl_HEADER_TIME_H |
330 | 340 | gl_UNISTD_H |
341 | + gl_FUNC_UNSETENV | |
342 | + if test $HAVE_UNSETENV = 0 || test $REPLACE_UNSETENV = 1; then | |
343 | + AC_LIBOBJ([unsetenv]) | |
344 | + gl_PREREQ_UNSETENV | |
345 | + fi | |
346 | + gl_STDLIB_MODULE_INDICATOR([unsetenv]) | |
331 | 347 | gl_WCHAR_H |
332 | 348 | gl_WCTYPE_H |
333 | 349 | # End of code from modules |
@@ -533,6 +549,7 @@ AC_DEFUN([gl_FILE_LIST], [ | ||
533 | 549 | lib/rename.c |
534 | 550 | lib/rmdir.c |
535 | 551 | lib/same-inode.h |
552 | + lib/setenv.c | |
536 | 553 | lib/signal.in.h |
537 | 554 | lib/stat.c |
538 | 555 | lib/stdbool.in.h |
@@ -556,6 +573,7 @@ AC_DEFUN([gl_FILE_LIST], [ | ||
556 | 573 | lib/time.in.h |
557 | 574 | lib/unistd.c |
558 | 575 | lib/unistd.in.h |
576 | + lib/unsetenv.c | |
559 | 577 | lib/verify.h |
560 | 578 | lib/wchar.in.h |
561 | 579 | lib/wctype-h.c |
@@ -571,6 +589,7 @@ AC_DEFUN([gl_FILE_LIST], [ | ||
571 | 589 | m4/dirname.m4 |
572 | 590 | m4/double-slash-root.m4 |
573 | 591 | m4/eealloc.m4 |
592 | + m4/environ.m4 | |
574 | 593 | m4/errno_h.m4 |
575 | 594 | m4/exponentd.m4 |
576 | 595 | m4/exponentl.m4 |
@@ -618,6 +637,7 @@ AC_DEFUN([gl_FILE_LIST], [ | ||
618 | 637 | m4/readlink.m4 |
619 | 638 | m4/rename.m4 |
620 | 639 | m4/rmdir.m4 |
640 | + m4/setenv.m4 | |
621 | 641 | m4/signal_h.m4 |
622 | 642 | m4/ssize_t.m4 |
623 | 643 | m4/stat.m4 |
@@ -0,0 +1,160 @@ | ||
1 | +# setenv.m4 serial 26 | |
2 | +dnl Copyright (C) 2001-2004, 2006-2016 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_REQUIRE([gl_FUNC_SETENV_SEPARATE]) | |
10 | + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | |
11 | + if test $ac_cv_func_setenv = no; then | |
12 | + HAVE_SETENV=0 | |
13 | + else | |
14 | + AC_CACHE_CHECK([whether setenv validates arguments], | |
15 | + [gl_cv_func_setenv_works], | |
16 | + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ | |
17 | + #include <stdlib.h> | |
18 | + #include <errno.h> | |
19 | + #include <string.h> | |
20 | + ]], [[ | |
21 | + int result = 0; | |
22 | + { | |
23 | + if (setenv ("", "", 0) != -1) | |
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; | |
35 | + ]])], | |
36 | + [gl_cv_func_setenv_works=yes], [gl_cv_func_setenv_works=no], | |
37 | + [case "$host_os" in | |
38 | + # Guess yes on glibc systems. | |
39 | + *-gnu*) gl_cv_func_setenv_works="guessing yes" ;; | |
40 | + # If we don't know, assume the worst. | |
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 | |
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]) | |
63 | + gl_PREREQ_SETENV | |
64 | +]) | |
65 | + | |
66 | +AC_DEFUN([gl_FUNC_UNSETENV], | |
67 | +[ | |
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 | |
74 | + AC_CHECK_FUNCS([unsetenv]) | |
75 | + if test $ac_cv_func_unsetenv = no; then | |
76 | + HAVE_UNSETENV=0 | |
77 | + else | |
78 | + HAVE_UNSETENV=1 | |
79 | + dnl Some BSDs return void, failing to do error checking. | |
80 | + AC_CACHE_CHECK([for unsetenv() return type], [gt_cv_func_unsetenv_ret], | |
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> | |
87 | +extern | |
88 | +#ifdef __cplusplus | |
89 | +"C" | |
90 | +#endif | |
91 | +int unsetenv (const char *name); | |
92 | + ]], | |
93 | + [[]])], | |
94 | + [gt_cv_func_unsetenv_ret='int'], | |
95 | + [gt_cv_func_unsetenv_ret='void'])]) | |
96 | + if test $gt_cv_func_unsetenv_ret = 'void'; then | |
97 | + AC_DEFINE([VOID_UNSETENV], [1], [Define to 1 if unsetenv returns void | |
98 | + instead of int.]) | |
99 | + REPLACE_UNSETENV=1 | |
100 | + fi | |
101 | + | |
102 | + dnl Solaris 10 unsetenv does not remove all copies of a name. | |
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], | |
106 | + [gl_cv_func_unsetenv_works], | |
107 | + [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ | |
108 | + #include <stdlib.h> | |
109 | + #include <errno.h> | |
110 | + extern char **environ; | |
111 | + ]], [[ | |
112 | + char entry1[] = "a=1"; | |
113 | + char entry2[] = "b=2"; | |
114 | + char *env[] = { entry1, entry2, NULL }; | |
115 | + if (putenv ((char *) "a=1")) return 1; | |
116 | + if (putenv (entry2)) return 2; | |
117 | + entry2[0] = 'a'; | |
118 | + unsetenv ("a"); | |
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; | |
127 | + ]])], | |
128 | + [gl_cv_func_unsetenv_works=yes], [gl_cv_func_unsetenv_works=no], | |
129 | + [case "$host_os" in | |
130 | + # Guess yes on glibc systems. | |
131 | + *-gnu*) gl_cv_func_unsetenv_works="guessing yes" ;; | |
132 | + # If we don't know, assume the worst. | |
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 | |
142 | + fi | |
143 | +]) | |
144 | + | |
145 | +# Prerequisites of lib/setenv.c. | |
146 | +AC_DEFUN([gl_PREREQ_SETENV], | |
147 | +[ | |
148 | + AC_REQUIRE([AC_FUNC_ALLOCA]) | |
149 | + AC_REQUIRE([gl_ENVIRON]) | |
150 | + AC_CHECK_HEADERS_ONCE([unistd.h]) | |
151 | + AC_CHECK_HEADERS([search.h]) | |
152 | + AC_CHECK_FUNCS([tsearch]) | |
153 | +]) | |
154 | + | |
155 | +# Prerequisites of lib/unsetenv.c. | |
156 | +AC_DEFUN([gl_PREREQ_UNSETENV], | |
157 | +[ | |
158 | + AC_REQUIRE([gl_ENVIRON]) | |
159 | + AC_CHECK_HEADERS_ONCE([unistd.h]) | |
160 | +]) |
@@ -0,0 +1,390 @@ | ||
1 | +/* Copyright (C) 1992, 1995-2003, 2005-2016 Free Software Foundation, Inc. | |
2 | + This file is part of the GNU C Library. | |
3 | + | |
4 | + This program is free software: you can redistribute it and/or modify | |
5 | + it under the terms of the GNU General Public License as published by | |
6 | + the Free Software Foundation; either version 3 of the License, or | |
7 | + (at your option) any later version. | |
8 | + | |
9 | + This program is distributed in the hope that it will be useful, | |
10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | + GNU General Public License for more details. | |
13 | + | |
14 | + You should have received a copy of the GNU General Public License | |
15 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | + | |
17 | +#if !_LIBC | |
18 | +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc | |
19 | + optimizes away the name == NULL test below. */ | |
20 | +# define _GL_ARG_NONNULL(params) | |
21 | + | |
22 | +# define _GL_USE_STDLIB_ALLOC 1 | |
23 | +# include <config.h> | |
24 | +#endif | |
25 | + | |
26 | +#include <alloca.h> | |
27 | + | |
28 | +/* Specification. */ | |
29 | +#include <stdlib.h> | |
30 | + | |
31 | +#include <errno.h> | |
32 | +#ifndef __set_errno | |
33 | +# define __set_errno(ev) ((errno) = (ev)) | |
34 | +#endif | |
35 | + | |
36 | +#include <string.h> | |
37 | +#if _LIBC || HAVE_UNISTD_H | |
38 | +# include <unistd.h> | |
39 | +#endif | |
40 | + | |
41 | +#if !_LIBC | |
42 | +# include "malloca.h" | |
43 | +#endif | |
44 | + | |
45 | +#if _LIBC || !HAVE_SETENV | |
46 | + | |
47 | +#if !_LIBC | |
48 | +# define __environ environ | |
49 | +#endif | |
50 | + | |
51 | +#if _LIBC | |
52 | +/* This lock protects against simultaneous modifications of 'environ'. */ | |
53 | +# include <bits/libc-lock.h> | |
54 | +__libc_lock_define_initialized (static, envlock) | |
55 | +# define LOCK __libc_lock_lock (envlock) | |
56 | +# define UNLOCK __libc_lock_unlock (envlock) | |
57 | +#else | |
58 | +# define LOCK | |
59 | +# define UNLOCK | |
60 | +#endif | |
61 | + | |
62 | +/* In the GNU C library we must keep the namespace clean. */ | |
63 | +#ifdef _LIBC | |
64 | +# define setenv __setenv | |
65 | +# define clearenv __clearenv | |
66 | +# define tfind __tfind | |
67 | +# define tsearch __tsearch | |
68 | +#endif | |
69 | + | |
70 | +/* In the GNU C library implementation we try to be more clever and | |
71 | + allow arbitrarily many changes of the environment given that the used | |
72 | + values are from a small set. Outside glibc this will eat up all | |
73 | + memory after a while. */ | |
74 | +#if defined _LIBC || (defined HAVE_SEARCH_H && defined HAVE_TSEARCH \ | |
75 | + && defined __GNUC__) | |
76 | +# define USE_TSEARCH 1 | |
77 | +# include <search.h> | |
78 | +typedef int (*compar_fn_t) (const void *, const void *); | |
79 | + | |
80 | +/* This is a pointer to the root of the search tree with the known | |
81 | + values. */ | |
82 | +static void *known_values; | |
83 | + | |
84 | +# define KNOWN_VALUE(Str) \ | |
85 | + ({ \ | |
86 | + void *value = tfind (Str, &known_values, (compar_fn_t) strcmp); \ | |
87 | + value != NULL ? *(char **) value : NULL; \ | |
88 | + }) | |
89 | +# define STORE_VALUE(Str) \ | |
90 | + tsearch (Str, &known_values, (compar_fn_t) strcmp) | |
91 | + | |
92 | +#else | |
93 | +# undef USE_TSEARCH | |
94 | + | |
95 | +# define KNOWN_VALUE(Str) NULL | |
96 | +# define STORE_VALUE(Str) do { } while (0) | |
97 | + | |
98 | +#endif | |
99 | + | |
100 | + | |
101 | +/* If this variable is not a null pointer we allocated the current | |
102 | + environment. */ | |
103 | +static char **last_environ; | |
104 | + | |
105 | + | |
106 | +/* This function is used by 'setenv' and 'putenv'. The difference between | |
107 | + the two functions is that for the former must create a new string which | |
108 | + is then placed in the environment, while the argument of 'putenv' | |
109 | + must be used directly. This is all complicated by the fact that we try | |
110 | + to reuse values once generated for a 'setenv' call since we can never | |
111 | + free the strings. */ | |
112 | +int | |
113 | +__add_to_environ (const char *name, const char *value, const char *combined, | |
114 | + int replace) | |
115 | +{ | |
116 | + char **ep; | |
117 | + size_t size; | |
118 | + const size_t namelen = strlen (name); | |
119 | + const size_t vallen = value != NULL ? strlen (value) + 1 : 0; | |
120 | + | |
121 | + LOCK; | |
122 | + | |
123 | + /* We have to get the pointer now that we have the lock and not earlier | |
124 | + since another thread might have created a new environment. */ | |
125 | + ep = __environ; | |
126 | + | |
127 | + size = 0; | |
128 | + if (ep != NULL) | |
129 | + { | |
130 | + for (; *ep != NULL; ++ep) | |
131 | + if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=') | |
132 | + break; | |
133 | + else | |
134 | + ++size; | |
135 | + } | |
136 | + | |
137 | + if (ep == NULL || *ep == NULL) | |
138 | + { | |
139 | + char **new_environ; | |
140 | +#ifdef USE_TSEARCH | |
141 | + char *new_value; | |
142 | +#endif | |
143 | + | |
144 | + /* We allocated this space; we can extend it. */ | |
145 | + new_environ = | |
146 | + (char **) (last_environ == NULL | |
147 | + ? malloc ((size + 2) * sizeof (char *)) | |
148 | + : realloc (last_environ, (size + 2) * sizeof (char *))); | |
149 | + if (new_environ == NULL) | |
150 | + { | |
151 | + /* It's easier to set errno to ENOMEM than to rely on the | |
152 | + 'malloc-posix' and 'realloc-posix' gnulib modules. */ | |
153 | + __set_errno (ENOMEM); | |
154 | + UNLOCK; | |
155 | + return -1; | |
156 | + } | |
157 | + | |
158 | + /* If the whole entry is given add it. */ | |
159 | + if (combined != NULL) | |
160 | + /* We must not add the string to the search tree since it belongs | |
161 | + to the user. */ | |
162 | + new_environ[size] = (char *) combined; | |
163 | + else | |
164 | + { | |
165 | + /* See whether the value is already known. */ | |
166 | +#ifdef USE_TSEARCH | |
167 | +# ifdef _LIBC | |
168 | + new_value = (char *) alloca (namelen + 1 + vallen); | |
169 | + __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), | |
170 | + value, vallen); | |
171 | +# else | |
172 | + new_value = (char *) malloca (namelen + 1 + vallen); | |
173 | + if (new_value == NULL) | |
174 | + { | |
175 | + __set_errno (ENOMEM); | |
176 | + UNLOCK; | |
177 | + return -1; | |
178 | + } | |
179 | + memcpy (new_value, name, namelen); | |
180 | + new_value[namelen] = '='; | |
181 | + memcpy (&new_value[namelen + 1], value, vallen); | |
182 | +# endif | |
183 | + | |
184 | + new_environ[size] = KNOWN_VALUE (new_value); | |
185 | + if (new_environ[size] == NULL) | |
186 | +#endif | |
187 | + { | |
188 | + new_environ[size] = (char *) malloc (namelen + 1 + vallen); | |
189 | + if (new_environ[size] == NULL) | |
190 | + { | |
191 | +#if defined USE_TSEARCH && !defined _LIBC | |
192 | + freea (new_value); | |
193 | +#endif | |
194 | + __set_errno (ENOMEM); | |
195 | + UNLOCK; | |
196 | + return -1; | |
197 | + } | |
198 | + | |
199 | +#ifdef USE_TSEARCH | |
200 | + memcpy (new_environ[size], new_value, namelen + 1 + vallen); | |
201 | +#else | |
202 | + memcpy (new_environ[size], name, namelen); | |
203 | + new_environ[size][namelen] = '='; | |
204 | + memcpy (&new_environ[size][namelen + 1], value, vallen); | |
205 | +#endif | |
206 | + /* And save the value now. We cannot do this when we remove | |
207 | + the string since then we cannot decide whether it is a | |
208 | + user string or not. */ | |
209 | + STORE_VALUE (new_environ[size]); | |
210 | + } | |
211 | +#if defined USE_TSEARCH && !defined _LIBC | |
212 | + freea (new_value); | |
213 | +#endif | |
214 | + } | |
215 | + | |
216 | + if (__environ != last_environ) | |
217 | + memcpy ((char *) new_environ, (char *) __environ, | |
218 | + size * sizeof (char *)); | |
219 | + | |
220 | + new_environ[size + 1] = NULL; | |
221 | + | |
222 | + last_environ = __environ = new_environ; | |
223 | + } | |
224 | + else if (replace) | |
225 | + { | |
226 | + char *np; | |
227 | + | |
228 | + /* Use the user string if given. */ | |
229 | + if (combined != NULL) | |
230 | + np = (char *) combined; | |
231 | + else | |
232 | + { | |
233 | +#ifdef USE_TSEARCH | |
234 | + char *new_value; | |
235 | +# ifdef _LIBC | |
236 | + new_value = alloca (namelen + 1 + vallen); | |
237 | + __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1), | |
238 | + value, vallen); | |
239 | +# else | |
240 | + new_value = malloca (namelen + 1 + vallen); | |
241 | + if (new_value == NULL) | |
242 | + { | |
243 | + __set_errno (ENOMEM); | |
244 | + UNLOCK; | |
245 | + return -1; | |
246 | + } | |
247 | + memcpy (new_value, name, namelen); | |
248 | + new_value[namelen] = '='; | |
249 | + memcpy (&new_value[namelen + 1], value, vallen); | |
250 | +# endif | |
251 | + | |
252 | + np = KNOWN_VALUE (new_value); | |
253 | + if (np == NULL) | |
254 | +#endif | |
255 | + { | |
256 | + np = (char *) malloc (namelen + 1 + vallen); | |
257 | + if (np == NULL) | |
258 | + { | |
259 | +#if defined USE_TSEARCH && !defined _LIBC | |
260 | + freea (new_value); | |
261 | +#endif | |
262 | + __set_errno (ENOMEM); | |
263 | + UNLOCK; | |
264 | + return -1; | |
265 | + } | |
266 | + | |
267 | +#ifdef USE_TSEARCH | |
268 | + memcpy (np, new_value, namelen + 1 + vallen); | |
269 | +#else | |
270 | + memcpy (np, name, namelen); | |
271 | + np[namelen] = '='; | |
272 | + memcpy (&np[namelen + 1], value, vallen); | |
273 | +#endif | |
274 | + /* And remember the value. */ | |
275 | + STORE_VALUE (np); | |
276 | + } | |
277 | +#if defined USE_TSEARCH && !defined _LIBC | |
278 | + freea (new_value); | |
279 | +#endif | |
280 | + } | |
281 | + | |
282 | + *ep = np; | |
283 | + } | |
284 | + | |
285 | + UNLOCK; | |
286 | + | |
287 | + return 0; | |
288 | +} | |
289 | + | |
290 | +int | |
291 | +setenv (const char *name, const char *value, int replace) | |
292 | +{ | |
293 | + if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) | |
294 | + { | |
295 | + __set_errno (EINVAL); | |
296 | + return -1; | |
297 | + } | |
298 | + | |
299 | + return __add_to_environ (name, value, NULL, replace); | |
300 | +} | |
301 | + | |
302 | +/* The 'clearenv' was planned to be added to POSIX.1 but probably | |
303 | + never made it. Nevertheless the POSIX.9 standard (POSIX bindings | |
304 | + for Fortran 77) requires this function. */ | |
305 | +int | |
306 | +clearenv (void) | |
307 | +{ | |
308 | + LOCK; | |
309 | + | |
310 | + if (__environ == last_environ && __environ != NULL) | |
311 | + { | |
312 | + /* We allocated this environment so we can free it. */ | |
313 | + free (__environ); | |
314 | + last_environ = NULL; | |
315 | + } | |
316 | + | |
317 | + /* Clear the environment pointer removes the whole environment. */ | |
318 | + __environ = NULL; | |
319 | + | |
320 | + UNLOCK; | |
321 | + | |
322 | + return 0; | |
323 | +} | |
324 | + | |
325 | +#ifdef _LIBC | |
326 | +static void | |
327 | +free_mem (void) | |
328 | +{ | |
329 | + /* Remove all traces. */ | |
330 | + clearenv (); | |
331 | + | |
332 | + /* Now remove the search tree. */ | |
333 | + __tdestroy (known_values, free); | |
334 | + known_values = NULL; | |
335 | +} | |
336 | +text_set_element (__libc_subfreeres, free_mem); | |
337 | + | |
338 | + | |
339 | +# undef setenv | |
340 | +# undef clearenv | |
341 | +weak_alias (__setenv, setenv) | |
342 | +weak_alias (__clearenv, clearenv) | |
343 | +#endif | |
344 | + | |
345 | +#endif /* _LIBC || !HAVE_SETENV */ | |
346 | + | |
347 | +/* The rest of this file is called into use when replacing an existing | |
348 | + but buggy setenv. Known bugs include failure to diagnose invalid | |
349 | + name, and consuming a leading '=' from value. */ | |
350 | +#if HAVE_SETENV | |
351 | + | |
352 | +# undef setenv | |
353 | +# if !HAVE_DECL_SETENV | |
354 | +extern int setenv (const char *, const char *, int); | |
355 | +# endif | |
356 | +# define STREQ(a, b) (strcmp (a, b) == 0) | |
357 | + | |
358 | +int | |
359 | +rpl_setenv (const char *name, const char *value, int replace) | |
360 | +{ | |
361 | + int result; | |
362 | + if (!name || !*name || strchr (name, '=')) | |
363 | + { | |
364 | + errno = EINVAL; | |
365 | + return -1; | |
366 | + } | |
367 | + /* Call the real setenv even if replace is 0, in case implementation | |
368 | + has underlying data to update, such as when environ changes. */ | |
369 | + result = setenv (name, value, replace); | |
370 | + if (result == 0 && replace && *value == '=') | |
371 | + { | |
372 | + char *tmp = getenv (name); | |
373 | + if (!STREQ (tmp, value)) | |
374 | + { | |
375 | + int saved_errno; | |
376 | + size_t len = strlen (value); | |
377 | + tmp = malloca (len + 2); | |
378 | + /* Since leading '=' is eaten, double it up. */ | |
379 | + *tmp = '='; | |
380 | + memcpy (tmp + 1, value, len + 1); | |
381 | + result = setenv (name, tmp, replace); | |
382 | + saved_errno = errno; | |
383 | + freea (tmp); | |
384 | + errno = saved_errno; | |
385 | + } | |
386 | + } | |
387 | + return result; | |
388 | +} | |
389 | + | |
390 | +#endif /* HAVE_SETENV */ |
@@ -0,0 +1,127 @@ | ||
1 | +/* Copyright (C) 1992, 1995-2002, 2005-2016 Free Software Foundation, Inc. | |
2 | + This file is part of the GNU C Library. | |
3 | + | |
4 | + This program is free software: you can redistribute it and/or modify | |
5 | + it under the terms of the GNU General Public License as published by | |
6 | + the Free Software Foundation; either version 3 of the License, or | |
7 | + (at your option) any later version. | |
8 | + | |
9 | + This program is distributed in the hope that it will be useful, | |
10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | + GNU General Public License for more details. | |
13 | + | |
14 | + You should have received a copy of the GNU General Public License | |
15 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | + | |
17 | +/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc | |
18 | + optimizes away the name == NULL test below. */ | |
19 | +#define _GL_ARG_NONNULL(params) | |
20 | + | |
21 | +#include <config.h> | |
22 | + | |
23 | +/* Specification. */ | |
24 | +#include <stdlib.h> | |
25 | + | |
26 | +#include <errno.h> | |
27 | +#if !_LIBC | |
28 | +# define __set_errno(ev) ((errno) = (ev)) | |
29 | +#endif | |
30 | + | |
31 | +#include <string.h> | |
32 | +#include <unistd.h> | |
33 | + | |
34 | +#if !_LIBC | |
35 | +# define __environ environ | |
36 | +#endif | |
37 | + | |
38 | +#if _LIBC | |
39 | +/* This lock protects against simultaneous modifications of 'environ'. */ | |
40 | +# include <bits/libc-lock.h> | |
41 | +__libc_lock_define_initialized (static, envlock) | |
42 | +# define LOCK __libc_lock_lock (envlock) | |
43 | +# define UNLOCK __libc_lock_unlock (envlock) | |
44 | +#else | |
45 | +# define LOCK | |
46 | +# define UNLOCK | |
47 | +#endif | |
48 | + | |
49 | +/* In the GNU C library we must keep the namespace clean. */ | |
50 | +#ifdef _LIBC | |
51 | +# define unsetenv __unsetenv | |
52 | +#endif | |
53 | + | |
54 | +#if _LIBC || !HAVE_UNSETENV | |
55 | + | |
56 | +int | |
57 | +unsetenv (const char *name) | |
58 | +{ | |
59 | + size_t len; | |
60 | + char **ep; | |
61 | + | |
62 | + if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) | |
63 | + { | |
64 | + __set_errno (EINVAL); | |
65 | + return -1; | |
66 | + } | |
67 | + | |
68 | + len = strlen (name); | |
69 | + | |
70 | + LOCK; | |
71 | + | |
72 | + ep = __environ; | |
73 | + while (*ep != NULL) | |
74 | + if (!strncmp (*ep, name, len) && (*ep)[len] == '=') | |
75 | + { | |
76 | + /* Found it. Remove this pointer by moving later ones back. */ | |
77 | + char **dp = ep; | |
78 | + | |
79 | + do | |
80 | + dp[0] = dp[1]; | |
81 | + while (*dp++); | |
82 | + /* Continue the loop in case NAME appears again. */ | |
83 | + } | |
84 | + else | |
85 | + ++ep; | |
86 | + | |
87 | + UNLOCK; | |
88 | + | |
89 | + return 0; | |
90 | +} | |
91 | + | |
92 | +#ifdef _LIBC | |
93 | +# undef unsetenv | |
94 | +weak_alias (__unsetenv, unsetenv) | |
95 | +#endif | |
96 | + | |
97 | +#else /* HAVE_UNSETENV */ | |
98 | + | |
99 | +# undef unsetenv | |
100 | +# if !HAVE_DECL_UNSETENV | |
101 | +# if VOID_UNSETENV | |
102 | +extern void unsetenv (const char *); | |
103 | +# else | |
104 | +extern int unsetenv (const char *); | |
105 | +# endif | |
106 | +# endif | |
107 | + | |
108 | +/* Call the underlying unsetenv, in case there is hidden bookkeeping | |
109 | + that needs updating beyond just modifying environ. */ | |
110 | +int | |
111 | +rpl_unsetenv (const char *name) | |
112 | +{ | |
113 | + int result = 0; | |
114 | + if (!name || !*name || strchr (name, '=')) | |
115 | + { | |
116 | + errno = EINVAL; | |
117 | + return -1; | |
118 | + } | |
119 | + while (getenv (name)) | |
120 | +# if !VOID_UNSETENV | |
121 | + result = | |
122 | +# endif | |
123 | + unsetenv (name); | |
124 | + return result; | |
125 | +} | |
126 | + | |
127 | +#endif /* HAVE_UNSETENV */ |
@@ -46,12 +46,14 @@ IMPORTED_GNULIB_MODULES="\ | ||
46 | 46 | rawmemchr \ |
47 | 47 | readlink \ |
48 | 48 | rename \ |
49 | + setenv \ | |
49 | 50 | signal-h \ |
50 | 51 | strchrnul \ |
51 | 52 | strstr \ |
52 | 53 | strtok_r \ |
53 | 54 | sys_stat \ |
54 | 55 | unistd \ |
56 | + unsetenv \ | |
55 | 57 | update-copyright \ |
56 | 58 | wchar \ |
57 | 59 | wctype-h \ |