* Return a boolean value from an environment variable. This can be in * numerical or string form, i.e. "1" or "true". */
| 943 | * numerical or string form, i.e. "1" or "true". |
| 944 | */ |
| 945 | int |
| 946 | getenv_bool(const char *name, bool *data) |
| 947 | { |
| 948 | char *val; |
| 949 | int ret = 0; |
| 950 | |
| 951 | if (name == NULL) |
| 952 | return (0); |
| 953 | |
| 954 | val = kern_getenv(name); |
| 955 | if (val == NULL) |
| 956 | return (0); |
| 957 | |
| 958 | if ((strcmp(val, "1") == 0) || (strcasecmp(val, "true") == 0)) { |
| 959 | *data = true; |
| 960 | ret = 1; |
| 961 | } else if ((strcmp(val, "0") == 0) || (strcasecmp(val, "false") == 0)) { |
| 962 | *data = false; |
| 963 | ret = 1; |
| 964 | } else { |
| 965 | /* Spit out a warning for malformed boolean variables. */ |
| 966 | printf("Environment variable %s has non-boolean value \"%s\"\n", |
| 967 | name, val); |
| 968 | } |
| 969 | freeenv(val); |
| 970 | |
| 971 | return (ret); |
| 972 | } |
| 973 | |
| 974 | /* |
| 975 | * Wrapper around getenv_bool to easily check for true. |
no test coverage detected