* @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`,
| 108 | * |
| 109 | */ |
| 110 | int 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 | |
| 154 | int utimensat(int __fd, const char *__path, const struct timespec __times[2], int __flags) |
| 155 | { |
nothing calls this directly
no test coverage detected