diff options
| author | Damien George <damien.p.george@gmail.com> | 2018-07-03 13:02:12 +1000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2018-07-03 13:04:29 +1000 |
| commit | a3c3dbd9559523937267fe5a24d86417e909ada7 (patch) | |
| tree | 4024da0d17c50e34e5d609fc153deec8c596c206 /extmod/vfs.c | |
| parent | 349d8e13242d1ec098bb4fd35e61439851d46f91 (diff) | |
extmod/vfs: Support opening a file descriptor (int) with VfsPosix.
Fixes issue #3865.
Diffstat (limited to 'extmod/vfs.c')
| -rw-r--r-- | extmod/vfs.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/extmod/vfs.c b/extmod/vfs.c index 77531b874..fd7f2a4fe 100644 --- a/extmod/vfs.c +++ b/extmod/vfs.c @@ -38,6 +38,10 @@ #include "extmod/vfs_fat.h" #endif +#if MICROPY_VFS_POSIX +#include "extmod/vfs_posix.h" +#endif + // For mp_vfs_proxy_call, the maximum number of additional args that can be passed. // A fixed maximum size is used to avoid the need for a costly variable array. #define PROXY_MAX_ARGS (2) @@ -264,6 +268,13 @@ mp_obj_t mp_vfs_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + #if MICROPY_VFS_POSIX + // If the file is an integer then delegate straight to the POSIX handler + if (MP_OBJ_IS_SMALL_INT(args[ARG_file].u_obj)) { + return mp_vfs_posix_file_open(&mp_type_textio, args[ARG_file].u_obj, args[ARG_mode].u_obj); + } + #endif + mp_vfs_mount_t *vfs = lookup_path(args[ARG_file].u_obj, &args[ARG_file].u_obj); return mp_vfs_proxy_call(vfs, MP_QSTR_open, 2, (mp_obj_t*)&args); } |
