diff options
Diffstat (limited to 'ports/unix/main.c')
-rw-r--r-- | ports/unix/main.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ports/unix/main.c b/ports/unix/main.c index cab3f3873..903fa40ac 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -717,6 +717,24 @@ uint mp_import_stat(const char *path) { } return MP_IMPORT_STAT_NO_EXIST; } + +#if MICROPY_PY_IO +// Factory function for I/O stream classes, only needed if generic VFS subsystem isn't used. +// Note: buffering and encoding are currently ignored. +mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kwargs) { + enum { ARG_file, ARG_mode }; + STATIC const mp_arg_t allowed_args[] = { + { MP_QSTR_file, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE} }, + { MP_QSTR_mode, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_QSTR(MP_QSTR_r)} }, + { MP_QSTR_buffering, MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_encoding, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kwargs, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + return mp_vfs_posix_file_open(&mp_type_textio, args[ARG_file].u_obj, args[ARG_mode].u_obj); +} +MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); +#endif #endif void nlr_jump_fail(void *val) { |