Sha256: b2d7fbb27e23704e3367ede9916cc233f76d912be21c2aee8a635eeca627977f

Contents?: true

Size: 1023 Bytes

Versions: 10

Compression:

Stored size: 1023 Bytes

Contents

//! 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) }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
wasmtime-13.0.0 ./ext/cargo-vendor/rustix-0.37.23/src/fs/cwd.rs
wasmtime-12.0.1 ./ext/cargo-vendor/rustix-0.37.23/src/fs/cwd.rs
wasmtime-12.0.0 ./ext/cargo-vendor/rustix-0.37.23/src/fs/cwd.rs
wasmtime-11.0.0 ./ext/cargo-vendor/rustix-0.37.23/src/fs/cwd.rs
wasmtime-10.0.1 ./ext/cargo-vendor/rustix-0.37.23/src/fs/cwd.rs
wasmtime-10.0.0 ./ext/cargo-vendor/rustix-0.37.23/src/fs/cwd.rs
wasmtime-9.0.4 ./ext/cargo-vendor/rustix-0.37.23/src/fs/cwd.rs
wasmtime-9.0.1 ./ext/cargo-vendor/rustix-0.37.19/src/fs/cwd.rs
wasmtime-8.0.0 ./ext/cargo-vendor/rustix-0.37.13/src/fs/cwd.rs
wasmtime-7.0.0 ./ext/cargo-vendor/rustix-0.37.5/src/fs/cwd.rs