unix/modos: getenv(): Handle non-existing envvar correctly.

This commit is contained in:
Paul Sokolovsky 2015-11-14 17:12:04 +02:00
parent 16d42368a6
commit ec314c951d
1 changed files with 3 additions and 0 deletions

View File

@ -137,6 +137,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_system_obj, mod_os_system);
STATIC mp_obj_t mod_os_getenv(mp_obj_t var_in) {
const char *s = getenv(mp_obj_str_get_str(var_in));
if (s == NULL) {
return mp_const_none;
}
return mp_obj_new_str(s, strlen(s), false);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_obj, mod_os_getenv);