Skip to content

Commit d511079

Browse files
Nikita Nazarenkodpgeorge
authored andcommitted
unix: add unlink function to os module
1 parent 4140e19 commit d511079

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

unix/modos.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,22 @@ STATIC mp_obj_t mod_os_stat(mp_obj_t path_in) {
6565
}
6666
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_stat_obj, mod_os_stat);
6767

68+
STATIC mp_obj_t mod_os_unlink(mp_obj_t path_in) {
69+
mp_uint_t len;
70+
const char *path = mp_obj_str_get_data(path_in, &len);
71+
72+
int r = unlink(path);
73+
74+
RAISE_ERRNO(r, errno);
75+
76+
return mp_const_none;
77+
}
78+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_unlink_obj, mod_os_unlink);
79+
6880
STATIC const mp_map_elem_t mp_module_os_globals_table[] = {
6981
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR__os) },
7082
{ MP_OBJ_NEW_QSTR(MP_QSTR_stat), (mp_obj_t)&mod_os_stat_obj },
83+
{ MP_OBJ_NEW_QSTR(MP_QSTR_unlink),(mp_obj_t)&mod_os_unlink_obj},
7184
};
7285

7386
STATIC MP_DEFINE_CONST_DICT(mp_module_os_globals, mp_module_os_globals_table);

unix/qstrdefsport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Q(flush)
3636

3737
Q(_os)
3838
Q(stat)
39+
Q(unlink)
3940

4041
Q(ffi)
4142
Q(ffimod)

0 commit comments

Comments
 (0)