1 | //! The `cwd` function, representing the current working directory. |
2 | //! |
3 | //! # Safety |
4 | //! |
5 | //! This file uses `AT_FDCWD`, which is a raw file descriptor, but which is |
6 | //! always valid. |
7 | |
8 | #![allow (unsafe_code)] |
9 | |
10 | use crate::backend; |
11 | use backend::c; |
12 | use backend::fd::{BorrowedFd, RawFd}; |
13 | |
14 | /// Return the value of [`CWD`]. |
15 | #[deprecated (note = "Use `CWD` in place of `cwd()`." )] |
16 | pub const fn cwd() -> BorrowedFd<'static> { |
17 | let at_fdcwd: i32 = c::AT_FDCWD as RawFd; |
18 | |
19 | // SAFETY: `AT_FDCWD` is a reserved value that is never dynamically |
20 | // allocated, so it'll remain valid for the duration of `'static`. |
21 | unsafe { BorrowedFd::<'static>::borrow_raw(fd:at_fdcwd) } |
22 | } |
23 | |