diff --git a/arch/arm/src/stm32/stm32_comp.c b/arch/arm/src/stm32/stm32_comp.c index ada2600421..b46b678f94 100644 --- a/arch/arm/src/stm32/stm32_comp.c +++ b/arch/arm/src/stm32/stm32_comp.c @@ -1069,7 +1069,6 @@ FAR struct comp_dev_s* stm32_compinitialize(int intf) if (ret < 0) { aerr("ERROR: Failed to initialize COMP%d: %d\n", intf, ret); - errno = -ret; return NULL; } diff --git a/arch/arm/src/stm32/stm32_hrtim.c b/arch/arm/src/stm32/stm32_hrtim.c index af1c032c38..09da49edf9 100644 --- a/arch/arm/src/stm32/stm32_hrtim.c +++ b/arch/arm/src/stm32/stm32_hrtim.c @@ -5313,7 +5313,6 @@ FAR struct hrtim_dev_s* stm32_hrtiminitialize(void) if (ret < 0) { tmrerr("ERROR: Failed to initialize HRTIM1: %d\n", ret); - errno = -ret; return NULL; } diff --git a/arch/arm/src/stm32/stm32_opamp.c b/arch/arm/src/stm32/stm32_opamp.c index e79e8ed806..e839bba863 100644 --- a/arch/arm/src/stm32/stm32_opamp.c +++ b/arch/arm/src/stm32/stm32_opamp.c @@ -1402,7 +1402,6 @@ FAR struct opamp_dev_s* stm32_opampinitialize(int intf) if (ret < 0) { aerr("ERROR: Failed to initialize OPAMP%d: %d\n", intf, ret); - errno = -ret; return NULL; } diff --git a/arch/arm/src/stm32f7/stm32_dma2d.c b/arch/arm/src/stm32f7/stm32_dma2d.c index f0ec212339..8e6276484e 100644 --- a/arch/arm/src/stm32f7/stm32_dma2d.c +++ b/arch/arm/src/stm32f7/stm32_dma2d.c @@ -2261,7 +2261,6 @@ FAR struct dma2d_layer_s *stm32_dma2dinitltdc(FAR struct stm32_ltdc_s *layer) { lcderr("ERROR: Returning -EINVAL, unsupported pixel format: %d\n", layer->vinfo.fmt); - errno = -EINVAL; return NULL; } diff --git a/binfmt/libelf/libelf_init.c b/binfmt/libelf/libelf_init.c index 7307261df6..3e09a6676a 100644 --- a/binfmt/libelf/libelf_init.c +++ b/binfmt/libelf/libelf_init.c @@ -101,7 +101,7 @@ static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo, ret = stat(filename, &buf); if (ret < 0) { - int errval = errno; + int errval = get_errno(); berr("Failed to stat file: %d\n", errval); return -errval; } @@ -165,7 +165,7 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo) loadinfo->filfd = open(filename, O_RDONLY); if (loadinfo->filfd < 0) { - int errval = errno; + int errval = get_errno(); berr("Failed to open ELF binary %s: %d\n", filename, errval); return -errval; } diff --git a/binfmt/libelf/libelf_read.c b/binfmt/libelf/libelf_read.c index 490ba1fdd9..a240e107fb 100644 --- a/binfmt/libelf/libelf_read.c +++ b/binfmt/libelf/libelf_read.c @@ -127,7 +127,7 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer, rpos = lseek(loadinfo->filfd, offset, SEEK_SET); if (rpos != offset) { - int errval = errno; + int errval = get_errno(); berr("Failed to seek to position %lu: %d\n", (unsigned long)offset, errval); return -errval; diff --git a/binfmt/libnxflat/libnxflat_init.c b/binfmt/libnxflat/libnxflat_init.c index eff6cd8b29..d3f48c0073 100644 --- a/binfmt/libnxflat/libnxflat_init.c +++ b/binfmt/libnxflat/libnxflat_init.c @@ -111,7 +111,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo) loadinfo->filfd = open(filename, O_RDONLY); if (loadinfo->filfd < 0) { - int errval = errno; + int errval = get_errno(); berr("Failed to open NXFLAT binary %s: %d\n", filename, errval); return -errval; } diff --git a/binfmt/libnxflat/libnxflat_read.c b/binfmt/libnxflat/libnxflat_read.c index 720f725679..09016f5d3d 100644 --- a/binfmt/libnxflat/libnxflat_read.c +++ b/binfmt/libnxflat/libnxflat_read.c @@ -131,7 +131,7 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, rpos = lseek(loadinfo->filfd, offset, SEEK_SET); if (rpos != offset) { - int errval = errno; + int errval = get_errno(); berr("Failed to seek to position %d: %d\n", offset, errval); return -errval; } diff --git a/configs/sama5d4-ek/src/at25_main.c b/configs/sama5d4-ek/src/at25_main.c index 699f613b10..2d07927ee3 100644 --- a/configs/sama5d4-ek/src/at25_main.c +++ b/configs/sama5d4-ek/src/at25_main.c @@ -144,7 +144,7 @@ int at25_main(int argc, char *argv) fd = open(g_at25dev, O_WRONLY); if (fd < 0) { - int errcode = errno; + int errcode = get_errno(); fprintf(stderr, "ERROR: Failed to open %s: %d\n", g_at25dev, errcode); return EXIT_FAILURE; } @@ -205,7 +205,7 @@ int at25_main(int argc, char *argv) nwritten = write(fd, src, memoutstream.public.nput); if (nwritten <= 0) { - int errcode = errno; + int errcode = get_errno(); if (errno != EINTR) { fprintf(stderr, "ERROR: Write failed: %d\n", errcode); @@ -235,7 +235,7 @@ int at25_main(int argc, char *argv) fd = open(g_at25dev, O_RDONLY); if (fd < 0) { - int errcode = errno; + int errcode = get_errno(); fprintf(stderr, "ERROR: Failed to open %s: %d\n", g_at25dev, errcode); return EXIT_FAILURE; } @@ -254,7 +254,7 @@ int at25_main(int argc, char *argv) nread = read(fd, g_iobuffer, rdsize); if (nread <= 0) { - int errcode = errno; + int errcode = get_errno(); if (errno != EINTR) { fprintf(stderr, "ERROR: Read failed: %d\n", errcode); diff --git a/drivers/net/telnet.c b/drivers/net/telnet.c index 9dbded1e1e..6c849826ef 100644 --- a/drivers/net/telnet.c +++ b/drivers/net/telnet.c @@ -863,7 +863,7 @@ static int telnet_session(FAR struct telnet_session_s *session) priv->td_minor); ret = stat(session->ts_devpath, &statbuf); - DEBUGASSERT(ret >= 0 || errno == ENOENT); + DEBUGASSERT(ret >= 0 || get_errno() == ENOENT); } while (ret >= 0 && start != g_telnet_common.tc_minor); diff --git a/graphics/nxmu/nx_start.c b/graphics/nxmu/nx_start.c index cfa39cc523..348e8c09d7 100644 --- a/graphics/nxmu/nx_start.c +++ b/graphics/nxmu/nx_start.c @@ -190,7 +190,7 @@ int nx_start(void) CONFIG_NXSTART_SERVERSTACK, nx_server, NULL); if (server < 0) { - int errcode = errno; + int errcode = get_errno(); DEBUGASSERT(errcode > 0); gerr("ERROR: Failed to create nx_server kernel thread: %d\n", errcode); diff --git a/libc/modlib/modlib_init.c b/libc/modlib/modlib_init.c index 964272ca0a..a8f10118e0 100644 --- a/libc/modlib/modlib_init.c +++ b/libc/modlib/modlib_init.c @@ -98,7 +98,7 @@ static inline int modlib_filelen(FAR struct mod_loadinfo_s *loadinfo, ret = stat(filename, &buf); if (ret < 0) { - int errval = errno; + int errval = get_errno(); serr("ERROR: Failed to stat file: %d\n", errval); return -errval; } @@ -163,7 +163,7 @@ int modlib_initialize(FAR const char *filename, loadinfo->filfd = open(filename, O_RDONLY); if (loadinfo->filfd < 0) { - int errval = errno; + int errval = get_errno(); serr("ERROR: Failed to open ELF binary %s: %d\n", filename, errval); return -errval; } diff --git a/libc/modlib/modlib_read.c b/libc/modlib/modlib_read.c index 169d581429..00402ffcae 100644 --- a/libc/modlib/modlib_read.c +++ b/libc/modlib/modlib_read.c @@ -121,7 +121,7 @@ int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, rpos = lseek(loadinfo->filfd, offset, SEEK_SET); if (rpos != offset) { - int errval = errno; + int errval = get_errno(); serr("ERROR: Failed to seek to position %lu: %d\n", (unsigned long)offset, errval); return -errval; diff --git a/libc/netdb/lib_dnsaddserver.c b/libc/netdb/lib_dnsaddserver.c index 3efbeb9ca0..21de6bcbaa 100644 --- a/libc/netdb/lib_dnsaddserver.c +++ b/libc/netdb/lib_dnsaddserver.c @@ -90,7 +90,7 @@ int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) stream = fopen(CONFIG_NETDB_RESOLVCONF_PATH, "at"); if (stream == NULL) { - int errcode = errno; + int errcode = get_errno(); nerr("ERROR: Failed to open %s: %d\n", CONFIG_NETDB_RESOLVCONF_PATH, errcode); DEBUGASSERT(errcode > 0); diff --git a/libc/netdb/lib_dnsforeach.c b/libc/netdb/lib_dnsforeach.c index cc34b1658f..ab02f85a0b 100644 --- a/libc/netdb/lib_dnsforeach.c +++ b/libc/netdb/lib_dnsforeach.c @@ -104,7 +104,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg) stream = fopen(CONFIG_NETDB_RESOLVCONF_PATH, "rb"); if (stream == NULL) { - int errcode = errno; + int errcode = get_errno(); nerr("ERROR: Failed to open %s: %d\n", CONFIG_NETDB_RESOLVCONF_PATH, errcode); DEBUGASSERT(errcode > 0); diff --git a/libc/netdb/lib_gethostbyaddrr.c b/libc/netdb/lib_gethostbyaddrr.c index 53e91fda34..8366425b16 100644 --- a/libc/netdb/lib_gethostbyaddrr.c +++ b/libc/netdb/lib_gethostbyaddrr.c @@ -263,7 +263,7 @@ int lib_hostfile_lookup(FAR const void *addr, socklen_t len, int type, stream = fopen(CONFIG_NETDB_HOSTCONF_PATH, "r"); if (stream == NULL) { - int errcode = errno; + int errcode = get_errno(); nerr("ERROR: Failed to open the hosts file %s: %d\n", CONFIG_NETDB_HOSTCONF_PATH, errcode); diff --git a/libc/netdb/lib_gethostbynamer.c b/libc/netdb/lib_gethostbynamer.c index 8ad93ac6f3..d1a2e5fb2d 100644 --- a/libc/netdb/lib_gethostbynamer.c +++ b/libc/netdb/lib_gethostbynamer.c @@ -597,7 +597,7 @@ static int lib_hostfile_lookup(FAR const char *name, FAR struct hostent *host, stream = fopen(CONFIG_NETDB_HOSTCONF_PATH, "r"); if (stream == NULL) { - int errcode = errno; + int errcode = get_errno(); nerr("ERROR: Failed to open the hosts file %s: %d\n", CONFIG_NETDB_HOSTCONF_PATH, errcode); diff --git a/libc/pthread/pthread_setcancelstate.c b/libc/pthread/pthread_setcancelstate.c index e81a4440f7..457d26f1ab 100644 --- a/libc/pthread/pthread_setcancelstate.c +++ b/libc/pthread/pthread_setcancelstate.c @@ -85,7 +85,7 @@ int pthread_setcancelstate(int state, FAR int *oldstate) ret = task_setcancelstate(state, oldstate); if (ret < 0) { - ret = errno; + ret = get_errno(); } return ret; diff --git a/libc/pthread/pthread_setcanceltype.c b/libc/pthread/pthread_setcanceltype.c index 583376dfcc..590fa03b8c 100644 --- a/libc/pthread/pthread_setcanceltype.c +++ b/libc/pthread/pthread_setcanceltype.c @@ -85,7 +85,7 @@ int pthread_setcanceltype(int type, FAR int *oldtype) ret = task_setcanceltype(type, oldtype); if (ret < 0) { - ret = errno; + ret = get_errno(); } return ret; diff --git a/libc/stdio/lib_fclose.c b/libc/stdio/lib_fclose.c index 022d7bde8e..374e9f4e53 100644 --- a/libc/stdio/lib_fclose.c +++ b/libc/stdio/lib_fclose.c @@ -89,7 +89,7 @@ int fclose(FAR FILE *stream) if ((stream->fs_oflags & O_WROK) != 0) { ret = lib_fflush(stream, true); - errcode = errno; + errcode = get_errno(); } /* Close the underlying file descriptor and save the return status */ @@ -103,7 +103,7 @@ int fclose(FAR FILE *stream) if (ret == OK) { ret = status; - errcode = errno; + errcode = get_errno(); } } diff --git a/libc/stdlib/lib_wctomb.c b/libc/stdlib/lib_wctomb.c index cef60ad149..f60f347829 100644 --- a/libc/stdlib/lib_wctomb.c +++ b/libc/stdlib/lib_wctomb.c @@ -66,7 +66,7 @@ int wctomb(FAR char *s, wchar_t wc) if ((size_t) wc >= 0x100) { - errno = EILSEQ; + set_errno(EILSEQ); return -1; } diff --git a/libc/time/lib_localtime.c b/libc/time/lib_localtime.c index ac5cd64f64..f1fc6ae083 100644 --- a/libc/time/lib_localtime.c +++ b/libc/time/lib_localtime.c @@ -2374,7 +2374,7 @@ static time_t time1(FAR struct tm *const tmp, if (tmp == NULL) { - errno = EINVAL; + set_errno(EINVAL); return -1; } diff --git a/libc/wqueue/work_signal.c b/libc/wqueue/work_signal.c index da8b174cd5..53fc8f829d 100644 --- a/libc/wqueue/work_signal.c +++ b/libc/wqueue/work_signal.c @@ -98,7 +98,7 @@ int work_signal(int qid) ret = kill(g_usrwork.pid, SIGWORK); if (ret < 0) { - int errcode = errno; + int errcode = get_errno(); ret = -errcode; } } diff --git a/libc/wqueue/work_usrthread.c b/libc/wqueue/work_usrthread.c index 17d3b10f25..5e919d8e0a 100644 --- a/libc/wqueue/work_usrthread.c +++ b/libc/wqueue/work_usrthread.c @@ -360,7 +360,7 @@ int work_usrstart(void) DEBUGASSERT(g_usrwork.pid > 0); if (g_usrwork.pid < 0) { - int errcode = errno; + int errcode = get_errno(); DEBUGASSERT(errcode > 0); return -errcode; } diff --git a/mm/mm_heap/mm_sem.c b/mm/mm_heap/mm_sem.c index fae3b27867..51eda272a5 100644 --- a/mm/mm_heap/mm_sem.c +++ b/mm/mm_heap/mm_sem.c @@ -200,7 +200,7 @@ void mm_takesemaphore(FAR struct mm_heap_s *heap) #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) DEBUGASSERT(ret == -EINTR); #else - int errcode = errno; + int errcode = get_errno(); DEBUGASSERT(errcode == EINTR); ret = -errcode; #endif diff --git a/net/route/net_fileroute.c b/net/route/net_fileroute.c index 32074efd85..8cbdd517ce 100644 --- a/net/route/net_fileroute.c +++ b/net/route/net_fileroute.c @@ -170,7 +170,7 @@ int net_routesize(FAR const char *path, size_t entrysize) * created yet? */ - errcode = errno; + errcode = get_errno(); if (errcode == ENOENT) { /* The routing table file has not been created. Return size zero. */ diff --git a/sched/wqueue/kwork_hpthread.c b/sched/wqueue/kwork_hpthread.c index 8a3d3f0e88..59aa0391be 100644 --- a/sched/wqueue/kwork_hpthread.c +++ b/sched/wqueue/kwork_hpthread.c @@ -162,7 +162,7 @@ int work_hpstart(void) DEBUGASSERT(pid > 0); if (pid < 0) { - int errcode = errno; + int errcode = get_errno(); DEBUGASSERT(errcode > 0); serr("ERROR: kthread_create failed: %d\n", errcode); diff --git a/sched/wqueue/kwork_lpthread.c b/sched/wqueue/kwork_lpthread.c index 4b6b3ee997..daebd137ad 100644 --- a/sched/wqueue/kwork_lpthread.c +++ b/sched/wqueue/kwork_lpthread.c @@ -209,7 +209,7 @@ int work_lpstart(void) DEBUGASSERT(pid > 0); if (pid < 0) { - int errcode = errno; + int errcode = get_errno(); DEBUGASSERT(errcode > 0); serr("ERROR: kthread_create %d failed: %d\n", wndx, errcode);