diff options
| author | geniusgogo <[email protected]> | 2023-05-15 20:40:27 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-15 20:40:27 +0800 |
| commit | 0e4a3142a88fbf3a4f3ea818112ceb0b0a4eb2ed (patch) | |
| tree | bfbccc2180ab87c1ae88390e80a25127c5304bfe /components/dfs | |
| parent | 8a1260c56af07b7753b2ed40519f014697093a8d (diff) | |
[component] add openat syscall. (#7488)
Diffstat (limited to 'components/dfs')
| -rw-r--r-- | components/dfs/dfs_v1/src/dfs_posix.c | 47 | ||||
| -rw-r--r-- | components/dfs/dfs_v2/src/dfs_posix.c | 47 |
2 files changed, 94 insertions, 0 deletions
diff --git a/components/dfs/dfs_v1/src/dfs_posix.c b/components/dfs/dfs_v1/src/dfs_posix.c index fd6d56d0b5..b0b7e3dd16 100644 --- a/components/dfs/dfs_v1/src/dfs_posix.c +++ b/components/dfs/dfs_v1/src/dfs_posix.c @@ -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 diff --git a/components/dfs/dfs_v2/src/dfs_posix.c b/components/dfs/dfs_v2/src/dfs_posix.c index fd6d56d0b5..b0b7e3dd16 100644 --- a/components/dfs/dfs_v2/src/dfs_posix.c +++ b/components/dfs/dfs_v2/src/dfs_posix.c @@ -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 |
