File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / libiconv / srcm4 / setenv.m4
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 13:38:46 2021 UTC (3 years, 3 months ago) by misho
Branches: libiconv, MAIN
CVS tags: v1_16p0, HEAD
libiconv 1.16

    1: # setenv.m4 serial 28
    2: dnl Copyright (C) 2001-2004, 2006-2019 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* | gnu*) gl_cv_func_setenv_works="guessing yes" ;;
   40:                         # Guess yes on musl systems.
   41:          *-musl*)       gl_cv_func_setenv_works="guessing yes" ;;
   42:                         # If we don't know, assume the worst.
   43:          *)             gl_cv_func_setenv_works="guessing no" ;;
   44:        esac
   45:       ])])
   46:     case "$gl_cv_func_setenv_works" in
   47:       *yes) ;;
   48:       *)
   49:         REPLACE_SETENV=1
   50:         ;;
   51:     esac
   52:   fi
   53: ])
   54: 
   55: # Like gl_FUNC_SETENV, except prepare for separate compilation
   56: # (no REPLACE_SETENV, no AC_LIBOBJ).
   57: AC_DEFUN([gl_FUNC_SETENV_SEPARATE],
   58: [
   59:   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
   60:   AC_CHECK_DECLS_ONCE([setenv])
   61:   if test $ac_cv_have_decl_setenv = no; then
   62:     HAVE_DECL_SETENV=0
   63:   fi
   64:   AC_CHECK_FUNCS_ONCE([setenv])
   65:   gl_PREREQ_SETENV
   66: ])
   67: 
   68: AC_DEFUN([gl_FUNC_UNSETENV],
   69: [
   70:   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
   71:   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   72:   AC_CHECK_DECLS_ONCE([unsetenv])
   73:   if test $ac_cv_have_decl_unsetenv = no; then
   74:     HAVE_DECL_UNSETENV=0
   75:   fi
   76:   AC_CHECK_FUNCS([unsetenv])
   77:   if test $ac_cv_func_unsetenv = no; then
   78:     HAVE_UNSETENV=0
   79:   else
   80:     HAVE_UNSETENV=1
   81:     dnl Some BSDs return void, failing to do error checking.
   82:     AC_CACHE_CHECK([for unsetenv() return type], [gt_cv_func_unsetenv_ret],
   83:       [AC_COMPILE_IFELSE(
   84:          [AC_LANG_PROGRAM(
   85:             [[
   86: #undef _BSD
   87: #define _BSD 1 /* unhide unsetenv declaration in OSF/1 5.1 <stdlib.h> */
   88: #include <stdlib.h>
   89: extern
   90: #ifdef __cplusplus
   91: "C"
   92: #endif
   93: int unsetenv (const char *name);
   94:             ]],
   95:             [[]])],
   96:          [gt_cv_func_unsetenv_ret='int'],
   97:          [gt_cv_func_unsetenv_ret='void'])])
   98:     if test $gt_cv_func_unsetenv_ret = 'void'; then
   99:       AC_DEFINE([VOID_UNSETENV], [1], [Define to 1 if unsetenv returns void
  100:        instead of int.])
  101:       REPLACE_UNSETENV=1
  102:     fi
  103: 
  104:     dnl Solaris 10 unsetenv does not remove all copies of a name.
  105:     dnl Haiku alpha 2 unsetenv gets confused by assignment to environ.
  106:     dnl OpenBSD 4.7 unsetenv("") does not fail.
  107:     AC_CACHE_CHECK([whether unsetenv obeys POSIX],
  108:       [gl_cv_func_unsetenv_works],
  109:       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
  110:        #include <stdlib.h>
  111:        #include <errno.h>
  112:        extern char **environ;
  113:       ]], [[
  114:        char entry1[] = "a=1";
  115:        char entry2[] = "b=2";
  116:        char *env[] = { entry1, entry2, NULL };
  117:        if (putenv ((char *) "a=1")) return 1;
  118:        if (putenv (entry2)) return 2;
  119:        entry2[0] = 'a';
  120:        unsetenv ("a");
  121:        if (getenv ("a")) return 3;
  122:        if (!unsetenv ("") || errno != EINVAL) return 4;
  123:        entry2[0] = 'b';
  124:        environ = env;
  125:        if (!getenv ("a")) return 5;
  126:        entry2[0] = 'a';
  127:        unsetenv ("a");
  128:        if (getenv ("a")) return 6;
  129:       ]])],
  130:       [gl_cv_func_unsetenv_works=yes], [gl_cv_func_unsetenv_works=no],
  131:       [case "$host_os" in
  132:                  # Guess yes on glibc systems.
  133:          *-gnu*) gl_cv_func_unsetenv_works="guessing yes" ;;
  134:                  # If we don't know, assume the worst.
  135:          *)      gl_cv_func_unsetenv_works="guessing no" ;;
  136:        esac
  137:       ])])
  138:     case "$gl_cv_func_unsetenv_works" in
  139:       *yes) ;;
  140:       *)
  141:         REPLACE_UNSETENV=1
  142:         ;;
  143:     esac
  144:   fi
  145: ])
  146: 
  147: # Prerequisites of lib/setenv.c.
  148: AC_DEFUN([gl_PREREQ_SETENV],
  149: [
  150:   AC_REQUIRE([AC_FUNC_ALLOCA])
  151:   AC_REQUIRE([gl_ENVIRON])
  152:   AC_CHECK_HEADERS_ONCE([unistd.h])
  153:   AC_CHECK_HEADERS([search.h])
  154:   AC_CHECK_FUNCS([tsearch])
  155: ])
  156: 
  157: # Prerequisites of lib/unsetenv.c.
  158: AC_DEFUN([gl_PREREQ_UNSETENV],
  159: [
  160:   AC_REQUIRE([gl_ENVIRON])
  161:   AC_CHECK_HEADERS_ONCE([unistd.h])
  162: ])

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>