[component] add openat syscall. (#7488)

This commit is contained in:
geniusgogo
2023-05-15 20:40:27 +08:00
committed by GitHub
parent 8a1260c56a
commit 0e4a3142a8
3 changed files with 136 additions and 0 deletions
+47
View File
@@ -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
+47
View File
@@ -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