diff options
Diffstat (limited to 'vendor/rustix-0.36.5/src/fs/cwd.rs')
-rw-r--r-- | vendor/rustix-0.36.5/src/fs/cwd.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/rustix-0.36.5/src/fs/cwd.rs b/vendor/rustix-0.36.5/src/fs/cwd.rs new file mode 100644 index 000000000..d0455cd6c --- /dev/null +++ b/vendor/rustix-0.36.5/src/fs/cwd.rs @@ -0,0 +1,32 @@ +//! The `cwd` function, representing the current working directory. +//! +//! # Safety +//! +//! This file uses `AT_FDCWD`, which is a raw file descriptor, but which is +//! always valid. + +#![allow(unsafe_code)] + +use crate::backend; +use backend::fd::{BorrowedFd, RawFd}; + +/// `AT_FDCWD`—Returns a handle representing the current working directory. +/// +/// This returns a file descriptor which refers to the process current +/// directory which can be used as the directory argument in `*at` +/// functions such as [`openat`]. +/// +/// # References +/// - [POSIX] +/// +/// [`openat`]: crate::fs::openat +/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fcntl.h.html +#[inline] +#[doc(alias = "AT_FDCWD")] +pub const fn cwd() -> BorrowedFd<'static> { + let at_fdcwd = backend::io::types::AT_FDCWD as RawFd; + + // Safety: `AT_FDCWD` is a reserved value that is never dynamically + // allocated, so it'll remain valid for the duration of `'static`. + unsafe { BorrowedFd::<'static>::borrow_raw(at_fdcwd) } +} |