Skip to content
Snippets Groups Projects
Commit ec314c95 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

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

parent 16d42368
No related branches found
No related tags found
No related merge requests found
...@@ -137,6 +137,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_system_obj, mod_os_system); ...@@ -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) { STATIC mp_obj_t mod_os_getenv(mp_obj_t var_in) {
const char *s = getenv(mp_obj_str_get_str(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); return mp_obj_new_str(s, strlen(s), false);
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_obj, mod_os_getenv); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_obj, mod_os_getenv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment