fd = open(filename, O_RDWR | O_CREAT | flags, permissions);
if (fd < 0) {
+ int dirfd;
mode_t dirperm;
char *p, *dir;
if ((dirperm & 0060) != 0) dirperm |= 0010;
if ((dirperm & 0006) != 0) dirperm |= 0001;
- if (fr_mkdir(NULL, dir, -1, dirperm, NULL, NULL) < 0) {
+ if (fr_mkdir(&dirfd, dir, -1, dirperm, NULL, NULL) < 0) {
fr_strerror_printf("Failed to create directory %s: %s", dir, fr_syserror(errno));
talloc_free(dir);
return -1;
}
talloc_free(dir);
- fd = open(filename, O_RDWR | O_CREAT | flags, permissions);
+ fd = openat(dirfd, p+1, O_RDWR | O_CREAT | flags, permissions);
+ close(dirfd);
if (fd < 0) {
fr_strerror_printf("Failed to open file %s: %s", filename, fr_syserror(errno));
return -1;