Commit d8557834 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

unix/modos: Add getenv().

Dependency of upip.
parent a01f6c9a
......@@ -30,6 +30,7 @@
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "py/mpconfig.h"
#include "py/nlr.h"
......@@ -134,6 +135,12 @@ STATIC mp_obj_t mod_os_system(mp_obj_t cmd_in) {
}
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));
return mp_obj_new_str(s, strlen(s), false);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_obj, mod_os_getenv);
STATIC const mp_map_elem_t mp_module_os_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR__os) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&mod_os_stat_obj },
......@@ -142,6 +149,7 @@ STATIC const mp_map_elem_t mp_module_os_globals_table[] = {
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_system), (mp_obj_t)&mod_os_system_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_unlink),(mp_obj_t)&mod_os_unlink_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_getenv),(mp_obj_t)&mod_os_getenv_obj},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_os_globals, mp_module_os_globals_table);
......
......@@ -41,6 +41,7 @@ Q(statvfs)
#endif
Q(system)
Q(unlink)
Q(getenv)
Q(ffi)
Q(ffimod)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment