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 18, 2024
1 parent fd95721 commit 18e7eb4
Show file tree
Hide file tree
Showing 39 changed files with 145 additions and 74 deletions.
4 changes: 3 additions & 1 deletion 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 @@ -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
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_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 @@ -82,7 +84,7 @@ FAR DIR *opendir(FAR const char *path)
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
4 changes: 3 additions & 1 deletion 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 @@ -67,7 +69,7 @@ FAR struct dirent *readdir(DIR *dirp)
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
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 @@ -56,7 +58,7 @@ void rewinddir(FAR DIR *dirp)
{
if (dirp != NULL)
{
lseek(dirp->fd, 0, SEEK_SET);
_NX_SEEK(dirp->fd, 0, SEEK_SET);
}
else
{
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 @@ -58,7 +60,7 @@ void seekdir(FAR DIR *dirp, off_t offset)
{
if (dirp != NULL)
{
lseek(dirp->fd, offset, SEEK_SET);
_NX_SEEK(dirp->fd, offset, SEEK_SET);
}
else
{
Expand Down
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 @@ -60,7 +62,7 @@ off_t telldir(FAR DIR *dirp)
{
if (dirp != NULL)
{
return lseek(dirp->fd, 0, SEEK_CUR);
return _NX_SEEK(dirp->fd, 0, SEEK_CUR);
}

set_errno(EBADF);
Expand Down
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;
}
9 changes: 5 additions & 4 deletions libs/libc/locale/lib_catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <sys/stat.h>
#include <unistd.h>

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

#ifdef CONFIG_LIBC_LOCALE_CATALOG
Expand Down Expand Up @@ -87,13 +88,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)
Expand All @@ -104,12 +105,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;
}

Expand Down
7 changes: 4 additions & 3 deletions libs/libc/locale/lib_gettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sys/stat.h>
#include <unistd.h>

#include <nuttx/fs/fs.h>
#include <nuttx/mutex.h>
#include <nuttx/tls.h>

Expand Down Expand Up @@ -129,13 +130,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);
Expand All @@ -147,7 +148,7 @@ static FAR void *momap(FAR const char *path, FAR size_t *size)
}
}

close(fd);
_NX_CLOSE(fd);
return map;
}

Expand Down
4 changes: 3 additions & 1 deletion libs/libc/misc/lib_fdsan.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <setjmp.h>
#include <sys/ioctl.h>

#include <nuttx/fs/fs.h>

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion libs/libc/misc/lib_memfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

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

#if defined(CONFIG_LIBC_MEMFD_TMPFS) || defined(CONFIG_LIBC_MEMFD_SHMFS)
Expand Down Expand Up @@ -74,7 +76,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);
Expand Down
4 changes: 3 additions & 1 deletion libs/libc/misc/lib_mknod.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <sys/stat.h>
#include <unistd.h>

#include <nuttx/fs/fs.h>

#include "libc.h"

/****************************************************************************
Expand Down Expand Up @@ -90,7 +92,7 @@ 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;

Expand Down
10 changes: 6 additions & 4 deletions libs/libc/misc/lib_ncompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#include <signal.h>
#include <errno.h>

#include <nuttx/fs/fs.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion libs/libc/misc/lib_openat.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <errno.h>
#include <fcntl.h>

#include <nuttx/fs/fs.h>

#include "libc.h"

/****************************************************************************
Expand Down Expand Up @@ -93,7 +95,7 @@ int openat(int dirfd, FAR const char *path, int oflags, ...)
va_end(ap);
}

ret = open(fullpath, oflags, mode);
ret = _NX_OPEN(fullpath, oflags, mode);
lib_put_pathbuffer(fullpath);
return ret;
}
5 changes: 3 additions & 2 deletions libs/libc/net/lib_getifaddrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <string.h>
#include <unistd.h>

#include <nuttx/fs/fs.h>
#include <nuttx/net/netconfig.h>

#include "libc.h"
Expand Down Expand Up @@ -271,7 +272,7 @@ int getifaddrs(FAR struct ifaddrs **addrs)
#endif
}

close(sockfd);
_NX_CLOSE(sockfd);
return OK;

err:
Expand All @@ -281,6 +282,6 @@ int getifaddrs(FAR struct ifaddrs **addrs)
*addrs = NULL;
}

close(sockfd);
_NX_CLOSE(sockfd);
return ERROR;
}
Loading

0 comments on commit 18e7eb4

Please sign in to comment.