diff options
| author | iabdalkader <i.abdalkader@gmail.com> | 2023-11-20 14:24:04 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-03-15 18:11:28 +1100 |
| commit | 85028aadab6763a0d899e71f54643840d9f8546d (patch) | |
| tree | 6a6e1a60b307fd183a0b3200ca2ea13240d21d3e /py/stream.c | |
| parent | 61ee59ad8917d64f4f4a0e7a261fd838c5724014 (diff) | |
py/stream: Add mp_stream_seek() helper function.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Diffstat (limited to 'py/stream.c')
| -rw-r--r-- | py/stream.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/py/stream.c b/py/stream.c index aa905ca8c..e008fb999 100644 --- a/py/stream.c +++ b/py/stream.c @@ -82,6 +82,18 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode return done; } +mp_uint_t mp_stream_seek(mp_obj_t stream, mp_off_t offset, int whence, int *errcode) { + struct mp_stream_seek_t seek_s; + seek_s.offset = offset; + seek_s.whence = whence; + const mp_stream_p_t *stream_p = mp_get_stream(stream); + mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, errcode); + if (res == MP_STREAM_ERROR) { + return -1; + } + return seek_s.offset; +} + const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) { const mp_obj_type_t *type = mp_obj_get_type(self_in); if (MP_OBJ_TYPE_HAS_SLOT(type, protocol)) { |
