aboutsummaryrefslogtreecommitdiff
path: root/py/stream.c
diff options
context:
space:
mode:
authorblmorris <bryan.morrissey@gmail.com>2015-08-04 19:45:30 -0400
committerDamien George <damien.p.george@gmail.com>2015-08-13 22:56:32 +0100
commitbdd78c31b68db5323796d93e0a17159806ce10fc (patch)
tree882f4679c6d8867584564a87162d954790981b58 /py/stream.c
parentc39093d801b8fb50c9af48902e9bb5faa9ab1e8b (diff)
py: Add stream_tell method, and use for unix and stmhal file tell.
Diffstat (limited to 'py/stream.c')
-rw-r--r--py/stream.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/py/stream.c b/py/stream.c
index 258f916e0..ba672ce2c 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -26,6 +26,7 @@
*/
#include <string.h>
+#include <unistd.h>
#include "py/nlr.h"
#include "py/objstr.h"
@@ -400,6 +401,14 @@ STATIC mp_obj_t stream_seek(mp_uint_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_seek_obj, 2, 3, stream_seek);
+STATIC mp_obj_t stream_tell(mp_obj_t self) {
+ mp_obj_t offset = MP_OBJ_NEW_SMALL_INT(0);
+ mp_obj_t whence = MP_OBJ_NEW_SMALL_INT(SEEK_CUR);
+ const mp_obj_t args[3] = {self, offset, whence};
+ return stream_seek(3, args);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_tell_obj, stream_tell);
+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj, 1, 2, stream_read);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_readinto_obj, 2, 3, stream_readinto);
MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_readall_obj, stream_readall);