summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extmod/extmod.mk2
-rw-r--r--lib/embed/__errno.c13
-rw-r--r--ports/esp32/mphalport.c7
-rw-r--r--ports/esp8266/Makefile1
-rw-r--r--ports/esp8266/esp_mphal.c5
-rw-r--r--py/stream.c12
6 files changed, 20 insertions, 20 deletions
diff --git a/extmod/extmod.mk b/extmod/extmod.mk
index 69d8cfad3..e312acba8 100644
--- a/extmod/extmod.mk
+++ b/extmod/extmod.mk
@@ -47,7 +47,7 @@ CFLAGS_MOD += -DMICROPY_PY_USSL=1
ifeq ($(MICROPY_SSL_AXTLS),1)
CFLAGS_MOD += -DMICROPY_SSL_AXTLS=1 -I$(TOP)/lib/axtls/ssl -I$(TOP)/lib/axtls/crypto -I$(TOP)/extmod/axtls-include
AXTLS_DIR = lib/axtls
-$(BUILD)/$(AXTLS_DIR)/%.o: CFLAGS += -Wno-all -Wno-unused-parameter -Wno-uninitialized -Wno-sign-compare -Wno-old-style-definition $(AXTLS_DEFS_EXTRA)
+$(BUILD)/$(AXTLS_DIR)/%.o: CFLAGS += -Wno-all -Wno-unused-parameter -Wno-uninitialized -Wno-sign-compare -Wno-old-style-definition -Dmp_stream_errno=errno $(AXTLS_DEFS_EXTRA)
SRC_MOD += $(addprefix $(AXTLS_DIR)/,\
ssl/asn1.c \
ssl/loader.c \
diff --git a/lib/embed/__errno.c b/lib/embed/__errno.c
new file mode 100644
index 000000000..86417a02d
--- /dev/null
+++ b/lib/embed/__errno.c
@@ -0,0 +1,13 @@
+// This file provides a version of __errno() for embedded systems that do not have one.
+// This function is needed for expressions of the form: &errno
+
+static int embed_errno;
+
+#if defined(__linux__)
+int *__errno_location(void)
+#else
+int *__errno(void)
+#endif
+{
+ return &embed_errno;
+}
diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c
index 4f7785f24..99548ad62 100644
--- a/ports/esp32/mphalport.c
+++ b/ports/esp32/mphalport.c
@@ -195,13 +195,6 @@ void mp_hal_delay_us(uint32_t us) {
}
}
-/*
-extern int mp_stream_errno;
-int *__errno() {
- return &mp_stream_errno;
-}
-*/
-
// Wake up the main task if it is sleeping
void mp_hal_wake_main_task_from_isr(void) {
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
diff --git a/ports/esp8266/Makefile b/ports/esp8266/Makefile
index 85a04c070..7fb1bc43c 100644
--- a/ports/esp8266/Makefile
+++ b/ports/esp8266/Makefile
@@ -120,6 +120,7 @@ EXTMOD_SRC_C = $(addprefix extmod/,\
)
LIB_SRC_C = $(addprefix lib/,\
+ embed/__errno.c \
libc/string0.c \
libm/math.c \
libm/fmodf.c \
diff --git a/ports/esp8266/esp_mphal.c b/ports/esp8266/esp_mphal.c
index 8859046d7..20d0557d6 100644
--- a/ports/esp8266/esp_mphal.c
+++ b/ports/esp8266/esp_mphal.c
@@ -206,8 +206,3 @@ int ets_esf_free_bufs(int idx) {
}
return cnt;
}
-
-extern int mp_stream_errno;
-int *__errno() {
- return &mp_stream_errno;
-}
diff --git a/py/stream.c b/py/stream.c
index e6ffd3e2b..dce64a44d 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -503,14 +503,12 @@ 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;
+#include <errno.h>
ssize_t mp_stream_posix_write(void *stream, const void *buf, size_t len) {
mp_obj_base_t *o = stream;
const mp_stream_p_t *stream_p = o->type->protocol;
- mp_uint_t out_sz = stream_p->write(MP_OBJ_FROM_PTR(stream), buf, len, &mp_stream_errno);
+ mp_uint_t out_sz = stream_p->write(MP_OBJ_FROM_PTR(stream), buf, len, &errno);
if (out_sz == MP_STREAM_ERROR) {
return -1;
} else {
@@ -521,7 +519,7 @@ ssize_t mp_stream_posix_write(void *stream, const void *buf, size_t len) {
ssize_t mp_stream_posix_read(void *stream, void *buf, size_t len) {
mp_obj_base_t *o = stream;
const mp_stream_p_t *stream_p = o->type->protocol;
- mp_uint_t out_sz = stream_p->read(MP_OBJ_FROM_PTR(stream), buf, len, &mp_stream_errno);
+ mp_uint_t out_sz = stream_p->read(MP_OBJ_FROM_PTR(stream), buf, len, &errno);
if (out_sz == MP_STREAM_ERROR) {
return -1;
} else {
@@ -535,7 +533,7 @@ off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence) {
struct mp_stream_seek_t seek_s;
seek_s.offset = offset;
seek_s.whence = whence;
- mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &mp_stream_errno);
+ mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &errno);
if (res == MP_STREAM_ERROR) {
return -1;
}
@@ -545,7 +543,7 @@ off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence) {
int mp_stream_posix_fsync(void *stream) {
mp_obj_base_t *o = stream;
const mp_stream_p_t *stream_p = o->type->protocol;
- mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_FLUSH, 0, &mp_stream_errno);
+ mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_FLUSH, 0, &errno);
if (res == MP_STREAM_ERROR) {
return -1;
}