unix/modos: Add getenv().

Dependency of upip.
This commit is contained in:
Paul Sokolovsky 2015-11-13 21:29:18 +02:00
parent a01f6c9ae7
commit d8557834c0
2 changed files with 9 additions and 0 deletions

View File

@ -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);

View File

@ -41,6 +41,7 @@ Q(statvfs)
#endif
Q(system)
Q(unlink)
Q(getenv)
Q(ffi)
Q(ffimod)