return strdup_to(ret, ".");
}
-int chase_and_open(const char *path, const char *root, ChaseFlags chase_flags, int open_flags, char **ret_path) {
+int chase_and_open(
+ const char *path,
+ const char *root,
+ ChaseFlags chase_flags,
+ int open_flags,
+ char **ret_path) {
+
_cleanup_close_ int path_fd = -EBADF;
_cleanup_free_ char *p = NULL, *fname = NULL;
- mode_t mode = open_flags & O_DIRECTORY ? 0755 : 0644;
int r;
assert(!(chase_flags & (CHASE_NONEXISTENT|CHASE_STEP)));
return xopenat_full(AT_FDCWD, path,
open_flags | (FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? O_NOFOLLOW : 0),
/* xopen_flags = */ 0,
- mode);
+ MODE_INVALID);
r = chase(path, root, CHASE_PARENT|chase_flags, &p, &path_fd);
if (r < 0)
return r;
}
- r = xopenat_full(path_fd, strempty(fname), open_flags|O_NOFOLLOW, /* xopen_flags = */ 0, mode);
+ r = xopenat_full(path_fd, strempty(fname), open_flags|O_NOFOLLOW, /* xopen_flags = */ 0, MODE_INVALID);
if (r < 0)
return r;
return pfd;
}
-int chase_and_openat(int dir_fd, const char *path, ChaseFlags chase_flags, int open_flags, char **ret_path) {
+int chase_and_openat(
+ int dir_fd,
+ const char *path,
+ ChaseFlags chase_flags,
+ int open_flags,
+ char **ret_path) {
+
_cleanup_close_ int path_fd = -EBADF;
_cleanup_free_ char *p = NULL, *fname = NULL;
- mode_t mode = open_flags & O_DIRECTORY ? 0755 : 0644;
int r;
assert(!(chase_flags & (CHASE_NONEXISTENT|CHASE_STEP)));
return xopenat_full(dir_fd, path,
open_flags | (FLAGS_SET(chase_flags, CHASE_NOFOLLOW) ? O_NOFOLLOW : 0),
/* xopen_flags = */ 0,
- mode);
+ MODE_INVALID);
r = chaseat(dir_fd, path, chase_flags|CHASE_PARENT, &p, &path_fd);
if (r < 0)
return r;
}
- r = xopenat_full(path_fd, strempty(fname), open_flags|O_NOFOLLOW, /* xopen_flags = */ 0, mode);
+ r = xopenat_full(path_fd, strempty(fname), open_flags|O_NOFOLLOW, /* xopen_flags= */ 0, MODE_INVALID);
if (r < 0)
return r;
* • If the path is specified NULL or empty, behaves like fd_reopen().
*
* • If XO_NOCOW is specified will turn on the NOCOW btrfs flag on the file, if available.
+ *
+ * • If mode is specified as MODE_INVALID, we'll use 0755 for dirs, and 0644 for regular files.
*/
+ if (mode == MODE_INVALID)
+ mode = (open_flags & O_DIRECTORY) ? 0755 : 0644;
+
if (isempty(path)) {
assert(!FLAGS_SET(open_flags, O_CREAT|O_EXCL));
return fd_reopen(dir_fd, open_flags & ~O_NOFOLLOW);