diff options
author | Damien George <damien.p.george@gmail.com> | 2014-07-27 22:38:58 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-07-27 22:38:58 +0100 |
commit | adf0f2ae1a3debf8465ece7e065ddba2d4032e8c (patch) | |
tree | 090c7544536b130b47e30f8834d7450272dfb54a /stmhal/pybstdio.c | |
parent | 05c255f039b5c0fbdcb0754748fd5d36135acfd9 (diff) | |
download | micropython-adf0f2ae1a3debf8465ece7e065ddba2d4032e8c.tar.gz micropython-adf0f2ae1a3debf8465ece7e065ddba2d4032e8c.zip |
py: Change stream protocol API: fns return uint; is_text for text.
Diffstat (limited to 'stmhal/pybstdio.c')
-rw-r--r-- | stmhal/pybstdio.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c index 9846ce0453..88f47d1b44 100644 --- a/stmhal/pybstdio.c +++ b/stmhal/pybstdio.c @@ -27,6 +27,7 @@ #include <stdio.h> #include <stdint.h> #include <string.h> +#include <errno.h> #include "mpconfig.h" #include "misc.h" @@ -109,7 +110,7 @@ void stdio_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, print(env, "<io.FileIO %d>", self->fd); } -STATIC mp_int_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { pyb_stdio_obj_t *self = self_in; if (self->fd == STDIO_FD_IN) { for (uint i = 0; i < size; i++) { @@ -119,23 +120,21 @@ STATIC mp_int_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *err } ((byte*)buf)[i] = c; } - *errcode = 0; return size; } else { - *errcode = 1; - return 0; + *errcode = EPERM; + return MP_STREAM_ERROR; } } -STATIC mp_int_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { pyb_stdio_obj_t *self = self_in; if (self->fd == STDIO_FD_OUT || self->fd == STDIO_FD_ERR) { stdout_tx_strn_cooked(buf, size); - *errcode = 0; return size; } else { - *errcode = 1; - return 0; + *errcode = EPERM; + return MP_STREAM_ERROR; } } @@ -162,6 +161,7 @@ STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table); STATIC const mp_stream_p_t stdio_obj_stream_p = { .read = stdio_read, .write = stdio_write, + .is_text = true, }; STATIC const mp_obj_type_t stdio_obj_type = { |