From 4c560a1107cfb28020afcc348077edcbf3bea7e6 Mon Sep 17 00:00:00 2001 From: wangmingrong1 Date: Tue, 5 Nov 2024 16:43:46 +0800 Subject: [PATCH] libc: modify open,close... to _NX_OPEN,_NX_CLOSE Signed-off-by: wangmingrong1 --- libs/libc/aio/aio_return.c | 3 ++- libs/libc/aio/lio_listio.c | 5 +++-- libs/libc/dirent/lib_closedir.c | 6 ++++-- libs/libc/dirent/lib_dirfd.c | 4 +++- libs/libc/dirent/lib_fdopendir.c | 8 +++++--- libs/libc/dirent/lib_nftw.c | 4 +++- libs/libc/dirent/lib_opendir.c | 6 ++++-- libs/libc/dirent/lib_readdir.c | 6 ++++-- libs/libc/dirent/lib_readdirr.c | 2 +- libs/libc/dirent/lib_rewinddir.c | 4 +++- libs/libc/dirent/lib_scandir.c | 10 ++++++---- libs/libc/dirent/lib_seekdir.c | 4 +++- libs/libc/dirent/lib_telldir.c | 4 +++- libs/libc/dlfcn/lib_dladdr.c | 4 +++- libs/libc/eventfd/lib_eventfd.c | 7 +++++-- libs/libc/gdbstub/lib_gdbstub.c | 3 ++- libs/libc/grp/lib_getgrbuf.c | 4 +++- libs/libc/inttypes/lib_strtoimax.c | 6 ++++-- libs/libc/inttypes/lib_strtoumax.c | 6 ++++-- libs/libc/locale/lib_catalog.c | 16 +++++++++------- libs/libc/locale/lib_gettext.c | 14 ++++++++------ libs/libc/locale/lib_iconv.c | 8 +++++--- libs/libc/lzf/lzf_d.c | 17 ++++++++++------- libs/libc/misc/lib_fchmodat.c | 4 +++- libs/libc/misc/lib_fdsan.c | 4 +++- libs/libc/misc/lib_fstatat.c | 4 +++- libs/libc/misc/lib_glob.c | 4 +++- libs/libc/misc/lib_memfd.c | 6 ++++-- libs/libc/misc/lib_mkdirat.c | 4 +++- libs/libc/misc/lib_mkfifo.c | 4 ++-- libs/libc/misc/lib_mknod.c | 8 +++++--- libs/libc/misc/lib_ncompress.c | 10 ++++++---- libs/libc/misc/lib_openat.c | 6 ++++-- libs/libc/misc/lib_utimensat.c | 4 +++- libs/libc/modlib/modlib_gethandle.c | 3 ++- libs/libc/modlib/modlib_getsymbol.c | 5 +++-- libs/libc/modlib/modlib_insert.c | 5 +++-- libs/libc/modlib/modlib_remove.c | 3 ++- libs/libc/net/lib_getifaddrs.c | 7 ++++--- libs/libc/net/lib_indextoname.c | 5 +++-- libs/libc/net/lib_inetntop.c | 3 ++- libs/libc/net/lib_inetpton.c | 4 +++- libs/libc/net/lib_nameindex.c | 4 +++- libs/libc/net/lib_nametoindex.c | 5 +++-- libs/libc/netdb/lib_dnsbind.c | 3 ++- libs/libc/netdb/lib_dnsquery.c | 5 +++-- libs/libc/netdb/lib_rexec.c | 21 +++++++++++---------- libs/libc/pwd/lib_getspnamr.c | 8 +++++--- libs/libc/sched/clock_getres.c | 3 ++- libs/libc/sched/sched_getprioritymax.c | 3 ++- libs/libc/sched/task_setcancelstate.c | 3 ++- libs/libc/semaphore/sem_clockwait.c | 5 +++-- libs/libc/semaphore/sem_close.c | 4 ++-- libs/libc/semaphore/sem_destroy.c | 5 +++-- libs/libc/semaphore/sem_getvalue.c | 3 ++- libs/libc/semaphore/sem_init.c | 5 +++-- libs/libc/semaphore/sem_open.c | 7 ++++--- libs/libc/semaphore/sem_post.c | 5 +++-- libs/libc/semaphore/sem_setprotocol.c | 3 ++- libs/libc/semaphore/sem_trywait.c | 5 +++-- libs/libc/semaphore/sem_unlink.c | 3 ++- libs/libc/semaphore/sem_wait.c | 5 +++-- libs/libc/signal/sig_addset.c | 4 +++- libs/libc/signal/sig_altstack.c | 6 ++++-- libs/libc/signal/sig_delset.c | 4 +++- libs/libc/signal/sig_ismember.c | 3 ++- libs/libc/signal/sig_killpg.c | 4 +++- libs/libc/signal/sig_psignal.c | 4 +++- libs/libc/signal/sig_set.c | 4 +++- libs/libc/signal/sig_signal.c | 4 +++- libs/libc/stdio/lib_fclose.c | 6 ++++-- libs/libc/stdio/lib_fflush.c | 4 ++-- libs/libc/stdio/lib_fgetpos.c | 4 +++- libs/libc/stdio/lib_fgetwc.c | 4 +++- libs/libc/stdio/lib_fileno.c | 2 +- libs/libc/stdio/lib_fmemopen.c | 12 +++++++----- libs/libc/stdio/lib_fopen.c | 10 ++++++---- libs/libc/stdio/lib_fopencookie.c | 4 +++- libs/libc/stdio/lib_freopen.c | 8 +++++--- libs/libc/stdio/lib_fseeko.c | 4 +++- libs/libc/stdio/lib_fsetpos.c | 4 +++- libs/libc/stdio/lib_ftello.c | 4 +++- libs/libc/stdio/lib_getchar.c | 6 ++++-- libs/libc/stdio/lib_getdelim.c | 4 +++- libs/libc/stdio/lib_libdgets.c | 4 +++- libs/libc/stdio/lib_libfwrite.c | 4 ++-- libs/libc/stdio/lib_libvscanf.c | 10 ++++++---- libs/libc/stdio/lib_open_memstream.c | 10 ++++++---- libs/libc/stdio/lib_putchar.c | 6 ++++-- libs/libc/stdio/lib_putwchar.c | 4 +++- libs/libc/stdio/lib_rdflush_unlocked.c | 4 +++- libs/libc/stdio/lib_renameat.c | 4 +++- libs/libc/stdio/lib_rewind.c | 4 +++- libs/libc/stdio/lib_setvbuf.c | 4 ++-- libs/libc/stdio/lib_tempnam.c | 4 +++- libs/libc/stdio/lib_tmpfile.c | 4 +++- libs/libc/stdlib/lib_mkstemp.c | 4 +++- libs/libc/stdlib/lib_mktemp.c | 5 +++-- libs/libc/stdlib/lib_openpty.c | 11 ++++++----- libs/libc/stdlib/lib_reallocarray.c | 4 +++- libs/libc/stdlib/lib_realpath.c | 20 +++++++++++--------- libs/libc/stdlib/lib_strtol.c | 6 ++++-- libs/libc/stdlib/lib_strtold.c | 11 ++++++----- libs/libc/stdlib/lib_strtoll.c | 6 ++++-- libs/libc/stdlib/lib_strtoul.c | 6 ++++-- libs/libc/stdlib/lib_strtoull.c | 6 ++++-- libs/libc/termios/lib_ttyname.c | 4 +++- libs/libc/time/lib_gettimeofday.c | 3 ++- libs/libc/time/lib_localtime.c | 4 ++-- libs/libc/time/lib_nanosleep.c | 4 +++- libs/libc/time/lib_settimeofday.c | 3 ++- libs/libc/unistd/lib_access.c | 4 +++- libs/libc/unistd/lib_chdir.c | 4 +++- libs/libc/unistd/lib_crypt_r.c | 8 +++++--- libs/libc/unistd/lib_daemon.c | 6 ++++-- libs/libc/unistd/lib_execl.c | 6 ++++-- libs/libc/unistd/lib_execle.c | 6 ++++-- libs/libc/unistd/lib_fchownat.c | 4 +++- libs/libc/unistd/lib_flock.c | 4 +++- libs/libc/unistd/lib_getcwd.c | 8 +++++--- libs/libc/unistd/lib_getentropy.c | 4 +++- libs/libc/unistd/lib_getpass.c | 8 +++++--- libs/libc/unistd/lib_getpgid.c | 4 +++- libs/libc/unistd/lib_getpriority.c | 5 +++-- libs/libc/unistd/lib_getrlimit.c | 4 +++- libs/libc/unistd/lib_getrusage.c | 4 +++- libs/libc/unistd/lib_linkat.c | 4 +++- libs/libc/unistd/lib_lockf.c | 6 ++++-- libs/libc/unistd/lib_nice.c | 4 +++- libs/libc/unistd/lib_pathconf.c | 4 +++- libs/libc/unistd/lib_posix_fallocate.c | 4 +++- libs/libc/unistd/lib_readlinkat.c | 4 +++- libs/libc/unistd/lib_setegid.c | 4 +++- libs/libc/unistd/lib_seteuid.c | 4 +++- libs/libc/unistd/lib_setgid.c | 4 +++- libs/libc/unistd/lib_setuid.c | 4 +++- libs/libc/unistd/lib_symlinkat.c | 4 +++- libs/libc/unistd/lib_sysconf.c | 3 ++- libs/libc/unistd/lib_times.c | 4 +++- libs/libc/unistd/lib_truncate.c | 6 ++++-- libs/libc/unistd/lib_unlinkat.c | 4 +++- libs/libc/unistd/lib_utimes.c | 4 +++- libs/libc/userfs/lib_userfs.c | 3 ++- libs/libc/wchar/lib_mbrtowc.c | 4 +++- libs/libc/wchar/lib_wcrtomb.c | 4 +++- 145 files changed, 507 insertions(+), 267 deletions(-) diff --git a/libs/libc/aio/aio_return.c b/libs/libc/aio/aio_return.c index f3a8f5192a0f6..3e6831fc269ef 100644 --- a/libs/libc/aio/aio_return.c +++ b/libs/libc/aio/aio_return.c @@ -25,6 +25,7 @@ ****************************************************************************/ #include +#include #include #include @@ -98,7 +99,7 @@ ssize_t aio_return(FAR struct aiocb *aiocbp) DEBUGASSERT(aiocbp); if (aiocbp->aio_result < 0) { - set_errno(-aiocbp->aio_result); + _NX_SETERRNO(-aiocbp->aio_result); return ERROR; } diff --git a/libs/libc/aio/lio_listio.c b/libs/libc/aio/lio_listio.c index d3d93c086a7cf..0d00679b643f5 100644 --- a/libs/libc/aio/lio_listio.c +++ b/libs/libc/aio/lio_listio.c @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -515,7 +516,7 @@ int lio_listio(int mode, FAR struct aiocb * const list[], int nent, if (mode != LIO_WAIT && mode != LIO_NOWAIT) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } @@ -688,7 +689,7 @@ int lio_listio(int mode, FAR struct aiocb * const list[], int nent, sched_unlock(); if (ret < 0) { - set_errno(retcode); + _NX_SETERRNO(retcode); return ERROR; } diff --git a/libs/libc/dirent/lib_closedir.c b/libs/libc/dirent/lib_closedir.c index c4c04cb1c6597..207b9e2e379f3 100644 --- a/libs/libc/dirent/lib_closedir.c +++ b/libs/libc/dirent/lib_closedir.c @@ -33,6 +33,8 @@ #include +#include + #include "libc.h" /**************************************************************************** @@ -69,7 +71,7 @@ int closedir(FAR DIR *dirp) if (dirp == NULL) { - set_errno(EBADF); + _NX_SETERRNO(EBADF); return -1; } @@ -78,7 +80,7 @@ int closedir(FAR DIR *dirp) (uintptr_t)dirp); ret = android_fdsan_close_with_tag(dirp->fd, tag); #else - ret = close(dirp->fd); + ret = _NX_CLOSE(dirp->fd); #endif lib_free(dirp); diff --git a/libs/libc/dirent/lib_dirfd.c b/libs/libc/dirent/lib_dirfd.c index 717cebec8e409..754858f89fb05 100644 --- a/libs/libc/dirent/lib_dirfd.c +++ b/libs/libc/dirent/lib_dirfd.c @@ -27,6 +27,8 @@ #include #include +#include + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -62,6 +64,6 @@ int dirfd(FAR DIR *dirp) return dirp->fd; } - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } diff --git a/libs/libc/dirent/lib_fdopendir.c b/libs/libc/dirent/lib_fdopendir.c index 6176e13d5bb06..0f553d2c475aa 100644 --- a/libs/libc/dirent/lib_fdopendir.c +++ b/libs/libc/dirent/lib_fdopendir.c @@ -33,6 +33,8 @@ # include #endif +#include + #include "libc.h" /**************************************************************************** @@ -69,7 +71,7 @@ FAR DIR *fdopendir(int fd) FAR DIR *dir; int ret; - ret = fstat(fd, &st); + ret = _NX_STAT(fd, &st); if (ret == -1) { return NULL; @@ -77,14 +79,14 @@ FAR DIR *fdopendir(int fd) if (!S_ISDIR(st.st_mode)) { - set_errno(ENOTDIR); + _NX_SETERRNO(ENOTDIR); return NULL; } dir = lib_malloc(sizeof(*dir)); if (dir == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return NULL; } diff --git a/libs/libc/dirent/lib_nftw.c b/libs/libc/dirent/lib_nftw.c index 0a70f708d0434..1a9e1698da3e6 100644 --- a/libs/libc/dirent/lib_nftw.c +++ b/libs/libc/dirent/lib_nftw.c @@ -32,6 +32,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -198,7 +200,7 @@ do_nftw(FAR char *path, nftw_cb_t fn, int fdlimit, int flags, int level) if (strlen(de->d_name) > PATH_MAX - j) { - set_errno(ENAMETOOLONG); + _NX_SETERRNO(ENAMETOOLONG); closedir(dir); return -1; } diff --git a/libs/libc/dirent/lib_opendir.c b/libs/libc/dirent/lib_opendir.c index dad8372ac76fb..d4a8f619d08ab 100644 --- a/libs/libc/dirent/lib_opendir.c +++ b/libs/libc/dirent/lib_opendir.c @@ -34,6 +34,8 @@ #include +#include + #include "libc.h" /**************************************************************************** @@ -78,11 +80,11 @@ FAR DIR *opendir(FAR const char *path) dir = lib_malloc(sizeof(*dir)); if (dir == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return NULL; } - fd = open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC); + fd = _NX_OPEN(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC); if (fd < 0) { lib_free(dir); diff --git a/libs/libc/dirent/lib_readdir.c b/libs/libc/dirent/lib_readdir.c index 80c587ea8d63c..dba9696ddbd0c 100644 --- a/libs/libc/dirent/lib_readdir.c +++ b/libs/libc/dirent/lib_readdir.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,11 +65,11 @@ FAR struct dirent *readdir(DIR *dirp) if (!dirp) { - set_errno(EBADF); + _NX_SETERRNO(EBADF); return NULL; } - ret = read(dirp->fd, &dirp->entry, sizeof(struct dirent)); + ret = _NX_READ(dirp->fd, &dirp->entry, sizeof(struct dirent)); if (ret <= 0) { return NULL; diff --git a/libs/libc/dirent/lib_readdirr.c b/libs/libc/dirent/lib_readdirr.c index e7cbf472d322f..1baea3a5e0de1 100644 --- a/libs/libc/dirent/lib_readdirr.c +++ b/libs/libc/dirent/lib_readdirr.c @@ -76,7 +76,7 @@ int readdir_r(FAR DIR *dirp, FAR struct dirent *entry, /* NOTE: The following use or errno is *not* thread-safe */ - set_errno(0); + _NX_SETERRNO(0); tmp = readdir(dirp); if (!tmp) { diff --git a/libs/libc/dirent/lib_rewinddir.c b/libs/libc/dirent/lib_rewinddir.c index fdea97bdc4d46..1e2608f4f17f5 100644 --- a/libs/libc/dirent/lib_rewinddir.c +++ b/libs/libc/dirent/lib_rewinddir.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -60,6 +62,6 @@ void rewinddir(FAR DIR *dirp) } else { - set_errno(EBADF); + _NX_SETERRNO(EBADF); } } diff --git a/libs/libc/dirent/lib_scandir.c b/libs/libc/dirent/lib_scandir.c index c734ff1d243cb..d65a7d9fda567 100644 --- a/libs/libc/dirent/lib_scandir.c +++ b/libs/libc/dirent/lib_scandir.c @@ -31,6 +31,8 @@ #include #include +#include + #include "libc.h" /* The scandir() function is not appropriate for use within the kernel in its @@ -102,7 +104,7 @@ int scandir(FAR const char *path, FAR struct dirent ***namelist, /* opendir might have set errno. Reset to zero. */ - set_errno(0); + _NX_SETERRNO(0); for (d = readdir(dirp); d != NULL; d = readdir(dirp)) { @@ -121,7 +123,7 @@ int scandir(FAR const char *path, FAR struct dirent ***namelist, * zero. */ - set_errno(0); + _NX_SETERRNO(0); /* Grow the directory entry list, if required. */ @@ -179,7 +181,7 @@ int scandir(FAR const char *path, FAR struct dirent ***namelist, * to zero. */ - set_errno(0); + _NX_SETERRNO(0); } if (get_errno() == 0) @@ -221,7 +223,7 @@ int scandir(FAR const char *path, FAR struct dirent ***namelist, { /* Restore original errno value in case of success. */ - set_errno(errsv); + _NX_SETERRNO(errsv); } return result; diff --git a/libs/libc/dirent/lib_seekdir.c b/libs/libc/dirent/lib_seekdir.c index fd547498be8a1..6a8c9e3a4d955 100644 --- a/libs/libc/dirent/lib_seekdir.c +++ b/libs/libc/dirent/lib_seekdir.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -62,6 +64,6 @@ void seekdir(FAR DIR *dirp, off_t offset) } else { - set_errno(EBADF); + _NX_SETERRNO(EBADF); } } diff --git a/libs/libc/dirent/lib_telldir.c b/libs/libc/dirent/lib_telldir.c index 5eb840b076148..44c07525b6db5 100644 --- a/libs/libc/dirent/lib_telldir.c +++ b/libs/libc/dirent/lib_telldir.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -63,6 +65,6 @@ off_t telldir(FAR DIR *dirp) return lseek(dirp->fd, 0, SEEK_CUR); } - set_errno(EBADF); + _NX_SETERRNO(EBADF); return -1; } diff --git a/libs/libc/dlfcn/lib_dladdr.c b/libs/libc/dlfcn/lib_dladdr.c index b0ba15da86f84..4207691617146 100644 --- a/libs/libc/dlfcn/lib_dladdr.c +++ b/libs/libc/dlfcn/lib_dladdr.c @@ -29,6 +29,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -39,6 +41,6 @@ int dladdr(const FAR void *addr, FAR Dl_info *info) { - set_errno(ENOTSUP); + _NX_SETERRNO(ENOTSUP); return 0; } diff --git a/libs/libc/eventfd/lib_eventfd.c b/libs/libc/eventfd/lib_eventfd.c index 30a86253e7b21..187a4112f578e 100644 --- a/libs/libc/eventfd/lib_eventfd.c +++ b/libs/libc/eventfd/lib_eventfd.c @@ -28,17 +28,20 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ int eventfd_read(int fd, FAR eventfd_t *value) { - return read(fd, value, sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0; + return _NX_READ(fd, value, sizeof (eventfd_t)) != sizeof (eventfd_t) + ? -1 : 0; } int eventfd_write(int fd, eventfd_t value) { - return write(fd, &value, + return _NX_WRITE(fd, &value, sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0; } diff --git a/libs/libc/gdbstub/lib_gdbstub.c b/libs/libc/gdbstub/lib_gdbstub.c index 45660591f5cda..fc70e62f0e8bd 100644 --- a/libs/libc/gdbstub/lib_gdbstub.c +++ b/libs/libc/gdbstub/lib_gdbstub.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -648,7 +649,7 @@ static ssize_t gdb_hex2bin(FAR void *buf, size_t buf_len, in[pos], in[pos + 1], 0 }; - set_errno(0); + _NX_SETERRNO(0); out[pos / 2] = strtoul(ch, NULL, 16); /* Decode high nibble */ if (out[pos / 2] == 0 && get_errno()) { diff --git a/libs/libc/grp/lib_getgrbuf.c b/libs/libc/grp/lib_getgrbuf.c index 6f99916952122..ab3b66a3afe3c 100644 --- a/libs/libc/grp/lib_getgrbuf.c +++ b/libs/libc/grp/lib_getgrbuf.c @@ -31,6 +31,8 @@ #include #include +#include + #include "grp/lib_grp.h" #include "libc.h" @@ -108,7 +110,7 @@ FAR struct group *getgrbuf(gid_t gid, FAR const char *name, lib_free(g_buf); g_grp = NULL; g_buf = NULL; - set_errno(err); + _NX_SETERRNO(err); return NULL; } diff --git a/libs/libc/inttypes/lib_strtoimax.c b/libs/libc/inttypes/lib_strtoimax.c index ea4d15c6da8de..21975c3ea1b98 100644 --- a/libs/libc/inttypes/lib_strtoimax.c +++ b/libs/libc/inttypes/lib_strtoimax.c @@ -31,6 +31,8 @@ #include #include +#include + #include "libc.h" /* Current implementation depends on strtoull() and, hence, is only @@ -96,7 +98,7 @@ intmax_t strtoimax(FAR const char *nptr, FAR char **endptr, int base) if (accum > limit) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); return INTMAX_MIN; } @@ -105,7 +107,7 @@ intmax_t strtoimax(FAR const char *nptr, FAR char **endptr, int base) if (accum > INTMAX_MAX) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); return INTMAX_MAX; } } diff --git a/libs/libc/inttypes/lib_strtoumax.c b/libs/libc/inttypes/lib_strtoumax.c index d6e2240e479af..a3a101e6e804c 100644 --- a/libs/libc/inttypes/lib_strtoumax.c +++ b/libs/libc/inttypes/lib_strtoumax.c @@ -30,6 +30,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -71,7 +73,7 @@ uintmax_t strtoumax(FAR const char *nptr, FAR char **endptr, int base) if (base < 0) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return 0; } @@ -87,7 +89,7 @@ uintmax_t strtoumax(FAR const char *nptr, FAR char **endptr, int base) if (accum < prev) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); accum = UINTMAX_MAX; break; } diff --git a/libs/libc/locale/lib_catalog.c b/libs/libc/locale/lib_catalog.c index 06944e940b122..4cb83fd948b68 100644 --- a/libs/libc/locale/lib_catalog.c +++ b/libs/libc/locale/lib_catalog.c @@ -36,6 +36,8 @@ #include #include +#include + #ifdef CONFIG_LIBC_LOCALE_CATALOG /**************************************************************************** @@ -85,13 +87,13 @@ static nl_catd catmap(FAR const char *path) struct stat st; int fd; - fd = open(path, O_RDONLY | O_CLOEXEC); + fd = _NX_OPEN(path, O_RDONLY | O_CLOEXEC); if (fd < 0) { return catd; } - if (fstat(fd, &st) >= 0) + if (_NX_STAT(fd, &st) >= 0) { catd = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (catd != MAP_FAILED) @@ -102,12 +104,12 @@ static nl_catd catmap(FAR const char *path) { munmap(catd, st.st_size); catd = MAP_FAILED; - set_errno(ENOENT); + _NX_SETERRNO(ENOENT); } } } - close(fd); + _NX_CLOSE(fd); return catd; } @@ -290,7 +292,7 @@ nl_catd catopen(FAR const char *name, int oflag) } } - set_errno(ENOENT); + _NX_SETERRNO(ENOENT); return MAP_FAILED; } @@ -328,7 +330,7 @@ FAR char *catgets(nl_catd catd, int set_id, int msg_id, FAR const char *s) set = bsearch(&set_id, set, be32toh(hdr->nsets), sizeof(*set), setcmp); if (set == NULL) { - set_errno(ENOMSG); + _NX_SETERRNO(ENOMSG); return (FAR char *)s; } @@ -336,7 +338,7 @@ FAR char *catgets(nl_catd catd, int set_id, int msg_id, FAR const char *s) msg = bsearch(&msg_id, msg, be32toh(set->nmsgs), sizeof(*msg), msgcmp); if (msg == NULL) { - set_errno(ENOMSG); + _NX_SETERRNO(ENOMSG); return (FAR char *)s; } diff --git a/libs/libc/locale/lib_gettext.c b/libs/libc/locale/lib_gettext.c index 5a86302510c24..bb08284c684c1 100644 --- a/libs/libc/locale/lib_gettext.c +++ b/libs/libc/locale/lib_gettext.c @@ -40,6 +40,8 @@ #include #include +#include + #include "libc.h" #ifdef CONFIG_LIBC_LOCALE_GETTEXT @@ -129,13 +131,13 @@ static FAR void *momap(FAR const char *path, FAR size_t *size) struct stat st; int fd; - fd = open(path, O_RDONLY | O_CLOEXEC); + fd = _NX_OPEN(path, O_RDONLY | O_CLOEXEC); if (fd < 0) { return map; } - if (fstat(fd, &st) >= 0) + if (_NX_STAT(fd, &st) >= 0) { *size = st.st_size; map = mmap(NULL, *size, PROT_READ, MAP_SHARED, fd, 0); @@ -147,7 +149,7 @@ static FAR void *momap(FAR const char *path, FAR size_t *size) } } - close(fd); + _NX_CLOSE(fd); return map; } @@ -730,7 +732,7 @@ FAR char *textdomain(FAR const char *domainname) domainlen = strnlen(domainname, NAME_MAX); if (domainlen == NAME_MAX) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return NULL; } @@ -781,7 +783,7 @@ FAR char *bindtextdomain(FAR const char *domainname, { if (domainname == NULL || dirname) { - set_errno(EINVAL); /* Only support the default path */ + _NX_SETERRNO(EINVAL); /* Only support the default path */ } return NULL; @@ -819,7 +821,7 @@ FAR char *bind_textdomain_codeset(FAR const char *domainname, { if (codeset && strcasecmp(codeset, "UTF-8")) { - set_errno(EINVAL); /* Only support utf8 */ + _NX_SETERRNO(EINVAL); /* Only support utf8 */ } return NULL; diff --git a/libs/libc/locale/lib_iconv.c b/libs/libc/locale/lib_iconv.c index 9ba81c8e01fe6..37a3a4ead9bc0 100644 --- a/libs/libc/locale/lib_iconv.c +++ b/libs/libc/locale/lib_iconv.c @@ -33,6 +33,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -339,7 +341,7 @@ iconv_t iconv_open(FAR const char *to, FAR const char *from) if ((t = find_charmap(to)) == -1 || (f = find_charmap(from)) == -1 || (g_charmaps[t] >= 0330)) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return (iconv_t)-1; } @@ -356,7 +358,7 @@ iconv_t iconv_open(FAR const char *to, FAR const char *from) scd = lib_malloc(sizeof(*scd)); if (scd == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return (iconv_t)-1; } @@ -1437,7 +1439,7 @@ size_t iconv(iconv_t cd, FAR char **in, FAR size_t *inb, err = EINVAL; x = -1; end: - set_errno(err); + _NX_SETERRNO(err); return x; } diff --git a/libs/libc/lzf/lzf_d.c b/libs/libc/lzf/lzf_d.c index 5bd34812cec7c..8178f0684dcc9 100644 --- a/libs/libc/lzf/lzf_d.c +++ b/libs/libc/lzf/lzf_d.c @@ -2,7 +2,8 @@ * libs/libc/lzf/lzf_d.c * * SPDX-License-Identifier: BSD-2-Clause - * SPDX-FileCopyrightText: 2000-2010 Marc Alexander Lehmann + * SPDX-FileCopyrightText: + * 2000-2010 Marc Alexander Lehmann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -34,6 +35,8 @@ #include "lzf/lzf.h" +#include + #ifdef CONFIG_LIBC_LZF /**************************************************************************** @@ -81,14 +84,14 @@ unsigned int lzf_decompress (FAR const void *const in_data, if (op + ctrl > out_end) { - set_errno(E2BIG); + _NX_SETERRNO(E2BIG); return 0; } #if CHECK_INPUT if (ip + ctrl > in_end) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return 0; } #endif @@ -205,7 +208,7 @@ unsigned int lzf_decompress (FAR const void *const in_data, #if CHECK_INPUT if (ip >= in_end) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return 0; } @@ -216,7 +219,7 @@ unsigned int lzf_decompress (FAR const void *const in_data, #if CHECK_INPUT if (ip >= in_end) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return 0; } #endif @@ -226,13 +229,13 @@ unsigned int lzf_decompress (FAR const void *const in_data, if (op + len + 2 > out_end) { - set_errno(E2BIG); + _NX_SETERRNO(E2BIG); return 0; } if (ref < (uint8_t *)out_data) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return 0; } diff --git a/libs/libc/misc/lib_fchmodat.c b/libs/libc/misc/lib_fchmodat.c index 65186a39b042d..496a66de2379c 100644 --- a/libs/libc/misc/lib_fchmodat.c +++ b/libs/libc/misc/lib_fchmodat.c @@ -28,6 +28,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -72,7 +74,7 @@ int fchmodat(int dirfd, FAR const char *path, mode_t mode, int flags) ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/misc/lib_fdsan.c b/libs/libc/misc/lib_fdsan.c index f85dd59b34f9d..3bcc60073e81f 100644 --- a/libs/libc/misc/lib_fdsan.c +++ b/libs/libc/misc/lib_fdsan.c @@ -40,6 +40,8 @@ #include #include +#include + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -131,7 +133,7 @@ int android_fdsan_close_with_tag(int fd, uint64_t expected_tag) int ret; android_fdsan_exchange_owner_tag(fd, expected_tag, 0); - ret = close(fd); + ret = _NX_CLOSE(fd); /************************************************************************** * If we were expecting to close with a tag, abort on EBADF. diff --git a/libs/libc/misc/lib_fstatat.c b/libs/libc/misc/lib_fstatat.c index f9660719d82d7..31793c1e66558 100644 --- a/libs/libc/misc/lib_fstatat.c +++ b/libs/libc/misc/lib_fstatat.c @@ -28,6 +28,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -73,7 +75,7 @@ int fstatat(int dirfd, FAR const char *path, FAR struct stat *buf, ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/misc/lib_glob.c b/libs/libc/misc/lib_glob.c index e86811bd172ad..6c0b0cf9c0455 100644 --- a/libs/libc/misc/lib_glob.c +++ b/libs/libc/misc/lib_glob.c @@ -36,6 +36,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -359,7 +361,7 @@ static int do_glob(FAR char *buf, size_t pos, int type, FAR char *pat, return GLOB_ABORTED; } - set_errno(old_errno); + _NX_SETERRNO(old_errno); return 0; } diff --git a/libs/libc/misc/lib_memfd.c b/libs/libc/misc/lib_memfd.c index 58d1dac1d4e9d..441a033c86524 100644 --- a/libs/libc/misc/lib_memfd.c +++ b/libs/libc/misc/lib_memfd.c @@ -31,6 +31,8 @@ #include #include +#include + #if defined(CONFIG_LIBC_MEMFD_TMPFS) || defined(CONFIG_LIBC_MEMFD_SHMFS) /**************************************************************************** * Pre-processor Definitions @@ -51,7 +53,7 @@ int memfd_create(FAR const char *name, unsigned int flags) { #ifdef CONFIG_LIBC_MEMFD_ERROR - set_errno(ENOSYS); + _NX_SETERRNO(ENOSYS); return -1; #else char path[PATH_MAX]; @@ -66,7 +68,7 @@ int memfd_create(FAR const char *name, unsigned int flags) } # else mkdir(LIBC_MEM_FD_VFS_PATH, 0666); - ret = open(path, O_RDWR | flags, 0660); + ret = _NX_OPEN(path, O_RDWR | flags, 0660); if (ret >= 0) { unlink(path); diff --git a/libs/libc/misc/lib_mkdirat.c b/libs/libc/misc/lib_mkdirat.c index df306096d35fa..97be21edd4993 100644 --- a/libs/libc/misc/lib_mkdirat.c +++ b/libs/libc/misc/lib_mkdirat.c @@ -27,6 +27,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -70,7 +72,7 @@ int mkdirat(int dirfd, FAR const char *path, mode_t mode) ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/misc/lib_mkfifo.c b/libs/libc/misc/lib_mkfifo.c index 407f08ae641be..bd0cd52a79e9c 100644 --- a/libs/libc/misc/lib_mkfifo.c +++ b/libs/libc/misc/lib_mkfifo.c @@ -76,7 +76,7 @@ int mkfifo(FAR const char *pathname, mode_t mode) ret = nx_mkfifo(pathname, mode, CONFIG_DEV_FIFO_SIZE); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); ret = ERROR; } @@ -120,7 +120,7 @@ int mkfifoat(int dirfd, FAR const char *path, mode_t mode) ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/misc/lib_mknod.c b/libs/libc/misc/lib_mknod.c index afb70a6c7794d..713f2fc30dac4 100644 --- a/libs/libc/misc/lib_mknod.c +++ b/libs/libc/misc/lib_mknod.c @@ -29,6 +29,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -90,12 +92,12 @@ int mknod(FAR const char *path, mode_t mode, dev_t dev) ret = creat(path, mode & ~S_IFMT); if (ret >= 0) { - ret = close(ret); + ret = _NX_CLOSE(ret); } break; default: - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); break; } @@ -140,7 +142,7 @@ int mknodat(int dirfd, FAR const char *path, mode_t mode, dev_t dev) ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/misc/lib_ncompress.c b/libs/libc/misc/lib_ncompress.c index 683e3d331beb7..390b5c07ffd37 100644 --- a/libs/libc/misc/lib_ncompress.c +++ b/libs/libc/misc/lib_ncompress.c @@ -52,6 +52,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -485,7 +487,7 @@ void compress(int fdin, int fdout) clear_htab(); - while ((rsize = read(fdin, inbuf, IBUFSIZ)) > 0) + while ((rsize = _NX_READ(fdin, inbuf, IBUFSIZ)) > 0) { if (bytes_in == 0) { @@ -727,7 +729,7 @@ void decompress(int fdin, int fdout) bytes_out = 0; insize = 0; - while (insize < 3 && (rsize = read(fdin, inbuf + insize, IBUFSIZ)) > 0) + while (insize < 3 && (rsize = _NX_READ(fdin, inbuf + insize, IBUFSIZ)) > 0) insize += rsize; if (insize < 3 || inbuf[0] != MAGIC_1 || inbuf[1] != MAGIC_2) @@ -795,7 +797,7 @@ void decompress(int fdin, int fdout) if (insize < sizeof(inbuf) - IBUFSIZ) { - if ((rsize = read(fdin, inbuf + insize, IBUFSIZ)) < 0) + if ((rsize = _NX_READ(fdin, inbuf + insize, IBUFSIZ)) < 0) read_error(); insize += rsize; @@ -936,7 +938,7 @@ void decompress(int fdin, int fdout) } while (rsize > 0); - if (outpos > 0 && write(fdout, outbuf, outpos) != outpos) + if (outpos > 0 && _NX_WRITE(fdout, outbuf, outpos) != outpos) write_error(); } diff --git a/libs/libc/misc/lib_openat.c b/libs/libc/misc/lib_openat.c index 9c35df7fc5063..656359c1a657b 100644 --- a/libs/libc/misc/lib_openat.c +++ b/libs/libc/misc/lib_openat.c @@ -28,6 +28,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -72,7 +74,7 @@ int openat(int dirfd, FAR const char *path, int oflags, ...) ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } @@ -85,5 +87,5 @@ int openat(int dirfd, FAR const char *path, int oflags, ...) va_end(ap); } - return open(fullpath, oflags, mode); + return _NX_OPEN(fullpath, oflags, mode); } diff --git a/libs/libc/misc/lib_utimensat.c b/libs/libc/misc/lib_utimensat.c index 4c16ace45658e..a9dd43f31b2ff 100644 --- a/libs/libc/misc/lib_utimensat.c +++ b/libs/libc/misc/lib_utimensat.c @@ -28,6 +28,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -72,7 +74,7 @@ int utimensat(int dirfd, FAR const char *path, ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/modlib/modlib_gethandle.c b/libs/libc/modlib/modlib_gethandle.c index ddd7303df35e4..19a3fbca19c2b 100644 --- a/libs/libc/modlib/modlib_gethandle.c +++ b/libs/libc/modlib/modlib_gethandle.c @@ -27,6 +27,7 @@ #include #include +#include #include /**************************************************************************** @@ -70,7 +71,7 @@ FAR void *modlib_gethandle(FAR const char *name) if (modp == NULL) { berr("ERROR: Failed to find module %s\n", name); - set_errno(ENOENT); + _NX_SETERRNO(ENOENT); } modlib_registry_unlock(); diff --git a/libs/libc/modlib/modlib_getsymbol.c b/libs/libc/modlib/modlib_getsymbol.c index c73a454a109ba..07b54b77dddd3 100644 --- a/libs/libc/modlib/modlib_getsymbol.c +++ b/libs/libc/modlib/modlib_getsymbol.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -100,7 +101,7 @@ FAR const void *modlib_getsymbol(FAR void *handle, FAR const char *name) if (symbol == NULL) { berr("ERROR: Failed to find symbol in symbol \"%s\" in table\n", name); - set_errno(ENOENT); + _NX_SETERRNO(ENOENT); return NULL; } @@ -111,6 +112,6 @@ FAR const void *modlib_getsymbol(FAR void *handle, FAR const char *name) errout_with_lock: modlib_registry_unlock(); - set_errno(err); + _NX_SETERRNO(err); return NULL; } diff --git a/libs/libc/modlib/modlib_insert.c b/libs/libc/modlib/modlib_insert.c index c9faac0cdad06..02c91b8107f42 100644 --- a/libs/libc/modlib/modlib_insert.c +++ b/libs/libc/modlib/modlib_insert.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -307,7 +308,7 @@ FAR void *modlib_insert(FAR const char *filename, FAR const char *modname) if (modlib_registry_find(modname) != NULL) { modlib_registry_unlock(); - set_errno(EEXIST); + _NX_SETERRNO(EEXIST); return NULL; } #endif @@ -430,6 +431,6 @@ FAR void *modlib_insert(FAR const char *filename, FAR const char *modname) errout_with_loadinfo: modlib_uninitialize(&loadinfo); modlib_registry_unlock(); - set_errno(-ret); + _NX_SETERRNO(-ret); return NULL; } diff --git a/libs/libc/modlib/modlib_remove.c b/libs/libc/modlib/modlib_remove.c index 10db0de41981b..6b81c3d65d626 100644 --- a/libs/libc/modlib/modlib_remove.c +++ b/libs/libc/modlib/modlib_remove.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -230,6 +231,6 @@ int modlib_remove(FAR void *handle) errout_with_lock: modlib_registry_unlock(); - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/net/lib_getifaddrs.c b/libs/libc/net/lib_getifaddrs.c index 7a722e9a0deb7..1fbef6a081267 100644 --- a/libs/libc/net/lib_getifaddrs.c +++ b/libs/libc/net/lib_getifaddrs.c @@ -32,6 +32,7 @@ #include #include +#include #include #include "libc.h" @@ -122,7 +123,7 @@ int getifaddrs(FAR struct ifaddrs **addrs) if (addrs == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } @@ -271,7 +272,7 @@ int getifaddrs(FAR struct ifaddrs **addrs) #endif } - close(sockfd); + _NX_CLOSE(sockfd); return OK; err: @@ -281,6 +282,6 @@ int getifaddrs(FAR struct ifaddrs **addrs) *addrs = NULL; } - close(sockfd); + _NX_CLOSE(sockfd); return ERROR; } diff --git a/libs/libc/net/lib_indextoname.c b/libs/libc/net/lib_indextoname.c index 73d04b12cc087..1efa9f27446e7 100644 --- a/libs/libc/net/lib_indextoname.c +++ b/libs/libc/net/lib_indextoname.c @@ -30,6 +30,7 @@ #include #include +#include #include /**************************************************************************** @@ -65,11 +66,11 @@ FAR char *if_indextoname(unsigned int ifindex, FAR char *ifname) if (ioctl(sockfd, SIOCGIFNAME, (unsigned long)&req) >= 0) { strlcpy(ifname, req.ifr_name, IF_NAMESIZE); - close(sockfd); + _NX_CLOSE(sockfd); return ifname; } - close(sockfd); + _NX_CLOSE(sockfd); } return NULL; diff --git a/libs/libc/net/lib_inetntop.c b/libs/libc/net/lib_inetntop.c index dbaf10e3b512e..40326982bc70f 100644 --- a/libs/libc/net/lib_inetntop.c +++ b/libs/libc/net/lib_inetntop.c @@ -49,6 +49,7 @@ #include #include +#include #include /**************************************************************************** @@ -314,7 +315,7 @@ FAR const char *inet_ntop(int af, FAR const void *src, FAR char *dest, if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); memset(dest, 0, size); return NULL; } diff --git a/libs/libc/net/lib_inetpton.c b/libs/libc/net/lib_inetpton.c index e2ef39409a2e2..6f074bce806a9 100644 --- a/libs/libc/net/lib_inetpton.c +++ b/libs/libc/net/lib_inetpton.c @@ -53,6 +53,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -402,7 +404,7 @@ int inet_pton(int af, FAR const char *src, FAR void *dest) #endif default: - set_errno(EAFNOSUPPORT); + _NX_SETERRNO(EAFNOSUPPORT); return ERROR; } } diff --git a/libs/libc/net/lib_nameindex.c b/libs/libc/net/lib_nameindex.c index fa22eba519cf3..0001c5b6db70a 100644 --- a/libs/libc/net/lib_nameindex.c +++ b/libs/libc/net/lib_nameindex.c @@ -27,6 +27,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -66,7 +68,7 @@ FAR struct if_nameindex *if_nameindex(void) ifn = lib_malloc((sizeof(*ifn) + IF_NAMESIZE) * MAX_IFINDEX); if (ifn == NULL) { - set_errno(ENOBUFS); + _NX_SETERRNO(ENOBUFS); return NULL; } diff --git a/libs/libc/net/lib_nametoindex.c b/libs/libc/net/lib_nametoindex.c index 1e8c695f71067..0367847b8502f 100644 --- a/libs/libc/net/lib_nametoindex.c +++ b/libs/libc/net/lib_nametoindex.c @@ -30,6 +30,7 @@ #include #include +#include #include /**************************************************************************** @@ -61,11 +62,11 @@ unsigned int if_nametoindex(FAR const char *ifname) strlcpy(req.ifr_name, ifname, IF_NAMESIZE); if (ioctl(sockfd, SIOCGIFINDEX, (unsigned long)&req) >= 0) { - close(sockfd); + _NX_CLOSE(sockfd); return req.ifr_ifindex; } - close(sockfd); + _NX_CLOSE(sockfd); } return 0; diff --git a/libs/libc/netdb/lib_dnsbind.c b/libs/libc/netdb/lib_dnsbind.c index 3b8017b6d5a1e..0faf4f59f6ec2 100644 --- a/libs/libc/netdb/lib_dnsbind.c +++ b/libs/libc/netdb/lib_dnsbind.c @@ -31,6 +31,7 @@ #include #include +#include #include #include "netdb/lib_dns.h" @@ -101,7 +102,7 @@ int dns_bind(sa_family_t family, bool stream) { ret = -get_errno(); nerr("ERROR: setsockopt() failed: %d\n", ret); - close(sd); + _NX_CLOSE(sd); return ret; } diff --git a/libs/libc/netdb/lib_dnsquery.c b/libs/libc/netdb/lib_dnsquery.c index b636ef3bfc9b2..fe6474a240727 100644 --- a/libs/libc/netdb/lib_dnsquery.c +++ b/libs/libc/netdb/lib_dnsquery.c @@ -49,6 +49,7 @@ #include +#include #include #include #include @@ -912,7 +913,7 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, } } - close(sd); + _NX_CLOSE(sd); } #endif @@ -971,7 +972,7 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, } } - close(sd); + _NX_CLOSE(sd); } #endif /* CONFIG_NET_IPv4 */ diff --git a/libs/libc/netdb/lib_rexec.c b/libs/libc/netdb/lib_rexec.c index 2d23d0d7dc953..db945bacad2c7 100644 --- a/libs/libc/netdb/lib_rexec.c +++ b/libs/libc/netdb/lib_rexec.c @@ -33,6 +33,7 @@ #include #include +#include #include /**************************************************************************** @@ -68,7 +69,7 @@ int rexec_af(FAR char **ahost, int inport, FAR const char *user, if (!cmd || !ahost) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } @@ -90,14 +91,14 @@ int rexec_af(FAR char **ahost, int inport, FAR const char *user, *ahost = strdup(res->ai_canonname); if (*ahost == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); goto addr_out; } } else { *ahost = NULL; - set_errno(ENOENT); + _NX_SETERRNO(ENOENT); goto addr_out; } @@ -114,7 +115,7 @@ int rexec_af(FAR char **ahost, int inport, FAR const char *user, /* ignore second connection(fd2p always is NULL) */ - ret = write(sock, "", 1); + ret = _NX_WRITE(sock, "", 1); if (ret < 0) { goto conn_out; @@ -124,11 +125,11 @@ int rexec_af(FAR char **ahost, int inport, FAR const char *user, if (user) { - ret = write(sock, user, strlen(user) + 1); + ret = _NX_WRITE(sock, user, strlen(user) + 1); } else { - ret = write(sock, "", 1); + ret = _NX_WRITE(sock, "", 1); } if (ret < 0) @@ -140,11 +141,11 @@ int rexec_af(FAR char **ahost, int inport, FAR const char *user, if (passwd) { - ret = write(sock, passwd, strlen(passwd) + 1); + ret = _NX_WRITE(sock, passwd, strlen(passwd) + 1); } else { - ret = write(sock, "", 1); + ret = _NX_WRITE(sock, "", 1); } if (ret < 0) @@ -154,7 +155,7 @@ int rexec_af(FAR char **ahost, int inport, FAR const char *user, /* Send command */ - ret = write(sock, cmd, strlen(cmd) + 1); + ret = _NX_WRITE(sock, cmd, strlen(cmd) + 1); if (ret < 0) { goto conn_out; @@ -164,7 +165,7 @@ int rexec_af(FAR char **ahost, int inport, FAR const char *user, return sock; conn_out: - close(sock); + _NX_CLOSE(sock); sock_out: lib_free(*ahost); addr_out: diff --git a/libs/libc/pwd/lib_getspnamr.c b/libs/libc/pwd/lib_getspnamr.c index 69ee8622a2bc3..d6ba6f17450a9 100644 --- a/libs/libc/pwd/lib_getspnamr.c +++ b/libs/libc/pwd/lib_getspnamr.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -142,7 +144,7 @@ int getspnam_r(FAR const char *name, FAR struct spwd *sp, FAR char *buf, if (*name == '.' || strchr(name, '/') || l == 0) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } @@ -150,7 +152,7 @@ int getspnam_r(FAR const char *name, FAR struct spwd *sp, FAR char *buf, if (size < l + BUFFER_EXTRA) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); return -1; } @@ -170,7 +172,7 @@ int getspnam_r(FAR const char *name, FAR struct spwd *sp, FAR char *buf, if (buf[k - 1] != '\n') { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); fclose(f); return -1; } diff --git a/libs/libc/sched/clock_getres.c b/libs/libc/sched/clock_getres.c index 6d373175c6418..34aff280abb1e 100644 --- a/libs/libc/sched/clock_getres.c +++ b/libs/libc/sched/clock_getres.c @@ -32,6 +32,7 @@ #include #include +#include /**************************************************************************** * Public Functions @@ -56,7 +57,7 @@ int clock_getres(clockid_t clock_id, struct timespec *res) { default: serr("Returning ERROR\n"); - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); ret = ERROR; break; diff --git a/libs/libc/sched/sched_getprioritymax.c b/libs/libc/sched/sched_getprioritymax.c index c8db4327ce1da..65604d3804c47 100644 --- a/libs/libc/sched/sched_getprioritymax.c +++ b/libs/libc/sched/sched_getprioritymax.c @@ -29,6 +29,7 @@ #include #include +#include /**************************************************************************** * Public Functions @@ -56,7 +57,7 @@ int sched_get_priority_max(int policy) { if (policy < SCHED_OTHER || policy > SCHED_SPORADIC) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } diff --git a/libs/libc/sched/task_setcancelstate.c b/libs/libc/sched/task_setcancelstate.c index ad5cc23870f54..26378449e6a0e 100644 --- a/libs/libc/sched/task_setcancelstate.c +++ b/libs/libc/sched/task_setcancelstate.c @@ -33,6 +33,7 @@ #include #include +#include #include /**************************************************************************** @@ -121,7 +122,7 @@ int task_setcancelstate(int state, FAR int *oldstate) } else { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); ret = ERROR; } diff --git a/libs/libc/semaphore/sem_clockwait.c b/libs/libc/semaphore/sem_clockwait.c index 7d6eb730bcd6a..ddc64fbb8d33d 100644 --- a/libs/libc/semaphore/sem_clockwait.c +++ b/libs/libc/semaphore/sem_clockwait.c @@ -30,6 +30,7 @@ #include #include +#include #include /**************************************************************************** @@ -84,7 +85,7 @@ int sem_clockwait(FAR sem_t *sem, clockid_t clockid, if (sem == NULL || abstime == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } @@ -97,7 +98,7 @@ int sem_clockwait(FAR sem_t *sem, clockid_t clockid, ret = nxsem_clockwait(sem, clockid, abstime); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); ret = ERROR; } diff --git a/libs/libc/semaphore/sem_close.c b/libs/libc/semaphore/sem_close.c index 9ea59c939981d..eb6b31f53185f 100644 --- a/libs/libc/semaphore/sem_close.c +++ b/libs/libc/semaphore/sem_close.c @@ -25,7 +25,7 @@ ****************************************************************************/ #include - +#include #include #ifdef CONFIG_FS_NAMED_SEMAPHORES @@ -67,7 +67,7 @@ int sem_close(FAR sem_t *sem) ret = nxsem_close(sem); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/semaphore/sem_destroy.c b/libs/libc/semaphore/sem_destroy.c index a55c1c6889bf3..38a85c72b9774 100644 --- a/libs/libc/semaphore/sem_destroy.c +++ b/libs/libc/semaphore/sem_destroy.c @@ -28,6 +28,7 @@ #include +#include #include /**************************************************************************** @@ -66,14 +67,14 @@ int sem_destroy(FAR sem_t *sem) if (sem == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } ret = nxsem_destroy(sem); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); ret = ERROR; } diff --git a/libs/libc/semaphore/sem_getvalue.c b/libs/libc/semaphore/sem_getvalue.c index 194f5fa1ef5b9..9e1e81ad4ac91 100644 --- a/libs/libc/semaphore/sem_getvalue.c +++ b/libs/libc/semaphore/sem_getvalue.c @@ -28,6 +28,7 @@ #include +#include #include /**************************************************************************** @@ -102,7 +103,7 @@ int sem_getvalue(FAR sem_t *sem, FAR int *sval) ret = nxsem_get_value(sem, sval); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); ret = ERROR; } diff --git a/libs/libc/semaphore/sem_init.c b/libs/libc/semaphore/sem_init.c index 37facb0b1f865..27ae1295fb586 100644 --- a/libs/libc/semaphore/sem_init.c +++ b/libs/libc/semaphore/sem_init.c @@ -31,6 +31,7 @@ #include #include +#include #include /**************************************************************************** @@ -124,14 +125,14 @@ int sem_init(FAR sem_t *sem, int pshared, unsigned int value) if (sem == NULL || value > SEM_VALUE_MAX) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } ret = nxsem_init(sem, pshared, value); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); ret = ERROR; } diff --git a/libs/libc/semaphore/sem_open.c b/libs/libc/semaphore/sem_open.c index 3c51a38d0c592..d1999e5d022e0 100644 --- a/libs/libc/semaphore/sem_open.c +++ b/libs/libc/semaphore/sem_open.c @@ -31,6 +31,7 @@ #include #include +#include #include #ifdef CONFIG_FS_NAMED_SEMAPHORES @@ -94,13 +95,13 @@ FAR sem_t *sem_open(FAR const char *name, int oflags, ...) { if (strlen(name) >= PATH_MAX) { - set_errno(ENAMETOOLONG); + _NX_SETERRNO(ENAMETOOLONG); return SEM_FAILED; } if (strlen(strrchr(name, '/') + 1) >= NAME_MAX) { - set_errno(ENAMETOOLONG); + _NX_SETERRNO(ENAMETOOLONG); return SEM_FAILED; } } @@ -117,7 +118,7 @@ FAR sem_t *sem_open(FAR const char *name, int oflags, ...) errcode = nxsem_open(&sem, name, oflags, mode, value); if (errcode < 0) { - set_errno(-errcode); + _NX_SETERRNO(-errcode); return SEM_FAILED; } diff --git a/libs/libc/semaphore/sem_post.c b/libs/libc/semaphore/sem_post.c index 31a896d61c4ed..3580b0ca013de 100644 --- a/libs/libc/semaphore/sem_post.c +++ b/libs/libc/semaphore/sem_post.c @@ -28,6 +28,7 @@ #include +#include #include /**************************************************************************** @@ -71,14 +72,14 @@ int sem_post(FAR sem_t *sem) if (sem == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } ret = nxsem_post(sem); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); ret = ERROR; } diff --git a/libs/libc/semaphore/sem_setprotocol.c b/libs/libc/semaphore/sem_setprotocol.c index 775bf28dd710d..c57d19a725875 100644 --- a/libs/libc/semaphore/sem_setprotocol.c +++ b/libs/libc/semaphore/sem_setprotocol.c @@ -29,6 +29,7 @@ #include #include +#include #include #ifndef CONFIG_PRIORITY_INHERITANCE @@ -149,7 +150,7 @@ int sem_setprotocol(FAR sem_t *sem, int protocol) ret = nxsem_set_protocol(sem, protocol); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); ret = ERROR; } diff --git a/libs/libc/semaphore/sem_trywait.c b/libs/libc/semaphore/sem_trywait.c index 98603e290c9d3..1e46982cee83f 100644 --- a/libs/libc/semaphore/sem_trywait.c +++ b/libs/libc/semaphore/sem_trywait.c @@ -28,6 +28,7 @@ #include +#include #include /**************************************************************************** @@ -61,7 +62,7 @@ int sem_trywait(FAR sem_t *sem) if (sem == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } @@ -70,7 +71,7 @@ int sem_trywait(FAR sem_t *sem) ret = nxsem_trywait(sem); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); ret = ERROR; } diff --git a/libs/libc/semaphore/sem_unlink.c b/libs/libc/semaphore/sem_unlink.c index f78c14d1739c3..53e7fbd725b66 100644 --- a/libs/libc/semaphore/sem_unlink.c +++ b/libs/libc/semaphore/sem_unlink.c @@ -28,6 +28,7 @@ #include +#include #include /**************************************************************************** @@ -62,7 +63,7 @@ int sem_unlink(FAR const char *name) ret = nxsem_unlink(name); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/semaphore/sem_wait.c b/libs/libc/semaphore/sem_wait.c index 0e137411b0c1f..81339bc3e974c 100644 --- a/libs/libc/semaphore/sem_wait.c +++ b/libs/libc/semaphore/sem_wait.c @@ -29,6 +29,7 @@ #include #include +#include #include /**************************************************************************** @@ -63,7 +64,7 @@ int sem_wait(FAR sem_t *sem) if (sem == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } @@ -94,7 +95,7 @@ int sem_wait(FAR sem_t *sem) return OK; errout_with_cancelpt: - set_errno(errcode); + _NX_SETERRNO(errcode); leave_cancellation_point(); return ERROR; } diff --git a/libs/libc/signal/sig_addset.c b/libs/libc/signal/sig_addset.c index 57d00c70fb560..7405b398867d8 100644 --- a/libs/libc/signal/sig_addset.c +++ b/libs/libc/signal/sig_addset.c @@ -26,6 +26,8 @@ #include #include + +#include #include /**************************************************************************** @@ -98,7 +100,7 @@ int sigaddset(FAR sigset_t *set, int signo) ret = nxsig_addset(set, signo); if (ret < 0) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); ret = ERROR; } diff --git a/libs/libc/signal/sig_altstack.c b/libs/libc/signal/sig_altstack.c index 4f4c18fe6414e..959703d06b487 100644 --- a/libs/libc/signal/sig_altstack.c +++ b/libs/libc/signal/sig_altstack.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -54,13 +56,13 @@ int sigaltstack(FAR const stack_t *ss, FAR stack_t *oss) if (ss->ss_size < MINSIGSTKSZ) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return ERROR; } /* not support SS_ONSTACK now */ - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } diff --git a/libs/libc/signal/sig_delset.c b/libs/libc/signal/sig_delset.c index 29d6a960667aa..66c7e4dc17b4c 100644 --- a/libs/libc/signal/sig_delset.c +++ b/libs/libc/signal/sig_delset.c @@ -26,6 +26,8 @@ #include #include + +#include #include /**************************************************************************** @@ -98,7 +100,7 @@ int sigdelset(FAR sigset_t *set, int signo) ret = nxsig_delset(set, signo); if (ret < 0) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); ret = ERROR; } diff --git a/libs/libc/signal/sig_ismember.c b/libs/libc/signal/sig_ismember.c index 0b760c728c319..0af7be7562b2c 100644 --- a/libs/libc/signal/sig_ismember.c +++ b/libs/libc/signal/sig_ismember.c @@ -27,6 +27,7 @@ #include #include +#include #include /**************************************************************************** @@ -101,7 +102,7 @@ int sigismember(FAR const sigset_t *set, int signo) ret = nxsig_ismember(set, signo); if (ret < 0) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); ret = ERROR; } diff --git a/libs/libc/signal/sig_killpg.c b/libs/libc/signal/sig_killpg.c index f0c2d5008e031..9a2e8598610b8 100644 --- a/libs/libc/signal/sig_killpg.c +++ b/libs/libc/signal/sig_killpg.c @@ -27,6 +27,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -61,7 +63,7 @@ int killpg(pid_t pgrp, int signo) { if (pgrp <= CONFIG_SMP_NCPUS) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } diff --git a/libs/libc/signal/sig_psignal.c b/libs/libc/signal/sig_psignal.c index 4402f80c269e9..2ad94213b44c8 100644 --- a/libs/libc/signal/sig_psignal.c +++ b/libs/libc/signal/sig_psignal.c @@ -31,6 +31,8 @@ #include #include +#include + /* Uses streams... not available to kernel code */ #ifndef __KERNEL__ @@ -114,7 +116,7 @@ void psiginfo(FAR const siginfo_t *pinfo, FAR const char *message) { if (pinfo == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); } else { diff --git a/libs/libc/signal/sig_set.c b/libs/libc/signal/sig_set.c index ae2f23c746919..0721dacbd4f88 100644 --- a/libs/libc/signal/sig_set.c +++ b/libs/libc/signal/sig_set.c @@ -30,6 +30,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -152,6 +154,6 @@ _sa_handler_t sigset(int signo, _sa_handler_t func) return disposition; err: - set_errno(-ret); + _NX_SETERRNO(-ret); return (_sa_handler_t)SIG_ERR; } diff --git a/libs/libc/signal/sig_signal.c b/libs/libc/signal/sig_signal.c index 8ed40cf2ef2d6..a9f1d7529d7fa 100644 --- a/libs/libc/signal/sig_signal.c +++ b/libs/libc/signal/sig_signal.c @@ -30,6 +30,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -113,6 +115,6 @@ _sa_handler_t signal(int signo, _sa_handler_t func) } err: - set_errno(-ret); + _NX_SETERRNO(-ret); return (_sa_handler_t)SIG_ERR; } diff --git a/libs/libc/stdio/lib_fclose.c b/libs/libc/stdio/lib_fclose.c index cee301e1f2857..5377271434faf 100644 --- a/libs/libc/stdio/lib_fclose.c +++ b/libs/libc/stdio/lib_fclose.c @@ -36,6 +36,8 @@ # include #endif +#include + #include "libc.h" /**************************************************************************** @@ -110,7 +112,7 @@ int fclose(FAR FILE *stream) (uintptr_t)stream); status = android_fdsan_close_with_tag(fd, tag); #else - status = close(fd); + status = _NX_CLOSE(fd); #endif } @@ -148,7 +150,7 @@ int fclose(FAR FILE *stream) if (ret != OK) { - set_errno(errcode); + _NX_SETERRNO(errcode); return EOF; } diff --git a/libs/libc/stdio/lib_fflush.c b/libs/libc/stdio/lib_fflush.c index 2a7358c6d20dc..f1b80a1a4b814 100644 --- a/libs/libc/stdio/lib_fflush.c +++ b/libs/libc/stdio/lib_fflush.c @@ -79,7 +79,7 @@ int fflush_unlocked(FAR FILE *stream) * all of the buffered write data. Set the errno value. */ - set_errno(-ret); + _NX_SETERRNO(-ret); /* And return EOF on failure. */ @@ -114,7 +114,7 @@ int fflush(FAR FILE *stream) * all of the buffered write data. Set the errno value. */ - set_errno(-ret); + _NX_SETERRNO(-ret); /* And return EOF on failure. */ diff --git a/libs/libc/stdio/lib_fgetpos.c b/libs/libc/stdio/lib_fgetpos.c index f2eecfd1d1c0c..2e5bebb926b13 100644 --- a/libs/libc/stdio/lib_fgetpos.c +++ b/libs/libc/stdio/lib_fgetpos.c @@ -30,6 +30,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -58,7 +60,7 @@ int fgetpos(FAR FILE *stream, FAR fpos_t *pos) #ifdef CONFIG_DEBUG_FEATURES if (!stream || !pos) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } #endif diff --git a/libs/libc/stdio/lib_fgetwc.c b/libs/libc/stdio/lib_fgetwc.c index 5215abf3088a8..8656001cc5ba7 100644 --- a/libs/libc/stdio/lib_fgetwc.c +++ b/libs/libc/stdio/lib_fgetwc.c @@ -33,6 +33,8 @@ #include #include +#include + #ifdef CONFIG_FILE_STREAM /**************************************************************************** @@ -76,7 +78,7 @@ wint_t fgetwc_unlocked(FAR FILE *f) { if (!mbsinit(&st)) { - set_errno(EILSEQ); + _NX_SETERRNO(EILSEQ); } f->fs_flags |= __FS_FLAG_EOF; diff --git a/libs/libc/stdio/lib_fileno.c b/libs/libc/stdio/lib_fileno.c index a32e57fe6fe92..9ace72c9a2857 100644 --- a/libs/libc/stdio/lib_fileno.c +++ b/libs/libc/stdio/lib_fileno.c @@ -48,7 +48,7 @@ int fileno(FAR FILE *stream) if (ret < 0) { - set_errno(EBADF); + _NX_SETERRNO(EBADF); return ERROR; } diff --git a/libs/libc/stdio/lib_fmemopen.c b/libs/libc/stdio/lib_fmemopen.c index 846c50f4bbf00..aeb87fc0b2d26 100644 --- a/libs/libc/stdio/lib_fmemopen.c +++ b/libs/libc/stdio/lib_fmemopen.c @@ -34,6 +34,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -128,7 +130,7 @@ static off_t fmemopen_seek(FAR void *c, FAR off_t *offset, int whence) new_offset = fmemopen_cookie->pos + *offset; break; default: - set_errno(ENOTSUP); + _NX_SETERRNO(ENOTSUP); return -1; } @@ -136,7 +138,7 @@ static off_t fmemopen_seek(FAR void *c, FAR off_t *offset, int whence) if (new_offset < 0 || new_offset > fmemopen_cookie->end) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } @@ -180,7 +182,7 @@ FAR FILE *fmemopen(FAR void *buf, size_t size, FAR const char *mode) fmemopen_cookie = lib_zalloc(sizeof(struct fmemopen_cookie_s)); if (fmemopen_cookie == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return NULL; } @@ -198,7 +200,7 @@ FAR FILE *fmemopen(FAR void *buf, size_t size, FAR const char *mode) if ((oflags & O_RDWR) != O_RDWR) { lib_free(fmemopen_cookie); - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return NULL; } @@ -212,7 +214,7 @@ FAR FILE *fmemopen(FAR void *buf, size_t size, FAR const char *mode) if (fmemopen_cookie->buf == NULL) { lib_free(fmemopen_cookie); - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return NULL; } diff --git a/libs/libc/stdio/lib_fopen.c b/libs/libc/stdio/lib_fopen.c index 08812223845c8..7e9eae8b88af1 100644 --- a/libs/libc/stdio/lib_fopen.c +++ b/libs/libc/stdio/lib_fopen.c @@ -38,6 +38,8 @@ # include #endif +#include + #include "libc.h" /**************************************************************************** @@ -153,7 +155,7 @@ FAR FILE *fdopen(int fd, FAR const char *mode) return filep; errout: - set_errno(-ret); + _NX_SETERRNO(-ret); return NULL; } @@ -177,7 +179,7 @@ FAR FILE *fopen(FAR const char *path, FAR const char *mode) /* Open the file */ - fd = open(path, oflags, 0666); + fd = _NX_OPEN(path, oflags, 0666); /* If the open was successful, then call fdopen() using the file * descriptor returned by open. If open failed, then just return the @@ -193,7 +195,7 @@ FAR FILE *fopen(FAR const char *path, FAR const char *mode) * failures are reported by fdopen(). */ - close(fd); + _NX_CLOSE(fd); } } @@ -403,6 +405,6 @@ int lib_mode2oflags(FAR const char *mode) */ errout: - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } diff --git a/libs/libc/stdio/lib_fopencookie.c b/libs/libc/stdio/lib_fopencookie.c index 7efdad0d192ad..ba89c475f3450 100644 --- a/libs/libc/stdio/lib_fopencookie.c +++ b/libs/libc/stdio/lib_fopencookie.c @@ -33,6 +33,8 @@ #include #include #include + +#include #include #include "libc.h" @@ -82,7 +84,7 @@ static off_t cookie_seek_cb(FAR void *cookie, FAR off_t *offset, int whence) * possible to perform seek operations on the stream. */ - set_errno(ENOTSUP); + _NX_SETERRNO(ENOTSUP); return -1; } diff --git a/libs/libc/stdio/lib_freopen.c b/libs/libc/stdio/lib_freopen.c index 2297bfbdc06fd..69f0cf8b12dcc 100644 --- a/libs/libc/stdio/lib_freopen.c +++ b/libs/libc/stdio/lib_freopen.c @@ -31,6 +31,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -97,7 +99,7 @@ FAR FILE *freopen(FAR const char *path, FAR const char *mode, return NULL; } - fd = open(path, oflags, 0666); + fd = _NX_OPEN(path, oflags, 0666); if (fd < 0) { return NULL; @@ -120,7 +122,7 @@ FAR FILE *freopen(FAR const char *path, FAR const char *mode, /* Duplicate the new fd to the stream. */ ret = dup2(fd, fileno(stream)); - close(fd); + _NX_CLOSE(fd); if (ret < 0) { return NULL; @@ -162,6 +164,6 @@ FAR FILE *freopen(FAR const char *path, FAR const char *mode, return stream; } - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return NULL; } diff --git a/libs/libc/stdio/lib_fseeko.c b/libs/libc/stdio/lib_fseeko.c index 72002ffc41e80..8b9007114939d 100644 --- a/libs/libc/stdio/lib_fseeko.c +++ b/libs/libc/stdio/lib_fseeko.c @@ -32,6 +32,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -63,7 +65,7 @@ int fseeko(FAR FILE *stream, off_t offset, int whence) if (!stream) { - set_errno(EBADF); + _NX_SETERRNO(EBADF); return ERROR; } #endif diff --git a/libs/libc/stdio/lib_fsetpos.c b/libs/libc/stdio/lib_fsetpos.c index a0ac40ffc09a8..ed996359d0eeb 100644 --- a/libs/libc/stdio/lib_fsetpos.c +++ b/libs/libc/stdio/lib_fsetpos.c @@ -32,6 +32,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -58,7 +60,7 @@ int fsetpos(FAR FILE *stream, FAR fpos_t *pos) #ifdef CONFIG_DEBUG_FEATURES if (!stream || !pos) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } #endif diff --git a/libs/libc/stdio/lib_ftello.c b/libs/libc/stdio/lib_ftello.c index 0d4c9341f99fe..8644282456266 100644 --- a/libs/libc/stdio/lib_ftello.c +++ b/libs/libc/stdio/lib_ftello.c @@ -32,6 +32,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -105,7 +107,7 @@ off_t ftello(FAR FILE *stream) if (!stream) { - set_errno(EBADF); + _NX_SETERRNO(EBADF); return ERROR; } diff --git a/libs/libc/stdio/lib_getchar.c b/libs/libc/stdio/lib_getchar.c index 4034661d8a618..4bede7edfe9e7 100644 --- a/libs/libc/stdio/lib_getchar.c +++ b/libs/libc/stdio/lib_getchar.c @@ -27,6 +27,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -37,7 +39,7 @@ int getchar(void) return fgetc(stdin); #else unsigned char c; - return read(STDIN_FILENO, &c, 1) == 1 ? c : EOF; + return _NX_READ(STDIN_FILENO, &c, 1) == 1 ? c : EOF; #endif } @@ -47,6 +49,6 @@ int getchar_unlocked(void) return fgetc_unlocked(stdin); #else unsigned char c; - return read(STDIN_FILENO, &c, 1) == 1 ? c : EOF; + return _NX_READ(STDIN_FILENO, &c, 1) == 1 ? c : EOF; #endif } diff --git a/libs/libc/stdio/lib_getdelim.c b/libs/libc/stdio/lib_getdelim.c index 3eaed14caa33f..1dda58d4d9a5e 100644 --- a/libs/libc/stdio/lib_getdelim.c +++ b/libs/libc/stdio/lib_getdelim.c @@ -28,6 +28,8 @@ #include +#include + #include "libc.h" /**************************************************************************** @@ -202,7 +204,7 @@ ssize_t getdelim(FAR char **lineptr, size_t *n, int delimiter, return ncopied; errout: - set_errno(ret); + _NX_SETERRNO(ret); return -1; } diff --git a/libs/libc/stdio/lib_libdgets.c b/libs/libc/stdio/lib_libdgets.c index 0f1f8da350af8..b8a47b37075ae 100644 --- a/libs/libc/stdio/lib_libdgets.c +++ b/libs/libc/stdio/lib_libdgets.c @@ -30,6 +30,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -43,7 +45,7 @@ static int dgetc(int fd) { unsigned char c; - return read(fd, &c, 1) == 1 ? c : EOF; + return _NX_READ(fd, &c, 1) == 1 ? c : EOF; } /**************************************************************************** diff --git a/libs/libc/stdio/lib_libfwrite.c b/libs/libc/stdio/lib_libfwrite.c index 37a6535de0574..29896b6ae00e7 100644 --- a/libs/libc/stdio/lib_libfwrite.c +++ b/libs/libc/stdio/lib_libfwrite.c @@ -58,7 +58,7 @@ ssize_t lib_fwrite_unlocked(FAR const void *ptr, size_t count, if (stream == NULL) { - set_errno(EBADF); + _NX_SETERRNO(EBADF); return ret; } @@ -66,7 +66,7 @@ ssize_t lib_fwrite_unlocked(FAR const void *ptr, size_t count, if ((stream->fs_oflags & O_WROK) == 0) { - set_errno(EBADF); + _NX_SETERRNO(EBADF); goto errout; } diff --git a/libs/libc/stdio/lib_libvscanf.c b/libs/libc/stdio/lib_libvscanf.c index f232ab042dee3..caa9058b3ebc6 100644 --- a/libs/libc/stdio/lib_libvscanf.c +++ b/libs/libc/stdio/lib_libvscanf.c @@ -32,6 +32,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -843,7 +845,7 @@ static int vscanf_internal(FAR struct lib_instream_s *stream, FAR int *lastc, /* Preserve the errno value */ errsave = get_errno(); - set_errno(0); + _NX_SETERRNO(0); switch (modifier) { @@ -894,7 +896,7 @@ static int vscanf_internal(FAR struct lib_instream_s *stream, FAR int *lastc, return assigncount; } - set_errno(errsave); + _NX_SETERRNO(errsave); if (!noassign) { /* We have to check whether we need to return a long or @@ -1081,7 +1083,7 @@ static int vscanf_internal(FAR struct lib_instream_s *stream, FAR int *lastc, /* Preserve the errno value */ errsave = get_errno(); - set_errno(0); + _NX_SETERRNO(0); # ifdef CONFIG_HAVE_DOUBLE if (modifier >= L_MOD) @@ -1108,7 +1110,7 @@ static int vscanf_internal(FAR struct lib_instream_s *stream, FAR int *lastc, } #endif - set_errno(errsave); + _NX_SETERRNO(errsave); if (!noassign) { diff --git a/libs/libc/stdio/lib_open_memstream.c b/libs/libc/stdio/lib_open_memstream.c index eef98b5e06331..76f7702ba7f4b 100644 --- a/libs/libc/stdio/lib_open_memstream.c +++ b/libs/libc/stdio/lib_open_memstream.c @@ -34,6 +34,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -130,7 +132,7 @@ static off_t memstream_seek(FAR void *c, FAR off_t *offset, int whence) new_offset = memstream_cookie->pos + *offset; break; default: - set_errno(ENOTSUP); + _NX_SETERRNO(ENOTSUP); return -1; } @@ -138,7 +140,7 @@ static off_t memstream_seek(FAR void *c, FAR off_t *offset, int whence) if (new_offset < 0 || new_offset > memstream_cookie->end) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } @@ -197,14 +199,14 @@ FAR FILE *open_memstream(FAR char **bufp, FAR size_t *sizep) if (bufp == NULL || sizep == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return NULL; } memstream_cookie = lib_zalloc(sizeof(struct memstream_cookie_s)); if (memstream_cookie == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return NULL; } diff --git a/libs/libc/stdio/lib_putchar.c b/libs/libc/stdio/lib_putchar.c index e993667e2c014..f139407ead5d0 100644 --- a/libs/libc/stdio/lib_putchar.c +++ b/libs/libc/stdio/lib_putchar.c @@ -27,6 +27,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -37,7 +39,7 @@ int putchar(int c) return fputc(c, stdout); #else unsigned char tmp = c; - return write(STDOUT_FILENO, &tmp, 1) == 1 ? c : EOF; + return _NX_WRITE(STDOUT_FILENO, &tmp, 1) == 1 ? c : EOF; #endif } @@ -47,6 +49,6 @@ int putchar_unlocked(int c) return fputc_unlocked(c, stdout); #else unsigned char tmp = c; - return write(STDOUT_FILENO, &tmp, 1) == 1 ? c : EOF; + return _NX_WRITE(STDOUT_FILENO, &tmp, 1) == 1 ? c : EOF; #endif } diff --git a/libs/libc/stdio/lib_putwchar.c b/libs/libc/stdio/lib_putwchar.c index c4761fc6c0d07..c0451d87f27fa 100644 --- a/libs/libc/stdio/lib_putwchar.c +++ b/libs/libc/stdio/lib_putwchar.c @@ -33,6 +33,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -66,7 +68,7 @@ wint_t putwchar_unlocked(wchar_t c) return WEOF; } - return write(STDOUT_FILENO, mbc, l) == l ? c : WEOF; + return _NX_WRITE(STDOUT_FILENO, mbc, l) == l ? c : WEOF; #endif } diff --git a/libs/libc/stdio/lib_rdflush_unlocked.c b/libs/libc/stdio/lib_rdflush_unlocked.c index 59f2cbc33d792..390d4015ea588 100644 --- a/libs/libc/stdio/lib_rdflush_unlocked.c +++ b/libs/libc/stdio/lib_rdflush_unlocked.c @@ -31,6 +31,8 @@ #include #include +#include + #include "libc.h" #ifndef CONFIG_STDIO_DISABLE_BUFFERING @@ -56,7 +58,7 @@ int lib_rdflush_unlocked(FAR FILE *stream) if (stream == NULL) { - set_errno(EBADF); + _NX_SETERRNO(EBADF); return ERROR; } diff --git a/libs/libc/stdio/lib_renameat.c b/libs/libc/stdio/lib_renameat.c index f1e3319cf3085..7cbcec6c0da16 100644 --- a/libs/libc/stdio/lib_renameat.c +++ b/libs/libc/stdio/lib_renameat.c @@ -27,6 +27,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -84,7 +86,7 @@ int renameat(int olddirfd, FAR const char *oldpath, if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/stdio/lib_rewind.c b/libs/libc/stdio/lib_rewind.c index fadc4d71c06a1..fea03de658706 100644 --- a/libs/libc/stdio/lib_rewind.c +++ b/libs/libc/stdio/lib_rewind.c @@ -28,6 +28,8 @@ #include +#include + #include "libc.h" /**************************************************************************** @@ -44,7 +46,7 @@ void rewind(FAR FILE *stream) if (!stream) { - set_errno(EBADF); + _NX_SETERRNO(EBADF); return; } diff --git a/libs/libc/stdio/lib_setvbuf.c b/libs/libc/stdio/lib_setvbuf.c index 3231dbf176d8f..c47954fa57770 100644 --- a/libs/libc/stdio/lib_setvbuf.c +++ b/libs/libc/stdio/lib_setvbuf.c @@ -247,13 +247,13 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) funlockfile(stream); errout: - set_errno(errcode); + _NX_SETERRNO(errcode); return ERROR; #else /* Return that setvbuf() is not supported */ - set_errno(ENOSYS); + _NX_SETERRNO(ENOSYS); return ERROR; #endif } diff --git a/libs/libc/stdio/lib_tempnam.c b/libs/libc/stdio/lib_tempnam.c index def08537a5488..2dfe75bea951a 100644 --- a/libs/libc/stdio/lib_tempnam.c +++ b/libs/libc/stdio/lib_tempnam.c @@ -30,6 +30,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -91,7 +93,7 @@ FAR char *tempnam(FAR const char *dir, FAR const char *pfx) } else { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); } return NULL; diff --git a/libs/libc/stdio/lib_tmpfile.c b/libs/libc/stdio/lib_tmpfile.c index 779db9c61c79e..b5a16c877570a 100644 --- a/libs/libc/stdio/lib_tmpfile.c +++ b/libs/libc/stdio/lib_tmpfile.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -45,7 +47,7 @@ FAR FILE *tmpfile(void) fp = fdopen(fd, "w+"); if (fp == NULL) { - close(fd); + _NX_CLOSE(fd); } } diff --git a/libs/libc/stdlib/lib_mkstemp.c b/libs/libc/stdlib/lib_mkstemp.c index 6f65bfed25d1e..eb635c0e10742 100644 --- a/libs/libc/stdlib/lib_mkstemp.c +++ b/libs/libc/stdlib/lib_mkstemp.c @@ -31,6 +31,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -68,7 +70,7 @@ int mkstemp(FAR char *path_template) if (path) { - ret = open(path, O_RDWR | O_CREAT | O_EXCL, 0600); + ret = _NX_OPEN(path, O_RDWR | O_CREAT | O_EXCL, 0600); } return ret; diff --git a/libs/libc/stdlib/lib_mktemp.c b/libs/libc/stdlib/lib_mktemp.c index e742daa105e8c..233bc5f3a064a 100644 --- a/libs/libc/stdlib/lib_mktemp.c +++ b/libs/libc/stdlib/lib_mktemp.c @@ -37,6 +37,7 @@ #include #include +#include #include /**************************************************************************** @@ -241,7 +242,7 @@ FAR char *mktemp(FAR char *path_template) { /* We have it... Clear the errno and return the template */ - set_errno(0); + _NX_SETERRNO(0); return path_template; } @@ -250,7 +251,7 @@ FAR char *mktemp(FAR char *path_template) /* We could not find an unique filename */ - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return NULL; } diff --git a/libs/libc/stdlib/lib_openpty.c b/libs/libc/stdlib/lib_openpty.c index 24f74dc574043..f216552fe878e 100644 --- a/libs/libc/stdlib/lib_openpty.c +++ b/libs/libc/stdlib/lib_openpty.c @@ -32,6 +32,7 @@ #include #include +#include #include /**************************************************************************** @@ -71,7 +72,7 @@ int posix_openpt(int oflag) { #ifdef CONFIG_PSEUDOTERM_SUSV1 - return open("/dev/ptmx", oflag); + return _NX_OPEN("/dev/ptmx", oflag); #else int minor; @@ -81,13 +82,13 @@ int posix_openpt(int oflag) int fd; snprintf(devname, sizeof(devname), "/dev/pty%d", minor); - fd = open(devname, oflag); + fd = _NX_OPEN(devname, oflag); if (fd < 0) { /* Fail, register and try again */ pty_register(minor); - fd = open(devname, oflag); + fd = _NX_OPEN(devname, oflag); } if (fd >= 0) @@ -155,7 +156,7 @@ int openpty(FAR int *master, FAR int *slave, FAR char *name, goto err; } - ret = open(buf, O_RDWR | O_NOCTTY); + ret = _NX_OPEN(buf, O_RDWR | O_NOCTTY); if (ret < 0) { goto err; @@ -183,6 +184,6 @@ int openpty(FAR int *master, FAR int *slave, FAR char *name, return 0; err: - close(*master); + _NX_CLOSE(*master); return ret; } diff --git a/libs/libc/stdlib/lib_reallocarray.c b/libs/libc/stdlib/lib_reallocarray.c index 7810883a56043..2c5bc67a2258d 100644 --- a/libs/libc/stdlib/lib_reallocarray.c +++ b/libs/libc/stdlib/lib_reallocarray.c @@ -27,6 +27,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -71,7 +73,7 @@ FAR void *reallocarray(FAR void *ptr, size_t nmemb, size_t size) if ((SIZE_MAX / nmemb) < size) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return NULL; } } diff --git a/libs/libc/stdlib/lib_realpath.c b/libs/libc/stdlib/lib_realpath.c index 3973e1ac73d6b..312fcd769b388 100644 --- a/libs/libc/stdlib/lib_realpath.c +++ b/libs/libc/stdlib/lib_realpath.c @@ -32,6 +32,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -58,13 +60,13 @@ FAR char *lib_realpath(FAR const char *path, FAR char *resolved, if (path == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return NULL; } if (*path == '\0') { - set_errno(ENOENT); + _NX_SETERRNO(ENOENT); return NULL; } @@ -73,7 +75,7 @@ FAR char *lib_realpath(FAR const char *path, FAR char *resolved, fres = resolved = lib_malloc(PATH_MAX); if (resolved == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return NULL; } } @@ -174,7 +176,7 @@ FAR char *lib_realpath(FAR const char *path, FAR char *resolved, if (p - resolved + 1 + q - path + 1 > PATH_MAX) { - set_errno(ENAMETOOLONG); + _NX_SETERRNO(ENAMETOOLONG); goto out; } @@ -203,7 +205,7 @@ FAR char *lib_realpath(FAR const char *path, FAR char *resolved, { if (nlnk++ >= SYMLOOP_MAX) { - set_errno(ELOOP); + _NX_SETERRNO(ELOOP); goto out; } @@ -212,7 +214,7 @@ FAR char *lib_realpath(FAR const char *path, FAR char *resolved, wbuf[0] = lib_calloc(2, PATH_MAX); if (wbuf[0] == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); goto out; } @@ -224,7 +226,7 @@ FAR char *lib_realpath(FAR const char *path, FAR char *resolved, { if (n == 0) { - set_errno(ENOENT); + _NX_SETERRNO(ENOENT); } goto out; @@ -234,7 +236,7 @@ FAR char *lib_realpath(FAR const char *path, FAR char *resolved, if (n + (len = strlen(q)) + 1 > PATH_MAX) { - set_errno(ENAMETOOLONG); + _NX_SETERRNO(ENAMETOOLONG); goto out; } @@ -255,7 +257,7 @@ FAR char *lib_realpath(FAR const char *path, FAR char *resolved, if (*q == '/' && !S_ISDIR(sb.st_mode)) { - set_errno(ENOTDIR); + _NX_SETERRNO(ENOTDIR); goto out; } diff --git a/libs/libc/stdlib/lib_strtol.c b/libs/libc/stdlib/lib_strtol.c index 9e78ae814c13f..0ce73809ffca2 100644 --- a/libs/libc/stdlib/lib_strtol.c +++ b/libs/libc/stdlib/lib_strtol.c @@ -30,6 +30,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -86,7 +88,7 @@ long strtol(FAR const char *nptr, FAR char **endptr, int base) if (accum > limit) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); retval = LONG_MIN; } else @@ -98,7 +100,7 @@ long strtol(FAR const char *nptr, FAR char **endptr, int base) { if (accum > LONG_MAX) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); retval = LONG_MAX; } else diff --git a/libs/libc/stdlib/lib_strtold.c b/libs/libc/stdlib/lib_strtold.c index 56a20992bdfd6..761367e6ba51c 100644 --- a/libs/libc/stdlib/lib_strtold.c +++ b/libs/libc/stdlib/lib_strtold.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -399,11 +400,11 @@ static long_double decfloat(FAR char *ptr, FAR char **endptr) } else if (num_digit + num_decimal > ldbl_max_10_exp) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); } else if (num_digit + num_decimal < ldbl_min_10_exp) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); } if (k % 9) @@ -561,13 +562,13 @@ static long_double hexfloat(FAR char *ptr, if (e2 > -emin) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); return ldbl_max * ldbl_max; } if (e2 < emin - 2 * ldbl_mant_dig) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); return ldbl_min * ldbl_min; } @@ -613,7 +614,7 @@ static long_double hexfloat(FAR char *ptr, if (!y) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); } return scalbnx(y, 2., e2); diff --git a/libs/libc/stdlib/lib_strtoll.c b/libs/libc/stdlib/lib_strtoll.c index 05dc917d1a8c8..710385785be78 100644 --- a/libs/libc/stdlib/lib_strtoll.c +++ b/libs/libc/stdlib/lib_strtoll.c @@ -30,6 +30,8 @@ #include #include +#include + #include "libc.h" #ifdef CONFIG_HAVE_LONG_LONG @@ -89,7 +91,7 @@ long long strtoll(FAR const char *nptr, FAR char **endptr, int base) if (accum > limit) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); retval = LLONG_MIN; } else @@ -101,7 +103,7 @@ long long strtoll(FAR const char *nptr, FAR char **endptr, int base) { if (accum > LLONG_MAX) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); return LLONG_MAX; } else diff --git a/libs/libc/stdlib/lib_strtoul.c b/libs/libc/stdlib/lib_strtoul.c index 0dadec7c3c90a..7a6f26e2890ad 100644 --- a/libs/libc/stdlib/lib_strtoul.c +++ b/libs/libc/stdlib/lib_strtoul.c @@ -29,6 +29,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -81,7 +83,7 @@ unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base) if (base < 0) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); } else { @@ -96,7 +98,7 @@ unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base) if (accum > limit || (accum == limit && value > last_digit)) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); accum = ULONG_MAX; break; } diff --git a/libs/libc/stdlib/lib_strtoull.c b/libs/libc/stdlib/lib_strtoull.c index e3ac64f920fab..d8eb11659bc52 100644 --- a/libs/libc/stdlib/lib_strtoull.c +++ b/libs/libc/stdlib/lib_strtoull.c @@ -30,6 +30,8 @@ #include #include +#include + #include "libc.h" #ifdef CONFIG_HAVE_LONG_LONG @@ -84,7 +86,7 @@ unsigned long long strtoull(FAR const char *nptr, if (base < 0) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); accum = 0; } else @@ -100,7 +102,7 @@ unsigned long long strtoull(FAR const char *nptr, if (accum > limit || (accum == limit && value > last_digit)) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); accum = ULLONG_MAX; break; } diff --git a/libs/libc/termios/lib_ttyname.c b/libs/libc/termios/lib_ttyname.c index cbcfd4a85a6c0..d2c3a5811c300 100644 --- a/libs/libc/termios/lib_ttyname.c +++ b/libs/libc/termios/lib_ttyname.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -63,7 +65,7 @@ FAR char *ttyname(int fd) ret = ttyname_r(fd, name, TTY_NAME_MAX); if (ret != 0) { - set_errno(ret); + _NX_SETERRNO(ret); return NULL; } diff --git a/libs/libc/time/lib_gettimeofday.c b/libs/libc/time/lib_gettimeofday.c index 85358311e85ef..d4cceec28d78e 100644 --- a/libs/libc/time/lib_gettimeofday.c +++ b/libs/libc/time/lib_gettimeofday.c @@ -30,6 +30,7 @@ #include #include +#include /**************************************************************************** * Public Functions @@ -67,7 +68,7 @@ int gettimeofday(FAR struct timeval *tv, FAR struct timezone *tz) #ifdef CONFIG_DEBUG_FEATURES if (!tv) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } #endif diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c index 8dd6f5f3d277e..378985ec72e9b 100644 --- a/libs/libc/time/lib_localtime.c +++ b/libs/libc/time/lib_localtime.c @@ -2187,7 +2187,7 @@ static FAR struct tm *timesub(FAR const time_t *timep, } else { - set_errno(EOVERFLOW); + _NX_SETERRNO(EOVERFLOW); return NULL; } @@ -2644,7 +2644,7 @@ static time_t time1(FAR struct tm *tmp, if (tmp == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } diff --git a/libs/libc/time/lib_nanosleep.c b/libs/libc/time/lib_nanosleep.c index 4d8d0308e484e..830e47fe2e3b1 100644 --- a/libs/libc/time/lib_nanosleep.c +++ b/libs/libc/time/lib_nanosleep.c @@ -29,6 +29,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -96,7 +98,7 @@ int nanosleep(FAR const struct timespec *rqtp, FAR struct timespec *rmtp) ret = clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rmtp); if (ret != 0) { - set_errno(ret); + _NX_SETERRNO(ret); ret = ERROR; } diff --git a/libs/libc/time/lib_settimeofday.c b/libs/libc/time/lib_settimeofday.c index dc0a5ab7e43cb..ea38df68e80ad 100644 --- a/libs/libc/time/lib_settimeofday.c +++ b/libs/libc/time/lib_settimeofday.c @@ -30,6 +30,7 @@ #include #include +#include /**************************************************************************** * Public Functions @@ -65,7 +66,7 @@ int settimeofday(FAR const struct timeval *tv, FAR const struct timezone *tz) #ifdef CONFIG_DEBUG_FEATURES if (!tv || tv->tv_usec >= USEC_PER_SEC) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } #endif diff --git a/libs/libc/unistd/lib_access.c b/libs/libc/unistd/lib_access.c index 9ad7e421d09f3..96fd4527c092b 100644 --- a/libs/libc/unistd/lib_access.c +++ b/libs/libc/unistd/lib_access.c @@ -30,6 +30,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -143,7 +145,7 @@ int faccessat(int dirfd, FAR const char *path, int amode, int flags) ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/unistd/lib_chdir.c b/libs/libc/unistd/lib_chdir.c index 025def3bd0967..5050f87664263 100644 --- a/libs/libc/unistd/lib_chdir.c +++ b/libs/libc/unistd/lib_chdir.c @@ -31,6 +31,8 @@ #include #include +#include + #include "libc.h" #ifndef CONFIG_DISABLE_ENVIRON @@ -91,7 +93,7 @@ int chdir(FAR const char *path) if (!S_ISDIR(buf.st_mode)) { - set_errno(ENOTDIR); + _NX_SETERRNO(ENOTDIR); return ERROR; } diff --git a/libs/libc/unistd/lib_crypt_r.c b/libs/libc/unistd/lib_crypt_r.c index 91bf8ad73b857..b86986147fc2d 100644 --- a/libs/libc/unistd/lib_crypt_r.c +++ b/libs/libc/unistd/lib_crypt_r.c @@ -29,6 +29,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -77,14 +79,14 @@ static int md5_init(FAR cryptodev_context_t *ctx) int fd; memset(ctx, 0, sizeof(cryptodev_context_t)); - fd = open("/dev/crypto", O_RDWR, 0); + fd = _NX_OPEN("/dev/crypto", O_RDWR, 0); if (fd < 0) { return -get_errno(); } ret = ioctl(fd, CRIOGET, &ctx->fd); - close(fd); + _NX_CLOSE(fd); if (ret < 0) { return -get_errno(); @@ -130,7 +132,7 @@ static int md5_finish(FAR cryptodev_context_t *ctx, ioctl(ctx->fd, CIOCFSESSION, &ctx->session.ses); ctx->crypt.ses = 0; - close(ctx->fd); + _NX_CLOSE(ctx->fd); memset(ctx, 0, sizeof(cryptodev_context_t)); return ret; } diff --git a/libs/libc/unistd/lib_daemon.c b/libs/libc/unistd/lib_daemon.c index b9e11d24ca935..b496b4b359f4d 100644 --- a/libs/libc/unistd/lib_daemon.c +++ b/libs/libc/unistd/lib_daemon.c @@ -30,6 +30,8 @@ #include #include +#include + /* Not appropriate for use within the OS */ #if defined(CONFIG_BUILD_FLAT) || !defined(__KERNEL__) @@ -113,7 +115,7 @@ int daemon(int nochdir, int noclose) if (noclose == 0) { - int fd = open("/dev/null", O_RDWR); + int fd = _NX_OPEN("/dev/null", O_RDWR); if (fd < 0) { return -1; @@ -137,7 +139,7 @@ int daemon(int nochdir, int noclose) if (fd > 2) { - close(fd); + _NX_CLOSE(fd); } } diff --git a/libs/libc/unistd/lib_execl.c b/libs/libc/unistd/lib_execl.c index 4ba1d2dba9326..acde281bf2f3e 100644 --- a/libs/libc/unistd/lib_execl.c +++ b/libs/libc/unistd/lib_execl.c @@ -31,6 +31,8 @@ #include #include +#include + #include "libc.h" #ifdef CONFIG_LIBC_EXECFUNCS @@ -139,7 +141,7 @@ int execl(FAR const char *path, FAR const char *arg0, ...) if (++nargs > MAX_EXECL_ARGS) { - set_errno(E2BIG); + _NX_SETERRNO(E2BIG); va_end(ap); return ERROR; } @@ -154,7 +156,7 @@ int execl(FAR const char *path, FAR const char *arg0, ...) argv = (FAR char **)lib_malloc((nargs + 1) * sizeof(FAR char *)); if (argv == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return ERROR; } diff --git a/libs/libc/unistd/lib_execle.c b/libs/libc/unistd/lib_execle.c index 537d1e2d28f8d..b99611ed912ac 100644 --- a/libs/libc/unistd/lib_execle.c +++ b/libs/libc/unistd/lib_execle.c @@ -31,6 +31,8 @@ #include #include +#include + #include "libc.h" #ifdef CONFIG_LIBC_EXECFUNCS @@ -140,7 +142,7 @@ int execle(FAR const char *path, FAR const char *arg0, ...) if (++nargs > MAX_EXECL_ARGS) { - set_errno(E2BIG); + _NX_SETERRNO(E2BIG); va_end(ap); return ERROR; } @@ -156,7 +158,7 @@ int execle(FAR const char *path, FAR const char *arg0, ...) argv = (FAR char **)lib_malloc((nargs + 1) * sizeof(FAR char *)); if (argv == NULL) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return ERROR; } diff --git a/libs/libc/unistd/lib_fchownat.c b/libs/libc/unistd/lib_fchownat.c index 8992f65e200b3..960113aaea34b 100644 --- a/libs/libc/unistd/lib_fchownat.c +++ b/libs/libc/unistd/lib_fchownat.c @@ -28,6 +28,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -74,7 +76,7 @@ int fchownat(int dirfd, FAR const char *path, uid_t owner, ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/unistd/lib_flock.c b/libs/libc/unistd/lib_flock.c index 9b16956cffb77..4727807ffe883 100644 --- a/libs/libc/unistd/lib_flock.c +++ b/libs/libc/unistd/lib_flock.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -82,7 +84,7 @@ int flock(int fd, int cmd) } else { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } diff --git a/libs/libc/unistd/lib_getcwd.c b/libs/libc/unistd/lib_getcwd.c index 41091fd1a1f3c..6e156536d23a3 100644 --- a/libs/libc/unistd/lib_getcwd.c +++ b/libs/libc/unistd/lib_getcwd.c @@ -32,6 +32,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -84,7 +86,7 @@ FAR char *getcwd(FAR char *buf, size_t size) if (buf && size == 0) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return NULL; } @@ -108,7 +110,7 @@ FAR char *getcwd(FAR char *buf, size_t size) if (strlen(pwd) + 1 > size) { - set_errno(ERANGE); + _NX_SETERRNO(ERANGE); return NULL; } @@ -117,7 +119,7 @@ FAR char *getcwd(FAR char *buf, size_t size) buf = lib_malloc(size); if (!buf) { - set_errno(ENOMEM); + _NX_SETERRNO(ENOMEM); return NULL; } } diff --git a/libs/libc/unistd/lib_getentropy.c b/libs/libc/unistd/lib_getentropy.c index b4ea0598d52ed..3325af4317539 100644 --- a/libs/libc/unistd/lib_getentropy.c +++ b/libs/libc/unistd/lib_getentropy.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -58,7 +60,7 @@ int getentropy(FAR void *buffer, size_t length) { if (length > 256) { - set_errno(EIO); + _NX_SETERRNO(EIO); return -1; } diff --git a/libs/libc/unistd/lib_getpass.c b/libs/libc/unistd/lib_getpass.c index e323fb42fd87b..4cdb082848d23 100644 --- a/libs/libc/unistd/lib_getpass.c +++ b/libs/libc/unistd/lib_getpass.c @@ -27,6 +27,8 @@ #include #include +#include + /**************************************************************************** * Private Data ****************************************************************************/ @@ -45,7 +47,7 @@ FAR char *getpass(FAR const char *prompt) ssize_t bytes_read; int fd; - if ((fd = open("/dev/console", O_RDONLY | O_NOCTTY)) < 0) + if ((fd = _NX_OPEN("/dev/console", O_RDONLY | O_NOCTTY)) < 0) { fd = STDIN_FILENO; } @@ -64,7 +66,7 @@ FAR char *getpass(FAR const char *prompt) return 0; } - while ((bytes_read = read(fd, g_password + total_bytes_read, + while ((bytes_read = _NX_READ(fd, g_password + total_bytes_read, sizeof(g_password) - total_bytes_read)) > 0) { if (bytes_read > 0 && g_password[total_bytes_read] == '\n') @@ -89,7 +91,7 @@ FAR char *getpass(FAR const char *prompt) if (fd > STDERR_FILENO) { - close(fd); + _NX_CLOSE(fd); } return g_password; diff --git a/libs/libc/unistd/lib_getpgid.c b/libs/libc/unistd/lib_getpgid.c index ddca4d001f8fa..a2e90379588c6 100644 --- a/libs/libc/unistd/lib_getpgid.c +++ b/libs/libc/unistd/lib_getpgid.c @@ -30,6 +30,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -58,7 +60,7 @@ pid_t getpgid(pid_t pid) { if (pid < 0) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return INVALID_PROCESS_ID; } diff --git a/libs/libc/unistd/lib_getpriority.c b/libs/libc/unistd/lib_getpriority.c index 8f2f7461ea33f..f0c4f5e7ff1a3 100644 --- a/libs/libc/unistd/lib_getpriority.c +++ b/libs/libc/unistd/lib_getpriority.c @@ -31,6 +31,7 @@ #include #include +#include #include /**************************************************************************** @@ -71,7 +72,7 @@ int getpriority(int which, id_t who) if (which > PRIO_USER || which < PRIO_PROCESS) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } @@ -88,7 +89,7 @@ int getpriority(int which, id_t who) /* Since -1 is a legal return value, clear errno to avoid the chaos */ - set_errno(0); + _NX_SETERRNO(0); return NZERO - param.sched_priority; } diff --git a/libs/libc/unistd/lib_getrlimit.c b/libs/libc/unistd/lib_getrlimit.c index 1e4850aafc5d6..1ec9d9af00956 100644 --- a/libs/libc/unistd/lib_getrlimit.c +++ b/libs/libc/unistd/lib_getrlimit.c @@ -32,6 +32,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -51,7 +53,7 @@ int getrlimit(int resource, FAR struct rlimit *rlp) if (rlp == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } diff --git a/libs/libc/unistd/lib_getrusage.c b/libs/libc/unistd/lib_getrusage.c index d718ed205ba3e..8d5d7665802d7 100644 --- a/libs/libc/unistd/lib_getrusage.c +++ b/libs/libc/unistd/lib_getrusage.c @@ -31,6 +31,8 @@ #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -61,7 +63,7 @@ int getrusage(int who, FAR struct rusage *r_usage) if (r_usage == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } diff --git a/libs/libc/unistd/lib_linkat.c b/libs/libc/unistd/lib_linkat.c index cb0729a2c79fc..eb9ecc3c94955 100644 --- a/libs/libc/unistd/lib_linkat.c +++ b/libs/libc/unistd/lib_linkat.c @@ -27,6 +27,8 @@ #include #include +#include + #include "libc.h" #ifdef CONFIG_PSEUDOFS_SOFTLINKS @@ -92,7 +94,7 @@ int linkat(int olddirfd, FAR const char *path1, if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/unistd/lib_lockf.c b/libs/libc/unistd/lib_lockf.c index 419571748b1bd..7b321c2b66aef 100644 --- a/libs/libc/unistd/lib_lockf.c +++ b/libs/libc/unistd/lib_lockf.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -109,11 +111,11 @@ int lockf(int fd, int cmd, off_t len) return OK; } - set_errno(EACCES); + _NX_SETERRNO(EACCES); return ERROR; } } - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return ERROR; } diff --git a/libs/libc/unistd/lib_nice.c b/libs/libc/unistd/lib_nice.c index 4e02715c6403c..55b48ccb4062b 100644 --- a/libs/libc/unistd/lib_nice.c +++ b/libs/libc/unistd/lib_nice.c @@ -28,6 +28,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -47,7 +49,7 @@ int nice(int inc) int prio; int ret; - set_errno(0); + _NX_SETERRNO(0); ret = getpriority(PRIO_PROCESS, 0); if (get_errno() != 0) { diff --git a/libs/libc/unistd/lib_pathconf.c b/libs/libc/unistd/lib_pathconf.c index 69d750a62f5a4..20344b744229b 100644 --- a/libs/libc/unistd/lib_pathconf.c +++ b/libs/libc/unistd/lib_pathconf.c @@ -30,6 +30,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -140,7 +142,7 @@ long fpathconf(int fildes, int name) /* Assume valid but not implemented for the time being */ - set_errno(ENOSYS); + _NX_SETERRNO(ENOSYS); return ERROR; } } diff --git a/libs/libc/unistd/lib_posix_fallocate.c b/libs/libc/unistd/lib_posix_fallocate.c index 6f50ef37b5042..9f9cf96b62670 100644 --- a/libs/libc/unistd/lib_posix_fallocate.c +++ b/libs/libc/unistd/lib_posix_fallocate.c @@ -30,6 +30,8 @@ #include +#include + #ifndef CONFIG_DISABLE_MOUNTPOINT /**************************************************************************** @@ -79,7 +81,7 @@ int posix_fallocate(int fd, off_t offset, off_t len) return EFBIG; } - if (fstat(fd, &st) != 0) + if (_NX_STAT(fd, &st) != 0) { return get_errno(); } diff --git a/libs/libc/unistd/lib_readlinkat.c b/libs/libc/unistd/lib_readlinkat.c index 8d3043b9a722a..5448527cd96d1 100644 --- a/libs/libc/unistd/lib_readlinkat.c +++ b/libs/libc/unistd/lib_readlinkat.c @@ -27,6 +27,8 @@ #include #include +#include + #include "libc.h" #ifdef CONFIG_PSEUDOFS_SOFTLINKS @@ -76,7 +78,7 @@ ssize_t readlinkat(int dirfd, FAR const char *path, FAR char *buf, ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/unistd/lib_setegid.c b/libs/libc/unistd/lib_setegid.c index fc72ca1aa9350..181a0454a71a5 100644 --- a/libs/libc/unistd/lib_setegid.c +++ b/libs/libc/unistd/lib_setegid.c @@ -30,6 +30,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -63,6 +65,6 @@ int setegid(gid_t gid) * implementation. */ - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } diff --git a/libs/libc/unistd/lib_seteuid.c b/libs/libc/unistd/lib_seteuid.c index 6d137ea7cda5e..3267a232c4893 100644 --- a/libs/libc/unistd/lib_seteuid.c +++ b/libs/libc/unistd/lib_seteuid.c @@ -29,6 +29,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -62,6 +64,6 @@ int seteuid(uid_t uid) * implementation. */ - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } diff --git a/libs/libc/unistd/lib_setgid.c b/libs/libc/unistd/lib_setgid.c index 57b70179af0c8..bca17857498e5 100644 --- a/libs/libc/unistd/lib_setgid.c +++ b/libs/libc/unistd/lib_setgid.c @@ -30,6 +30,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -64,6 +66,6 @@ int setgid(gid_t gid) * implementation. */ - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } diff --git a/libs/libc/unistd/lib_setuid.c b/libs/libc/unistd/lib_setuid.c index fdd4f53bbe391..71290b128068d 100644 --- a/libs/libc/unistd/lib_setuid.c +++ b/libs/libc/unistd/lib_setuid.c @@ -29,6 +29,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -63,6 +65,6 @@ int setuid(uid_t uid) * implementation. */ - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } diff --git a/libs/libc/unistd/lib_symlinkat.c b/libs/libc/unistd/lib_symlinkat.c index 14ebe44a858c6..c3df326e8c3c9 100644 --- a/libs/libc/unistd/lib_symlinkat.c +++ b/libs/libc/unistd/lib_symlinkat.c @@ -27,6 +27,8 @@ #include #include +#include + #include "libc.h" #ifdef CONFIG_PSEUDOFS_SOFTLINKS @@ -73,7 +75,7 @@ int symlinkat(FAR const char *path1, int dirfd, FAR const char *path2) ret = lib_getfullpath(dirfd, path2, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/unistd/lib_sysconf.c b/libs/libc/unistd/lib_sysconf.c index 8683350a9a1b2..0c73cd51cddb1 100644 --- a/libs/libc/unistd/lib_sysconf.c +++ b/libs/libc/unistd/lib_sysconf.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -271,6 +272,6 @@ long sysconf(int name) break; } - set_errno(errcode); + _NX_SETERRNO(errcode); return ERROR; } diff --git a/libs/libc/unistd/lib_times.c b/libs/libc/unistd/lib_times.c index f6f51f8cefe2b..a49ed31a0fff6 100644 --- a/libs/libc/unistd/lib_times.c +++ b/libs/libc/unistd/lib_times.c @@ -29,6 +29,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -54,7 +56,7 @@ clock_t times(FAR struct tms *buffer) { if (buffer == NULL) { - set_errno(EINVAL); + _NX_SETERRNO(EINVAL); return -1; } diff --git a/libs/libc/unistd/lib_truncate.c b/libs/libc/unistd/lib_truncate.c index b328e1246a68b..3f836fb3607b5 100644 --- a/libs/libc/unistd/lib_truncate.c +++ b/libs/libc/unistd/lib_truncate.c @@ -31,6 +31,8 @@ #include #include +#include + #ifndef CONFIG_DISABLE_MOUNTPOINT /**************************************************************************** @@ -104,7 +106,7 @@ int truncate(FAR const char *path, off_t length) /* Open the regular file at 'path' for write-only access */ - fd = open(path, O_WRONLY); + fd = _NX_OPEN(path, O_WRONLY); if (fd < 0) { return ERROR; @@ -114,7 +116,7 @@ int truncate(FAR const char *path, off_t length) ret = ftruncate(fd, length); - close(fd); + _NX_CLOSE(fd); return ret; } diff --git a/libs/libc/unistd/lib_unlinkat.c b/libs/libc/unistd/lib_unlinkat.c index a63acb54e670f..0a78bbd83ce75 100644 --- a/libs/libc/unistd/lib_unlinkat.c +++ b/libs/libc/unistd/lib_unlinkat.c @@ -28,6 +28,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -74,7 +76,7 @@ int unlinkat(int dirfd, FAR const char *path, int flags) ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/unistd/lib_utimes.c b/libs/libc/unistd/lib_utimes.c index 4ed8da56a4829..a4509369f1c06 100644 --- a/libs/libc/unistd/lib_utimes.c +++ b/libs/libc/unistd/lib_utimes.c @@ -28,6 +28,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -59,7 +61,7 @@ int futimesat(int dirfd, FAR const char *path, const struct timeval tv[2]) ret = lib_getfullpath(dirfd, path, fullpath, sizeof(fullpath)); if (ret < 0) { - set_errno(-ret); + _NX_SETERRNO(-ret); return ERROR; } diff --git a/libs/libc/userfs/lib_userfs.c b/libs/libc/userfs/lib_userfs.c index 886f1fbfb0350..5a8eeaf681df0 100644 --- a/libs/libc/userfs/lib_userfs.c +++ b/libs/libc/userfs/lib_userfs.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -1235,7 +1236,7 @@ int userfs_run(FAR const char *mountpt, /* Close the LocalHost socket */ errout_with_sockfd: - close(info->sockfd); + _NX_CLOSE(info->sockfd); /* Free the IO Buffer */ diff --git a/libs/libc/wchar/lib_mbrtowc.c b/libs/libc/wchar/lib_mbrtowc.c index 3efe93290b9e1..b31fc849f291e 100644 --- a/libs/libc/wchar/lib_mbrtowc.c +++ b/libs/libc/wchar/lib_mbrtowc.c @@ -35,6 +35,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -183,6 +185,6 @@ size_t mbrtowc(FAR wchar_t *pwc, FAR const char *s, ilseq: *(FAR uint32_t *)ps = 0; - set_errno(EILSEQ); + _NX_SETERRNO(EILSEQ); return -1; } diff --git a/libs/libc/wchar/lib_wcrtomb.c b/libs/libc/wchar/lib_wcrtomb.c index 17e8a7e30227f..17ef34f607bcf 100644 --- a/libs/libc/wchar/lib_wcrtomb.c +++ b/libs/libc/wchar/lib_wcrtomb.c @@ -27,6 +27,8 @@ #include #include +#include + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -72,6 +74,6 @@ size_t wcrtomb(FAR char *s, wchar_t wc, FAR mbstate_t *ps) return 4; } - set_errno(EILSEQ); + _NX_SETERRNO(EILSEQ); return -1; }