MCPcopy Create free account
hub / github.com/F-Stack/f-stack / getenv_bool

Function getenv_bool

freebsd/kern/kern_environment.c:945–972  ·  view source on GitHub ↗

* Return a boolean value from an environment variable. This can be in * numerical or string form, i.e. "1" or "true". */

Source from the content-addressed store, hash-verified

943 * numerical or string form, i.e. "1" or "true".
944 */
945int
946getenv_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.

Callers 2

getenv_is_trueFunction · 0.85
getenv_is_falseFunction · 0.85

Calls 5

strcmpFunction · 0.85
strcasecmpFunction · 0.85
kern_getenvFunction · 0.70
printfFunction · 0.70
freeenvFunction · 0.70

Tested by

no test coverage detected