Skip to content

Commit

Permalink
libc: modify open,close... to _NX_OPEN,_NX_CLOSE
Browse files Browse the repository at this point in the history
Signed-off-by: wangmingrong1 <[email protected]>
  • Loading branch information
W-M-R committed Nov 11, 2024
1 parent 5e8f1ee commit 4c560a1
Show file tree
Hide file tree
Showing 145 changed files with 507 additions and 267 deletions.
3 changes: 2 additions & 1 deletion libs/libc/aio/aio_return.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
****************************************************************************/

#include <nuttx/config.h>
#include <nuttx/fs/fs.h>

#include <aio.h>
#include <assert.h>
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions libs/libc/aio/lio_listio.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <debug.h>
#include <errno.h>

#include <nuttx/fs/fs.h>
#include <nuttx/signal.h>
#include <nuttx/sched.h>

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions libs/libc/dirent/lib_closedir.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include <unistd.h>

#include <nuttx/fs/fs.h>

#include "libc.h"

/****************************************************************************
Expand Down Expand Up @@ -69,7 +71,7 @@ int closedir(FAR DIR *dirp)

if (dirp == NULL)
{
set_errno(EBADF);
_NX_SETERRNO(EBADF);
return -1;
}

Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion libs/libc/dirent/lib_dirfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <dirent.h>
#include <errno.h>

#include <nuttx/fs/fs.h>

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -62,6 +64,6 @@ int dirfd(FAR DIR *dirp)
return dirp->fd;
}

set_errno(EINVAL);
_NX_SETERRNO(EINVAL);
return -1;
}
8 changes: 5 additions & 3 deletions libs/libc/dirent/lib_fdopendir.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
# include <android/fdsan.h>
#endif

#include <nuttx/fs/fs.h>

#include "libc.h"

/****************************************************************************
Expand Down Expand Up @@ -69,22 +71,22 @@ FAR DIR *fdopendir(int fd)
FAR DIR *dir;
int ret;

ret = fstat(fd, &st);
ret = _NX_STAT(fd, &st);
if (ret == -1)
{
return NULL;
}

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;
}

Expand Down
4 changes: 3 additions & 1 deletion libs/libc/dirent/lib_nftw.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <string.h>
#include <limits.h>

#include <nuttx/fs/fs.h>

#include "libc.h"

/****************************************************************************
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions libs/libc/dirent/lib_opendir.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include <string.h>

#include <nuttx/fs/fs.h>

#include "libc.h"

/****************************************************************************
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions libs/libc/dirent/lib_readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <errno.h>
#include <unistd.h>

#include <nuttx/fs/fs.h>

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libs/libc/dirent/lib_readdirr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 3 additions & 1 deletion libs/libc/dirent/lib_rewinddir.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <errno.h>
#include <unistd.h>

#include <nuttx/fs/fs.h>

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -60,6 +62,6 @@ void rewinddir(FAR DIR *dirp)
}
else
{
set_errno(EBADF);
_NX_SETERRNO(EBADF);
}
}
10 changes: 6 additions & 4 deletions libs/libc/dirent/lib_scandir.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <errno.h>
#include <stdlib.h>

#include <nuttx/fs/fs.h>

#include "libc.h"

/* The scandir() function is not appropriate for use within the kernel in its
Expand Down Expand Up @@ -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))
{
Expand All @@ -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. */

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion libs/libc/dirent/lib_seekdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <errno.h>
#include <unistd.h>

#include <nuttx/fs/fs.h>

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -62,6 +64,6 @@ void seekdir(FAR DIR *dirp, off_t offset)
}
else
{
set_errno(EBADF);
_NX_SETERRNO(EBADF);
}
}
4 changes: 3 additions & 1 deletion libs/libc/dirent/lib_telldir.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <unistd.h>
#include <errno.h>

#include <nuttx/fs/fs.h>

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -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;
}
4 changes: 3 additions & 1 deletion libs/libc/dlfcn/lib_dladdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <errno.h>
#include <dlfcn.h>

#include <nuttx/fs/fs.h>

/****************************************************************************
* Public Functions
****************************************************************************/
Expand All @@ -39,6 +41,6 @@

int dladdr(const FAR void *addr, FAR Dl_info *info)
{
set_errno(ENOTSUP);
_NX_SETERRNO(ENOTSUP);
return 0;
}
7 changes: 5 additions & 2 deletions libs/libc/eventfd/lib_eventfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@
#include <sys/ioctl.h>
#include <unistd.h>

#include <nuttx/fs/fs.h>

/****************************************************************************
* 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;
}
3 changes: 2 additions & 1 deletion libs/libc/gdbstub/lib_gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <nuttx/nuttx.h>
#include <nuttx/sched.h>
#include <nuttx/ascii.h>
#include <nuttx/fs/fs.h>
#include <nuttx/gdbstub.h>
#include <nuttx/memoryregion.h>

Expand Down Expand Up @@ -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())
{
Expand Down
4 changes: 3 additions & 1 deletion libs/libc/grp/lib_getgrbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <errno.h>
#include <grp.h>

#include <nuttx/fs/fs.h>

#include "grp/lib_grp.h"
#include "libc.h"

Expand Down Expand Up @@ -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;
}
6 changes: 4 additions & 2 deletions libs/libc/inttypes/lib_strtoimax.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <inttypes.h>
#include <errno.h>

#include <nuttx/fs/fs.h>

#include "libc.h"

/* Current implementation depends on strtoull() and, hence, is only
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand Down
Loading

0 comments on commit 4c560a1

Please sign in to comment.