MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / openat

Function openat

components/dfs/dfs_v2/src/dfs_posix.c:110–152  ·  view source on GitHub ↗

* @brief Opens a file relative to a directory file descriptor. * * @param dirfd The file descriptor of the directory to base the relative path on. * @param path The path to the file to be opened, relative to the directory specified by `dirfd`. * Can be an absolute path (in which case `dirfd` is ignored). * @param flag File access and status flags (e.g., `O_RDONLY`, `O_WRONLY`,

Source from the content-addressed store, hash-verified

108 *
109 */
110int openat(int dirfd, const char *path, int flag, ...)
111{
112 struct dfs_file *d;
113 char *fullpath;
114 int fd;
115
116 if (!path)
117 {
118 rt_set_errno(-EBADF);
119 return -1;
120 }
121
122 fullpath = (char*)path;
123
124 if (path[0] != '/')
125 {
126 if (dirfd != AT_FDCWD)
127 {
128 d = fd_get(dirfd);
129 if (!d || !d->vnode)
130 {
131 rt_set_errno(-EBADF);
132 return -1;
133 }
134
135 fullpath = dfs_dentry_full_path(d->dentry);
136 if (!fullpath)
137 {
138 rt_set_errno(-ENOMEM);
139 return -1;
140 }
141 }
142 }
143
144 fd = open(fullpath, flag, 0);
145
146 if (fullpath != path)
147 {
148 rt_free(fullpath);
149 }
150
151 return fd;
152}
153
154int utimensat(int __fd, const char *__path, const struct timespec __times[2], int __flags)
155{

Callers

nothing calls this directly

Calls 5

rt_set_errnoFunction · 0.85
dfs_dentry_full_pathFunction · 0.85
rt_freeFunction · 0.85
fd_getFunction · 0.70
openFunction · 0.70

Tested by

no test coverage detected