diff options
Diffstat (limited to 'py')
-rw-r--r-- | py/mpconfig.h | 6 | ||||
-rw-r--r-- | py/stream.c | 4 | ||||
-rw-r--r-- | py/stream.h | 2 |
3 files changed, 11 insertions, 1 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h index edf6e71d0e..890e072ab5 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -522,6 +522,12 @@ typedef double mp_float_t; #define MICROPY_STREAMS_NON_BLOCK (0) #endif +// Whether to provide stream functions with POSIX-like signatures +// (useful for porting existing libraries to MicroPython). +#ifndef MICROPY_STREAMS_POSIX_API +#define MICROPY_STREAMS_POSIX_API (0) +#endif + // Whether to call __init__ when importing builtin modules for the first time #ifndef MICROPY_MODULE_BUILTIN_INIT #define MICROPY_MODULE_BUILTIN_INIT (0) diff --git a/py/stream.c b/py/stream.c index d426973e83..473eb96904 100644 --- a/py/stream.c +++ b/py/stream.c @@ -511,6 +511,7 @@ STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj, 2, 3, stream_ioctl); +#if MICROPY_STREAMS_POSIX_API /* * POSIX-like functions * @@ -519,7 +520,6 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj, 2, 3, stream_ioctl); * POSIX-compatible software to work with MicroPython streams. */ - // errno-like variable. If any of the functions below returned with error // status, this variable will contain error no. int mp_stream_errno; @@ -568,3 +568,5 @@ int mp_stream_posix_fsync(mp_obj_t stream) { } return res; } + +#endif diff --git a/py/stream.h b/py/stream.h index 8dd6898873..33d85e823c 100644 --- a/py/stream.h +++ b/py/stream.h @@ -84,11 +84,13 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf, mp_uint_t size, int *errcode, void mp_stream_write_adaptor(void *self, const char *buf, size_t len); +#if MICROPY_STREAMS_POSIX_API // Functions with POSIX-compatible signatures ssize_t mp_stream_posix_write(mp_obj_t stream, const void *buf, size_t len); ssize_t mp_stream_posix_read(mp_obj_t stream, void *buf, size_t len); off_t mp_stream_posix_lseek(mp_obj_t stream, off_t offset, int whence); int mp_stream_posix_fsync(mp_obj_t stream); +#endif #if MICROPY_STREAMS_NON_BLOCK #define mp_is_nonblocking_error(errno) ((errno) == EAGAIN || (errno) == EWOULDBLOCK) |