rustix/fs/cwd.rs
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
10use crate::backend;
11use backend::c;
12use backend::fd::{BorrowedFd, RawFd};
13
14/// Return the value of [`CWD`].
15#[deprecated(note = "Use `CWD` in place of `cwd()`.")]
16pub const fn cwd() -> BorrowedFd<'static> {
17 let at_fdcwd = 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(at_fdcwd) }
22}