File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,27 @@ impl Dir {
7575 }
7676 }
7777
78+ /// Returns the file descriptor associated with the directory stream.
79+ ///
80+ /// The file descriptor is used internally by the directory stream. As a result, it is useful
81+ /// only for functions which do not depend or alter the file position.
82+ ///
83+ /// # References
84+ ///
85+ /// - [POSIX]
86+ ///
87+ /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/dirfd.html
88+ #[ inline]
89+ #[ doc( alias = "dirfd" ) ]
90+ pub fn fd < ' a > ( & ' a self ) -> io:: Result < BorrowedFd < ' a > > {
91+ let raw_fd = unsafe { c:: dirfd ( self . libc_dir . as_ptr ( ) ) } ;
92+ if raw_fd < 0 {
93+ Err ( io:: Errno :: last_os_error ( ) )
94+ } else {
95+ Ok ( unsafe { BorrowedFd :: borrow_raw ( raw_fd) } )
96+ }
97+ }
98+
7899 /// Borrow `fd` and construct a `Dir` that reads entries from the given
79100 /// directory file descriptor.
80101 #[ inline]
Original file line number Diff line number Diff line change @@ -50,6 +50,22 @@ impl Dir {
5050 } )
5151 }
5252
53+ /// Returns the file descriptor associated with the directory stream.
54+ ///
55+ /// The file descriptor is used internally by the directory stream. As a result, it is useful
56+ /// only for functions which do not depend or alter the file position.
57+ ///
58+ /// # References
59+ ///
60+ /// - [POSIX]
61+ ///
62+ /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/dirfd.html
63+ #[ inline]
64+ #[ doc( alias = "dirfd" ) ]
65+ pub fn fd < ' a > ( & ' a self ) -> io:: Result < BorrowedFd < ' a > > {
66+ Ok ( self . fd . as_fd ( ) )
67+ }
68+
5369 /// Borrow `fd` and construct a `Dir` that reads entries from the given
5470 /// directory file descriptor.
5571 #[ inline]
You can’t perform that action at this time.
0 commit comments