unix: add unlink function to os module

This commit is contained in:
Nikita Nazarenko 2014-12-10 13:31:35 +03:00 committed by Damien George
parent 4140e19c8a
commit d51107927d
2 changed files with 14 additions and 0 deletions

View File

@ -65,9 +65,22 @@ STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_stat_obj, mod_os_stat);
STATIC mp_obj_t mod_os_unlink(mp_obj_t path_in) {
mp_uint_t len;
const char *path = mp_obj_str_get_data(path_in, &len);
int r = unlink(path);
RAISE_ERRNO(r, errno);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_unlink_obj, mod_os_unlink);
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 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_unlink),(mp_obj_t)&mod_os_unlink_obj},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_os_globals, mp_module_os_globals_table);

View File

@ -36,6 +36,7 @@ Q(flush)
Q(_os)
Q(stat)
Q(unlink)
Q(ffi)
Q(ffimod)