unix/modos: Add mkdir().

Dependency of upip.
This commit is contained in:
Paul Sokolovsky 2015-11-13 22:26:10 +02:00
parent d8557834c0
commit 27dafa5ed5
2 changed files with 11 additions and 0 deletions

View File

@ -141,6 +141,15 @@ STATIC mp_obj_t mod_os_getenv(mp_obj_t var_in) {
} }
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);
STATIC mp_obj_t mod_os_mkdir(mp_obj_t path_in) {
// TODO: Accept mode param
const char *path = mp_obj_str_get_str(path_in);
int r = mkdir(path, 0777);
RAISE_ERRNO(r, errno);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_mkdir_obj, mod_os_mkdir);
STATIC const mp_map_elem_t mp_module_os_globals_table[] = { 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___name__), MP_OBJ_NEW_QSTR(MP_QSTR__os) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&mod_os_stat_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&mod_os_stat_obj },
@ -150,6 +159,7 @@ STATIC const mp_map_elem_t mp_module_os_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_system), (mp_obj_t)&mod_os_system_obj }, { 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_unlink),(mp_obj_t)&mod_os_unlink_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_getenv),(mp_obj_t)&mod_os_getenv_obj}, { MP_OBJ_NEW_QSTR(MP_QSTR_getenv),(mp_obj_t)&mod_os_getenv_obj},
{ MP_OBJ_NEW_QSTR(MP_QSTR_mkdir),(mp_obj_t)&mod_os_mkdir_obj},
}; };
STATIC MP_DEFINE_CONST_DICT(mp_module_os_globals, mp_module_os_globals_table); STATIC MP_DEFINE_CONST_DICT(mp_module_os_globals, mp_module_os_globals_table);

View File

@ -42,6 +42,7 @@ Q(statvfs)
Q(system) Q(system)
Q(unlink) Q(unlink)
Q(getenv) Q(getenv)
Q(mkdir)
Q(ffi) Q(ffi)
Q(ffimod) Q(ffimod)