summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/vfs_fat_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'extmod/vfs_fat_file.c')
-rw-r--r--extmod/vfs_fat_file.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index 23e5aa10ff..cbd013f160 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -103,22 +103,9 @@ STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t siz
}
-STATIC mp_obj_t file_obj_close(mp_obj_t self_in) {
- pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in);
- // if fs==NULL then the file is closed and in that case this method is a no-op
- if (self->fp.obj.fs != NULL) {
- FRESULT res = f_close(&self->fp);
- if (res != FR_OK) {
- mp_raise_OSError(fresult_to_errno_table[res]);
- }
- }
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(file_obj_close_obj, file_obj_close);
-
STATIC mp_obj_t file_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
- return file_obj_close(args[0]);
+ return mp_stream_close(args[0]);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(file_obj___exit___obj, 4, 4, file_obj___exit__);
@@ -153,6 +140,17 @@ STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
}
return 0;
+ } else if (request == MP_STREAM_CLOSE) {
+ // if fs==NULL then the file is closed and in that case this method is a no-op
+ if (self->fp.obj.fs != NULL) {
+ FRESULT res = f_close(&self->fp);
+ if (res != FR_OK) {
+ *errcode = fresult_to_errno_table[res];
+ return MP_STREAM_ERROR;
+ }
+ }
+ return 0;
+
} else {
*errcode = MP_EINVAL;
return MP_STREAM_ERROR;
@@ -234,10 +232,10 @@ STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_readlines), MP_ROM_PTR(&mp_stream_unbuffered_readlines_obj) },
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
{ MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj) },
- { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&file_obj_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_stream_close_obj) },
{ MP_ROM_QSTR(MP_QSTR_seek), MP_ROM_PTR(&mp_stream_seek_obj) },
{ MP_ROM_QSTR(MP_QSTR_tell), MP_ROM_PTR(&mp_stream_tell_obj) },
- { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&file_obj_close_obj) },
+ { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_stream_close_obj) },
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&file_obj___exit___obj) },
};