Skip to content

Commit a874566

Browse files
committed
io/Open: add OpenDirectoryPath()
1 parent 613a142 commit a874566

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/io/Open.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ OpenDirectory(FileAt file, int flags)
101101
return fd;
102102
}
103103

104+
UniqueFileDescriptor
105+
OpenDirectoryPath(FileAt file, int flags)
106+
{
107+
UniqueFileDescriptor fd;
108+
if (!fd.Open(file, O_PATH|O_DIRECTORY|flags))
109+
throw FmtErrno("Failed to open {:?}", file.name);
110+
111+
return fd;
112+
}
113+
104114
#ifdef HAVE_OPENAT2
105115

106116
UniqueFileDescriptor

src/io/Open.hxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ OpenWriteOnly(FileAt file, int flags=0);
3737
UniqueFileDescriptor
3838
OpenDirectory(FileAt file, int flags=0);
3939

40+
/**
41+
* Combination of OpenDirectory() and OpenPath() - open a directory as
42+
* an O_PATH file descriptor. Like OpenDirectory(), it will fail with
43+
* ENOTDIR if the specified path exists but is not a directory
44+
*/
45+
UniqueFileDescriptor
46+
OpenDirectoryPath(FileAt file, int flags=0);
47+
4048
struct opwn_how;
4149

4250
/**

0 commit comments

Comments
 (0)