mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-22 11:30:01 +08:00
[component] add openat syscall. (#7488)
This commit is contained in:
@@ -62,6 +62,53 @@ int open(const char *file, int flags, ...)
|
||||
}
|
||||
RTM_EXPORT(open);
|
||||
|
||||
#ifndef AT_FDCWD
|
||||
#define AT_FDCWD (-100)
|
||||
#endif
|
||||
int openat(int dirfd, const char *path, int flag, ...)
|
||||
{
|
||||
struct dfs_file *d;
|
||||
char *fullpath;
|
||||
int fd;
|
||||
|
||||
if (!path)
|
||||
{
|
||||
rt_set_errno(-EBADF);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fullpath = (char*)path;
|
||||
|
||||
if (path[0] != '/')
|
||||
{
|
||||
if (dirfd != AT_FDCWD)
|
||||
{
|
||||
d = fd_get(dirfd);
|
||||
if (!d || !d->vnode)
|
||||
{
|
||||
rt_set_errno(-EBADF);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fullpath = dfs_normalize_path(d->vnode->fullpath, path);
|
||||
if (!fullpath)
|
||||
{
|
||||
rt_set_errno(-ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(fullpath, flag, 0);
|
||||
|
||||
if (fullpath != path)
|
||||
{
|
||||
rt_free(fullpath);
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* this function is a POSIX compliant version,
|
||||
* which will create a new file or rewrite an existing one
|
||||
|
||||
@@ -62,6 +62,53 @@ int open(const char *file, int flags, ...)
|
||||
}
|
||||
RTM_EXPORT(open);
|
||||
|
||||
#ifndef AT_FDCWD
|
||||
#define AT_FDCWD (-100)
|
||||
#endif
|
||||
int openat(int dirfd, const char *path, int flag, ...)
|
||||
{
|
||||
struct dfs_file *d;
|
||||
char *fullpath;
|
||||
int fd;
|
||||
|
||||
if (!path)
|
||||
{
|
||||
rt_set_errno(-EBADF);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fullpath = (char*)path;
|
||||
|
||||
if (path[0] != '/')
|
||||
{
|
||||
if (dirfd != AT_FDCWD)
|
||||
{
|
||||
d = fd_get(dirfd);
|
||||
if (!d || !d->vnode)
|
||||
{
|
||||
rt_set_errno(-EBADF);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fullpath = dfs_normalize_path(d->vnode->fullpath, path);
|
||||
if (!fullpath)
|
||||
{
|
||||
rt_set_errno(-ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(fullpath, flag, 0);
|
||||
|
||||
if (fullpath != path)
|
||||
{
|
||||
rt_free(fullpath);
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* this function is a POSIX compliant version,
|
||||
* which will create a new file or rewrite an existing one
|
||||
|
||||
Reference in New Issue
Block a user