diff options
author | Damien George <damien.p.george@gmail.com> | 2020-03-18 17:47:15 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-03-18 21:01:07 +1100 |
commit | 2cdf1d25f59409b6130c0e8b6cf50300aed2d7e6 (patch) | |
tree | 762d210ad4a7c51903498bc0a2c3b885059e778f /ports/unix/main.c | |
parent | 68b1bc2042f8e5dcdfbe12c5b0dace0b174f6911 (diff) |
unix: Remove custom file implementation to use extmod's VFS POSIX one.
The implementation in extmod/vfs_posix_file.c is now equivalent to that in
ports/unix/file.c, so remove the latter and use the former instead.
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) { |