From d51107927d53a80835195ba1ac97048c203f05f2 Mon Sep 17 00:00:00 2001 From: Nikita Nazarenko Date: Wed, 10 Dec 2014 13:31:35 +0300 Subject: [PATCH] unix: add unlink function to os module --- unix/modos.c | 13 +++++++++++++ unix/qstrdefsport.h | 1 + 2 files changed, 14 insertions(+) diff --git a/unix/modos.c b/unix/modos.c index 712c528b4d..b9a2810ba9 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -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); diff --git a/unix/qstrdefsport.h b/unix/qstrdefsport.h index dcc57da7e1..fca5793c01 100644 --- a/unix/qstrdefsport.h +++ b/unix/qstrdefsport.h @@ -36,6 +36,7 @@ Q(flush) Q(_os) Q(stat) +Q(unlink) Q(ffi) Q(ffimod)